utxo

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2024 License: BSD-3-Clause Imports: 23 Imported by: 0

Documentation

Overview

Package utxo is a generated GoMock package.

Package utxo is a generated GoMock package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ProduceLocked

func ProduceLocked(
	utxoDB avax.UTXOAdder,
	txID ids.ID,
	outs []*avax.TransferableOutput,
	appliedLockState locked.State,
) error

Creates UTXOs from [outs] and adds them to the UTXO set. UTXOs with LockedOut will have 'thisTxID' replaced with [txID]. [txID] is the ID of the tx that created [outs].

Types

type CaminoSpender

type CaminoSpender interface {
	// Lock the provided amount while deducting the provided fee.
	// Arguments:
	// - [keys] are the owners of the funds
	// - [totalAmountToLock] is the amount of funds that are trying to be locked with [appliedLockState]
	// - [totalAmountToBurn] is the amount of AVAX that should be burned
	// - [appliedLockState] state to set (except BondDeposit)
	// - [to] owner of unlocked amounts if appliedLockState is Unlocked
	// - [change] owner of unlocked amounts resulting from splittig inputs
	// - [asOf] timestamp against LockTime is compared
	// Returns:
	// - [inputs] the inputs that should be consumed to fund the outputs
	// - [outputs] the outputs that should be returned to the UTXO set
	// - [signers] the proof of ownership of the funds being moved
	// - [owners] the owners used for proof of ownership, used e.g. for multiSig
	Lock(
		utxoDB avax.UTXOReader,
		keys []*secp256k1.PrivateKey,
		totalAmountToLock uint64,
		totalAmountToBurn uint64,
		appliedLockState locked.State,
		to *secp256k1fx.OutputOwners,
		change *secp256k1fx.OutputOwners,
		asOf uint64,
	) (
		[]*avax.TransferableInput,
		[]*avax.TransferableOutput,
		[][]*secp256k1.PrivateKey,
		[]*secp256k1fx.OutputOwners,
		error,
	)

	// Undeposit all deposited by [depositTxIDs] utxos owned by [keys]. Returned results are unsorted.
	// Arguments:
	// - [state] chainstate which will be used to fetch utxos and deposit data
	// - [keys] are the owners of the deposits
	// - [depositTxIDs] ids of deposit transactions
	// Returns:
	// - [inputs] unsorted inputs that should be consumed to fund the outputs
	// - [outputs] unsorted outputs that should be returned to the UTXO set
	// - [signers] the unsorted proof of ownership of the funds being moved
	UnlockDeposit(
		state state.Chain,
		keys []*secp256k1.PrivateKey,
		depositTxIDs []ids.ID,
	) (
		[]*avax.TransferableInput,
		[]*avax.TransferableOutput,
		[][]*secp256k1.PrivateKey,
		error,
	)

	Unlocker
}

type CaminoVerifier

type CaminoVerifier interface {
	// Verify that lock [tx] is semantically valid.
	// Arguments:
	// - [ins] and [outs] are the inputs and outputs of [tx].
	// - [creds] are the credentials of [tx], which allow [ins] to be spent.
	// - [ins] must have at least ([mintedAmount] - [burnedAmount]) less than the [outs].
	// - [assetID] is id of allowed asset, ins/outs with other assets will return error
	// - [appliedLockState] are lockState that was applied to [ins] lockState to produce [outs]
	//
	// Precondition: [tx] has already been syntactically verified.
	VerifyLock(
		tx txs.UnsignedTx,
		utxoDB avax.UTXOGetter,
		ins []*avax.TransferableInput,
		outs []*avax.TransferableOutput,
		creds []verify.Verifiable,
		mintedAmount uint64,
		burnedAmount uint64,
		assetID ids.ID,
		appliedLockState locked.State,
	) error

	// Verify that deposit unlock [tx] is semantically valid.
	// Arguments:
	// - [ins] and [outs] are the inputs and outputs of [tx].
	// - [creds] are the credentials of [tx], which allow [ins] to be spent.
	// - [burnedAmount] if any of deposits are still active, then unlocked inputs must have at least [burnedAmount] more than unlocked outs.
	// - [assetID] is id of allowed asset, ins/outs with other assets will return error
	// - [verifyCreds] if false, [creds] will be ignored
	//
	// Precondition: [tx] has already been syntactically verified.
	VerifyUnlockDeposit(
		utxoDB avax.UTXOGetter,
		tx txs.UnsignedTx,
		ins []*avax.TransferableInput,
		outs []*avax.TransferableOutput,
		creds []verify.Verifiable,
		burnedAmount uint64,
		assetID ids.ID,
		verifyCreds bool,
	) error

	Unlocker
}

