diff --git a/lbry/extras/daemon/daemon.py b/lbry/extras/daemon/daemon.py index e0523367f..0d3359494 100644 --- a/lbry/extras/daemon/daemon.py +++ b/lbry/extras/daemon/daemon.py @@ -4112,7 +4112,7 @@ class Daemon(metaclass=JSONRPCServerType): @staticmethod def _constrain_txo_from_kwargs( constraints, type=None, txid=None, # pylint: disable=redefined-builtin - claim_id=None, name=None, unspent=False, + claim_id=None, name=None, unspent=False, reposted_claim_id=None, is_my_input_or_output=None, exclude_internal_transfers=False, is_my_output=None, is_not_my_output=None, is_my_input=None, is_not_my_input=None): @@ -4133,6 +4133,7 @@ class Daemon(metaclass=JSONRPCServerType): database.constrain_single_or_list(constraints, 'claim_id', claim_id) database.constrain_single_or_list(constraints, 'claim_name', name) database.constrain_single_or_list(constraints, 'txid', txid) + database.constrain_single_or_list(constraints, 'reposted_claim_id', reposted_claim_id) return constraints @requires(WALLET_COMPONENT) @@ -4196,7 +4197,7 @@ class Daemon(metaclass=JSONRPCServerType): @requires(WALLET_COMPONENT) def jsonrpc_txo_sum(self, account_id=None, wallet_id=None, **kwargs): """ - Sum transaction outputs. + Sum of transaction outputs. Usage: txo_list [--account_id=] [--type=...] [--txid=...] @@ -4204,8 +4205,7 @@ class Daemon(metaclass=JSONRPCServerType): [--is_my_input_or_output | [[--is_my_output | --is_not_my_output] [--is_my_input | --is_not_my_input]] ] - [--exclude_internal_transfers] - [--wallet_id=] + [--exclude_internal_transfers] [--wallet_id=] Options: --type= : (str or list) claim type: stream, channel, support, @@ -4228,7 +4228,7 @@ class Daemon(metaclass=JSONRPCServerType): --account_id= : (str) id of the account to query --wallet_id= : (str) restrict results to specific wallet - Returns: {Paginated[Output]} + Returns: int """ wallet = self.wallet_manager.get_wallet_or_default(wallet_id) return self.ledger.get_txo_sum( diff --git a/lbry/wallet/database.py b/lbry/wallet/database.py index bb301ab29..5c707be9f 100644 --- a/lbry/wallet/database.py +++ b/lbry/wallet/database.py @@ -439,13 +439,16 @@ class Database(SQLiteMixin): txo_type integer not null default 0, claim_id text, - claim_name text + claim_name text, + + reposted_claim_id text ); create index if not exists txo_txid_idx on txo (txid); create index if not exists txo_address_idx on txo (address); create index if not exists txo_claim_id_idx on txo (claim_id); create index if not exists txo_claim_name_idx on txo (claim_name); create index if not exists txo_txo_type_idx on txo (txo_type); + create index if not exists txo_reposted_claim_idx on txo (reposted_claim_id); """ CREATE_TXI_TABLE = """ @@ -483,7 +486,10 @@ class Database(SQLiteMixin): } if txo.is_claim: if txo.can_decode_claim: - row['txo_type'] = TXO_TYPES.get(txo.claim.claim_type, TXO_TYPES['stream']) + claim = txo.claim + row['txo_type'] = TXO_TYPES.get(claim.claim_type, TXO_TYPES['stream']) + if claim.is_repost: + row['reposted_claim_id'] = claim.repost.reference.claim_id else: row['txo_type'] = TXO_TYPES['stream'] elif txo.is_support: diff --git a/tests/integration/blockchain/test_claim_commands.py b/tests/integration/blockchain/test_claim_commands.py index 252d8299b..d7e32301b 100644 --- a/tests/integration/blockchain/test_claim_commands.py +++ b/tests/integration/blockchain/test_claim_commands.py @@ -1023,12 +1023,16 @@ class StreamCommands(ClaimTestCase): claim_id = self.get_claim_id(tx) self.assertEqual((await self.claim_search(name='newstuff'))[0]['meta']['reposted'], 0) + self.assertItemCount(await self.daemon.jsonrpc_txo_list(reposted_claim_id=claim_id), 0) + self.assertItemCount(await self.daemon.jsonrpc_txo_list(type='repost'), 0) tx = await self.stream_repost(claim_id, 'newstuff-again', '1.1') repost_id = self.get_claim_id(tx) self.assertItemCount(await self.daemon.jsonrpc_claim_list(claim_type='repost'), 1) self.assertEqual((await self.claim_search(name='newstuff'))[0]['meta']['reposted'], 1) self.assertEqual((await self.claim_search(reposted_claim_id=claim_id))[0]['claim_id'], repost_id) + self.assertEqual((await self.txo_list(reposted_claim_id=claim_id))[0]['claim_id'], repost_id) + self.assertEqual((await self.txo_list(type='repost'))[0]['claim_id'], repost_id) # tags are inherited (non-common / indexed tags) self.assertItemCount(await self.daemon.jsonrpc_claim_search(any_tags=['foo'], claim_type=['stream', 'repost']), 2)