Skip to content

Commit

Permalink
Fix for new versions of Geth which return formatted data on revert ra…
Browse files Browse the repository at this point in the history
…ther than standard data (#949).
  • Loading branch information
ricmoo committed Nov 22, 2020
1 parent fbbe4ad commit 4a8d579
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
12 changes: 10 additions & 2 deletions packages/providers/src.ts/etherscan-provider.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"use strict";

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 { deepCopy, defineReadOnly } from "@ethersproject/properties";
import { ConnectionInfo, fetchJson } from "@ethersproject/web";
Expand Down Expand Up @@ -86,7 +86,15 @@ function checkLogTag(blockTag: string): number | "latest" {

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
let message = error.message;
Expand Down
14 changes: 11 additions & 3 deletions packages/providers/src.ts/json-rpc-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import { Provider, TransactionRequest, TransactionResponse } from "@ethersproject/abstract-provider";
import { Signer, TypedDataDomain, TypedDataField, TypedDataSigner } from "@ethersproject/abstract-signer";
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 { Network, Networkish } from "@ethersproject/networks";
import { checkProperties, deepCopy, Deferrable, defineReadOnly, getStatic, resolveProperties, shallowCopy } from "@ethersproject/properties";
Expand All @@ -21,7 +21,16 @@ import { BaseProvider, Event } from "./base-provider";

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;
if (error.code === Logger.errors.SERVER_ERROR && error.error && typeof(error.error.message) === "string") {
message = error.error.message;
Expand Down Expand Up @@ -448,7 +457,6 @@ export class JsonRpcProvider extends BaseProvider {
if (args == null) {
logger.throwError(method + " not implemented", Logger.errors.NOT_IMPLEMENTED, { operation: method });
}

try {
return await this.send(args[0], args[1])
} catch (error) {
Expand Down

0 comments on commit 4a8d579

Please sign in to comment.