Skip to content

Commit 637d2dd

Browse files
committed
Merge petertodd#268: Update getrawtransaction to work with block hash argument
af9e5c4 Update getrawtransaction to work with block hash argument (kafka2000) Pull request description: The current implementation of getrawtransaction doesn't allow to provide the block hash. This PR is meant to fill this gap. Top commit has no ACKs. Tree-SHA512: 28af9c5304f0a087931e3a271544d7d7f6f8c0283a4af9b5b908406b2293b44f84c39508659ba9d96e42a6ebcd3b082df05880d3f31d5771fd87f701902fc13a
2 parents 8097203 + af9e5c4 commit 637d2dd

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)