avax

package
v1.10.15 Latest Latest
Warning

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

Go to latest
Published: Dec 8, 2023 License: BSD-3-Clause Imports: 29 Imported by: 54

Documentation

Overview

Package avax is a generated GoMock package.

Package avax is a generated GoMock package.

Index

Constants

View Source
const MaxMemoSize = 256

MaxMemoSize is the maximum number of bytes in the memo field

Variables

View Source
var (
	ErrNilTx          = errors.New("nil tx is not valid")
	ErrWrongNetworkID = errors.New("tx has wrong network ID")
	ErrWrongChainID   = errors.New("tx has wrong chain ID")
	ErrMemoTooLarge   = errors.New("memo exceeds maximum length")
)
View Source
var (
	ErrNilTransferableOutput   = errors.New("nil transferable output is not valid")
	ErrNilTransferableFxOutput = errors.New("nil transferable feature extension output is not valid")
	ErrOutputsNotSorted        = errors.New("outputs not sorted")

	ErrNilTransferableInput   = errors.New("nil transferable input is not valid")
	ErrNilTransferableFxInput = errors.New("nil transferable feature extension input is not valid")
	ErrInputsNotSortedUnique  = errors.New("inputs not sorted and unique")
)
View Source
var ErrInsufficientFunds = errors.New("insufficient funds")
View Source
var (
	ErrMismatchedChainIDs = errors.New("mismatched chainIDs")
)

Functions

func Consume added in v1.9.10

func Consume(utxoDB UTXODeleter, ins []*TransferableInput)

Removes the UTXOs consumed by [ins] from the UTXO set

func GetBalance

func GetBalance(db UTXOReader, addrs set.Set[ids.ShortID]) (uint64, error)

GetBalance returns the current balance of [addrs]

func IsSortedTransferableOutputs

func IsSortedTransferableOutputs(outs []*TransferableOutput, c codec.Manager) bool

IsSortedTransferableOutputs returns true if output objects are sorted

func ParseLocalAddresses

func ParseLocalAddresses(a AddressManager, addrStrs []string) (set.Set[ids.ShortID], error)

func ParseServiceAddress added in v1.8.4

func ParseServiceAddress(a AddressManager, addrStr string) (ids.ShortID, error)

ParseServiceAddress get address ID from address string, being it either localized (using address manager, doing also components validations), or not localized. If both attempts fail, reports error from localized address parsing

func ParseServiceAddresses added in v1.8.4

func ParseServiceAddresses(a AddressManager, addrStrs []string) (set.Set[ids.ShortID], error)

ParseServiceAddress get addresses IDs from addresses strings, being them either localized or not

func Produce added in v1.9.10

func Produce(
	utxoDB UTXOAdder,
	txID ids.ID,
	outs []*TransferableOutput,
)

Adds the UTXOs created by [outs] to the UTXO set. [txID] is the ID of the tx that created [outs].

func SortTransferableInputsWithSigners

func SortTransferableInputsWithSigners(ins []*TransferableInput, signers [][]*secp256k1.PrivateKey)

SortTransferableInputsWithSigners sorts the inputs and signers based on the input's utxo ID

func SortTransferableOutputs

func SortTransferableOutputs(outs []*TransferableOutput, c codec.Manager)

SortTransferableOutputs sorts output objects

func VerifyTx

func VerifyTx(
	feeAmount uint64,
	feeAssetID ids.ID,
	allIns [][]*TransferableInput,
	allOuts [][]*TransferableOutput,
	c codec.Manager,
) error

VerifyTx verifies that the inputs and outputs flowcheck, including a fee. Additionally, this verifies that the inputs and outputs are sorted.

Types

type AddressManager

type AddressManager interface {
	// ParseLocalAddress takes in an address for this chain and produces the ID
	ParseLocalAddress(addrStr string) (ids.ShortID, error)

	// ParseAddress takes in an address and produces the ID of the chain it's
	// for and the ID of the address
	ParseAddress(addrStr string) (ids.ID, ids.ShortID, error)

	// FormatLocalAddress takes in a raw address and produces the formatted
	// address for this chain
	FormatLocalAddress(addr ids.ShortID) (string, error)

	// FormatAddress takes in a chainID and a raw address and produces the
	// formatted address for that chain
	FormatAddress(chainID ids.ID, addr ids.ShortID) (string, error)
}

func NewAddressManager

func NewAddressManager(ctx *snow.Context) AddressManager

type Addressable

type Addressable interface {
	Addresses() [][]byte
}

Addressable is the interface a feature extension must provide to be able to be tracked as a part of the utxo set for a set of addresses

type Amounter

