Skip to content

Commit af9e5c4

Browse files
committed
Update getrawtransaction to work with block hash argument
1 parent 1b7795d commit af9e5c4

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

bitcoin/rpc.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -566,24 +566,30 @@ def getrawmempool(self, verbose=False):
566566
r = [lx(txid) for txid in r]
567567
return r
568568

569-
def getrawtransaction(self, txid, verbose=False):
569+
def getrawtransaction(self, txid, verbose=False, block_hash=None):
570570
"""Return transaction with hash txid
571571
572572
Raises IndexError if transaction not found.
573573
574574
verbose - If true a dict is returned instead with additional
575575
information on the transaction.
576576
577+
block_hash - Hash of the block containing the transaction
578+
(required when transaction not currently indexed by Bitcoin Core)
579+
577580
Note that if all txouts are spent and the transaction index is not
578581
enabled the transaction may not be available.
579582
"""
580583
try:
581-
r = self._call('getrawtransaction', b2lx(txid), 1 if verbose else 0)
584+
if block_hash is None:
585+
r = self._call('getrawtransaction', b2lx(txid), 1 if verbose else 0)
586+
else:
587+
r = self._call('getrawtransaction', b2lx(txid), 1 if verbose else 0, b2lx(block_hash))
582588
except InvalidAddressOrKeyError as ex:
583589
raise IndexError('%s.getrawtransaction(): %s (%d)' %
584590
(self.__class__.__name__, ex.error['message'], ex.error['code']))
585591
if verbose:
586-
r['tx'] = CTransaction.deserialize(unhexlify_str(r['hex']))
592+
r['tx'] = CTransaction.deserialize(unhexlify(r['hex']))
587593
del r['hex']
588594
del r['txid']
589595
del r['version']
@@ -592,8 +598,7 @@ def getrawtransaction(self, txid, verbose=False):
592598
del r['vout']
593599
r['blockhash'] = lx(r['blockhash']) if 'blockhash' in r else None
594600
else:
595-
r = CTransaction.deserialize(unhexlify_str(r))
596-
601+
r = CTransaction.deserialize(unhexlify(r))
597602
return r
598603

599604
def getreceivedbyaddress(self, addr, minconf=1):

0 commit comments

Comments
 (0)