Fix for new versions of Geth which return formatted data on revert rather than standard data (#949).

This commit is contained in:
Richard Moore 2020-11-22 17:43:32 -05:00
parent fbbe4ad638
commit 4a8d579dca
No known key found for this signature in database
GPG Key ID: 665176BE8E9DC651
2 changed files with 21 additions and 5 deletions

@ -1,7 +1,7 @@
"use strict"; "use strict";
import { BlockTag, TransactionRequest, TransactionResponse } from "@ethersproject/abstract-provider"; import { BlockTag, TransactionRequest, TransactionResponse } from "@ethersproject/abstract-provider";
import { hexlify, hexValue } from "@ethersproject/bytes"; import { hexlify, hexValue, isHexString } from "@ethersproject/bytes";
import { Network, Networkish } from "@ethersproject/networks"; import { Network, Networkish } from "@ethersproject/networks";
import { deepCopy, defineReadOnly } from "@ethersproject/properties"; import { deepCopy, defineReadOnly } from "@ethersproject/properties";
import { ConnectionInfo, fetchJson } from "@ethersproject/web"; import { ConnectionInfo, fetchJson } from "@ethersproject/web";
@ -86,7 +86,15 @@ function checkLogTag(blockTag: string): number | "latest" {
const defaultApiKey = "9D13ZE7XSBTJ94N9BNJ2MA33VMAY2YPIRB"; const defaultApiKey = "9D13ZE7XSBTJ94N9BNJ2MA33VMAY2YPIRB";
function checkError(method: string, error: any, transaction: any): never { function checkError(method: string, error: any, transaction: any): any {
// Undo the "convenience" some nodes are attempting to prevent backwards
// incompatibility; maybe for v6 consider forwarding reverts as errors
if (method === "call" && error.code === Logger.errors.SERVER_ERROR) {
const e = error.error;
if (e && e.message.match("reverted") && isHexString(e.data)) {
return e.data;
}
}
// Get the message from any nested error structure // Get the message from any nested error structure
let message = error.message; let message = error.message;

@ -5,7 +5,7 @@
import { Provider, TransactionRequest, TransactionResponse } from "@ethersproject/abstract-provider"; import { Provider, TransactionRequest, TransactionResponse } from "@ethersproject/abstract-provider";
import { Signer, TypedDataDomain, TypedDataField, TypedDataSigner } from "@ethersproject/abstract-signer"; import { Signer, TypedDataDomain, TypedDataField, TypedDataSigner } from "@ethersproject/abstract-signer";
import { BigNumber } from "@ethersproject/bignumber"; import { BigNumber } from "@ethersproject/bignumber";
import { Bytes, hexlify, hexValue } from "@ethersproject/bytes"; import { Bytes, hexlify, hexValue, isHexString } from "@ethersproject/bytes";
import { _TypedDataEncoder } from "@ethersproject/hash"; import { _TypedDataEncoder } from "@ethersproject/hash";
import { Network, Networkish } from "@ethersproject/networks"; import { Network, Networkish } from "@ethersproject/networks";
import { checkProperties, deepCopy, Deferrable, defineReadOnly, getStatic, resolveProperties, shallowCopy } from "@ethersproject/properties"; import { checkProperties, deepCopy, Deferrable, defineReadOnly, getStatic, resolveProperties, shallowCopy } from "@ethersproject/properties";
@ -21,7 +21,16 @@ import { BaseProvider, Event } from "./base-provider";
const errorGas = [ "call", "estimateGas" ]; const errorGas = [ "call", "estimateGas" ];
function checkError(method: string, error: any, params: any): never { function checkError(method: string, error: any, params: any): any {
// Undo the "convenience" some nodes are attempting to prevent backwards
// incompatibility; maybe for v6 consider forwarding reverts as errors
if (method === "call" && error.code === Logger.errors.SERVER_ERROR) {
const e = error.error;
if (e && e.message.match("reverted") && isHexString(e.data)) {
return e.data;
}
}
let message = error.message; let message = error.message;
if (error.code === Logger.errors.SERVER_ERROR && error.error && typeof(error.error.message) === "string") { if (error.code === Logger.errors.SERVER_ERROR && error.error && typeof(error.error.message) === "string") {
message = error.error.message; message = error.error.message;
@ -448,7 +457,6 @@ export class JsonRpcProvider extends BaseProvider {
if (args == null) { if (args == null) {
logger.throwError(method + " not implemented", Logger.errors.NOT_IMPLEMENTED, { operation: method }); logger.throwError(method + " not implemented", Logger.errors.NOT_IMPLEMENTED, { operation: method });
} }
try { try {
return await this.send(args[0], args[1]) return await this.send(args[0], args[1])
} catch (error) { } catch (error) {