type Amounter interface {
	snow.ContextInitializable
	// Amount returns how much value this element represents of the asset in its
	// transaction.
	Amount() uint64
}

Amounter is a data structure that has an amount of something associated with it

type Asset

type Asset struct {
	ID ids.ID `serialize:"true" json:"assetID"`
}

func (*Asset) AssetID

func (asset *Asset) AssetID() ids.ID

AssetID returns the ID of the contained asset

func (*Asset) Verify

func (asset *Asset) Verify() error

type AtomicUTXOManager

type AtomicUTXOManager interface {
	// GetAtomicUTXOs returns exported UTXOs such that at least one of the
	// addresses in [addrs] is referenced.
	//
	// Returns at most [limit] UTXOs.
	//
	// Returns:
	// * The fetched UTXOs
	// * The address associated with the last UTXO fetched
	// * The ID of the last UTXO fetched
	// * Any error that may have occurred upstream.
	GetAtomicUTXOs(
		chainID ids.ID,
		addrs set.Set[ids.ShortID],
		startAddr ids.ShortID,
		startUTXOID ids.ID,
		limit int,
	) ([]*UTXO, ids.ShortID, ids.ID, error)
}

func NewAtomicUTXOManager

func NewAtomicUTXOManager(sm atomic.SharedMemory, codec codec.Manager) AtomicUTXOManager

type BaseTx

type BaseTx struct {
	NetworkID    uint32                `serialize:"true" json:"networkID"`    // ID of the network this chain lives on
	BlockchainID ids.ID                `serialize:"true" json:"blockchainID"` // ID of the chain on which this transaction exists (prevents replay attacks)
	Outs         []*TransferableOutput `serialize:"true" json:"outputs"`      // The outputs of this transaction
	Ins          []*TransferableInput  `serialize:"true" json:"inputs"`       // The inputs to this transaction
	Memo         types.JSONByteSlice   `serialize:"true" json:"memo"`         // Memo field contains arbitrary bytes, up to maxMemoSize
}

BaseTx is the basis of all standard transactions.

func (*BaseTx) InputUTXOs

func (t *BaseTx) InputUTXOs() []*UTXOID

InputUTXOs track which UTXOs this transaction is consuming.

func (*BaseTx) NumCredentials

func (t *BaseTx) NumCredentials() int

NumCredentials returns the number of expected credentials

func (*BaseTx) Verify added in v1.8.4

func (t *BaseTx) Verify(ctx *snow.Context) error

Verify ensures that transaction metadata is valid

type Coster

type Coster interface {
	// Cost returns how much this element costs to be included in its
	// transaction.
	Cost() (uint64, error)
}

Coster is a data structure that has a cost associated with it

type FlowChecker

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

func NewFlowChecker

func NewFlowChecker() *FlowChecker

func (*FlowChecker) Consume

func (fc *FlowChecker) Consume(assetID ids.ID, amount uint64)

func (*FlowChecker) Produce

func (fc *FlowChecker) Produce(assetID ids.ID, amount uint64)

func (*FlowChecker) Verify

func (fc *FlowChecker) Verify() error

type Metadata

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

TODO: Delete this once the downstream dependencies have been updated.

func (*Metadata) Bytes

func (md *Metadata) Bytes() []byte

UnsignedBytes returns the unsigned binary representation of this data

func (*Metadata) ID

func (md *Metadata) ID() ids.ID

ID returns the unique ID of this data

func (*Metadata) Initialize

func (md *Metadata) Initialize(unsignedBytes, bytes []byte)

Initialize set the bytes and ID

func (*Metadata) SignedBytes added in v1.8.4

func (md *Metadata) SignedBytes() []byte

Bytes returns the binary representation of this data

func (*Metadata) Verify

func (md *Metadata) Verify() error

type MockTransferableIn added in v1.9.3

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

MockTransferableIn is a mock of TransferableIn interface.

func NewMockTransferableIn added in v1.9.3

func NewMockTransferableIn(ctrl *gomock.Controller) *MockTransferableIn

NewMockTransferableIn creates a new mock instance.

func (*MockTransferableIn) Amount added in v1.9.3

func (m *MockTransferableIn) Amount() uint64

Amount mocks base method.

func (*MockTransferableIn) Cost added in v1.9.3

func (m *MockTransferableIn) Cost() (uint64, error)

Cost mocks base method.

func (*MockTransferableIn) EXPECT added in v1.9.3

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockTransferableIn) InitCtx added in v1.9.3

func (m *MockTransferableIn) InitCtx(arg0 *snow.Context)

InitCtx mocks base method.

func (*MockTransferableIn) Verify added in v1.9.3

