*add blacklist of RPC methods to not cache
This commit is contained in:
parent
d14d8006ae
commit
66dc3534b2
|
@ -137,6 +137,12 @@ export class RPC {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public deleteCachedRequest(request: RPCRequest): void {
|
||||||
|
const hash = this.hashRequest(request);
|
||||||
|
|
||||||
|
this.cache.del(hash);
|
||||||
|
}
|
||||||
|
|
||||||
private hashRequest(request: RPCRequest): string {
|
private hashRequest(request: RPCRequest): string {
|
||||||
const tempRequest = {
|
const tempRequest = {
|
||||||
method: request.method,
|
method: request.method,
|
||||||
|
|
11
src/index.ts
11
src/index.ts
|
@ -74,6 +74,14 @@ interface ConsensusBlockRequest {
|
||||||
|
|
||||||
let client: Client;
|
let client: Client;
|
||||||
|
|
||||||
|
const RPC_NO_CACHE = [
|
||||||
|
"eth_call",
|
||||||
|
"eth_estimateGas",
|
||||||
|
"eth_sendRawTransaction",
|
||||||
|
"eth_getTransactionReceipt",
|
||||||
|
"eth_getTransactionCount",
|
||||||
|
];
|
||||||
|
|
||||||
const plugin: Plugin = {
|
const plugin: Plugin = {
|
||||||
name: "eth",
|
name: "eth",
|
||||||
async plugin(api: PluginAPI): Promise<void> {
|
async plugin(api: PluginAPI): Promise<void> {
|
||||||
|
@ -178,6 +186,9 @@ const plugin: Plugin = {
|
||||||
}
|
}
|
||||||
let ret = provider.rpc.getCachedRequest(request);
|
let ret = provider.rpc.getCachedRequest(request);
|
||||||
|
|
||||||
|
if (RPC_NO_CACHE.includes(request.method)) {
|
||||||
|
provider.rpc.deleteCachedRequest(request);
|
||||||
|
}
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
return { ...ret, id: request.id ?? ret.id };
|
return { ...ret, id: request.id ?? ret.id };
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue