| Date: Tue, 3 Jul 2018 13:51:54 +0100
Implement protocol method blockchain.block.headers
Diffstat:
M server.py | 50 +++++++++++++++++++------------
1 file changed, 31 insertions(+), 19 deletions(-)
--- |
| t@@ -171,6 +171,14 @@ def handle_query(sock, line, rpc, txmonitor):
error = {"message": "height " + str(height) + " out of range",
"code": -1}
send_error(sock, query["id"], error)
+ elif method == "blockchain.block.headers":
+ MAX_CHUNK_SIZE = 2016
+ start_height = query["params"][0]
+ count = query["params"][1]
+ count = min(count, MAX_CHUNK_SIZE)
+ headers_hex, n = get_block_headers_hex(rpc, start_height, count)
+ send_response(sock, query, {'hex': headers_hex, 'count': n, 'max':
+ MAX_CHUNK_SIZE})
elif method == "blockchain.block.get_chunk":
RETARGET_INTERVAL = 2016
index = query["params"][0]
t@@ -179,25 +187,8 @@ def handle_query(sock, line, rpc, txmonitor):
next_height = tip_height + 1
start_height = min(index*RETARGET_INTERVAL, next_height)
count = min(next_height - start_height, RETARGET_INTERVAL)
- #read count number of headers starting from start_height
- result = bytearray()
- the_hash = rpc.call("getblockhash", [start_height])
- for i in range(count):
- header = rpc.call("getblockheader", [the_hash])
- #add header hex to result
- if "previousblockhash" in header:
- prevblockhash = header["previousblockhash"]
- else:
- prevblockhash = "00"*32 #genesis block
- h1 = struct.pack(" |