UNPKG

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