|
43 | 43 | import urlparse
|
44 | 44 |
|
45 | 45 | import bitcoin
|
46 |
| -from bitcoin.core import COIN, lx, b2lx, CBlock, CTransaction, COutPoint, CTxOut |
| 46 | +from bitcoin.core import COIN, lx, b2lx, CBlock, CBlockHeader, CTransaction, COutPoint, CTxOut |
47 | 47 | from bitcoin.core.script import CScript
|
48 | 48 | from bitcoin.wallet import CBitcoinAddress, CBitcoinSecret
|
49 | 49 |
|
@@ -350,6 +350,24 @@ def getbestblockhash(self):
|
350 | 350 | """Return hash of best (tip) block in longest block chain."""
|
351 | 351 | return lx(self._call('getbestblockhash'))
|
352 | 352 |
|
| 353 | + def getblockheader(self, block_hash): |
| 354 | + """Get block header <block_hash> |
| 355 | +
|
| 356 | + Raises IndexError if block_hash is not valid. |
| 357 | + """ |
| 358 | + try: |
| 359 | + block_hash = b2lx(block_hash) |
| 360 | + except TypeError: |
| 361 | + raise TypeError('%s.getblockheader(): block_hash must be bytes; got %r instance' % |
| 362 | + (self.__class__.__name__, block_hash.__class__)) |
| 363 | + try: |
| 364 | + r = self._call('getblockheader', block_hash, False) |
| 365 | + except JSONRPCError as ex: |
| 366 | + raise IndexError('%s.getblockheader(): %s (%d)' % |
| 367 | + (self.__class__.__name__, ex.error['message'], ex.error['code'])) |
| 368 | + return CBlockHeader.deserialize(unhexlify(r)) |
| 369 | + |
| 370 | + |
353 | 371 | def getblock(self, block_hash):
|
354 | 372 | """Get block <block_hash>
|
355 | 373 |
|
|
0 commit comments