mirror of
https://github.com/alexgo-io/stacks-puppet-node.git
synced 2026-04-22 10:36:57 +08:00
use get_name_history_page for getting pages of a name's history. do not rely on start_block or end_block, since we have the power to paginate directly
This commit is contained in:
@@ -2680,7 +2680,7 @@ def get_name_history(name, hostport=None, proxy=None, history_page=None):
|
||||
|
||||
return {'status': True, 'history': resp['history'], 'indexing': indexing, 'lastblock': lastblock}
|
||||
|
||||
for i in range(0, 10000): # this is obviously too big
|
||||
for i in range(0, 100000000): # this is obviously too big
|
||||
resp = get_name_history_page(name, i, proxy=proxy)
|
||||
if 'error' in resp:
|
||||
return resp
|
||||
|
||||
@@ -490,7 +490,7 @@ class BlockstackAPIEndpointHandler(SimpleHTTPRequestHandler):
|
||||
status = 'revoked' if name_rec['revoked'] else 'registered'
|
||||
address = name_rec['address']
|
||||
if address:
|
||||
address = virtualchain.address_reencode(str(address), network='mainnet')
|
||||
address = virtualchain.address_reencode(str(address))
|
||||
|
||||
log.debug("{} is {}".format(name, status))
|
||||
ret = {
|
||||
@@ -509,10 +509,10 @@ class BlockstackAPIEndpointHandler(SimpleHTTPRequestHandler):
|
||||
return self._reply_json(ret)
|
||||
|
||||
|
||||
def GET_name_history(self, path_info, name ):
|
||||
def GET_name_history(self, path_info, name):
|
||||
"""
|
||||
Get the history of a name or subdomain.
|
||||
Takes `start_block` and `end_block` in the query string.
|
||||
Requires 'page' in the query string
|
||||
return the history on success
|
||||
return 400 on invalid start_block or end_block
|
||||
return 502 on failure to query blockstack server
|
||||
@@ -521,35 +521,27 @@ class BlockstackAPIEndpointHandler(SimpleHTTPRequestHandler):
|
||||
return self._reply_json({'error': 'Invalid name or subdomain'}, status_code=400)
|
||||
|
||||
qs_values = path_info['qs_values']
|
||||
start_block = qs_values.get('start_block', None)
|
||||
end_block = qs_values.get('end_block', None)
|
||||
page = qs_values.get('page', None)
|
||||
|
||||
if page is None:
|
||||
return self._reply_json({'error': 'Missing page argument'}, status_code=400)
|
||||
|
||||
try:
|
||||
if start_block is None:
|
||||
start_block = FIRST_BLOCK_MAINNET
|
||||
else:
|
||||
start_block = int(start_block)
|
||||
|
||||
if end_block is None:
|
||||
end_block = 2**32 # hope we never get this many blocks!
|
||||
else:
|
||||
end_block = int(end_block)
|
||||
assert len(page) < 10
|
||||
page = int(page)
|
||||
assert page >= 0
|
||||
assert page <= 2**32 - 1
|
||||
except:
|
||||
log.error("Invalid start_block or end_block")
|
||||
self._reply_json({'error': 'Invalid start_block or end_block'}, status_code=400)
|
||||
log.error("Invalid page")
|
||||
self._reply_json({'error': 'Invalid page'}, status_code=400)
|
||||
return
|
||||
|
||||
blockstackd_url = get_blockstackd_url()
|
||||
res = blockstackd_client.get_name_record(name, include_expired=True, include_history=True, hostport=blockstackd_url)
|
||||
res = blockstackd_client.get_name_history_page(name, page, hostport=blockstackd_url)
|
||||
if json_is_error(res):
|
||||
return self._reply_json({'error': res['error']}, status_code=res.get('http_status', 502))
|
||||
|
||||
history = {}
|
||||
for block_height in res['history'].keys():
|
||||
if int(block_height) >= start_block and int(block_height) <= end_block:
|
||||
history[block_height] = res['history'][block_height]
|
||||
|
||||
return self._reply_json(history)
|
||||
return self._reply_json(res['history'])
|
||||
|
||||
|
||||
def GET_name_zonefile( self, path_info, name ):
|
||||
|
||||
Reference in New Issue
Block a user