UNPKG

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