Skip to content

Commit

Permalink
fixed #154
Browse files Browse the repository at this point in the history
  • Loading branch information
debris committed Apr 20, 2015
1 parent 1c8cd7d commit 38641df
Show file tree
Hide file tree
Showing 11 changed files with 47 additions and 122 deletions.
7 changes: 4 additions & 3 deletions dist/web3-light.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions dist/web3-light.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/web3-light.min.js

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions dist/web3.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions dist/web3.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/web3.min.js

Large diffs are not rendered by default.

55 changes: 27 additions & 28 deletions example/contract.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,30 @@
<script type="text/javascript">

var web3 = require('web3');
web3.setProvider(new web3.providers.HttpProvider());
web3.setProvider(new web3.providers.HttpProvider("http://localhost:8545"));

// solidity source code
var source = "" +
"contract test {\n" +
" function multiply(uint a) returns(uint d) {\n" +
" return a * 7;\n" +
" }\n" +
"}\n";
/*var source = "" +*/
/*"contract test {\n" +*/
/*" function multiply(uint a) constant returns(uint d) {\n" +*/
/*" return a * 7;\n" +*/
/*" }\n" +*/
/*"}\n";*/
var source = "605280600c6000396000f3006000357c010000000000000000000000000000000000000000000000000000000090048063c6888fa114602e57005b60376004356041565b8060005260206000f35b6000600782029050604d565b91905056";

// contract description, this will be autogenerated somehow
var desc = [{
"name": "multiply(uint256)",
"type": "function",
"inputs": [
{
"name": "a",
"type": "uint256"
}
],
"outputs": [
{
"name": "d",
"type": "uint256"
}
]
// contract description, this is autogenerated using solc CLI
var desc = [{
"constant" : true,
"inputs" : [{
"name" : "a",
"type" : "uint256"
}],
"name" : "multiply",
"outputs" : [{
"name" : "d",
"type" : "uint256"
}],
"type" : "function"
}];

var myContract;
Expand All @@ -41,11 +39,12 @@
document.getElementById('create').style.visibility = 'hidden';
document.getElementById('source').innerText = source;

// create contract
var address = web3.eth.sendTransaction({data: web3.eth.compile.solidity(source)}),
Contract = web3.eth.contract(desc);
// let's assume that coinbase is our account
web3.eth.defaultAccount = web3.eth.coinbase;

myContract = new Contract(address);
// create contract
var Contract = web3.eth.contract(desc);
myContract = new Contract({data: source});
document.getElementById('call').style.visibility = 'visible';
}

Expand All @@ -54,7 +53,7 @@
var param = parseInt(document.getElementById('value').value);

// call the contract
var res = myContract.call().multiply(param);
var res = myContract.multiply(param);
document.getElementById('result').innerText = res.toString(10);
}

Expand Down
77 changes: 0 additions & 77 deletions example/contract_with_array.html

This file was deleted.

2 changes: 1 addition & 1 deletion example/event_inc.html
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
// let's assume that we have a private key to coinbase ;)
web3.eth.defaultAccount = web3.eth.coinbase;
var Contract = web3.eth.contract(desc);
contract = new Contract(source);
contract = new Contract({data: source});
contract.Incremented({odd: true}).watch(update);

};
Expand Down
7 changes: 4 additions & 3 deletions lib/web3/contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,12 +191,13 @@ function Contract(abi, options) {
var address = '';
if (utils.isAddress(options)) {
address = options;
} else { // is a source code!
} else { // is an object!
// TODO, parse the rest of the args
var code = options;
options = options || {};
var args = Array.prototype.slice.call(arguments, 2);
var bytes = solAbi.formatConstructorParams(abi, args);
address = web3.eth.sendTransaction({data: code + bytes});
options.data += bytes;
address = web3.eth.sendTransaction(options);
}

var result = {};
Expand Down
2 changes: 1 addition & 1 deletion test/web3.eth.contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ describe('web3.eth.contract', function() {
});

var Con = contract(description);
var myCon = new Con(code, 2);
var myCon = new Con({data: code}, 2);
});
});

0 comments on commit 38641df

Please sign in to comment.