added --is_spent filter to txo list/sum commands

This commit is contained in:
Lex Berezhny 2020-03-31 23:08:51 -04:00
parent 052e77dd5a
commit 769ea8cdfe
3 changed files with 24 additions and 8 deletions

View file

@ -4168,11 +4168,15 @@ class Daemon(metaclass=JSONRPCServerType):
@staticmethod @staticmethod
def _constrain_txo_from_kwargs( def _constrain_txo_from_kwargs(
constraints, type=None, txid=None, # pylint: disable=redefined-builtin constraints, type=None, txid=None, # pylint: disable=redefined-builtin
claim_id=None, channel_id=None, name=None, unspent=False, reposted_claim_id=None, claim_id=None, channel_id=None, name=None, reposted_claim_id=None,
is_spent=False, is_not_spent=False, unspent=False,
is_my_input_or_output=None, exclude_internal_transfers=False, is_my_input_or_output=None, exclude_internal_transfers=False,
is_my_output=None, is_not_my_output=None, is_my_output=None, is_not_my_output=None,
is_my_input=None, is_not_my_input=None): is_my_input=None, is_not_my_input=None):
constraints['unspent'] = unspent if unspent or is_not_spent:
constraints['unspent'] = True
elif is_spent:
constraints['is_spent'] = True
constraints['exclude_internal_transfers'] = exclude_internal_transfers constraints['exclude_internal_transfers'] = exclude_internal_transfers
if is_my_input_or_output is True: if is_my_input_or_output is True:
constraints['is_my_input_or_output'] = True constraints['is_my_input_or_output'] = True
@ -4201,7 +4205,8 @@ class Daemon(metaclass=JSONRPCServerType):
List my transaction outputs. List my transaction outputs.
Usage: Usage:
txo_list [--account_id=<account_id>] [--type=<type>...] [--txid=<txid>...] [--unspent] txo_list [--account_id=<account_id>] [--type=<type>...] [--txid=<txid>...]
[--is_spent] [--is_not_spent] [--unspent]
[--claim_id=<claim_id>...] [--channel_id=<channel_id>...] [--name=<name>...] [--claim_id=<claim_id>...] [--channel_id=<channel_id>...] [--name=<name>...]
[--is_my_input_or_output | [--is_my_input_or_output |
[[--is_my_output | --is_not_my_output] [--is_my_input | --is_not_my_input]] [[--is_my_output | --is_not_my_output] [--is_my_input | --is_not_my_input]]
@ -4217,7 +4222,9 @@ class Daemon(metaclass=JSONRPCServerType):
--claim_id=<claim_id> : (str or list) claim id --claim_id=<claim_id> : (str or list) claim id
--channel_id=<channel_id> : (str or list) claims in this channel --channel_id=<channel_id> : (str or list) claims in this channel
--name=<name> : (str or list) claim name --name=<name> : (str or list) claim name
--unspent : (bool) hide spent outputs, show only unspent ones --is_spent : (bool) only show spent txos
--is_not_spent : (bool) only show not spent txos
--unspent : (bool) deprecated, alias for --is_not_spent
--is_my_input_or_output : (bool) txos which have your inputs or your outputs, --is_my_input_or_output : (bool) txos which have your inputs or your outputs,
if using this flag the other related flags if using this flag the other related flags
are ignored (--is_my_output, --is_my_input, etc) are ignored (--is_my_output, --is_my_input, etc)
@ -4330,7 +4337,8 @@ class Daemon(metaclass=JSONRPCServerType):
Usage: Usage:
txo_list [--account_id=<account_id>] [--type=<type>...] [--txid=<txid>...] txo_list [--account_id=<account_id>] [--type=<type>...] [--txid=<txid>...]
[--claim_id=<claim_id>...] [--name=<name>...] [--unspent] [--claim_id=<claim_id>...] [--name=<name>...]
[--is_spent] [--is_not_spent] [--unspent]
[--is_my_input_or_output | [--is_my_input_or_output |
[[--is_my_output | --is_not_my_output] [--is_my_input | --is_not_my_input]] [[--is_my_output | --is_not_my_output] [--is_my_input | --is_not_my_input]]
] ]
@ -4342,7 +4350,9 @@ class Daemon(metaclass=JSONRPCServerType):
--txid=<txid> : (str or list) transaction id of outputs --txid=<txid> : (str or list) transaction id of outputs
--claim_id=<claim_id> : (str or list) claim id --claim_id=<claim_id> : (str or list) claim id
--name=<name> : (str or list) claim name --name=<name> : (str or list) claim name
--unspent : (bool) hide spent outputs, show only unspent ones --is_spent : (bool) only show spent txos
--is_not_spent : (bool) only show not spent txos
--unspent : (bool) deprecated, alias for --is_not_spent
--is_my_input_or_output : (bool) txos which have your inputs or your outputs, --is_my_input_or_output : (bool) txos which have your inputs or your outputs,
if using this flag the other related flags if using this flag the other related flags
are ignored (--is_my_output, --is_my_input, etc) are ignored (--is_my_output, --is_my_input, etc)

View file

@ -694,7 +694,7 @@ class Database(SQLiteMixin):
self, cols, accounts=None, is_my_input=None, is_my_output=True, self, cols, accounts=None, is_my_input=None, is_my_output=True,
is_my_input_or_output=None, exclude_internal_transfers=False, is_my_input_or_output=None, exclude_internal_transfers=False,
include_is_spent=False, include_is_my_input=False, include_is_spent=False, include_is_my_input=False,
read_only=False, **constraints): is_spent=False, read_only=False, **constraints):
for rename_col in ('txid', 'txoid'): for rename_col in ('txid', 'txoid'):
for rename_constraint in (rename_col, rename_col+'__in', rename_col+'__not_in'): for rename_constraint in (rename_col, rename_col+'__in', rename_col+'__not_in'):
if rename_constraint in constraints: if rename_constraint in constraints:
@ -737,7 +737,9 @@ class Database(SQLiteMixin):
'txi.address__not_in': my_addresses 'txi.address__not_in': my_addresses
} }
sql = [f"SELECT {cols} FROM txo JOIN tx ON (tx.txid=txo.txid)"] sql = [f"SELECT {cols} FROM txo JOIN tx ON (tx.txid=txo.txid)"]
if include_is_spent: if is_spent:
constraints['spent.txoid__is_not_null'] = True
if include_is_spent or is_spent:
sql.append("LEFT JOIN txi AS spent ON (spent.txoid=txo.txoid)") sql.append("LEFT JOIN txi AS spent ON (spent.txoid=txo.txoid)")
if include_is_my_input: if include_is_my_input:
sql.append("LEFT JOIN txi ON (txi.position=0 AND txi.txid=txo.txid)") sql.append("LEFT JOIN txi ON (txi.position=0 AND txi.txid=txo.txid)")

View file

@ -547,6 +547,10 @@ class TransactionOutputCommands(ClaimTestCase):
r = await self.txo_list(is_my_input=True, is_my_output=True, type="other", unspent=True) r = await self.txo_list(is_my_input=True, is_my_output=True, type="other", unspent=True)
self.assertEqual([change2], r) self.assertEqual([change2], r)
# only spent "change"
r = await self.txo_list(is_my_input=True, is_my_output=True, type="other", is_spent=True)
self.assertEqual([change1], r)
# all my unspent stuff # all my unspent stuff
r = await self.txo_list(is_my_output=True, unspent=True) r = await self.txo_list(is_my_output=True, unspent=True)
self.assertEqual([change2, kept_channel], r) self.assertEqual([change2, kept_channel], r)