Commit 7a179003 authored by smartcontracts's avatar smartcontracts Committed by GitHub

feat(cmn): add JsonRpcProvider validator (#2379)

Adds a new JsonRpcProvider validator which specifically parses the input
type into a JsonRpcProvider instead of a generic provider.
Co-authored-by: default avatarmergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
parent ff8c632a
---
'@eth-optimism/common-ts': patch
---
Adds the jsonRpcProvider validator as an input validator
......@@ -18,6 +18,19 @@ const provider = makeValidator<Provider>((input) => {
return new ethers.providers.JsonRpcProvider(parsed)
})
const jsonRpcProvider = makeValidator<ethers.providers.JsonRpcProvider>(
(input) => {
const parsed = url()._parse(input)
return new ethers.providers.JsonRpcProvider(parsed)
}
)
const staticJsonRpcProvider =
makeValidator<ethers.providers.StaticJsonRpcProvider>((input) => {
const parsed = url()._parse(input)
return new ethers.providers.StaticJsonRpcProvider(parsed)
})
const wallet = makeValidator<Signer>((input) => {
if (!ethers.utils.isHexString(input)) {
throw new Error(`expected wallet to be a hex string`)
......@@ -37,4 +50,6 @@ export const validators = {
json,
wallet,
provider,
jsonRpcProvider,
staticJsonRpcProvider,
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment