mirror of
https://github.com/ElementsProject/elements.git
synced 2026-08-17 13:07:54 +02:00
Adding script to generate element blocks
Move generate element blocks script to contri/elements-dev-tools/ Fixing bug with not specifying datadir for generate element blocks script Adding python docs, adding python env Fixing indents issue on comment
This commit is contained in:
parent
5e4868dded
commit
bb4e9bb149
1 changed files with 39 additions and 0 deletions
39
contrib/elements-devtools/generate_element_blocks.py
Normal file
39
contrib/elements-devtools/generate_element_blocks.py
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
import os
|
||||
import subprocess
|
||||
import json
|
||||
import argparse
|
||||
|
||||
def sign_block(datadir):
|
||||
"""
|
||||
Gets a new blocks hex, generates a signature for that block,
|
||||
then submits the signed block to the running elementsd
|
||||
"""
|
||||
bc=["./elements-cli", "-regtest"]
|
||||
if datadir is not None:
|
||||
bc.append("-datadir=" + datadir)
|
||||
new_block = subprocess.check_output(bc + ["getnewblockhex"]).strip('\n')
|
||||
blocksig = subprocess.check_output(bc + ["signblock", new_block]).strip('\n')
|
||||
signed_block = subprocess.check_output(bc + ["combineblocksigs", new_block, '["' + blocksig + '"]'])
|
||||
signed_block_json = json.loads(signed_block)
|
||||
signed_block_hex = signed_block_json['hex']
|
||||
subprocess.check_output(bc + ['submitblock', signed_block_hex])
|
||||
|
||||
def generate_n_blocks(n,datadir):
|
||||
"""
|
||||
Generates n blocks and places them into the given datadir
|
||||
"""
|
||||
for i in range(0,n):
|
||||
sign_block(datadir)
|
||||
|
||||
if __name__ == "__main__":
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('--num')
|
||||
parser.add_argument("--datadir")
|
||||
num_blocks=100
|
||||
args = vars(parser.parse_args())
|
||||
datadir = args['datadir']
|
||||
if args['num'] != None:
|
||||
num_blocks=int(args['num'])
|
||||
generate_n_blocks(num_blocks,datadir)
|
||||
Loading…
Add table
Add a link
Reference in a new issue