Browse Source

add --deserialize option to gettransaction

283
ThomasV 10 years ago
parent
commit
53a3f00389
  1. 19
      lib/commands.py
  2. 2
      lib/transaction.py

19
lib/commands.py

@ -71,7 +71,7 @@ register_command('getaddressbalance', 1, 0, 0, [('address', 'Bitcoin address')]
register_command('getaddresshistory', 1, 0, 0, [('address', 'Bitcoin address')], [], 'Return the transaction history of a wallet address', '')
register_command('getconfig', 0, 0, 0, [('key', 'Variable name')], [], 'Return a configuration variable', '')
register_command('getpubkeys', 0, 1, 0, [('address', 'Bitcoin address')], [], 'Return the public keys for a wallet address', '')
register_command('getrawtx', 1, 0, 0, [('txid', 'Transaction ID')], [], 'Retrieve a transaction', '')
register_command('gettransaction', 1, 0, 0, [('txid', 'Transaction ID')], ['deserialize'], 'Retrieve a transaction', '')
register_command('getseed', 0, 1, 1, [], [], 'Get seed phrase', 'Print the generation seed of your wallet.')
register_command('getmpk', 0, 1, 0, [], [], 'Get Master Public Key', 'Return your wallet\'s master public key')
register_command('help', 0, 0, 0, [], [], 'Print help on a command.', '')
@ -132,6 +132,7 @@ command_options = {
'language': ("-L", "--lang", None, "Default language for wordlist"),
'gap_limit': ("-G", "--gap", None, "Gap limit"),
'mpk': (None, "--mpk", None, "Restore from master public key"),
'deserialize': ("-d", "--deserialize", False, "Deserialize transaction"),
}
@ -308,8 +309,7 @@ class Commands:
def decoderawtransaction(self, raw):
tx = Transaction(raw)
tx.deserialize()
return {'inputs':tx.inputs, 'outputs':tx.outputs}
return tx.deserialize()
def sendrawtransaction(self, raw):
tx = Transaction(raw)
@ -532,16 +532,15 @@ class Commands:
out.append(item)
return out
def getrawtransaction(self, tx_hash):
if self.wallet:
tx = self.wallet.transactions.get(tx_hash)
if tx:
return tx
def gettransaction(self, tx_hash, deserialize=False):
tx = self.wallet.transactions.get(tx_hash) if self.wallet else None
if tx is None and self.network:
raw = self.network.synchronous_get([('blockchain.transaction.get', [tx_hash])])[0]
if raw:
return Transaction(raw)
tx = Transaction(raw)
else:
return "unknown transaction"
raise BaseException("Unknown transaction")
return tx.deserialize() if deserialize else tx
def encrypt(self, pubkey, message):
return bitcoin.encrypt_message(message, pubkey)

2
lib/transaction.py

@ -494,6 +494,7 @@ class Transaction:
self.inputs = d['inputs']
self.outputs = [(x['type'], x['address'], x['value']) for x in d['outputs']]
self.locktime = d['lockTime']
return d
@classmethod
def from_io(klass, inputs, outputs, locktime=0):
@ -501,7 +502,6 @@ class Transaction:
self.inputs = inputs
self.outputs = outputs
self.locktime = locktime
#self.raw = self.serialize()
return self
@classmethod

Loading…
Cancel
Save