mirror of https://github.com/embarklabs/embark.git
support instanceOf config
This commit is contained in:
parent
2a8f0635b9
commit
2b6e5e834a
|
@ -1,15 +0,0 @@
|
||||||
{
|
|
||||||
"0xb6cfeab83614da04c03db0fb8a6787a45d0be8d576fcc6f8f457a5a816d22ab3": {
|
|
||||||
"name": "development",
|
|
||||||
"contracts": {
|
|
||||||
"2ac097aa929aece4724cc229cc7bd26c7dfa153f3274b5623936cb4a4dc12fa1": {
|
|
||||||
"address": "0xc55a44f8971248db2d0503e81a7d45a1a4a486c3",
|
|
||||||
"name": "token"
|
|
||||||
},
|
|
||||||
"769b12e03a7cbca8ad232b5aa5c15b453d3e9332aaf3c468ce29026b34606a05": {
|
|
||||||
"address": "0x26ee9ba44458921c20cdeecfbb5ab2f96d00b3f7",
|
|
||||||
"name": "SimpleStorage"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -12,6 +12,13 @@
|
||||||
100,
|
100,
|
||||||
"$token"
|
"$token"
|
||||||
]
|
]
|
||||||
|
},
|
||||||
|
"SimpleStorage2": {
|
||||||
|
"instanceOf": "SimpleStorage",
|
||||||
|
"args": [
|
||||||
|
100,
|
||||||
|
"$token"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
var Compiler = require('./compiler.js');
|
var Compiler = require('./compiler.js');
|
||||||
var toposort = require('toposort');
|
var toposort = require('toposort');
|
||||||
|
|
||||||
|
// TODO: create a contract object
|
||||||
|
|
||||||
var ContractsManager = function(options) {
|
var ContractsManager = function(options) {
|
||||||
this.contractFiles = options.contractFiles;
|
this.contractFiles = options.contractFiles;
|
||||||
this.contractsConfig = options.contractsConfig;
|
this.contractsConfig = options.contractsConfig;
|
||||||
|
@ -21,24 +23,12 @@ ContractsManager.prototype.compileContracts = function() {
|
||||||
|
|
||||||
ContractsManager.prototype.build = function() {
|
ContractsManager.prototype.build = function() {
|
||||||
|
|
||||||
// determine dependencies
|
// =======================
|
||||||
for (var className in this.compiledContracts) {
|
// =======================
|
||||||
var contract = this.compiledContracts[className];
|
// TODO: this should be going through the contract config, not just the
|
||||||
var contractConfig = this.contractsConfig.contracts[className];
|
// compiled list
|
||||||
|
// =======================
|
||||||
if (this.contractsConfig.args === null || this.contractsConfig.args === []) continue;
|
// =======================
|
||||||
|
|
||||||
var ref = contractConfig.args; //get arguments
|
|
||||||
for (var j = 0; j < ref.length; j++) {
|
|
||||||
var arg = ref[j];
|
|
||||||
if (arg[0] === "$") {
|
|
||||||
if (this.contractDependencies[className] === void 0) {
|
|
||||||
this.contractDependencies[className] = [];
|
|
||||||
}
|
|
||||||
this.contractDependencies[className].push(arg.substr(1));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for(var className in this.compiledContracts) {
|
for(var className in this.compiledContracts) {
|
||||||
var contract = this.compiledContracts[className];
|
var contract = this.compiledContracts[className];
|
||||||
|
@ -59,9 +49,52 @@ ContractsManager.prototype.build = function() {
|
||||||
contract.args = contractConfig.args || [];
|
contract.args = contractConfig.args || [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
contract.type = 'file';
|
||||||
|
|
||||||
contract.className = className;
|
contract.className = className;
|
||||||
|
|
||||||
this.contracts[className] = contract;
|
this.contracts[className] = contract;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for(var className in this.contractsConfig.contracts) {
|
||||||
|
var contractConfig = this.contractsConfig.contracts[className];
|
||||||
|
var contract;
|
||||||
|
|
||||||
|
if (contractConfig.instanceOf !== undefined) {
|
||||||
|
// TODO: should merge with parent object
|
||||||
|
var parentContractName = contractConfig.instanceOf;
|
||||||
|
var parentContract = this.contractsConfig.contracts[parentContractName];
|
||||||
|
var parentContractObject = this.contracts[parentContractName];
|
||||||
|
contract = JSON.parse(JSON.stringify(parentContractObject));
|
||||||
|
contract.deploy = true;
|
||||||
|
contract.className = className;
|
||||||
|
contract.args = (contractConfig.args || parentContract.args);
|
||||||
|
contract.gas = (contractConfig.gas || parentContract.gas);
|
||||||
|
contract.gasPrice = (contractConfig.gasPrice || parentContract.gasPrice);
|
||||||
|
|
||||||
|
this.contracts[className] = contract;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// determine dependencies
|
||||||
|
for (var className in this.compiledContracts) {
|
||||||
|
var contract = this.compiledContracts[className];
|
||||||
|
var contractConfig = this.contractsConfig.contracts[className];
|
||||||
|
|
||||||
|
if (this.contractsConfig.args === null || this.contractsConfig.args === []) continue;
|
||||||
|
|
||||||
|
var ref = contractConfig.args; //get arguments
|
||||||
|
for (var j = 0; j < ref.length; j++) {
|
||||||
|
var arg = ref[j];
|
||||||
|
if (arg[0] === "$") {
|
||||||
|
if (this.contractDependencies[className] === void 0) {
|
||||||
|
this.contractDependencies[className] = [];
|
||||||
|
}
|
||||||
|
this.contractDependencies[className].push(arg.substr(1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
ContractsManager.prototype.getContract = function(className) {
|
ContractsManager.prototype.getContract = function(className) {
|
||||||
|
@ -92,8 +125,8 @@ ContractsManager.prototype.sortContracts = function(contractList) {
|
||||||
// TODO: should be built contracts
|
// TODO: should be built contracts
|
||||||
ContractsManager.prototype.listContracts = function() {
|
ContractsManager.prototype.listContracts = function() {
|
||||||
var contracts = [];
|
var contracts = [];
|
||||||
for(var className in this.compiledContracts) {
|
for(var className in this.contracts) {
|
||||||
var contract = this.compiledContracts[className];
|
var contract = this.contracts[className];
|
||||||
contracts.push(contract);
|
contracts.push(contract);
|
||||||
}
|
}
|
||||||
return this.sortContracts(contracts);
|
return this.sortContracts(contracts);
|
||||||
|
|
Loading…
Reference in New Issue