Commit c9fad0a4 authored by chriseth's avatar chriseth

Merge pull request #22 from ethereum/patch/encode-ethereumjs-abi

Use ethereumjs-abi for encoding requests [WI]
parents f738864d aff86d7d
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
"merkle-patricia-tree": "^2.1.2", "merkle-patricia-tree": "^2.1.2",
"ethereumjs-util": "^4.4.0", "ethereumjs-util": "^4.4.0",
"ethereumjs-tx": "^1.1.1", "ethereumjs-tx": "^1.1.1",
"ethereumjs-abi": "^0.6.1", "ethereumjs-abi": "^0.6.2",
"web3": "^0.15.3", "web3": "^0.15.3",
"jquery": "^2.2.0", "jquery": "^2.2.0",
"brace": "^0.8.0", "brace": "^0.8.0",
......
...@@ -13,9 +13,6 @@ function UniversalDApp (contracts, options) { ...@@ -13,9 +13,6 @@ function UniversalDApp (contracts, options) {
this.renderOutputModifier = options.renderOutputModifier || function (name, content) { return content; }; this.renderOutputModifier = options.renderOutputModifier || function (name, content) { return content; };
this.web3 = options.web3; this.web3 = options.web3;
if (!this.web3) {
throw new Error('Web3 is required for ABI encoding');
}
if (options.mode === 'vm') { if (options.mode === 'vm') {
// FIXME: use `options.vm` or `this.vm` consistently // FIXME: use `options.vm` or `this.vm` consistently
...@@ -180,7 +177,6 @@ UniversalDApp.prototype.getInstanceInterface = function (contract, address, $tar ...@@ -180,7 +177,6 @@ UniversalDApp.prototype.getInstanceInterface = function (contract, address, $tar
return 1; return 1;
} }
}); });
var web3contract = this.web3.eth.contract(abi);
var funABI = this.getConstructorInterface(abi); var funABI = this.getConstructorInterface(abi);
var $createInterface = $('<div class="createContract"/>'); var $createInterface = $('<div class="createContract"/>');
...@@ -252,7 +248,7 @@ UniversalDApp.prototype.getInstanceInterface = function (contract, address, $tar ...@@ -252,7 +248,7 @@ UniversalDApp.prototype.getInstanceInterface = function (contract, address, $tar
} }
}); });
} else { } else {
var eventFilter = web3contract.at(address).allEvents(); var eventFilter = this.web3.eth.contract(abi).at(address).allEvents();
eventFilter.watch(parseLogs); eventFilter.watch(parseLogs);
} }
$instance.append($title); $instance.append($title);
...@@ -274,8 +270,12 @@ UniversalDApp.prototype.getInstanceInterface = function (contract, address, $tar ...@@ -274,8 +270,12 @@ UniversalDApp.prototype.getInstanceInterface = function (contract, address, $tar
$instance.append(self.getCallButton({ $instance.append(self.getCallButton({
abi: funABI, abi: funABI,
encode: function (args) { encode: function (args) {
var obj = web3contract.at('0x00')[funABI.name]; var types = [];
return obj.getData.apply(obj, args); for (var i = 0; i < funABI.inputs.length; i++) {
types.push(funABI.inputs[i].type);
}
return Buffer.concat([ ethJSABI.methodID(funABI.name, types), ethJSABI.rawEncode(types, args) ]).toString('hex');
}, },
address: address address: address
})); }));
...@@ -287,8 +287,14 @@ UniversalDApp.prototype.getInstanceInterface = function (contract, address, $tar ...@@ -287,8 +287,14 @@ UniversalDApp.prototype.getInstanceInterface = function (contract, address, $tar
$createInterface.append(this.getCallButton({ $createInterface.append(this.getCallButton({
abi: funABI, abi: funABI,
encode: function (args) { encode: function (args) {
var obj = web3contract.new; var types = [];
return obj.getData.apply(obj, args); for (var i = 0; i < funABI.inputs.length; i++) {
types.push(funABI.inputs[i].type);
}
// NOTE: the caller will concatenate the bytecode and this
// it could be done here too for consistency
return ethJSABI.rawEncode(types, args).toString('hex');
}, },
contractName: contract.name, contractName: contract.name,
bytecode: contract.bytecode, bytecode: contract.bytecode,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment