ethers.js/src.ts/providers/plugin-fallback.ts
2023-02-02 03:05:37 -05:00

36 lines
1.1 KiB
TypeScript

import { AbstractProviderPlugin } from "./abstract-provider.js";
import { defineProperties } from "../utils/index.js";
import type { AbstractProvider, PerformActionRequest } from "./abstract-provider.js";
export const PluginIdFallbackProvider = "org.ethers.plugins.provider.QualifiedPlugin";
export class CheckQualifiedPlugin implements AbstractProviderPlugin {
declare name: string;
constructor() {
defineProperties<CheckQualifiedPlugin>(this, { name: PluginIdFallbackProvider });
}
connect(provider: AbstractProvider): CheckQualifiedPlugin {
return this;
}
// Retruns true if this value should be considered qualified for
// inclusion in the quorum.
isQualified(action: PerformActionRequest, result: any): boolean {
return true;
}
}
export class PossiblyPrunedTransactionPlugin extends CheckQualifiedPlugin {
isQualified(action: PerformActionRequest, result: any): boolean {
if (action.method === "getTransaction" || action.method === "getTransactionReceipt") {
if (result == null) { return false; }
}
return super.isQualified(action, result);
}
}