Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to generate signer keys to file #1587

Merged
merged 1 commit into from
Oct 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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