web3-eth-contract
Advanced tools
Comparing version 1.0.0-beta.48 to 1.0.0-beta.49
@@ -8,6 +8,4 @@ 'use strict'; | ||
var Utils = require('web3-utils'); | ||
var web3Providers = require('web3-providers'); | ||
var web3CoreHelpers = require('web3-core-helpers'); | ||
var web3EthAbi = require('web3-eth-abi'); | ||
var web3CorePromievent = require('web3-core-promievent'); | ||
var isFunction = _interopDefault(require('lodash/isFunction')); | ||
@@ -20,4 +18,2 @@ var isUndefined = _interopDefault(require('lodash/isUndefined')); | ||
var web3CoreSubscriptions = require('web3-core-subscriptions'); | ||
var _regeneratorRuntime = _interopDefault(require('@babel/runtime/regenerator')); | ||
var _asyncToGenerator = _interopDefault(require('@babel/runtime/helpers/asyncToGenerator')); | ||
var _classCallCheck = _interopDefault(require('@babel/runtime/helpers/classCallCheck')); | ||
@@ -27,4 +23,4 @@ var _createClass = _interopDefault(require('@babel/runtime/helpers/createClass')); | ||
var _getPrototypeOf = _interopDefault(require('@babel/runtime/helpers/getPrototypeOf')); | ||
var _assertThisInitialized = _interopDefault(require('@babel/runtime/helpers/assertThisInitialized')); | ||
var _inherits = _interopDefault(require('@babel/runtime/helpers/inherits')); | ||
var _assertThisInitialized = _interopDefault(require('@babel/runtime/helpers/assertThisInitialized')); | ||
var web3Core = require('web3-core'); | ||
@@ -121,11 +117,2 @@ | ||
}, { | ||
key: "givenParametersLengthIsValid", | ||
value: function givenParametersLengthIsValid() { | ||
var inputLength = this.getInputLength(); | ||
if (this.contractMethodParameters.length === inputLength) { | ||
return true; | ||
} | ||
throw new Error("The number of arguments is not matching the methods required number. You need to pass ".concat(inputLength, " arguments.")); | ||
} | ||
}, { | ||
key: "getIndexedInputs", | ||
@@ -194,10 +181,9 @@ value: function getIndexedInputs() { | ||
var _this = this; | ||
var indexedInputs = abiItemModel.getIndexedInputs(); | ||
var topics = []; | ||
indexedInputs.forEach(function (indexedInput) { | ||
if (filter[indexedInput.name]) { | ||
var filterItem = filter[indexedInput.name]; | ||
abiItemModel.getIndexedInputs().forEach(function (input) { | ||
if (filter[input.name]) { | ||
var filterItem = filter[input.name]; | ||
if (isArray(filterItem)) { | ||
filterItem = filterItem.map(function (item) { | ||
return _this.abiCoder.encodeParameter(indexedInput.type, item); | ||
return _this.abiCoder.encodeParameter(input.type, item); | ||
}); | ||
@@ -207,4 +193,6 @@ topics.push(filterItem); | ||
} | ||
topics.push(_this.abiCoder.encodeParameter(indexedInput.type, filterItem)); | ||
topics.push(_this.abiCoder.encodeParameter(input.type, filterItem)); | ||
return; | ||
} | ||
topics.push(null); | ||
}); | ||
@@ -423,8 +411,8 @@ return topics; | ||
} | ||
if (typeof options.filter !== 'undefined') { | ||
options.topics = options.topics.concat(this.eventFilterEncoder.encode(abiItemModel, options.filter)); | ||
} | ||
if (!abiItemModel.anonymous) { | ||
options.topics.unshift(abiItemModel.signature); | ||
} | ||
if (typeof options.filter !== 'undefined') { | ||
options.topics = options.topics.concat(this.eventFilterEncoder.encode(abiItemModel, options.filter)); | ||
} | ||
if (!options.address) { | ||
@@ -491,3 +479,3 @@ options.address = contract.address; | ||
if (methodArguments[0]['data']) { | ||
target.contract.options.data = methodArguments[0]['data']; | ||
target.contract.data = methodArguments[0]['data']; | ||
} | ||
@@ -504,10 +492,7 @@ if (methodArguments[0]['arguments']) { | ||
var abiItemModelFound = abiItemModel.some(function (model) { | ||
model.contractMethodParameters = methodArguments; | ||
try { | ||
model.givenParametersLengthIsValid(); | ||
} catch (error) { | ||
return false; | ||
if (model.getInputLength() === methodArguments.length) { | ||
abiItemModel = model; | ||
return true; | ||
} | ||
abiItemModel = model; | ||
return true; | ||
return false; | ||
}); | ||
@@ -517,3 +502,2 @@ if (!abiItemModelFound) { | ||
} | ||
return anonymousFunction; | ||
} | ||
@@ -541,3 +525,3 @@ abiItemModel.contractMethodParameters = methodArguments; | ||
anonymousFunction.encodeABI = function () { | ||
return target.methodEncoder.encode(abiItemModel, target.contract.options.data); | ||
return target.methodEncoder.encode(abiItemModel, target.contract.data); | ||
}; | ||
@@ -559,16 +543,13 @@ return anonymousFunction; | ||
} catch (error) { | ||
var promiEvent = new web3CorePromievent.PromiEvent(); | ||
var promiEvent = new web3CoreMethod.PromiEvent(); | ||
method = this.methodFactory.createMethodByRequestType(abiItemModel, this.contract, requestType); | ||
method.arguments = methodArguments; | ||
promiEvent.reject(error); | ||
promiEvent.emit('error', error); | ||
method.setArguments(methodArguments); | ||
if (isFunction(method.callback)) { | ||
method.callback(error, null); | ||
} | ||
promiEvent.reject(error); | ||
promiEvent.emit('error', error); | ||
return promiEvent; | ||
} | ||
if (requestType === 'call' || requestType === 'estimate') { | ||
return method.execute(this.contract); | ||
} | ||
return method.execute(this.contract, new web3CorePromievent.PromiEvent()); | ||
return method.execute(); | ||
} | ||
@@ -578,9 +559,8 @@ }, { | ||
value: function createMethod(abiItemModel, methodArguments, requestType) { | ||
abiItemModel.givenParametersLengthIsValid(); | ||
var method = this.methodFactory.createMethodByRequestType(abiItemModel, this.contract, requestType); | ||
method.arguments = methodArguments; | ||
method.setArguments(methodArguments); | ||
if (typeof method.parameters[0] === 'undefined') { | ||
method.parameters[0] = {}; | ||
} | ||
method.parameters[0]['data'] = this.methodEncoder.encode(abiItemModel, this.contract.options.data); | ||
method.parameters[0]['data'] = this.methodEncoder.encode(abiItemModel, this.contract.data); | ||
method.parameters[0] = this.methodOptionsMapper.map(this.contract, method.parameters[0]); | ||
@@ -653,8 +633,8 @@ this.methodOptionsValidator.validate(abiItemModel, method); | ||
var SendContractMethod = | ||
function (_SendTransactionMetho) { | ||
_inherits(SendContractMethod, _SendTransactionMetho); | ||
function SendContractMethod(utils, formatters, transactionConfirmationWorkflow, sendRawTransactionMethod, chainIdMethod, getTransactionCountMethod, allEventsLogDecoder, abiModel) { | ||
function (_EthSendTransactionMe) { | ||
_inherits(SendContractMethod, _EthSendTransactionMe); | ||
function SendContractMethod(utils, formatters, moduleInstance, transactionObserver, chainIdMethod, getTransactionCountMethod, sendRawTransactionMethod, allEventsLogDecoder, abiModel) { | ||
var _this; | ||
_classCallCheck(this, SendContractMethod); | ||
_this = _possibleConstructorReturn(this, _getPrototypeOf(SendContractMethod).call(this, utils, formatters, transactionConfirmationWorkflow, sendRawTransactionMethod, chainIdMethod, getTransactionCountMethod)); | ||
_this = _possibleConstructorReturn(this, _getPrototypeOf(SendContractMethod).call(this, utils, formatters, moduleInstance, transactionObserver, chainIdMethod, getTransactionCountMethod, sendRawTransactionMethod)); | ||
_this.allEventsLogDecoder = allEventsLogDecoder; | ||
@@ -692,3 +672,3 @@ _this.abiModel = abiModel; | ||
return SendContractMethod; | ||
}(web3CoreMethod.SendTransactionMethod); | ||
}(web3CoreMethod.EthSendTransactionMethod); | ||
@@ -731,3 +711,3 @@ var MethodOptionsValidator = | ||
value: function isValueValid(abiItemModel, method) { | ||
return !abiItemModel.payable && !method.parameters[0].value > 0 || abiItemModel.payable && method.parameters[0].value > 0; | ||
return abiItemModel.payable || !abiItemModel.payable && !method.parameters[0].value; | ||
} | ||
@@ -741,6 +721,6 @@ }]); | ||
_inherits(CallContractMethod, _CallMethod); | ||
function CallContractMethod(utils, formatters, abiCoder, abiItemModel) { | ||
function CallContractMethod(utils, formatters, moduleInstance, abiCoder, abiItemModel) { | ||
var _this; | ||
_classCallCheck(this, CallContractMethod); | ||
_this = _possibleConstructorReturn(this, _getPrototypeOf(CallContractMethod).call(this, utils, formatters)); | ||
_this = _possibleConstructorReturn(this, _getPrototypeOf(CallContractMethod).call(this, utils, formatters, moduleInstance)); | ||
_this.abiCoder = abiCoder; | ||
@@ -767,10 +747,7 @@ _this.abiItemModel = abiItemModel; | ||
var ContractDeployMethod = | ||
function (_SendTransactionMetho) { | ||
_inherits(ContractDeployMethod, _SendTransactionMetho); | ||
function ContractDeployMethod(utils, formatters, transactionConfirmationWorkflow, sendRawTransactionMethod, chainIdMethod, getTransactionCountMethod, contract) { | ||
var _this; | ||
function (_EthSendTransactionMe) { | ||
_inherits(ContractDeployMethod, _EthSendTransactionMe); | ||
function ContractDeployMethod(utils, formatters, moduleInstance, transactionObserver, chainIdMethod, getTransactionCountMethod, sendRawTransactionMethod) { | ||
_classCallCheck(this, ContractDeployMethod); | ||
_this = _possibleConstructorReturn(this, _getPrototypeOf(ContractDeployMethod).call(this, utils, formatters, transactionConfirmationWorkflow, sendRawTransactionMethod, chainIdMethod, getTransactionCountMethod)); | ||
_this.contract = contract; | ||
return _this; | ||
return _possibleConstructorReturn(this, _getPrototypeOf(ContractDeployMethod).call(this, utils, formatters, moduleInstance, transactionObserver, chainIdMethod, getTransactionCountMethod, sendRawTransactionMethod)); | ||
} | ||
@@ -786,3 +763,3 @@ _createClass(ContractDeployMethod, [{ | ||
value: function afterExecution(response) { | ||
var clonedContract = this.contract.clone(); | ||
var clonedContract = this.moduleInstance.clone(); | ||
clonedContract.address = response.contractAddress; | ||
@@ -793,3 +770,3 @@ return clonedContract; | ||
return ContractDeployMethod; | ||
}(web3CoreMethod.SendTransactionMethod); | ||
}(web3CoreMethod.EthSendTransactionMethod); | ||
@@ -799,6 +776,6 @@ var PastEventLogsMethod = | ||
_inherits(PastEventLogsMethod, _GetPastLogsMethod); | ||
function PastEventLogsMethod(utils, formatters, eventLogDecoder, abiItemModel, eventOptionsMapper) { | ||
function PastEventLogsMethod(utils, formatters, moduleInstance, eventLogDecoder, abiItemModel, eventOptionsMapper) { | ||
var _this; | ||
_classCallCheck(this, PastEventLogsMethod); | ||
_this = _possibleConstructorReturn(this, _getPrototypeOf(PastEventLogsMethod).call(this, utils, formatters)); | ||
_this = _possibleConstructorReturn(this, _getPrototypeOf(PastEventLogsMethod).call(this, utils, formatters, moduleInstance)); | ||
_this.abiItemModel = abiItemModel; | ||
@@ -814,2 +791,5 @@ _this.eventLogDecoder = eventLogDecoder; | ||
this.parameters[0] = this.eventOptionsMapper.map(this.abiItemModel, moduleInstance, this.parameters[0]); | ||
if (this.parameters[0].filter) { | ||
delete this.parameters[0].filter; | ||
} | ||
} | ||
@@ -832,6 +812,6 @@ }, { | ||
_inherits(AllPastEventLogsMethod, _GetPastLogsMethod); | ||
function AllPastEventLogsMethod(utils, formatters, allEventsLogDecoder, abiModel, allEventsOptionsMapper) { | ||
function AllPastEventLogsMethod(utils, formatters, moduleInstance, allEventsLogDecoder, abiModel, allEventsOptionsMapper) { | ||
var _this; | ||
_classCallCheck(this, AllPastEventLogsMethod); | ||
_this = _possibleConstructorReturn(this, _getPrototypeOf(AllPastEventLogsMethod).call(this, utils, formatters)); | ||
_this = _possibleConstructorReturn(this, _getPrototypeOf(AllPastEventLogsMethod).call(this, utils, formatters, moduleInstance)); | ||
_this.abiModel = abiModel; | ||
@@ -847,2 +827,5 @@ _this.allEventsLogDecoder = allEventsLogDecoder; | ||
this.parameters[0] = this.allEventsOptionsMapper.map(this.abiModel, moduleInstance, this.parameters[0]); | ||
if (this.parameters[0].filter) { | ||
delete this.parameters[0].filter; | ||
} | ||
} | ||
@@ -864,3 +847,3 @@ }, { | ||
function () { | ||
function MethodFactory(utils, formatters, contractModuleFactory, methodModuleFactory, abiCoder) { | ||
function MethodFactory(utils, formatters, contractModuleFactory, abiCoder) { | ||
_classCallCheck(this, MethodFactory); | ||
@@ -870,3 +853,2 @@ this.utils = utils; | ||
this.contractModuleFactory = contractModuleFactory; | ||
this.methodModuleFactory = methodModuleFactory; | ||
this.abiCoder = abiCoder; | ||
@@ -880,9 +862,9 @@ } | ||
case 'call': | ||
rpcMethod = this.createCallContractMethod(abiItem); | ||
rpcMethod = this.createCallContractMethod(abiItem, contract); | ||
break; | ||
case 'send': | ||
rpcMethod = this.createSendContractMethod(abiItem, contract.abiModel); | ||
rpcMethod = this.createSendContractMethod(contract); | ||
break; | ||
case 'estimate': | ||
rpcMethod = this.createEstimateGasMethod(); | ||
rpcMethod = this.createEstimateGasMethod(contract); | ||
break; | ||
@@ -900,20 +882,20 @@ case 'contract-deployment': | ||
key: "createPastEventLogsMethod", | ||
value: function createPastEventLogsMethod(abiItem) { | ||
return new PastEventLogsMethod(this.utils, this.formatters, this.contractModuleFactory.createEventLogDecoder(), abiItem, this.contractModuleFactory.createEventOptionsMapper()); | ||
value: function createPastEventLogsMethod(abiItem, contract) { | ||
return new PastEventLogsMethod(this.utils, this.formatters, contract, this.contractModuleFactory.createEventLogDecoder(), abiItem, this.contractModuleFactory.createEventOptionsMapper()); | ||
} | ||
}, { | ||
key: "createAllPastEventLogsMethod", | ||
value: function createAllPastEventLogsMethod(abiModel) { | ||
return new AllPastEventLogsMethod(this.utils, this.formatters, this.contractModuleFactory.createAllEventsLogDecoder(), abiModel, this.contractModuleFactory.createAllEventsOptionsMapper()); | ||
value: function createAllPastEventLogsMethod(abiModel, contract) { | ||
return new AllPastEventLogsMethod(this.utils, this.formatters, contract, this.contractModuleFactory.createAllEventsLogDecoder(), abiModel, this.contractModuleFactory.createAllEventsOptionsMapper()); | ||
} | ||
}, { | ||
key: "createCallContractMethod", | ||
value: function createCallContractMethod(abiItem) { | ||
return new CallContractMethod(this.utils, this.formatters, this.abiCoder, abiItem); | ||
value: function createCallContractMethod(abiItem, contract) { | ||
return new CallContractMethod(this.utils, this.formatters, contract, this.abiCoder, abiItem); | ||
} | ||
}, { | ||
key: "createSendContractMethod", | ||
value: function createSendContractMethod(abiItem, abiModel) { | ||
var transactionConfirmationWorkflow = this.methodModuleFactory.createTransactionConfirmationWorkflow(); | ||
return new SendContractMethod(this.utils, this.formatters, transactionConfirmationWorkflow, new web3CoreMethod.SendRawTransactionMethod(this.utils, this.formatters, transactionConfirmationWorkflow), new web3CoreMethod.ChainIdMethod(this.utils, this.formatters), new web3CoreMethod.GetTransactionCountMethod(this.utils, this.formatters), this.contractModuleFactory.createAllEventsLogDecoder(), abiModel); | ||
value: function createSendContractMethod(contract) { | ||
var transactionObserver = new web3CoreMethod.TransactionObserver(contract.currentProvider, this.getTransactionObserverTimeout(contract), contract.transactionConfirmationBlocks, new web3CoreMethod.GetTransactionReceiptMethod(this.utils, this.formatters, contract), new web3CoreMethod.GetBlockByHashMethod(this.utils, this.formatters, contract), new web3CoreSubscriptions.NewHeadsSubscription(this.utils, this.formatters, contract)); | ||
return new SendContractMethod(this.utils, this.formatters, contract, transactionObserver, new web3CoreMethod.ChainIdMethod(this.utils, this.formatters, contract), new web3CoreMethod.GetTransactionCountMethod(this.utils, this.formatters, contract), new web3CoreMethod.SendRawTransactionMethod(this.utils, this.formatters, contract, transactionObserver), this.contractModuleFactory.createAllEventsLogDecoder(), contract.abiModel); | ||
} | ||
@@ -923,10 +905,19 @@ }, { | ||
value: function createContractDeployMethod(contract) { | ||
var transactionConfirmationWorkflow = this.methodModuleFactory.createTransactionConfirmationWorkflow(); | ||
return new ContractDeployMethod(this.utils, this.formatters, transactionConfirmationWorkflow, new web3CoreMethod.SendRawTransactionMethod(this.utils, this.formatters, transactionConfirmationWorkflow), new web3CoreMethod.ChainIdMethod(this.utils, this.formatters), new web3CoreMethod.GetTransactionCountMethod(this.utils, this.formatters), contract); | ||
return new ContractDeployMethod(this.utils, this.formatters, contract, new web3CoreMethod.TransactionObserver(contract.currentProvider, this.getTransactionObserverTimeout(contract), contract.transactionConfirmationBlocks, new web3CoreMethod.GetTransactionReceiptMethod(this.utils, this.formatters, contract), new web3CoreMethod.GetBlockByHashMethod(this.utils, this.formatters, contract), new web3CoreSubscriptions.NewHeadsSubscription(this.utils, this.formatters, contract)), new web3CoreMethod.ChainIdMethod(this.utils, this.formatters, contract), new web3CoreMethod.GetTransactionCountMethod(this.utils, this.formatters, contract), new web3CoreMethod.SendRawTransactionMethod(this.utils, this.formatters, contract)); | ||
} | ||
}, { | ||
key: "createEstimateGasMethod", | ||
value: function createEstimateGasMethod() { | ||
return new web3CoreMethod.EstimateGasMethod(this.utils, this.formatters); | ||
value: function createEstimateGasMethod(contract) { | ||
return new web3CoreMethod.EstimateGasMethod(this.utils, this.formatters, contract); | ||
} | ||
}, { | ||
key: "getTransactionObserverTimeout", | ||
value: function getTransactionObserverTimeout(contract) { | ||
var timeout = contract.transactionBlockTimeout; | ||
var providerName = contract.currentProvider.constructor.name; | ||
if (providerName === 'HttpProvider' || providerName === 'CustomProvider') { | ||
timeout = contract.transactionPollingTimeout; | ||
} | ||
return timeout; | ||
} | ||
}]); | ||
@@ -1000,9 +991,9 @@ return MethodFactory; | ||
_inherits(AbstractContract, _AbstractWeb3Module); | ||
function AbstractContract(provider, providersModuleFactory, methodModuleFactory, contractModuleFactory, accounts, abiCoder, utils, formatters) { | ||
function AbstractContract(provider, contractModuleFactory, accounts, abiCoder, utils, formatters) { | ||
var _this; | ||
var abi = arguments.length > 8 && arguments[8] !== undefined ? arguments[8] : []; | ||
var address = arguments.length > 9 && arguments[9] !== undefined ? arguments[9] : ''; | ||
var options = arguments.length > 10 && arguments[10] !== undefined ? arguments[10] : {}; | ||
var abi = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : []; | ||
var address = arguments.length > 7 && arguments[7] !== undefined ? arguments[7] : ''; | ||
var options = arguments.length > 8 && arguments[8] !== undefined ? arguments[8] : {}; | ||
_classCallCheck(this, AbstractContract); | ||
_this = _possibleConstructorReturn(this, _getPrototypeOf(AbstractContract).call(this, provider, providersModuleFactory, methodModuleFactory, null, options)); | ||
_this = _possibleConstructorReturn(this, _getPrototypeOf(AbstractContract).call(this, provider, options, null, null)); | ||
_this.contractModuleFactory = contractModuleFactory; | ||
@@ -1018,4 +1009,4 @@ _this.abiCoder = abiCoder; | ||
_this.transactionSigner = options.transactionSigner; | ||
_this.methods = _this.contractModuleFactory.createMethodsProxy(_assertThisInitialized(_assertThisInitialized(_this))); | ||
_this.events = _this.contractModuleFactory.createEventSubscriptionsProxy(_assertThisInitialized(_assertThisInitialized(_this))); | ||
_this.methods = _this.contractModuleFactory.createMethodsProxy(_assertThisInitialized(_this)); | ||
_this.events = _this.contractModuleFactory.createEventSubscriptionsProxy(_assertThisInitialized(_this)); | ||
if (address) { | ||
@@ -1042,44 +1033,16 @@ _this.address = address; | ||
key: "getPastEvents", | ||
value: function () { | ||
var _getPastEvents = _asyncToGenerator( | ||
_regeneratorRuntime.mark(function _callee(eventName, options, callback) { | ||
var method, response; | ||
return _regeneratorRuntime.wrap(function _callee$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
if (!(eventName !== 'allEvents')) { | ||
_context.next = 6; | ||
break; | ||
} | ||
if (this.abiModel.hasEvent(eventName)) { | ||
_context.next = 3; | ||
break; | ||
} | ||
throw new Error("Event with name \"".concat(eventName, "\" does not exists.")); | ||
case 3: | ||
method = this.methodFactory.createPastEventLogsMethod(this.abiModel.getEvent(eventName)); | ||
_context.next = 7; | ||
break; | ||
case 6: | ||
method = this.methodFactory.createAllPastEventLogsMethod(this.abiModel); | ||
case 7: | ||
method.parameters = [options]; | ||
method.callback = callback; | ||
_context.next = 11; | ||
return method.execute(this); | ||
case 11: | ||
response = _context.sent; | ||
return _context.abrupt("return", response); | ||
case 13: | ||
case "end": | ||
return _context.stop(); | ||
} | ||
} | ||
}, _callee, this); | ||
})); | ||
return function getPastEvents(_x, _x2, _x3) { | ||
return _getPastEvents.apply(this, arguments); | ||
}; | ||
}() | ||
value: function getPastEvents(eventName, options, callback) { | ||
var method; | ||
if (eventName !== 'allEvents') { | ||
if (!this.abiModel.hasEvent(eventName)) { | ||
return Promise.reject(new Error("Event with name \"".concat(eventName, "\" does not exists."))); | ||
} | ||
method = this.methodFactory.createPastEventLogsMethod(this.abiModel.getEvent(eventName), this); | ||
} else { | ||
method = this.methodFactory.createAllPastEventLogsMethod(this.abiModel, this); | ||
} | ||
method.parameters = [options]; | ||
method.callback = callback; | ||
return method.execute(); | ||
} | ||
}, { | ||
@@ -1093,3 +1056,3 @@ key: "deploy", | ||
value: function clone() { | ||
var clone = this.contractModuleFactory.createContract(this.currentProvider, this.providersModuleFactory, this.accounts, [], '', this.options); | ||
var clone = this.contractModuleFactory.createContract(this.currentProvider, this.accounts, [], '', this.options); | ||
clone.abiModel = this.abiModel; | ||
@@ -1118,2 +1081,11 @@ return clone; | ||
} | ||
}, { | ||
key: "data", | ||
get: function get() { | ||
return this.options.data; | ||
} | ||
, | ||
set: function set(value) { | ||
this.options.data = value; | ||
} | ||
}]); | ||
@@ -1125,3 +1097,3 @@ return AbstractContract; | ||
function () { | ||
function ContractModuleFactory(utils, formatters, abiCoder, accounts, methodModuleFactory) { | ||
function ContractModuleFactory(utils, formatters, abiCoder) { | ||
_classCallCheck(this, ContractModuleFactory); | ||
@@ -1131,9 +1103,7 @@ this.utils = utils; | ||
this.abiCoder = abiCoder; | ||
this.accounts = accounts; | ||
this.methodModuleFactory = methodModuleFactory; | ||
} | ||
_createClass(ContractModuleFactory, [{ | ||
key: "createContract", | ||
value: function createContract(provider, providersModuleFactory, accounts, abi, address, options) { | ||
return new AbstractContract(provider, providersModuleFactory, this.methodModuleFactory, this, accounts, this.abiCoder, this.utils, this.formatters, abi, address, options); | ||
value: function createContract(provider, accounts, abi, address, options) { | ||
return new AbstractContract(provider, this, accounts, this.abiCoder, this.utils, this.formatters, abi, address, options); | ||
} | ||
@@ -1203,3 +1173,3 @@ }, { | ||
value: function createMethodFactory() { | ||
return new MethodFactory(this.utils, this.formatters, this, this.methodModuleFactory, this.abiCoder); | ||
return new MethodFactory(this.utils, this.formatters, this, this.abiCoder); | ||
} | ||
@@ -1225,5 +1195,5 @@ }, { | ||
var Contract = function Contract(provider, abi, accounts, address, options) { | ||
return new ContractModuleFactory(Utils, web3CoreHelpers.formatters, new web3EthAbi.AbiCoder(), accounts, new web3CoreMethod.MethodModuleFactory()).createContract(provider, new web3Providers.ProvidersModuleFactory(), accounts, abi, address, options); | ||
}; | ||
function Contract(provider, abi, accounts, address, options) { | ||
return new ContractModuleFactory(Utils, web3CoreHelpers.formatters, new web3EthAbi.AbiCoder(), accounts).createContract(provider, accounts, abi, address, options); | ||
} | ||
@@ -1230,0 +1200,0 @@ exports.AbstractContract = AbstractContract; |
import * as Utils from 'web3-utils'; | ||
import { ProvidersModuleFactory } from 'web3-providers'; | ||
import { formatters } from 'web3-core-helpers'; | ||
import { AbiCoder } from 'web3-eth-abi'; | ||
import { PromiEvent } from 'web3-core-promievent'; | ||
import isFunction from 'lodash/isFunction'; | ||
@@ -10,4 +8,4 @@ import isUndefined from 'lodash/isUndefined'; | ||
import isArray from 'lodash/isArray'; | ||
import { SendTransactionMethod, CallMethod, GetPastLogsMethod, EstimateGasMethod, SendRawTransactionMethod, ChainIdMethod, GetTransactionCountMethod, MethodModuleFactory } from 'web3-core-method'; | ||
import { LogSubscription } from 'web3-core-subscriptions'; | ||
import { PromiEvent, EthSendTransactionMethod, CallMethod, GetPastLogsMethod, EstimateGasMethod, ChainIdMethod, GetTransactionCountMethod, GetTransactionReceiptMethod, GetBlockByHashMethod, SendRawTransactionMethod, TransactionObserver } from 'web3-core-method'; | ||
import { NewHeadsSubscription, LogSubscription } from 'web3-core-subscriptions'; | ||
import { AbstractWeb3Module } from 'web3-core'; | ||
@@ -86,9 +84,2 @@ | ||
} | ||
givenParametersLengthIsValid() { | ||
const inputLength = this.getInputLength(); | ||
if (this.contractMethodParameters.length === inputLength) { | ||
return true; | ||
} | ||
throw new Error(`The number of arguments is not matching the methods required number. You need to pass ${inputLength} arguments.`); | ||
} | ||
getIndexedInputs() { | ||
@@ -131,10 +122,9 @@ return this.getInputs().filter(input => { | ||
encode(abiItemModel, filter) { | ||
const indexedInputs = abiItemModel.getIndexedInputs(); | ||
let topics = []; | ||
indexedInputs.forEach(indexedInput => { | ||
if (filter[indexedInput.name]) { | ||
let filterItem = filter[indexedInput.name]; | ||
abiItemModel.getIndexedInputs().forEach(input => { | ||
if (filter[input.name]) { | ||
let filterItem = filter[input.name]; | ||
if (isArray(filterItem)) { | ||
filterItem = filterItem.map(item => { | ||
return this.abiCoder.encodeParameter(indexedInput.type, item); | ||
return this.abiCoder.encodeParameter(input.type, item); | ||
}); | ||
@@ -144,4 +134,6 @@ topics.push(filterItem); | ||
} | ||
topics.push(this.abiCoder.encodeParameter(indexedInput.type, filterItem)); | ||
topics.push(this.abiCoder.encodeParameter(input.type, filterItem)); | ||
return; | ||
} | ||
topics.push(null); | ||
}); | ||
@@ -313,8 +305,8 @@ return topics; | ||
} | ||
if (typeof options.filter !== 'undefined') { | ||
options.topics = options.topics.concat(this.eventFilterEncoder.encode(abiItemModel, options.filter)); | ||
} | ||
if (!abiItemModel.anonymous) { | ||
options.topics.unshift(abiItemModel.signature); | ||
} | ||
if (typeof options.filter !== 'undefined') { | ||
options.topics = options.topics.concat(this.eventFilterEncoder.encode(abiItemModel, options.filter)); | ||
} | ||
if (!options.address) { | ||
@@ -375,3 +367,3 @@ options.address = contract.address; | ||
if (methodArguments[0]['data']) { | ||
target.contract.options.data = methodArguments[0]['data']; | ||
target.contract.data = methodArguments[0]['data']; | ||
} | ||
@@ -388,10 +380,7 @@ if (methodArguments[0]['arguments']) { | ||
const abiItemModelFound = abiItemModel.some(model => { | ||
model.contractMethodParameters = methodArguments; | ||
try { | ||
model.givenParametersLengthIsValid(); | ||
} catch (error) { | ||
return false; | ||
if (model.getInputLength() === methodArguments.length) { | ||
abiItemModel = model; | ||
return true; | ||
} | ||
abiItemModel = model; | ||
return true; | ||
return false; | ||
}); | ||
@@ -401,3 +390,2 @@ if (!abiItemModelFound) { | ||
} | ||
return anonymousFunction; | ||
} | ||
@@ -420,3 +408,3 @@ abiItemModel.contractMethodParameters = methodArguments; | ||
anonymousFunction.encodeABI = function () { | ||
return target.methodEncoder.encode(abiItemModel, target.contract.options.data); | ||
return target.methodEncoder.encode(abiItemModel, target.contract.data); | ||
}; | ||
@@ -438,23 +426,19 @@ return anonymousFunction; | ||
method = this.methodFactory.createMethodByRequestType(abiItemModel, this.contract, requestType); | ||
method.arguments = methodArguments; | ||
promiEvent.reject(error); | ||
promiEvent.emit('error', error); | ||
method.setArguments(methodArguments); | ||
if (isFunction(method.callback)) { | ||
method.callback(error, null); | ||
} | ||
promiEvent.reject(error); | ||
promiEvent.emit('error', error); | ||
return promiEvent; | ||
} | ||
if (requestType === 'call' || requestType === 'estimate') { | ||
return method.execute(this.contract); | ||
} | ||
return method.execute(this.contract, new PromiEvent()); | ||
return method.execute(); | ||
} | ||
createMethod(abiItemModel, methodArguments, requestType) { | ||
abiItemModel.givenParametersLengthIsValid(); | ||
const method = this.methodFactory.createMethodByRequestType(abiItemModel, this.contract, requestType); | ||
method.arguments = methodArguments; | ||
method.setArguments(methodArguments); | ||
if (typeof method.parameters[0] === 'undefined') { | ||
method.parameters[0] = {}; | ||
} | ||
method.parameters[0]['data'] = this.methodEncoder.encode(abiItemModel, this.contract.options.data); | ||
method.parameters[0]['data'] = this.methodEncoder.encode(abiItemModel, this.contract.data); | ||
method.parameters[0] = this.methodOptionsMapper.map(this.contract, method.parameters[0]); | ||
@@ -513,5 +497,5 @@ this.methodOptionsValidator.validate(abiItemModel, method); | ||
class SendContractMethod extends SendTransactionMethod { | ||
constructor(utils, formatters$$1, transactionConfirmationWorkflow, sendRawTransactionMethod, chainIdMethod, getTransactionCountMethod, allEventsLogDecoder, abiModel) { | ||
super(utils, formatters$$1, transactionConfirmationWorkflow, sendRawTransactionMethod, chainIdMethod, getTransactionCountMethod); | ||
class SendContractMethod extends EthSendTransactionMethod { | ||
constructor(utils, formatters$$1, moduleInstance, transactionObserver, chainIdMethod, getTransactionCountMethod, sendRawTransactionMethod, allEventsLogDecoder, abiModel) { | ||
super(utils, formatters$$1, moduleInstance, transactionObserver, chainIdMethod, getTransactionCountMethod, sendRawTransactionMethod); | ||
this.allEventsLogDecoder = allEventsLogDecoder; | ||
@@ -571,3 +555,3 @@ this.abiModel = abiModel; | ||
isValueValid(abiItemModel, method) { | ||
return !abiItemModel.payable && !method.parameters[0].value > 0 || abiItemModel.payable && method.parameters[0].value > 0; | ||
return abiItemModel.payable || !abiItemModel.payable && !method.parameters[0].value; | ||
} | ||
@@ -577,4 +561,4 @@ } | ||
class CallContractMethod extends CallMethod { | ||
constructor(utils, formatters$$1, abiCoder, abiItemModel) { | ||
super(utils, formatters$$1); | ||
constructor(utils, formatters$$1, moduleInstance, abiCoder, abiItemModel) { | ||
super(utils, formatters$$1, moduleInstance); | ||
this.abiCoder = abiCoder; | ||
@@ -595,6 +579,5 @@ this.abiItemModel = abiItemModel; | ||
class ContractDeployMethod extends SendTransactionMethod { | ||
constructor(utils, formatters$$1, transactionConfirmationWorkflow, sendRawTransactionMethod, chainIdMethod, getTransactionCountMethod, contract) { | ||
super(utils, formatters$$1, transactionConfirmationWorkflow, sendRawTransactionMethod, chainIdMethod, getTransactionCountMethod); | ||
this.contract = contract; | ||
class ContractDeployMethod extends EthSendTransactionMethod { | ||
constructor(utils, formatters$$1, moduleInstance, transactionObserver, chainIdMethod, getTransactionCountMethod, sendRawTransactionMethod) { | ||
super(utils, formatters$$1, moduleInstance, transactionObserver, chainIdMethod, getTransactionCountMethod, sendRawTransactionMethod); | ||
} | ||
@@ -606,3 +589,3 @@ beforeExecution(moduleInstance) { | ||
afterExecution(response) { | ||
const clonedContract = this.contract.clone(); | ||
const clonedContract = this.moduleInstance.clone(); | ||
clonedContract.address = response.contractAddress; | ||
@@ -614,4 +597,4 @@ return clonedContract; | ||
class PastEventLogsMethod extends GetPastLogsMethod { | ||
constructor(utils, formatters$$1, eventLogDecoder, abiItemModel, eventOptionsMapper) { | ||
super(utils, formatters$$1); | ||
constructor(utils, formatters$$1, moduleInstance, eventLogDecoder, abiItemModel, eventOptionsMapper) { | ||
super(utils, formatters$$1, moduleInstance); | ||
this.abiItemModel = abiItemModel; | ||
@@ -624,2 +607,5 @@ this.eventLogDecoder = eventLogDecoder; | ||
this.parameters[0] = this.eventOptionsMapper.map(this.abiItemModel, moduleInstance, this.parameters[0]); | ||
if (this.parameters[0].filter) { | ||
delete this.parameters[0].filter; | ||
} | ||
} | ||
@@ -635,4 +621,4 @@ afterExecution(response) { | ||
class AllPastEventLogsMethod extends GetPastLogsMethod { | ||
constructor(utils, formatters$$1, allEventsLogDecoder, abiModel, allEventsOptionsMapper) { | ||
super(utils, formatters$$1); | ||
constructor(utils, formatters$$1, moduleInstance, allEventsLogDecoder, abiModel, allEventsOptionsMapper) { | ||
super(utils, formatters$$1, moduleInstance); | ||
this.abiModel = abiModel; | ||
@@ -645,2 +631,5 @@ this.allEventsLogDecoder = allEventsLogDecoder; | ||
this.parameters[0] = this.allEventsOptionsMapper.map(this.abiModel, moduleInstance, this.parameters[0]); | ||
if (this.parameters[0].filter) { | ||
delete this.parameters[0].filter; | ||
} | ||
} | ||
@@ -656,7 +645,6 @@ afterExecution(response) { | ||
class MethodFactory { | ||
constructor(utils, formatters$$1, contractModuleFactory, methodModuleFactory, abiCoder) { | ||
constructor(utils, formatters$$1, contractModuleFactory, abiCoder) { | ||
this.utils = utils; | ||
this.formatters = formatters$$1; | ||
this.contractModuleFactory = contractModuleFactory; | ||
this.methodModuleFactory = methodModuleFactory; | ||
this.abiCoder = abiCoder; | ||
@@ -668,9 +656,9 @@ } | ||
case 'call': | ||
rpcMethod = this.createCallContractMethod(abiItem); | ||
rpcMethod = this.createCallContractMethod(abiItem, contract); | ||
break; | ||
case 'send': | ||
rpcMethod = this.createSendContractMethod(abiItem, contract.abiModel); | ||
rpcMethod = this.createSendContractMethod(contract); | ||
break; | ||
case 'estimate': | ||
rpcMethod = this.createEstimateGasMethod(); | ||
rpcMethod = this.createEstimateGasMethod(contract); | ||
break; | ||
@@ -686,22 +674,29 @@ case 'contract-deployment': | ||
} | ||
createPastEventLogsMethod(abiItem) { | ||
return new PastEventLogsMethod(this.utils, this.formatters, this.contractModuleFactory.createEventLogDecoder(), abiItem, this.contractModuleFactory.createEventOptionsMapper()); | ||
createPastEventLogsMethod(abiItem, contract) { | ||
return new PastEventLogsMethod(this.utils, this.formatters, contract, this.contractModuleFactory.createEventLogDecoder(), abiItem, this.contractModuleFactory.createEventOptionsMapper()); | ||
} | ||
createAllPastEventLogsMethod(abiModel) { | ||
return new AllPastEventLogsMethod(this.utils, this.formatters, this.contractModuleFactory.createAllEventsLogDecoder(), abiModel, this.contractModuleFactory.createAllEventsOptionsMapper()); | ||
createAllPastEventLogsMethod(abiModel, contract) { | ||
return new AllPastEventLogsMethod(this.utils, this.formatters, contract, this.contractModuleFactory.createAllEventsLogDecoder(), abiModel, this.contractModuleFactory.createAllEventsOptionsMapper()); | ||
} | ||
createCallContractMethod(abiItem) { | ||
return new CallContractMethod(this.utils, this.formatters, this.abiCoder, abiItem); | ||
createCallContractMethod(abiItem, contract) { | ||
return new CallContractMethod(this.utils, this.formatters, contract, this.abiCoder, abiItem); | ||
} | ||
createSendContractMethod(abiItem, abiModel) { | ||
const transactionConfirmationWorkflow = this.methodModuleFactory.createTransactionConfirmationWorkflow(); | ||
return new SendContractMethod(this.utils, this.formatters, transactionConfirmationWorkflow, new SendRawTransactionMethod(this.utils, this.formatters, transactionConfirmationWorkflow), new ChainIdMethod(this.utils, this.formatters), new GetTransactionCountMethod(this.utils, this.formatters), this.contractModuleFactory.createAllEventsLogDecoder(), abiModel); | ||
createSendContractMethod(contract) { | ||
const transactionObserver = new TransactionObserver(contract.currentProvider, this.getTransactionObserverTimeout(contract), contract.transactionConfirmationBlocks, new GetTransactionReceiptMethod(this.utils, this.formatters, contract), new GetBlockByHashMethod(this.utils, this.formatters, contract), new NewHeadsSubscription(this.utils, this.formatters, contract)); | ||
return new SendContractMethod(this.utils, this.formatters, contract, transactionObserver, new ChainIdMethod(this.utils, this.formatters, contract), new GetTransactionCountMethod(this.utils, this.formatters, contract), new SendRawTransactionMethod(this.utils, this.formatters, contract, transactionObserver), this.contractModuleFactory.createAllEventsLogDecoder(), contract.abiModel); | ||
} | ||
createContractDeployMethod(contract) { | ||
const transactionConfirmationWorkflow = this.methodModuleFactory.createTransactionConfirmationWorkflow(); | ||
return new ContractDeployMethod(this.utils, this.formatters, transactionConfirmationWorkflow, new SendRawTransactionMethod(this.utils, this.formatters, transactionConfirmationWorkflow), new ChainIdMethod(this.utils, this.formatters), new GetTransactionCountMethod(this.utils, this.formatters), contract); | ||
return new ContractDeployMethod(this.utils, this.formatters, contract, new TransactionObserver(contract.currentProvider, this.getTransactionObserverTimeout(contract), contract.transactionConfirmationBlocks, new GetTransactionReceiptMethod(this.utils, this.formatters, contract), new GetBlockByHashMethod(this.utils, this.formatters, contract), new NewHeadsSubscription(this.utils, this.formatters, contract)), new ChainIdMethod(this.utils, this.formatters, contract), new GetTransactionCountMethod(this.utils, this.formatters, contract), new SendRawTransactionMethod(this.utils, this.formatters, contract)); | ||
} | ||
createEstimateGasMethod() { | ||
return new EstimateGasMethod(this.utils, this.formatters); | ||
createEstimateGasMethod(contract) { | ||
return new EstimateGasMethod(this.utils, this.formatters, contract); | ||
} | ||
getTransactionObserverTimeout(contract) { | ||
let timeout = contract.transactionBlockTimeout; | ||
const providerName = contract.currentProvider.constructor.name; | ||
if (providerName === 'HttpProvider' || providerName === 'CustomProvider') { | ||
timeout = contract.transactionPollingTimeout; | ||
} | ||
return timeout; | ||
} | ||
} | ||
@@ -745,4 +740,4 @@ | ||
class AbstractContract extends AbstractWeb3Module { | ||
constructor(provider, providersModuleFactory, methodModuleFactory, contractModuleFactory, accounts, abiCoder, utils, formatters$$1, abi = [], address = '', options = {}) { | ||
super(provider, providersModuleFactory, methodModuleFactory, null, options); | ||
constructor(provider, contractModuleFactory, accounts, abiCoder, utils, formatters$$1, abi = [], address = '', options = {}) { | ||
super(provider, options, null, null); | ||
this.contractModuleFactory = contractModuleFactory; | ||
@@ -778,2 +773,8 @@ this.abiCoder = abiCoder; | ||
} | ||
get data() { | ||
return this.options.data; | ||
} | ||
set data(value) { | ||
this.options.data = value; | ||
} | ||
once(eventName, options, callback) { | ||
@@ -791,16 +792,15 @@ if (!callback) { | ||
} | ||
async getPastEvents(eventName, options, callback) { | ||
getPastEvents(eventName, options, callback) { | ||
let method; | ||
if (eventName !== 'allEvents') { | ||
if (!this.abiModel.hasEvent(eventName)) { | ||
throw new Error(`Event with name "${eventName}" does not exists.`); | ||
return Promise.reject(new Error(`Event with name "${eventName}" does not exists.`)); | ||
} | ||
method = this.methodFactory.createPastEventLogsMethod(this.abiModel.getEvent(eventName)); | ||
method = this.methodFactory.createPastEventLogsMethod(this.abiModel.getEvent(eventName), this); | ||
} else { | ||
method = this.methodFactory.createAllPastEventLogsMethod(this.abiModel); | ||
method = this.methodFactory.createAllPastEventLogsMethod(this.abiModel, this); | ||
} | ||
method.parameters = [options]; | ||
method.callback = callback; | ||
const response = await method.execute(this); | ||
return response; | ||
return method.execute(); | ||
} | ||
@@ -811,3 +811,3 @@ deploy(options) { | ||
clone() { | ||
const clone = this.contractModuleFactory.createContract(this.currentProvider, this.providersModuleFactory, this.accounts, [], '', this.options); | ||
const clone = this.contractModuleFactory.createContract(this.currentProvider, this.accounts, [], '', this.options); | ||
clone.abiModel = this.abiModel; | ||
@@ -819,11 +819,9 @@ return clone; | ||
class ContractModuleFactory { | ||
constructor(utils, formatters$$1, abiCoder, accounts, methodModuleFactory) { | ||
constructor(utils, formatters$$1, abiCoder) { | ||
this.utils = utils; | ||
this.formatters = formatters$$1; | ||
this.abiCoder = abiCoder; | ||
this.accounts = accounts; | ||
this.methodModuleFactory = methodModuleFactory; | ||
} | ||
createContract(provider, providersModuleFactory, accounts, abi, address, options) { | ||
return new AbstractContract(provider, providersModuleFactory, this.methodModuleFactory, this, accounts, this.abiCoder, this.utils, this.formatters, abi, address, options); | ||
createContract(provider, accounts, abi, address, options) { | ||
return new AbstractContract(provider, this, accounts, this.abiCoder, this.utils, this.formatters, abi, address, options); | ||
} | ||
@@ -867,3 +865,3 @@ createAbiModel(mappedAbi) { | ||
createMethodFactory() { | ||
return new MethodFactory(this.utils, this.formatters, this, this.methodModuleFactory, this.abiCoder); | ||
return new MethodFactory(this.utils, this.formatters, this, this.abiCoder); | ||
} | ||
@@ -881,6 +879,6 @@ createMethodsProxy(contract) { | ||
const Contract = (provider, abi, accounts, address, options) => { | ||
return new ContractModuleFactory(Utils, formatters, new AbiCoder(), accounts, new MethodModuleFactory()).createContract(provider, new ProvidersModuleFactory(), accounts, abi, address, options); | ||
}; | ||
function Contract(provider, abi, accounts, address, options) { | ||
return new ContractModuleFactory(Utils, formatters, new AbiCoder(), accounts).createContract(provider, accounts, abi, address, options); | ||
} | ||
export { AbstractContract, ContractModuleFactory, Contract }; |
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('web3-utils'), require('web3-providers'), require('web3-core-helpers'), require('web3-eth-abi'), require('web3-core-promievent'), require('lodash/isFunction'), require('lodash/isUndefined'), require('lodash/cloneDeep'), require('lodash/isArray'), require('@babel/runtime/helpers/get'), require('web3-core-method'), require('web3-core-subscriptions'), require('@babel/runtime/regenerator'), require('@babel/runtime/helpers/asyncToGenerator'), require('@babel/runtime/helpers/classCallCheck'), require('@babel/runtime/helpers/createClass'), require('@babel/runtime/helpers/possibleConstructorReturn'), require('@babel/runtime/helpers/getPrototypeOf'), require('@babel/runtime/helpers/inherits'), require('@babel/runtime/helpers/assertThisInitialized'), require('web3-core')) : | ||
typeof define === 'function' && define.amd ? define(['exports', 'web3-utils', 'web3-providers', 'web3-core-helpers', 'web3-eth-abi', 'web3-core-promievent', 'lodash/isFunction', 'lodash/isUndefined', 'lodash/cloneDeep', 'lodash/isArray', '@babel/runtime/helpers/get', 'web3-core-method', 'web3-core-subscriptions', '@babel/runtime/regenerator', '@babel/runtime/helpers/asyncToGenerator', '@babel/runtime/helpers/classCallCheck', '@babel/runtime/helpers/createClass', '@babel/runtime/helpers/possibleConstructorReturn', '@babel/runtime/helpers/getPrototypeOf', '@babel/runtime/helpers/inherits', '@babel/runtime/helpers/assertThisInitialized', 'web3-core'], factory) : | ||
(factory((global.Web3EthContract = {}),global.Utils,global.web3Providers,global.web3CoreHelpers,global.web3EthAbi,global.web3CorePromievent,global.isFunction,global.isUndefined,global.cloneDeep,global.isArray,global._get,global.web3CoreMethod,global.web3CoreSubscriptions,global._regeneratorRuntime,global._asyncToGenerator,global._classCallCheck,global._createClass,global._possibleConstructorReturn,global._getPrototypeOf,global._inherits,global._assertThisInitialized,global.web3Core)); | ||
}(this, (function (exports,Utils,web3Providers,web3CoreHelpers,web3EthAbi,web3CorePromievent,isFunction,isUndefined,cloneDeep,isArray,_get,web3CoreMethod,web3CoreSubscriptions,_regeneratorRuntime,_asyncToGenerator,_classCallCheck,_createClass,_possibleConstructorReturn,_getPrototypeOf,_inherits,_assertThisInitialized,web3Core) { 'use strict'; | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('web3-utils'), require('web3-core-helpers'), require('web3-eth-abi'), require('lodash/isFunction'), require('lodash/isUndefined'), require('lodash/cloneDeep'), require('lodash/isArray'), require('@babel/runtime/helpers/get'), require('web3-core-method'), require('web3-core-subscriptions'), require('@babel/runtime/helpers/classCallCheck'), require('@babel/runtime/helpers/createClass'), require('@babel/runtime/helpers/possibleConstructorReturn'), require('@babel/runtime/helpers/getPrototypeOf'), require('@babel/runtime/helpers/assertThisInitialized'), require('@babel/runtime/helpers/inherits'), require('web3-core')) : | ||
typeof define === 'function' && define.amd ? define(['exports', 'web3-utils', 'web3-core-helpers', 'web3-eth-abi', 'lodash/isFunction', 'lodash/isUndefined', 'lodash/cloneDeep', 'lodash/isArray', '@babel/runtime/helpers/get', 'web3-core-method', 'web3-core-subscriptions', '@babel/runtime/helpers/classCallCheck', '@babel/runtime/helpers/createClass', '@babel/runtime/helpers/possibleConstructorReturn', '@babel/runtime/helpers/getPrototypeOf', '@babel/runtime/helpers/assertThisInitialized', '@babel/runtime/helpers/inherits', 'web3-core'], factory) : | ||
(factory((global.Web3EthContract = {}),global.Utils,global.web3CoreHelpers,global.web3EthAbi,global.isFunction,global.isUndefined,global.cloneDeep,global.isArray,global._get,global.web3CoreMethod,global.web3CoreSubscriptions,global._classCallCheck,global._createClass,global._possibleConstructorReturn,global._getPrototypeOf,global._assertThisInitialized,global._inherits,global.web3Core)); | ||
}(this, (function (exports,Utils,web3CoreHelpers,web3EthAbi,isFunction,isUndefined,cloneDeep,isArray,_get,web3CoreMethod,web3CoreSubscriptions,_classCallCheck,_createClass,_possibleConstructorReturn,_getPrototypeOf,_assertThisInitialized,_inherits,web3Core) { 'use strict'; | ||
@@ -12,4 +12,2 @@ isFunction = isFunction && isFunction.hasOwnProperty('default') ? isFunction['default'] : isFunction; | ||
_get = _get && _get.hasOwnProperty('default') ? _get['default'] : _get; | ||
_regeneratorRuntime = _regeneratorRuntime && _regeneratorRuntime.hasOwnProperty('default') ? _regeneratorRuntime['default'] : _regeneratorRuntime; | ||
_asyncToGenerator = _asyncToGenerator && _asyncToGenerator.hasOwnProperty('default') ? _asyncToGenerator['default'] : _asyncToGenerator; | ||
_classCallCheck = _classCallCheck && _classCallCheck.hasOwnProperty('default') ? _classCallCheck['default'] : _classCallCheck; | ||
@@ -19,4 +17,4 @@ _createClass = _createClass && _createClass.hasOwnProperty('default') ? _createClass['default'] : _createClass; | ||
_getPrototypeOf = _getPrototypeOf && _getPrototypeOf.hasOwnProperty('default') ? _getPrototypeOf['default'] : _getPrototypeOf; | ||
_assertThisInitialized = _assertThisInitialized && _assertThisInitialized.hasOwnProperty('default') ? _assertThisInitialized['default'] : _assertThisInitialized; | ||
_inherits = _inherits && _inherits.hasOwnProperty('default') ? _inherits['default'] : _inherits; | ||
_assertThisInitialized = _assertThisInitialized && _assertThisInitialized.hasOwnProperty('default') ? _assertThisInitialized['default'] : _assertThisInitialized; | ||
@@ -112,11 +110,2 @@ var AbiModel = | ||
}, { | ||
key: "givenParametersLengthIsValid", | ||
value: function givenParametersLengthIsValid() { | ||
var inputLength = this.getInputLength(); | ||
if (this.contractMethodParameters.length === inputLength) { | ||
return true; | ||
} | ||
throw new Error("The number of arguments is not matching the methods required number. You need to pass ".concat(inputLength, " arguments.")); | ||
} | ||
}, { | ||
key: "getIndexedInputs", | ||
@@ -185,10 +174,9 @@ value: function getIndexedInputs() { | ||
var _this = this; | ||
var indexedInputs = abiItemModel.getIndexedInputs(); | ||
var topics = []; | ||
indexedInputs.forEach(function (indexedInput) { | ||
if (filter[indexedInput.name]) { | ||
var filterItem = filter[indexedInput.name]; | ||
abiItemModel.getIndexedInputs().forEach(function (input) { | ||
if (filter[input.name]) { | ||
var filterItem = filter[input.name]; | ||
if (isArray(filterItem)) { | ||
filterItem = filterItem.map(function (item) { | ||
return _this.abiCoder.encodeParameter(indexedInput.type, item); | ||
return _this.abiCoder.encodeParameter(input.type, item); | ||
}); | ||
@@ -198,4 +186,6 @@ topics.push(filterItem); | ||
} | ||
topics.push(_this.abiCoder.encodeParameter(indexedInput.type, filterItem)); | ||
topics.push(_this.abiCoder.encodeParameter(input.type, filterItem)); | ||
return; | ||
} | ||
topics.push(null); | ||
}); | ||
@@ -414,8 +404,8 @@ return topics; | ||
} | ||
if (typeof options.filter !== 'undefined') { | ||
options.topics = options.topics.concat(this.eventFilterEncoder.encode(abiItemModel, options.filter)); | ||
} | ||
if (!abiItemModel.anonymous) { | ||
options.topics.unshift(abiItemModel.signature); | ||
} | ||
if (typeof options.filter !== 'undefined') { | ||
options.topics = options.topics.concat(this.eventFilterEncoder.encode(abiItemModel, options.filter)); | ||
} | ||
if (!options.address) { | ||
@@ -482,3 +472,3 @@ options.address = contract.address; | ||
if (methodArguments[0]['data']) { | ||
target.contract.options.data = methodArguments[0]['data']; | ||
target.contract.data = methodArguments[0]['data']; | ||
} | ||
@@ -495,10 +485,7 @@ if (methodArguments[0]['arguments']) { | ||
var abiItemModelFound = abiItemModel.some(function (model) { | ||
model.contractMethodParameters = methodArguments; | ||
try { | ||
model.givenParametersLengthIsValid(); | ||
} catch (error) { | ||
return false; | ||
if (model.getInputLength() === methodArguments.length) { | ||
abiItemModel = model; | ||
return true; | ||
} | ||
abiItemModel = model; | ||
return true; | ||
return false; | ||
}); | ||
@@ -508,3 +495,2 @@ if (!abiItemModelFound) { | ||
} | ||
return anonymousFunction; | ||
} | ||
@@ -532,3 +518,3 @@ abiItemModel.contractMethodParameters = methodArguments; | ||
anonymousFunction.encodeABI = function () { | ||
return target.methodEncoder.encode(abiItemModel, target.contract.options.data); | ||
return target.methodEncoder.encode(abiItemModel, target.contract.data); | ||
}; | ||
@@ -550,16 +536,13 @@ return anonymousFunction; | ||
} catch (error) { | ||
var promiEvent = new web3CorePromievent.PromiEvent(); | ||
var promiEvent = new web3CoreMethod.PromiEvent(); | ||
method = this.methodFactory.createMethodByRequestType(abiItemModel, this.contract, requestType); | ||
method.arguments = methodArguments; | ||
promiEvent.reject(error); | ||
promiEvent.emit('error', error); | ||
method.setArguments(methodArguments); | ||
if (isFunction(method.callback)) { | ||
method.callback(error, null); | ||
} | ||
promiEvent.reject(error); | ||
promiEvent.emit('error', error); | ||
return promiEvent; | ||
} | ||
if (requestType === 'call' || requestType === 'estimate') { | ||
return method.execute(this.contract); | ||
} | ||
return method.execute(this.contract, new web3CorePromievent.PromiEvent()); | ||
return method.execute(); | ||
} | ||
@@ -569,9 +552,8 @@ }, { | ||
value: function createMethod(abiItemModel, methodArguments, requestType) { | ||
abiItemModel.givenParametersLengthIsValid(); | ||
var method = this.methodFactory.createMethodByRequestType(abiItemModel, this.contract, requestType); | ||
method.arguments = methodArguments; | ||
method.setArguments(methodArguments); | ||
if (typeof method.parameters[0] === 'undefined') { | ||
method.parameters[0] = {}; | ||
} | ||
method.parameters[0]['data'] = this.methodEncoder.encode(abiItemModel, this.contract.options.data); | ||
method.parameters[0]['data'] = this.methodEncoder.encode(abiItemModel, this.contract.data); | ||
method.parameters[0] = this.methodOptionsMapper.map(this.contract, method.parameters[0]); | ||
@@ -644,8 +626,8 @@ this.methodOptionsValidator.validate(abiItemModel, method); | ||
var SendContractMethod = | ||
function (_SendTransactionMetho) { | ||
_inherits(SendContractMethod, _SendTransactionMetho); | ||
function SendContractMethod(utils, formatters, transactionConfirmationWorkflow, sendRawTransactionMethod, chainIdMethod, getTransactionCountMethod, allEventsLogDecoder, abiModel) { | ||
function (_EthSendTransactionMe) { | ||
_inherits(SendContractMethod, _EthSendTransactionMe); | ||
function SendContractMethod(utils, formatters, moduleInstance, transactionObserver, chainIdMethod, getTransactionCountMethod, sendRawTransactionMethod, allEventsLogDecoder, abiModel) { | ||
var _this; | ||
_classCallCheck(this, SendContractMethod); | ||
_this = _possibleConstructorReturn(this, _getPrototypeOf(SendContractMethod).call(this, utils, formatters, transactionConfirmationWorkflow, sendRawTransactionMethod, chainIdMethod, getTransactionCountMethod)); | ||
_this = _possibleConstructorReturn(this, _getPrototypeOf(SendContractMethod).call(this, utils, formatters, moduleInstance, transactionObserver, chainIdMethod, getTransactionCountMethod, sendRawTransactionMethod)); | ||
_this.allEventsLogDecoder = allEventsLogDecoder; | ||
@@ -683,3 +665,3 @@ _this.abiModel = abiModel; | ||
return SendContractMethod; | ||
}(web3CoreMethod.SendTransactionMethod); | ||
}(web3CoreMethod.EthSendTransactionMethod); | ||
@@ -722,3 +704,3 @@ var MethodOptionsValidator = | ||
value: function isValueValid(abiItemModel, method) { | ||
return !abiItemModel.payable && !method.parameters[0].value > 0 || abiItemModel.payable && method.parameters[0].value > 0; | ||
return abiItemModel.payable || !abiItemModel.payable && !method.parameters[0].value; | ||
} | ||
@@ -732,6 +714,6 @@ }]); | ||
_inherits(CallContractMethod, _CallMethod); | ||
function CallContractMethod(utils, formatters, abiCoder, abiItemModel) { | ||
function CallContractMethod(utils, formatters, moduleInstance, abiCoder, abiItemModel) { | ||
var _this; | ||
_classCallCheck(this, CallContractMethod); | ||
_this = _possibleConstructorReturn(this, _getPrototypeOf(CallContractMethod).call(this, utils, formatters)); | ||
_this = _possibleConstructorReturn(this, _getPrototypeOf(CallContractMethod).call(this, utils, formatters, moduleInstance)); | ||
_this.abiCoder = abiCoder; | ||
@@ -758,10 +740,7 @@ _this.abiItemModel = abiItemModel; | ||
var ContractDeployMethod = | ||
function (_SendTransactionMetho) { | ||
_inherits(ContractDeployMethod, _SendTransactionMetho); | ||
function ContractDeployMethod(utils, formatters, transactionConfirmationWorkflow, sendRawTransactionMethod, chainIdMethod, getTransactionCountMethod, contract) { | ||
var _this; | ||
function (_EthSendTransactionMe) { | ||
_inherits(ContractDeployMethod, _EthSendTransactionMe); | ||
function ContractDeployMethod(utils, formatters, moduleInstance, transactionObserver, chainIdMethod, getTransactionCountMethod, sendRawTransactionMethod) { | ||
_classCallCheck(this, ContractDeployMethod); | ||
_this = _possibleConstructorReturn(this, _getPrototypeOf(ContractDeployMethod).call(this, utils, formatters, transactionConfirmationWorkflow, sendRawTransactionMethod, chainIdMethod, getTransactionCountMethod)); | ||
_this.contract = contract; | ||
return _this; | ||
return _possibleConstructorReturn(this, _getPrototypeOf(ContractDeployMethod).call(this, utils, formatters, moduleInstance, transactionObserver, chainIdMethod, getTransactionCountMethod, sendRawTransactionMethod)); | ||
} | ||
@@ -777,3 +756,3 @@ _createClass(ContractDeployMethod, [{ | ||
value: function afterExecution(response) { | ||
var clonedContract = this.contract.clone(); | ||
var clonedContract = this.moduleInstance.clone(); | ||
clonedContract.address = response.contractAddress; | ||
@@ -784,3 +763,3 @@ return clonedContract; | ||
return ContractDeployMethod; | ||
}(web3CoreMethod.SendTransactionMethod); | ||
}(web3CoreMethod.EthSendTransactionMethod); | ||
@@ -790,6 +769,6 @@ var PastEventLogsMethod = | ||
_inherits(PastEventLogsMethod, _GetPastLogsMethod); | ||
function PastEventLogsMethod(utils, formatters, eventLogDecoder, abiItemModel, eventOptionsMapper) { | ||
function PastEventLogsMethod(utils, formatters, moduleInstance, eventLogDecoder, abiItemModel, eventOptionsMapper) { | ||
var _this; | ||
_classCallCheck(this, PastEventLogsMethod); | ||
_this = _possibleConstructorReturn(this, _getPrototypeOf(PastEventLogsMethod).call(this, utils, formatters)); | ||
_this = _possibleConstructorReturn(this, _getPrototypeOf(PastEventLogsMethod).call(this, utils, formatters, moduleInstance)); | ||
_this.abiItemModel = abiItemModel; | ||
@@ -805,2 +784,5 @@ _this.eventLogDecoder = eventLogDecoder; | ||
this.parameters[0] = this.eventOptionsMapper.map(this.abiItemModel, moduleInstance, this.parameters[0]); | ||
if (this.parameters[0].filter) { | ||
delete this.parameters[0].filter; | ||
} | ||
} | ||
@@ -823,6 +805,6 @@ }, { | ||
_inherits(AllPastEventLogsMethod, _GetPastLogsMethod); | ||
function AllPastEventLogsMethod(utils, formatters, allEventsLogDecoder, abiModel, allEventsOptionsMapper) { | ||
function AllPastEventLogsMethod(utils, formatters, moduleInstance, allEventsLogDecoder, abiModel, allEventsOptionsMapper) { | ||
var _this; | ||
_classCallCheck(this, AllPastEventLogsMethod); | ||
_this = _possibleConstructorReturn(this, _getPrototypeOf(AllPastEventLogsMethod).call(this, utils, formatters)); | ||
_this = _possibleConstructorReturn(this, _getPrototypeOf(AllPastEventLogsMethod).call(this, utils, formatters, moduleInstance)); | ||
_this.abiModel = abiModel; | ||
@@ -838,2 +820,5 @@ _this.allEventsLogDecoder = allEventsLogDecoder; | ||
this.parameters[0] = this.allEventsOptionsMapper.map(this.abiModel, moduleInstance, this.parameters[0]); | ||
if (this.parameters[0].filter) { | ||
delete this.parameters[0].filter; | ||
} | ||
} | ||
@@ -855,3 +840,3 @@ }, { | ||
function () { | ||
function MethodFactory(utils, formatters, contractModuleFactory, methodModuleFactory, abiCoder) { | ||
function MethodFactory(utils, formatters, contractModuleFactory, abiCoder) { | ||
_classCallCheck(this, MethodFactory); | ||
@@ -861,3 +846,2 @@ this.utils = utils; | ||
this.contractModuleFactory = contractModuleFactory; | ||
this.methodModuleFactory = methodModuleFactory; | ||
this.abiCoder = abiCoder; | ||
@@ -871,9 +855,9 @@ } | ||
case 'call': | ||
rpcMethod = this.createCallContractMethod(abiItem); | ||
rpcMethod = this.createCallContractMethod(abiItem, contract); | ||
break; | ||
case 'send': | ||
rpcMethod = this.createSendContractMethod(abiItem, contract.abiModel); | ||
rpcMethod = this.createSendContractMethod(contract); | ||
break; | ||
case 'estimate': | ||
rpcMethod = this.createEstimateGasMethod(); | ||
rpcMethod = this.createEstimateGasMethod(contract); | ||
break; | ||
@@ -891,20 +875,20 @@ case 'contract-deployment': | ||
key: "createPastEventLogsMethod", | ||
value: function createPastEventLogsMethod(abiItem) { | ||
return new PastEventLogsMethod(this.utils, this.formatters, this.contractModuleFactory.createEventLogDecoder(), abiItem, this.contractModuleFactory.createEventOptionsMapper()); | ||
value: function createPastEventLogsMethod(abiItem, contract) { | ||
return new PastEventLogsMethod(this.utils, this.formatters, contract, this.contractModuleFactory.createEventLogDecoder(), abiItem, this.contractModuleFactory.createEventOptionsMapper()); | ||
} | ||
}, { | ||
key: "createAllPastEventLogsMethod", | ||
value: function createAllPastEventLogsMethod(abiModel) { | ||
return new AllPastEventLogsMethod(this.utils, this.formatters, this.contractModuleFactory.createAllEventsLogDecoder(), abiModel, this.contractModuleFactory.createAllEventsOptionsMapper()); | ||
value: function createAllPastEventLogsMethod(abiModel, contract) { | ||
return new AllPastEventLogsMethod(this.utils, this.formatters, contract, this.contractModuleFactory.createAllEventsLogDecoder(), abiModel, this.contractModuleFactory.createAllEventsOptionsMapper()); | ||
} | ||
}, { | ||
key: "createCallContractMethod", | ||
value: function createCallContractMethod(abiItem) { | ||
return new CallContractMethod(this.utils, this.formatters, this.abiCoder, abiItem); | ||
value: function createCallContractMethod(abiItem, contract) { | ||
return new CallContractMethod(this.utils, this.formatters, contract, this.abiCoder, abiItem); | ||
} | ||
}, { | ||
key: "createSendContractMethod", | ||
value: function createSendContractMethod(abiItem, abiModel) { | ||
var transactionConfirmationWorkflow = this.methodModuleFactory.createTransactionConfirmationWorkflow(); | ||
return new SendContractMethod(this.utils, this.formatters, transactionConfirmationWorkflow, new web3CoreMethod.SendRawTransactionMethod(this.utils, this.formatters, transactionConfirmationWorkflow), new web3CoreMethod.ChainIdMethod(this.utils, this.formatters), new web3CoreMethod.GetTransactionCountMethod(this.utils, this.formatters), this.contractModuleFactory.createAllEventsLogDecoder(), abiModel); | ||
value: function createSendContractMethod(contract) { | ||
var transactionObserver = new web3CoreMethod.TransactionObserver(contract.currentProvider, this.getTransactionObserverTimeout(contract), contract.transactionConfirmationBlocks, new web3CoreMethod.GetTransactionReceiptMethod(this.utils, this.formatters, contract), new web3CoreMethod.GetBlockByHashMethod(this.utils, this.formatters, contract), new web3CoreSubscriptions.NewHeadsSubscription(this.utils, this.formatters, contract)); | ||
return new SendContractMethod(this.utils, this.formatters, contract, transactionObserver, new web3CoreMethod.ChainIdMethod(this.utils, this.formatters, contract), new web3CoreMethod.GetTransactionCountMethod(this.utils, this.formatters, contract), new web3CoreMethod.SendRawTransactionMethod(this.utils, this.formatters, contract, transactionObserver), this.contractModuleFactory.createAllEventsLogDecoder(), contract.abiModel); | ||
} | ||
@@ -914,10 +898,19 @@ }, { | ||
value: function createContractDeployMethod(contract) { | ||
var transactionConfirmationWorkflow = this.methodModuleFactory.createTransactionConfirmationWorkflow(); | ||
return new ContractDeployMethod(this.utils, this.formatters, transactionConfirmationWorkflow, new web3CoreMethod.SendRawTransactionMethod(this.utils, this.formatters, transactionConfirmationWorkflow), new web3CoreMethod.ChainIdMethod(this.utils, this.formatters), new web3CoreMethod.GetTransactionCountMethod(this.utils, this.formatters), contract); | ||
return new ContractDeployMethod(this.utils, this.formatters, contract, new web3CoreMethod.TransactionObserver(contract.currentProvider, this.getTransactionObserverTimeout(contract), contract.transactionConfirmationBlocks, new web3CoreMethod.GetTransactionReceiptMethod(this.utils, this.formatters, contract), new web3CoreMethod.GetBlockByHashMethod(this.utils, this.formatters, contract), new web3CoreSubscriptions.NewHeadsSubscription(this.utils, this.formatters, contract)), new web3CoreMethod.ChainIdMethod(this.utils, this.formatters, contract), new web3CoreMethod.GetTransactionCountMethod(this.utils, this.formatters, contract), new web3CoreMethod.SendRawTransactionMethod(this.utils, this.formatters, contract)); | ||
} | ||
}, { | ||
key: "createEstimateGasMethod", | ||
value: function createEstimateGasMethod() { | ||
return new web3CoreMethod.EstimateGasMethod(this.utils, this.formatters); | ||
value: function createEstimateGasMethod(contract) { | ||
return new web3CoreMethod.EstimateGasMethod(this.utils, this.formatters, contract); | ||
} | ||
}, { | ||
key: "getTransactionObserverTimeout", | ||
value: function getTransactionObserverTimeout(contract) { | ||
var timeout = contract.transactionBlockTimeout; | ||
var providerName = contract.currentProvider.constructor.name; | ||
if (providerName === 'HttpProvider' || providerName === 'CustomProvider') { | ||
timeout = contract.transactionPollingTimeout; | ||
} | ||
return timeout; | ||
} | ||
}]); | ||
@@ -991,9 +984,9 @@ return MethodFactory; | ||
_inherits(AbstractContract, _AbstractWeb3Module); | ||
function AbstractContract(provider, providersModuleFactory, methodModuleFactory, contractModuleFactory, accounts, abiCoder, utils, formatters) { | ||
function AbstractContract(provider, contractModuleFactory, accounts, abiCoder, utils, formatters) { | ||
var _this; | ||
var abi = arguments.length > 8 && arguments[8] !== undefined ? arguments[8] : []; | ||
var address = arguments.length > 9 && arguments[9] !== undefined ? arguments[9] : ''; | ||
var options = arguments.length > 10 && arguments[10] !== undefined ? arguments[10] : {}; | ||
var abi = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : []; | ||
var address = arguments.length > 7 && arguments[7] !== undefined ? arguments[7] : ''; | ||
var options = arguments.length > 8 && arguments[8] !== undefined ? arguments[8] : {}; | ||
_classCallCheck(this, AbstractContract); | ||
_this = _possibleConstructorReturn(this, _getPrototypeOf(AbstractContract).call(this, provider, providersModuleFactory, methodModuleFactory, null, options)); | ||
_this = _possibleConstructorReturn(this, _getPrototypeOf(AbstractContract).call(this, provider, options, null, null)); | ||
_this.contractModuleFactory = contractModuleFactory; | ||
@@ -1009,4 +1002,4 @@ _this.abiCoder = abiCoder; | ||
_this.transactionSigner = options.transactionSigner; | ||
_this.methods = _this.contractModuleFactory.createMethodsProxy(_assertThisInitialized(_assertThisInitialized(_this))); | ||
_this.events = _this.contractModuleFactory.createEventSubscriptionsProxy(_assertThisInitialized(_assertThisInitialized(_this))); | ||
_this.methods = _this.contractModuleFactory.createMethodsProxy(_assertThisInitialized(_this)); | ||
_this.events = _this.contractModuleFactory.createEventSubscriptionsProxy(_assertThisInitialized(_this)); | ||
if (address) { | ||
@@ -1033,44 +1026,16 @@ _this.address = address; | ||
key: "getPastEvents", | ||
value: function () { | ||
var _getPastEvents = _asyncToGenerator( | ||
_regeneratorRuntime.mark(function _callee(eventName, options, callback) { | ||
var method, response; | ||
return _regeneratorRuntime.wrap(function _callee$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
if (!(eventName !== 'allEvents')) { | ||
_context.next = 6; | ||
break; | ||
} | ||
if (this.abiModel.hasEvent(eventName)) { | ||
_context.next = 3; | ||
break; | ||
} | ||
throw new Error("Event with name \"".concat(eventName, "\" does not exists.")); | ||
case 3: | ||
method = this.methodFactory.createPastEventLogsMethod(this.abiModel.getEvent(eventName)); | ||
_context.next = 7; | ||
break; | ||
case 6: | ||
method = this.methodFactory.createAllPastEventLogsMethod(this.abiModel); | ||
case 7: | ||
method.parameters = [options]; | ||
method.callback = callback; | ||
_context.next = 11; | ||
return method.execute(this); | ||
case 11: | ||
response = _context.sent; | ||
return _context.abrupt("return", response); | ||
case 13: | ||
case "end": | ||
return _context.stop(); | ||
} | ||
} | ||
}, _callee, this); | ||
})); | ||
return function getPastEvents(_x, _x2, _x3) { | ||
return _getPastEvents.apply(this, arguments); | ||
}; | ||
}() | ||
value: function getPastEvents(eventName, options, callback) { | ||
var method; | ||
if (eventName !== 'allEvents') { | ||
if (!this.abiModel.hasEvent(eventName)) { | ||
return Promise.reject(new Error("Event with name \"".concat(eventName, "\" does not exists."))); | ||
} | ||
method = this.methodFactory.createPastEventLogsMethod(this.abiModel.getEvent(eventName), this); | ||
} else { | ||
method = this.methodFactory.createAllPastEventLogsMethod(this.abiModel, this); | ||
} | ||
method.parameters = [options]; | ||
method.callback = callback; | ||
return method.execute(); | ||
} | ||
}, { | ||
@@ -1084,3 +1049,3 @@ key: "deploy", | ||
value: function clone() { | ||
var clone = this.contractModuleFactory.createContract(this.currentProvider, this.providersModuleFactory, this.accounts, [], '', this.options); | ||
var clone = this.contractModuleFactory.createContract(this.currentProvider, this.accounts, [], '', this.options); | ||
clone.abiModel = this.abiModel; | ||
@@ -1109,2 +1074,11 @@ return clone; | ||
} | ||
}, { | ||
key: "data", | ||
get: function get() { | ||
return this.options.data; | ||
} | ||
, | ||
set: function set(value) { | ||
this.options.data = value; | ||
} | ||
}]); | ||
@@ -1116,3 +1090,3 @@ return AbstractContract; | ||
function () { | ||
function ContractModuleFactory(utils, formatters, abiCoder, accounts, methodModuleFactory) { | ||
function ContractModuleFactory(utils, formatters, abiCoder) { | ||
_classCallCheck(this, ContractModuleFactory); | ||
@@ -1122,9 +1096,7 @@ this.utils = utils; | ||
this.abiCoder = abiCoder; | ||
this.accounts = accounts; | ||
this.methodModuleFactory = methodModuleFactory; | ||
} | ||
_createClass(ContractModuleFactory, [{ | ||
key: "createContract", | ||
value: function createContract(provider, providersModuleFactory, accounts, abi, address, options) { | ||
return new AbstractContract(provider, providersModuleFactory, this.methodModuleFactory, this, accounts, this.abiCoder, this.utils, this.formatters, abi, address, options); | ||
value: function createContract(provider, accounts, abi, address, options) { | ||
return new AbstractContract(provider, this, accounts, this.abiCoder, this.utils, this.formatters, abi, address, options); | ||
} | ||
@@ -1194,3 +1166,3 @@ }, { | ||
value: function createMethodFactory() { | ||
return new MethodFactory(this.utils, this.formatters, this, this.methodModuleFactory, this.abiCoder); | ||
return new MethodFactory(this.utils, this.formatters, this, this.abiCoder); | ||
} | ||
@@ -1216,5 +1188,5 @@ }, { | ||
var Contract = function Contract(provider, abi, accounts, address, options) { | ||
return new ContractModuleFactory(Utils, web3CoreHelpers.formatters, new web3EthAbi.AbiCoder(), accounts, new web3CoreMethod.MethodModuleFactory()).createContract(provider, new web3Providers.ProvidersModuleFactory(), accounts, abi, address, options); | ||
}; | ||
function Contract(provider, abi, accounts, address, options) { | ||
return new ContractModuleFactory(Utils, web3CoreHelpers.formatters, new web3EthAbi.AbiCoder(), accounts).createContract(provider, accounts, abi, address, options); | ||
} | ||
@@ -1221,0 +1193,0 @@ exports.AbstractContract = AbstractContract; |
{ | ||
"name": "web3-eth-contract", | ||
"namespace": "ethereum", | ||
"version": "1.0.0-beta.48", | ||
"version": "1.0.0-beta.49", | ||
"description": "Web3 module to interact with Ethereum smart contracts.", | ||
@@ -21,14 +21,14 @@ "repository": "https://github.com/ethereum/web3.js/tree/1.0/packages/web3-eth-contract", | ||
"lodash": "^4.17.11", | ||
"web3-core": "1.0.0-beta.48", | ||
"web3-core-helpers": "1.0.0-beta.48", | ||
"web3-core-method": "1.0.0-beta.48", | ||
"web3-core-promievent": "1.0.0-beta.48", | ||
"web3-core-subscriptions": "1.0.0-beta.48", | ||
"web3-eth-abi": "1.0.0-beta.48", | ||
"web3-eth-accounts": "1.0.0-beta.48", | ||
"web3-providers": "1.0.0-beta.48", | ||
"web3-utils": "1.0.0-beta.48" | ||
"web3-core": "1.0.0-beta.49", | ||
"web3-core-helpers": "1.0.0-beta.49", | ||
"web3-core-method": "1.0.0-beta.49", | ||
"web3-core-subscriptions": "1.0.0-beta.49", | ||
"web3-eth-abi": "1.0.0-beta.49", | ||
"web3-eth-accounts": "1.0.0-beta.49", | ||
"web3-providers": "1.0.0-beta.49", | ||
"web3-utils": "1.0.0-beta.49" | ||
}, | ||
"devDependencies": { | ||
"dtslint": "^0.4.2" | ||
"definitelytyped-header-parser": "^1.0.1", | ||
"dtslint": "0.4.2" | ||
}, | ||
@@ -38,3 +38,4 @@ "files": [ | ||
"types/index.d.ts" | ||
] | ||
], | ||
"gitHead": "eb1452cdd1591e0f26ff0f66df68ee0feb3f8c47" | ||
} |
@@ -113,3 +113,5 @@ /* | ||
export interface EventData { | ||
returnValues: {}, | ||
returnValues: { | ||
[key: string]: any; | ||
}, | ||
raw: { | ||
@@ -116,0 +118,0 @@ data: string; |
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
Copyleft License
License(Experimental) Copyleft license information was found.
Found 1 instance in 1 package
Mixed license
License(Experimental) Package contains multiple licenses.
Found 1 instance in 1 package
Non-permissive License
License(Experimental) A license not known to be considered permissive was found.
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
Copyleft License
License(Experimental) Copyleft license information was found.
Found 1 instance in 1 package
Non-permissive License
License(Experimental) A license not known to be considered permissive was found.
Found 1 instance in 1 package
10
8
259258
2
3
3215
+ Addedelliptic@6.5.4(transitive)
+ Addedethers@4.0.49(transitive)
+ Addedweb3-core@1.0.0-beta.49(transitive)
+ Addedweb3-core-helpers@1.0.0-beta.49(transitive)
+ Addedweb3-core-method@1.0.0-beta.49(transitive)
+ Addedweb3-core-subscriptions@1.0.0-beta.49(transitive)
+ Addedweb3-eth-abi@1.0.0-beta.49(transitive)
+ Addedweb3-eth-accounts@1.0.0-beta.49(transitive)
+ Addedweb3-eth-iban@1.0.0-beta.49(transitive)
+ Addedweb3-providers@1.0.0-beta.49(transitive)
+ Addedweb3-utils@1.0.0-beta.49(transitive)
- Removedweb3-core-promievent@1.0.0-beta.48
- Removedelliptic@6.3.3(transitive)
- Removedethers@4.0.26(transitive)
- Removedhttp-https@1.0.0(transitive)
- Removedoboe@2.1.4(transitive)
- Removedweb3-core@1.0.0-beta.48(transitive)
- Removedweb3-core-helpers@1.0.0-beta.48(transitive)
- Removedweb3-core-method@1.0.0-beta.48(transitive)
- Removedweb3-core-promievent@1.0.0-beta.48(transitive)
- Removedweb3-core-subscriptions@1.0.0-beta.48(transitive)
- Removedweb3-eth-abi@1.0.0-beta.48(transitive)
- Removedweb3-eth-accounts@1.0.0-beta.48(transitive)
- Removedweb3-eth-iban@1.0.0-beta.48(transitive)
- Removedweb3-providers@1.0.0-beta.48(transitive)
- Removedweb3-utils@1.0.0-beta.48(transitive)
Updatedweb3-core@1.0.0-beta.49
Updatedweb3-eth-abi@1.0.0-beta.49
Updatedweb3-providers@1.0.0-beta.49
Updatedweb3-utils@1.0.0-beta.49