handle decimal encoded string output from lbryum
This commit is contained in:
parent
371591f96e
commit
8c61185387
2 changed files with 23 additions and 18 deletions
|
@ -635,7 +635,7 @@ class Wallet(object):
|
||||||
|
|
||||||
if my_claim:
|
if my_claim:
|
||||||
log.info("Updating claim")
|
log.info("Updating claim")
|
||||||
if self.get_balance() < bid - my_claim['amount']:
|
if self.get_balance() < bid - Decimal(my_claim['amount']):
|
||||||
raise InsufficientFundsError()
|
raise InsufficientFundsError()
|
||||||
new_metadata = yield self.update_metadata(_metadata, my_claim['value'])
|
new_metadata = yield self.update_metadata(_metadata, my_claim['value'])
|
||||||
old_claim_outpoint = ClaimOutpoint(my_claim['txid'], my_claim['nout'])
|
old_claim_outpoint = ClaimOutpoint(my_claim['txid'], my_claim['nout'])
|
||||||
|
|
|
@ -8,7 +8,6 @@ import requests
|
||||||
import urllib
|
import urllib
|
||||||
import simplejson as json
|
import simplejson as json
|
||||||
from requests import exceptions as requests_exceptions
|
from requests import exceptions as requests_exceptions
|
||||||
from decimal import Decimal
|
|
||||||
import random
|
import random
|
||||||
|
|
||||||
from twisted.web import server
|
from twisted.web import server
|
||||||
|
@ -1492,15 +1491,8 @@ class Daemon(AuthJSONRPCServer):
|
||||||
txid, amount, value, n, height
|
txid, amount, value, n, height
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def _convert_amount_to_float(r):
|
|
||||||
if not r:
|
|
||||||
return False
|
|
||||||
else:
|
|
||||||
r['amount'] = float(r['amount']) / 10 ** 8
|
|
||||||
return r
|
|
||||||
|
|
||||||
d = self.session.wallet.get_claim_info(name, txid, nout)
|
d = self.session.wallet.get_claim_info(name, txid, nout)
|
||||||
d.addCallback(_convert_amount_to_float)
|
d.addCallback(format_json_out_amount_as_float)
|
||||||
d.addCallback(lambda r: self._render_response(r))
|
d.addCallback(lambda r: self._render_response(r))
|
||||||
return d
|
return d
|
||||||
|
|
||||||
|
@ -1826,15 +1818,8 @@ class Daemon(AuthJSONRPCServer):
|
||||||
list of name claims
|
list of name claims
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def _clean(claims):
|
|
||||||
for c in claims:
|
|
||||||
for k in c.keys():
|
|
||||||
if isinstance(c[k], Decimal):
|
|
||||||
c[k] = float(c[k])
|
|
||||||
return defer.succeed(claims)
|
|
||||||
|
|
||||||
d = self.session.wallet.get_name_claims()
|
d = self.session.wallet.get_name_claims()
|
||||||
d.addCallback(_clean)
|
d.addCallback(format_json_out_amount_as_float)
|
||||||
d.addCallback(lambda claims: self._render_response(claims))
|
d.addCallback(lambda claims: self._render_response(claims))
|
||||||
return d
|
return d
|
||||||
|
|
||||||
|
@ -1861,6 +1846,7 @@ class Daemon(AuthJSONRPCServer):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
d = self.session.wallet.get_claims_for_name(name)
|
d = self.session.wallet.get_claims_for_name(name)
|
||||||
|
d.addCallback(format_json_out_amount_as_float)
|
||||||
d.addCallback(lambda r: self._render_response(r))
|
d.addCallback(lambda r: self._render_response(r))
|
||||||
return d
|
return d
|
||||||
|
|
||||||
|
@ -2562,3 +2548,22 @@ def get_version_from_tag(tag):
|
||||||
return match.group(1)
|
return match.group(1)
|
||||||
else:
|
else:
|
||||||
raise Exception('Failed to parse version from tag {}'.format(tag))
|
raise Exception('Failed to parse version from tag {}'.format(tag))
|
||||||
|
|
||||||
|
|
||||||
|
# lbryum returns json loadeable object with amounts as decimal encoded string,
|
||||||
|
# convert them into floats for the daemon
|
||||||
|
# TODO: daemon should also use decimal encoded string
|
||||||
|
def format_json_out_amount_as_float(obj):
|
||||||
|
if isinstance(obj, dict):
|
||||||
|
for k, v in obj.iteritems():
|
||||||
|
if k == 'amount' or k == 'effective_amount':
|
||||||
|
obj[k] = float(obj[k])
|
||||||
|
if isinstance(v, dict) or isinstance(v, list):
|
||||||
|
obj[k] = format_json_out_amount_as_float(v)
|
||||||
|
|
||||||
|
elif isinstance(obj, list):
|
||||||
|
obj = [format_json_out_amount_as_float(o) for o in obj]
|
||||||
|
return obj
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue