obelisk

Electrum server using libbitcoin as its backend
git clone https://git.parazyd.org/obelisk
Log | Files | Refs | README | LICENSE

commit b5e4ed32fabaa3d57057f12114be7aaa22dc0124
parent b4ba13a19e7f5a9f57b537d0139f365a76b78147
Author: parazyd <parazyd@dyne.org>
Date:   Thu, 15 Apr 2021 23:35:15 +0200

protocol/blockchain.block.header: Inefficient implementation of cp_height.

Diffstat:
Mobelisk/protocol.py | 11++++++-----
Mtests/test_electrum_protocol.py | 11++++-------
2 files changed, 10 insertions(+), 12 deletions(-)

diff --git a/obelisk/protocol.py b/obelisk/protocol.py @@ -241,10 +241,11 @@ class ElectrumProtocol(asyncio.Protocol): # pylint: disable=R0904,R0902 return JsonRPCError.internalerror() return {"result": safe_hexlify(header)} - # TODO: Help needed - return JsonRPCError.invalidrequest() + # The following works, but is extremely inefficient. + # The best solution would be to figure something out in + # libbitcoin-server cp_headers = [] - for i in range(index - 1, cp_height): + for i in range(0, cp_height + 1): _ec, data = await self.bx.fetch_block_header(i) if _ec and _ec != 0: self.log.debug("Got error: %s", repr(_ec)) @@ -252,11 +253,11 @@ class ElectrumProtocol(asyncio.Protocol): # pylint: disable=R0904,R0902 cp_headers.append(data) hashed = [double_sha256(i) for i in cp_headers] - branch, root = merkle_branch_and_root(hashed, 1, length=len(cp_headers)) + branch, root = merkle_branch_and_root(hashed, index) return { "result": { "branch": [hash_to_hex_str(i) for i in branch], - "header": safe_hexlify(cp_headers[1]), + "header": safe_hexlify(cp_headers[index]), "root": hash_to_hex_str(root), } } diff --git a/tests/test_electrum_protocol.py b/tests/test_electrum_protocol.py @@ -76,13 +76,10 @@ async def test_blockchain_block_header(protocol, writer): data = await protocol.blockchain_block_header(writer, {"params": params}) assert data["result"] == expect["result"] - # params = [123, 130] - # expect = get_expect(method, params) - # data = await protocol.blockchain_block_header(writer, {"params": params}) - # pprint(expect) - # print() - # pprint(data) - # assert data["result"] == expect["result"] + params = [13, 25] + expect = get_expect(method, params) + data = await protocol.blockchain_block_header(writer, {"params": params}) + assert data["result"] == expect["result"] async def test_blockchain_block_headers(protocol, writer):