type Handler

type Handler interface {
	Spender
	Verifier
}

func NewCaminoHandler

func NewCaminoHandler(
	ctx *snow.Context,
	clk *mockable.Clock,
	fx fx.Fx,
	lockModeBondDeposit bool,
) Handler

func NewHandler

func NewHandler(
	ctx *snow.Context,
	clk *mockable.Clock,
	fx fx.Fx,
) Handler

type MockHandler

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

MockHandler is a mock of Handler interface.

func NewMockHandler

func NewMockHandler(ctrl *gomock.Controller) *MockHandler

NewMockHandler creates a new mock instance.

func (*MockHandler) Authorize

func (m *MockHandler) Authorize(arg0 state.Chain, arg1 ids.ID, arg2 []*secp256k1.PrivateKey) (verify.Verifiable, []*secp256k1.PrivateKey, error)

Authorize mocks base method.

func (*MockHandler) EXPECT

func (m *MockHandler) EXPECT() *MockHandlerMockRecorder

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

func (*MockHandler) Lock

Lock mocks base method.

func (*MockHandler) Spend

Spend mocks base method.

func (*MockHandler) Unlock

func (m *MockHandler) Unlock(arg0 state.Chain, arg1 []ids.ID, arg2 locked.State) ([]*avax.TransferableInput, []*avax.TransferableOutput, error)

Unlock mocks base method.

func (*MockHandler) UnlockDeposit

func (m *MockHandler) UnlockDeposit(arg0 state.Chain, arg1 []*secp256k1.PrivateKey, arg2 []ids.ID) ([]*avax.TransferableInput, []*avax.TransferableOutput, [][]*secp256k1.PrivateKey, error)

UnlockDeposit mocks base method.

func (*MockHandler) VerifyLock

func (m *MockHandler) VerifyLock(arg0 txs.UnsignedTx, arg1 avax.UTXOGetter, arg2 []*avax.TransferableInput, arg3 []*avax.TransferableOutput, arg4 []verify.Verifiable, arg5 uint64, arg6 ids.ID, arg7 locked.State) error

VerifyLock mocks base method.

func (*MockHandler) VerifySpend

func (m *MockHandler) VerifySpend(arg0 txs.UnsignedTx, arg1 avax.UTXOGetter, arg2 []*avax.TransferableInput, arg3 []*avax.TransferableOutput, arg4 []verify.Verifiable, arg5 map[ids.ID]uint64) error

VerifySpend mocks base method.

func (*MockHandler) VerifySpendUTXOs

func (m *MockHandler) VerifySpendUTXOs(arg0 txs.UnsignedTx, arg1 []*avax.UTXO, arg2 []*avax.TransferableInput, arg3 []*avax.TransferableOutput, arg4 []verify.Verifiable, arg5 map[ids.ID]uint64) error

VerifySpendUTXOs mocks base method.

func (*MockHandler) VerifyUnlockDeposit

func (m *MockHandler) VerifyUnlockDeposit(arg0 state.Chain, arg1 txs.UnsignedTx, arg2 []*avax.TransferableInput, arg3 []*avax.TransferableOutput, arg4 []verify.Verifiable, arg5 uint64, arg6 ids.ID) (map[ids.ID]uint64, error)

VerifyUnlockDeposit mocks base method.

type MockHandlerMockRecorder

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

MockHandlerMockRecorder is the mock recorder for MockHandler.

func (*MockHandlerMockRecorder) Authorize

func (mr *MockHandlerMockRecorder) Authorize(arg0, arg1, arg2 interface{}) *gomock.Call

Authorize indicates an expected call of Authorize.

func (*MockHandlerMockRecorder) Lock

func (mr *MockHandlerMockRecorder) Lock(arg0, arg1, arg2, arg3, arg4, arg5, arg6 interface{}) *gomock.Call

Lock indicates an expected call of Lock.

func (*MockHandlerMockRecorder) Spend

func (mr *MockHandlerMockRecorder) Spend(arg0, arg1, arg2, arg3 interface{}) *gomock.Call

Spend indicates an expected call of Spend.

func (*MockHandlerMockRecorder) Unlock

func (mr *MockHandlerMockRecorder) Unlock(arg0, arg1, arg2 interface{}) *gomock.Call

Unlock indicates an expected call of Unlock.

func (*MockHandlerMockRecorder) UnlockDeposit

