UNPKG

88 kBJavaScriptView Raw
1(function (global, factory) {
2 typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@babel/runtime/helpers/classCallCheck'), require('@babel/runtime/helpers/createClass'), require('eventemitter3'), require('conflux-web-core-subscriptions'), require('@babel/runtime/helpers/possibleConstructorReturn'), require('@babel/runtime/helpers/getPrototypeOf'), require('@babel/runtime/helpers/inherits'), require('lodash/isFunction'), require('@babel/runtime/helpers/toConsumableArray'), require('@babel/runtime/regenerator'), require('@babel/runtime/helpers/asyncToGenerator'), require('lodash/isString'), require('lodash/cloneDeep'), require('rxjs'), require('@babel/runtime/helpers/get')) :
3 typeof define === 'function' && define.amd ? define(['exports', '@babel/runtime/helpers/classCallCheck', '@babel/runtime/helpers/createClass', 'eventemitter3', 'conflux-web-core-subscriptions', '@babel/runtime/helpers/possibleConstructorReturn', '@babel/runtime/helpers/getPrototypeOf', '@babel/runtime/helpers/inherits', 'lodash/isFunction', '@babel/runtime/helpers/toConsumableArray', '@babel/runtime/regenerator', '@babel/runtime/helpers/asyncToGenerator', 'lodash/isString', 'lodash/cloneDeep', 'rxjs', '@babel/runtime/helpers/get'], factory) :
4 (global = global || self, factory(global.ConfluxWebCoreMethod = {}, global._classCallCheck, global._createClass, global.EventEmitter, global.confluxWebCoreSubscriptions, global._possibleConstructorReturn, global._getPrototypeOf, global._inherits, global.isFunction, global._toConsumableArray, global._regeneratorRuntime, global._asyncToGenerator, global.isString, global.cloneDeep, global.rxjs, global._get));
5}(this, (function (exports, _classCallCheck, _createClass, EventEmitter, confluxWebCoreSubscriptions, _possibleConstructorReturn, _getPrototypeOf, _inherits, isFunction, _toConsumableArray, _regeneratorRuntime, _asyncToGenerator, isString, cloneDeep, rxjs, _get) { 'use strict';
6
7 _classCallCheck = _classCallCheck && Object.prototype.hasOwnProperty.call(_classCallCheck, 'default') ? _classCallCheck['default'] : _classCallCheck;
8 _createClass = _createClass && Object.prototype.hasOwnProperty.call(_createClass, 'default') ? _createClass['default'] : _createClass;
9 EventEmitter = EventEmitter && Object.prototype.hasOwnProperty.call(EventEmitter, 'default') ? EventEmitter['default'] : EventEmitter;
10 _possibleConstructorReturn = _possibleConstructorReturn && Object.prototype.hasOwnProperty.call(_possibleConstructorReturn, 'default') ? _possibleConstructorReturn['default'] : _possibleConstructorReturn;
11 _getPrototypeOf = _getPrototypeOf && Object.prototype.hasOwnProperty.call(_getPrototypeOf, 'default') ? _getPrototypeOf['default'] : _getPrototypeOf;
12 _inherits = _inherits && Object.prototype.hasOwnProperty.call(_inherits, 'default') ? _inherits['default'] : _inherits;
13 isFunction = isFunction && Object.prototype.hasOwnProperty.call(isFunction, 'default') ? isFunction['default'] : isFunction;
14 _toConsumableArray = _toConsumableArray && Object.prototype.hasOwnProperty.call(_toConsumableArray, 'default') ? _toConsumableArray['default'] : _toConsumableArray;
15 _regeneratorRuntime = _regeneratorRuntime && Object.prototype.hasOwnProperty.call(_regeneratorRuntime, 'default') ? _regeneratorRuntime['default'] : _regeneratorRuntime;
16 _asyncToGenerator = _asyncToGenerator && Object.prototype.hasOwnProperty.call(_asyncToGenerator, 'default') ? _asyncToGenerator['default'] : _asyncToGenerator;
17 isString = isString && Object.prototype.hasOwnProperty.call(isString, 'default') ? isString['default'] : isString;
18 cloneDeep = cloneDeep && Object.prototype.hasOwnProperty.call(cloneDeep, 'default') ? cloneDeep['default'] : cloneDeep;
19 _get = _get && Object.prototype.hasOwnProperty.call(_get, 'default') ? _get['default'] : _get;
20
21 var PromiEvent = function () {
22 function PromiEvent() {
23 var _this = this;
24 _classCallCheck(this, PromiEvent);
25 this.promise = new Promise(function (resolve, reject) {
26 _this.resolve = resolve;
27 _this.reject = reject;
28 });
29 this.eventEmitter = new EventEmitter();
30 return new Proxy(this, {
31 get: this.proxyHandler
32 });
33 }
34 _createClass(PromiEvent, [{
35 key: "proxyHandler",
36 value: function proxyHandler(target, name) {
37 if (name === 'resolve' || name === 'reject') {
38 return target[name];
39 }
40 if (name === 'then') {
41 return target.promise.then.bind(target.promise);
42 }
43 if (name === 'catch') {
44 return target.promise["catch"].bind(target.promise);
45 }
46 if (target.eventEmitter[name]) {
47 return target.eventEmitter[name];
48 }
49 }
50 }]);
51 return PromiEvent;
52 }();
53
54 var AbstractMethod = function () {
55 function AbstractMethod(rpcMethod, parametersAmount, utils, formatters, moduleInstance) {
56 _classCallCheck(this, AbstractMethod);
57 this.utils = utils;
58 this.formatters = formatters;
59 this.moduleInstance = moduleInstance;
60 this._arguments = {
61 parameters: []
62 };
63 this._rpcMethod = rpcMethod;
64 this._parametersAmount = parametersAmount;
65 }
66 _createClass(AbstractMethod, [{
67 key: "beforeExecution",
68 value: function beforeExecution(moduleInstance) {}
69 }, {
70 key: "afterExecution",
71 value: function afterExecution(response) {
72 return response;
73 }
74 }, {
75 key: "execute",
76 value: function () {
77 var _execute = _asyncToGenerator( _regeneratorRuntime.mark(function _callee() {
78 var response;
79 return _regeneratorRuntime.wrap(function _callee$(_context) {
80 while (1) {
81 switch (_context.prev = _context.next) {
82 case 0:
83 this.beforeExecution(this.moduleInstance);
84 if (!(this.parameters.length !== this.parametersAmount)) {
85 _context.next = 3;
86 break;
87 }
88 throw new Error("Invalid Arguments length: expected: ".concat(this.parametersAmount, ", given: ").concat(this.parameters.length));
89 case 3:
90 _context.prev = 3;
91 _context.next = 6;
92 return this.moduleInstance.currentProvider.send(this.rpcMethod, this.parameters);
93 case 6:
94 response = _context.sent;
95 if (response) {
96 response = this.afterExecution(response);
97 }
98 if (this.callback) {
99 this.callback(false, response);
100 }
101 return _context.abrupt("return", response);
102 case 12:
103 _context.prev = 12;
104 _context.t0 = _context["catch"](3);
105 if (this.callback) {
106 this.callback(_context.t0, null);
107 }
108 throw _context.t0;
109 case 16:
110 case "end":
111 return _context.stop();
112 }
113 }
114 }, _callee, this, [[3, 12]]);
115 }));
116 function execute() {
117 return _execute.apply(this, arguments);
118 }
119 return execute;
120 }()
121 }, {
122 key: "setArguments",
123 value: function setArguments(methodArguments) {
124 var parameters = cloneDeep(_toConsumableArray(methodArguments));
125 var callback = null;
126 if (parameters.length > this.parametersAmount) {
127 if (!isFunction(parameters[parameters.length - 1])) {
128 throw new TypeError("The latest parameter should be a function otherwise it can't be used as callback");
129 }
130 callback = parameters.pop();
131 }
132 this._arguments = {
133 callback: callback,
134 parameters: parameters
135 };
136 }
137 }, {
138 key: "getArguments",
139 value: function getArguments() {
140 return this._arguments;
141 }
142 }, {
143 key: "isHash",
144 value: function isHash(parameter) {
145 return isString(parameter) && parameter.startsWith('0x');
146 }
147 }, {
148 key: "rpcMethod",
149 set: function set(value) {
150 this._rpcMethod = value;
151 }
152 ,
153 get: function get() {
154 return this._rpcMethod;
155 }
156 }, {
157 key: "parametersAmount",
158 set: function set(value) {
159 this._parametersAmount = value;
160 }
161 ,
162 get: function get() {
163 return this._parametersAmount;
164 }
165 }, {
166 key: "parameters",
167 get: function get() {
168 return this._arguments.parameters;
169 }
170 ,
171 set: function set(value) {
172 this._arguments.parameters = value;
173 }
174 }, {
175 key: "callback",
176 get: function get() {
177 return this._arguments.callback;
178 }
179 ,
180 set: function set(value) {
181 this._arguments.callback = value;
182 }
183 }]);
184 return AbstractMethod;
185 }();
186
187 function _createSuper(Derived) { return function () { var Super = _getPrototypeOf(Derived), result; if (_isNativeReflectConstruct()) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
188 function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
189 var AbstractGetBlockMethod = function (_AbstractMethod) {
190 _inherits(AbstractGetBlockMethod, _AbstractMethod);
191 var _super = _createSuper(AbstractGetBlockMethod);
192 function AbstractGetBlockMethod(rpcMethod, utils, formatters, moduleInstance) {
193 _classCallCheck(this, AbstractGetBlockMethod);
194 return _super.call(this, rpcMethod, 2, utils, formatters, moduleInstance);
195 }
196 _createClass(AbstractGetBlockMethod, [{
197 key: "beforeExecution",
198 value: function beforeExecution(moduleInstance) {
199 this.parameters[0] = this.formatters.inputBlockAddressFormatter(this.parameters[0]);
200 if (isFunction(this.parameters[1])) {
201 this.callback = this.parameters[1];
202 this.parameters[1] = false;
203 } else {
204 this.parameters[1] = !!this.parameters[1];
205 }
206 }
207 }, {
208 key: "afterExecution",
209 value: function afterExecution(response) {
210 return this.formatters.outputBlockFormatter(response);
211 }
212 }]);
213 return AbstractGetBlockMethod;
214 }(AbstractMethod);
215
216 function _createSuper$1(Derived) { return function () { var Super = _getPrototypeOf(Derived), result; if (_isNativeReflectConstruct$1()) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
217 function _isNativeReflectConstruct$1() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
218 var GetBlockByNumberMethod = function (_AbstractGetBlockMeth) {
219 _inherits(GetBlockByNumberMethod, _AbstractGetBlockMeth);
220 var _super = _createSuper$1(GetBlockByNumberMethod);
221 function GetBlockByNumberMethod(utils, formatters, moduleInstance) {
222 _classCallCheck(this, GetBlockByNumberMethod);
223 return _super.call(this, 'cfx_getBlockByEpochNumber', utils, formatters, moduleInstance);
224 }
225 return GetBlockByNumberMethod;
226 }(AbstractGetBlockMethod);
227
228 function _createSuper$2(Derived) { return function () { var Super = _getPrototypeOf(Derived), result; if (_isNativeReflectConstruct$2()) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
229 function _isNativeReflectConstruct$2() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
230 var GetTransactionReceiptMethod = function (_AbstractMethod) {
231 _inherits(GetTransactionReceiptMethod, _AbstractMethod);
232 var _super = _createSuper$2(GetTransactionReceiptMethod);
233 function GetTransactionReceiptMethod(utils, formatters, moduleInstance) {
234 _classCallCheck(this, GetTransactionReceiptMethod);
235 return _super.call(this, 'cfx_getTransactionReceipt', 1, utils, formatters, moduleInstance);
236 }
237 _createClass(GetTransactionReceiptMethod, [{
238 key: "afterExecution",
239 value: function afterExecution(response) {
240 if (response !== null) {
241 return this.formatters.outputTransactionReceiptFormatter(response);
242 }
243 return response;
244 }
245 }]);
246 return GetTransactionReceiptMethod;
247 }(AbstractMethod);
248
249 var TransactionObserver = function () {
250 function TransactionObserver(provider, timeout, blockConfirmations, getTransactionReceiptMethod, getBlockByNumberMethod, newHeadsSubscription) {
251 _classCallCheck(this, TransactionObserver);
252 this.provider = provider;
253 this.timeout = timeout;
254 this.blockConfirmations = blockConfirmations;
255 this.getTransactionReceiptMethod = getTransactionReceiptMethod;
256 this.getBlockByNumberMethod = getBlockByNumberMethod;
257 this.newHeadsSubscription = newHeadsSubscription;
258 this.blockNumbers = [];
259 this.lastBlock = false;
260 this.confirmations = 0;
261 this.confirmationChecks = 0;
262 this.interval = false;
263 }
264 _createClass(TransactionObserver, [{
265 key: "observe",
266 value: function observe(transactionHash) {
267 var _this = this;
268 return rxjs.Observable.create(function (observer) {
269 if (_this.provider.supportsSubscriptions()) {
270 _this.startSocketObserver(transactionHash, observer);
271 } else {
272 _this.startHttpObserver(transactionHash, observer);
273 }
274 });
275 }
276 }, {
277 key: "startSocketObserver",
278 value: function startSocketObserver(transactionHash, observer) {
279 var _this2 = this;
280 this.newHeadsSubscription.subscribe( function () {
281 var _ref = _asyncToGenerator( _regeneratorRuntime.mark(function _callee(error, newHead) {
282 var receipt;
283 return _regeneratorRuntime.wrap(function _callee$(_context) {
284 while (1) {
285 switch (_context.prev = _context.next) {
286 case 0:
287 _context.prev = 0;
288 if (!observer.closed) {
289 _context.next = 5;
290 break;
291 }
292 _context.next = 4;
293 return _this2.newHeadsSubscription.unsubscribe();
294 case 4:
295 return _context.abrupt("return");
296 case 5:
297 if (!error) {
298 _context.next = 7;
299 break;
300 }
301 throw error;
302 case 7:
303 _this2.getTransactionReceiptMethod.parameters = [transactionHash];
304 _context.next = 10;
305 return _this2.getTransactionReceiptMethod.execute();
306 case 10:
307 receipt = _context.sent;
308 if (_this2.blockNumbers.includes(newHead.number)) {
309 _context.next = 25;
310 break;
311 }
312 if (!receipt) {
313 _context.next = 19;
314 break;
315 }
316 _this2.confirmations++;
317 _this2.emitNext(receipt, observer);
318 if (!_this2.isConfirmed()) {
319 _context.next = 19;
320 break;
321 }
322 _context.next = 18;
323 return _this2.newHeadsSubscription.unsubscribe();
324 case 18:
325 observer.complete();
326 case 19:
327 _this2.blockNumbers.push(newHead.number);
328 _this2.confirmationChecks++;
329 if (!_this2.isTimeoutTimeExceeded()) {
330 _context.next = 25;
331 break;
332 }
333 _context.next = 24;
334 return _this2.newHeadsSubscription.unsubscribe();
335 case 24:
336 _this2.emitError(new Error('Timeout exceeded during the transaction confirmation process. Be aware the transaction could still get confirmed!'), receipt, observer);
337 case 25:
338 _context.next = 30;
339 break;
340 case 27:
341 _context.prev = 27;
342 _context.t0 = _context["catch"](0);
343 _this2.emitError(_context.t0, false, observer);
344 case 30:
345 case "end":
346 return _context.stop();
347 }
348 }
349 }, _callee, null, [[0, 27]]);
350 }));
351 return function (_x, _x2) {
352 return _ref.apply(this, arguments);
353 };
354 }());
355 }
356 }, {
357 key: "startHttpObserver",
358 value: function startHttpObserver(transactionHash, observer) {
359 var _this3 = this;
360 var interval = setInterval( _asyncToGenerator( _regeneratorRuntime.mark(function _callee2() {
361 var receipt, block;
362 return _regeneratorRuntime.wrap(function _callee2$(_context2) {
363 while (1) {
364 switch (_context2.prev = _context2.next) {
365 case 0:
366 _context2.prev = 0;
367 if (!observer.closed) {
368 _context2.next = 4;
369 break;
370 }
371 clearInterval(interval);
372 return _context2.abrupt("return");
373 case 4:
374 _this3.getTransactionReceiptMethod.parameters = [transactionHash];
375 _context2.next = 7;
376 return _this3.getTransactionReceiptMethod.execute();
377 case 7:
378 receipt = _context2.sent;
379 if (!receipt) {
380 _context2.next = 22;
381 break;
382 }
383 if (!_this3.lastBlock) {
384 _context2.next = 16;
385 break;
386 }
387 _context2.next = 12;
388 return _this3.getBlockByNumber(_this3.increaseBlockNumber(_this3.lastBlock.number));
389 case 12:
390 block = _context2.sent;
391 if (block && _this3.isValidConfirmation(block)) {
392 _this3.lastBlock = block;
393 _this3.confirmations++;
394 _this3.emitNext(receipt, observer);
395 }
396 _context2.next = 21;
397 break;
398 case 16:
399 _context2.next = 18;
400 return _this3.getBlockByNumber(receipt.blockNumber);
401 case 18:
402 _this3.lastBlock = _context2.sent;
403 _this3.confirmations++;
404 _this3.emitNext(receipt, observer);
405 case 21:
406 if (_this3.isConfirmed()) {
407 clearInterval(interval);
408 observer.complete();
409 }
410 case 22:
411 _this3.confirmationChecks++;
412 if (_this3.isTimeoutTimeExceeded()) {
413 clearInterval(interval);
414 _this3.emitError(new Error('Timeout exceeded during the transaction confirmation process. Be aware the transaction could still get confirmed!'), receipt, observer);
415 }
416 _context2.next = 30;
417 break;
418 case 26:
419 _context2.prev = 26;
420 _context2.t0 = _context2["catch"](0);
421 clearInterval(interval);
422 _this3.emitError(_context2.t0, false, observer);
423 case 30:
424 case "end":
425 return _context2.stop();
426 }
427 }
428 }, _callee2, null, [[0, 26]]);
429 })), 1000);
430 }
431 }, {
432 key: "emitNext",
433 value: function emitNext(receipt, observer) {
434 observer.next({
435 receipt: receipt,
436 confirmations: this.confirmations
437 });
438 }
439 }, {
440 key: "emitError",
441 value: function emitError(error, receipt, observer) {
442 observer.error({
443 error: error,
444 receipt: receipt,
445 confirmations: this.confirmations,
446 confirmationChecks: this.confirmationChecks
447 });
448 }
449 }, {
450 key: "getBlockByNumber",
451 value: function getBlockByNumber(blockNumber) {
452 this.getBlockByNumberMethod.parameters = [blockNumber];
453 return this.getBlockByNumberMethod.execute();
454 }
455 }, {
456 key: "isConfirmed",
457 value: function isConfirmed() {
458 return this.confirmations === this.blockConfirmations;
459 }
460 }, {
461 key: "isValidConfirmation",
462 value: function isValidConfirmation(block) {
463 return this.lastBlock.hash === block.parentHash && this.lastBlock.number !== block.number;
464 }
465 }, {
466 key: "isTimeoutTimeExceeded",
467 value: function isTimeoutTimeExceeded() {
468 return this.confirmationChecks === this.timeout;
469 }
470 }, {
471 key: "increaseBlockNumber",
472 value: function increaseBlockNumber(blockNumber) {
473 return '0x' + (parseInt(blockNumber, 16) + 1).toString(16);
474 }
475 }]);
476 return TransactionObserver;
477 }();
478
479 function _createSuper$3(Derived) { return function () { var Super = _getPrototypeOf(Derived), result; if (_isNativeReflectConstruct$3()) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
480 function _isNativeReflectConstruct$3() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
481 var GetTransactionCountMethod = function (_AbstractMethod) {
482 _inherits(GetTransactionCountMethod, _AbstractMethod);
483 var _super = _createSuper$3(GetTransactionCountMethod);
484 function GetTransactionCountMethod(utils, formatters, moduleInstance) {
485 _classCallCheck(this, GetTransactionCountMethod);
486 return _super.call(this, 'cfx_getTransactionCount', 2, utils, formatters, moduleInstance);
487 }
488 _createClass(GetTransactionCountMethod, [{
489 key: "beforeExecution",
490 value: function beforeExecution(moduleInstance) {
491 this.parameters[0] = this.formatters.inputAddressFormatter(this.parameters[0]);
492 if (isFunction(this.parameters[1])) {
493 this.callback = this.parameters[1];
494 this.parameters[1] = moduleInstance.defaultEpoch;
495 }
496 this.parameters[1] = this.formatters.inputDefaultEpochNumberFormatter(this.parameters[1], moduleInstance);
497 }
498 }, {
499 key: "afterExecution",
500 value: function afterExecution(response) {
501 return this.utils.hexToNumber(response);
502 }
503 }]);
504 return GetTransactionCountMethod;
505 }(AbstractMethod);
506
507 function _createSuper$4(Derived) { return function () { var Super = _getPrototypeOf(Derived), result; if (_isNativeReflectConstruct$4()) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
508 function _isNativeReflectConstruct$4() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
509 var ChainIdMethod = function (_AbstractMethod) {
510 _inherits(ChainIdMethod, _AbstractMethod);
511 var _super = _createSuper$4(ChainIdMethod);
512 function ChainIdMethod(utils, formatters, moduleInstance) {
513 _classCallCheck(this, ChainIdMethod);
514 return _super.call(this, 'eth_chainId', 0, utils, formatters, moduleInstance);
515 }
516 _createClass(ChainIdMethod, [{
517 key: "afterExecution",
518 value: function afterExecution(response) {
519 return this.utils.hexToNumber(response);
520 }
521 }]);
522 return ChainIdMethod;
523 }(AbstractMethod);
524
525 var AbstractMethodFactory = function () {
526 function AbstractMethodFactory(utils, formatters) {
527 _classCallCheck(this, AbstractMethodFactory);
528 this.utils = utils;
529 this.formatters = formatters;
530 this._methods = null;
531 }
532 _createClass(AbstractMethodFactory, [{
533 key: "hasMethod",
534 value: function hasMethod(name) {
535 return typeof this.methods[name] !== 'undefined';
536 }
537 }, {
538 key: "createMethod",
539 value: function createMethod(name, moduleInstance) {
540 var method = this.methods[name];
541 if (method.Type === 'observed-transaction-method') {
542 return new method(this.utils, this.formatters, moduleInstance, this.createTransactionObserver(moduleInstance));
543 }
544 if (method.Type === 'cfx-send-transaction-method') {
545 return new method(this.utils, this.formatters, moduleInstance, this.createTransactionObserver(moduleInstance), new ChainIdMethod(this.utils, this.formatters, moduleInstance), new GetTransactionCountMethod(this.utils, this.formatters, moduleInstance));
546 }
547 return new method(this.utils, this.formatters, moduleInstance);
548 }
549 }, {
550 key: "getTimeout",
551 value: function getTimeout(moduleInstance) {
552 var timeout = moduleInstance.transactionBlockTimeout;
553 if (!moduleInstance.currentProvider.supportsSubscriptions()) {
554 timeout = moduleInstance.transactionPollingTimeout;
555 }
556 return timeout;
557 }
558 }, {
559 key: "createTransactionObserver",
560 value: function createTransactionObserver(moduleInstance) {
561 return new TransactionObserver(moduleInstance.currentProvider, this.getTimeout(moduleInstance), moduleInstance.transactionConfirmationBlocks, new GetTransactionReceiptMethod(this.utils, this.formatters, moduleInstance), new GetBlockByNumberMethod(this.utils, this.formatters, moduleInstance), new confluxWebCoreSubscriptions.NewHeadsSubscription(this.utils, this.formatters, moduleInstance));
562 }
563 }, {
564 key: "methods",
565 get: function get() {
566 if (this._methods) {
567 return this._methods;
568 }
569 throw new Error('No methods defined for MethodFactory!');
570 }
571 ,
572 set: function set(value) {
573 this._methods = value;
574 }
575 }]);
576 return AbstractMethodFactory;
577 }();
578
579 var MethodProxy =
580 function MethodProxy(target, methodFactory) {
581 _classCallCheck(this, MethodProxy);
582 return new Proxy(target, {
583 get: function get(target, name) {
584 if (methodFactory.hasMethod(name)) {
585 var RpcMethod = function RpcMethod() {
586 method.setArguments(arguments);
587 return method.execute();
588 };
589 if (typeof target[name] !== 'undefined') {
590 throw new TypeError("Duplicated method ".concat(name, ". This method is defined as RPC call and as Object method."));
591 }
592 var method = methodFactory.createMethod(name, target);
593 RpcMethod.method = method;
594 RpcMethod.request = function () {
595 method.setArguments(arguments);
596 return method;
597 };
598 return RpcMethod;
599 }
600 return target[name];
601 }
602 });
603 };
604
605 function _createSuper$5(Derived) { return function () { var Super = _getPrototypeOf(Derived), result; if (_isNativeReflectConstruct$5()) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
606 function _isNativeReflectConstruct$5() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
607 var GetProtocolVersionMethod = function (_AbstractMethod) {
608 _inherits(GetProtocolVersionMethod, _AbstractMethod);
609 var _super = _createSuper$5(GetProtocolVersionMethod);
610 function GetProtocolVersionMethod(utils, formatters, moduleInstance) {
611 _classCallCheck(this, GetProtocolVersionMethod);
612 return _super.call(this, 'eth_protocolVersion', 0, utils, formatters, moduleInstance);
613 }
614 _createClass(GetProtocolVersionMethod, [{
615 key: "afterExecution",
616 value: function afterExecution(response) {
617 return this.utils.hexToNumber(response);
618 }
619 }]);
620 return GetProtocolVersionMethod;
621 }(AbstractMethod);
622
623 function _createSuper$6(Derived) { return function () { var Super = _getPrototypeOf(Derived), result; if (_isNativeReflectConstruct$6()) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
624 function _isNativeReflectConstruct$6() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
625 var VersionMethod = function (_AbstractMethod) {
626 _inherits(VersionMethod, _AbstractMethod);
627 var _super = _createSuper$6(VersionMethod);
628 function VersionMethod(utils, formatters, moduleInstance) {
629 _classCallCheck(this, VersionMethod);
630 return _super.call(this, 'net_version', 0, utils, formatters, moduleInstance);
631 }
632 _createClass(VersionMethod, [{
633 key: "afterExecution",
634 value: function afterExecution(response) {
635 return this.utils.hexToNumber(response);
636 }
637 }]);
638 return VersionMethod;
639 }(AbstractMethod);
640
641 function _createSuper$7(Derived) { return function () { var Super = _getPrototypeOf(Derived), result; if (_isNativeReflectConstruct$7()) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
642 function _isNativeReflectConstruct$7() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
643 var ListeningMethod = function (_AbstractMethod) {
644 _inherits(ListeningMethod, _AbstractMethod);
645 var _super = _createSuper$7(ListeningMethod);
646 function ListeningMethod(utils, formatters, moduleInstance) {
647 _classCallCheck(this, ListeningMethod);
648 return _super.call(this, 'net_listening', 0, utils, formatters, moduleInstance);
649 }
650 return ListeningMethod;
651 }(AbstractMethod);
652
653 function _createSuper$8(Derived) { return function () { var Super = _getPrototypeOf(Derived), result; if (_isNativeReflectConstruct$8()) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
654 function _isNativeReflectConstruct$8() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
655 var PeerCountMethod = function (_AbstractMethod) {
656 _inherits(PeerCountMethod, _AbstractMethod);
657 var _super = _createSuper$8(PeerCountMethod);
658 function PeerCountMethod(utils, formatters, moduleInstance) {
659 _classCallCheck(this, PeerCountMethod);
660 return _super.call(this, 'net_peerCount', 0, utils, formatters, moduleInstance);
661 }
662 _createClass(PeerCountMethod, [{
663 key: "afterExecution",
664 value: function afterExecution(response) {
665 return this.utils.hexToNumber(response);
666 }
667 }]);
668 return PeerCountMethod;
669 }(AbstractMethod);
670
671 function _createSuper$9(Derived) { return function () { var Super = _getPrototypeOf(Derived), result; if (_isNativeReflectConstruct$9()) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
672 function _isNativeReflectConstruct$9() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
673 var GetNodeInfoMethod = function (_AbstractMethod) {
674 _inherits(GetNodeInfoMethod, _AbstractMethod);
675 var _super = _createSuper$9(GetNodeInfoMethod);
676 function GetNodeInfoMethod(utils, formatters, moduleInstance) {
677 _classCallCheck(this, GetNodeInfoMethod);
678 return _super.call(this, 'confluxWeb_clientVersion', 0, utils, formatters, moduleInstance);
679 }
680 return GetNodeInfoMethod;
681 }(AbstractMethod);
682
683 function _createSuper$a(Derived) { return function () { var Super = _getPrototypeOf(Derived), result; if (_isNativeReflectConstruct$a()) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
684 function _isNativeReflectConstruct$a() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
685 var GetCoinbaseMethod = function (_AbstractMethod) {
686 _inherits(GetCoinbaseMethod, _AbstractMethod);
687 var _super = _createSuper$a(GetCoinbaseMethod);
688 function GetCoinbaseMethod(utils, formatters, moduleInstance) {
689 _classCallCheck(this, GetCoinbaseMethod);
690 return _super.call(this, 'eth_coinbase', 0, utils, formatters, moduleInstance);
691 }
692 return GetCoinbaseMethod;
693 }(AbstractMethod);
694
695 function _createSuper$b(Derived) { return function () { var Super = _getPrototypeOf(Derived), result; if (_isNativeReflectConstruct$b()) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
696 function _isNativeReflectConstruct$b() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
697 var IsMiningMethod = function (_AbstractMethod) {
698 _inherits(IsMiningMethod, _AbstractMethod);
699 var _super = _createSuper$b(IsMiningMethod);
700 function IsMiningMethod(utils, formatters, moduleInstance) {
701 _classCallCheck(this, IsMiningMethod);
702 return _super.call(this, 'eth_mining', 0, utils, formatters, moduleInstance);
703 }
704 return IsMiningMethod;
705 }(AbstractMethod);
706
707 function _createSuper$c(Derived) { return function () { var Super = _getPrototypeOf(Derived), result; if (_isNativeReflectConstruct$c()) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
708 function _isNativeReflectConstruct$c() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
709 var GetHashrateMethod = function (_AbstractMethod) {
710 _inherits(GetHashrateMethod, _AbstractMethod);
711 var _super = _createSuper$c(GetHashrateMethod);
712 function GetHashrateMethod(utils, formatters, moduleInstance) {
713 _classCallCheck(this, GetHashrateMethod);
714 return _super.call(this, 'eth_hashrate', 0, utils, formatters, moduleInstance);
715 }
716 _createClass(GetHashrateMethod, [{
717 key: "afterExecution",
718 value: function afterExecution(response) {
719 return this.utils.hexToNumber(response);
720 }
721 }]);
722 return GetHashrateMethod;
723 }(AbstractMethod);
724
725 function _createSuper$d(Derived) { return function () { var Super = _getPrototypeOf(Derived), result; if (_isNativeReflectConstruct$d()) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
726 function _isNativeReflectConstruct$d() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
727 var IsSyncingMethod = function (_AbstractMethod) {
728 _inherits(IsSyncingMethod, _AbstractMethod);
729 var _super = _createSuper$d(IsSyncingMethod);
730 function IsSyncingMethod(utils, formatters, moduleInstance) {
731 _classCallCheck(this, IsSyncingMethod);
732 return _super.call(this, 'eth_syncing', 0, utils, formatters, moduleInstance);
733 }
734 _createClass(IsSyncingMethod, [{
735 key: "afterExecution",
736 value: function afterExecution(response) {
737 if (typeof response !== 'boolean') {
738 return this.formatters.outputSyncingFormatter(response);
739 }
740 return response;
741 }
742 }]);
743 return IsSyncingMethod;
744 }(AbstractMethod);
745
746 function _createSuper$e(Derived) { return function () { var Super = _getPrototypeOf(Derived), result; if (_isNativeReflectConstruct$e()) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
747 function _isNativeReflectConstruct$e() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
748 var GetGasPriceMethod = function (_AbstractMethod) {
749 _inherits(GetGasPriceMethod, _AbstractMethod);
750 var _super = _createSuper$e(GetGasPriceMethod);
751 function GetGasPriceMethod(utils, formatters, moduleInstance) {
752 _classCallCheck(this, GetGasPriceMethod);
753 return _super.call(this, 'cfx_gasPrice', 0, utils, formatters, moduleInstance);
754 }
755 _createClass(GetGasPriceMethod, [{
756 key: "afterExecution",
757 value: function afterExecution(response) {
758 return this.formatters.outputBigNumberFormatter(response);
759 }
760 }]);
761 return GetGasPriceMethod;
762 }(AbstractMethod);
763
764 function _createSuper$f(Derived) { return function () { var Super = _getPrototypeOf(Derived), result; if (_isNativeReflectConstruct$f()) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
765 function _isNativeReflectConstruct$f() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
766 var SubmitWorkMethod = function (_AbstractMethod) {
767 _inherits(SubmitWorkMethod, _AbstractMethod);
768 var _super = _createSuper$f(SubmitWorkMethod);
769 function SubmitWorkMethod(utils, formatters, moduleInstance) {
770 _classCallCheck(this, SubmitWorkMethod);
771 return _super.call(this, 'eth_submitWork', 3, utils, formatters, moduleInstance);
772 }
773 return SubmitWorkMethod;
774 }(AbstractMethod);
775
776 function _createSuper$g(Derived) { return function () { var Super = _getPrototypeOf(Derived), result; if (_isNativeReflectConstruct$g()) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
777 function _isNativeReflectConstruct$g() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
778 var GetWorkMethod = function (_AbstractMethod) {
779 _inherits(GetWorkMethod, _AbstractMethod);
780 var _super = _createSuper$g(GetWorkMethod);
781 function GetWorkMethod(utils, formatters, moduleInstance) {
782 _classCallCheck(this, GetWorkMethod);
783 return _super.call(this, 'eth_getWork', 0, utils, formatters, moduleInstance);
784 }
785 return GetWorkMethod;
786 }(AbstractMethod);
787
788 function _createSuper$h(Derived) { return function () { var Super = _getPrototypeOf(Derived), result; if (_isNativeReflectConstruct$h()) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
789 function _isNativeReflectConstruct$h() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
790 var GetAccountsMethod = function (_AbstractMethod) {
791 _inherits(GetAccountsMethod, _AbstractMethod);
792 var _super = _createSuper$h(GetAccountsMethod);
793 function GetAccountsMethod(utils, formatters, moduleInstance) {
794 _classCallCheck(this, GetAccountsMethod);
795 return _super.call(this, 'cfx_accounts', 0, utils, formatters, moduleInstance);
796 }
797 _createClass(GetAccountsMethod, [{
798 key: "afterExecution",
799 value: function afterExecution(response) {
800 var _this = this;
801 return response.map(function (responseItem) {
802 return _this.utils.toChecksumAddress(responseItem);
803 });
804 }
805 }]);
806 return GetAccountsMethod;
807 }(AbstractMethod);
808
809 function _createSuper$i(Derived) { return function () { var Super = _getPrototypeOf(Derived), result; if (_isNativeReflectConstruct$i()) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
810 function _isNativeReflectConstruct$i() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
811 var GetBalanceMethod = function (_AbstractMethod) {
812 _inherits(GetBalanceMethod, _AbstractMethod);
813 var _super = _createSuper$i(GetBalanceMethod);
814 function GetBalanceMethod(utils, formatters, moduleInstance) {
815 _classCallCheck(this, GetBalanceMethod);
816 return _super.call(this, 'cfx_getBalance', 2, utils, formatters, moduleInstance);
817 }
818 _createClass(GetBalanceMethod, [{
819 key: "beforeExecution",
820 value: function beforeExecution(moduleInstance) {
821 this.parameters[0] = this.formatters.inputAddressFormatter(this.parameters[0]);
822 if (isFunction(this.parameters[1])) {
823 this.callback = this.parameters[1];
824 this.parameters[1] = moduleInstance.defaultEpoch;
825 }
826 this.parameters[1] = this.formatters.inputDefaultEpochNumberFormatter(this.parameters[1], moduleInstance);
827 }
828 }, {
829 key: "afterExecution",
830 value: function afterExecution(response) {
831 return this.formatters.outputBigNumberFormatter(response);
832 }
833 }]);
834 return GetBalanceMethod;
835 }(AbstractMethod);
836
837 function _createSuper$j(Derived) { return function () { var Super = _getPrototypeOf(Derived), result; if (_isNativeReflectConstruct$j()) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
838 function _isNativeReflectConstruct$j() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
839 var RequestAccountsMethod = function (_AbstractMethod) {
840 _inherits(RequestAccountsMethod, _AbstractMethod);
841 var _super = _createSuper$j(RequestAccountsMethod);
842 function RequestAccountsMethod(utils, formatters, moduleInstance) {
843 _classCallCheck(this, RequestAccountsMethod);
844 return _super.call(this, 'eth_requestAccounts', 0, utils, formatters, moduleInstance);
845 }
846 return RequestAccountsMethod;
847 }(AbstractMethod);
848
849 function _createSuper$k(Derived) { return function () { var Super = _getPrototypeOf(Derived), result; if (_isNativeReflectConstruct$k()) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
850 function _isNativeReflectConstruct$k() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
851 var AbstractGetBlockTransactionCountMethod = function (_AbstractMethod) {
852 _inherits(AbstractGetBlockTransactionCountMethod, _AbstractMethod);
853 var _super = _createSuper$k(AbstractGetBlockTransactionCountMethod);
854 function AbstractGetBlockTransactionCountMethod(rpcMethod, utils, formatters, moduleInstance) {
855 _classCallCheck(this, AbstractGetBlockTransactionCountMethod);
856 return _super.call(this, rpcMethod, 1, utils, formatters, moduleInstance);
857 }
858 _createClass(AbstractGetBlockTransactionCountMethod, [{
859 key: "beforeExecution",
860 value: function beforeExecution(moduleInstance) {
861 this.parameters[0] = this.formatters.inputBlockAddressFormatter(this.parameters[0]);
862 }
863 }, {
864 key: "afterExecution",
865 value: function afterExecution(response) {
866 return this.utils.hexToNumber(response);
867 }
868 }]);
869 return AbstractGetBlockTransactionCountMethod;
870 }(AbstractMethod);
871
872 function _createSuper$l(Derived) { return function () { var Super = _getPrototypeOf(Derived), result; if (_isNativeReflectConstruct$l()) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
873 function _isNativeReflectConstruct$l() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
874 var GetBlockByHashMethod = function (_AbstractGetBlockMeth) {
875 _inherits(GetBlockByHashMethod, _AbstractGetBlockMeth);
876 var _super = _createSuper$l(GetBlockByHashMethod);
877 function GetBlockByHashMethod(utils, formatters, moduleInstance) {
878 _classCallCheck(this, GetBlockByHashMethod);
879 return _super.call(this, 'cfx_getBlockByHash', utils, formatters, moduleInstance);
880 }
881 return GetBlockByHashMethod;
882 }(AbstractGetBlockMethod);
883
884 function _createSuper$m(Derived) { return function () { var Super = _getPrototypeOf(Derived), result; if (_isNativeReflectConstruct$m()) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
885 function _isNativeReflectConstruct$m() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
886 var GetBlockTransactionCountByHashMethod = function (_AbstractGetBlockTran) {
887 _inherits(GetBlockTransactionCountByHashMethod, _AbstractGetBlockTran);
888 var _super = _createSuper$m(GetBlockTransactionCountByHashMethod);
889 function GetBlockTransactionCountByHashMethod(utils, formatters, moduleInstance) {
890 _classCallCheck(this, GetBlockTransactionCountByHashMethod);
891 return _super.call(this, 'cfx_getBlockTransactionCountByHash', utils, formatters, moduleInstance);
892 }
893 return GetBlockTransactionCountByHashMethod;
894 }(AbstractGetBlockTransactionCountMethod);
895
896 function _createSuper$n(Derived) { return function () { var Super = _getPrototypeOf(Derived), result; if (_isNativeReflectConstruct$n()) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
897 function _isNativeReflectConstruct$n() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
898 var GetBlockTransactionCountByNumberMethod = function (_AbstractGetBlockTran) {
899 _inherits(GetBlockTransactionCountByNumberMethod, _AbstractGetBlockTran);
900 var _super = _createSuper$n(GetBlockTransactionCountByNumberMethod);
901 function GetBlockTransactionCountByNumberMethod(utils, formatters, moduleInstance) {
902 _classCallCheck(this, GetBlockTransactionCountByNumberMethod);
903 return _super.call(this, 'cfx_getBlockTransactionCountByNumber', utils, formatters, moduleInstance);
904 }
905 return GetBlockTransactionCountByNumberMethod;
906 }(AbstractGetBlockTransactionCountMethod);
907
908 function _createSuper$o(Derived) { return function () { var Super = _getPrototypeOf(Derived), result; if (_isNativeReflectConstruct$o()) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
909 function _isNativeReflectConstruct$o() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
910 var AbstractGetTransactionFromBlockMethod = function (_AbstractMethod) {
911 _inherits(AbstractGetTransactionFromBlockMethod, _AbstractMethod);
912 var _super = _createSuper$o(AbstractGetTransactionFromBlockMethod);
913 function AbstractGetTransactionFromBlockMethod(rpcMethod, utils, formatters, moduleInstance) {
914 _classCallCheck(this, AbstractGetTransactionFromBlockMethod);
915 return _super.call(this, rpcMethod, 2, utils, formatters, moduleInstance);
916 }
917 _createClass(AbstractGetTransactionFromBlockMethod, [{
918 key: "beforeExecution",
919 value: function beforeExecution(moduleInstance) {
920 this.parameters[0] = this.formatters.inputBlockAddressFormatter(this.parameters[0]);
921 this.parameters[1] = this.utils.numberToHex(this.parameters[1]);
922 }
923 }, {
924 key: "afterExecution",
925 value: function afterExecution(response) {
926 return this.formatters.outputTransactionFormatter(response);
927 }
928 }]);
929 return AbstractGetTransactionFromBlockMethod;
930 }(AbstractMethod);
931
932 function _createSuper$p(Derived) { return function () { var Super = _getPrototypeOf(Derived), result; if (_isNativeReflectConstruct$p()) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
933 function _isNativeReflectConstruct$p() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
934 var AbstractObservedTransactionMethod = function (_AbstractMethod) {
935 _inherits(AbstractObservedTransactionMethod, _AbstractMethod);
936 var _super = _createSuper$p(AbstractObservedTransactionMethod);
937 function AbstractObservedTransactionMethod(rpcMethod, parametersAmount, utils, formatters, moduleInstance, transactionObserver) {
938 var _this;
939 _classCallCheck(this, AbstractObservedTransactionMethod);
940 _this = _super.call(this, rpcMethod, parametersAmount, utils, formatters, moduleInstance);
941 _this.transactionObserver = transactionObserver;
942 _this.promiEvent = new PromiEvent();
943 return _this;
944 }
945 _createClass(AbstractObservedTransactionMethod, [{
946 key: "execute",
947 value: function execute() {
948 var _this2 = this;
949 this.beforeExecution(this.moduleInstance);
950 this.moduleInstance.currentProvider.send(this.rpcMethod, this.parameters).then(function (transactionHash) {
951 if (_this2.callback) {
952 _this2.promiEvent.resolve(_this2.callback(false, transactionHash));
953 return;
954 }
955 _this2.promiEvent.resolve(transactionHash);
956 })["catch"](function (error) {
957 if (_this2.callback) {
958 _this2.callback(error, null);
959 return;
960 }
961 _this2.handleError(error, false, 0);
962 });
963 return this.promiEvent;
964 }
965 }, {
966 key: "handleError",
967 value: function handleError(error, receipt, confirmations) {
968 if (this.promiEvent.listenerCount('error') > 0) {
969 this.promiEvent.emit('error', error, receipt, confirmations);
970 this.promiEvent.removeAllListeners();
971 return;
972 }
973 this.promiEvent.reject(error);
974 }
975 }], [{
976 key: "Type",
977 get: function get() {
978 return 'observed-transaction-method';
979 }
980 }]);
981 return AbstractObservedTransactionMethod;
982 }(AbstractMethod);
983
984 function _createSuper$q(Derived) { return function () { var Super = _getPrototypeOf(Derived), result; if (_isNativeReflectConstruct$q()) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
985 function _isNativeReflectConstruct$q() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
986 var SendTransactionMethod = function (_AbstractObservedTran) {
987 _inherits(SendTransactionMethod, _AbstractObservedTran);
988 var _super = _createSuper$q(SendTransactionMethod);
989 function SendTransactionMethod(utils, formatters, moduleInstance, transactionObserver) {
990 _classCallCheck(this, SendTransactionMethod);
991 return _super.call(this, 'cfx_sendTransaction', 1, utils, formatters, moduleInstance, transactionObserver);
992 }
993 _createClass(SendTransactionMethod, [{
994 key: "beforeExecution",
995 value: function beforeExecution(moduleInstance) {
996 this.parameters[0] = this.formatters.inputTransactionFormatter(this.parameters[0], moduleInstance);
997 }
998 }]);
999 return SendTransactionMethod;
1000 }(AbstractObservedTransactionMethod);
1001
1002 function _createSuper$r(Derived) { return function () { var Super = _getPrototypeOf(Derived), result; if (_isNativeReflectConstruct$r()) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
1003 function _isNativeReflectConstruct$r() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
1004 var CfxSendTransactionMethod = function (_SendTransactionMetho) {
1005 _inherits(CfxSendTransactionMethod, _SendTransactionMetho);
1006 var _super = _createSuper$r(CfxSendTransactionMethod);
1007 function CfxSendTransactionMethod(utils, formatters, moduleInstance, transactionObserver, chainIdMethod, getTransactionCountMethod) {
1008 var _this;
1009 _classCallCheck(this, CfxSendTransactionMethod);
1010 _this = _super.call(this, utils, formatters, moduleInstance, transactionObserver);
1011 _this.chainIdMethod = chainIdMethod;
1012 _this.getTransactionCountMethod = getTransactionCountMethod;
1013 return _this;
1014 }
1015 _createClass(CfxSendTransactionMethod, [{
1016 key: "beforeExecution",
1017 value: function beforeExecution(moduleInstance) {
1018 if (this.rpcMethod !== 'cfx_sendRawTransaction') {
1019 _get(_getPrototypeOf(CfxSendTransactionMethod.prototype), "beforeExecution", this).call(this, moduleInstance);
1020 }
1021 }
1022 }, {
1023 key: "execute",
1024 value: function execute() {
1025 var _this2 = this;
1026 if (!this.parameters[0].gas && this.moduleInstance.defaultGas) {
1027 this.parameters[0]['gas'] = this.moduleInstance.defaultGas;
1028 }
1029 if (!this.parameters[0].gasPrice && this.parameters[0].gasPrice !== 0) {
1030 if (!this.moduleInstance.defaultGasPrice) {
1031 this.moduleInstance.currentProvider.send('cfx_gasPrice', []).then(function (gasPrice) {
1032 _this2.parameters[0].gasPrice = gasPrice;
1033 _this2.execute();
1034 })["catch"](function (error) {
1035 _this2.handleError(error, false, 0);
1036 });
1037 return this.promiEvent;
1038 }
1039 this.parameters[0]['gasPrice'] = this.moduleInstance.defaultGasPrice;
1040 }
1041 if (this.hasAccounts() && this.isDefaultSigner()) {
1042 if (this.moduleInstance.accounts.wallet[this.parameters[0].from]) {
1043 this.sendRawTransaction(this.moduleInstance.accounts.wallet[this.parameters[0].from].privateKey)["catch"](function (error) {
1044 _this2.handleError(error, false, 0);
1045 });
1046 return this.promiEvent;
1047 }
1048 }
1049 if (this.hasCustomSigner()) {
1050 this.sendRawTransaction()["catch"](function (error) {
1051 _this2.handleError(error, false, 0);
1052 });
1053 return this.promiEvent;
1054 }
1055 return _get(_getPrototypeOf(CfxSendTransactionMethod.prototype), "execute", this).call(this);
1056 }
1057 }, {
1058 key: "sendRawTransaction",
1059 value: function () {
1060 var _sendRawTransaction = _asyncToGenerator( _regeneratorRuntime.mark(function _callee() {
1061 var privateKey,
1062 transaction,
1063 response,
1064 _args = arguments;
1065 return _regeneratorRuntime.wrap(function _callee$(_context) {
1066 while (1) {
1067 switch (_context.prev = _context.next) {
1068 case 0:
1069 privateKey = _args.length > 0 && _args[0] !== undefined ? _args[0] : null;
1070 this.beforeExecution(this.moduleInstance);
1071 if (!(!this.parameters[0].nonce && this.parameters[0].nonce !== 0)) {
1072 _context.next = 7;
1073 break;
1074 }
1075 this.getTransactionCountMethod.parameters = [this.parameters[0].from, 'latest_state'];
1076 _context.next = 6;
1077 return this.getTransactionCountMethod.execute();
1078 case 6:
1079 this.parameters[0].nonce = _context.sent;
1080 case 7:
1081 if (!this.parameters[0].storageLimit) {
1082 this.parameters[0]['storageLimit'] = 100000000;
1083 }
1084 if (!this.parameters[0].chainId) {
1085 this.parameters[0]['chainId'] = 0;
1086 }
1087 if (this.parameters[0].epochHeight) {
1088 _context.next = 13;
1089 break;
1090 }
1091 _context.next = 12;
1092 return this.moduleInstance.currentProvider.send('cfx_epochNumber', []);
1093 case 12:
1094 this.parameters[0].epochHeight = _context.sent;
1095 case 13:
1096 transaction = this.parameters[0];
1097 transaction.to = transaction.to || '0x';
1098 transaction.data = transaction.data || '0x';
1099 transaction.value = transaction.value || '0x';
1100 delete transaction.from;
1101 _context.next = 20;
1102 return this.moduleInstance.transactionSigner.sign(transaction, privateKey);
1103 case 20:
1104 response = _context.sent;
1105 this.parameters = [response.rawTransaction];
1106 this.rpcMethod = 'cfx_sendRawTransaction';
1107 return _context.abrupt("return", _get(_getPrototypeOf(CfxSendTransactionMethod.prototype), "execute", this).call(this));
1108 case 24:
1109 case "end":
1110 return _context.stop();
1111 }
1112 }
1113 }, _callee, this);
1114 }));
1115 function sendRawTransaction() {
1116 return _sendRawTransaction.apply(this, arguments);
1117 }
1118 return sendRawTransaction;
1119 }()
1120 }, {
1121 key: "isDefaultSigner",
1122 value: function isDefaultSigner() {
1123 return this.moduleInstance.transactionSigner.type === 'TransactionSigner';
1124 }
1125 }, {
1126 key: "hasAccounts",
1127 value: function hasAccounts() {
1128 return this.moduleInstance.accounts && this.moduleInstance.accounts.wallet.accountsIndex > 0;
1129 }
1130 }, {
1131 key: "hasCustomSigner",
1132 value: function hasCustomSigner() {
1133 return this.moduleInstance.transactionSigner.type !== 'TransactionSigner';
1134 }
1135 }], [{
1136 key: "Type",
1137 get: function get() {
1138 return 'cfx-send-transaction-method';
1139 }
1140 }]);
1141 return CfxSendTransactionMethod;
1142 }(SendTransactionMethod);
1143
1144 function _createSuper$s(Derived) { return function () { var Super = _getPrototypeOf(Derived), result; if (_isNativeReflectConstruct$s()) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
1145 function _isNativeReflectConstruct$s() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
1146 var GetTransactionMethod = function (_AbstractMethod) {
1147 _inherits(GetTransactionMethod, _AbstractMethod);
1148 var _super = _createSuper$s(GetTransactionMethod);
1149 function GetTransactionMethod(utils, formatters, moduleInstance) {
1150 _classCallCheck(this, GetTransactionMethod);
1151 return _super.call(this, 'cfx_getTransactionByHash', 1, utils, formatters, moduleInstance);
1152 }
1153 _createClass(GetTransactionMethod, [{
1154 key: "afterExecution",
1155 value: function afterExecution(response) {
1156 return this.formatters.outputTransactionFormatter(response);
1157 }
1158 }]);
1159 return GetTransactionMethod;
1160 }(AbstractMethod);
1161
1162 function _createSuper$t(Derived) { return function () { var Super = _getPrototypeOf(Derived), result; if (_isNativeReflectConstruct$t()) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
1163 function _isNativeReflectConstruct$t() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
1164 var GetTransactionByBlockHashAndIndexMethod = function (_AbstractGetTransacti) {
1165 _inherits(GetTransactionByBlockHashAndIndexMethod, _AbstractGetTransacti);
1166 var _super = _createSuper$t(GetTransactionByBlockHashAndIndexMethod);
1167 function GetTransactionByBlockHashAndIndexMethod(utils, formatters, moduleInstance) {
1168 _classCallCheck(this, GetTransactionByBlockHashAndIndexMethod);
1169 return _super.call(this, 'cfx_getTransactionByBlockHashAndIndex', utils, formatters, moduleInstance);
1170 }
1171 return GetTransactionByBlockHashAndIndexMethod;
1172 }(AbstractGetTransactionFromBlockMethod);
1173
1174 function _createSuper$u(Derived) { return function () { var Super = _getPrototypeOf(Derived), result; if (_isNativeReflectConstruct$u()) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
1175 function _isNativeReflectConstruct$u() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
1176 var GetTransactionByBlockAddressAndIndexMethod = function (_AbstractGetTransacti) {
1177 _inherits(GetTransactionByBlockAddressAndIndexMethod, _AbstractGetTransacti);
1178 var _super = _createSuper$u(GetTransactionByBlockAddressAndIndexMethod);
1179 function GetTransactionByBlockAddressAndIndexMethod(utils, formatters, moduleInstance) {
1180 _classCallCheck(this, GetTransactionByBlockAddressAndIndexMethod);
1181 return _super.call(this, 'cfx_getTransactionByBlockAddressAndIndex', utils, formatters, moduleInstance);
1182 }
1183 return GetTransactionByBlockAddressAndIndexMethod;
1184 }(AbstractGetTransactionFromBlockMethod);
1185
1186 function _createSuper$v(Derived) { return function () { var Super = _getPrototypeOf(Derived), result; if (_isNativeReflectConstruct$v()) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
1187 function _isNativeReflectConstruct$v() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
1188 var SendRawTransactionMethod = function (_AbstractObservedTran) {
1189 _inherits(SendRawTransactionMethod, _AbstractObservedTran);
1190 var _super = _createSuper$v(SendRawTransactionMethod);
1191 function SendRawTransactionMethod(utils, formatters, moduleInstance, transactionObserver) {
1192 _classCallCheck(this, SendRawTransactionMethod);
1193 return _super.call(this, 'cfx_sendRawTransaction', 1, utils, formatters, moduleInstance, transactionObserver);
1194 }
1195 return SendRawTransactionMethod;
1196 }(AbstractObservedTransactionMethod);
1197
1198 function _createSuper$w(Derived) { return function () { var Super = _getPrototypeOf(Derived), result; if (_isNativeReflectConstruct$w()) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
1199 function _isNativeReflectConstruct$w() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
1200 var SignTransactionMethod = function (_AbstractMethod) {
1201 _inherits(SignTransactionMethod, _AbstractMethod);
1202 var _super = _createSuper$w(SignTransactionMethod);
1203 function SignTransactionMethod(utils, formatters, moduleInstance) {
1204 _classCallCheck(this, SignTransactionMethod);
1205 return _super.call(this, 'cfx_signTransaction', 1, utils, formatters, moduleInstance);
1206 }
1207 _createClass(SignTransactionMethod, [{
1208 key: "beforeExecution",
1209 value: function beforeExecution(moduleInstance) {
1210 this.parameters[0] = this.formatters.inputTransactionFormatter(this.parameters[0], moduleInstance);
1211 }
1212 }]);
1213 return SignTransactionMethod;
1214 }(AbstractMethod);
1215
1216 function _createSuper$x(Derived) { return function () { var Super = _getPrototypeOf(Derived), result; if (_isNativeReflectConstruct$x()) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
1217 function _isNativeReflectConstruct$x() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
1218 var GetCodeMethod = function (_AbstractMethod) {
1219 _inherits(GetCodeMethod, _AbstractMethod);
1220 var _super = _createSuper$x(GetCodeMethod);
1221 function GetCodeMethod(utils, formatters, moduleInstance) {
1222 _classCallCheck(this, GetCodeMethod);
1223 return _super.call(this, 'cfx_getCode', 2, utils, formatters, moduleInstance);
1224 }
1225 _createClass(GetCodeMethod, [{
1226 key: "beforeExecution",
1227 value: function beforeExecution(moduleInstance) {
1228 this.parameters[0] = this.formatters.inputAddressFormatter(this.parameters[0]);
1229 if (isFunction(this.parameters[1])) {
1230 this.callback = this.parameters[1];
1231 this.parameters[1] = moduleInstance.defaultEpoch;
1232 }
1233 this.parameters[1] = this.formatters.inputDefaultEpochNumberFormatter(this.parameters[1], moduleInstance);
1234 }
1235 }]);
1236 return GetCodeMethod;
1237 }(AbstractMethod);
1238
1239 function _createSuper$y(Derived) { return function () { var Super = _getPrototypeOf(Derived), result; if (_isNativeReflectConstruct$y()) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
1240 function _isNativeReflectConstruct$y() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
1241 var SignMethod = function (_AbstractMethod) {
1242 _inherits(SignMethod, _AbstractMethod);
1243 var _super = _createSuper$y(SignMethod);
1244 function SignMethod(utils, formatters, moduleInstance) {
1245 _classCallCheck(this, SignMethod);
1246 return _super.call(this, 'cfx_sign', 2, utils, formatters, moduleInstance);
1247 }
1248 _createClass(SignMethod, [{
1249 key: "beforeExecution",
1250 value: function beforeExecution(moduleInstance) {
1251 this.parameters[0] = this.formatters.inputSignFormatter(this.parameters[0]);
1252 this.parameters[1] = this.formatters.inputAddressFormatter(this.parameters[1]);
1253 this.parameters.reverse();
1254 }
1255 }]);
1256 return SignMethod;
1257 }(AbstractMethod);
1258
1259 function _createSuper$z(Derived) { return function () { var Super = _getPrototypeOf(Derived), result; if (_isNativeReflectConstruct$z()) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
1260 function _isNativeReflectConstruct$z() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
1261 var CallMethod = function (_AbstractMethod) {
1262 _inherits(CallMethod, _AbstractMethod);
1263 var _super = _createSuper$z(CallMethod);
1264 function CallMethod(utils, formatters, moduleInstance) {
1265 _classCallCheck(this, CallMethod);
1266 return _super.call(this, 'cfx_call', 2, utils, formatters, moduleInstance);
1267 }
1268 _createClass(CallMethod, [{
1269 key: "beforeExecution",
1270 value: function beforeExecution(moduleInstance) {
1271 this.parameters[0] = this.formatters.inputCallFormatter(this.parameters[0], moduleInstance);
1272 if (isFunction(this.parameters[1])) {
1273 this.callback = this.parameters[1];
1274 this.parameters[1] = moduleInstance.defaultEpoch;
1275 }
1276 this.parameters[1] = this.formatters.inputDefaultEpochNumberFormatter(this.parameters[1], moduleInstance);
1277 }
1278 }]);
1279 return CallMethod;
1280 }(AbstractMethod);
1281
1282 function _createSuper$A(Derived) { return function () { var Super = _getPrototypeOf(Derived), result; if (_isNativeReflectConstruct$A()) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
1283 function _isNativeReflectConstruct$A() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
1284 var GetStorageAtMethod = function (_AbstractMethod) {
1285 _inherits(GetStorageAtMethod, _AbstractMethod);
1286 var _super = _createSuper$A(GetStorageAtMethod);
1287 function GetStorageAtMethod(utils, formatters, moduleInstance) {
1288 _classCallCheck(this, GetStorageAtMethod);
1289 return _super.call(this, 'eth_getStorageAt', 3, utils, formatters, moduleInstance);
1290 }
1291 _createClass(GetStorageAtMethod, [{
1292 key: "beforeExecution",
1293 value: function beforeExecution(moduleInstance) {
1294 this.parameters[0] = this.formatters.inputAddressFormatter(this.parameters[0]);
1295 this.parameters[1] = this.utils.numberToHex(this.parameters[1]);
1296 if (isFunction(this.parameters[2])) {
1297 this.callback = this.parameters[2];
1298 this.parameters[2] = moduleInstance.defaultEpoch;
1299 }
1300 this.parameters[2] = this.formatters.inputDefaultEpochNumberFormatter(this.parameters[2], moduleInstance);
1301 }
1302 }]);
1303 return GetStorageAtMethod;
1304 }(AbstractMethod);
1305
1306 function _createSuper$B(Derived) { return function () { var Super = _getPrototypeOf(Derived), result; if (_isNativeReflectConstruct$B()) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
1307 function _isNativeReflectConstruct$B() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
1308 var EstimateGasMethod = function (_AbstractMethod) {
1309 _inherits(EstimateGasMethod, _AbstractMethod);
1310 var _super = _createSuper$B(EstimateGasMethod);
1311 function EstimateGasMethod(utils, formatters, moduleInstance) {
1312 _classCallCheck(this, EstimateGasMethod);
1313 return _super.call(this, 'cfx_estimateGas', 1, utils, formatters, moduleInstance);
1314 }
1315 _createClass(EstimateGasMethod, [{
1316 key: "beforeExecution",
1317 value: function beforeExecution(moduleInstance) {
1318 this.parameters[0] = this.formatters.inputCallFormatter(this.parameters[0], moduleInstance);
1319 }
1320 }, {
1321 key: "afterExecution",
1322 value: function afterExecution(response) {
1323 return this.utils.hexToNumber(response);
1324 }
1325 }]);
1326 return EstimateGasMethod;
1327 }(AbstractMethod);
1328
1329 function _createSuper$C(Derived) { return function () { var Super = _getPrototypeOf(Derived), result; if (_isNativeReflectConstruct$C()) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
1330 function _isNativeReflectConstruct$C() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
1331 var GetPastLogsMethod = function (_AbstractMethod) {
1332 _inherits(GetPastLogsMethod, _AbstractMethod);
1333 var _super = _createSuper$C(GetPastLogsMethod);
1334 function GetPastLogsMethod(utils, formatters, moduleInstance) {
1335 _classCallCheck(this, GetPastLogsMethod);
1336 return _super.call(this, 'cfx_getLogs', 1, utils, formatters, moduleInstance);
1337 }
1338 _createClass(GetPastLogsMethod, [{
1339 key: "beforeExecution",
1340 value: function beforeExecution(moduleInstance) {
1341 this.parameters[0] = this.formatters.inputLogFormatter(this.parameters[0]);
1342 }
1343 }, {
1344 key: "afterExecution",
1345 value: function afterExecution(response) {
1346 var _this = this;
1347 return response.map(function (responseItem) {
1348 return _this.formatters.outputLogFormatter(responseItem);
1349 });
1350 }
1351 }]);
1352 return GetPastLogsMethod;
1353 }(AbstractMethod);
1354
1355 function _createSuper$D(Derived) { return function () { var Super = _getPrototypeOf(Derived), result; if (_isNativeReflectConstruct$D()) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
1356 function _isNativeReflectConstruct$D() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
1357 var GetEpochNumberMethod = function (_AbstractMethod) {
1358 _inherits(GetEpochNumberMethod, _AbstractMethod);
1359 var _super = _createSuper$D(GetEpochNumberMethod);
1360 function GetEpochNumberMethod(utils, formatters, moduleInstance) {
1361 _classCallCheck(this, GetEpochNumberMethod);
1362 return _super.call(this, 'cfx_epochNumber', 1, utils, formatters, moduleInstance);
1363 }
1364 _createClass(GetEpochNumberMethod, [{
1365 key: "beforeExecution",
1366 value: function beforeExecution(moduleInstance) {
1367 if (this.parameters[0] === undefined) {
1368 this.parameters[0] = 'latest_mined';
1369 }
1370 if (!this.formatters.isPredefinedEpochNumber(this.parameters[0])) {
1371 throw new Error('The epoch field must be predefined epoch number.');
1372 }
1373 }
1374 }, {
1375 key: "afterExecution",
1376 value: function afterExecution(response) {
1377 return this.utils.hexToNumber(response);
1378 }
1379 }]);
1380 return GetEpochNumberMethod;
1381 }(AbstractMethod);
1382
1383 exports.AbstractGetBlockMethod = AbstractGetBlockMethod;
1384 exports.AbstractGetBlockTransactionCountMethod = AbstractGetBlockTransactionCountMethod;
1385 exports.AbstractGetTransactionFromBlockMethod = AbstractGetTransactionFromBlockMethod;
1386 exports.AbstractMethod = AbstractMethod;
1387 exports.AbstractMethodFactory = AbstractMethodFactory;
1388 exports.AbstractObservedTransactionMethod = AbstractObservedTransactionMethod;
1389 exports.CallMethod = CallMethod;
1390 exports.CfxSendTransactionMethod = CfxSendTransactionMethod;
1391 exports.ChainIdMethod = ChainIdMethod;
1392 exports.EstimateGasMethod = EstimateGasMethod;
1393 exports.GetAccountsMethod = GetAccountsMethod;
1394 exports.GetBalanceMethod = GetBalanceMethod;
1395 exports.GetBlockByHashMethod = GetBlockByHashMethod;
1396 exports.GetBlockByNumberMethod = GetBlockByNumberMethod;
1397 exports.GetBlockTransactionCountByHashMethod = GetBlockTransactionCountByHashMethod;
1398 exports.GetBlockTransactionCountByNumberMethod = GetBlockTransactionCountByNumberMethod;
1399 exports.GetCodeMethod = GetCodeMethod;
1400 exports.GetCoinbaseMethod = GetCoinbaseMethod;
1401 exports.GetEpochNumberMethod = GetEpochNumberMethod;
1402 exports.GetGasPriceMethod = GetGasPriceMethod;
1403 exports.GetHashrateMethod = GetHashrateMethod;
1404 exports.GetNodeInfoMethod = GetNodeInfoMethod;
1405 exports.GetPastLogsMethod = GetPastLogsMethod;
1406 exports.GetProtocolVersionMethod = GetProtocolVersionMethod;
1407 exports.GetStorageAtMethod = GetStorageAtMethod;
1408 exports.GetTransactionByBlockAddressAndIndexMethod = GetTransactionByBlockAddressAndIndexMethod;
1409 exports.GetTransactionByBlockHashAndIndexMethod = GetTransactionByBlockHashAndIndexMethod;
1410 exports.GetTransactionCountMethod = GetTransactionCountMethod;
1411 exports.GetTransactionMethod = GetTransactionMethod;
1412 exports.GetTransactionReceiptMethod = GetTransactionReceiptMethod;
1413 exports.GetWorkMethod = GetWorkMethod;
1414 exports.IsMiningMethod = IsMiningMethod;
1415 exports.IsSyncingMethod = IsSyncingMethod;
1416 exports.ListeningMethod = ListeningMethod;
1417 exports.MethodProxy = MethodProxy;
1418 exports.PeerCountMethod = PeerCountMethod;
1419 exports.PromiEvent = PromiEvent;
1420 exports.RequestAccountsMethod = RequestAccountsMethod;
1421 exports.SendRawTransactionMethod = SendRawTransactionMethod;
1422 exports.SendTransactionMethod = SendTransactionMethod;
1423 exports.SignMethod = SignMethod;
1424 exports.SignTransactionMethod = SignTransactionMethod;
1425 exports.SubmitWorkMethod = SubmitWorkMethod;
1426 exports.TransactionObserver = TransactionObserver;
1427 exports.VersionMethod = VersionMethod;
1428
1429 Object.defineProperty(exports, '__esModule', { value: true });
1430
1431})));