essential-eth 0.8.0 → 0.9.1-next.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/classes/Contract.js +38 -34
- package/dist/cjs/classes/test/Contract/crv.test.js +146 -339
- package/dist/cjs/classes/test/Contract/ens-abi.d.ts +1 -1
- package/dist/cjs/classes/test/Contract/ens.test.js +9 -66
- package/dist/cjs/classes/test/Contract/fei.test.js +11 -11
- package/dist/cjs/classes/test/Contract/foo-abi.d.ts +1 -1
- package/dist/cjs/classes/test/Contract/uni.test.js +66 -164
- package/dist/cjs/classes/utils/clean-block.js +4 -4
- package/dist/cjs/classes/utils/clean-log.js +4 -4
- package/dist/cjs/classes/utils/clean-transaction-receipt.js +4 -4
- package/dist/cjs/classes/utils/clean-transaction.js +4 -4
- package/dist/cjs/classes/utils/encode-decode-transaction.js +10 -10
- package/dist/cjs/classes/utils/fetchers.d.ts +8 -2
- package/dist/cjs/classes/utils/fetchers.js +20 -12
- package/dist/cjs/classes/utils/prepare-transaction.js +4 -4
- package/dist/cjs/index.d.ts +21 -21
- package/dist/cjs/index.js +21 -21
- package/dist/cjs/index.umd.js +1 -1
- package/dist/cjs/index.umd.js.map +1 -1
- package/dist/cjs/logger/logger.js +79 -41
- package/dist/cjs/logger/package-version.d.ts +1 -1
- package/dist/cjs/logger/package-version.js +1 -1
- package/dist/cjs/providers/AlchemyProvider.d.ts +4 -0
- package/dist/cjs/providers/AlchemyProvider.js +84 -0
- package/dist/cjs/providers/BaseProvider.js +471 -404
- package/dist/cjs/providers/FallthroughProvider.js +74 -38
- package/dist/cjs/providers/JsonRpcProvider.js +52 -31
- package/dist/cjs/providers/test/fallthrough-provider/get-gas-price.test.js +9 -9
- package/dist/cjs/providers/test/get-transaction-count.test.js +54 -91
- package/dist/cjs/providers/test/json-rpc-provider/call.test.js +87 -148
- package/dist/cjs/providers/test/json-rpc-provider/estimate-gas.test.js +45 -116
- package/dist/cjs/providers/test/json-rpc-provider/get-balance.test.js +36 -74
- package/dist/cjs/providers/test/json-rpc-provider/get-block-number.test.js +27 -94
- package/dist/cjs/providers/test/json-rpc-provider/get-block.test.js +191 -278
- package/dist/cjs/providers/test/json-rpc-provider/get-code.test.js +106 -135
- package/dist/cjs/providers/test/json-rpc-provider/get-fee-data.test.js +48 -73
- package/dist/cjs/providers/test/json-rpc-provider/get-gas-price.test.js +29 -64
- package/dist/cjs/providers/test/json-rpc-provider/get-logs/get-logs.test.js +219 -0
- package/dist/cjs/providers/test/json-rpc-provider/get-logs/mocks.d.ts +14 -0
- package/dist/cjs/providers/test/json-rpc-provider/get-logs/mocks.js +149 -0
- package/dist/cjs/providers/test/json-rpc-provider/get-network.test.js +37 -79
- package/dist/cjs/providers/test/json-rpc-provider/get-transaction-receipt.test.js +136 -157
- package/dist/cjs/providers/test/json-rpc-provider/get-transaction.test.js +121 -162
- package/dist/cjs/providers/test/mock-of.d.ts +2 -0
- package/dist/cjs/providers/test/mock-of.js +9 -0
- package/dist/cjs/providers/test/rpc-urls.d.ts +1 -0
- package/dist/cjs/providers/test/rpc-urls.js +12 -6
- package/dist/cjs/providers/test/test-alchemy-provider.test.js +151 -0
- package/dist/cjs/providers/utils/chains-info.d.ts +5 -448
- package/dist/cjs/providers/utils/chains-info.js +13 -1344
- package/dist/cjs/shared/tiny-big/helpers.js +18 -18
- package/dist/cjs/shared/tiny-big/tiny-big.js +96 -56
- package/dist/cjs/shared/tiny-big/tiny-big.test.js +2 -2
- package/dist/cjs/shared/validate-type.d.ts +1 -1
- package/dist/cjs/shared/validate-type.js +4 -4
- package/dist/cjs/types/Block.types.d.ts +3 -3
- package/dist/cjs/types/Contract.types.d.ts +4 -4
- package/dist/cjs/types/Transaction.types.d.ts +5 -5
- package/dist/cjs/utils/bytes.d.ts +4 -4
- package/dist/cjs/utils/bytes.js +3 -3
- package/dist/cjs/utils/tests/bytes/arrayify.test.js +48 -24
- package/dist/cjs/utils/tests/bytes/concat.test.js +5 -3
- package/dist/cjs/utils/tests/bytes/hex-concat.test.js +15 -13
- package/dist/cjs/utils/tests/bytes/hex-data-length.test.js +49 -32
- package/dist/cjs/utils/tests/bytes/hex-data-slice.test.js +15 -16
- package/dist/cjs/utils/tests/bytes/hex-strip-zeros.test.js +57 -40
- package/dist/cjs/utils/tests/bytes/hex-value.test.js +118 -62
- package/dist/cjs/utils/tests/bytes/hex-zero-pad.test.js +71 -33
- package/dist/cjs/utils/tests/bytes/hexlify.test.js +45 -29
- package/dist/cjs/utils/tests/bytes/is-bytes-like.test.js +10 -11
- package/dist/cjs/utils/tests/bytes/is-bytes.test.js +70 -27
- package/dist/cjs/utils/tests/bytes/is-hex-string.test.js +37 -28
- package/dist/cjs/utils/tests/bytes/strip-zeros.test.js +94 -45
- package/dist/cjs/utils/tests/bytes/zero-pad.test.js +98 -34
- package/dist/cjs/utils/tests/compute-address.test.js +42 -20
- package/dist/cjs/utils/tests/compute-public-key.test.js +20 -9
- package/dist/cjs/utils/tests/ether-to-wei.test.js +5 -13
- package/dist/cjs/utils/tests/hash-message.test.js +26 -15
- package/dist/cjs/utils/tests/is-address.test.js +2 -9
- package/dist/cjs/utils/tests/keccak256.test.js +36 -12
- package/dist/cjs/utils/tests/solidity-keccak256.test.js +43 -42
- package/dist/cjs/utils/tests/split-signature.test.js +29 -8
- package/dist/cjs/utils/tests/to-checksum-address.test.js +1 -4
- package/dist/cjs/utils/tests/to-utf8-bytes.test.js +28 -8
- package/dist/cjs/utils/tests/wei-to-ether.test.js +10 -20
- package/dist/esm/classes/test/Contract/ens-abi.d.ts +1 -1
- package/dist/esm/classes/test/Contract/foo-abi.d.ts +1 -1
- package/dist/esm/classes/utils/fetchers.d.ts +8 -2
- package/dist/esm/classes/utils/fetchers.js +6 -3
- package/dist/esm/index.d.ts +21 -21
- package/dist/esm/index.js +16 -16
- package/dist/esm/logger/package-version.d.ts +1 -1
- package/dist/esm/logger/package-version.js +1 -1
- package/dist/esm/providers/AlchemyProvider.d.ts +4 -0
- package/dist/esm/providers/AlchemyProvider.js +7 -0
- package/dist/esm/providers/FallthroughProvider.js +15 -7
- package/dist/esm/providers/test/json-rpc-provider/get-logs/mocks.d.ts +14 -0
- package/dist/esm/providers/test/json-rpc-provider/get-logs/mocks.js +142 -0
- package/dist/esm/providers/test/mock-of.d.ts +2 -0
- package/dist/esm/providers/test/mock-of.js +1 -0
- package/dist/esm/providers/test/rpc-urls.d.ts +1 -0
- package/dist/esm/providers/test/rpc-urls.js +14 -6
- package/dist/esm/providers/utils/chains-info.d.ts +5 -448
- package/dist/esm/providers/utils/chains-info.js +13 -1344
- package/dist/esm/shared/validate-type.d.ts +1 -1
- package/dist/esm/types/Block.types.d.ts +3 -3
- package/dist/esm/types/Contract.types.d.ts +4 -4
- package/dist/esm/types/Transaction.types.d.ts +5 -5
- package/dist/esm/utils/bytes.d.ts +4 -4
- package/package.json +23 -51
- package/readme.md +16 -38
- package/dist/cjs/providers/test/json-rpc-provider/get-logs.test.js +0 -361
|
@@ -1,19 +1,46 @@
|
|
|
1
|
-
function
|
|
1
|
+
function _assert_this_initialized(self) {
|
|
2
2
|
if (self === void 0) {
|
|
3
3
|
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
|
|
4
4
|
}
|
|
5
5
|
return self;
|
|
6
6
|
}
|
|
7
|
-
function
|
|
7
|
+
function _class_call_check(instance, Constructor) {
|
|
8
8
|
if (!(instance instanceof Constructor)) {
|
|
9
9
|
throw new TypeError("Cannot call a class as a function");
|
|
10
10
|
}
|
|
11
11
|
}
|
|
12
|
-
function
|
|
13
|
-
|
|
12
|
+
function _defineProperties(target, props) {
|
|
13
|
+
for(var i = 0; i < props.length; i++){
|
|
14
|
+
var descriptor = props[i];
|
|
15
|
+
descriptor.enumerable = descriptor.enumerable || false;
|
|
16
|
+
descriptor.configurable = true;
|
|
17
|
+
if ("value" in descriptor) descriptor.writable = true;
|
|
18
|
+
Object.defineProperty(target, descriptor.key, descriptor);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
function _create_class(Constructor, protoProps, staticProps) {
|
|
22
|
+
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
|
23
|
+
if (staticProps) _defineProperties(Constructor, staticProps);
|
|
24
|
+
return Constructor;
|
|
25
|
+
}
|
|
26
|
+
function _define_property(obj, key, value) {
|
|
27
|
+
if (key in obj) {
|
|
28
|
+
Object.defineProperty(obj, key, {
|
|
29
|
+
value: value,
|
|
30
|
+
enumerable: true,
|
|
31
|
+
configurable: true,
|
|
32
|
+
writable: true
|
|
33
|
+
});
|
|
34
|
+
} else {
|
|
35
|
+
obj[key] = value;
|
|
36
|
+
}
|
|
37
|
+
return obj;
|
|
38
|
+
}
|
|
39
|
+
function _get_prototype_of(o) {
|
|
40
|
+
_get_prototype_of = Object.setPrototypeOf ? Object.getPrototypeOf : function getPrototypeOf(o) {
|
|
14
41
|
return o.__proto__ || Object.getPrototypeOf(o);
|
|
15
42
|
};
|
|
16
|
-
return
|
|
43
|
+
return _get_prototype_of(o);
|
|
17
44
|
}
|
|
18
45
|
function _inherits(subClass, superClass) {
|
|
19
46
|
if (typeof superClass !== "function" && superClass !== null) {
|
|
@@ -26,26 +53,26 @@ function _inherits(subClass, superClass) {
|
|
|
26
53
|
configurable: true
|
|
27
54
|
}
|
|
28
55
|
});
|
|
29
|
-
if (superClass)
|
|
56
|
+
if (superClass) _set_prototype_of(subClass, superClass);
|
|
30
57
|
}
|
|
31
|
-
function
|
|
32
|
-
if (call && (
|
|
58
|
+
function _possible_constructor_return(self, call) {
|
|
59
|
+
if (call && (_type_of(call) === "object" || typeof call === "function")) {
|
|
33
60
|
return call;
|
|
34
61
|
}
|
|
35
|
-
return
|
|
62
|
+
return _assert_this_initialized(self);
|
|
36
63
|
}
|
|
37
|
-
function
|
|
38
|
-
|
|
64
|
+
function _set_prototype_of(o, p) {
|
|
65
|
+
_set_prototype_of = Object.setPrototypeOf || function setPrototypeOf(o, p) {
|
|
39
66
|
o.__proto__ = p;
|
|
40
67
|
return o;
|
|
41
68
|
};
|
|
42
|
-
return
|
|
69
|
+
return _set_prototype_of(o, p);
|
|
43
70
|
}
|
|
44
|
-
|
|
71
|
+
function _type_of(obj) {
|
|
45
72
|
"@swc/helpers - typeof";
|
|
46
73
|
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
|
47
|
-
}
|
|
48
|
-
function
|
|
74
|
+
}
|
|
75
|
+
function _is_native_reflect_construct() {
|
|
49
76
|
if (typeof Reflect === "undefined" || !Reflect.construct) return false;
|
|
50
77
|
if (Reflect.construct.sham) return false;
|
|
51
78
|
if (typeof Proxy === "function") return true;
|
|
@@ -56,31 +83,35 @@ function _isNativeReflectConstruct() {
|
|
|
56
83
|
return false;
|
|
57
84
|
}
|
|
58
85
|
}
|
|
59
|
-
function
|
|
60
|
-
var hasNativeReflectConstruct =
|
|
86
|
+
function _create_super(Derived) {
|
|
87
|
+
var hasNativeReflectConstruct = _is_native_reflect_construct();
|
|
61
88
|
return function _createSuperInternal() {
|
|
62
|
-
var Super =
|
|
89
|
+
var Super = _get_prototype_of(Derived), result;
|
|
63
90
|
if (hasNativeReflectConstruct) {
|
|
64
|
-
var NewTarget =
|
|
91
|
+
var NewTarget = _get_prototype_of(this).constructor;
|
|
65
92
|
result = Reflect.construct(Super, arguments, NewTarget);
|
|
66
93
|
} else {
|
|
67
94
|
result = Super.apply(this, arguments);
|
|
68
95
|
}
|
|
69
|
-
return
|
|
96
|
+
return _possible_constructor_return(this, result);
|
|
70
97
|
};
|
|
71
98
|
}
|
|
72
99
|
import { logger } from "../logger/logger";
|
|
73
100
|
import { BaseProvider } from "./BaseProvider";
|
|
74
101
|
// https://advancedweb.hu/how-to-add-timeout-to-a-promise-in-javascript/
|
|
75
102
|
var promiseTimeout = function(prom, time) {
|
|
76
|
-
return Promise
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
103
|
+
return new Promise(function(resolve, reject) {
|
|
104
|
+
var timeout = setTimeout(function() {
|
|
105
|
+
return reject(new Error("Promise timed out"));
|
|
106
|
+
}, time);
|
|
107
|
+
prom.then(function(result) {
|
|
108
|
+
clearTimeout(timeout);
|
|
109
|
+
resolve(result);
|
|
110
|
+
}).catch(function(error) {
|
|
111
|
+
clearTimeout(timeout);
|
|
112
|
+
reject(error);
|
|
113
|
+
});
|
|
114
|
+
});
|
|
84
115
|
};
|
|
85
116
|
var DEFAULT_TIMEOUT_DURATION = 8000;
|
|
86
117
|
/**
|
|
@@ -89,10 +120,10 @@ var DEFAULT_TIMEOUT_DURATION = 8000;
|
|
|
89
120
|
*/ export var FallthroughProvider = /*#__PURE__*/ function(BaseProvider) {
|
|
90
121
|
"use strict";
|
|
91
122
|
_inherits(FallthroughProvider, BaseProvider);
|
|
92
|
-
var _super =
|
|
123
|
+
var _super = _create_super(FallthroughProvider);
|
|
93
124
|
function FallthroughProvider(rpcUrls) {
|
|
94
125
|
var options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
|
95
|
-
|
|
126
|
+
_class_call_check(this, FallthroughProvider);
|
|
96
127
|
var _this;
|
|
97
128
|
if (!Array.isArray(rpcUrls)) {
|
|
98
129
|
logger.throwError("Array required", {
|
|
@@ -108,10 +139,11 @@ var DEFAULT_TIMEOUT_DURATION = 8000;
|
|
|
108
139
|
// index of current trusted rpc url
|
|
109
140
|
/**
|
|
110
141
|
* @ignore
|
|
111
|
-
*/ _this
|
|
142
|
+
*/ _define_property(_assert_this_initialized(_this), "rpcUrlCounter", 0);
|
|
143
|
+
_define_property(_assert_this_initialized(_this), "timeoutDuration", void 0);
|
|
112
144
|
/**
|
|
113
145
|
* @ignore
|
|
114
|
-
*/ _this
|
|
146
|
+
*/ _define_property(_assert_this_initialized(_this), "post", function(body) {
|
|
115
147
|
// while failing post, add to rpcUrlCounter and post again
|
|
116
148
|
var genesisCount = _this.rpcUrlCounter;
|
|
117
149
|
var recursivePostRetry = function() {
|
|
@@ -132,15 +164,19 @@ var DEFAULT_TIMEOUT_DURATION = 8000;
|
|
|
132
164
|
return res;
|
|
133
165
|
};
|
|
134
166
|
return recursivePostRetry();
|
|
135
|
-
};
|
|
167
|
+
});
|
|
136
168
|
_this.timeoutDuration = options.timeoutDuration || DEFAULT_TIMEOUT_DURATION;
|
|
137
169
|
return _this;
|
|
138
170
|
}
|
|
139
|
-
|
|
140
|
-
|
|
171
|
+
_create_class(FallthroughProvider, [
|
|
172
|
+
{
|
|
173
|
+
key: "selectRpcUrl",
|
|
174
|
+
value: /**
|
|
141
175
|
* @ignore
|
|
142
|
-
*/
|
|
143
|
-
|
|
144
|
-
|
|
176
|
+
*/ function selectRpcUrl() {
|
|
177
|
+
return this._rpcUrls[this.rpcUrlCounter];
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
]);
|
|
145
181
|
return FallthroughProvider;
|
|
146
182
|
}(BaseProvider);
|
|
@@ -1,19 +1,33 @@
|
|
|
1
|
-
function
|
|
1
|
+
function _assert_this_initialized(self) {
|
|
2
2
|
if (self === void 0) {
|
|
3
3
|
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
|
|
4
4
|
}
|
|
5
5
|
return self;
|
|
6
6
|
}
|
|
7
|
-
function
|
|
7
|
+
function _class_call_check(instance, Constructor) {
|
|
8
8
|
if (!(instance instanceof Constructor)) {
|
|
9
9
|
throw new TypeError("Cannot call a class as a function");
|
|
10
10
|
}
|
|
11
11
|
}
|
|
12
|
-
function
|
|
13
|
-
|
|
12
|
+
function _defineProperties(target, props) {
|
|
13
|
+
for(var i = 0; i < props.length; i++){
|
|
14
|
+
var descriptor = props[i];
|
|
15
|
+
descriptor.enumerable = descriptor.enumerable || false;
|
|
16
|
+
descriptor.configurable = true;
|
|
17
|
+
if ("value" in descriptor) descriptor.writable = true;
|
|
18
|
+
Object.defineProperty(target, descriptor.key, descriptor);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
function _create_class(Constructor, protoProps, staticProps) {
|
|
22
|
+
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
|
23
|
+
if (staticProps) _defineProperties(Constructor, staticProps);
|
|
24
|
+
return Constructor;
|
|
25
|
+
}
|
|
26
|
+
function _get_prototype_of(o) {
|
|
27
|
+
_get_prototype_of = Object.setPrototypeOf ? Object.getPrototypeOf : function getPrototypeOf(o) {
|
|
14
28
|
return o.__proto__ || Object.getPrototypeOf(o);
|
|
15
29
|
};
|
|
16
|
-
return
|
|
30
|
+
return _get_prototype_of(o);
|
|
17
31
|
}
|
|
18
32
|
function _inherits(subClass, superClass) {
|
|
19
33
|
if (typeof superClass !== "function" && superClass !== null) {
|
|
@@ -26,26 +40,26 @@ function _inherits(subClass, superClass) {
|
|
|
26
40
|
configurable: true
|
|
27
41
|
}
|
|
28
42
|
});
|
|
29
|
-
if (superClass)
|
|
43
|
+
if (superClass) _set_prototype_of(subClass, superClass);
|
|
30
44
|
}
|
|
31
|
-
function
|
|
32
|
-
if (call && (
|
|
45
|
+
function _possible_constructor_return(self, call) {
|
|
46
|
+
if (call && (_type_of(call) === "object" || typeof call === "function")) {
|
|
33
47
|
return call;
|
|
34
48
|
}
|
|
35
|
-
return
|
|
49
|
+
return _assert_this_initialized(self);
|
|
36
50
|
}
|
|
37
|
-
function
|
|
38
|
-
|
|
51
|
+
function _set_prototype_of(o, p) {
|
|
52
|
+
_set_prototype_of = Object.setPrototypeOf || function setPrototypeOf(o, p) {
|
|
39
53
|
o.__proto__ = p;
|
|
40
54
|
return o;
|
|
41
55
|
};
|
|
42
|
-
return
|
|
56
|
+
return _set_prototype_of(o, p);
|
|
43
57
|
}
|
|
44
|
-
|
|
58
|
+
function _type_of(obj) {
|
|
45
59
|
"@swc/helpers - typeof";
|
|
46
60
|
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
|
47
|
-
}
|
|
48
|
-
function
|
|
61
|
+
}
|
|
62
|
+
function _is_native_reflect_construct() {
|
|
49
63
|
if (typeof Reflect === "undefined" || !Reflect.construct) return false;
|
|
50
64
|
if (Reflect.construct.sham) return false;
|
|
51
65
|
if (typeof Proxy === "function") return true;
|
|
@@ -56,42 +70,49 @@ function _isNativeReflectConstruct() {
|
|
|
56
70
|
return false;
|
|
57
71
|
}
|
|
58
72
|
}
|
|
59
|
-
function
|
|
60
|
-
var hasNativeReflectConstruct =
|
|
73
|
+
function _create_super(Derived) {
|
|
74
|
+
var hasNativeReflectConstruct = _is_native_reflect_construct();
|
|
61
75
|
return function _createSuperInternal() {
|
|
62
|
-
var Super =
|
|
76
|
+
var Super = _get_prototype_of(Derived), result;
|
|
63
77
|
if (hasNativeReflectConstruct) {
|
|
64
|
-
var NewTarget =
|
|
78
|
+
var NewTarget = _get_prototype_of(this).constructor;
|
|
65
79
|
result = Reflect.construct(Super, arguments, NewTarget);
|
|
66
80
|
} else {
|
|
67
81
|
result = Super.apply(this, arguments);
|
|
68
82
|
}
|
|
69
|
-
return
|
|
83
|
+
return _possible_constructor_return(this, result);
|
|
70
84
|
};
|
|
71
85
|
}
|
|
72
86
|
import { BaseProvider } from "./BaseProvider";
|
|
73
87
|
export var JsonRpcProvider = /*#__PURE__*/ function(BaseProvider) {
|
|
74
88
|
"use strict";
|
|
75
89
|
_inherits(JsonRpcProvider, BaseProvider);
|
|
76
|
-
var _super =
|
|
90
|
+
var _super = _create_super(JsonRpcProvider);
|
|
77
91
|
function JsonRpcProvider() {
|
|
78
92
|
var rpcUrl = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : "https://free-eth-node.com/api/eth";
|
|
79
|
-
|
|
93
|
+
_class_call_check(this, JsonRpcProvider);
|
|
80
94
|
return _super.call(this, [
|
|
81
95
|
rpcUrl
|
|
82
96
|
]);
|
|
83
97
|
}
|
|
84
|
-
|
|
85
|
-
|
|
98
|
+
_create_class(JsonRpcProvider, [
|
|
99
|
+
{
|
|
100
|
+
/**
|
|
86
101
|
* @ignore
|
|
87
|
-
*/
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
102
|
+
*/ key: "selectRpcUrl",
|
|
103
|
+
value: function selectRpcUrl() {
|
|
104
|
+
return this._rpcUrls[0];
|
|
105
|
+
}
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
/**
|
|
91
109
|
* @ignore
|
|
92
|
-
*/
|
|
93
|
-
|
|
94
|
-
|
|
110
|
+
*/ key: "post",
|
|
111
|
+
value: function post(body) {
|
|
112
|
+
return this._post(body);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
]);
|
|
95
116
|
return JsonRpcProvider;
|
|
96
117
|
}(BaseProvider);
|
|
97
118
|
/**
|
|
@@ -13,7 +13,7 @@ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
|
13
13
|
Promise.resolve(value).then(_next, _throw);
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
|
-
function
|
|
16
|
+
function _async_to_generator(fn) {
|
|
17
17
|
return function() {
|
|
18
18
|
var self = this, args = arguments;
|
|
19
19
|
return new Promise(function(resolve, reject) {
|
|
@@ -28,7 +28,7 @@ function _asyncToGenerator(fn) {
|
|
|
28
28
|
});
|
|
29
29
|
};
|
|
30
30
|
}
|
|
31
|
-
|
|
31
|
+
function _ts_generator(thisArg, body) {
|
|
32
32
|
var f, y, t, g, _ = {
|
|
33
33
|
label: 0,
|
|
34
34
|
sent: function() {
|
|
@@ -122,7 +122,7 @@ var __generator = this && this.__generator || function(thisArg, body) {
|
|
|
122
122
|
done: true
|
|
123
123
|
};
|
|
124
124
|
}
|
|
125
|
-
}
|
|
125
|
+
}
|
|
126
126
|
import { performance } from "perf_hooks";
|
|
127
127
|
import { FallthroughProvider } from "../../../index";
|
|
128
128
|
import { rpcUrls } from "../rpc-urls";
|
|
@@ -135,9 +135,9 @@ function timePromise(fn) {
|
|
|
135
135
|
return fn().then(onPromiseDone, onPromiseDone);
|
|
136
136
|
}
|
|
137
137
|
describe("provider.getGasPrice", function() {
|
|
138
|
-
it("should fallthrough on several types of invalid urls", /*#__PURE__*/
|
|
138
|
+
it("should fallthrough on several types of invalid urls", /*#__PURE__*/ _async_to_generator(function() {
|
|
139
139
|
var essentialEthProvider, block;
|
|
140
|
-
return
|
|
140
|
+
return _ts_generator(this, function(_state) {
|
|
141
141
|
switch(_state.label){
|
|
142
142
|
case 0:
|
|
143
143
|
essentialEthProvider = new FallthroughProvider([
|
|
@@ -158,9 +158,9 @@ describe("provider.getGasPrice", function() {
|
|
|
158
158
|
}
|
|
159
159
|
});
|
|
160
160
|
}));
|
|
161
|
-
it("should fallthrough after timeout linearly", /*#__PURE__*/
|
|
161
|
+
it("should fallthrough after timeout linearly", /*#__PURE__*/ _async_to_generator(function() {
|
|
162
162
|
var essentialEthProvider;
|
|
163
|
-
return
|
|
163
|
+
return _ts_generator(this, function(_state) {
|
|
164
164
|
switch(_state.label){
|
|
165
165
|
case 0:
|
|
166
166
|
essentialEthProvider = new FallthroughProvider([
|
|
@@ -191,9 +191,9 @@ describe("provider.getGasPrice", function() {
|
|
|
191
191
|
}
|
|
192
192
|
});
|
|
193
193
|
}));
|
|
194
|
-
it("should mutex the current rpc selection properly", /*#__PURE__*/
|
|
194
|
+
it("should mutex the current rpc selection properly", /*#__PURE__*/ _async_to_generator(function() {
|
|
195
195
|
var providers, allBlocks;
|
|
196
|
-
return
|
|
196
|
+
return _ts_generator(this, function(_state) {
|
|
197
197
|
switch(_state.label){
|
|
198
198
|
case 0:
|
|
199
199
|
providers = [
|
|
@@ -1,11 +1,3 @@
|
|
|
1
|
-
function _arrayLikeToArray(arr, len) {
|
|
2
|
-
if (len == null || len > arr.length) len = arr.length;
|
|
3
|
-
for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
|
|
4
|
-
return arr2;
|
|
5
|
-
}
|
|
6
|
-
function _arrayWithHoles(arr) {
|
|
7
|
-
if (Array.isArray(arr)) return arr;
|
|
8
|
-
}
|
|
9
1
|
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
10
2
|
try {
|
|
11
3
|
var info = gen[key](arg);
|
|
@@ -20,7 +12,7 @@ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
|
20
12
|
Promise.resolve(value).then(_next, _throw);
|
|
21
13
|
}
|
|
22
14
|
}
|
|
23
|
-
function
|
|
15
|
+
function _async_to_generator(fn) {
|
|
24
16
|
return function() {
|
|
25
17
|
var self = this, args = arguments;
|
|
26
18
|
return new Promise(function(resolve, reject) {
|
|
@@ -35,45 +27,7 @@ function _asyncToGenerator(fn) {
|
|
|
35
27
|
});
|
|
36
28
|
};
|
|
37
29
|
}
|
|
38
|
-
function
|
|
39
|
-
var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
|
|
40
|
-
if (_i == null) return;
|
|
41
|
-
var _arr = [];
|
|
42
|
-
var _n = true;
|
|
43
|
-
var _d = false;
|
|
44
|
-
var _s, _e;
|
|
45
|
-
try {
|
|
46
|
-
for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
|
|
47
|
-
_arr.push(_s.value);
|
|
48
|
-
if (i && _arr.length === i) break;
|
|
49
|
-
}
|
|
50
|
-
} catch (err) {
|
|
51
|
-
_d = true;
|
|
52
|
-
_e = err;
|
|
53
|
-
} finally{
|
|
54
|
-
try {
|
|
55
|
-
if (!_n && _i["return"] != null) _i["return"]();
|
|
56
|
-
} finally{
|
|
57
|
-
if (_d) throw _e;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
return _arr;
|
|
61
|
-
}
|
|
62
|
-
function _nonIterableRest() {
|
|
63
|
-
throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
64
|
-
}
|
|
65
|
-
function _slicedToArray(arr, i) {
|
|
66
|
-
return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
|
|
67
|
-
}
|
|
68
|
-
function _unsupportedIterableToArray(o, minLen) {
|
|
69
|
-
if (!o) return;
|
|
70
|
-
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
|
|
71
|
-
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
72
|
-
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
73
|
-
if (n === "Map" || n === "Set") return Array.from(n);
|
|
74
|
-
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
|
|
75
|
-
}
|
|
76
|
-
var __generator = this && this.__generator || function(thisArg, body) {
|
|
30
|
+
function _ts_generator(thisArg, body) {
|
|
77
31
|
var f, y, t, g, _ = {
|
|
78
32
|
label: 0,
|
|
79
33
|
sent: function() {
|
|
@@ -167,48 +121,47 @@ var __generator = this && this.__generator || function(thisArg, body) {
|
|
|
167
121
|
done: true
|
|
168
122
|
};
|
|
169
123
|
}
|
|
170
|
-
}
|
|
171
|
-
import
|
|
172
|
-
import
|
|
173
|
-
import {
|
|
124
|
+
}
|
|
125
|
+
import * as unfetch from "isomorphic-unfetch";
|
|
126
|
+
import { jsonRpcProvider, tinyBig } from "../..";
|
|
127
|
+
import { buildFetchInit, buildRPCPostBody } from "../../classes/utils/fetchers";
|
|
128
|
+
import { mockOf } from "./mock-of";
|
|
174
129
|
import { rpcUrls } from "./rpc-urls";
|
|
175
|
-
|
|
130
|
+
jest.mock("isomorphic-unfetch");
|
|
176
131
|
var address = "0x71660c4005ba85c37ccec55d0c4493e66fe775d3";
|
|
177
132
|
function testGetTC(rpcUrl, blockTag) {
|
|
178
133
|
return _testGetTC.apply(this, arguments);
|
|
179
134
|
}
|
|
180
135
|
function _testGetTC() {
|
|
181
|
-
_testGetTC =
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
* @param blockTag
|
|
185
|
-
*/ _asyncToGenerator(function(rpcUrl, blockTag) {
|
|
186
|
-
var eeProvider, ethersProvider, web3Provider, _ref, eeTC, ethersTC, web3TC;
|
|
187
|
-
return __generator(this, function(_state) {
|
|
136
|
+
_testGetTC = _async_to_generator(function(rpcUrl, blockTag) {
|
|
137
|
+
var provider, mockPostResponse, spy, transactionCount, expectedBlockTag;
|
|
138
|
+
return _ts_generator(this, function(_state) {
|
|
188
139
|
switch(_state.label){
|
|
189
140
|
case 0:
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
141
|
+
provider = jsonRpcProvider(rpcUrl);
|
|
142
|
+
mockPostResponse = JSON.stringify({
|
|
143
|
+
jsonrpc: "2.0",
|
|
144
|
+
id: 1,
|
|
145
|
+
result: "0xa"
|
|
146
|
+
});
|
|
147
|
+
mockOf(unfetch.default).mockResolvedValueOnce({
|
|
148
|
+
text: function() {
|
|
149
|
+
return Promise.resolve(mockPostResponse);
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
spy = jest.spyOn(unfetch, "default");
|
|
193
153
|
return [
|
|
194
154
|
4,
|
|
195
|
-
|
|
196
|
-
eeProvider.getTransactionCount(address, blockTag),
|
|
197
|
-
ethersProvider.getTransactionCount(address, blockTag),
|
|
198
|
-
web3Provider.eth.getTransactionCount(address, blockTag)
|
|
199
|
-
])
|
|
155
|
+
provider.getTransactionCount(address, blockTag)
|
|
200
156
|
];
|
|
201
157
|
case 1:
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
}
|
|
210
|
-
expect(eeTC).toBe(ethersTC);
|
|
211
|
-
expect(eeTC).toBe(web3TC);
|
|
158
|
+
transactionCount = _state.sent();
|
|
159
|
+
expect(transactionCount.toString()).toBe("10");
|
|
160
|
+
expectedBlockTag = typeof blockTag === "number" ? tinyBig(blockTag).toHexString() : blockTag !== null && blockTag !== void 0 ? blockTag : "latest";
|
|
161
|
+
expect(spy).toHaveBeenCalledWith(rpcUrl, buildFetchInit(buildRPCPostBody("eth_getTransactionCount", [
|
|
162
|
+
address,
|
|
163
|
+
expectedBlockTag
|
|
164
|
+
])));
|
|
212
165
|
return [
|
|
213
166
|
2
|
|
214
167
|
];
|
|
@@ -217,10 +170,10 @@ function _testGetTC() {
|
|
|
217
170
|
});
|
|
218
171
|
return _testGetTC.apply(this, arguments);
|
|
219
172
|
}
|
|
220
|
-
describe("provider.
|
|
173
|
+
describe("provider.getTransactionCount matic", function() {
|
|
221
174
|
var rpcUrl = rpcUrls.matic;
|
|
222
|
-
it("should get latest
|
|
223
|
-
return
|
|
175
|
+
it("should get the latest by the latest block", /*#__PURE__*/ _async_to_generator(function() {
|
|
176
|
+
return _ts_generator(this, function(_state) {
|
|
224
177
|
switch(_state.label){
|
|
225
178
|
case 0:
|
|
226
179
|
return [
|
|
@@ -235,8 +188,8 @@ describe("provider.getBalance mainnet", function() {
|
|
|
235
188
|
}
|
|
236
189
|
});
|
|
237
190
|
}));
|
|
238
|
-
it("should get
|
|
239
|
-
return
|
|
191
|
+
it("should get transaction count by default latest block", /*#__PURE__*/ _async_to_generator(function() {
|
|
192
|
+
return _ts_generator(this, function(_state) {
|
|
240
193
|
switch(_state.label){
|
|
241
194
|
case 0:
|
|
242
195
|
return [
|
|
@@ -251,8 +204,8 @@ describe("provider.getBalance mainnet", function() {
|
|
|
251
204
|
}
|
|
252
205
|
});
|
|
253
206
|
}));
|
|
254
|
-
it("should get
|
|
255
|
-
return
|
|
207
|
+
it("should get transaction count by earliest block", /*#__PURE__*/ _async_to_generator(function() {
|
|
208
|
+
return _ts_generator(this, function(_state) {
|
|
256
209
|
switch(_state.label){
|
|
257
210
|
case 0:
|
|
258
211
|
return [
|
|
@@ -267,10 +220,20 @@ describe("provider.getBalance mainnet", function() {
|
|
|
267
220
|
}
|
|
268
221
|
});
|
|
269
222
|
}));
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
223
|
+
it("should get TC by block number", /*#__PURE__*/ _async_to_generator(function() {
|
|
224
|
+
return _ts_generator(this, function(_state) {
|
|
225
|
+
switch(_state.label){
|
|
226
|
+
case 0:
|
|
227
|
+
return [
|
|
228
|
+
4,
|
|
229
|
+
testGetTC(rpcUrl, 14649390)
|
|
230
|
+
];
|
|
231
|
+
case 1:
|
|
232
|
+
_state.sent();
|
|
233
|
+
return [
|
|
234
|
+
2
|
|
235
|
+
];
|
|
236
|
+
}
|
|
237
|
+
});
|
|
238
|
+
}));
|
|
276
239
|
});
|