-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6119 from NomicFoundation/network-plugin-cleanup
Network plugin cleanup
- Loading branch information
Showing
37 changed files
with
477 additions
and
426 deletions.
There are no files selected for viewing
16 changes: 16 additions & 0 deletions
16
v-next/hardhat/src/internal/builtin-plugins/network-manager/accounts/constants.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import type { SensitiveString } from "../../../../types/config.js"; | ||
|
||
export interface DefaultHDAccountsConfigParams { | ||
initialIndex: number; | ||
count: number; | ||
path: string; | ||
passphrase: SensitiveString; | ||
} | ||
|
||
export const DEFAULT_HD_ACCOUNTS_CONFIG_PARAMS: DefaultHDAccountsConfigParams = | ||
{ | ||
initialIndex: 0, | ||
count: 20, | ||
path: "m/44'/60'/0'/0", | ||
passphrase: "", | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
v-next/hardhat/src/internal/builtin-plugins/network-manager/base-provider.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import type { | ||
EthereumProvider, | ||
JsonRpcRequest, | ||
JsonRpcResponse, | ||
RequestArguments, | ||
SuccessfulJsonRpcResponse, | ||
} from "../../../types/providers.js"; | ||
|
||
import EventEmitter from "node:events"; | ||
import util from "node:util"; | ||
|
||
import { ensureError } from "@ignored/hardhat-vnext-utils/error"; | ||
|
||
export abstract class BaseProvider | ||
extends EventEmitter | ||
implements EthereumProvider | ||
{ | ||
public abstract request( | ||
requestArguments: RequestArguments, | ||
): Promise<SuccessfulJsonRpcResponse["result"]>; | ||
public abstract close(): Promise<void>; | ||
|
||
public send( | ||
method: string, | ||
params?: unknown[], | ||
): Promise<SuccessfulJsonRpcResponse["result"]> { | ||
return this.request({ method, params }); | ||
} | ||
|
||
public sendAsync( | ||
jsonRpcRequest: JsonRpcRequest, | ||
callback: (error: any, jsonRpcResponse: JsonRpcResponse) => void, | ||
): void { | ||
const handleJsonRpcRequest = async () => { | ||
let jsonRpcResponse: JsonRpcResponse; | ||
try { | ||
const result = await this.request({ | ||
method: jsonRpcRequest.method, | ||
params: jsonRpcRequest.params, | ||
}); | ||
jsonRpcResponse = { | ||
jsonrpc: "2.0", | ||
id: jsonRpcRequest.id, | ||
result, | ||
}; | ||
} catch (error) { | ||
ensureError(error); | ||
|
||
if (!("code" in error) || error.code === undefined) { | ||
throw error; | ||
} | ||
|
||
/* eslint-disable-next-line @typescript-eslint/restrict-template-expressions | ||
-- Allow string interpolation of unknown `error.code`. It will be converted | ||
to a number, and we will handle NaN cases appropriately afterwards. */ | ||
const errorCode = parseInt(`${error.code}`, 10); | ||
jsonRpcResponse = { | ||
jsonrpc: "2.0", | ||
id: jsonRpcRequest.id, | ||
error: { | ||
code: !isNaN(errorCode) ? errorCode : -1, | ||
message: error.message, | ||
data: { | ||
stack: error.stack, | ||
name: error.name, | ||
}, | ||
}, | ||
}; | ||
} | ||
|
||
return jsonRpcResponse; | ||
}; | ||
|
||
util.callbackify(handleJsonRpcRequest)(callback); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
v-next/hardhat/src/internal/builtin-plugins/network-manager/edr/edr-context.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { | ||
EdrContext, | ||
GENERIC_CHAIN_TYPE, | ||
genericChainProviderFactory, | ||
L1_CHAIN_TYPE, | ||
l1ProviderFactory, | ||
OPTIMISM_CHAIN_TYPE, | ||
optimismProviderFactory, | ||
} from "@ignored/edr-optimism"; | ||
|
||
let _globalEdrContext: EdrContext | undefined; | ||
|
||
export async function getGlobalEdrContext(): Promise<EdrContext> { | ||
if (_globalEdrContext === undefined) { | ||
_globalEdrContext = new EdrContext(); | ||
await _globalEdrContext.registerProviderFactory( | ||
GENERIC_CHAIN_TYPE, | ||
genericChainProviderFactory(), | ||
); | ||
await _globalEdrContext.registerProviderFactory( | ||
L1_CHAIN_TYPE, | ||
l1ProviderFactory(), | ||
); | ||
await _globalEdrContext.registerProviderFactory( | ||
OPTIMISM_CHAIN_TYPE, | ||
optimismProviderFactory(), | ||
); | ||
} | ||
|
||
return _globalEdrContext; | ||
} |
Oops, something went wrong.