mirror of https://github.com/embarklabs/embark.git
detect and replace library references with address
This commit is contained in:
parent
3cdc4eb72a
commit
ecab599d00
|
@ -1,5 +1,7 @@
|
||||||
{
|
{
|
||||||
"config": {},
|
"config": {
|
||||||
|
"homesteadBlock": 1
|
||||||
|
},
|
||||||
"nonce": "0x0000000000000042",
|
"nonce": "0x0000000000000042",
|
||||||
"difficulty": "0x0",
|
"difficulty": "0x0",
|
||||||
"alloc": {
|
"alloc": {
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
{
|
{
|
||||||
"config": {},
|
"config": {
|
||||||
|
"homesteadBlock": 1
|
||||||
|
},
|
||||||
"nonce": "0x0000000000000042",
|
"nonce": "0x0000000000000042",
|
||||||
"difficulty": "0x0",
|
"difficulty": "0x0",
|
||||||
"alloc": {
|
"alloc": {
|
||||||
|
|
|
@ -95,6 +95,7 @@ class Compiler {
|
||||||
// [2] classname
|
// [2] classname
|
||||||
const regex = /(.*):(.*)/;
|
const regex = /(.*):(.*)/;
|
||||||
const className = contractName.match(regex)[2];
|
const className = contractName.match(regex)[2];
|
||||||
|
const filename = contractName.match(regex)[1];
|
||||||
|
|
||||||
compiled_object[className] = {};
|
compiled_object[className] = {};
|
||||||
compiled_object[className].code = contract.bytecode;
|
compiled_object[className].code = contract.bytecode;
|
||||||
|
@ -104,7 +105,9 @@ class Compiler {
|
||||||
compiled_object[className].gasEstimates = contract.gasEstimates;
|
compiled_object[className].gasEstimates = contract.gasEstimates;
|
||||||
compiled_object[className].functionHashes = contract.functionHashes;
|
compiled_object[className].functionHashes = contract.functionHashes;
|
||||||
compiled_object[className].abiDefinition = JSON.parse(contract.interface);
|
compiled_object[className].abiDefinition = JSON.parse(contract.interface);
|
||||||
|
compiled_object[className].filename = filename
|
||||||
}
|
}
|
||||||
|
|
||||||
callback(null, compiled_object);
|
callback(null, compiled_object);
|
||||||
}
|
}
|
||||||
], function (err, result) {
|
], function (err, result) {
|
||||||
|
|
|
@ -61,6 +61,7 @@ class ContractsManager {
|
||||||
contract.gasEstimates = compiledContract.gasEstimates;
|
contract.gasEstimates = compiledContract.gasEstimates;
|
||||||
contract.functionHashes = compiledContract.functionHashes;
|
contract.functionHashes = compiledContract.functionHashes;
|
||||||
contract.abiDefinition = compiledContract.abiDefinition;
|
contract.abiDefinition = compiledContract.abiDefinition;
|
||||||
|
contract.filename = compiledContract.filename;
|
||||||
|
|
||||||
contract.gas = (contractConfig && contractConfig.gas) || self.contractsConfig.gas || 'auto';
|
contract.gas = (contractConfig && contractConfig.gas) || self.contractsConfig.gas || 'auto';
|
||||||
self.adjustGas(contract);
|
self.adjustGas(contract);
|
||||||
|
|
|
@ -105,18 +105,32 @@ class Deploy {
|
||||||
return callback(new Error(err));
|
return callback(new Error(err));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let contractCode = contract.code;
|
||||||
|
let contractsList = self.contractsManager.listContracts();
|
||||||
|
for (let contractObj of contractsList) {
|
||||||
|
let filename = contractObj.filename;
|
||||||
|
let deployedAddress = contractObj.deployedAddress;
|
||||||
|
if (deployedAddress) {
|
||||||
|
deployedAddress = deployedAddress.substr(2);
|
||||||
|
}
|
||||||
|
let linkReference = '__' + filename + ":" + contractObj.className;
|
||||||
|
let toReplace = linkReference + "_".repeat(40 - linkReference.length);
|
||||||
|
contractCode = contractCode.replace(toReplace, deployedAddress);
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: probably needs to be defaultAccount
|
// TODO: probably needs to be defaultAccount
|
||||||
// TODO: it wouldn't necessary be the first address
|
// TODO: it wouldn't necessary be the first address
|
||||||
// use defined blockchain address or first address
|
// use defined blockchain address or first address
|
||||||
contractParams.push({
|
contractParams.push({
|
||||||
//from: this.web3.eth.coinbase,
|
//from: this.web3.eth.coinbase,
|
||||||
from: accounts[0],
|
from: accounts[0],
|
||||||
data: "0x" + contract.code,
|
data: "0x" + contractCode,
|
||||||
gas: contract.gas,
|
gas: contract.gas,
|
||||||
gasPrice: contract.gasPrice
|
gasPrice: contract.gasPrice
|
||||||
});
|
});
|
||||||
|
|
||||||
self.logger.info("deploying " + contract.className.bold.cyan + " with ".green + contract.gas + " gas".green);
|
self.logger.info("deploying " + contract.className.bold.cyan + " with ".green + contract.gas + " gas".green);
|
||||||
|
|
||||||
contractParams.push(function (err, transaction) {
|
contractParams.push(function (err, transaction) {
|
||||||
self.logger.contractsState(self.contractsManager.contractsState());
|
self.logger.contractsState(self.contractsManager.contractsState());
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,17 @@
|
||||||
|
pragma solidity ^0.4.11;
|
||||||
|
|
||||||
|
library AMyLib {
|
||||||
|
|
||||||
|
function add(uint _a, uint _b) returns (uint _c) {
|
||||||
|
return _a + _b;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
contract Test {
|
||||||
|
|
||||||
|
function testAdd() constant returns (uint _result) {
|
||||||
|
return AMyLib.add(1, 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,5 +1,7 @@
|
||||||
{
|
{
|
||||||
"config": {},
|
"config": {
|
||||||
|
"homesteadBlock": 1
|
||||||
|
},
|
||||||
"nonce": "0x0000000000000042",
|
"nonce": "0x0000000000000042",
|
||||||
"difficulty": "0x0",
|
"difficulty": "0x0",
|
||||||
"alloc": {
|
"alloc": {
|
||||||
|
|
Loading…
Reference in New Issue