web3-eth-contract
Advanced tools
Comparing version 1.0.0-beta.11 to 1.0.0-beta.12
{ | ||
"name": "web3-eth-contract", | ||
"version": "1.0.0-beta.11", | ||
"version": "1.0.0-beta.12", | ||
"description": "Web3 module to interact with Ethereum smart contracts.", | ||
@@ -10,9 +10,10 @@ "repository": "https://github.com/ethereum/web3.js/tree/master/packages/web3-eth-contract", | ||
"underscore": "1.8.3", | ||
"web3-core-helpers": "^1.0.0-beta.11", | ||
"web3-core-method": "^1.0.0-beta.11", | ||
"web3-core-promievent": "^1.0.0-beta.11", | ||
"web3-core-subscriptions": "^1.0.0-beta.11", | ||
"web3-eth-abi": "^1.0.0-beta.11", | ||
"web3-utils": "^1.0.0-beta.11" | ||
"web3-core": "^1.0.0-beta.12", | ||
"web3-core-helpers": "^1.0.0-beta.12", | ||
"web3-core-method": "^1.0.0-beta.12", | ||
"web3-core-promievent": "^1.0.0-beta.12", | ||
"web3-core-subscriptions": "^1.0.0-beta.12", | ||
"web3-eth-abi": "^1.0.0-beta.12", | ||
"web3-utils": "^1.0.0-beta.12" | ||
} | ||
} |
@@ -32,13 +32,10 @@ # web3-eth-contract | ||
// in node.js | ||
var Eth = require('web3-eth'); | ||
var Web3EthContract = require('web3-eth-contract'); | ||
var eth = new Eth('ws://localhost:8546'); | ||
// set provider for all later instances to use | ||
Web3EthContract.setProvider('ws://localhost:8546'); | ||
// add the eth package | ||
Web3EthContract.prototype._eth = this; | ||
var contract = new Web3EthContract(jsonInterface, address); | ||
contract.methods.somFunc().send({from: ....}) | ||
.on('receipt', funciton(){ | ||
.on('receipt', function(){ | ||
... | ||
@@ -45,0 +42,0 @@ }); |
101
src/index.js
@@ -23,6 +23,6 @@ /* | ||
* var Contract = require('web3-eth-contract'); | ||
* Contract.prototype._eth = needsAEthInstance; | ||
* Contract.setProvider('ws://localhost:8546'); | ||
* var contract = new Contract(abi, address, ...); | ||
* | ||
* @author Fabian Vogelsteller <fabian@frozeman.de> | ||
* @author Fabian Vogelsteller <fabian@ethereum.org> | ||
* @date 2017 | ||
@@ -36,2 +36,3 @@ */ | ||
var _ = require('underscore'); | ||
var core = require('web3-core'); | ||
var Method = require('web3-core-method'); | ||
@@ -59,2 +60,9 @@ var utils = require('web3-utils'); | ||
// sets _requestmanager | ||
core.packageInit(this, [Contract.currentProvider]); | ||
this.clearSubscriptions = this._requestManager.clearSubscriptions; | ||
if(!(this instanceof Contract)) { | ||
@@ -68,3 +76,33 @@ throw new Error('Please use the "new" keyword to instantiate a web3.eth.contract() object!'); | ||
// add custom send Methods | ||
var _ethereumCall = [ | ||
new Method({ | ||
name: 'estimateGas', | ||
call: 'eth_estimateGas', | ||
params: 1, | ||
inputFormatter: [formatters.inputCallFormatter], | ||
outputFormatter: utils.hexToNumber | ||
}), | ||
new Method({ | ||
name: 'call', | ||
call: 'eth_call', | ||
params: 2, | ||
inputFormatter: [formatters.inputCallFormatter, formatters.inputDefaultBlockNumberFormatter] | ||
}), | ||
new Method({ | ||
name: 'sendTransaction', | ||
call: 'eth_sendTransaction', | ||
params: 1, | ||
inputFormatter: [formatters.inputTransactionFormatter] | ||
}) | ||
]; | ||
// attach methods to this._ethereumCall | ||
this._ethereumCall = {}; | ||
_.each(_ethereumCall, function (method) { | ||
method.attachToObject(_this._ethereumCall); | ||
method.setRequestManager(_this._requestManager, Contract._ethAccounts); // second param means is eth.accounts (necessary for wallet signing) | ||
}); | ||
// create the options object | ||
@@ -175,3 +213,6 @@ this.options = {}; | ||
Contract.prototype._eth = {}; // eth is attached here in web3-eth/src/index.js | ||
Contract.setProvider = function(provider, accounts) { | ||
Contract.currentProvider = provider; | ||
Contract._ethAccounts = accounts; | ||
}; | ||
@@ -187,3 +228,3 @@ | ||
Contract.prototype._getCallback = function getCallback(args) { | ||
if (_.isFunction(args[args.length - 1])) { | ||
if (args && _.isFunction(args[args.length - 1])) { | ||
return args.pop(); // modify the args array! | ||
@@ -355,3 +396,3 @@ } | ||
var methodSignature = this._method.signature, | ||
args = this.arguments; | ||
args = this.arguments || []; | ||
@@ -363,7 +404,9 @@ var signature = false, | ||
}).map(function (json) { | ||
if(json.inputs.length !== args.length) { | ||
throw new Error('The number of arguments is not matching the methods required number. You need to pass '+ json.inputs.length +' arguments.'); | ||
var inputLength = (_.isArray(json.inputs)) ? json.inputs.length : 0; | ||
if (inputLength !== args.length) { | ||
throw new Error('The number of arguments is not matching the methods required number. You need to pass '+ inputLength +' arguments.'); | ||
} | ||
if(json.type === 'function') { | ||
if (json.type === 'function') { | ||
signature = json.signature; | ||
@@ -586,3 +629,3 @@ } | ||
type: 'eth', | ||
requestManager: this._eth._requestManager | ||
requestManager: this._requestManager | ||
}); | ||
@@ -613,3 +656,3 @@ subscription.subscribe('logs', subOptions.params, subOptions.callback || function () {}); | ||
}); | ||
getPastLogs.setRequestManager(this._eth._requestManager); | ||
getPastLogs.setRequestManager(this._requestManager); | ||
var call = getPastLogs.buildCall(); | ||
@@ -630,2 +673,3 @@ | ||
Contract.prototype._createTxObject = function _createTxObject(){ | ||
var args = Array.prototype.slice.call(arguments); | ||
var txObject = {}; | ||
@@ -645,15 +689,14 @@ | ||
if (arguments.length) { | ||
if (arguments.length !== this.method.inputs.length) { | ||
throw errors.InvalidNumberOfParams(arguments.length, this.method.inputs.length, this.method.name); | ||
} | ||
if (args.length !== this.method.inputs.length) { | ||
throw errors.InvalidNumberOfParams(args.length, this.method.inputs.length, this.method.name); | ||
} | ||
txObject.arguments = arguments; | ||
} | ||
txObject.arguments = args; | ||
txObject._method = this.method; | ||
txObject._parent = this.parent; | ||
if(this.deployData) | ||
if(this.deployData) { | ||
txObject._deployData = this.deployData; | ||
} | ||
@@ -741,3 +784,3 @@ return txObject; | ||
return this._parent._eth.estimateGas(args.options, args.callback); | ||
return this._parent._ethereumCall.estimateGas(args.options, args.callback); | ||
@@ -748,22 +791,12 @@ case 'call': | ||
this._parent._eth.call(args.options, args.defaultBlock, function (err, result) { | ||
// decode result | ||
// add output formatter for decoding | ||
this._parent._ethereumCall.call.method.outputFormatter = function (result) { | ||
if(result) { | ||
result = _this._parent._decodeMethodReturn(_this._method.outputs, result); | ||
} | ||
return result; | ||
}; | ||
// throw error | ||
if(err) { | ||
return utils._fireError(err, null, defer.reject, args.callback); | ||
} | ||
return this._parent._ethereumCall.call(args.options, args.defaultBlock, args.callback); | ||
if(_.isFunction(args.callback)) { | ||
args.callback(null, result); | ||
} | ||
defer.resolve(result); | ||
}); | ||
return defer.eventEmitter; | ||
case 'send': | ||
@@ -817,3 +850,3 @@ | ||
return this._parent._eth.sendTransaction.apply(extraFormatters, [args.options, args.callback]); | ||
return this._parent._ethereumCall.sendTransaction.apply(extraFormatters, [args.options, args.callback]); | ||
@@ -820,0 +853,0 @@ } |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
28488
667
8
49
+ Addedweb3-core@^1.0.0-beta.12
+ Added@types/bn.js@5.1.6(transitive)
+ Added@types/node@12.20.55(transitive)
+ Addedabortcontroller-polyfill@1.7.5(transitive)
+ Addedavailable-typed-arrays@1.0.7(transitive)
+ Addedbignumber.js@9.1.2(transitive)
+ Addedbufferutil@4.0.8(transitive)
+ Addedcall-bind@1.0.7(transitive)
+ Addedcross-fetch@4.0.0(transitive)
+ Addedd@1.0.2(transitive)
+ Addeddebug@2.6.9(transitive)
+ Addeddefine-data-property@1.1.4(transitive)
+ Addedes-define-property@1.0.0(transitive)
+ Addedes-errors@1.3.0(transitive)
+ Addedes5-ext@0.10.64(transitive)
+ Addedes6-iterator@2.0.3(transitive)
+ Addedes6-promise@4.2.8(transitive)
+ Addedes6-symbol@3.1.4(transitive)
+ Addedesniff@2.0.1(transitive)
+ Addedevent-emitter@0.3.5(transitive)
+ Addedext@1.7.0(transitive)
+ Addedfor-each@0.3.3(transitive)
+ Addedfunction-bind@1.1.2(transitive)
+ Addedget-intrinsic@1.2.4(transitive)
+ Addedgopd@1.0.1(transitive)
+ Addedhas-property-descriptors@1.0.2(transitive)
+ Addedhas-proto@1.0.3(transitive)
+ Addedhas-symbols@1.0.3(transitive)
+ Addedhas-tostringtag@1.0.2(transitive)
+ Addedhasown@2.0.2(transitive)
+ Addedhttp-https@1.0.0(transitive)
+ Addedis-arguments@1.1.1(transitive)
+ Addedis-callable@1.2.7(transitive)
+ Addedis-generator-function@1.0.10(transitive)
+ Addedis-typed-array@1.1.13(transitive)
+ Addedis-typedarray@1.0.0(transitive)
+ Addedms@2.0.0(transitive)
+ Addednext-tick@1.1.0(transitive)
+ Addednode-fetch@2.7.0(transitive)
+ Addednode-gyp-build@4.8.2(transitive)
+ Addedoboe@2.1.5(transitive)
+ Addedpossible-typed-array-names@1.0.0(transitive)
+ Addedset-function-length@1.2.2(transitive)
+ Addedtr46@0.0.3(transitive)
+ Addedtype@2.7.3(transitive)
+ Addedtypedarray-to-buffer@3.1.5(transitive)
+ Addedutf-8-validate@5.0.10(transitive)
+ Addedutil@0.12.5(transitive)
+ Addedweb3-core@1.10.4(transitive)
+ Addedweb3-core-requestmanager@1.10.4(transitive)
+ Addedweb3-providers-http@1.10.4(transitive)
+ Addedweb3-providers-ipc@1.10.4(transitive)
+ Addedweb3-providers-ws@1.10.4(transitive)
+ Addedwebidl-conversions@3.0.1(transitive)
+ Addedwebsocket@1.0.35(transitive)
+ Addedwhatwg-url@5.0.0(transitive)
+ Addedwhich-typed-array@1.1.15(transitive)
+ Addedyaeti@0.0.6(transitive)
Updatedweb3-eth-abi@^1.0.0-beta.12
Updatedweb3-utils@^1.0.0-beta.12