Skip to content

Commit 8831dfb

Browse files
committed
fix(contracts): replace $accounts for onDeploy too
This was intended from the start, but was only done for args
1 parent 3cf9ea6 commit 8831dfb

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

lib/modules/deployment/contract_deployer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class ContractDeployer {
1515
}
1616

1717
// TODO: determining the arguments could also be in a module since it's not
18-
// part of ta 'normal' contract deployment
18+
// part of a 'normal' contract deployment
1919
determineArguments(suppliedArgs, contract, accounts, callback) {
2020
const self = this;
2121

lib/modules/specialconfigs/index.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,23 @@ class SpecialConfigs {
3737
replaceWithAddresses(cmd, cb) {
3838
const self = this;
3939

40-
let regex = /\$\w+/g;
41-
stringReplaceAsync.seq(cmd, regex, (match) => {
40+
let regex = /\$\w+\[?\d?\]?/g;
41+
stringReplaceAsync.seq(cmd, regex, (match, index) => {
4242
return (new Promise((resolve, reject) => {
43+
if (match.startsWith('$accounts')) {
44+
let accountIndex = cmd.substring(index + 10, index + 12);
45+
accountIndex = parseInt(accountIndex, 10);
46+
return self.events.request('blockchain:getAccounts', (err, accounts) => {
47+
if (err) {
48+
return reject('Error getting accounts: ' + err.message || err);
49+
}
50+
if (!accounts[accountIndex]) {
51+
return reject(__('No corresponding account at index %d', accountIndex));
52+
}
53+
resolve(accounts[accountIndex]);
54+
});
55+
}
56+
4357
let referedContractName = match.slice(1);
4458
self.events.request('contracts:contract', referedContractName, (referedContract) => {
4559
if (!referedContract) {

0 commit comments

Comments
 (0)