Use consistent naming scheme for plugins.

This commit is contained in:
Richard Moore 2023-02-02 03:05:37 -05:00
parent a22eb3fbe5
commit 8f30da1858
5 changed files with 14 additions and 41 deletions

@ -94,7 +94,7 @@ export abstract class MulticoinProviderPlugin implements AbstractProviderPlugin
} }
} }
const BasicMulticoinPluginId = "org.ethers.plugins.BasicMulticoin"; const BasicMulticoinPluginId = "org.ethers.plugins.provider.BasicMulticoin";
/** /**
* A basic multicoin provider plugin. * A basic multicoin provider plugin.
@ -492,7 +492,7 @@ export class EnsResolver {
static async getEnsAddress(provider: Provider): Promise<string> { static async getEnsAddress(provider: Provider): Promise<string> {
const network = await provider.getNetwork(); const network = await provider.getNetwork();
const ensPlugin = network.getPlugin<EnsPlugin>("org.ethers.network-plugins.ens"); const ensPlugin = network.getPlugin<EnsPlugin>("org.ethers.plugins.network.Ens");
// No ENS... // No ENS...
assert(ensPlugin, "network does not support ENS", "UNSUPPORTED_OPERATION", { assert(ensPlugin, "network does not support ENS", "UNSUPPORTED_OPERATION", {
@ -502,16 +502,10 @@ export class EnsResolver {
} }
static async #getResolver(provider: Provider, name: string): Promise<null | string> { static async #getResolver(provider: Provider, name: string): Promise<null | string> {
const network = await provider.getNetwork(); const ensAddr = await EnsResolver.getEnsAddress(provider);
const ensPlugin = network.getPlugin<EnsPlugin>("org.ethers.network-plugins.ens");
// No ENS...
assert(ensPlugin, "network does not support ENS", "UNSUPPORTED_OPERATION", {
operation: "getResolver", info: { network: network.name } });
try { try {
const contract = new Contract(ensPlugin.address, [ const contract = new Contract(ensAddr, [
"function resolver(bytes32) view returns (address)" "function resolver(bytes32) view returns (address)"
], provider); ], provider);

@ -143,7 +143,7 @@ export class Network {
} }
computeIntrinsicGas(tx: TransactionLike): number { computeIntrinsicGas(tx: TransactionLike): number {
const costs = this.getPlugin<GasCostPlugin>("org.ethers.gas-cost") || (new GasCostPlugin()); const costs = this.getPlugin<GasCostPlugin>("org.ethers.plugins.network.GasCost") || (new GasCostPlugin());
let gas = costs.txBase; let gas = costs.txBase;
if (tx.to == null) { gas += costs.txCreate; } if (tx.to == null) { gas += costs.txCreate; }

@ -5,7 +5,7 @@ import { defineProperties } from "../utils/index.js";
import type { AbstractProvider, PerformActionRequest } from "./abstract-provider.js"; import type { AbstractProvider, PerformActionRequest } from "./abstract-provider.js";
export const PluginIdFallbackProvider = "org.ethers.plugins.QualifiedPlugin"; export const PluginIdFallbackProvider = "org.ethers.plugins.provider.QualifiedPlugin";
export class CheckQualifiedPlugin implements AbstractProviderPlugin { export class CheckQualifiedPlugin implements AbstractProviderPlugin {
declare name: string; declare name: string;

@ -50,7 +50,7 @@ export class GasCostPlugin extends NetworkPlugin implements GasCostParameters {
constructor(effectiveBlock?: number, costs?: GasCostParameters) { constructor(effectiveBlock?: number, costs?: GasCostParameters) {
if (effectiveBlock == null) { effectiveBlock = 0; } if (effectiveBlock == null) { effectiveBlock = 0; }
super(`org.ethers.network-plugins.gas-cost#${ (effectiveBlock || 0) }`); super(`org.ethers.network.plugins.GasCost#${ (effectiveBlock || 0) }`);
const props: Record<string, number> = { effectiveBlock }; const props: Record<string, number> = { effectiveBlock };
function set(name: keyof GasCostParameters, nullish: number): void { function set(name: keyof GasCostParameters, nullish: number): void {
@ -86,7 +86,7 @@ export class EnsPlugin extends NetworkPlugin {
readonly targetNetwork!: number; readonly targetNetwork!: number;
constructor(address?: null | string, targetNetwork?: null | number) { constructor(address?: null | string, targetNetwork?: null | number) {
super("org.ethers.network-plugins.ens"); super("org.ethers.plugins.network.Ens");
defineProperties<EnsPlugin>(this, { defineProperties<EnsPlugin>(this, {
address: (address || EnsAddress), address: (address || EnsAddress),
targetNetwork: ((targetNetwork == null) ? 1: targetNetwork) targetNetwork: ((targetNetwork == null) ? 1: targetNetwork)
@ -96,39 +96,17 @@ export class EnsPlugin extends NetworkPlugin {
clone(): EnsPlugin { clone(): EnsPlugin {
return new EnsPlugin(this.address, this.targetNetwork); return new EnsPlugin(this.address, this.targetNetwork);
} }
// validate(network: Network): this {
// network.formatter.address(this.address);
// return this;
// }
}
/*
export class MaxPriorityFeePlugin extends NetworkPlugin {
readonly priorityFee!: bigint;
constructor(priorityFee: BigNumberish) {
super("org.ethers.plugins.max-priority-fee");
defineProperties<MaxPriorityFeePlugin>(this, {
priorityFee: logger.getBigInt(priorityFee)
});
} }
async getPriorityFee(provider: Provider): Promise<bigint> {
return this.priorityFee;
}
clone(): MaxPriorityFeePlugin {
return new MaxPriorityFeePlugin(this.priorityFee);
}
}
*/
export class FeeDataNetworkPlugin extends NetworkPlugin { export class FeeDataNetworkPlugin extends NetworkPlugin {
readonly #feeDataFunc: (provider: Provider) => Promise<FeeData>; readonly #feeDataFunc: (provider: Provider) => Promise<FeeData>;
get feeDataFunc(): (provider: Provider) => Promise<FeeData> { return this.#feeDataFunc; } get feeDataFunc(): (provider: Provider) => Promise<FeeData> {
return this.#feeDataFunc;
}
constructor(feeDataFunc: (provider: Provider) => Promise<FeeData>) { constructor(feeDataFunc: (provider: Provider) => Promise<FeeData>) {
super("org.ethers.network-plugins.fee-data"); super("org.ethers.plugins.network.FeeData");
this.#feeDataFunc = feeDataFunc; this.#feeDataFunc = feeDataFunc;
} }
@ -140,6 +118,7 @@ export class FeeDataNetworkPlugin extends NetworkPlugin {
return new FeeDataNetworkPlugin(this.#feeDataFunc); return new FeeDataNetworkPlugin(this.#feeDataFunc);
} }
} }
/* /*
export class CustomBlockNetworkPlugin extends NetworkPlugin { export class CustomBlockNetworkPlugin extends NetworkPlugin {
readonly #blockFunc: (provider: Provider, block: BlockParams<string>) => Block<string>; readonly #blockFunc: (provider: Provider, block: BlockParams<string>) => Block<string>;

@ -48,7 +48,7 @@ export type DebugEventEtherscanProvider = {
error: any error: any
}; };
const EtherscanPluginId = "org.ethers.plugins.Etherscan"; const EtherscanPluginId = "org.ethers.plugins.provider.Etherscan";
/** /**
* A Network can include an **EtherscanPlugin** to provide * A Network can include an **EtherscanPlugin** to provide