From 3451f2608682bd044d7b7165b0d3aa640e8fd81f Mon Sep 17 00:00:00 2001 From: Marek Kotewicz Date: Wed, 12 Nov 2014 20:39:13 +0100 Subject: changes to make everything work --- lib/main.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'lib/main.js') diff --git a/lib/main.js b/lib/main.js index c3ed22f8b..d7f8531d2 100644 --- a/lib/main.js +++ b/lib/main.js @@ -84,8 +84,11 @@ 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' }, + { name: 'contractCreate', call: 'eth_contractCreate' }, + { name: 'contractCall', call: 'eth_contractCall' } ]; return methods; }; -- cgit v1.2.3 From 0e67fcd361ea1681f989077969417e166ea8453e Mon Sep 17 00:00:00 2001 From: Marek Kotewicz Date: Thu, 13 Nov 2014 12:24:34 +0100 Subject: contract object --- lib/main.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'lib/main.js') diff --git a/lib/main.js b/lib/main.js index d7f8531d2..fc0170287 100644 --- a/lib/main.js +++ b/lib/main.js @@ -86,9 +86,7 @@ var ethMethods = function () { { name: 'uncle', call: uncleCall }, { name: 'compilers', call: 'eth_compilers' }, { name: 'lll', call: 'eth_lll' }, - { name: 'solidity', call: 'eth_solidity' }, - { name: 'contractCreate', call: 'eth_contractCreate' }, - { name: 'contractCall', call: 'eth_contractCall' } + { name: 'solidity', call: 'eth_solidity' } ]; return methods; }; -- cgit v1.2.3 From b1428555d10c5449e0f91f53f1dd0e8d1a1f9732 Mon Sep 17 00:00:00 2001 From: Marek Kotewicz Date: Thu, 13 Nov 2014 18:29:31 +0100 Subject: added storageAt --- lib/main.js | 1 + 1 file changed, 1 insertion(+) (limited to 'lib/main.js') diff --git a/lib/main.js b/lib/main.js index fc0170287..e2caf6bc3 100644 --- a/lib/main.js +++ b/lib/main.js @@ -77,6 +77,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' }, -- cgit v1.2.3 From ea8db7a4aecb034c6a967ccd3b17c50f423cb77c Mon Sep 17 00:00:00 2001 From: Marek Kotewicz Date: Fri, 14 Nov 2014 13:11:47 +0100 Subject: improved contracts interface --- lib/main.js | 42 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 39 insertions(+), 3 deletions(-) (limited to 'lib/main.js') diff --git a/lib/main.js b/lib/main.js index e2caf6bc3..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); @@ -292,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()); @@ -454,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; -- cgit v1.2.3