@qevm/providers 1.0.1 → 1.0.2
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/lib/alchemy-provider.d.ts +1 -1
- package/lib/alchemy-provider.d.ts.map +1 -1
- package/lib/alchemy-provider.js +29 -53
- package/lib/alchemy-provider.js.map +1 -1
- package/lib/ankr-provider.d.ts +1 -1
- package/lib/ankr-provider.d.ts.map +1 -1
- package/lib/ankr-provider.js +16 -36
- package/lib/ankr-provider.js.map +1 -1
- package/lib/base-provider.d.ts +3 -4
- package/lib/base-provider.d.ts.map +1 -1
- package/lib/base-provider.js +1477 -2132
- package/lib/base-provider.js.map +1 -1
- package/lib/browser-ipc-provider.js +1 -1
- package/lib/browser-ipc-provider.js.map +1 -1
- package/lib/browser-net.js +1 -2
- package/lib/browser-net.js.map +1 -1
- package/lib/browser-ws.js +5 -5
- package/lib/browser-ws.js.map +1 -1
- package/lib/cloudflare-provider.js +20 -83
- package/lib/cloudflare-provider.js.map +1 -1
- package/lib/etherscan-provider.js +237 -357
- package/lib/etherscan-provider.js.map +1 -1
- package/lib/fallback-provider.js +301 -430
- package/lib/fallback-provider.js.map +1 -1
- package/lib/formatter.d.ts +4 -4
- package/lib/formatter.d.ts.map +1 -1
- package/lib/formatter.js +107 -110
- package/lib/formatter.js.map +1 -1
- package/lib/index.js +25 -25
- package/lib/index.js.map +1 -1
- package/lib/infura-provider.d.ts +1 -1
- package/lib/infura-provider.d.ts.map +1 -1
- package/lib/infura-provider.js +34 -58
- package/lib/infura-provider.js.map +1 -1
- package/lib/ipc-provider.js +20 -40
- package/lib/ipc-provider.js.map +1 -1
- package/lib/json-rpc-batch-provider.d.ts +0 -1
- package/lib/json-rpc-batch-provider.d.ts.map +1 -1
- package/lib/json-rpc-batch-provider.js +27 -48
- package/lib/json-rpc-batch-provider.js.map +1 -1
- package/lib/json-rpc-provider.d.ts +1 -1
- package/lib/json-rpc-provider.d.ts.map +1 -1
- package/lib/json-rpc-provider.js +283 -482
- package/lib/json-rpc-provider.js.map +1 -1
- package/lib/nodesmith-provider.js +12 -32
- package/lib/nodesmith-provider.js.map +1 -1
- package/lib/pocket-provider.d.ts +1 -1
- package/lib/pocket-provider.d.ts.map +1 -1
- package/lib/pocket-provider.js +17 -37
- package/lib/pocket-provider.js.map +1 -1
- package/lib/url-json-rpc-provider.d.ts +1 -1
- package/lib/url-json-rpc-provider.d.ts.map +1 -1
- package/lib/url-json-rpc-provider.js +45 -116
- package/lib/url-json-rpc-provider.js.map +1 -1
- package/lib/web3-provider.d.ts +2 -2
- package/lib/web3-provider.d.ts.map +1 -1
- package/lib/web3-provider.js +49 -70
- package/lib/web3-provider.js.map +1 -1
- package/lib/websocket-provider.d.ts +2 -2
- package/lib/websocket-provider.d.ts.map +1 -1
- package/lib/websocket-provider.js +128 -225
- package/lib/websocket-provider.js.map +1 -1
- package/lib/ws.js +1 -1
- package/lib/ws.js.map +1 -1
- package/package.json +17 -14
- package/src.ts/alchemy-provider.ts +1 -1
- package/src.ts/ankr-provider.ts +1 -1
- package/src.ts/base-provider.ts +9 -9
- package/src.ts/etherscan-provider.ts +1 -1
- package/src.ts/fallback-provider.ts +4 -4
- package/src.ts/formatter.ts +2 -2
- package/src.ts/infura-provider.ts +1 -1
- package/src.ts/json-rpc-batch-provider.ts +1 -1
- package/src.ts/json-rpc-provider.ts +3 -3
- package/src.ts/pocket-provider.ts +1 -1
- package/src.ts/url-json-rpc-provider.ts +1 -1
- package/src.ts/websocket-provider.ts +1 -1
package/lib/json-rpc-provider.js
CHANGED
|
@@ -1,85 +1,34 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __extends = (this && this.__extends) || (function () {
|
|
3
|
-
var extendStatics = function (d, b) {
|
|
4
|
-
extendStatics = Object.setPrototypeOf ||
|
|
5
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
-
return extendStatics(d, b);
|
|
8
|
-
};
|
|
9
|
-
return function (d, b) {
|
|
10
|
-
if (typeof b !== "function" && b !== null)
|
|
11
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
-
extendStatics(d, b);
|
|
13
|
-
function __() { this.constructor = d; }
|
|
14
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
-
};
|
|
16
|
-
})();
|
|
17
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
18
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
19
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
20
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
21
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
22
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
23
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
24
|
-
});
|
|
25
|
-
};
|
|
26
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
27
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
28
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
29
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
30
|
-
function step(op) {
|
|
31
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
32
|
-
while (_) try {
|
|
33
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
34
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
35
|
-
switch (op[0]) {
|
|
36
|
-
case 0: case 1: t = op; break;
|
|
37
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
38
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
39
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
40
|
-
default:
|
|
41
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
42
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
43
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
44
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
45
|
-
if (t[2]) _.ops.pop();
|
|
46
|
-
_.trys.pop(); continue;
|
|
47
|
-
}
|
|
48
|
-
op = body.call(thisArg, _);
|
|
49
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
50
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
51
|
-
}
|
|
52
|
-
};
|
|
53
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
54
3
|
exports.JsonRpcProvider = exports.JsonRpcSigner = void 0;
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
4
|
+
const abstract_signer_1 = require("@qevm/abstract-signer");
|
|
5
|
+
const bignumber_1 = require("@qevm/bignumber");
|
|
6
|
+
const bytes_1 = require("@qevm/bytes");
|
|
7
|
+
const hash_1 = require("@qevm/hash");
|
|
8
|
+
const properties_1 = require("@ethersproject/properties");
|
|
9
|
+
const strings_1 = require("@qevm/strings");
|
|
10
|
+
const transactions_1 = require("@qevm/transactions");
|
|
11
|
+
const web_1 = require("@qevm/web");
|
|
12
|
+
const logger_1 = require("@ethersproject/logger");
|
|
13
|
+
const _version_1 = require("./_version");
|
|
14
|
+
const logger = new logger_1.Logger(_version_1.version);
|
|
15
|
+
const base_provider_1 = require("./base-provider");
|
|
16
|
+
const errorGas = ["call", "estimateGas"];
|
|
68
17
|
function spelunk(value, requireData) {
|
|
69
18
|
if (value == null) {
|
|
70
19
|
return null;
|
|
71
20
|
}
|
|
72
21
|
// These *are* the droids we're looking for.
|
|
73
22
|
if (typeof (value.message) === "string" && value.message.match("reverted")) {
|
|
74
|
-
|
|
23
|
+
const data = (0, bytes_1.isHexString)(value.data) ? value.data : null;
|
|
75
24
|
if (!requireData || data) {
|
|
76
|
-
return { message: value.message, data
|
|
25
|
+
return { message: value.message, data };
|
|
77
26
|
}
|
|
78
27
|
}
|
|
79
28
|
// Spelunk further...
|
|
80
29
|
if (typeof (value) === "object") {
|
|
81
|
-
for (
|
|
82
|
-
|
|
30
|
+
for (const key in value) {
|
|
31
|
+
const result = spelunk(value[key], requireData);
|
|
83
32
|
if (result) {
|
|
84
33
|
return result;
|
|
85
34
|
}
|
|
@@ -96,39 +45,34 @@ function spelunk(value, requireData) {
|
|
|
96
45
|
return null;
|
|
97
46
|
}
|
|
98
47
|
function checkError(method, error, params) {
|
|
99
|
-
|
|
48
|
+
const transaction = params.transaction || params.signedTransaction;
|
|
100
49
|
// Undo the "convenience" some nodes are attempting to prevent backwards
|
|
101
50
|
// incompatibility; maybe for v6 consider forwarding reverts as errors
|
|
102
51
|
if (method === "call") {
|
|
103
|
-
|
|
52
|
+
const result = spelunk(error, true);
|
|
104
53
|
if (result) {
|
|
105
54
|
return result.data;
|
|
106
55
|
}
|
|
107
56
|
// Nothing descriptive..
|
|
108
57
|
logger.throwError("missing revert data in call exception; Transaction reverted without a reason string", logger_1.Logger.errors.CALL_EXCEPTION, {
|
|
109
|
-
data: "0x",
|
|
110
|
-
transaction: transaction,
|
|
111
|
-
error: error
|
|
58
|
+
data: "0x", transaction, error
|
|
112
59
|
});
|
|
113
60
|
}
|
|
114
61
|
if (method === "estimateGas") {
|
|
115
62
|
// Try to find something, with a preference on SERVER_ERROR body
|
|
116
|
-
|
|
63
|
+
let result = spelunk(error.body, false);
|
|
117
64
|
if (result == null) {
|
|
118
65
|
result = spelunk(error, false);
|
|
119
66
|
}
|
|
120
67
|
// Found "reverted", this is a CALL_EXCEPTION
|
|
121
68
|
if (result) {
|
|
122
69
|
logger.throwError("cannot estimate gas; transaction may fail or may require manual gas limit", logger_1.Logger.errors.UNPREDICTABLE_GAS_LIMIT, {
|
|
123
|
-
reason: result.message,
|
|
124
|
-
method: method,
|
|
125
|
-
transaction: transaction,
|
|
126
|
-
error: error
|
|
70
|
+
reason: result.message, method, transaction, error
|
|
127
71
|
});
|
|
128
72
|
}
|
|
129
73
|
}
|
|
130
74
|
// @TODO: Should we spelunk for message too?
|
|
131
|
-
|
|
75
|
+
let message = error.message;
|
|
132
76
|
if (error.code === logger_1.Logger.errors.SERVER_ERROR && error.error && typeof (error.error.message) === "string") {
|
|
133
77
|
message = error.error.message;
|
|
134
78
|
}
|
|
@@ -142,40 +86,30 @@ function checkError(method, error, params) {
|
|
|
142
86
|
// "insufficient funds for gas * price + value + cost(data)"
|
|
143
87
|
if (message.match(/insufficient funds|base fee exceeds gas limit|InsufficientFunds/i)) {
|
|
144
88
|
logger.throwError("insufficient funds for intrinsic transaction cost", logger_1.Logger.errors.INSUFFICIENT_FUNDS, {
|
|
145
|
-
error
|
|
146
|
-
method: method,
|
|
147
|
-
transaction: transaction
|
|
89
|
+
error, method, transaction
|
|
148
90
|
});
|
|
149
91
|
}
|
|
150
92
|
// "nonce too low"
|
|
151
93
|
if (message.match(/nonce (is )?too low/i)) {
|
|
152
94
|
logger.throwError("nonce has already been used", logger_1.Logger.errors.NONCE_EXPIRED, {
|
|
153
|
-
error
|
|
154
|
-
method: method,
|
|
155
|
-
transaction: transaction
|
|
95
|
+
error, method, transaction
|
|
156
96
|
});
|
|
157
97
|
}
|
|
158
98
|
// "replacement transaction underpriced"
|
|
159
99
|
if (message.match(/replacement transaction underpriced|transaction gas price.*too low/i)) {
|
|
160
100
|
logger.throwError("replacement fee too low", logger_1.Logger.errors.REPLACEMENT_UNDERPRICED, {
|
|
161
|
-
error
|
|
162
|
-
method: method,
|
|
163
|
-
transaction: transaction
|
|
101
|
+
error, method, transaction
|
|
164
102
|
});
|
|
165
103
|
}
|
|
166
104
|
// "replacement transaction underpriced"
|
|
167
105
|
if (message.match(/only replay-protected/i)) {
|
|
168
106
|
logger.throwError("legacy pre-eip-155 transactions not supported", logger_1.Logger.errors.UNSUPPORTED_OPERATION, {
|
|
169
|
-
error
|
|
170
|
-
method: method,
|
|
171
|
-
transaction: transaction
|
|
107
|
+
error, method, transaction
|
|
172
108
|
});
|
|
173
109
|
}
|
|
174
110
|
if (errorGas.indexOf(method) >= 0 && message.match(/gas required exceeds allowance|always failing transaction|execution reverted|revert/)) {
|
|
175
111
|
logger.throwError("cannot estimate gas; transaction may fail or may require manual gas limit", logger_1.Logger.errors.UNPREDICTABLE_GAS_LIMIT, {
|
|
176
|
-
error
|
|
177
|
-
method: method,
|
|
178
|
-
transaction: transaction
|
|
112
|
+
error, method, transaction
|
|
179
113
|
});
|
|
180
114
|
}
|
|
181
115
|
throw error;
|
|
@@ -188,7 +122,7 @@ function timer(timeout) {
|
|
|
188
122
|
function getResult(payload) {
|
|
189
123
|
if (payload.error) {
|
|
190
124
|
// @TODO: not any
|
|
191
|
-
|
|
125
|
+
const error = new Error(payload.error.message);
|
|
192
126
|
error.code = payload.error.code;
|
|
193
127
|
error.data = payload.error.data;
|
|
194
128
|
throw error;
|
|
@@ -201,57 +135,53 @@ function getLowerCase(value) {
|
|
|
201
135
|
}
|
|
202
136
|
return value;
|
|
203
137
|
}
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
var _this = _super.call(this) || this;
|
|
138
|
+
const _constructorGuard = {};
|
|
139
|
+
class JsonRpcSigner extends abstract_signer_1.Signer {
|
|
140
|
+
constructor(constructorGuard, provider, addressOrIndex) {
|
|
141
|
+
super();
|
|
209
142
|
if (constructorGuard !== _constructorGuard) {
|
|
210
143
|
throw new Error("do not call the JsonRpcSigner constructor directly; use provider.getSigner");
|
|
211
144
|
}
|
|
212
|
-
(0, properties_1.defineReadOnly)(
|
|
145
|
+
(0, properties_1.defineReadOnly)(this, "provider", provider);
|
|
213
146
|
if (addressOrIndex == null) {
|
|
214
147
|
addressOrIndex = 0;
|
|
215
148
|
}
|
|
216
149
|
if (typeof (addressOrIndex) === "string") {
|
|
217
|
-
(0, properties_1.defineReadOnly)(
|
|
218
|
-
(0, properties_1.defineReadOnly)(
|
|
150
|
+
(0, properties_1.defineReadOnly)(this, "_address", this.provider.formatter.address(addressOrIndex));
|
|
151
|
+
(0, properties_1.defineReadOnly)(this, "_index", null);
|
|
219
152
|
}
|
|
220
153
|
else if (typeof (addressOrIndex) === "number") {
|
|
221
|
-
(0, properties_1.defineReadOnly)(
|
|
222
|
-
(0, properties_1.defineReadOnly)(
|
|
154
|
+
(0, properties_1.defineReadOnly)(this, "_index", addressOrIndex);
|
|
155
|
+
(0, properties_1.defineReadOnly)(this, "_address", null);
|
|
223
156
|
}
|
|
224
157
|
else {
|
|
225
158
|
logger.throwArgumentError("invalid address or index", "addressOrIndex", addressOrIndex);
|
|
226
159
|
}
|
|
227
|
-
return _this;
|
|
228
160
|
}
|
|
229
|
-
|
|
161
|
+
connect(provider) {
|
|
230
162
|
return logger.throwError("cannot alter JSON-RPC Signer connection", logger_1.Logger.errors.UNSUPPORTED_OPERATION, {
|
|
231
163
|
operation: "connect"
|
|
232
164
|
});
|
|
233
|
-
}
|
|
234
|
-
|
|
165
|
+
}
|
|
166
|
+
connectUnchecked() {
|
|
235
167
|
return new UncheckedJsonRpcSigner(_constructorGuard, this.provider, this._address || this._index);
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
var _this = this;
|
|
168
|
+
}
|
|
169
|
+
getAddress() {
|
|
239
170
|
if (this._address) {
|
|
240
171
|
return Promise.resolve(this._address);
|
|
241
172
|
}
|
|
242
|
-
return this.provider.send("eth_accounts", []).then(
|
|
243
|
-
if (accounts.length <=
|
|
244
|
-
logger.throwError("unknown account #" +
|
|
173
|
+
return this.provider.send("eth_accounts", []).then((accounts) => {
|
|
174
|
+
if (accounts.length <= this._index) {
|
|
175
|
+
logger.throwError("unknown account #" + this._index, logger_1.Logger.errors.UNSUPPORTED_OPERATION, {
|
|
245
176
|
operation: "getAddress"
|
|
246
177
|
});
|
|
247
178
|
}
|
|
248
|
-
return
|
|
179
|
+
return this.provider.formatter.address(accounts[this._index]);
|
|
249
180
|
});
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
var _this = this;
|
|
181
|
+
}
|
|
182
|
+
sendUncheckedTransaction(transaction) {
|
|
253
183
|
transaction = (0, properties_1.shallowCopy)(transaction);
|
|
254
|
-
|
|
184
|
+
const fromAddress = this.getAddress().then((address) => {
|
|
255
185
|
if (address) {
|
|
256
186
|
address = address.toLowerCase();
|
|
257
187
|
}
|
|
@@ -261,35 +191,26 @@ var JsonRpcSigner = /** @class */ (function (_super) {
|
|
|
261
191
|
// wishes to use this, it is easy to specify explicitly, otherwise
|
|
262
192
|
// we look it up for them.
|
|
263
193
|
if (transaction.gasLimit == null) {
|
|
264
|
-
|
|
194
|
+
const estimate = (0, properties_1.shallowCopy)(transaction);
|
|
265
195
|
estimate.from = fromAddress;
|
|
266
196
|
transaction.gasLimit = this.provider.estimateGas(estimate);
|
|
267
197
|
}
|
|
268
198
|
if (transaction.to != null) {
|
|
269
|
-
transaction.to = Promise.resolve(transaction.to).then(
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
address = _a.sent();
|
|
280
|
-
if (address == null) {
|
|
281
|
-
logger.throwArgumentError("provided ENS name resolves to null", "tx.to", to);
|
|
282
|
-
}
|
|
283
|
-
return [2 /*return*/, address];
|
|
284
|
-
}
|
|
285
|
-
});
|
|
286
|
-
}); });
|
|
199
|
+
transaction.to = Promise.resolve(transaction.to).then(async (to) => {
|
|
200
|
+
if (to == null) {
|
|
201
|
+
return null;
|
|
202
|
+
}
|
|
203
|
+
const address = await this.provider.resolveName(to);
|
|
204
|
+
if (address == null) {
|
|
205
|
+
logger.throwArgumentError("provided ENS name resolves to null", "tx.to", to);
|
|
206
|
+
}
|
|
207
|
+
return address;
|
|
208
|
+
});
|
|
287
209
|
}
|
|
288
210
|
return (0, properties_1.resolveProperties)({
|
|
289
211
|
tx: (0, properties_1.resolveProperties)(transaction),
|
|
290
212
|
sender: fromAddress
|
|
291
|
-
}).then(
|
|
292
|
-
var tx = _a.tx, sender = _a.sender;
|
|
213
|
+
}).then(({ tx, sender }) => {
|
|
293
214
|
if (tx.from != null) {
|
|
294
215
|
if (tx.from.toLowerCase() !== sender) {
|
|
295
216
|
logger.throwArgumentError("from address mismatch", "transaction", transaction);
|
|
@@ -298,10 +219,10 @@ var JsonRpcSigner = /** @class */ (function (_super) {
|
|
|
298
219
|
else {
|
|
299
220
|
tx.from = sender;
|
|
300
221
|
}
|
|
301
|
-
|
|
302
|
-
return
|
|
222
|
+
const hexTx = this.provider.constructor.hexlifyTransaction(tx, { from: true });
|
|
223
|
+
return this.provider.send("eth_sendTransaction", [hexTx]).then((hash) => {
|
|
303
224
|
return hash;
|
|
304
|
-
},
|
|
225
|
+
}, (error) => {
|
|
305
226
|
if (typeof (error.message) === "string" && error.message.match(/user denied/i)) {
|
|
306
227
|
logger.throwError("user rejected transaction", logger_1.Logger.errors.ACTION_REJECTED, {
|
|
307
228
|
action: "sendTransaction",
|
|
@@ -311,180 +232,102 @@ var JsonRpcSigner = /** @class */ (function (_super) {
|
|
|
311
232
|
return checkError("sendTransaction", error, hexTx);
|
|
312
233
|
});
|
|
313
234
|
});
|
|
314
|
-
}
|
|
315
|
-
|
|
235
|
+
}
|
|
236
|
+
signTransaction(transaction) {
|
|
316
237
|
return logger.throwError("signing transactions is unsupported", logger_1.Logger.errors.UNSUPPORTED_OPERATION, {
|
|
317
238
|
operation: "signTransaction"
|
|
318
239
|
});
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
case 3:
|
|
334
|
-
_a.trys.push([3, 5, , 6]);
|
|
335
|
-
return [4 /*yield*/, (0, web_1.poll)(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
336
|
-
var tx;
|
|
337
|
-
return __generator(this, function (_a) {
|
|
338
|
-
switch (_a.label) {
|
|
339
|
-
case 0: return [4 /*yield*/, this.provider.getTransaction(hash)];
|
|
340
|
-
case 1:
|
|
341
|
-
tx = _a.sent();
|
|
342
|
-
if (tx === null) {
|
|
343
|
-
return [2 /*return*/, undefined];
|
|
344
|
-
}
|
|
345
|
-
return [2 /*return*/, this.provider._wrapTransaction(tx, hash, blockNumber)];
|
|
346
|
-
}
|
|
347
|
-
});
|
|
348
|
-
}); }, { oncePoll: this.provider })];
|
|
349
|
-
case 4:
|
|
350
|
-
// Unfortunately, JSON-RPC only provides and opaque transaction hash
|
|
351
|
-
// for a response, and we need the actual transaction, so we poll
|
|
352
|
-
// for it; it should show up very quickly
|
|
353
|
-
return [2 /*return*/, _a.sent()];
|
|
354
|
-
case 5:
|
|
355
|
-
error_1 = _a.sent();
|
|
356
|
-
error_1.transactionHash = hash;
|
|
357
|
-
throw error_1;
|
|
358
|
-
case 6: return [2 /*return*/];
|
|
359
|
-
}
|
|
360
|
-
});
|
|
361
|
-
});
|
|
362
|
-
};
|
|
363
|
-
JsonRpcSigner.prototype.signMessage = function (message) {
|
|
364
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
365
|
-
var data, address, error_2;
|
|
366
|
-
return __generator(this, function (_a) {
|
|
367
|
-
switch (_a.label) {
|
|
368
|
-
case 0:
|
|
369
|
-
data = ((typeof (message) === "string") ? (0, strings_1.toUtf8Bytes)(message) : message);
|
|
370
|
-
return [4 /*yield*/, this.getAddress()];
|
|
371
|
-
case 1:
|
|
372
|
-
address = _a.sent();
|
|
373
|
-
_a.label = 2;
|
|
374
|
-
case 2:
|
|
375
|
-
_a.trys.push([2, 4, , 5]);
|
|
376
|
-
return [4 /*yield*/, this.provider.send("personal_sign", [(0, bytes_1.hexlify)(data), address.toLowerCase()])];
|
|
377
|
-
case 3: return [2 /*return*/, _a.sent()];
|
|
378
|
-
case 4:
|
|
379
|
-
error_2 = _a.sent();
|
|
380
|
-
if (typeof (error_2.message) === "string" && error_2.message.match(/user denied/i)) {
|
|
381
|
-
logger.throwError("user rejected signing", logger_1.Logger.errors.ACTION_REJECTED, {
|
|
382
|
-
action: "signMessage",
|
|
383
|
-
from: address,
|
|
384
|
-
messageData: message
|
|
385
|
-
});
|
|
386
|
-
}
|
|
387
|
-
throw error_2;
|
|
388
|
-
case 5: return [2 /*return*/];
|
|
389
|
-
}
|
|
390
|
-
});
|
|
391
|
-
});
|
|
392
|
-
};
|
|
393
|
-
JsonRpcSigner.prototype._legacySignMessage = function (message) {
|
|
394
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
395
|
-
var data, address, error_3;
|
|
396
|
-
return __generator(this, function (_a) {
|
|
397
|
-
switch (_a.label) {
|
|
398
|
-
case 0:
|
|
399
|
-
data = ((typeof (message) === "string") ? (0, strings_1.toUtf8Bytes)(message) : message);
|
|
400
|
-
return [4 /*yield*/, this.getAddress()];
|
|
401
|
-
case 1:
|
|
402
|
-
address = _a.sent();
|
|
403
|
-
_a.label = 2;
|
|
404
|
-
case 2:
|
|
405
|
-
_a.trys.push([2, 4, , 5]);
|
|
406
|
-
return [4 /*yield*/, this.provider.send("eth_sign", [address.toLowerCase(), (0, bytes_1.hexlify)(data)])];
|
|
407
|
-
case 3:
|
|
408
|
-
// https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_sign
|
|
409
|
-
return [2 /*return*/, _a.sent()];
|
|
410
|
-
case 4:
|
|
411
|
-
error_3 = _a.sent();
|
|
412
|
-
if (typeof (error_3.message) === "string" && error_3.message.match(/user denied/i)) {
|
|
413
|
-
logger.throwError("user rejected signing", logger_1.Logger.errors.ACTION_REJECTED, {
|
|
414
|
-
action: "_legacySignMessage",
|
|
415
|
-
from: address,
|
|
416
|
-
messageData: message
|
|
417
|
-
});
|
|
418
|
-
}
|
|
419
|
-
throw error_3;
|
|
420
|
-
case 5: return [2 /*return*/];
|
|
421
|
-
}
|
|
422
|
-
});
|
|
423
|
-
});
|
|
424
|
-
};
|
|
425
|
-
JsonRpcSigner.prototype._signTypedData = function (domain, types, value) {
|
|
426
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
427
|
-
var populated, address, error_4;
|
|
428
|
-
var _this = this;
|
|
429
|
-
return __generator(this, function (_a) {
|
|
430
|
-
switch (_a.label) {
|
|
431
|
-
case 0: return [4 /*yield*/, hash_1._TypedDataEncoder.resolveNames(domain, types, value, function (name) {
|
|
432
|
-
return _this.provider.resolveName(name);
|
|
433
|
-
})];
|
|
434
|
-
case 1:
|
|
435
|
-
populated = _a.sent();
|
|
436
|
-
return [4 /*yield*/, this.getAddress()];
|
|
437
|
-
case 2:
|
|
438
|
-
address = _a.sent();
|
|
439
|
-
_a.label = 3;
|
|
440
|
-
case 3:
|
|
441
|
-
_a.trys.push([3, 5, , 6]);
|
|
442
|
-
return [4 /*yield*/, this.provider.send("eth_signTypedData_v4", [
|
|
443
|
-
address.toLowerCase(),
|
|
444
|
-
JSON.stringify(hash_1._TypedDataEncoder.getPayload(populated.domain, types, populated.value))
|
|
445
|
-
])];
|
|
446
|
-
case 4: return [2 /*return*/, _a.sent()];
|
|
447
|
-
case 5:
|
|
448
|
-
error_4 = _a.sent();
|
|
449
|
-
if (typeof (error_4.message) === "string" && error_4.message.match(/user denied/i)) {
|
|
450
|
-
logger.throwError("user rejected signing", logger_1.Logger.errors.ACTION_REJECTED, {
|
|
451
|
-
action: "_signTypedData",
|
|
452
|
-
from: address,
|
|
453
|
-
messageData: { domain: populated.domain, types: types, value: populated.value }
|
|
454
|
-
});
|
|
455
|
-
}
|
|
456
|
-
throw error_4;
|
|
457
|
-
case 6: return [2 /*return*/];
|
|
458
|
-
}
|
|
459
|
-
});
|
|
460
|
-
});
|
|
461
|
-
};
|
|
462
|
-
JsonRpcSigner.prototype.unlock = function (password) {
|
|
463
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
464
|
-
var provider, address;
|
|
465
|
-
return __generator(this, function (_a) {
|
|
466
|
-
switch (_a.label) {
|
|
467
|
-
case 0:
|
|
468
|
-
provider = this.provider;
|
|
469
|
-
return [4 /*yield*/, this.getAddress()];
|
|
470
|
-
case 1:
|
|
471
|
-
address = _a.sent();
|
|
472
|
-
return [2 /*return*/, provider.send("personal_unlockAccount", [address.toLowerCase(), password, null])];
|
|
240
|
+
}
|
|
241
|
+
async sendTransaction(transaction) {
|
|
242
|
+
// This cannot be mined any earlier than any recent block
|
|
243
|
+
const blockNumber = await this.provider._getInternalBlockNumber(100 + 2 * this.provider.pollingInterval);
|
|
244
|
+
// Send the transaction
|
|
245
|
+
const hash = await this.sendUncheckedTransaction(transaction);
|
|
246
|
+
try {
|
|
247
|
+
// Unfortunately, JSON-RPC only provides and opaque transaction hash
|
|
248
|
+
// for a response, and we need the actual transaction, so we poll
|
|
249
|
+
// for it; it should show up very quickly
|
|
250
|
+
return await (0, web_1.poll)(async () => {
|
|
251
|
+
const tx = await this.provider.getTransaction(hash);
|
|
252
|
+
if (tx === null) {
|
|
253
|
+
return undefined;
|
|
473
254
|
}
|
|
474
|
-
|
|
255
|
+
return this.provider._wrapTransaction(tx, hash, blockNumber);
|
|
256
|
+
}, { oncePoll: this.provider });
|
|
257
|
+
}
|
|
258
|
+
catch (error) {
|
|
259
|
+
error.transactionHash = hash;
|
|
260
|
+
throw error;
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
async signMessage(message) {
|
|
264
|
+
const data = ((typeof (message) === "string") ? (0, strings_1.toUtf8Bytes)(message) : message);
|
|
265
|
+
const address = await this.getAddress();
|
|
266
|
+
try {
|
|
267
|
+
return await this.provider.send("personal_sign", [(0, bytes_1.hexlify)(data), address.toLowerCase()]);
|
|
268
|
+
}
|
|
269
|
+
catch (error) {
|
|
270
|
+
if (typeof (error.message) === "string" && error.message.match(/user denied/i)) {
|
|
271
|
+
logger.throwError("user rejected signing", logger_1.Logger.errors.ACTION_REJECTED, {
|
|
272
|
+
action: "signMessage",
|
|
273
|
+
from: address,
|
|
274
|
+
messageData: message
|
|
275
|
+
});
|
|
276
|
+
}
|
|
277
|
+
throw error;
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
async _legacySignMessage(message) {
|
|
281
|
+
const data = ((typeof (message) === "string") ? (0, strings_1.toUtf8Bytes)(message) : message);
|
|
282
|
+
const address = await this.getAddress();
|
|
283
|
+
try {
|
|
284
|
+
// https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_sign
|
|
285
|
+
return await this.provider.send("eth_sign", [address.toLowerCase(), (0, bytes_1.hexlify)(data)]);
|
|
286
|
+
}
|
|
287
|
+
catch (error) {
|
|
288
|
+
if (typeof (error.message) === "string" && error.message.match(/user denied/i)) {
|
|
289
|
+
logger.throwError("user rejected signing", logger_1.Logger.errors.ACTION_REJECTED, {
|
|
290
|
+
action: "_legacySignMessage",
|
|
291
|
+
from: address,
|
|
292
|
+
messageData: message
|
|
293
|
+
});
|
|
294
|
+
}
|
|
295
|
+
throw error;
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
async _signTypedData(domain, types, value) {
|
|
299
|
+
// Populate any ENS names (in-place)
|
|
300
|
+
const populated = await hash_1._TypedDataEncoder.resolveNames(domain, types, value, (name) => {
|
|
301
|
+
return this.provider.resolveName(name);
|
|
475
302
|
});
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
303
|
+
const address = await this.getAddress();
|
|
304
|
+
try {
|
|
305
|
+
return await this.provider.send("eth_signTypedData_v4", [
|
|
306
|
+
address.toLowerCase(),
|
|
307
|
+
JSON.stringify(hash_1._TypedDataEncoder.getPayload(populated.domain, types, populated.value))
|
|
308
|
+
]);
|
|
309
|
+
}
|
|
310
|
+
catch (error) {
|
|
311
|
+
if (typeof (error.message) === "string" && error.message.match(/user denied/i)) {
|
|
312
|
+
logger.throwError("user rejected signing", logger_1.Logger.errors.ACTION_REJECTED, {
|
|
313
|
+
action: "_signTypedData",
|
|
314
|
+
from: address,
|
|
315
|
+
messageData: { domain: populated.domain, types, value: populated.value }
|
|
316
|
+
});
|
|
317
|
+
}
|
|
318
|
+
throw error;
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
async unlock(password) {
|
|
322
|
+
const provider = this.provider;
|
|
323
|
+
const address = await this.getAddress();
|
|
324
|
+
return provider.send("personal_unlockAccount", [address.toLowerCase(), password, null]);
|
|
325
|
+
}
|
|
326
|
+
}
|
|
479
327
|
exports.JsonRpcSigner = JsonRpcSigner;
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
484
|
-
}
|
|
485
|
-
UncheckedJsonRpcSigner.prototype.sendTransaction = function (transaction) {
|
|
486
|
-
var _this = this;
|
|
487
|
-
return this.sendUncheckedTransaction(transaction).then(function (hash) {
|
|
328
|
+
class UncheckedJsonRpcSigner extends JsonRpcSigner {
|
|
329
|
+
sendTransaction(transaction) {
|
|
330
|
+
return this.sendUncheckedTransaction(transaction).then((hash) => {
|
|
488
331
|
return {
|
|
489
332
|
hash: hash,
|
|
490
333
|
nonce: null,
|
|
@@ -495,139 +338,107 @@ var UncheckedJsonRpcSigner = /** @class */ (function (_super) {
|
|
|
495
338
|
chainId: null,
|
|
496
339
|
confirmations: 0,
|
|
497
340
|
from: null,
|
|
498
|
-
wait:
|
|
341
|
+
wait: (confirmations) => { return this.provider.waitForTransaction(hash, confirmations); }
|
|
499
342
|
};
|
|
500
343
|
});
|
|
501
|
-
}
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
var allowedTransactionKeys = {
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
const allowedTransactionKeys = {
|
|
505
347
|
chainId: true, data: true, gasLimit: true, gasPrice: true, nonce: true, to: true, value: true,
|
|
506
348
|
type: true, accessList: true,
|
|
507
349
|
maxFeePerGas: true, maxPriorityFeePerGas: true
|
|
508
350
|
};
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
351
|
+
class JsonRpcProvider extends base_provider_1.BaseProvider {
|
|
352
|
+
get _cache() {
|
|
353
|
+
if (this._eventLoopCache == null) {
|
|
354
|
+
this._eventLoopCache = {};
|
|
355
|
+
}
|
|
356
|
+
return this._eventLoopCache;
|
|
357
|
+
}
|
|
358
|
+
constructor(url, network) {
|
|
359
|
+
let networkOrReady = network;
|
|
514
360
|
// The network is unknown, query the JSON-RPC for it
|
|
515
361
|
if (networkOrReady == null) {
|
|
516
|
-
networkOrReady = new Promise(
|
|
517
|
-
setTimeout(
|
|
518
|
-
|
|
362
|
+
networkOrReady = new Promise((resolve, reject) => {
|
|
363
|
+
setTimeout(() => {
|
|
364
|
+
this.detectNetwork().then((network) => {
|
|
519
365
|
resolve(network);
|
|
520
|
-
},
|
|
366
|
+
}, (error) => {
|
|
521
367
|
reject(error);
|
|
522
368
|
});
|
|
523
369
|
}, 0);
|
|
524
370
|
});
|
|
525
371
|
}
|
|
526
|
-
|
|
372
|
+
super(networkOrReady);
|
|
527
373
|
// Default URL
|
|
528
374
|
if (!url) {
|
|
529
|
-
url = (0, properties_1.getStatic)(
|
|
375
|
+
url = (0, properties_1.getStatic)(this.constructor, "defaultUrl")();
|
|
530
376
|
}
|
|
531
377
|
if (typeof (url) === "string") {
|
|
532
|
-
(0, properties_1.defineReadOnly)(
|
|
378
|
+
(0, properties_1.defineReadOnly)(this, "connection", Object.freeze({
|
|
533
379
|
url: url
|
|
534
380
|
}));
|
|
535
381
|
}
|
|
536
382
|
else {
|
|
537
|
-
(0, properties_1.defineReadOnly)(
|
|
383
|
+
(0, properties_1.defineReadOnly)(this, "connection", Object.freeze((0, properties_1.shallowCopy)(url)));
|
|
538
384
|
}
|
|
539
|
-
|
|
540
|
-
return _this;
|
|
385
|
+
this._nextId = 42;
|
|
541
386
|
}
|
|
542
|
-
|
|
543
|
-
get: function () {
|
|
544
|
-
if (this._eventLoopCache == null) {
|
|
545
|
-
this._eventLoopCache = {};
|
|
546
|
-
}
|
|
547
|
-
return this._eventLoopCache;
|
|
548
|
-
},
|
|
549
|
-
enumerable: false,
|
|
550
|
-
configurable: true
|
|
551
|
-
});
|
|
552
|
-
JsonRpcProvider.defaultUrl = function () {
|
|
387
|
+
static defaultUrl() {
|
|
553
388
|
return "http:/\/localhost:8545";
|
|
554
|
-
}
|
|
555
|
-
|
|
556
|
-
var _this = this;
|
|
389
|
+
}
|
|
390
|
+
detectNetwork() {
|
|
557
391
|
if (!this._cache["detectNetwork"]) {
|
|
558
392
|
this._cache["detectNetwork"] = this._uncachedDetectNetwork();
|
|
559
393
|
// Clear this cache at the beginning of the next event loop
|
|
560
|
-
setTimeout(
|
|
561
|
-
|
|
394
|
+
setTimeout(() => {
|
|
395
|
+
this._cache["detectNetwork"] = null;
|
|
562
396
|
}, 0);
|
|
563
397
|
}
|
|
564
398
|
return this._cache["detectNetwork"];
|
|
565
|
-
}
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
return [3 /*break*/, 8];
|
|
594
|
-
case 8: return [3 /*break*/, 9];
|
|
595
|
-
case 9:
|
|
596
|
-
if (chainId != null) {
|
|
597
|
-
getNetwork = (0, properties_1.getStatic)(this.constructor, "getNetwork");
|
|
598
|
-
try {
|
|
599
|
-
return [2 /*return*/, getNetwork(bignumber_1.BigNumber.from(chainId).toNumber())];
|
|
600
|
-
}
|
|
601
|
-
catch (error) {
|
|
602
|
-
return [2 /*return*/, logger.throwError("could not detect network", logger_1.Logger.errors.NETWORK_ERROR, {
|
|
603
|
-
chainId: chainId,
|
|
604
|
-
event: "invalidNetwork",
|
|
605
|
-
serverError: error
|
|
606
|
-
})];
|
|
607
|
-
}
|
|
608
|
-
}
|
|
609
|
-
return [2 /*return*/, logger.throwError("could not detect network", logger_1.Logger.errors.NETWORK_ERROR, {
|
|
610
|
-
event: "noNetwork"
|
|
611
|
-
})];
|
|
612
|
-
}
|
|
613
|
-
});
|
|
399
|
+
}
|
|
400
|
+
async _uncachedDetectNetwork() {
|
|
401
|
+
await timer(0);
|
|
402
|
+
let chainId = null;
|
|
403
|
+
try {
|
|
404
|
+
chainId = await this.send("eth_chainId", []);
|
|
405
|
+
}
|
|
406
|
+
catch (error) {
|
|
407
|
+
try {
|
|
408
|
+
chainId = await this.send("net_version", []);
|
|
409
|
+
}
|
|
410
|
+
catch (error) { }
|
|
411
|
+
}
|
|
412
|
+
if (chainId != null) {
|
|
413
|
+
const getNetwork = (0, properties_1.getStatic)(this.constructor, "getNetwork");
|
|
414
|
+
try {
|
|
415
|
+
return getNetwork(bignumber_1.BigNumber.from(chainId).toNumber());
|
|
416
|
+
}
|
|
417
|
+
catch (error) {
|
|
418
|
+
return logger.throwError("could not detect network", logger_1.Logger.errors.NETWORK_ERROR, {
|
|
419
|
+
chainId: chainId,
|
|
420
|
+
event: "invalidNetwork",
|
|
421
|
+
serverError: error
|
|
422
|
+
});
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
return logger.throwError("could not detect network", logger_1.Logger.errors.NETWORK_ERROR, {
|
|
426
|
+
event: "noNetwork"
|
|
614
427
|
});
|
|
615
|
-
}
|
|
616
|
-
|
|
428
|
+
}
|
|
429
|
+
getSigner(addressOrIndex) {
|
|
617
430
|
return new JsonRpcSigner(_constructorGuard, this, addressOrIndex);
|
|
618
|
-
}
|
|
619
|
-
|
|
431
|
+
}
|
|
432
|
+
getUncheckedSigner(addressOrIndex) {
|
|
620
433
|
return this.getSigner(addressOrIndex).connectUnchecked();
|
|
621
|
-
}
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
return accounts.map(function (a) { return _this.formatter.address(a); });
|
|
434
|
+
}
|
|
435
|
+
listAccounts() {
|
|
436
|
+
return this.send("eth_accounts", []).then((accounts) => {
|
|
437
|
+
return accounts.map((a) => this.formatter.address(a));
|
|
626
438
|
});
|
|
627
|
-
}
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
var request = {
|
|
439
|
+
}
|
|
440
|
+
send(method, params) {
|
|
441
|
+
const request = {
|
|
631
442
|
method: method,
|
|
632
443
|
params: params,
|
|
633
444
|
id: (this._nextId++),
|
|
@@ -640,37 +451,37 @@ var JsonRpcProvider = /** @class */ (function (_super) {
|
|
|
640
451
|
});
|
|
641
452
|
// We can expand this in the future to any call, but for now these
|
|
642
453
|
// are the biggest wins and do not require any serializing parameters.
|
|
643
|
-
|
|
454
|
+
const cache = (["eth_chainId", "eth_blockNumber"].indexOf(method) >= 0);
|
|
644
455
|
if (cache && this._cache[method]) {
|
|
645
456
|
return this._cache[method];
|
|
646
457
|
}
|
|
647
|
-
|
|
648
|
-
|
|
458
|
+
const result = (0, web_1.fetchJson)(this.connection, JSON.stringify(request), getResult).then((result) => {
|
|
459
|
+
this.emit("debug", {
|
|
649
460
|
action: "response",
|
|
650
461
|
request: request,
|
|
651
462
|
response: result,
|
|
652
|
-
provider:
|
|
463
|
+
provider: this
|
|
653
464
|
});
|
|
654
465
|
return result;
|
|
655
|
-
},
|
|
656
|
-
|
|
466
|
+
}, (error) => {
|
|
467
|
+
this.emit("debug", {
|
|
657
468
|
action: "response",
|
|
658
469
|
error: error,
|
|
659
470
|
request: request,
|
|
660
|
-
provider:
|
|
471
|
+
provider: this
|
|
661
472
|
});
|
|
662
473
|
throw error;
|
|
663
474
|
});
|
|
664
475
|
// Cache the fetch, but clear it on the next event loop
|
|
665
476
|
if (cache) {
|
|
666
477
|
this._cache[method] = result;
|
|
667
|
-
setTimeout(
|
|
668
|
-
|
|
478
|
+
setTimeout(() => {
|
|
479
|
+
this._cache[method] = null;
|
|
669
480
|
}, 0);
|
|
670
481
|
}
|
|
671
482
|
return result;
|
|
672
|
-
}
|
|
673
|
-
|
|
483
|
+
}
|
|
484
|
+
prepareRequest(method, params) {
|
|
674
485
|
switch (method) {
|
|
675
486
|
case "getBlockNumber":
|
|
676
487
|
return ["eth_blockNumber", []];
|
|
@@ -699,11 +510,11 @@ var JsonRpcProvider = /** @class */ (function (_super) {
|
|
|
699
510
|
case "getTransactionReceipt":
|
|
700
511
|
return ["eth_getTransactionReceipt", [params.transactionHash]];
|
|
701
512
|
case "call": {
|
|
702
|
-
|
|
513
|
+
const hexlifyTransaction = (0, properties_1.getStatic)(this.constructor, "hexlifyTransaction");
|
|
703
514
|
return ["eth_call", [hexlifyTransaction(params.transaction, { from: true }), params.blockTag]];
|
|
704
515
|
}
|
|
705
516
|
case "estimateGas": {
|
|
706
|
-
|
|
517
|
+
const hexlifyTransaction = (0, properties_1.getStatic)(this.constructor, "hexlifyTransaction");
|
|
707
518
|
return ["eth_estimateGas", [hexlifyTransaction(params.transaction, { from: true })]];
|
|
708
519
|
}
|
|
709
520
|
case "getLogs":
|
|
@@ -715,57 +526,48 @@ var JsonRpcProvider = /** @class */ (function (_super) {
|
|
|
715
526
|
break;
|
|
716
527
|
}
|
|
717
528
|
return null;
|
|
718
|
-
}
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
params = (0, properties_1.shallowCopy)(params);
|
|
735
|
-
params.transaction = (0, properties_1.shallowCopy)(tx);
|
|
736
|
-
delete params.transaction.type;
|
|
737
|
-
}
|
|
738
|
-
_a.label = 2;
|
|
739
|
-
case 2:
|
|
740
|
-
args = this.prepareRequest(method, params);
|
|
741
|
-
if (args == null) {
|
|
742
|
-
logger.throwError(method + " not implemented", logger_1.Logger.errors.NOT_IMPLEMENTED, { operation: method });
|
|
743
|
-
}
|
|
744
|
-
_a.label = 3;
|
|
745
|
-
case 3:
|
|
746
|
-
_a.trys.push([3, 5, , 6]);
|
|
747
|
-
return [4 /*yield*/, this.send(args[0], args[1])];
|
|
748
|
-
case 4: return [2 /*return*/, _a.sent()];
|
|
749
|
-
case 5:
|
|
750
|
-
error_7 = _a.sent();
|
|
751
|
-
return [2 /*return*/, checkError(method, error_7, params)];
|
|
752
|
-
case 6: return [2 /*return*/];
|
|
529
|
+
}
|
|
530
|
+
async perform(method, params) {
|
|
531
|
+
// Legacy networks do not like the type field being passed along (which
|
|
532
|
+
// is fair), so we delete type if it is 0 and a non-EIP-1559 network
|
|
533
|
+
if (method === "call" || method === "estimateGas") {
|
|
534
|
+
const tx = params.transaction;
|
|
535
|
+
if (tx && tx.type != null && bignumber_1.BigNumber.from(tx.type).isZero()) {
|
|
536
|
+
// If there are no EIP-1559 properties, it might be non-EIP-1559
|
|
537
|
+
if (tx.maxFeePerGas == null && tx.maxPriorityFeePerGas == null) {
|
|
538
|
+
const feeData = await this.getFeeData();
|
|
539
|
+
if (feeData.maxFeePerGas == null && feeData.maxPriorityFeePerGas == null) {
|
|
540
|
+
// Network doesn't know about EIP-1559 (and hence type)
|
|
541
|
+
params = (0, properties_1.shallowCopy)(params);
|
|
542
|
+
params.transaction = (0, properties_1.shallowCopy)(tx);
|
|
543
|
+
delete params.transaction.type;
|
|
544
|
+
}
|
|
753
545
|
}
|
|
754
|
-
}
|
|
755
|
-
}
|
|
756
|
-
|
|
757
|
-
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
const args = this.prepareRequest(method, params);
|
|
549
|
+
if (args == null) {
|
|
550
|
+
logger.throwError(method + " not implemented", logger_1.Logger.errors.NOT_IMPLEMENTED, { operation: method });
|
|
551
|
+
}
|
|
552
|
+
try {
|
|
553
|
+
return await this.send(args[0], args[1]);
|
|
554
|
+
}
|
|
555
|
+
catch (error) {
|
|
556
|
+
return checkError(method, error, params);
|
|
557
|
+
}
|
|
558
|
+
}
|
|
559
|
+
_startEvent(event) {
|
|
758
560
|
if (event.tag === "pending") {
|
|
759
561
|
this._startPending();
|
|
760
562
|
}
|
|
761
|
-
|
|
762
|
-
}
|
|
763
|
-
|
|
563
|
+
super._startEvent(event);
|
|
564
|
+
}
|
|
565
|
+
_startPending() {
|
|
764
566
|
if (this._pendingFilter != null) {
|
|
765
567
|
return;
|
|
766
568
|
}
|
|
767
|
-
|
|
768
|
-
|
|
569
|
+
const self = this;
|
|
570
|
+
const pendingFilter = this.send("eth_newPendingTransactionFilter", []);
|
|
769
571
|
this._pendingFilter = pendingFilter;
|
|
770
572
|
pendingFilter.then(function (filterId) {
|
|
771
573
|
function poll() {
|
|
@@ -773,7 +575,7 @@ var JsonRpcProvider = /** @class */ (function (_super) {
|
|
|
773
575
|
if (self._pendingFilter != pendingFilter) {
|
|
774
576
|
return null;
|
|
775
577
|
}
|
|
776
|
-
|
|
578
|
+
let seq = Promise.resolve();
|
|
777
579
|
hashes.forEach(function (hash) {
|
|
778
580
|
// @TODO: This should be garbage collected at some point... How? When?
|
|
779
581
|
self._emitted["t:" + hash.toLowerCase()] = "pending";
|
|
@@ -794,18 +596,18 @@ var JsonRpcProvider = /** @class */ (function (_super) {
|
|
|
794
596
|
}
|
|
795
597
|
setTimeout(function () { poll(); }, 0);
|
|
796
598
|
return null;
|
|
797
|
-
}).catch(
|
|
599
|
+
}).catch((error) => { });
|
|
798
600
|
}
|
|
799
601
|
poll();
|
|
800
602
|
return filterId;
|
|
801
|
-
}).catch(
|
|
802
|
-
}
|
|
803
|
-
|
|
603
|
+
}).catch((error) => { });
|
|
604
|
+
}
|
|
605
|
+
_stopEvent(event) {
|
|
804
606
|
if (event.tag === "pending" && this.listenerCount("pending") === 0) {
|
|
805
607
|
this._pendingFilter = null;
|
|
806
608
|
}
|
|
807
|
-
|
|
808
|
-
}
|
|
609
|
+
super._stopEvent(event);
|
|
610
|
+
}
|
|
809
611
|
// Convert an ethers.js transaction into a JSON-RPC transaction
|
|
810
612
|
// - gasLimit => gas
|
|
811
613
|
// - All values hexlified
|
|
@@ -815,24 +617,24 @@ var JsonRpcProvider = /** @class */ (function (_super) {
|
|
|
815
617
|
// before this is called
|
|
816
618
|
// @TODO: This will likely be removed in future versions and prepareRequest
|
|
817
619
|
// will be the preferred method for this.
|
|
818
|
-
|
|
620
|
+
static hexlifyTransaction(transaction, allowExtra) {
|
|
819
621
|
// Check only allowed properties are given
|
|
820
|
-
|
|
622
|
+
const allowed = (0, properties_1.shallowCopy)(allowedTransactionKeys);
|
|
821
623
|
if (allowExtra) {
|
|
822
|
-
for (
|
|
624
|
+
for (const key in allowExtra) {
|
|
823
625
|
if (allowExtra[key]) {
|
|
824
626
|
allowed[key] = true;
|
|
825
627
|
}
|
|
826
628
|
}
|
|
827
629
|
}
|
|
828
630
|
(0, properties_1.checkProperties)(transaction, allowed);
|
|
829
|
-
|
|
631
|
+
const result = {};
|
|
830
632
|
// JSON-RPC now requires numeric values to be "quantity" values
|
|
831
633
|
["chainId", "gasLimit", "gasPrice", "type", "maxFeePerGas", "maxPriorityFeePerGas", "nonce", "value"].forEach(function (key) {
|
|
832
634
|
if (transaction[key] == null) {
|
|
833
635
|
return;
|
|
834
636
|
}
|
|
835
|
-
|
|
637
|
+
const value = (0, bytes_1.hexValue)(bignumber_1.BigNumber.from(transaction[key]));
|
|
836
638
|
if (key === "gasLimit") {
|
|
837
639
|
key = "gas";
|
|
838
640
|
}
|
|
@@ -848,8 +650,7 @@ var JsonRpcProvider = /** @class */ (function (_super) {
|
|
|
848
650
|
result["accessList"] = (0, transactions_1.accessListify)(transaction.accessList);
|
|
849
651
|
}
|
|
850
652
|
return result;
|
|
851
|
-
}
|
|
852
|
-
|
|
853
|
-
}(base_provider_1.BaseProvider));
|
|
653
|
+
}
|
|
654
|
+
}
|
|
854
655
|
exports.JsonRpcProvider = JsonRpcProvider;
|
|
855
656
|
//# sourceMappingURL=json-rpc-provider.js.map
|