mirror of https://github.com/embarklabs/embark.git
detect and replace library references with address
This commit is contained in:
parent
b56b51cf6e
commit
48f9c54d9d
|
@ -1,5 +1,7 @@
|
|||
{
|
||||
"config": {},
|
||||
"config": {
|
||||
"homesteadBlock": 1
|
||||
},
|
||||
"nonce": "0x0000000000000042",
|
||||
"difficulty": "0x0",
|
||||
"alloc": {
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
{
|
||||
"config": {},
|
||||
"config": {
|
||||
"homesteadBlock": 1
|
||||
},
|
||||
"nonce": "0x0000000000000042",
|
||||
"difficulty": "0x0",
|
||||
"alloc": {
|
||||
|
|
|
@ -106,6 +106,7 @@ class Compiler {
|
|||
// [2] classname
|
||||
const regex = /(.*):(.*)/;
|
||||
const className = contractName.match(regex)[2];
|
||||
const filename = contractName.match(regex)[1];
|
||||
|
||||
compiled_object[className] = {};
|
||||
compiled_object[className].code = contract.bytecode;
|
||||
|
@ -115,7 +116,9 @@ class Compiler {
|
|||
compiled_object[className].gasEstimates = contract.gasEstimates;
|
||||
compiled_object[className].functionHashes = contract.functionHashes;
|
||||
compiled_object[className].abiDefinition = JSON.parse(contract.interface);
|
||||
compiled_object[className].filename = filename
|
||||
}
|
||||
|
||||
callback(null, compiled_object);
|
||||
}
|
||||
], function (err, result) {
|
||||
|
|
|
@ -62,6 +62,7 @@ class ContractsManager {
|
|||
contract.gasEstimates = compiledContract.gasEstimates;
|
||||
contract.functionHashes = compiledContract.functionHashes;
|
||||
contract.abiDefinition = compiledContract.abiDefinition;
|
||||
contract.filename = compiledContract.filename;
|
||||
|
||||
contract.gas = (contractConfig && contractConfig.gas) || self.contractsConfig.gas || 'auto';
|
||||
self.adjustGas(contract);
|
||||
|
|
|
@ -105,18 +105,32 @@ class Deploy {
|
|||
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: it wouldn't necessary be the first address
|
||||
// use defined blockchain address or first address
|
||||
contractParams.push({
|
||||
//from: this.web3.eth.coinbase,
|
||||
from: accounts[0],
|
||||
data: "0x" + contract.code,
|
||||
data: "0x" + contractCode,
|
||||
gas: contract.gas,
|
||||
gasPrice: contract.gasPrice
|
||||
});
|
||||
|
||||
self.logger.info("deploying " + contract.className.bold.cyan + " with ".green + contract.gas + " gas".green);
|
||||
|
||||
contractParams.push(function (err, transaction) {
|
||||
self.logger.contractsState(self.contractsManager.contractsState());
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@ contract SimpleStorage {
|
|||
storedData = x;
|
||||
}
|
||||
|
||||
function set2(uint x, uint y) {
|
||||
function set2(uint x, uint unusedGiveWarning) {
|
||||
storedData = x;
|
||||
}
|
||||
|
||||
|
|
|
@ -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",
|
||||
"difficulty": "0x0",
|
||||
"alloc": {
|
||||
|
|
Loading…
Reference in New Issue