Implement new genesis_util's
This commit is contained in:
parent
b325805878
commit
7c4824b1aa
3 changed files with 131 additions and 0 deletions
49
programs/genesis_util/apply_patch.py
Executable file
49
programs/genesis_util/apply_patch.py
Executable file
|
|
@ -0,0 +1,49 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
import argparse
|
||||
import json
|
||||
import sys
|
||||
|
||||
def dump_json(obj, out, pretty):
|
||||
if pretty:
|
||||
json.dump(obj, out, indent=2, sort_keys=True)
|
||||
else:
|
||||
json.dump(obj, out, separators=(",", ":"), sort_keys=True)
|
||||
return
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description="Remove entities from snapshot")
|
||||
parser.add_argument("-o", "--output", metavar="OUT", default="-", help="output filename (default: stdout)")
|
||||
parser.add_argument("-i", "--input", metavar="IN", default="-", help="input filename (default: stdin)")
|
||||
parser.add_argument("-d", "--delta", metavar="DELTA", nargs="+", help="list of delta file(s) to apply")
|
||||
parser.add_argument("-p", "--pretty", action="store_true", default=False, help="pretty print output")
|
||||
opts = parser.parse_args()
|
||||
|
||||
if opts.input == "-":
|
||||
genesis = json.load(sys.stdin)
|
||||
else:
|
||||
with open(opts.input, "r") as f:
|
||||
genesis = json.load(f)
|
||||
|
||||
if opts.delta is None:
|
||||
opts.delta = []
|
||||
for filename in opts.delta:
|
||||
with open(filename, "r") as f:
|
||||
patch = json.load(f)
|
||||
for k, v in patch.get("append", {}).items():
|
||||
genesis[k].extend(v)
|
||||
print("appended {n} items to {k}".format(n=len(v), k=k))
|
||||
for k, v in patch.get("replace", {}).items():
|
||||
genesis[k] = v
|
||||
print("replaced item {k}".format(k=k))
|
||||
|
||||
if opts.output == "-":
|
||||
dump_json( genesis, sys.stdout, opts.pretty )
|
||||
sys.stdout.flush()
|
||||
else:
|
||||
with open(opts.output, "w") as f:
|
||||
dump_json( genesis, f, opts.pretty )
|
||||
return
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
14
programs/genesis_util/canonical_format.py
Executable file
14
programs/genesis_util/canonical_format.py
Executable file
|
|
@ -0,0 +1,14 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
import argparse
|
||||
import json
|
||||
import sys
|
||||
|
||||
if len(sys.argv) < 3:
|
||||
print("syntax: "+sys.argv[0]+" INFILE OUTFILE")
|
||||
sys.exit(0)
|
||||
|
||||
with open(sys.argv[1], "r") as infile:
|
||||
genesis = json.load(infile)
|
||||
with open(sys.argv[2], "w") as outfile:
|
||||
json.dump(genesis, outfile, separators=(',', ':'), sort_keys=True)
|
||||
68
programs/genesis_util/generate_init_patch.py
Executable file
68
programs/genesis_util/generate_init_patch.py
Executable file
|
|
@ -0,0 +1,68 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
import argparse
|
||||
import json
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
def dump_json(obj, out, pretty):
|
||||
if pretty:
|
||||
json.dump(obj, out, indent=2, sort_keys=True)
|
||||
else:
|
||||
json.dump(obj, out, separators=(",", ":"), sort_keys=True)
|
||||
return
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description="Remove entities from snapshot")
|
||||
parser.add_argument("-o", "--output", metavar="OUT", default="-", help="output filename (default: stdout)")
|
||||
parser.add_argument("-n", "--num", metavar="N", default=11, type=int, help="number of init witnesses")
|
||||
parser.add_argument("-p", "--pretty", action="store_true", default=False, help="pretty print output")
|
||||
parser.add_argument("-s", "--secret", metavar="SECRET", default=None, help="private key generation secret")
|
||||
opts = parser.parse_args()
|
||||
|
||||
if opts.secret is None:
|
||||
sys.stderr.write("missing required parameter --secret\n")
|
||||
sys.stderr.flush()
|
||||
sys.exit(1)
|
||||
|
||||
wit_accounts = []
|
||||
wit_wits = []
|
||||
|
||||
for i in range(opts.num):
|
||||
owner_str = subprocess.check_output(["programs/genesis_util/get_dev_key", opts.secret, "wit-owner-"+str(i)]).decode("utf-8")
|
||||
active_str = subprocess.check_output(["programs/genesis_util/get_dev_key", opts.secret, "wit-active-"+str(i)]).decode("utf-8")
|
||||
prod_str = subprocess.check_output(["programs/genesis_util/get_dev_key", opts.secret, "wit-block-signing-"+str(i)]).decode("utf-8")
|
||||
owner = json.loads(owner_str)
|
||||
active = json.loads(active_str)
|
||||
prod = json.loads(prod_str)
|
||||
wit_accounts.append({
|
||||
"name" : "init"+str(i),
|
||||
"owner_key" : owner[0]["public_key"],
|
||||
"active_key" : active[0]["public_key"],
|
||||
"is_lifetime_member" : True,
|
||||
})
|
||||
wit_wits.append({
|
||||
"owner_name" : "init"+str(i),
|
||||
"block_signing_key" : prod[0]["public_key"],
|
||||
})
|
||||
|
||||
result = {
|
||||
"append" : {
|
||||
"initial_accounts" : wit_accounts },
|
||||
"replace" : {
|
||||
"initial_workers" : [],
|
||||
"initial_witnesses" : wit_wits,
|
||||
}
|
||||
}
|
||||
|
||||
if opts.output == "-":
|
||||
dump_json( result, sys.stdout, opts.pretty )
|
||||
sys.stdout.flush()
|
||||
else:
|
||||
with open(opts.output, "w") as f:
|
||||
dump_json( result, f, opts.pretty )
|
||||
|
||||
return
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Loading…
Reference in a new issue