Skip to content

Commit

Permalink
check for account existence first
Browse files Browse the repository at this point in the history
  • Loading branch information
mikedotexe authored and Mike Purvis committed Aug 18, 2020
1 parent c31b67a commit 1b08873
Showing 1 changed file with 7 additions and 12 deletions.
19 changes: 7 additions & 12 deletions commands/create-account.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,18 +112,6 @@ async function createAccount(options) {
keyPair = await KeyPair.fromRandom('ed25519');
publicKey = keyPair.getPublicKey();
}
if (keyPair) {
// keyFilePath = near.connection.signer.keyStore.getKeyFilePath(options.networkId, options.accountId);

if (near.connection.signer.keyStore.keyStores.length) {
keyRootPath = near.connection.signer.keyStore.keyStores[0].keyDir;
}
keyFilePath = `${keyRootPath}/${options.networkId}/${options.accountId}.json`;
await near.connection.signer.keyStore.setKey(options.networkId, options.accountId, keyPair);
await eventtracking.track(eventtracking.EVENT_ID_CREATE_ACCOUNT_END, { success: true, new_keypair: true }, options);
} else {
await eventtracking.track(eventtracking.EVENT_ID_CREATE_ACCOUNT_END, { success: true, new_keypair: false }, options);
}
// Check to see if account already exists
try {
// This is expected to error because the account shouldn't exist
Expand All @@ -134,6 +122,13 @@ async function createAccount(options) {
throw e;
}
}
if (keyPair) {
if (near.connection.signer.keyStore.keyStores.length) {
keyRootPath = near.connection.signer.keyStore.keyStores[0].keyDir;
}
keyFilePath = `${keyRootPath}/${options.networkId}/${options.accountId}.json`;
await near.connection.signer.keyStore.setKey(options.networkId, options.accountId, keyPair);
}
// Create account
console.log(`Saving key to '${keyFilePath}'`);
try {
Expand Down

0 comments on commit 1b08873

Please sign in to comment.