custom json encoder for transactions
This commit is contained in:
parent
72d7d0b07a
commit
f957837e21
@ -115,12 +115,12 @@ class Commands:
|
|||||||
i['index'] = i['vout']
|
i['index'] = i['vout']
|
||||||
outputs = map(lambda x: (x[0],int(1e8*x[1])), outputs.items())
|
outputs = map(lambda x: (x[0],int(1e8*x[1])), outputs.items())
|
||||||
tx = Transaction.from_io(inputs, outputs)
|
tx = Transaction.from_io(inputs, outputs)
|
||||||
return tx.as_dict()
|
return tx
|
||||||
|
|
||||||
def signrawtransaction(self, raw_tx, input_info, private_keys):
|
def signrawtransaction(self, raw_tx, input_info, private_keys):
|
||||||
tx = Transaction(raw_tx)
|
tx = Transaction(raw_tx)
|
||||||
self.wallet.signrawtransaction(tx, input_info, private_keys, self.password)
|
self.wallet.signrawtransaction(tx, input_info, private_keys, self.password)
|
||||||
return tx.as_dict()
|
return tx
|
||||||
|
|
||||||
def decoderawtransaction(self, raw):
|
def decoderawtransaction(self, raw):
|
||||||
tx = Transaction(raw)
|
tx = Transaction(raw)
|
||||||
@ -251,7 +251,7 @@ class Commands:
|
|||||||
|
|
||||||
def mksendmanytx(self, outputs, fee = None, change_addr = None, domain = None):
|
def mksendmanytx(self, outputs, fee = None, change_addr = None, domain = None):
|
||||||
tx = self._mktx(outputs, fee, change_addr, domain)
|
tx = self._mktx(outputs, fee, change_addr, domain)
|
||||||
return tx.as_dict()
|
return tx
|
||||||
|
|
||||||
|
|
||||||
def payto(self, to_address, amount, fee = None, change_addr = None, domain = None):
|
def payto(self, to_address, amount, fee = None, change_addr = None, domain = None):
|
||||||
|
|||||||
@ -379,10 +379,6 @@ class Transaction:
|
|||||||
self.input_info = None
|
self.input_info = None
|
||||||
self.is_complete = True
|
self.is_complete = True
|
||||||
|
|
||||||
|
|
||||||
def __repr__(self):
|
|
||||||
return "Transaction('"+self.raw+"')"
|
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.raw
|
return self.raw
|
||||||
|
|
||||||
|
|||||||
13
lib/util.py
13
lib/util.py
@ -1,4 +1,4 @@
|
|||||||
import os, sys, re
|
import os, sys, re, json
|
||||||
import platform
|
import platform
|
||||||
import shutil
|
import shutil
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
@ -6,6 +6,14 @@ is_verbose = True
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class MyEncoder(json.JSONEncoder):
|
||||||
|
def default(self, obj):
|
||||||
|
from transaction import Transaction
|
||||||
|
if isinstance(obj, Transaction):
|
||||||
|
return obj.as_dict()
|
||||||
|
return super(MyEncoder, self).default(obj)
|
||||||
|
|
||||||
|
|
||||||
def set_verbosity(b):
|
def set_verbosity(b):
|
||||||
global is_verbose
|
global is_verbose
|
||||||
is_verbose = b
|
is_verbose = b
|
||||||
@ -23,9 +31,8 @@ def print_msg(*args):
|
|||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
|
|
||||||
def print_json(obj):
|
def print_json(obj):
|
||||||
import json
|
|
||||||
try:
|
try:
|
||||||
s = json.dumps(obj,sort_keys = True, indent = 4)
|
s = json.dumps(obj, sort_keys = True, indent = 4, cls=MyEncoder)
|
||||||
except TypeError:
|
except TypeError:
|
||||||
s = repr(obj)
|
s = repr(obj)
|
||||||
sys.stdout.write(s + "\n")
|
sys.stdout.write(s + "\n")
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user