From 48f9c54d9d2bc49af49afca1d85ea4e504c2c278 Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Sun, 16 Jul 2017 12:10:17 -0400 Subject: [PATCH] detect and replace library references with address --- boilerplate/config/development/genesis.json | 4 +++- demo/config/development/genesis.json | 4 +++- lib/contracts/compiler.js | 3 +++ lib/contracts/contracts.js | 1 + lib/contracts/deploy.js | 16 +++++++++++++++- test_app/app/contracts/simple_storage.sol | 2 +- test_app/app/contracts/test.sol | 17 +++++++++++++++++ test_app/config/development/genesis.json | 4 +++- 8 files changed, 46 insertions(+), 5 deletions(-) create mode 100644 test_app/app/contracts/test.sol diff --git a/boilerplate/config/development/genesis.json b/boilerplate/config/development/genesis.json index 8df404021..4a50a438b 100644 --- a/boilerplate/config/development/genesis.json +++ b/boilerplate/config/development/genesis.json @@ -1,5 +1,7 @@ { - "config": {}, + "config": { + "homesteadBlock": 1 + }, "nonce": "0x0000000000000042", "difficulty": "0x0", "alloc": { diff --git a/demo/config/development/genesis.json b/demo/config/development/genesis.json index 8df404021..4a50a438b 100644 --- a/demo/config/development/genesis.json +++ b/demo/config/development/genesis.json @@ -1,5 +1,7 @@ { - "config": {}, + "config": { + "homesteadBlock": 1 + }, "nonce": "0x0000000000000042", "difficulty": "0x0", "alloc": { diff --git a/lib/contracts/compiler.js b/lib/contracts/compiler.js index f80520280..1757194fa 100644 --- a/lib/contracts/compiler.js +++ b/lib/contracts/compiler.js @@ -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) { diff --git a/lib/contracts/contracts.js b/lib/contracts/contracts.js index 9799e4df9..97c67b871 100644 --- a/lib/contracts/contracts.js +++ b/lib/contracts/contracts.js @@ -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); diff --git a/lib/contracts/deploy.js b/lib/contracts/deploy.js index f9b2259be..e3103da23 100644 --- a/lib/contracts/deploy.js +++ b/lib/contracts/deploy.js @@ -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()); diff --git a/test_app/app/contracts/simple_storage.sol b/test_app/app/contracts/simple_storage.sol index 7c8ea15c4..41d608d39 100644 --- a/test_app/app/contracts/simple_storage.sol +++ b/test_app/app/contracts/simple_storage.sol @@ -12,7 +12,7 @@ contract SimpleStorage { storedData = x; } - function set2(uint x, uint y) { + function set2(uint x, uint unusedGiveWarning) { storedData = x; } diff --git a/test_app/app/contracts/test.sol b/test_app/app/contracts/test.sol new file mode 100644 index 000000000..2618d93df --- /dev/null +++ b/test_app/app/contracts/test.sol @@ -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); + } + +} diff --git a/test_app/config/development/genesis.json b/test_app/config/development/genesis.json index 8df404021..4a50a438b 100644 --- a/test_app/config/development/genesis.json +++ b/test_app/config/development/genesis.json @@ -1,5 +1,7 @@ { - "config": {}, + "config": { + "homesteadBlock": 1 + }, "nonce": "0x0000000000000042", "difficulty": "0x0", "alloc": {