genesis_util: Implement some more genesis utilities
This commit is contained in:
parent
44b2198f97
commit
f8b8f01a78
4 changed files with 145 additions and 0 deletions
|
|
@ -27,3 +27,8 @@ install( TARGETS
|
|||
LIBRARY DESTINATION lib
|
||||
ARCHIVE DESTINATION lib
|
||||
)
|
||||
|
||||
add_executable( convert_address convert_address.cpp )
|
||||
|
||||
target_link_libraries( convert_address
|
||||
PRIVATE graphene_chain fc ${CMAKE_DL_LIBS} ${PLATFORM_SPECIFIC_LIBS} )
|
||||
|
|
|
|||
52
programs/genesis_util/change_asset_symbol.py
Normal file
52
programs/genesis_util/change_asset_symbol.py
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
#!/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="Change an asset's symbol with referential integrity")
|
||||
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("-f", "--from", metavar="PREFIX", default="", help="initial prefix")
|
||||
parser.add_argument("-t", "--to", metavar="PREFIX", default="", help="new prefix")
|
||||
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)
|
||||
|
||||
frum = opts.__dict__["from"] # from is a language keyword and cannot be an attribute name
|
||||
|
||||
for asset in genesis["initial_assets"]:
|
||||
if asset["symbol"] == frum:
|
||||
asset["symbol"] = opts.to
|
||||
|
||||
for balance in genesis["initial_balances"]:
|
||||
if balance["asset_symbol"] == frum:
|
||||
balance["asset_symbol"] = opts.to
|
||||
|
||||
for vb in genesis["initial_vesting_balances"]:
|
||||
if balance["asset_symbol"] == frum:
|
||||
balance["asset_symbol"] = opts.to
|
||||
|
||||
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()
|
||||
23
programs/genesis_util/convert_address.cpp
Normal file
23
programs/genesis_util/convert_address.cpp
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
|
||||
/**
|
||||
* Convert BTC / PTS addresses to a Graphene address.
|
||||
*/
|
||||
|
||||
#include <graphene/chain/pts_address.hpp>
|
||||
#include <graphene/chain/protocol/address.hpp>
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
using namespace graphene::chain;
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
// grab 0 or more whitespace-delimited PTS addresses from stdin
|
||||
std::string s;
|
||||
while( std::cin >> s )
|
||||
{
|
||||
std::cout << std::string( address( pts_address( s ) ) ) << std::endl;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
65
programs/genesis_util/generate_account_patch.py
Executable file
65
programs/genesis_util/generate_account_patch.py
Executable file
|
|
@ -0,0 +1,65 @@
|
|||
#!/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="Generate a patch file that adds init accounts")
|
||||
parser.add_argument("-o", "--output", metavar="OUT", default="-", help="output filename (default: stdout)")
|
||||
parser.add_argument("-a", "--accounts", metavar="ACCOUNTS", default="-", help="file containing name, balances to create")
|
||||
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)
|
||||
|
||||
with open(opts.accounts, "r") as f:
|
||||
accounts = json.load(f)
|
||||
|
||||
initial_accounts = []
|
||||
initial_balances = []
|
||||
for e in accounts:
|
||||
name = e["name"]
|
||||
owner_str = subprocess.check_output(["programs/genesis_util/get_dev_key", opts.secret, "owner-"+name]).decode("utf-8")
|
||||
active_str = subprocess.check_output(["programs/genesis_util/get_dev_key", opts.secret, "active-"+name]).decode("utf-8")
|
||||
owner = json.loads(owner_str)
|
||||
active = json.loads(active_str)
|
||||
initial_accounts.append({
|
||||
"name" : name,
|
||||
"owner_key" : owner[0]["public_key"],
|
||||
"active_key" : active[0]["public_key"],
|
||||
"is_lifetime_member" : True,
|
||||
})
|
||||
for bal in e.get("balances", []):
|
||||
bal = dict(bal)
|
||||
bal["owner"] = active[0]["address"]
|
||||
initial_balances.append(bal)
|
||||
result = {
|
||||
"append" : {
|
||||
"initial_accounts" : initial_accounts },
|
||||
}
|
||||
if len(initial_balances) > 0:
|
||||
result["append"]["initial_balances"] = initial_balances
|
||||
|
||||
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