From 8831dfb0ee82ff191e2591b668cadb8916e235ed Mon Sep 17 00:00:00 2001 From: Jonathan Rainville Date: Wed, 7 Nov 2018 16:38:19 -0500 Subject: [PATCH] fix(contracts): replace $accounts for onDeploy too This was intended from the start, but was only done for args --- lib/modules/deployment/contract_deployer.js | 2 +- lib/modules/specialconfigs/index.js | 18 ++++++++++++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/lib/modules/deployment/contract_deployer.js b/lib/modules/deployment/contract_deployer.js index 78e112af6..a8b78a324 100644 --- a/lib/modules/deployment/contract_deployer.js +++ b/lib/modules/deployment/contract_deployer.js @@ -15,7 +15,7 @@ class ContractDeployer { } // TODO: determining the arguments could also be in a module since it's not - // part of ta 'normal' contract deployment + // part of a 'normal' contract deployment determineArguments(suppliedArgs, contract, accounts, callback) { const self = this; diff --git a/lib/modules/specialconfigs/index.js b/lib/modules/specialconfigs/index.js index d4eb465d7..eba90faf1 100644 --- a/lib/modules/specialconfigs/index.js +++ b/lib/modules/specialconfigs/index.js @@ -37,9 +37,23 @@ class SpecialConfigs { replaceWithAddresses(cmd, cb) { const self = this; - let regex = /\$\w+/g; - stringReplaceAsync.seq(cmd, regex, (match) => { + let regex = /\$\w+\[?\d?\]?/g; + stringReplaceAsync.seq(cmd, regex, (match, index) => { return (new Promise((resolve, reject) => { + if (match.startsWith('$accounts')) { + let accountIndex = cmd.substring(index + 10, index + 12); + accountIndex = parseInt(accountIndex, 10); + return self.events.request('blockchain:getAccounts', (err, accounts) => { + if (err) { + return reject('Error getting accounts: ' + err.message || err); + } + if (!accounts[accountIndex]) { + return reject(__('No corresponding account at index %d', accountIndex)); + } + resolve(accounts[accountIndex]); + }); + } + let referedContractName = match.slice(1); self.events.request('contracts:contract', referedContractName, (referedContract) => { if (!referedContract) {