From 205688866715ade4056e3c3d15cf07527daca4a0 Mon Sep 17 00:00:00 2001 From: Victor Shyba Date: Sun, 28 Jul 2019 18:25:16 -0300 Subject: [PATCH] implement tips_received tips_sent, wip, in python for now --- lbry/lbry/extras/daemon/Daemon.py | 19 +++++++++++++------ .../integration/test_transaction_commands.py | 4 ++-- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/lbry/lbry/extras/daemon/Daemon.py b/lbry/lbry/extras/daemon/Daemon.py index a40ea0fa5..e12c9772d 100644 --- a/lbry/lbry/extras/daemon/Daemon.py +++ b/lbry/lbry/extras/daemon/Daemon.py @@ -1044,10 +1044,17 @@ class Daemon(metaclass=JSONRPCServerType): (decimal) amount of lbry credits in wallet """ account = self.get_account_or_default(account_id) - get_balance = partial(account.get_balance, confirmations=True) - claims_balance = await get_balance(include_claims=True, claim_type__or={'is_claim':True, 'is_update': True}) - supports_balance = await get_balance(include_claims=True, is_support=True) - total = await get_balance(include_claims=True) + get_total_balance = partial(account.get_balance, confirmations=True, include_claims=True) + total = await get_total_balance() + claims_balance = await get_total_balance(claim_type__or={'is_claim':True, 'is_update': True}) + supports_balance = await get_total_balance(is_support=True) + tips_received, tips_sent = 0, 0 + for transaction in await account.get_transactions(): + for support_output in transaction.my_support_outputs: + if all([not txi.is_my_account for txi in transaction.inputs]): + tips_received += support_output.amount + for support_output in transaction.other_support_outputs: + tips_sent += support_output.amount unavailable = claims_balance + supports_balance return { 'total': dewies_to_lbc(total), @@ -1057,8 +1064,8 @@ class Daemon(metaclass=JSONRPCServerType): 'claims': dewies_to_lbc(claims_balance), 'supports': dewies_to_lbc(supports_balance) }, - 'tips_received': '0.0', - 'tips_sent': '0.0' + 'tips_received': dewies_to_lbc(tips_received), + 'tips_sent': dewies_to_lbc(tips_sent) } @requires("wallet") diff --git a/lbry/tests/integration/test_transaction_commands.py b/lbry/tests/integration/test_transaction_commands.py index fecc5325d..fafd0c722 100644 --- a/lbry/tests/integration/test_transaction_commands.py +++ b/lbry/tests/integration/test_transaction_commands.py @@ -59,8 +59,8 @@ class TransactionCommandsTestCase(CommandTestCase): first_claim_id, '0.3', tip=True, account_id=second_account_id)).id) final_balance = await self.daemon.jsonrpc_account_balance() self.assertEqual({ - 'tips_received': '0.0', - 'tips_sent': '0.0', + 'tips_received': '0.3', + 'tips_sent': '0.5', 'total': '8.777264', 'available': '5.477264', 'reserved': {'claims': '1.0', 'supports': '2.3', 'total': '3.3'}