Skip to content

Commit

Permalink
infra: Add script for syncing headers
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexITC committed Apr 14, 2019
1 parent 62a313b commit 28c8c71
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions infra/misc/sync_headers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/python
#
# Traverses all headers for a single coin.

import requests
import sys

base_url = 'https://xsnexplorer.io/api'

def get_next(coin, last_seen_hash = ''):
url = base_url + '/' + coin + '/blocks/headers?limit=1000'
if last_seen_hash != '':
url = url + '&lastSeenHash=' + last_seen_hash
return requests.get(url).json()

def get_all(coin, trace = '', last_seen_hash = ''):
print('getting from ' + trace)
data = get_next(coin, last_seen_hash)['data']
if len(data) == 0:
print('done\n')
else:
get_all(coin, str(data[-1]['height']), data[-1]['hash'])

if __name__ == "__main__":
sys.setrecursionlimit(999999999)
get_all('ltc', '0')

0 comments on commit 28c8c71

Please sign in to comment.