added eth_serpent, contract separated to another file

This commit is contained in:
Marek Kotewicz
2014-11-17 15:46:46 +01:00
parent f6ee8e52dd
commit 27a8799e48
7 changed files with 81 additions and 48 deletions

View File

@@ -22,8 +22,6 @@
* @date 2014
*/
var abi = require('./abi');
function flattenPromise (obj) {
if (obj instanceof Promise) {
return Promise.resolve(obj);
@@ -89,7 +87,8 @@ var ethMethods = function () {
{ name: 'uncle', call: uncleCall },
{ name: 'compilers', call: 'eth_compilers' },
{ name: 'lll', call: 'eth_lll' },
{ name: 'solidity', call: 'eth_solidity' }
{ name: 'solidity', call: 'eth_solidity' },
{ name: 'serpent', call: 'eth_serpent' }
];
return methods;
};
@@ -455,40 +454,5 @@ function messageHandler(data) {
}
}
web3.contract = function (address, desc) {
var inputParser = abi.inputParser(desc);
var outputParser = abi.outputParser(desc);
var contract = {};
desc.forEach(function (method) {
contract[method.name] = function () {
var params = Array.prototype.slice.call(arguments);
var parsed = inputParser[method.name].apply(null, params);
var onSuccess = function (result) {
return outputParser[method.name](result);
};
return {
call: function (extra) {
extra = extra || {};
extra.to = address;
extra.data = parsed;
return web3.eth.call(extra).then(onSuccess);
},
transact: function (extra) {
extra = extra || {};
extra.to = address;
extra.data = parsed;
return web3.eth.transact(extra).then(onSuccess);
}
};
};
});
return contract;
};
module.exports = web3;