txs
Package txs is the X-chain (xvm) transaction package for the luxfi/node binary.
import "github.com/luxfi/node/vms/xvm/txs"Package txs is the X-chain (xvm) transaction package for the luxfi/node binary. It owns the native-ZAP struct-is-wire tx codec: the signed-tx envelope (wire.SignedTx), the per-type unsigned bodies keyed by a 1-byte xkind discriminator, and the per-fx Initial-State / Operation accessors the X-VM uses to build, sign, and parse on-chain transactions.
There is no pcodecs.Manager, no linearcodec, and no reflection-driven slot map. Each tx type serializes itself directly onto a github.com/luxfi/zap buffer; polymorphic fx primitives (outputs, inputs, operations, credentials) name themselves on the wire via their (TypeKind, ShapeKind) envelope and are reconstructed by envelope dispatch (fxwire.go).
Package txs is a generated GoMock package.
Functions
IsSortedAndUniqueOperations
func IsSortedAndUniqueOperations(ops []*Operation) boolSortOperations
func SortOperations(ops []*Operation)SortOperationsWithSigners
func SortOperationsWithSigners(ops []*Operation, signers [][]*secp256k1.PrivateKey)UnsignedBytes
func UnsignedBytes(u UnsignedTx) ([]byte, error)UnsignedBytes returns the canonical native-ZAP wire bytes of an unsigned tx, serializing (and caching) them on first use. This is the signing target — every fx signature is computed over hash(unsignedBytes).
Types
BaseTx
BaseTx is the basis of all transactions. It carries the multi-asset spending envelope (NetworkID/BlockchainID/Outs/Ins/Memo) as an embedded lux.BaseTx — X-Chain is a universal multi-fx settlement layer, so Outs/Ins hold arbitrary fx primitives, not the fixed secp256k1 stride the P-Chain uses. The struct is the source of truth; Bytes() is the cached native-ZAP wire encoding.
Wire (unsigned): zap object { xkind@0, baseTxEnvelope@8 } where the envelope is a wire.XVMBaseTx (each Out/In an fx-typed TransferableOut/In envelope).
func (t *BaseTx) Bytes() []bytefunc (t *BaseTx) InitRuntime(rt *runtime.Runtime)func (t *BaseTx) InitializeRuntime(rt *runtime.Runtime) errorfunc (t *BaseTx) InitializeWithRuntime(rt *runtime.Runtime) errorfunc (t *BaseTx) InputIDs() set.Set[ids.ID]func (t *BaseTx) InputUTXOs() []*lux.UTXOIDfunc (t *BaseTx) NumCredentials() intfunc (t *BaseTx) SetBytes(bytes []byte)func (t *BaseTx) Visit(v Visitor) errorCreateAssetTx
CreateAssetTx is a transaction that creates a new asset.
Wire (unsigned): the shared { xkind@0, baseTxEnvelope@8 } prefix, then Name@16 / Symbol@24 (text) + Denomination@32 (u8) + the InitialStates as a packed (length list @36, blob @44) of self-delimiting InitialState objects.
func (t *CreateAssetTx) InitRuntime(rt *runtime.Runtime)func (t *CreateAssetTx) InitialStates() []*InitialStatefunc (t *CreateAssetTx) InitializeRuntime(rt *runtime.Runtime) errorfunc (t *CreateAssetTx) InitializeWithRuntime(rt *runtime.Runtime) errorfunc (t *CreateAssetTx) Visit(v Visitor) errorExportTx
ExportTx is a transaction that exports an asset to another blockchain.
Wire (unsigned): the shared { xkind@0, baseTxEnvelope@8 } prefix, then DestinationChain@16 (32B) + the exported outputs as a packed (length list @48, blob @56) of self-delimiting wire TransferableOut envelopes.
func (t *ExportTx) InitRuntime(rt *runtime.Runtime)func (t *ExportTx) InitializeRuntime(rt *runtime.Runtime) errorfunc (t *ExportTx) InitializeWithRuntime(rt *runtime.Runtime) errorfunc (t *ExportTx) Visit(v Visitor) errorFxIndex
FxIndex maps a wire.TypeKind (fx family) to its position in a parser's fx list. Array-backed: Get is one bounds-checked load, no hashing. A slot of -1 means no fx of that family is registered.
func NewFxIndex() *FxIndexfunc (fi *FxIndex) Get(kind wire.TypeKind) (int, bool)func (fi *FxIndex) GetFx(val interface{}) (int, bool)func (fi *FxIndex) Set(kind wire.TypeKind, idx int)ImportTx
ImportTx is a transaction that imports an asset from another blockchain.
Wire (unsigned): the shared { xkind@0, baseTxEnvelope@8 } prefix, then SourceChain@16 (32B) + the imported inputs as a packed (length list @48, blob @56) of self-delimiting wire TransferableIn envelopes.
func (t *ImportTx) InitRuntime(rt *runtime.Runtime)func (t *ImportTx) InitializeRuntime(rt *runtime.Runtime) errorfunc (t *ImportTx) InitializeWithRuntime(rt *runtime.Runtime) errorfunc (t *ImportTx) InputIDs() set.Set[ids.ID]func (t *ImportTx) InputUTXOs() []*lux.UTXOIDfunc (t *ImportTx) NumCredentials() intfunc (t *ImportTx) Visit(v Visitor) errorInitialState
InitialState is the per-fx genesis state a CreateAssetTx installs: an fx index plus that fx's initial output set. Outs is a heterogeneous slice of fx state outputs, each serialized as its own (TypeKind, ShapeKind, ZAP) wire envelope — the FxID is recovered from the envelope's TypeKind, so it is not stored on the wire.
Wire: zap object { FxIndex@0 (u32), Outs (length list @4, blob @12) }.
func (is *InitialState) Bytes() ([]byte, error)func (is *InitialState) Compare(other *InitialState) intfunc (is *InitialState) InitRuntime(*runtime.Runtime)func (is *InitialState) Sort()func (is *InitialState) Verify(numFxs int) errorMockUnsignedTx
MockUnsignedTx is a mock of UnsignedTx interface.
func NewMockUnsignedTx(ctrl *gomock.Controller) *MockUnsignedTxfunc (m *MockUnsignedTx) Bytes() []bytefunc (m *MockUnsignedTx) EXPECT() *MockUnsignedTxMockRecorderfunc (m *MockUnsignedTx) InitRuntime(arg0 context.Context)func (m *MockUnsignedTx) InitializeRuntime(arg0 context.Context) errorfunc (m *MockUnsignedTx) InputIDs() set.Set[ids.ID]func (m *MockUnsignedTx) InputUTXOs() []*lux.UTXOIDfunc (m *MockUnsignedTx) NumCredentials() intfunc (m *MockUnsignedTx) SetBytes(unsignedBytes []byte)func (m *MockUnsignedTx) Visit(visitor Visitor) errorMockUnsignedTxMockRecorder
MockUnsignedTxMockRecorder is the mock recorder for MockUnsignedTx.
func (mr *MockUnsignedTxMockRecorder) Bytes() *gomock.Callfunc (mr *MockUnsignedTxMockRecorder) InitRuntime(arg0 any) *gomock.Callfunc (mr *MockUnsignedTxMockRecorder) InitializeRuntime(arg0 any) *gomock.Callfunc (mr *MockUnsignedTxMockRecorder) InputIDs() *gomock.Callfunc (mr *MockUnsignedTxMockRecorder) InputUTXOs() *gomock.Callfunc (mr *MockUnsignedTxMockRecorder) NumCredentials() *gomock.Callfunc (mr *MockUnsignedTxMockRecorder) SetBytes(unsignedBytes any) *gomock.Callfunc (mr *MockUnsignedTxMockRecorder) Visit(visitor any) *gomock.CallOperation
Operation runs a single fx operation (mint / NFT transfer / property burn) over a set of consumed UTXOs of a given asset.
Wire: zap object { Asset@0 (32B), UTXOIDs@32 (36B-stride list), Op@40 (the fx operation's own (TypeKind, ShapeKind, ZAP) envelope) }. FxID is recovered from the Op envelope's TypeKind, so it is not stored on the wire.
func (op *Operation) Bytes() ([]byte, error)func (op *Operation) Verify() errorOperationTx
OperationTx is a transaction that runs a set of fx operations over existing UTXOs (mint / NFT transfer / property burn ...).
Wire (unsigned): the shared { xkind@0, baseTxEnvelope@8 } prefix, then the Operations as a packed (length list @16, blob @24) of self-delimiting Operation objects.
func (t *OperationTx) InitRuntime(rt *runtime.Runtime)func (t *OperationTx) InitializeRuntime(rt *runtime.Runtime) errorfunc (t *OperationTx) InitializeWithRuntime(rt *runtime.Runtime) errorfunc (t *OperationTx) InputIDs() set.Set[ids.ID]func (t *OperationTx) InputUTXOs() []*lux.UTXOIDfunc (t *OperationTx) NumCredentials() intfunc (t *OperationTx) Operations() []*Operationfunc (t *OperationTx) Visit(v Visitor) errorParser
func NewCustomParser(
fxIndex *FxIndex,
clock *mockable.Clock,
logger log.Logger,
fxList []fxs.Fx,
) (Parser, error)func NewParser(fxs []fxs.Fx) (Parser, error)Tx
Tx is the core operation that can be performed. The tx uses the UTXO model. Specifically, a txs inputs will consume previous txs outputs. A tx will be valid if the inputs have the authority to consume the outputs they are attempting to consume and the inputs consume sufficient state to produce the outputs.
A signed tx is a wire.SignedTx envelope: the unsigned tx bytes (which carry the xkind discriminator at offset 0) followed by a packed list of fx credential envelopes. There is no codec.
func Parse(signedBytes []byte) (*Tx, error)func (t *Tx) Bytes() []bytefunc (t *Tx) GossipID() ids.IDfunc (t *Tx) ID() ids.IDfunc (t *Tx) Initialize() errorfunc (t *Tx) InputIDs() set.Set[ids.ID]func (t *Tx) SetBytes(unsignedBytes, signedBytes []byte)func (t *Tx) SignNFTFx(signers [][]*secp256k1.PrivateKey) errorfunc (t *Tx) SignPropertyFx(signers [][]*secp256k1.PrivateKey) errorfunc (t *Tx) SignSECP256K1Fx(signers [][]*secp256k1.PrivateKey) errorfunc (t *Tx) Size() intfunc (t *Tx) UTXOs() []*lux.UTXOUnsignedTx
func ParseUnsignedTx(unsignedBytes []byte) (UnsignedTx, error)Visitor
Allow vm to execute custom logic against the underlying transaction types.