add command exportcp to export checkpoints
Also exported additional 17 headers on last checkpoint to provide data for get_target blockchain method
This commit is contained in:
parent
4aea667280
commit
d06e6aa67e
|
@ -437,5 +437,22 @@ class Blockchain(util.PrintError):
|
|||
height = (index + 1) * CHUNK_LEN - 1
|
||||
h = self.get_hash(height)
|
||||
target = self.get_target(height)
|
||||
cp.append((h, target))
|
||||
if len(h.strip('0')) == 0:
|
||||
raise Exception('%s file has not enough data.' % self.path())
|
||||
if index < n - 1:
|
||||
cp.append((h, target))
|
||||
else:
|
||||
dgw3_headers = []
|
||||
if os.path.exists(self.path()):
|
||||
with open(self.path(), 'rb') as f:
|
||||
lower_header = height - POW_AVERAGING_WINDOW
|
||||
for height in range(height, lower_header-1, -1):
|
||||
f.seek(height*80)
|
||||
hd = f.read(80)
|
||||
if len(hd) < 80:
|
||||
raise Exception(
|
||||
'Expected to read a full header.'
|
||||
' This was only {} bytes'.format(len(hd)))
|
||||
dgw3_headers.append((height, bh2u(hd)))
|
||||
cp.append((h, target, dgw3_headers))
|
||||
return cp
|
||||
|
|
|
@ -658,6 +658,15 @@ class Commands:
|
|||
to config settings (static/dynamic)"""
|
||||
return self.config.fee_per_kb()
|
||||
|
||||
@command('n')
|
||||
def exportcp(self, cpfile):
|
||||
"""Export checkpoints to file"""
|
||||
try:
|
||||
self.network.export_checkpoints(cpfile)
|
||||
return 'Exporting checkpoints done'
|
||||
except Exception as e:
|
||||
return 'Error exporting checkpoints: ' + str(e)
|
||||
|
||||
@command('')
|
||||
def help(self):
|
||||
# for the python console
|
||||
|
@ -680,6 +689,7 @@ param_descriptions = {
|
|||
'requested_amount': 'Requested amount (in ZEC).',
|
||||
'outputs': 'list of ["address", amount]',
|
||||
'redeem_script': 'redeem script (hexadecimal)',
|
||||
'cpfile': 'Checkpoints file',
|
||||
}
|
||||
|
||||
command_options = {
|
||||
|
|
Loading…
Reference in New Issue