diff --git a/lbry/wallet/server/db/prefixes.py b/lbry/wallet/server/db/prefixes.py index 53e17596c..3b9108da4 100644 --- a/lbry/wallet/server/db/prefixes.py +++ b/lbry/wallet/server/db/prefixes.py @@ -658,6 +658,13 @@ class ClaimToSupportPrefixRow(PrefixRow): key_struct = struct.Struct(b'>20sLH') value_struct = struct.Struct(b'>Q') + key_part_lambdas = [ + lambda: b'', + struct.Struct(b'>20s').pack, + struct.Struct(b'>20sL').pack, + struct.Struct(b'>20sLH').pack + ] + @classmethod def pack_key(cls, claim_hash: bytes, tx_num: int, position: int): return super().pack_key(claim_hash, tx_num, position) diff --git a/lbry/wallet/server/leveldb.py b/lbry/wallet/server/leveldb.py index f1ea674ea..82b5e4d4a 100644 --- a/lbry/wallet/server/leveldb.py +++ b/lbry/wallet/server/leveldb.py @@ -189,13 +189,13 @@ class LevelDB: def get_support_amount(self, claim_hash: bytes): total = 0 - for packed in self.db.iterator(prefix=DB_PREFIXES.claim_to_support.value + claim_hash, include_key=False): + for packed in self.db.iterator(prefix=Prefixes.claim_to_support.pack_partial_key(claim_hash), include_key=False): total += Prefixes.claim_to_support.unpack_value(packed).amount return total def get_supports(self, claim_hash: bytes): supports = [] - for k, v in self.db.iterator(prefix=DB_PREFIXES.claim_to_support.value + claim_hash): + for k, v in self.db.iterator(prefix=Prefixes.claim_to_support.pack_partial_key(claim_hash)): unpacked_k = Prefixes.claim_to_support.unpack_key(k) unpacked_v = Prefixes.claim_to_support.unpack_value(v) supports.append((unpacked_k.tx_num, unpacked_k.position, unpacked_v.amount))