Browse Source

Minor tweaks.

patch-2
Neil Booth 7 years ago
parent
commit
c8c896a14c
  1. 9
      docs/protocol-changes.rst
  2. 5
      docs/protocol-methods.rst
  3. 10
      electrumx/server/session.py

9
docs/protocol-changes.rst

@ -127,16 +127,19 @@ This version removes all support for :ref:`deserialized headers
Changes Changes
------- -------
* The argument *raw* removed from :func:`blockchain.headers.subscribe`, * Deserialized headers are no longer available, so removed argument
only raw headers can be subscribed to. *raw* from :func:`blockchain.headers.subscribe`.
* Only the first :func:`server.version` message is accepted. * Only the first :func:`server.version` message is accepted.
* Optional *cp_height* argument added to * Optional *cp_height* argument added to
:func:`blockchain.block.header` and :func:`blockchain.block.headers` :func:`blockchain.block.header` and :func:`blockchain.block.headers`
to return merkle proofs of the header to a given checkpoint.
New methods New methods
----------- -----------
* :func:`blockchain.transaction.id_from_pos` * :func:`blockchain.transaction.id_from_pos` to return a transaction
hash, and optionally a merkle proof, given a block height and
position in the block.
Removed methods Removed methods
--------------- ---------------

5
docs/protocol-methods.rst

@ -679,12 +679,13 @@ given a block height and a position in the block.
**Signature** **Signature**
.. function:: blockchain.transaction.id_from_pos(height, tx_pos, merkle=False) .. function:: blockchain.transaction.id_from_pos(height, tx_pos,
merkle=False)
.. versionadded:: 1.4 .. versionadded:: 1.4
*height* *height*
A block height in the main chain, an integer. The main chain block height, a non-negative integer.
*tx_pos* *tx_pos*

10
electrumx/server/session.py

@ -1055,7 +1055,7 @@ class ElectrumX(SessionBase):
return await self.daemon_request('getrawtransaction', tx_hash, verbose) return await self.daemon_request('getrawtransaction', tx_hash, verbose)
async def block_hash_and_tx_hashes(self, height): async def _block_hash_and_tx_hashes(self, height):
'''Returns a pair (block_hash, tx_hashes) for the main chain block at '''Returns a pair (block_hash, tx_hashes) for the main chain block at
the given height. the given height.
@ -1080,14 +1080,14 @@ class ElectrumX(SessionBase):
return branch return branch
async def transaction_merkle(self, tx_hash, height): async def transaction_merkle(self, tx_hash, height):
'''Return the markle tree to a confirmed transaction given its hash '''Return the markle branch to a confirmed transaction given its hash
and height. and height.
tx_hash: the transaction hash as a hexadecimal string tx_hash: the transaction hash as a hexadecimal string
height: the height of the block it is in height: the height of the block it is in
''' '''
assert_tx_hash(tx_hash) assert_tx_hash(tx_hash)
block_hash, tx_hashes = await self.block_hash_and_tx_hashes(height) block_hash, tx_hashes = await self._block_hash_and_tx_hashes(height)
try: try:
pos = tx_hashes.index(tx_hash) pos = tx_hashes.index(tx_hash)
except ValueError: except ValueError:
@ -1104,15 +1104,15 @@ class ElectrumX(SessionBase):
if merkle not in (True, False): if merkle not in (True, False):
raise RPCError(BAD_REQUEST, f'"merkle" must be a boolean') raise RPCError(BAD_REQUEST, f'"merkle" must be a boolean')
block_hash, tx_hashes = await self.block_hash_and_tx_hashes(height) block_hash, tx_hashes = await self._block_hash_and_tx_hashes(height)
try: try:
tx_hash = tx_hashes[tx_pos] tx_hash = tx_hashes[tx_pos]
except IndexError: except IndexError:
raise RPCError(BAD_REQUEST, f'no tx at position {tx_pos:,d} in ' raise RPCError(BAD_REQUEST, f'no tx at position {tx_pos:,d} in '
f'block {block_hash} at height {height:,d}') f'block {block_hash} at height {height:,d}')
branch = self._get_merkle_branch(tx_hashes, tx_pos)
if merkle: if merkle:
branch = self._get_merkle_branch(tx_hashes, tx_pos)
return {"tx_hash": tx_hash, "merkle": branch} return {"tx_hash": tx_hash, "merkle": branch}
else: else:
return tx_hash return tx_hash

Loading…
Cancel
Save