mirror of https://github.com/embarklabs/embark.git
support specifying contract args as an object
This commit is contained in:
parent
a03be15c4a
commit
05aadc5c10
|
@ -146,6 +146,7 @@ class ContractsManager {
|
|||
self.logger.trace(self.contracts);
|
||||
callback();
|
||||
},
|
||||
// TODO: needs refactoring, has gotten too complex
|
||||
/*eslint complexity: ["error", 16]*/
|
||||
/*eslint max-depth: ["error", 16]*/
|
||||
function determineDependencies(callback) {
|
||||
|
@ -162,7 +163,15 @@ class ContractsManager {
|
|||
|
||||
// look in arguments for dependencies
|
||||
if (contract.args === []) continue;
|
||||
let ref = contract.args;
|
||||
|
||||
let ref;
|
||||
if (Array.isArray(contract.args)) {
|
||||
ref = contract.args;
|
||||
} else {
|
||||
let keys = Object.keys(contract.args);
|
||||
ref = keys.map((k) => contract.args[k]).filter((x) => !x);
|
||||
}
|
||||
|
||||
for (let j = 0; j < ref.length; j++) {
|
||||
let arg = ref[j];
|
||||
if (arg[0] === "$") {
|
||||
|
|
|
@ -24,11 +24,26 @@ class Deploy {
|
|||
}, cb);
|
||||
}
|
||||
|
||||
determineArguments(suppliedArgs) {
|
||||
determineArguments(suppliedArgs, contract) {
|
||||
let realArgs = [], l, arg, contractName, referedContract;
|
||||
|
||||
for (l = 0; l < suppliedArgs.length; l++) {
|
||||
arg = suppliedArgs[l];
|
||||
let args = suppliedArgs;
|
||||
|
||||
if (!Array.isArray(args)) {
|
||||
args = [];
|
||||
let abi = contract.abiDefinition.find((abi) => abi.type === 'constructor');
|
||||
|
||||
for (let input of abi.inputs) {
|
||||
let inputValue = suppliedArgs[input.name];
|
||||
if (!inputValue) {
|
||||
this.logger.error(input.name + " has not been defined for " + contract.className + " constructor");
|
||||
}
|
||||
args.push(inputValue || "");
|
||||
}
|
||||
}
|
||||
|
||||
for (l = 0; l < args.length; l++) {
|
||||
arg = args[l];
|
||||
if (arg[0] === "$") {
|
||||
contractName = arg.substr(1);
|
||||
referedContract = this.contractsManager.getContract(contractName);
|
||||
|
@ -63,7 +78,7 @@ class Deploy {
|
|||
return callback();
|
||||
}
|
||||
|
||||
realArgs = self.determineArguments(params || contract.args);
|
||||
realArgs = self.determineArguments(params || contract.args, contract);
|
||||
|
||||
if (contract.address !== undefined) {
|
||||
try {
|
||||
|
@ -119,7 +134,7 @@ class Deploy {
|
|||
|
||||
contractToDeploy(contract, params, callback) {
|
||||
const self = this;
|
||||
let realArgs = self.determineArguments(params || contract.args);
|
||||
let realArgs = self.determineArguments(params || contract.args, contract);
|
||||
|
||||
this.deployContract(contract, realArgs, function (err, address) {
|
||||
if (err) {
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
contract ContractArgs {
|
||||
address public addr_1;
|
||||
address public addr_2;
|
||||
uint public value;
|
||||
|
||||
function() public payable { }
|
||||
|
||||
function ContractArgs(address[] _addresses, uint initialValue) public {
|
||||
addr_1 = _addresses[0];
|
||||
addr_2 = _addresses[1];
|
||||
value = initialValue;
|
||||
}
|
||||
|
||||
}
|
|
@ -55,6 +55,12 @@
|
|||
"MyToken3": {
|
||||
"instanceOf": "Tokn"
|
||||
},
|
||||
"ContractArgs": {
|
||||
"args": {
|
||||
"initialValue": 123,
|
||||
"_addresses": ["$MyToken2", "$SimpleStorage"]
|
||||
}
|
||||
},
|
||||
"SomeContract": {
|
||||
"args": [
|
||||
["$MyToken2", "$SimpleStorage"],
|
||||
|
|
Loading…
Reference in New Issue