func (m *MockTransferableIn) Verify() error

Verify mocks base method.

type MockTransferableInMockRecorder added in v1.9.3

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

MockTransferableInMockRecorder is the mock recorder for MockTransferableIn.

func (*MockTransferableInMockRecorder) Amount added in v1.9.3

Amount indicates an expected call of Amount.

func (*MockTransferableInMockRecorder) Cost added in v1.9.3

Cost indicates an expected call of Cost.

func (*MockTransferableInMockRecorder) InitCtx added in v1.9.3

func (mr *MockTransferableInMockRecorder) InitCtx(arg0 interface{}) *gomock.Call

InitCtx indicates an expected call of InitCtx.

func (*MockTransferableInMockRecorder) Verify added in v1.9.3

Verify indicates an expected call of Verify.

type MockTransferableOut added in v1.8.4

type MockTransferableOut struct {
	verify.IsState
	// contains filtered or unexported fields
}

MockTransferableOut is a mock of TransferableOut interface.

func NewMockTransferableOut added in v1.8.4

func NewMockTransferableOut(ctrl *gomock.Controller) *MockTransferableOut

NewMockTransferableOut creates a new mock instance.

func (*MockTransferableOut) Amount added in v1.8.4

func (m *MockTransferableOut) Amount() uint64

Amount mocks base method.

func (*MockTransferableOut) EXPECT added in v1.8.4

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockTransferableOut) InitCtx added in v1.8.4

func (m *MockTransferableOut) InitCtx(arg0 *snow.Context)

InitCtx mocks base method.

func (*MockTransferableOut) Verify added in v1.8.4

func (m *MockTransferableOut) Verify() error

Verify mocks base method.

type MockTransferableOutMockRecorder added in v1.8.4

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

MockTransferableOutMockRecorder is the mock recorder for MockTransferableOut.

func (*MockTransferableOutMockRecorder) Amount added in v1.8.4

Amount indicates an expected call of Amount.

func (*MockTransferableOutMockRecorder) InitCtx added in v1.8.4

func (mr *MockTransferableOutMockRecorder) InitCtx(arg0 interface{}) *gomock.Call

InitCtx indicates an expected call of InitCtx.

func (*MockTransferableOutMockRecorder) Verify added in v1.8.4

Verify indicates an expected call of Verify.

type TestAddressable

type TestAddressable struct {
	TestTransferable `serialize:"true"`

	Addrs [][]byte `serialize:"true"`
}

func (*TestAddressable) Addresses

func (a *TestAddressable) Addresses() [][]byte

type TestState added in v1.10.3

type TestState struct {
	verify.IsState `json:"-"`

	Err error
}

func (*TestState) InitCtx added in v1.10.3

func (*TestState) InitCtx(*snow.Context)

func (*TestState) Verify added in v1.10.3

func (v *TestState) Verify() error

type TestTransferable

type TestTransferable struct {
	TestState

	Val uint64 `serialize:"true"`
}

func (*TestTransferable) Amount

func (t *TestTransferable) Amount() uint64

func (*TestTransferable) Cost

func (*TestTransferable) Cost() (uint64, error)

func (*TestTransferable) InitCtx

func (*TestTransferable) InitCtx(*snow.Context)

type TransferableIn

type TransferableIn interface {
	verify.Verifiable
	Amounter
	Coster
}

TransferableIn is the interface a feature extension must provide to transfer value between features extensions.

type TransferableInput

type TransferableInput struct {
	UTXOID `serialize:"true"`
	Asset  `serialize:"true"`
	// FxID has serialize false because we don't want this to be encoded in bytes
	FxID ids.ID         `serialize:"false" json:"fxID"`
	In   TransferableIn `serialize:"true"  json:"input"`
}

func (*TransferableInput) Input

func (in *TransferableInput) Input() TransferableIn

Input returns the feature extension input that this Input is using.

func (*TransferableInput) Less added in v1.9.4

func (in *TransferableInput) Less(other *TransferableInput) bool

func (*TransferableInput) Verify

func (in *TransferableInput) Verify() error

type TransferableOut

type TransferableOut interface {
	snow.ContextInitializable
	verify.State
	Amounter
}

TransferableOut is the interface a feature extension must provide to transfer value between features extensions.

type TransferableOutput

type TransferableOutput struct {
	Asset `serialize:"true"`
	// FxID has serialize false because we don't want this to be encoded in bytes
	FxID ids.ID          `serialize:"false" json:"fxID"`
	Out  TransferableOut `serialize:"true"  json:"output"`
}

func (*TransferableOutput) InitCtx

