aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/abi.js4
-rw-r--r--lib/contract.js38
-rw-r--r--lib/web3.js10
3 files changed, 46 insertions, 6 deletions
diff --git a/lib/abi.js b/lib/abi.js
index 21580347d..d81c2f0c3 100644
--- a/lib/abi.js
+++ b/lib/abi.js
@@ -128,7 +128,7 @@ var formatInputReal = function (value) {
var dynamicTypeBytes = function (type, value) {
// TODO: decide what to do with array of strings
- if (arrayType(type) || prefixedType('string')(type))
+ if (arrayType(type) || type === 'string') // only string itself that is dynamic; stringX is static length.
return formatInputInt(value.length);
return "";
};
@@ -251,7 +251,7 @@ var formatOutputAddress = function (value) {
};
var dynamicBytesLength = function (type) {
- if (arrayType(type) || prefixedType('string')(type))
+ if (arrayType(type) || type === 'string') // only string itself that is dynamic; stringX is static length.
return ETH_PADDING * 2;
return 0;
};
diff --git a/lib/contract.js b/lib/contract.js
index 498908d37..efee00cd1 100644
--- a/lib/contract.js
+++ b/lib/contract.js
@@ -37,7 +37,7 @@ var abi = require('./abi');
* var myContract = web3.eth.contract('0x0123123121', abi); // creation of contract object
*
* myContract.myMethod('this is test string param for call'); // myMethod call (implicit, default)
- * myContract.myMethod('this is test string param for call').call(); // myMethod call (explicit)
+ * myContract.call().myMethod('this is test string param for call'); // myMethod call (explicit)
* myContract.transact().myMethod('this is test string param for transact'); // myMethod transact
*
* @param address - address of the contract, which should be called
@@ -46,6 +46,18 @@ var abi = require('./abi');
*/
var contract = function (address, desc) {
+
+ desc.forEach(function (method) {
+ // workaround for invalid assumption that method.name is the full anonymous prototype of the method.
+ // it's not. it's just the name. the rest of the code assumes it's actually the anonymous
+ // prototype, so we make it so as a workaround.
+ if (method.name.indexOf('(') === -1) {
+ var displayName = method.name;
+ var typeName = method.inputs.map(function(i){return i.type; }).join();
+ method.name = displayName + '(' + typeName + ')';
+ }
+ });
+
var inputParser = abi.inputParser(desc);
var outputParser = abi.outputParser(desc);
@@ -63,6 +75,15 @@ var contract = function (address, desc) {
return result;
};
+ result._options = {};
+ ['gas', 'gasPrice', 'value', 'from'].forEach(function(p) {
+ result[p] = function (v) {
+ result._options[p] = v;
+ return result;
+ };
+ });
+
+
desc.forEach(function (method) {
var displayName = abi.methodDisplayName(method.name);
@@ -77,11 +98,12 @@ var contract = function (address, desc) {
options.to = address;
options.data = signature + parsed;
- var isTransact = result._isTransact;
+ var isTransact = result._isTransact === true || (result._isTransact !== false && !method.constant);
+ var collapse = options.collapse !== false;
// reset
result._options = {};
- result._isTransact = false;
+ result._isTransact = null;
if (isTransact) {
// it's used byt natspec.js
@@ -95,7 +117,15 @@ var contract = function (address, desc) {
}
var output = web3.eth.call(options);
- return outputParser[displayName][typeName](output);
+ var ret = outputParser[displayName][typeName](output);
+ if (collapse)
+ {
+ if (ret.length === 1)
+ ret = ret[0];
+ else if (ret.length === 0)
+ ret = null;
+ }
+ return ret;
};
if (result[displayName] === undefined) {
diff --git a/lib/web3.js b/lib/web3.js
index 33e92ea92..7cf624c9c 100644
--- a/lib/web3.js
+++ b/lib/web3.js
@@ -82,6 +82,7 @@ var ethMethods = function () {
{ name: 'transaction', call: transactionCall },
{ name: 'uncle', call: uncleCall },
{ name: 'compilers', call: 'eth_compilers' },
+ { name: 'flush', call: 'eth_flush' },
{ name: 'lll', call: 'eth_lll' },
{ name: 'solidity', call: 'eth_solidity' },
{ name: 'serpent', call: 'eth_serpent' },
@@ -267,6 +268,15 @@ var web3 = {
/// eth object prototype
eth: {
+ contractFromAbi: function (abi) {
+ return function(addr) {
+ // Default to address of Config. TODO: rremove prior to genesis.
+ addr = addr || '0xc6d9d2cd449a754c494264e1809c50e34d64562b';
+ var ret = web3.eth.contract(addr, abi);
+ ret.address = addr;
+ return ret;
+ };
+ },
watch: function (params) {
return new web3.filter(params, ethWatch);
}