More consistent debug events for Providers.
This commit is contained in:
parent
638d1fe62e
commit
e8f28b55d7
@ -4,7 +4,7 @@ import { BlockTag, TransactionRequest, TransactionResponse } from "@ethersprojec
|
||||
import { hexlify, hexValue } from "@ethersproject/bytes";
|
||||
import * as errors from "@ethersproject/errors";
|
||||
import { Networkish } from "@ethersproject/networks";
|
||||
import { defineReadOnly } from "@ethersproject/properties";
|
||||
import { deepCopy, defineReadOnly } from "@ethersproject/properties";
|
||||
import { fetchJson } from "@ethersproject/web";
|
||||
|
||||
import { BaseProvider } from "./base-provider";
|
||||
@ -112,11 +112,17 @@ export class EtherscanProvider extends BaseProvider{
|
||||
if (this.apiKey) { apiKey += "&apikey=" + this.apiKey; }
|
||||
|
||||
let get = (url: string, procFunc?: (value: any) => any) => {
|
||||
this.emit("debug", {
|
||||
action: "request",
|
||||
request: url,
|
||||
provider: this
|
||||
});
|
||||
|
||||
return fetchJson(url, null, procFunc || getJsonResult).then((result) => {
|
||||
this.emit("debug", {
|
||||
action: "perform",
|
||||
action: "response",
|
||||
request: url,
|
||||
response: result,
|
||||
response: deepCopy(result),
|
||||
provider: this
|
||||
});
|
||||
return result;
|
||||
@ -310,13 +316,20 @@ export class EtherscanProvider extends BaseProvider{
|
||||
url += "&endblock=" + endBlock;
|
||||
url += "&sort=asc" + apiKey;
|
||||
|
||||
this.emit("debug", {
|
||||
action: "request",
|
||||
request: url,
|
||||
provider: this
|
||||
});
|
||||
|
||||
return fetchJson(url, null, getResult).then((result: Array<any>) => {
|
||||
this.emit("debug", {
|
||||
action: "getHistory",
|
||||
action: "response",
|
||||
request: url,
|
||||
response: result,
|
||||
response: deepCopy(result),
|
||||
provider: this
|
||||
});
|
||||
|
||||
let output: Array<TransactionResponse> = [];
|
||||
result.forEach((tx) => {
|
||||
["contractAddress", "to"].forEach(function(key) {
|
||||
|
@ -3,7 +3,7 @@
|
||||
import * as errors from "@ethersproject/errors";
|
||||
import { Network } from "@ethersproject/networks";
|
||||
import { shuffled } from "@ethersproject/random";
|
||||
import { defineReadOnly } from "@ethersproject/properties";
|
||||
import { deepCopy, defineReadOnly } from "@ethersproject/properties";
|
||||
|
||||
import { BaseProvider } from "./base-provider";
|
||||
|
||||
@ -148,14 +148,32 @@ export class FallbackProvider extends BaseProvider {
|
||||
run: () => {
|
||||
let t0 = now();
|
||||
let start = t0 - T0;
|
||||
this.emit("debug", "perform", rid, { weight, start, provider, method, params });
|
||||
this.emit("debug", {
|
||||
action: "request",
|
||||
rid: rid,
|
||||
backend: { weight, start, provider },
|
||||
request: { method: method, params: deepCopy(params) },
|
||||
provider: this
|
||||
});
|
||||
return provider.perform(method, params).then((result) => {
|
||||
let duration = now() - t0;
|
||||
this.emit("debug", "result", rid, { duration, result });
|
||||
this.emit("debug", {
|
||||
action: "response",
|
||||
rid: rid,
|
||||
backend: { weight, start, duration, provider },
|
||||
request: { method: method, params: deepCopy(params) },
|
||||
response: deepCopy(result)
|
||||
});
|
||||
return { weight: weight, result: result };
|
||||
}, (error) => {
|
||||
let duration = now() - t0;
|
||||
this.emit("debug", "error", rid, { duration, error });
|
||||
this.emit("debug", {
|
||||
action: "response",
|
||||
rid: rid,
|
||||
backend: { weight, start, duration, provider },
|
||||
request: { method: method, params: deepCopy(params) },
|
||||
error: error
|
||||
});
|
||||
return { weight: weight, error: error };
|
||||
});
|
||||
},
|
||||
|
@ -8,7 +8,7 @@ import { BigNumber } from "@ethersproject/bignumber";
|
||||
import { Bytes, hexlify, hexValue } from "@ethersproject/bytes";
|
||||
import * as errors from "@ethersproject/errors";
|
||||
import { getNetwork, Network, Networkish } from "@ethersproject/networks";
|
||||
import { checkProperties, defineReadOnly, resolveProperties, shallowCopy } from "@ethersproject/properties";
|
||||
import { checkProperties, deepCopy, defineReadOnly, resolveProperties, shallowCopy } from "@ethersproject/properties";
|
||||
import { toUtf8Bytes } from "@ethersproject/strings";
|
||||
import { ConnectionInfo, fetchJson, poll } from "@ethersproject/web";
|
||||
|
||||
@ -283,9 +283,15 @@ export class JsonRpcProvider extends BaseProvider {
|
||||
jsonrpc: "2.0"
|
||||
};
|
||||
|
||||
this.emit("debug", {
|
||||
action: "request",
|
||||
request: deepCopy(request),
|
||||
provider: this
|
||||
});
|
||||
|
||||
return fetchJson(this.connection, JSON.stringify(request), getResult).then((result) => {
|
||||
this.emit("debug", {
|
||||
action: "send",
|
||||
action: "response",
|
||||
request: request,
|
||||
response: result,
|
||||
provider: this
|
||||
|
Loading…
x
Reference in New Issue
Block a user