account_balance returns Decimal intead of rounded float

This commit is contained in:
Lex Berezhny 2018-08-30 17:12:57 -04:00
parent f0f30fd75c
commit 1d40ec34a2
2 changed files with 21 additions and 22 deletions

View file

@ -1140,23 +1140,21 @@ class Daemon(AuthJSONRPCServer):
(map) balance of account(s) (map) balance of account(s)
""" """
if account_id: if account_id:
for account in self.wallet_manager.accounts: account = self.get_account_or_error('account', account_id)
if account.id == account_id: args = {
if include_claims and not isinstance(account, LBCAccount): 'confirmations': confirmations,
raise Exception( 'include_reserved': include_reserved,
"'--include-claims' requires specifying an LBC ledger account. " 'include_seed': show_seed
"Found '{}', but it's an {} ledger account." }
.format(account_id, account.ledger.symbol) if include_claims:
) args['include_claims'] = True
args = { if not isinstance(account, LBCAccount):
'confirmations': confirmations, raise Exception(
'include_reserved': include_reserved, "'--include-claims' requires specifying an LBC ledger account. "
'include_seed': show_seed "Found '{}', but it's an {} ledger account."
} .format(account_id, account.ledger.symbol)
if include_claims: )
args['include_claims'] = True return account.get_details(**args)
return account.get_details(**args)
raise Exception("Couldn't find an account: '{}'.".format(account_id))
else: else:
if include_claims: if include_claims:
raise Exception("'--include-claims' requires specifying an LBC account by id.") raise Exception("'--include-claims' requires specifying an LBC account by id.")
@ -1185,7 +1183,7 @@ class Daemon(AuthJSONRPCServer):
dewies = yield self.default_account.get_balance( dewies = yield self.default_account.get_balance(
0 if include_unconfirmed else 6 0 if include_unconfirmed else 6
) )
return round(dewies / COIN, 3) return Decimal(dewies) / COIN
@requires("wallet") @requires("wallet")
@defer.inlineCallbacks @defer.inlineCallbacks

View file

@ -2,6 +2,7 @@ import json
import tempfile import tempfile
import logging import logging
import asyncio import asyncio
from decimal import Decimal
from types import SimpleNamespace from types import SimpleNamespace
from twisted.internet import defer from twisted.internet import defer
@ -206,7 +207,7 @@ class EpicAdventuresOfChris45(CommandTestCase):
# To get the unconfirmed balance he has to pass the '--include-unconfirmed' # To get the unconfirmed balance he has to pass the '--include-unconfirmed'
# flag to lbrynet: # flag to lbrynet:
result = yield self.daemon.jsonrpc_account_balance(include_unconfirmed=True) result = yield self.daemon.jsonrpc_account_balance(include_unconfirmed=True)
self.assertEqual(result, 8.99) self.assertEqual(result, Decimal('8.989893'))
# "Well, that's a relief." he thinks to himself as he exhales a sigh of relief. # "Well, that's a relief." he thinks to himself as he exhales a sigh of relief.
# He waits for a block # He waits for a block
@ -227,7 +228,7 @@ class EpicAdventuresOfChris45(CommandTestCase):
yield self.d_generate(1) yield self.d_generate(1)
# and it should be 6 total, enough to get the correct balance! # and it should be 6 total, enough to get the correct balance!
result = yield self.daemon.jsonrpc_account_balance() result = yield self.daemon.jsonrpc_account_balance()
self.assertEqual(result, 8.99) self.assertEqual(result, Decimal('8.989893'))
# Like a Swiss watch (right niko?) the blockchain never disappoints! We're # Like a Swiss watch (right niko?) the blockchain never disappoints! We're
# at 6 confirmations and the total is correct. # at 6 confirmations and the total is correct.
@ -258,7 +259,7 @@ class EpicAdventuresOfChris45(CommandTestCase):
# He quickly checks the unconfirmed balance to make sure everything looks # He quickly checks the unconfirmed balance to make sure everything looks
# correct. # correct.
result = yield self.daemon.jsonrpc_account_balance(include_unconfirmed=True) result = yield self.daemon.jsonrpc_account_balance(include_unconfirmed=True)
self.assertEqual(round(result, 2), 7.97) self.assertEqual(result, Decimal('7.969786'))
# Also checks that his new story can be found on the blockchain before # Also checks that his new story can be found on the blockchain before
# giving the link to all his friends. # giving the link to all his friends.
@ -270,7 +271,7 @@ class EpicAdventuresOfChris45(CommandTestCase):
yield self.d_generate(5) yield self.d_generate(5)
# When he comes back he verifies the confirmed balance. # When he comes back he verifies the confirmed balance.
result = yield self.daemon.jsonrpc_account_balance() result = yield self.daemon.jsonrpc_account_balance()
self.assertEqual(round(result, 2), 7.97) self.assertEqual(result, Decimal('7.969786'))
# As people start reading his story they discover some typos and notify # As people start reading his story they discover some typos and notify
# Chris who explains in despair "Oh! Noooooos!" but then remembers # Chris who explains in despair "Oh! Noooooos!" but then remembers