Get block Raises IndexError if block_hash is not valid.
(self, block_hash)
| 489 | |
| 490 | |
| 491 | def getblock(self, block_hash): |
| 492 | """Get block <block_hash> |
| 493 | |
| 494 | Raises IndexError if block_hash is not valid. |
| 495 | """ |
| 496 | try: |
| 497 | block_hash = b2lx(block_hash) |
| 498 | except TypeError: |
| 499 | raise TypeError('%s.getblock(): block_hash must be bytes; got %r instance' % |
| 500 | (self.__class__.__name__, block_hash.__class__)) |
| 501 | try: |
| 502 | # With this change ( https://github.com/bitcoin/bitcoin/commit/96c850c20913b191cff9f66fedbb68812b1a41ea#diff-a0c8f511d90e83aa9b5857e819ced344 ), |
| 503 | # bitcoin core's rpc takes 0/1/2 instead of true/false as the 2nd argument which specifies verbosity, since v0.15.0. |
| 504 | # The change above is backward-compatible so far; the old "false" is taken as the new "0". |
| 505 | r = self._call('getblock', block_hash, False) |
| 506 | except InvalidAddressOrKeyError as ex: |
| 507 | raise IndexError('%s.getblock(): %s (%d)' % |
| 508 | (self.__class__.__name__, ex.error['message'], ex.error['code'])) |
| 509 | return CBlock.deserialize(unhexlify_str(r)) |
| 510 | |
| 511 | def getblockcount(self): |
| 512 | """Return the number of blocks in the longest block chain""" |
no test coverage detected