URI: 
       tprotocol/blockchain.block.header: WIP cp_height. - obelisk - Electrum server using libbitcoin as its backend
  HTML git clone https://git.parazyd.org/obelisk
   DIR Log
   DIR Files
   DIR Refs
   DIR README
   DIR LICENSE
       ---
   DIR commit cab66a2fea98b07bcf9f30094c00d04047d740f3
   DIR parent 5ef73f51482298637aa7365a481503c5afba38fa
  HTML Author: parazyd <parazyd@dyne.org>
       Date:   Thu, 15 Apr 2021 21:09:07 +0200
       
       protocol/blockchain.block.header: WIP cp_height.
       
       The merkle proof calculation is broken and I need help with this.
       
       Diffstat:
         M obelisk/protocol.py                 |      17 ++++++++---------
         M tests/test_electrum_protocol.py     |      15 ++++++++-------
       
       2 files changed, 16 insertions(+), 16 deletions(-)
       ---
   DIR diff --git a/obelisk/protocol.py b/obelisk/protocol.py
       t@@ -241,23 +241,22 @@ class ElectrumProtocol(asyncio.Protocol):  # pylint: disable=R0904,R0902
                        return JsonRPCError.internalerror()
                    return {"result": safe_hexlify(header)}
        
       +        # TODO: Help needed
                cp_headers = []
       -        # headers up to and including cp_height
       -        for i in range(index, cp_height + 1):
       +        for i in range(index - 1, cp_height):
                    _ec, data = await self.bx.fetch_block_header(i)
                    if _ec and _ec != 0:
                        self.log.debug("Got error: %s", repr(_ec))
                        return JsonRPCError.internalerror()
                    cp_headers.append(data)
        
       -        # TODO: Review
       -        # TODO: Is index is 0 or last elem?
       -        branch, root = merkle_branch_and_root(cp_headers, 0)
       +        hashed = [double_sha256(i) for i in cp_headers]
       +        branch, root = merkle_branch_and_root(hashed, 1, length=len(cp_headers))
                return {
                    "result": {
       -                "branch": [safe_hexlify(i) for i in branch],
       -                "header": safe_hexlify(cp_headers[0]),
       -                "root": safe_hexlify(root),
       +                "branch": [hash_to_hex_str(i) for i in branch],
       +                "header": safe_hexlify(cp_headers[1]),
       +                "root": hash_to_hex_str(root),
                    }
                }
        
       t@@ -297,7 +296,7 @@ class ElectrumProtocol(asyncio.Protocol):  # pylint: disable=R0904,R0902
                }
        
                # The assumption is to fetch more headers if necessary.
       -        # TODO: Review
       +        # TODO: Review, help needed
                if cp_height > 0 and cp_height - start_height > count:
                    for i in range(cp_height - start_height):
                        _ec, data = await self.bx.fetch_block_header(start_height +
   DIR diff --git a/tests/test_electrum_protocol.py b/tests/test_electrum_protocol.py
       t@@ -79,10 +79,10 @@ async def test_blockchain_block_header(protocol, writer):
            # params = [123, 130]
            # expect = get_expect(method, params)
            # data = await protocol.blockchain_block_header(writer, {"params": params})
       -
       -    # assert data["result"]["header"] == expect["result"]["header"]
       -    # assert data["result"]["branch"] == expect["result"]["branch"]
       -    # assert data["result"]["root"] == expect["result"]["root"]
       +    # pprint(expect)
       +    # print()
       +    # pprint(data)
       +    # assert data["result"] == expect["result"]
        
        
        async def test_blockchain_block_headers(protocol, writer):
       t@@ -95,9 +95,10 @@ async def test_blockchain_block_headers(protocol, writer):
            # params = [123, 3, 127]
            # expect = get_expect(method, params)
            # data = await protocol.blockchain_block_headers(writer, {"params": params})
       -    # assert data["result"]["branch"] == expect["result"]["branch"]
       -    # assert data["result"]["root"] == expect["result"]["root"]
       -    # assert data["result"]["hex"] == expect["result"]["hex"]
       +    # pprint(expect)
       +    # print()
       +    # pprint(data)
       +    # assert data["result"] == expect["result"]
        
        
        async def test_blockchain_scripthash_get_balance(protocol, writer):