mirror of https://github.com/status-im/op-geth.git
fixed contract.js
This commit is contained in:
parent
0202b05a5d
commit
e45db42e94
|
@ -456,12 +456,24 @@ var abi = require('./abi');
|
|||
* @returns contract object
|
||||
*/
|
||||
|
||||
var contract = function contract (address, desc) {
|
||||
var contract = function (address, desc) {
|
||||
var inputParser = abi.inputParser(desc);
|
||||
var outputParser = abi.outputParser(desc);
|
||||
|
||||
var result = {};
|
||||
|
||||
result.call = function (options) {
|
||||
result._isTransact = false;
|
||||
result._options = options;
|
||||
return result;
|
||||
};
|
||||
|
||||
result.transact = function (options) {
|
||||
result._isTransact = true;
|
||||
result._options = options;
|
||||
return result;
|
||||
};
|
||||
|
||||
desc.forEach(function (method) {
|
||||
|
||||
var displayName = abi.methodDisplayName(method.name);
|
||||
|
@ -472,12 +484,12 @@ var contract = function contract (address, desc) {
|
|||
var signature = abi.methodSignature(method.name);
|
||||
var parsed = inputParser[displayName][typeName].apply(null, params);
|
||||
|
||||
var options = contract._options || {};
|
||||
var options = result._options || {};
|
||||
options.to = address;
|
||||
options.data = signature + parsed;
|
||||
|
||||
var output = "";
|
||||
if (contract._isTransact) {
|
||||
if (result._isTransact) {
|
||||
// it's used byt natspec.js
|
||||
// TODO: figure out better way to solve this
|
||||
web3._currentContractAbi = desc;
|
||||
|
@ -488,6 +500,10 @@ var contract = function contract (address, desc) {
|
|||
output = web3.eth.call(options);
|
||||
}
|
||||
|
||||
// reset
|
||||
result._options = {};
|
||||
result._isTransact = false;
|
||||
|
||||
return outputParser[displayName][typeName](output);
|
||||
};
|
||||
|
||||
|
@ -498,24 +514,10 @@ var contract = function contract (address, desc) {
|
|||
result[displayName][typeName] = impl;
|
||||
|
||||
});
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
var transact = function (options) {
|
||||
contract._isTransact = true;
|
||||
contract._options = options;
|
||||
return contract;
|
||||
};
|
||||
|
||||
var call = function (options) {
|
||||
contract._isTransact = false;
|
||||
contract._options = options;
|
||||
return contract;
|
||||
};
|
||||
|
||||
contract.transact = transact;
|
||||
contract.call = call;
|
||||
|
||||
module.exports = contract;
|
||||
|
||||
|
||||
|
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -45,12 +45,24 @@ var abi = require('./abi');
|
|||
* @returns contract object
|
||||
*/
|
||||
|
||||
var contract = function contract (address, desc) {
|
||||
var contract = function (address, desc) {
|
||||
var inputParser = abi.inputParser(desc);
|
||||
var outputParser = abi.outputParser(desc);
|
||||
|
||||
var result = {};
|
||||
|
||||
result.call = function (options) {
|
||||
result._isTransact = false;
|
||||
result._options = options;
|
||||
return result;
|
||||
};
|
||||
|
||||
result.transact = function (options) {
|
||||
result._isTransact = true;
|
||||
result._options = options;
|
||||
return result;
|
||||
};
|
||||
|
||||
desc.forEach(function (method) {
|
||||
|
||||
var displayName = abi.methodDisplayName(method.name);
|
||||
|
@ -61,12 +73,12 @@ var contract = function contract (address, desc) {
|
|||
var signature = abi.methodSignature(method.name);
|
||||
var parsed = inputParser[displayName][typeName].apply(null, params);
|
||||
|
||||
var options = contract._options || {};
|
||||
var options = result._options || {};
|
||||
options.to = address;
|
||||
options.data = signature + parsed;
|
||||
|
||||
var output = "";
|
||||
if (contract._isTransact) {
|
||||
if (result._isTransact) {
|
||||
// it's used byt natspec.js
|
||||
// TODO: figure out better way to solve this
|
||||
web3._currentContractAbi = desc;
|
||||
|
@ -77,6 +89,10 @@ var contract = function contract (address, desc) {
|
|||
output = web3.eth.call(options);
|
||||
}
|
||||
|
||||
// reset
|
||||
result._options = {};
|
||||
result._isTransact = false;
|
||||
|
||||
return outputParser[displayName][typeName](output);
|
||||
};
|
||||
|
||||
|
@ -87,23 +103,9 @@ var contract = function contract (address, desc) {
|
|||
result[displayName][typeName] = impl;
|
||||
|
||||
});
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
var transact = function (options) {
|
||||
contract._isTransact = true;
|
||||
contract._options = options;
|
||||
return contract;
|
||||
};
|
||||
|
||||
var call = function (options) {
|
||||
contract._isTransact = false;
|
||||
contract._options = options;
|
||||
return contract;
|
||||
};
|
||||
|
||||
contract.transact = transact;
|
||||
contract.call = call;
|
||||
|
||||
module.exports = contract;
|
||||
|
||||
|
|
Loading…
Reference in New Issue