func (out *TransferableOutput) InitCtx(ctx *snow.Context)

func (*TransferableOutput) Output

func (out *TransferableOutput) Output() TransferableOut

Output returns the feature extension output that this Output is using.

func (*TransferableOutput) Verify

func (out *TransferableOutput) Verify() error

type UTXO

type UTXO struct {
	UTXOID `serialize:"true"`
	Asset  `serialize:"true"`

	Out verify.State `serialize:"true" json:"output"`
}

func GetAllUTXOs

func GetAllUTXOs(db UTXOReader, addrs set.Set[ids.ShortID]) ([]*UTXO, error)

func GetPaginatedUTXOs

func GetPaginatedUTXOs(
	db UTXOReader,
	addrs set.Set[ids.ShortID],
	lastAddr ids.ShortID,
	lastUTXOID ids.ID,
	limit int,
) ([]*UTXO, ids.ShortID, ids.ID, error)

GetPaginatedUTXOs returns UTXOs such that at least one of the addresses in [addrs] is referenced.

Returns at most [limit] UTXOs.

Only returns UTXOs associated with addresses >= [startAddr].

For address [startAddr], only returns UTXOs whose IDs are greater than [startUTXOID].

Returns: * The fetched UTXOs * The address associated with the last UTXO fetched * The ID of the last UTXO fetched

func (*UTXO) Verify

func (utxo *UTXO) Verify() error

type UTXOAdder added in v1.9.10

type UTXOAdder interface {
	AddUTXO(utxo *UTXO)
}

type UTXODeleter added in v1.9.10

type UTXODeleter interface {
	DeleteUTXO(utxoID ids.ID)
}

type UTXOGetter

type UTXOGetter interface {
	// GetUTXO attempts to load a utxo.
	GetUTXO(utxoID ids.ID) (*UTXO, error)
}

UTXOGetter is a thin wrapper around a database to provide fetching of a UTXO.

type UTXOID

type UTXOID struct {
	// Serialized:
	TxID        ids.ID `serialize:"true" json:"txID"`
	OutputIndex uint32 `serialize:"true" json:"outputIndex"`

	// Symbol is false if the UTXO should be part of the DB
	Symbol bool `json:"-"`
	// contains filtered or unexported fields
}

func UTXOIDFromString added in v1.9.3

func UTXOIDFromString(s string) (*UTXOID, error)

UTXOIDFromString attempts to parse a string into a UTXOID

func (*UTXOID) InputID

func (utxo *UTXOID) InputID() ids.ID

InputID returns a unique ID of the UTXO that this input is spending

func (*UTXOID) InputSource

func (utxo *UTXOID) InputSource() (ids.ID, uint32)

InputSource returns the source of the UTXO that this input is spending

func (*UTXOID) Less added in v1.9.4

func (utxo *UTXOID) Less(other *UTXOID) bool

func (*UTXOID) String

func (utxo *UTXOID) String() string

func (*UTXOID) Symbolic

func (utxo *UTXOID) Symbolic() bool

Symbolic returns if this is the ID of a UTXO in the DB, or if it is a symbolic input

func (*UTXOID) Verify

func (utxo *UTXOID) Verify() error

type UTXOReader

type UTXOReader interface {
	UTXOGetter

	// UTXOIDs returns the slice of IDs associated with [addr], starting after
	// [previous].
	// If [previous] is not in the list, starts at beginning.
	// Returns at most [limit] IDs.
	UTXOIDs(addr []byte, previous ids.ID, limit int) ([]ids.ID, error)
}

UTXOReader is a thin wrapper around a database to provide fetching of UTXOs.

type UTXOState

type UTXOState interface {
	UTXOReader
	UTXOWriter

	// Checksum returns the current UTXOChecksum.
	Checksum() ids.ID
}

UTXOState is a thin wrapper around a database to provide, caching, serialization, and de-serialization for UTXOs.

func NewMeteredUTXOState

func NewMeteredUTXOState(
	db database.Database,
	codec codec.Manager,
	metrics prometheus.Registerer,
	trackChecksum bool,
) (UTXOState, error)

func NewUTXOState

func NewUTXOState(
	db database.Database,
	codec codec.Manager,
	trackChecksum bool,
) (UTXOState, error)

type UTXOWriter

type UTXOWriter interface {
	// PutUTXO saves the provided utxo to storage.
	PutUTXO(utxo *UTXO) error

	// DeleteUTXO deletes the provided utxo.
	DeleteUTXO(utxoID ids.ID) error
}

UTXOWriter is a thin wrapper around a database to provide storage and deletion of UTXOs.

Jump to

Keyboard shortcuts

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