From e4429242aacb9c7e6de68e3fe8d9e18854d21c42 Mon Sep 17 00:00:00 2001 From: nelisky Date: Tue, 3 Mar 2015 23:36:51 +0000 Subject: [PATCH 1/2] Allow insight_tx to be passed a dict object instead of an url --- trezorlib/tx_api.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/trezorlib/tx_api.py b/trezorlib/tx_api.py index 5816411..62a7867 100644 --- a/trezorlib/tx_api.py +++ b/trezorlib/tx_api.py @@ -52,12 +52,15 @@ def opcode_serialize(opcode): except: raise Exception('Unknown script opcode: %s' % opcode) -def insight_tx(url): - try: - f = urllib2.urlopen(url) - except: - raise Exception('URL error: %s' % url) - data = json.load(f) +def insight_tx(url, rawdata=False): + if not rawdata: + try: + f = urllib2.urlopen(url) + data = json.load(f) + except: + raise Exception('URL error: %s' % url) + else: + data = url t = proto_types.TransactionType() t.version = data['version'] From f3b7629a4fad2ed96ae0cb434d54d3cc087d42bd Mon Sep 17 00:00:00 2001 From: nelisky Date: Tue, 3 Mar 2015 23:37:32 +0000 Subject: [PATCH 2/2] Prevent floating point issues when pushing output amount --- trezorlib/tx_api.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/trezorlib/tx_api.py b/trezorlib/tx_api.py index 62a7867..94214f0 100644 --- a/trezorlib/tx_api.py +++ b/trezorlib/tx_api.py @@ -84,7 +84,7 @@ def insight_tx(url, rawdata=False): for vout in data['vout']: o = t.bin_outputs.add() - o.amount = int(Decimal(vout['value']) * 100000000) + o.amount = int(Decimal(str(vout['value'])) * 100000000) asm = vout['scriptPubKey']['asm'].split(' ') asm = [ opcode_serialize(x) for x in asm ] o.script_pubkey = ''.join(asm)