new api format, hide subtotals by default
This commit is contained in:
parent
59424a3e73
commit
35541bbbb9
2 changed files with 39 additions and 32 deletions
|
@ -1027,19 +1027,21 @@ class Daemon(metaclass=JSONRPCServerType):
|
||||||
return self.wallet_manager.get_detailed_accounts(**kwargs)
|
return self.wallet_manager.get_detailed_accounts(**kwargs)
|
||||||
|
|
||||||
@requires("wallet")
|
@requires("wallet")
|
||||||
async def jsonrpc_account_balance(self, account_id=None, confirmations=0):
|
async def jsonrpc_account_balance(self, account_id=None, confirmations=0, reserved_subtotals=False):
|
||||||
"""
|
"""
|
||||||
Return the balance of an account
|
Return the balance of an account
|
||||||
|
|
||||||
Usage:
|
Usage:
|
||||||
account_balance [<account_id>] [<address> | --address=<address>]
|
account_balance [<account_id>] [<address> | --address=<address>]
|
||||||
[<confirmations> | --confirmations=<confirmations>]
|
[<confirmations> | --confirmations=<confirmations>] [--reserved_subtotals]
|
||||||
|
|
||||||
Options:
|
Options:
|
||||||
--account_id=<account_id> : (str) If provided only the balance for this
|
--account_id=<account_id> : (str) If provided only the balance for this
|
||||||
account will be given. Otherwise default account.
|
account will be given. Otherwise default account.
|
||||||
--confirmations=<confirmations> : (int) Only include transactions with this many
|
--confirmations=<confirmations> : (int) Only include transactions with this many
|
||||||
confirmed blocks.
|
confirmed blocks.
|
||||||
|
--reserved_subtotals : (bool) Include detailed reserved balances on
|
||||||
|
claims, tips and supports.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
(decimal) amount of lbry credits in wallet
|
(decimal) amount of lbry credits in wallet
|
||||||
|
@ -1047,11 +1049,20 @@ class Daemon(metaclass=JSONRPCServerType):
|
||||||
account = self.get_account_or_default(account_id)
|
account = self.get_account_or_default(account_id)
|
||||||
get_total_balance = partial(account.get_balance, confirmations=confirmations, include_claims=True)
|
get_total_balance = partial(account.get_balance, confirmations=confirmations, include_claims=True)
|
||||||
total = await get_total_balance()
|
total = await get_total_balance()
|
||||||
|
if not reserved_subtotals:
|
||||||
|
reserved = await account.get_balance(
|
||||||
|
confirmations=confirmations, include_claims=True,
|
||||||
|
claim_type__or={'is_claim': True, 'is_support': True, 'is_update': True}
|
||||||
|
)
|
||||||
|
return {
|
||||||
|
'total': dewies_to_lbc(total),
|
||||||
|
'reserved': dewies_to_lbc(reserved),
|
||||||
|
'available': dewies_to_lbc(total - reserved),
|
||||||
|
'reserved_subtotals': None
|
||||||
|
}
|
||||||
claims_balance = await get_total_balance(claim_type__or={'is_claim':True, 'is_update': True})
|
claims_balance = await get_total_balance(claim_type__or={'is_claim':True, 'is_update': True})
|
||||||
tips_received, tips_sent, tips_balance, supports_balance = 0, 0, 0, 0
|
tips_balance, supports_balance = 0, 0
|
||||||
for amount, spent, from_me, to_me, height in await account.get_support_summary():
|
for amount, spent, from_me, to_me, height in await account.get_support_summary():
|
||||||
tips_sent += amount if from_me and not to_me else 0
|
|
||||||
tips_received += amount if to_me and not from_me else 0
|
|
||||||
if confirmations > 0 and not 0 < height <= self.ledger.headers.height - (confirmations - 1):
|
if confirmations > 0 and not 0 < height <= self.ledger.headers.height - (confirmations - 1):
|
||||||
continue
|
continue
|
||||||
if not spent and to_me:
|
if not spent and to_me:
|
||||||
|
@ -1061,14 +1072,12 @@ class Daemon(metaclass=JSONRPCServerType):
|
||||||
return {
|
return {
|
||||||
'total': dewies_to_lbc(total),
|
'total': dewies_to_lbc(total),
|
||||||
'available': dewies_to_lbc(total - unavailable),
|
'available': dewies_to_lbc(total - unavailable),
|
||||||
'reserved': {
|
'reserved': dewies_to_lbc(unavailable),
|
||||||
'total': dewies_to_lbc(unavailable),
|
'reserved_subtotals': {
|
||||||
'claims': dewies_to_lbc(claims_balance),
|
'claims': dewies_to_lbc(claims_balance),
|
||||||
'supports': dewies_to_lbc(supports_balance),
|
'supports': dewies_to_lbc(supports_balance),
|
||||||
'tips': dewies_to_lbc(tips_balance)
|
'tips': dewies_to_lbc(tips_balance)
|
||||||
},
|
}
|
||||||
'tips_received': dewies_to_lbc(tips_received),
|
|
||||||
'tips_sent': dewies_to_lbc(tips_sent)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@requires("wallet")
|
@requires("wallet")
|
||||||
|
|
|
@ -38,13 +38,12 @@ class TransactionCommandsTestCase(CommandTestCase):
|
||||||
await self.assertBalance(self.account, '11.0')
|
await self.assertBalance(self.account, '11.0')
|
||||||
|
|
||||||
async def test_granular_balances(self):
|
async def test_granular_balances(self):
|
||||||
initial_balance = await self.daemon.jsonrpc_account_balance()
|
initial_balance = await self.daemon.jsonrpc_account_balance(reserved_subtotals=True)
|
||||||
self.assertEqual({
|
self.assertEqual({
|
||||||
'tips_received': '0.0',
|
|
||||||
'tips_sent': '0.0',
|
|
||||||
'total': '10.0',
|
'total': '10.0',
|
||||||
'available': '10.0',
|
'available': '10.0',
|
||||||
'reserved': {'total': '0.0', 'claims': '0.0', 'supports': '0.0', 'tips': '0.0'}
|
'reserved': '0.0',
|
||||||
|
'reserved_subtotals': {'claims': '0.0', 'supports': '0.0', 'tips': '0.0'}
|
||||||
}, initial_balance)
|
}, initial_balance)
|
||||||
first_claim_id = self.get_claim_id(await self.stream_create('granularity', bid='3.0'))
|
first_claim_id = self.get_claim_id(await self.stream_create('granularity', bid='3.0'))
|
||||||
await self.stream_update(first_claim_id, data=b'news', bid='1.0')
|
await self.stream_update(first_claim_id, data=b'news', bid='1.0')
|
||||||
|
@ -53,29 +52,28 @@ class TransactionCommandsTestCase(CommandTestCase):
|
||||||
second_accound_address = await self.daemon.jsonrpc_address_unused(second_account_id)
|
second_accound_address = await self.daemon.jsonrpc_address_unused(second_account_id)
|
||||||
await self.confirm_tx((await self.daemon.jsonrpc_account_send('1.0', second_accound_address)).id)
|
await self.confirm_tx((await self.daemon.jsonrpc_account_send('1.0', second_accound_address)).id)
|
||||||
self.assertEqual({
|
self.assertEqual({
|
||||||
'tips_received': '0.0',
|
|
||||||
'tips_sent': '0.0',
|
|
||||||
'total': '8.97741',
|
'total': '8.97741',
|
||||||
'available': '5.97741',
|
'available': '5.97741',
|
||||||
'reserved': {'claims': '1.0', 'supports': '2.0', 'tips': '0.0', 'total': '3.0'}
|
'reserved': '3.0',
|
||||||
}, await self.daemon.jsonrpc_account_balance())
|
'reserved_subtotals': {'claims': '1.0', 'supports': '2.0', 'tips': '0.0'}
|
||||||
|
}, await self.daemon.jsonrpc_account_balance(reserved_subtotals=True))
|
||||||
second_claim_id = self.get_claim_id(await self.stream_create(
|
second_claim_id = self.get_claim_id(await self.stream_create(
|
||||||
name='granularity-is-cool', account_id=second_account_id, bid='0.1'))
|
name='granularity-is-cool', account_id=second_account_id, bid='0.1'))
|
||||||
await self.daemon.jsonrpc_support_create(second_claim_id, '0.5', tip=True)
|
await self.daemon.jsonrpc_support_create(second_claim_id, '0.5', tip=True)
|
||||||
first_account_tip_txid = await self.confirm_tx((await self.daemon.jsonrpc_support_create(
|
first_account_tip_txid = await self.confirm_tx((await self.daemon.jsonrpc_support_create(
|
||||||
first_claim_id, '0.3', tip=True, account_id=second_account_id)).id)
|
first_claim_id, '0.3', tip=True, account_id=second_account_id)).id)
|
||||||
self.assertEqual({
|
for with_subtotals in (True, False):
|
||||||
'tips_received': '0.3',
|
self.assertEqual({
|
||||||
'tips_sent': '0.5',
|
'total': '8.777264',
|
||||||
'total': '8.777264',
|
'available': '5.477264',
|
||||||
'available': '5.477264',
|
'reserved': '3.3',
|
||||||
'reserved': {'claims': '1.0', 'supports': '2.0', 'tips': '0.3', 'total': '3.3'}
|
'reserved_subtotals': {'claims': '1.0', 'supports': '2.0', 'tips': '0.3'} if with_subtotals else None
|
||||||
}, await self.daemon.jsonrpc_account_balance())
|
}, await self.daemon.jsonrpc_account_balance(reserved_subtotals=with_subtotals))
|
||||||
await self.confirm_tx((await self.daemon.jsonrpc_support_abandon(txid=first_account_tip_txid, nout=0)).id)
|
await self.confirm_tx((await self.daemon.jsonrpc_support_abandon(txid=first_account_tip_txid, nout=0)).id)
|
||||||
self.assertEqual({
|
for with_subtotals in (True, False):
|
||||||
'tips_received': '0.3',
|
self.assertEqual({
|
||||||
'tips_sent': '0.5',
|
'total': '8.777157',
|
||||||
'total': '8.777157',
|
'available': '5.777157',
|
||||||
'available': '5.777157',
|
'reserved': '3.0',
|
||||||
'reserved': {'claims': '1.0', 'supports': '2.0', 'tips': '0.0', 'total': '3.0'}
|
'reserved_subtotals': {'claims': '1.0', 'supports': '2.0', 'tips': '0.0'} if with_subtotals else None
|
||||||
}, await self.daemon.jsonrpc_account_balance())
|
}, await self.daemon.jsonrpc_account_balance(reserved_subtotals=with_subtotals))
|
||||||
|
|
Loading…
Add table
Reference in a new issue