aboutsummaryrefslogtreecommitdiffstats
path: root/lib/main.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/main.js')
-rw-r--r--lib/main.js48
1 files changed, 43 insertions, 5 deletions
diff --git a/lib/main.js b/lib/main.js
index c3ed22f8b..7990691de 100644
--- a/lib/main.js
+++ b/lib/main.js
@@ -22,6 +22,8 @@
* @date 2014
*/
+var abi = require('./abi');
+
function flattenPromise (obj) {
if (obj instanceof Promise) {
return Promise.resolve(obj);
@@ -77,6 +79,7 @@ var ethMethods = function () {
var methods = [
{ name: 'balanceAt', call: 'eth_balanceAt' },
{ name: 'stateAt', call: 'eth_stateAt' },
+ { name: 'storageAt', call: 'eth_storageAt' },
{ name: 'countAt', call: 'eth_countAt'},
{ name: 'codeAt', call: 'eth_codeAt' },
{ name: 'transact', call: 'eth_transact' },
@@ -84,8 +87,9 @@ var ethMethods = function () {
{ name: 'block', call: blockCall },
{ name: 'transaction', call: transactionCall },
{ name: 'uncle', call: uncleCall },
- { name: 'compile', call: 'eth_compile' },
- { name: 'lll', call: 'eth_lll' }
+ { name: 'compilers', call: 'eth_compilers' },
+ { name: 'lll', call: 'eth_lll' },
+ { name: 'solidity', call: 'eth_solidity' }
];
return methods;
};
@@ -290,9 +294,8 @@ var web3 = {
}
};
-var eth = web3.eth;
-setupMethods(eth, ethMethods());
-setupProperties(eth, ethProperties());
+setupMethods(web3.eth, ethMethods());
+setupProperties(web3.eth, ethProperties());
setupMethods(web3.db, dbMethods());
setupMethods(web3.shh, shhMethods());
@@ -452,5 +455,40 @@ 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;