|
@ -25,6 +25,8 @@ class SessionBase(JSONSession): |
|
|
sessions. |
|
|
sessions. |
|
|
''' |
|
|
''' |
|
|
|
|
|
|
|
|
|
|
|
MAX_CHUNK_SIZE = 2016 |
|
|
|
|
|
|
|
|
def __init__(self, controller, kind): |
|
|
def __init__(self, controller, kind): |
|
|
# Force v2 as a temporary hack for old Coinomi wallets |
|
|
# Force v2 as a temporary hack for old Coinomi wallets |
|
|
# Remove in April 2017 |
|
|
# Remove in April 2017 |
|
@ -255,13 +257,17 @@ class ElectrumX(SessionBase): |
|
|
return self.env.server_features() |
|
|
return self.env.server_features() |
|
|
|
|
|
|
|
|
def block_headers(self, start_height, count): |
|
|
def block_headers(self, start_height, count): |
|
|
'''Return concatenated block headers as hex for the main chain; |
|
|
'''Return count concatenated block headers as hex for the main chain; |
|
|
count headers starting at start_height. |
|
|
starting at start_height. |
|
|
|
|
|
|
|
|
start_height and count must be non-negative integers.''' |
|
|
start_height and count must be non-negative integers. At most |
|
|
|
|
|
MAX_CHUNK_SIZE headers will be returned. |
|
|
|
|
|
''' |
|
|
start_height = self.controller.non_negative_integer(start_height) |
|
|
start_height = self.controller.non_negative_integer(start_height) |
|
|
count = self.controller.non_negative_integer(count) |
|
|
count = self.controller.non_negative_integer(count) |
|
|
return self.controller.block_headers(start_height, count).hex() |
|
|
count = min(count, self.MAX_CHUNK_SIZE) |
|
|
|
|
|
hex_str, n = self.controller.block_headers(start_height, count) |
|
|
|
|
|
return {'hex': hex_str, 'count': n, 'max': self.MAX_CHUNK_SIZE} |
|
|
|
|
|
|
|
|
def block_get_chunk(self, index): |
|
|
def block_get_chunk(self, index): |
|
|
'''Return a chunk of block headers as a hexadecimal string. |
|
|
'''Return a chunk of block headers as a hexadecimal string. |
|
@ -270,9 +276,8 @@ class ElectrumX(SessionBase): |
|
|
index = self.controller.non_negative_integer(index) |
|
|
index = self.controller.non_negative_integer(index) |
|
|
chunk_size = self.coin.CHUNK_SIZE |
|
|
chunk_size = self.coin.CHUNK_SIZE |
|
|
start_height = index * chunk_size |
|
|
start_height = index * chunk_size |
|
|
count = chunk_size |
|
|
hex_str, n = self.controller.block_headers(start_height, chunk_size) |
|
|
|
|
|
return hex_str |
|
|
return self.controller.block_headers(start_height, count).hex() |
|
|
|
|
|
|
|
|
|
|
|
def block_get_chunk(self, index): |
|
|
def block_get_chunk(self, index): |
|
|
'''Return a chunk of block headers as a hexadecimal string. |
|
|
'''Return a chunk of block headers as a hexadecimal string. |
|
@ -462,7 +467,9 @@ class ElectrumX(SessionBase): |
|
|
if ptuple >= (1, 2): |
|
|
if ptuple >= (1, 2): |
|
|
# New handler as of 1.2 |
|
|
# New handler as of 1.2 |
|
|
handlers.update({ |
|
|
handlers.update({ |
|
|
'mempool.get_fee_histogram': controller.mempool_get_fee_histogram, |
|
|
'mempool.get_fee_histogram': |
|
|
|
|
|
controller.mempool_get_fee_histogram, |
|
|
|
|
|
'blockchain.block.headers': self.block_headers, |
|
|
}) |
|
|
}) |
|
|
|
|
|
|
|
|
self.electrumx_handlers = handlers |
|
|
self.electrumx_handlers = handlers |
|
|