Skip to content

Commit 48f9c54

Browse files
committed
detect and replace library references with address
1 parent b56b51c commit 48f9c54

File tree

8 files changed

+46
-5
lines changed

8 files changed

+46
-5
lines changed

boilerplate/config/development/genesis.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
{
2-
"config": {},
2+
"config": {
3+
"homesteadBlock": 1
4+
},
35
"nonce": "0x0000000000000042",
46
"difficulty": "0x0",
57
"alloc": {

demo/config/development/genesis.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
{
2-
"config": {},
2+
"config": {
3+
"homesteadBlock": 1
4+
},
35
"nonce": "0x0000000000000042",
46
"difficulty": "0x0",
57
"alloc": {

lib/contracts/compiler.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ class Compiler {
106106
// [2] classname
107107
const regex = /(.*):(.*)/;
108108
const className = contractName.match(regex)[2];
109+
const filename = contractName.match(regex)[1];
109110

110111
compiled_object[className] = {};
111112
compiled_object[className].code = contract.bytecode;
@@ -115,7 +116,9 @@ class Compiler {
115116
compiled_object[className].gasEstimates = contract.gasEstimates;
116117
compiled_object[className].functionHashes = contract.functionHashes;
117118
compiled_object[className].abiDefinition = JSON.parse(contract.interface);
119+
compiled_object[className].filename = filename
118120
}
121+
119122
callback(null, compiled_object);
120123
}
121124
], function (err, result) {

lib/contracts/contracts.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ class ContractsManager {
6262
contract.gasEstimates = compiledContract.gasEstimates;
6363
contract.functionHashes = compiledContract.functionHashes;
6464
contract.abiDefinition = compiledContract.abiDefinition;
65+
contract.filename = compiledContract.filename;
6566

6667
contract.gas = (contractConfig && contractConfig.gas) || self.contractsConfig.gas || 'auto';
6768
self.adjustGas(contract);

lib/contracts/deploy.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,18 +105,32 @@ class Deploy {
105105
return callback(new Error(err));
106106
}
107107

108+
let contractCode = contract.code;
109+
let contractsList = self.contractsManager.listContracts();
110+
for (let contractObj of contractsList) {
111+
let filename = contractObj.filename;
112+
let deployedAddress = contractObj.deployedAddress;
113+
if (deployedAddress) {
114+
deployedAddress = deployedAddress.substr(2);
115+
}
116+
let linkReference = '__' + filename + ":" + contractObj.className;
117+
let toReplace = linkReference + "_".repeat(40 - linkReference.length);
118+
contractCode = contractCode.replace(toReplace, deployedAddress);
119+
}
120+
108121
// TODO: probably needs to be defaultAccount
109122
// TODO: it wouldn't necessary be the first address
110123
// use defined blockchain address or first address
111124
contractParams.push({
112125
//from: this.web3.eth.coinbase,
113126
from: accounts[0],
114-
data: "0x" + contract.code,
127+
data: "0x" + contractCode,
115128
gas: contract.gas,
116129
gasPrice: contract.gasPrice
117130
});
118131

119132
self.logger.info("deploying " + contract.className.bold.cyan + " with ".green + contract.gas + " gas".green);
133+
120134
contractParams.push(function (err, transaction) {
121135
self.logger.contractsState(self.contractsManager.contractsState());
122136

test_app/app/contracts/simple_storage.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ contract SimpleStorage {
1212
storedData = x;
1313
}
1414

15-
function set2(uint x, uint y) {
15+
function set2(uint x, uint unusedGiveWarning) {
1616
storedData = x;
1717
}
1818

test_app/app/contracts/test.sol

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
pragma solidity ^0.4.11;
2+
3+
library AMyLib {
4+
5+
function add(uint _a, uint _b) returns (uint _c) {
6+
return _a + _b;
7+
}
8+
9+
}
10+
11+
contract Test {
12+
13+
function testAdd() constant returns (uint _result) {
14+
return AMyLib.add(1, 2);
15+
}
16+
17+
}

test_app/config/development/genesis.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
{
2-
"config": {},
2+
"config": {
3+
"homesteadBlock": 1
4+
},
35
"nonce": "0x0000000000000042",
46
"difficulty": "0x0",
57
"alloc": {

0 commit comments

Comments
 (0)