detect and replace library references with address

This commit is contained in:
Iuri Matias 2017-07-16 12:10:17 -04:00
parent b56b51cf6e
commit 48f9c54d9d
8 changed files with 46 additions and 5 deletions

View File

@ -1,5 +1,7 @@
{
"config": {},
"config": {
"homesteadBlock": 1
},
"nonce": "0x0000000000000042",
"difficulty": "0x0",
"alloc": {

View File

@ -1,5 +1,7 @@
{
"config": {},
"config": {
"homesteadBlock": 1
},
"nonce": "0x0000000000000042",
"difficulty": "0x0",
"alloc": {

View File

@ -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) {

View File

@ -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);

View File

@ -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());

View File

@ -12,7 +12,7 @@ contract SimpleStorage {
storedData = x;
}
function set2(uint x, uint y) {
function set2(uint x, uint unusedGiveWarning) {
storedData = x;
}

View File

@ -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);
}
}

View File

@ -1,5 +1,7 @@
{
"config": {},
"config": {
"homesteadBlock": 1
},
"nonce": "0x0000000000000042",
"difficulty": "0x0",
"alloc": {