diff --git a/commands/create-account.js b/commands/create-account.js index fb5a0520..40606ee3 100644 --- a/commands/create-account.js +++ b/commands/create-account.js @@ -75,7 +75,7 @@ const createAccountCommandDeprecated = { async function createAccount(options) { // NOTE: initialBalance is passed as part of config here, parsed in middleware/initial-balance // periods are disallowed in top-level accounts and can only be used for subaccounts - checkCredentials(options); + await checkCredentials(options.masterAccount, options.networkId, options.keyStore); const splitAccount = options.accountId.split('.'); const splitMaster = options.masterAccount.split('.'); diff --git a/index.js b/index.js index cfb4fb94..bcbb55a1 100644 --- a/index.js +++ b/index.js @@ -210,7 +210,7 @@ exports.keys = async function (options) { }; exports.sendMoney = async function (options) { - checkCredentials(options); + await checkCredentials(options.sender, options.networkId, options.keyStore); console.log(`Sending ${options.amount} NEAR to ${options.receiver} from ${options.sender}`); const near = await connect(options); const account = await near.account(options.sender); diff --git a/utils/check-credentials.js b/utils/check-credentials.js index a1869b24..8b6b00c6 100644 --- a/utils/check-credentials.js +++ b/utils/check-credentials.js @@ -1,19 +1,23 @@ const homedir = require('os').homedir(); const credentials_dir = homedir + '/.near-credentials'; +const fs = require('fs').promises; +const { askYesNoQuestion } = require('./readline'); -module.exports = async function checkCredentials(options) { - if(!(await options.keyStore.getKey(options.networkId, options.accountId))) { - console.log(`Unable to find ${options.networkId} credentials for ${options.accountId}`); - const hasInDefault = await options.keyStore.getKey('default', options.accountId); +module.exports = async function checkCredentials(accountId, networkId, keyStore) { + console.log('networkId', networkId); + console.log('accountId', accountId); + if(!(await keyStore.getKey(networkId, accountId))) { + console.log(`Unable to find ${networkId} credentials for ${accountId}`); + const hasInDefault = await keyStore.getKey('default', accountId); if(hasInDefault) { const answer = await askYesNoQuestion('Key found in deprecated \'default\' folder. Would you like to move key to \'testnet\' folder? (y/n): ', false); if(answer) { console.log('Moving files...'); - await fs.copyFile(`${credentials_dir}/default/${option.accountId}`, `${credentials_dir}/testnet/${options.accountId}`) + await fs.copyFile(`${credentials_dir}/default/${accountId}.json`, `${credentials_dir}/testnet/${accountId}.json`) + throw ('Please run command again.') } else { - console.log('Please relocate credentials found in \'default\' directory to \'testnet\'.'); - return; + throw ('Please relocate credentials found in \'default\' directory to \'testnet\'.'); } - } + } else throw ('error') } } \ No newline at end of file