func (mr *MockHandlerMockRecorder) UnlockDeposit(arg0, arg1, arg2 interface{}) *gomock.Call

UnlockDeposit indicates an expected call of UnlockDeposit.

func (*MockHandlerMockRecorder) VerifyLock

func (mr *MockHandlerMockRecorder) VerifyLock(arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7 interface{}) *gomock.Call

VerifyLock indicates an expected call of VerifyLock.

func (*MockHandlerMockRecorder) VerifySpend

func (mr *MockHandlerMockRecorder) VerifySpend(arg0, arg1, arg2, arg3, arg4, arg5 interface{}) *gomock.Call

VerifySpend indicates an expected call of VerifySpend.

func (*MockHandlerMockRecorder) VerifySpendUTXOs

func (mr *MockHandlerMockRecorder) VerifySpendUTXOs(arg0, arg1, arg2, arg3, arg4, arg5 interface{}) *gomock.Call

VerifySpendUTXOs indicates an expected call of VerifySpendUTXOs.

func (*MockHandlerMockRecorder) VerifyUnlockDeposit

func (mr *MockHandlerMockRecorder) VerifyUnlockDeposit(arg0, arg1, arg2, arg3, arg4, arg5, arg6 interface{}) *gomock.Call

VerifyUnlockDeposit indicates an expected call of VerifyUnlockDeposit.

type MockVerifier

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

MockVerifier is a mock of Verifier interface.

func NewMockVerifier

func NewMockVerifier(ctrl *gomock.Controller) *MockVerifier

NewMockVerifier creates a new mock instance.

func (*MockVerifier) EXPECT

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

func (*MockVerifier) Unlock

func (m *MockVerifier) Unlock(arg0 state.Chain, arg1 []ids.ID, arg2 locked.State) ([]*avax.TransferableInput, []*avax.TransferableOutput, error)

Unlock mocks base method.

func (*MockVerifier) VerifyLock

func (m *MockVerifier) VerifyLock(arg0 txs.UnsignedTx, arg1 avax.UTXOGetter, arg2 []*avax.TransferableInput, arg3 []*avax.TransferableOutput, arg4 []verify.Verifiable, arg5 uint64, arg6 uint64, arg7 ids.ID, arg8 locked.State) error

VerifyLock mocks base method.

func (*MockVerifier) VerifySpend

func (m *MockVerifier) VerifySpend(arg0 txs.UnsignedTx, arg1 avax.UTXOGetter, arg2 []*avax.TransferableInput, arg3 []*avax.TransferableOutput, arg4 []verify.Verifiable, arg5 map[ids.ID]uint64) error

VerifySpend mocks base method.

func (*MockVerifier) VerifySpendUTXOs

func (m *MockVerifier) VerifySpendUTXOs(arg0 avax.UTXOGetter, arg1 txs.UnsignedTx, arg2 []*avax.UTXO, arg3 []*avax.TransferableInput, arg4 []*avax.TransferableOutput, arg5 []verify.Verifiable, arg6 map[ids.ID]uint64) error

VerifySpendUTXOs mocks base method.

func (*MockVerifier) VerifyUnlockDeposit

func (m *MockVerifier) VerifyUnlockDeposit(arg0 avax.UTXOGetter, arg1 txs.UnsignedTx, arg2 []*avax.TransferableInput, arg3 []*avax.TransferableOutput, arg4 []verify.Verifiable, arg5 uint64, arg6 ids.ID, arg7 bool) error

VerifyUnlockDeposit mocks base method.

type MockVerifierMockRecorder

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

MockVerifierMockRecorder is the mock recorder for MockVerifier.

func (*MockVerifierMockRecorder) Unlock

func (mr *MockVerifierMockRecorder) Unlock(arg0, arg1, arg2 interface{}) *gomock.Call

Unlock indicates an expected call of Unlock.

func (*MockVerifierMockRecorder) VerifyLock

func (mr *MockVerifierMockRecorder) VerifyLock(arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8 interface{}) *gomock.Call

VerifyLock indicates an expected call of VerifyLock.

func (*MockVerifierMockRecorder) VerifySpend

func (mr *MockVerifierMockRecorder) VerifySpend(arg0, arg1, arg2, arg3, arg4, arg5 interface{}) *gomock.Call

VerifySpend indicates an expected call of VerifySpend.

func (*MockVerifierMockRecorder) VerifySpendUTXOs

