mirror of
https://github.com/embarklabs/embark.git
synced 2025-01-21 02:59:58 +00:00
re-add linking support; re-add contract json generation
This commit is contained in:
parent
fcde87f14b
commit
a14bebabf6
@ -14,6 +14,9 @@ module.exports = {
|
||||
console.log("==========================");
|
||||
},
|
||||
deploy: {
|
||||
Ownable: {
|
||||
deploy: false
|
||||
},
|
||||
SimpleStorage: {
|
||||
fromIndex: 0,
|
||||
args: [100]
|
||||
@ -21,6 +24,10 @@ module.exports = {
|
||||
// "SimpleStorage.methods.setRegistar(web3.eth.defaultAccount).send()"
|
||||
// ]
|
||||
},
|
||||
SimpleStorageTest: {
|
||||
//file: "./some_folder/test_contract.sol",
|
||||
args: [1000]
|
||||
},
|
||||
AnotherStorage: {
|
||||
args: ["$SimpleStorage"]
|
||||
//args: ["0x0000000000000000000000000000000000000000"]
|
||||
|
@ -74,6 +74,7 @@ class FunctionConfigs {
|
||||
let args = { contracts: {}, logger};
|
||||
for (let contract of contracts) {
|
||||
// TODO: for this to work correctly we need to add a default from address to the contract
|
||||
if (contract.deploy === false) continue;
|
||||
let contractInstance = await this.events.request2("runcode:eval", contract.className);
|
||||
args.contracts[contract.className] = contractInstance;
|
||||
}
|
||||
|
@ -218,7 +218,7 @@ Plugins.prototype.runActionsForEvent = function(eventName, args, cb) {
|
||||
|
||||
this.events.log("ACTION", eventName, "");
|
||||
|
||||
async.reduce(actionPlugins, args, function(current_args, pluginObj, nextEach) {
|
||||
async.reduce(actionPlugins, args, function (current_args, pluginObj, nextEach) {
|
||||
const [plugin, pluginName] = pluginObj;
|
||||
|
||||
self.events.log("== ACTION FOR " + eventName, plugin.name, pluginName);
|
||||
|
@ -8,7 +8,9 @@ class EthereumBlockchainClient {
|
||||
this.embark = embark;
|
||||
this.events = embark.events;
|
||||
|
||||
this.embark.registerActionForEvent("deployment:contract:deployed", this.addContractJSONToPipeline.bind(this));
|
||||
this.embark.registerActionForEvent('deployment:contract:beforeDeploy', this.determineArguments.bind(this));
|
||||
this.embark.registerActionForEvent('deployment:contract:beforeDeploy', this.doLinking.bind(this));
|
||||
this.events.request("blockchain:client:register", "ethereum", this.getClient.bind(this));
|
||||
this.events.request("deployment:deployer:register", "ethereum", this.deployer.bind(this));
|
||||
}
|
||||
@ -44,6 +46,53 @@ class EthereumBlockchainClient {
|
||||
})
|
||||
}
|
||||
|
||||
async doLinking(params, callback) {
|
||||
let contract = params.contract;
|
||||
|
||||
console.dir("= doLinking")
|
||||
|
||||
if (!contract.linkReferences || !Object.keys(contract.linkReferences).length) {
|
||||
return callback(null, params);
|
||||
}
|
||||
let contractCode = contract.code;
|
||||
let offset = 0;
|
||||
|
||||
async.eachLimit(contract.linkReferences, 1, (fileReference, eachCb1) => {
|
||||
async.eachOfLimit(fileReference, 1, (references, libName, eachCb2) => {
|
||||
let libContract = self.events.request2("contracts:contract", libName);
|
||||
|
||||
async.eachLimit(references, 1, (reference, eachCb3) => {
|
||||
if (!libContract) {
|
||||
return eachCb3(new Error(__('{{contractName}} has a link to the library {{libraryName}}, but it was not found. Is it in your contract folder?'), {
|
||||
contractName: contract.className,
|
||||
libraryName: libName
|
||||
}));
|
||||
}
|
||||
|
||||
let libAddress = libContract.deployedAddress;
|
||||
if (!libAddress) {
|
||||
return eachCb3(new Error(__("{{contractName}} needs {{libraryName}} but an address was not found, did you deploy it or configured an address?", {
|
||||
contractName: contract.className,
|
||||
libraryName: libName
|
||||
})));
|
||||
}
|
||||
|
||||
libAddress = libAddress.substr(2).toLowerCase();
|
||||
|
||||
// Multiplying by two because the original pos and length are in bytes, but we have an hex string
|
||||
contractCode = contractCode.substring(0, (reference.start * 2) + offset) + libAddress + contractCode.substring((reference.start * 2) + offset + (reference.length * 2));
|
||||
// Calculating an offset in case the length is at some point different than the address length
|
||||
offset += libAddress.length - (reference.length * 2);
|
||||
|
||||
eachCb3();
|
||||
}, eachCb2);
|
||||
}, eachCb1);
|
||||
}, (err) => {
|
||||
contract.code = contractCode;
|
||||
callback(err, params);
|
||||
});
|
||||
}
|
||||
|
||||
// TODO we can separate this into 3 separate methods, which will make it easier to test
|
||||
// determineArguments(suppliedArgs, contract, accounts, callback) {
|
||||
async determineArguments(params, callback) {
|
||||
@ -122,6 +171,19 @@ class EthereumBlockchainClient {
|
||||
});
|
||||
}
|
||||
|
||||
addContractJSONToPipeline(params, cb) {
|
||||
console.dir("-- addContractJSONToPipeline")
|
||||
// TODO: check if this is correct json object to generate
|
||||
const contract = params.contract;
|
||||
|
||||
this.events.request("pipeline:register", {
|
||||
path: [this.embark.config.embarkConfig.buildDir, 'contracts'],
|
||||
file: contract.className + '.json',
|
||||
format: 'json',
|
||||
content: contract
|
||||
}, cb);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module.exports = EthereumBlockchainClient;
|
||||
|
Loading…
x
Reference in New Issue
Block a user