Browse Source

sha3 method signature

cl-refactor
Marek Kotewicz 10 years ago
parent
commit
0538c11576
  1. 22
      dist/ethereum.js
  2. 6
      dist/ethereum.js.map
  3. 2
      dist/ethereum.min.js
  4. 16
      lib/abi.js
  5. 6
      lib/contract.js

22
dist/ethereum.js

@ -141,7 +141,6 @@ var toAbiInput = function (json, methodName, params) {
return;
}
bytes = "0x" + padLeft(index.toString(16), 2);
var method = json[index];
for (var i = 0; i < method.inputs.length; i++) {
@ -260,9 +259,22 @@ var outputParser = function (json) {
return parser;
};
var methodSignature = function (json, name) {
var method = json[findMethodIndex(json, name)];
var result = name + '(';
var inputTypes = method.inputs.map(function (inp) {
return inp.type;
});
result += inputTypes.join(',');
result += ')';
return web3.sha3(result);
};
module.exports = {
inputParser: inputParser,
outputParser: outputParser
outputParser: outputParser,
methodSignature: methodSignature
};
},{}],2:[function(require,module,exports){
@ -418,8 +430,10 @@ var contract = function (address, desc) {
call: function (extra) {
extra = extra || {};
extra.to = address;
extra.data = parsed;
return web3.eth.call(extra).then(onSuccess);
return abi.methodSignature(desc, method.name).then(function (signature) {
extra.data = signature.slice(0, 10) + parsed;
return web3.eth.call(extra).then(onSuccess);
});
},
transact: function (extra) {
extra = extra || {};

6
dist/ethereum.js.map

File diff suppressed because one or more lines are too long

2
dist/ethereum.min.js

File diff suppressed because one or more lines are too long

16
lib/abi.js

@ -140,7 +140,6 @@ var toAbiInput = function (json, methodName, params) {
return;
}
bytes = "0x" + padLeft(index.toString(16), 2);
var method = json[index];
for (var i = 0; i < method.inputs.length; i++) {
@ -259,7 +258,20 @@ var outputParser = function (json) {
return parser;
};
var methodSignature = function (json, name) {
var method = json[findMethodIndex(json, name)];
var result = name + '(';
var inputTypes = method.inputs.map(function (inp) {
return inp.type;
});
result += inputTypes.join(',');
result += ')';
return web3.sha3(result);
};
module.exports = {
inputParser: inputParser,
outputParser: outputParser
outputParser: outputParser,
methodSignature: methodSignature
};

6
lib/contract.js

@ -46,8 +46,10 @@ var contract = function (address, desc) {
call: function (extra) {
extra = extra || {};
extra.to = address;
extra.data = parsed;
return web3.eth.call(extra).then(onSuccess);
return abi.methodSignature(desc, method.name).then(function (signature) {
extra.data = signature.slice(0, 10) + parsed;
return web3.eth.call(extra).then(onSuccess);
});
},
transact: function (extra) {
extra = extra || {};

Loading…
Cancel
Save