Help us shape the future of Go! Take the 2026 Go Developer Survey

types

package
v0.7.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 18, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package types holds shared SDK domain types used across service packages.

Boundary discipline:

  • Only pure data types (structs, named primitives) and sentinel errors belong here.
  • No business logic, no helpers, no service glue.
  • Imports stay minimal and must not include service packages, because service imports from types must remain acyclic.

This package exists so every service can share the same vocabulary (WriteResult, BigInt, ...) without cross-importing each other's service package.

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidListOptions = errors.New("invalid list options")

ErrInvalidListOptions is returned when ListOptions values are out of range. It is exposed so callers can assert on the class of error without depending on a specific service package.

View Source
var ErrReceiptRPCFailure = txutil.ErrReceiptRPCFailure

ErrReceiptRPCFailure reports an RPC failure that cannot be retried or exhausted the receipt wait's consecutive error budget. The error preserves the RPC cause.

View Source
var ErrReceiptTimeout = txutil.ErrReceiptTimeout

ErrReceiptTimeout reports that the receipt wait or its parent context reached its deadline. Returned wait errors also match context.DeadlineExceeded.

View Source
var ErrTxFailed = txutil.ErrTxFailed

ErrTxFailed is the canonical sentinel reported when a transaction is mined but its receipt status is not successful (reverted or out-of-gas on-chain). Use errors.Is to match errors returned by any state-changing call in the SDK.

Service packages (payments, sessionkey, ...) provide convenience aliases to this sentinel; they are all the same error value.

Functions

This section is empty.

Types

type BigInt added in v0.2.0

type BigInt struct {
	// contains filtered or unexported fields
}

BigInt holds a uint256 value used by on-chain identifiers. Use Equal or Cmp for numeric comparisons.

func BigIntFromBig added in v0.2.0

func BigIntFromBig(v *big.Int) (BigInt, error)

BigIntFromBig returns a BigInt after validating that v is a uint256.

func NewBigInt added in v0.2.0

func NewBigInt(v uint64) BigInt

NewBigInt returns a BigInt from a uint64 value.

func ParseBigInt added in v0.2.0

func ParseBigInt(s string) (BigInt, error)

ParseBigInt parses a decimal uint256.

func (BigInt) Big added in v0.2.0

func (id BigInt) Big() *big.Int

Big returns a defensive copy of id.

func (BigInt) Bytes32 added in v0.2.0

func (id BigInt) Bytes32() [32]byte

Bytes32 returns id as a 32-byte big-endian uint256 value.

func (BigInt) Cmp added in v0.2.0

func (id BigInt) Cmp(other BigInt) int

Cmp compares id and other.

func (BigInt) Copy added in v0.2.0

func (id BigInt) Copy() BigInt

Copy returns an independent copy of id.

func (BigInt) Equal added in v0.2.0

func (id BigInt) Equal(other BigInt) bool

Equal reports whether id and other hold the same numeric value.

func (BigInt) IsZero added in v0.2.0

func (id BigInt) IsZero() bool

IsZero reports whether id is zero.

func (BigInt) MarshalJSON added in v0.2.0

func (id BigInt) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler.

func (BigInt) MarshalText added in v0.2.0

func (id BigInt) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler.

func (BigInt) String added in v0.2.0

func (id BigInt) String() string

String returns the decimal form of id.

func (BigInt) Uint64 added in v0.2.0

func (id BigInt) Uint64() (uint64, bool)

Uint64 returns id as uint64 when it fits.

func (*BigInt) UnmarshalJSON added in v0.2.0

func (id *BigInt) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler.

func (*BigInt) UnmarshalText added in v0.2.0

func (id *BigInt) UnmarshalText(text []byte) error

UnmarshalText implements encoding.TextUnmarshaler.

type BroadcastError added in v0.7.0

type BroadcastError struct {
	Transaction *ethtypes.Transaction
	Cause       error
}

BroadcastError reports an error returned while sending a signed transaction. It does not establish whether the node rejected or accepted the transaction. SDK-originated errors always contain Transaction and Cause. Use errors.AsType to recover the original transaction for lookup or resubmission; do not retry the business operation merely because its WriteResult is nil.

func (*BroadcastError) Error added in v0.7.0

func (e *BroadcastError) Error() string

func (*BroadcastError) Unwrap added in v0.7.0

func (e *BroadcastError) Unwrap() error

Unwrap preserves the original send error for errors.Is and errors.AsType.

type ChainID

type ChainID int64

ChainID is an EIP-155 chain identifier exposed at the SDK public boundary instead of the bare *big.Int used by go-ethereum. The newtype keeps callers honest about units (raw uint256 chain ids fit easily in int64 for every deployed EVM chain) and avoids silently accepting mutable *big.Int pointers across package boundaries.

The zero value is not a valid chain id; use IsValid to check.

func (ChainID) BigInt

func (c ChainID) BigInt() *big.Int

BigInt returns a freshly-allocated *big.Int for consumers (contract bindings, EIP-712 domain separators) that still require the legacy representation. The returned pointer is owned by the caller.

func (ChainID) Int64

func (c ChainID) Int64() int64

Int64 returns the chain id as an int64.

func (ChainID) IsValid

func (c ChainID) IsValid() bool

IsValid reports whether the chain id is a positive EIP-155 identifier.

type Epoch

type Epoch uint64

Epoch is a Filecoin chain epoch number. Zero is the valid "indefinite" sentinel in several warm-storage fields.

type ListOptions

type ListOptions struct {
	Offset uint64
	Limit  uint64
}

ListOptions configures a paginated list call.

Limit must be > 0. The zero value is rejected as a programming error: different services/contracts disagree on what "Limit == 0" means (some treat it as "all remaining", others as a default page size), so callers must be explicit.

When you want to iterate every record regardless of page size, use the service's IterateAll* method instead of trying to encode "no cap" via ListOptions.

func (ListOptions) Validate

func (o ListOptions) Validate() error

Validate returns ErrInvalidListOptions when Limit is not > 0.

type WriteResult

type WriteResult struct {
	Hash    common.Hash
	Receipt *ethtypes.Receipt
}

WriteResult is returned by every state-changing call in the SDK.

Hash is always populated when WriteResult is non-nil — it is set as soon as the transaction is broadcast. Receipt is populated only when the call was made with a wait option (e.g. WithWait(timeout)) and the transaction was mined and reached any requested confirmation count before the wait ended. Explicit confirmations apply to both successful and failed receipts, counting the inclusion block as the first confirmation.

Error semantics (observe WriteResult and err together):

  • WriteResult == nil, err != nil: no successful submission result is available. When sending returned an error, err wraps BroadcastError, which preserves the original signed transaction. A nil result does not establish that the node rejected the transaction; do not blindly retry the business operation with a new transaction.
  • WriteResult != nil, err == nil: transaction was broadcast successfully. Without a wait option, Receipt is nil. With a wait option, Receipt is non-nil and Status == 1 (successful execution).
  • WriteResult != nil, err != nil, Receipt == nil: the wait timed out before a terminal receipt was returned, was canceled, or receipt lookup failed. This includes both "not mined yet" and "already mined, but the configured confirmation count has not been satisfied yet". Hash is valid; callers can keep polling by Hash. Use errors.Is with ErrReceiptTimeout, ErrReceiptRPCFailure, or context.Canceled to distinguish these outcomes; RPC causes are preserved.
  • WriteResult != nil, err != nil, Receipt != nil: transaction was mined but execution reverted. err wraps ErrTxFailed (use errors.Is). Receipt carries the failed status and any logs emitted before revert.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL