Skip to content

Commit

Permalink
Add option to generate signer keys to file (#1587)
Browse files Browse the repository at this point in the history
  • Loading branch information
bowenwang1996 authored Oct 28, 2019
1 parent 6e15c96 commit a98cc2b
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
8 changes: 8 additions & 0 deletions genesis-tools/keypair-generator/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,14 @@ fn main() {
println!("SK: {}", key);
println!("PK: {}", key.public_key());
println!();
if generate_config {
let account_id = account_id
.expect("Account id must be specified if --generate-config is used");
let key_file_name = format!("signer{}_key.json", i);
let mut path = home_dir.to_path_buf();
path.push(&key_file_name);
generate_key_to_file(account_id, key.clone(), path);
}

pks.push(key.public_key());
}
Expand Down
20 changes: 19 additions & 1 deletion scripts/nodelib.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,24 @@ def generate_validator_key(home, is_release, nodocker, image, account_id):
subprocess.check_output(['docker', 'run', '-v', '%s:/srv/keypair-generator' % home, '-it', image, 'keypair-generator', '--home=/srv/keypair-generator', '--generate-config', '--account-id=%s' % account_id, 'validator-key'])
print("Validator key generated")

def generate_signer_key(home, is_release, nodocker, image, account_id):
print("Generating signer keys...")
if nodocker:
cmd = ['./target/%s/keypair-generator' % ('release' if is_release else 'debug')]
cmd.extend(['--home', home])
cmd.extend(['--generate-config'])
cmd.extend(['--account-id', account_id])
cmd.extend(['signer-keys'])
try:
subprocess.call(cmd)
except KeyboardInterrupt:
print("\nStopping NEARCore.")
else:
subprocess.check_output(['docker', 'run', '-v', '%s:/srv/keypair-generator' % home, '-it', image, 'keypair-generator', '--home=/srv/keypair-generator', '--generate-config', '--account-id=%s' % account_id, 'signer-keys'])
print("Signer keys generated")


def initialize_keys(home, is_release, nodocker, image, account_id):
def initialize_keys(home, is_release, nodocker, image, account_id, generate_signer_keys):
if nodocker:
install_cargo()
compile_package('keypair-generator', is_release)
Expand All @@ -229,6 +245,8 @@ def initialize_keys(home, is_release, nodocker, image, account_id):
except subprocess.CalledProcessError as exc:
print("Failed to fetch docker containers: %s" % exc)
exit(1)
if generate_signer_keys:
generate_signer_key(home, is_release, nodocker, image, account_id)
generate_node_key(home, is_release, nodocker, image)
if account_id:
generate_validator_key(home, is_release, nodocker, image, account_id)
Expand Down
3 changes: 2 additions & 1 deletion scripts/start_stakewars.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
parser.add_argument('--verbose', action='store_true', help='If set, prints verbose logs')
parser.add_argument('--home', default=os.path.expanduser('~/.near/'), help='Home path for storing configs, keys and chain data (Default: ~/.near)')
parser.add_argument('--init', action='store_true', help='If set, initialize the home dir by generating validator key and node key')
parser.add_argument('--signer-keys', action='store_true', help='If set, generate signer keys for account specified')
parser.add_argument('--account-id', default='', help='If set, the account id will be used for running a validator')
parser.add_argument(
'--image', default='nearprotocol/nearcore:stakewars',
Expand All @@ -26,7 +27,7 @@

nodocker = args.nodocker or args.local
if args.init:
initialize_keys(args.home, not args.debug, nodocker, args.image, args.account_id)
initialize_keys(args.home, not args.debug, nodocker, args.image, args.account_id, args.signer_keys)
else:
print("****************************************************")
print("* Running NEAR validator node for Stake Wars *")
Expand Down

0 comments on commit a98cc2b

Please sign in to comment.