Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add state override error types #1776

Merged
merged 1 commit into from
Feb 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/five-bugs-bathe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"viem": patch
---

Added missing state override error types.
25 changes: 23 additions & 2 deletions src/actions/public/call.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ import type { Client } from '../../clients/createClient.js'
import type { Transport } from '../../clients/transports/createTransport.js'
import { multicall3Abi } from '../../constants/abis.js'
import { aggregate3Signature } from '../../constants/contract.js'
import { InvalidAddressError } from '../../errors/address.js'
import {
InvalidAddressError,
type InvalidAddressErrorType,
} from '../../errors/address.js'
import { BaseError } from '../../errors/base.js'
import {
ChainDoesNotSupportContract,
Expand All @@ -19,10 +22,15 @@ import {
RawContractError,
type RawContractErrorType,
} from '../../errors/contract.js'
import { InvalidBytesLengthError } from '../../errors/data.js'
import {
InvalidBytesLengthError,
type InvalidBytesLengthErrorType,
} from '../../errors/data.js'
import {
AccountStateConflictError,
type AccountStateConflictErrorType,
StateAssignmentConflictError,
type StateAssignmentConflictErrorType,
} from '../../errors/stateOverride.js'
import type { ErrorType } from '../../errors/utils.js'
import type { BlockTag } from '../../types/block.js'
Expand Down Expand Up @@ -106,6 +114,7 @@ export type CallReturnType = { data: Hex | undefined }

export type CallErrorType = GetCallErrorReturnType<
| ParseAccountErrorType
| ParseStateOverrideErrorType
| AssertRequestErrorType
| NumberToHexErrorType
| FormatTransactionRequestErrorType
Expand Down Expand Up @@ -350,6 +359,8 @@ export function getRevertErrorData(err: unknown) {
return typeof error.data === 'object' ? error.data.data : error.data
}

export type ParseStateMappingErrorType = InvalidBytesLengthErrorType

export function parseStateMapping(
stateMapping: StateMapping | undefined,
): RpcStateMapping | undefined {
Expand All @@ -372,6 +383,11 @@ export function parseStateMapping(
}, {} as RpcStateMapping)
}

export type ParseAccountStateOverrideErrorType =
| NumberToHexErrorType
| StateAssignmentConflictErrorType
| ParseStateMappingErrorType

export function parseAccountStateOverride(
args: Omit<StateOverride[number], 'address'>,
): RpcAccountStateOverride {
Expand All @@ -396,6 +412,11 @@ export function parseAccountStateOverride(
return rpcAccountStateOverride
}

export type ParseStateOverrideErrorType =
| InvalidAddressErrorType
| AccountStateConflictErrorType
| ParseAccountStateOverrideErrorType

export function parseStateOverride(
args?: StateOverride,
): RpcStateOverride | undefined {
Expand Down
Loading