Skip to content

Commit

Permalink
Contracts deployed from supplied accounts are now backfilled into the…
Browse files Browse the repository at this point in the history
… JsSignatureProvider if they're not there already. Unified the way this happens to one method.
  • Loading branch information
thekevinbrown committed May 18, 2019
1 parent 6fae66a commit bca6519
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 12 deletions.
8 changes: 3 additions & 5 deletions src/accounts/accountManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 10 additions & 6 deletions src/configManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,46 +133,50 @@ export class ConfigManager {
* @author Kevin Brown <github.com/thekevinbrown>
*/
static get eos() {
return ConfigManager.config.eos;
return (ConfigManager.config && ConfigManager.config.eos) || '';
}

/**
* Returns the current EOSIO.CDT configuration
* @author Kevin Brown <github.com/thekevinbrown>
*/
static get cdt() {
return ConfigManager.config.cdt;
return (ConfigManager.config && ConfigManager.config.cdt) || '';
}

/**
* Returns the container keep alive setting or false
* @author Mitch Pierias <github.com/MitchPierias>
*/
static get keepAlive() {
return ConfigManager.config.keepAlive || DEFAULT_CONFIG.keepAlive;
return (ConfigManager.config && ConfigManager.config.keepAlive) || DEFAULT_CONFIG.keepAlive;
}

/**
* Returns the container keep alive setting or false
* @author Kevin Brown <github.com/thekevinbrown>
*/
static get debugTransactions() {
return ConfigManager.config.debugTransactions || DEFAULT_CONFIG.debugTransactions;
return true;
return (
(ConfigManager.config && ConfigManager.config.debugTransactions) ||
DEFAULT_CONFIG.debugTransactions
);
}

/**
* Returns the output build directory or [[CACHE_DIRECTORY]]
* @author Mitch Pierias <github.com/MitchPierias>
*/
static get outDir() {
return ConfigManager.config.outDir || DEFAULT_CONFIG.outDir;
return (ConfigManager.config && ConfigManager.config.outDir) || DEFAULT_CONFIG.outDir;
}

/**
* Returns the array of excluded strings or patterns
* @author Mitch Pierias <github.com/MitchPierias>
*/
static get exclude() {
return ConfigManager.config.exclude || DEFAULT_CONFIG.exclude;
return (ConfigManager.config && ConfigManager.config.exclude) || DEFAULT_CONFIG.exclude;
}
}
2 changes: 2 additions & 0 deletions src/contracts/contractDeployer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
23 changes: 22 additions & 1 deletion src/eosManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -68,6 +69,26 @@ export class EOSManager {
});
};

/**
* Ensures our signature provider has the key in question, and if not, adds it.
* @author Kevin Brown <github.com/thekevinbrown>
* @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 <github.com/thekevinbrown>
Expand All @@ -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}`);
Expand Down

0 comments on commit bca6519

Please sign in to comment.