Skip to content

Commit 805a8b3

Browse files
committed
Remove BlockscoutProvider temporarily until custom error issues are fixed.
1 parent d18aba6 commit 805a8b3

File tree

3 files changed

+57
-5
lines changed

3 files changed

+57
-5
lines changed

src.ts/providers/default-provider.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { assert } from "../utils/index.js";
33

44
import { AnkrProvider } from "./provider-ankr.js";
55
import { AlchemyProvider } from "./provider-alchemy.js";
6-
import { BlockscoutProvider } from "./provider-blockscout.js";
6+
//import { BlockscoutProvider } from "./provider-blockscout.js";
77
import { ChainstackProvider } from "./provider-chainstack.js";
88
import { CloudflareProvider } from "./provider-cloudflare.js";
99
import { EtherscanProvider } from "./provider-etherscan.js";
@@ -121,13 +121,13 @@ export function getDefaultProvider(network?: string | Networkish | WebSocketLike
121121
providers.push(new AnkrProvider(network, options.ankr));
122122
} catch (error) { }
123123
}
124-
124+
/* Temporarily remove until custom error issue is fixed
125125
if (allowService("blockscout")) {
126126
try {
127127
providers.push(new BlockscoutProvider(network, options.blockscout));
128128
} catch (error) { }
129129
}
130-
130+
*/
131131
if (allowService("chainstack")) {
132132
try {
133133
providers.push(new ChainstackProvider(network, options.chainstack));

src.ts/providers/provider-blockscout.ts

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,16 @@
2020
* @_subsection: api/providers/thirdparty:Blockscout [providers-blockscout]
2121
*/
2222
import {
23-
defineProperties, FetchRequest, assertArgument
23+
assertArgument, defineProperties, FetchRequest, isHexString
2424
} from "../utils/index.js";
2525

2626
import { Network } from "./network.js";
2727
import { JsonRpcProvider } from "./provider-jsonrpc.js";
2828

29-
import type { AbstractProvider } from "./abstract-provider.js";
29+
import type { AbstractProvider, PerformActionRequest } from "./abstract-provider.js";
3030
import type { CommunityResourcable } from "./community.js";
3131
import type { Networkish } from "./network.js";
32+
import type { JsonRpcPayload, JsonRpcError } from "./provider-jsonrpc.js";
3233

3334

3435
function getUrl(name: string): string {
@@ -108,6 +109,52 @@ export class BlockscoutProvider extends JsonRpcProvider implements CommunityReso
108109
return (this.apiKey === null);
109110
}
110111

112+
getRpcRequest(req: PerformActionRequest): null | { method: string, args: Array<any> } {
113+
// Blockscout enforces the TAG argument for estimateGas
114+
const resp = super.getRpcRequest(req);
115+
if (resp && resp.method === "eth_estimateGas" && resp.args.length == 1) {
116+
resp.args = resp.args.slice();
117+
resp.args.push("latest");
118+
}
119+
return resp;
120+
}
121+
122+
getRpcError(payload: JsonRpcPayload, _error: JsonRpcError): Error {
123+
const error = _error ? _error.error: null;
124+
125+
// Blockscout currently drops the VM result and replaces it with a
126+
// human-readable string, so we need to make it machine-readable.
127+
if (error && error.code === -32015 && !isHexString(error.data || "", true)) {
128+
const panicCodes = <Record<string, string>>{
129+
"assert(false)": "01",
130+
"arithmetic underflow or overflow": "11",
131+
"division or modulo by zero": "12",
132+
"out-of-bounds array access; popping on an empty array": "31",
133+
"out-of-bounds access of an array or bytesN": "32"
134+
};
135+
136+
let panicCode = "";
137+
if (error.message === "VM execution error.") {
138+
// eth_call passes this message
139+
panicCode = panicCodes[error.data] || "";
140+
} else if (panicCodes[error.message || ""]) {
141+
panicCode = panicCodes[error.message || ""];
142+
}
143+
144+
if (panicCode) {
145+
error.message += ` (reverted: ${ error.data })`;
146+
error.data = "0x4e487b7100000000000000000000000000000000000000000000000000000000000000" + panicCode;
147+
}
148+
149+
} else if (error && error.code === -32000) {
150+
if (error.message === "wrong transaction nonce") {
151+
error.message += " (nonce too low)";
152+
}
153+
}
154+
155+
return super.getRpcError(payload, _error);
156+
}
157+
111158
/**
112159
* Returns a prepared request for connecting to %%network%%
113160
* with %%apiKey%%.

src.ts/providers/provider-jsonrpc.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1002,6 +1002,11 @@ export abstract class JsonRpcApiProvider extends AbstractProvider {
10021002
transaction: ((<any>payload).params[0]),
10031003
info: { payload, error }
10041004
});
1005+
} else if (msg.match(/nonce/i) && msg.match(/too low/i)) {
1006+
return makeError("nonce has already been used", "NONCE_EXPIRED", {
1007+
transaction: ((<any>payload).params[0]),
1008+
info: { payload, error }
1009+
});
10051010
}
10061011
}
10071012

0 commit comments

Comments
 (0)