diff --git a/src/accounts/accountManager.ts b/src/accounts/accountManager.ts index 28f4e5f..e2e95c8 100644 --- a/src/accounts/accountManager.ts +++ b/src/accounts/accountManager.ts @@ -59,12 +59,10 @@ export class AccountManager { if (!account.name) throw new Error('Missing account name.'); if (!account.publicKey) throw new Error('Missing public key.'); if (!account.privateKey) throw new Error('Missing private key.'); + // Configure the Signature Provider if available - if (EOSManager.signatureProvider) { - const nonLegacyPublicKey = convertLegacyPublicKey(account.publicKey); - EOSManager.signatureProvider.keys.set(nonLegacyPublicKey, account.privateKey); - EOSManager.signatureProvider.availableKeys.push(nonLegacyPublicKey); - } + EOSManager.addSigningAccountIfMissing(account); + // Get the system contract const systemContract = await eos.getContract('eosio'); // Build account creation actions diff --git a/src/configManager.ts b/src/configManager.ts index 9d22c4d..4f27151 100644 --- a/src/configManager.ts +++ b/src/configManager.ts @@ -133,7 +133,7 @@ export class ConfigManager { * @author Kevin Brown */ static get eos() { - return ConfigManager.config.eos; + return (ConfigManager.config && ConfigManager.config.eos) || ''; } /** @@ -141,7 +141,7 @@ export class ConfigManager { * @author Kevin Brown */ static get cdt() { - return ConfigManager.config.cdt; + return (ConfigManager.config && ConfigManager.config.cdt) || ''; } /** @@ -149,7 +149,7 @@ export class ConfigManager { * @author Mitch Pierias */ static get keepAlive() { - return ConfigManager.config.keepAlive || DEFAULT_CONFIG.keepAlive; + return (ConfigManager.config && ConfigManager.config.keepAlive) || DEFAULT_CONFIG.keepAlive; } /** @@ -157,7 +157,11 @@ export class ConfigManager { * @author Kevin Brown */ static get debugTransactions() { - return ConfigManager.config.debugTransactions || DEFAULT_CONFIG.debugTransactions; + return true; + return ( + (ConfigManager.config && ConfigManager.config.debugTransactions) || + DEFAULT_CONFIG.debugTransactions + ); } /** @@ -165,7 +169,7 @@ export class ConfigManager { * @author Mitch Pierias */ static get outDir() { - return ConfigManager.config.outDir || DEFAULT_CONFIG.outDir; + return (ConfigManager.config && ConfigManager.config.outDir) || DEFAULT_CONFIG.outDir; } /** @@ -173,6 +177,6 @@ export class ConfigManager { * @author Mitch Pierias */ static get exclude() { - return ConfigManager.config.exclude || DEFAULT_CONFIG.exclude; + return (ConfigManager.config && ConfigManager.config.exclude) || DEFAULT_CONFIG.exclude; } } diff --git a/src/contracts/contractDeployer.ts b/src/contracts/contractDeployer.ts index 2bc24e4..14e71b1 100644 --- a/src/contracts/contractDeployer.ts +++ b/src/contracts/contractDeployer.ts @@ -35,6 +35,8 @@ export class ContractDeployer { contractIdentifier: string, account: Account ) { + EOSManager.addSigningAccountIfMissing(account); + // Initialize the serialization buffer const buffer = new Serialize.SerialBuffer({ textEncoder: EOSManager.api.textEncoder, diff --git a/src/eosManager.ts b/src/eosManager.ts index b34675a..2ec6ab7 100644 --- a/src/eosManager.ts +++ b/src/eosManager.ts @@ -4,6 +4,7 @@ import { Api, JsonRpc } from 'eosjs'; import { JsSignatureProvider } from 'eosjs/dist/eosjs-jssig'; import { Account } from './accounts'; import { ConfigManager } from './configManager'; +import { convertLegacyPublicKey } from 'eosjs/dist/eosjs-numeric'; interface InitArgs { adminAccount: Account; @@ -68,6 +69,26 @@ export class EOSManager { }); }; + /** + * Ensures our signature provider has the key in question, and if not, adds it. + * @author Kevin Brown + * @param account Account to be unioned into the signature list. + */ + static addSigningAccountIfMissing = (account: Account) => { + if (!account.publicKey || !account.privateKey) { + throw new Error( + `Provided account ${account.name} is missing a key and cannot be used for signing.` + ); + } + + // If the signature provider doesn't have it + if (!EOSManager.signatureProvider.keys.get(account.publicKey)) { + const nonLegacyPublicKey = convertLegacyPublicKey(account.publicKey); + EOSManager.signatureProvider.keys.set(nonLegacyPublicKey, account.privateKey); + EOSManager.signatureProvider.availableKeys.push(nonLegacyPublicKey); + } + }; + /** * Executes a transaction against a connected EOSjs client * @author Kevin Brown @@ -78,7 +99,7 @@ export class EOSManager { static transact = ( transaction: any, eos = EOSManager.api, - options = { blocksBehind: 3, expireSeconds: 30 } + options = { blocksBehind: 3, expireSeconds: 30, sign: true, broadcast: true } ) => { if (ConfigManager.debugTransactions) { const calls = transaction.actions.map((action: any) => `${action.account}.${action.name}`);