func (mr *MockVerifierMockRecorder) VerifySpendUTXOs(arg0, arg1, arg2, arg3, arg4, arg5, arg6 interface{}) *gomock.Call

VerifySpendUTXOs indicates an expected call of VerifySpendUTXOs.

func (*MockVerifierMockRecorder) VerifyUnlockDeposit

func (mr *MockVerifierMockRecorder) VerifyUnlockDeposit(arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7 interface{}) *gomock.Call

VerifyUnlockDeposit indicates an expected call of VerifyUnlockDeposit.

type Spender

type Spender interface {
	// Spend the provided amount while deducting the provided fee.
	// Arguments:
	// - [keys] are the owners of the funds
	// - [amount] is the amount of funds that are trying to be staked
	// - [fee] is the amount of AVAX that should be burned
	// - [changeAddr] is the address that change, if there is any, is sent to
	// Returns:
	// - [inputs] the inputs that should be consumed to fund the outputs
	// - [returnedOutputs] the outputs that should be immediately returned to
	//                     the UTXO set
	// - [stakedOutputs] the outputs that should be locked for the duration of
	//                   the staking period
	// - [signers] the proof of ownership of the funds being moved
	Spend(
		utxoReader avax.UTXOReader,
		keys []*secp256k1.PrivateKey,
		amount uint64,
		fee uint64,
		changeAddr ids.ShortID,
	) (
		[]*avax.TransferableInput,
		[]*avax.TransferableOutput,
		[]*avax.TransferableOutput,
		[][]*secp256k1.PrivateKey,
		error,
	)

	// Authorize an operation on behalf of the named subnet with the provided
	// keys.
	Authorize(
		state state.Chain,
		subnetID ids.ID,
		keys []*secp256k1.PrivateKey,
	) (
		verify.Verifiable,
		[]*secp256k1.PrivateKey,
		error,
	)

	CaminoSpender
}

TODO: Stake and Authorize should be replaced by similar methods in the P-chain wallet

type Unlocker

type Unlocker interface {
	// Unlock fetches utxos locked by [lockTxIDs] transactions
	// with lock state [removedLockState], and then spends them producing
	// [inputs] and [outputs].
	// Outputs will have their lock state [removedLockState] removed,
	// but could still be locked with other lock state.
	// Arguments:
	// - [state] are the state from which lock txs and locked utxos will be fetched.
	// - [lockTxIDs] is array of lock transaction ids.
	// - [removedLockState] is lock state that will be removed from result [outputs].
	// Returns:
	// - [inputs] the inputs that should be consumed to fund the outputs
	// - [outputs] the outputs that should be returned to the UTXO set
	Unlock(
		state state.Chain,
		lockTxIDs []ids.ID,
		removedLockState locked.State,
	) (
		[]*avax.TransferableInput,
		[]*avax.TransferableOutput,
		error,
	)
}

type Verifier

type Verifier interface {
	// Verify that [tx] is semantically valid.
	// [ins] and [outs] are the inputs and outputs of [tx].
	// [creds] are the credentials of [tx], which allow [ins] to be spent.
	// [unlockedProduced] is the map of assets that were produced and their
	// amounts.
	// The [ins] must have at least [unlockedProduced] than the [outs].
	//
	// Precondition: [tx] has already been syntactically verified.
	//
	// Note: [unlockedProduced] is modified by this method.
	VerifySpend(
		tx txs.UnsignedTx,
		utxoDB avax.UTXOGetter,
		ins []*avax.TransferableInput,
		outs []*avax.TransferableOutput,
		creds []verify.Verifiable,
		unlockedProduced map[ids.ID]uint64,
	) error

	// Verify that [tx] is semantically valid.
	// [utxos[i]] is the UTXO being consumed by [ins[i]].
	// [ins] and [outs] are the inputs and outputs of [tx].
	// [creds] are the credentials of [tx], which allow [ins] to be spent.
	// [unlockedProduced] is the map of assets that were produced and their
	// amounts.
	// The [ins] must have at least [unlockedProduced] more than the [outs].
	//
	// Precondition: [tx] has already been syntactically verified.
	//
	// Note: [unlockedProduced] is modified by this method.
	VerifySpendUTXOs(
		utxoDB avax.UTXOGetter,
		tx txs.UnsignedTx,
		utxos []*avax.UTXO,
		ins []*avax.TransferableInput,
		outs []*avax.TransferableOutput,
		creds []verify.Verifiable,
		unlockedProduced map[ids.ID]uint64,
	) error

	CaminoVerifier
}

Jump to

Keyboard shortcuts

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