txs

package
v1.4.1 Latest Latest
Warning

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

Go to latest
Published: Jun 25, 2026 License: BSD-3-Clause Imports: 3 Imported by: 0

Documentation

Overview

Package txs defines the transaction surface for the S-Chain — the Lux STORAGE VM. M0 has exactly one mutation: PutManifest, which records the (bucket, object) -> manifest mapping for an object whose file blobs already exist elsewhere (the S-Chain does NOT carry blobs in M0; it carries the content manifest that names them).

Wire format mirrors dexvm/txs exactly — a single type byte followed by the JSON body of the concrete struct (dexvm/txs/tx.go:621). The encoding is deterministic (encoding/json emits struct fields in declaration order and these types contain no maps), so the same logical transaction always serializes to identical bytes and therefore the same TxID. One codec, one way to read a transaction off the wire.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidTxType is returned when the leading type byte names no known tx.
	ErrInvalidTxType = errors.New("invalid transaction type")
	// ErrEmptyBucket / ErrEmptyObject reject a manifest with no addressable key.
	ErrEmptyBucket = errors.New("manifest: empty bucket")
	ErrEmptyObject = errors.New("manifest: empty object")
	// ErrNoFileIDs rejects a manifest that names no file blobs (M0 carries the
	// content manifest; an object with zero files has nothing to commit).
	ErrNoFileIDs = errors.New("manifest: no file ids")
)

Functions

func Marshal

func Marshal[T any](tx *T, txType TxType) ([]byte, error)

Marshal serializes a concrete transaction into wire bytes: type byte + JSON body. The single codec used by both constructors and the parser.

Types

type BaseTx

type BaseTx struct {
	TxID   ids.ID `json:"-"`
	TxType TxType `json:"type"`
	// contains filtered or unexported fields
}

BaseTx carries the fields common to every S-Chain transaction.

TxID is intentionally NOT serialized (json:"-"): the id is the checksum of the wire bytes, so embedding it in those bytes would be circular. It is always (re)derived from the wire on Parse and stamped by finalize on construction — the exact discipline dexvm/txs/tx.go:107 uses.

func (*BaseTx) Bytes

func (tx *BaseTx) Bytes() []byte

func (*BaseTx) ID

func (tx *BaseTx) ID() ids.ID

func (*BaseTx) Type

func (tx *BaseTx) Type() TxType

type PutManifestTx

type PutManifestTx struct {
	BaseTx
	Bucket  string   `json:"bucket"`
	Object  string   `json:"object"`
	FileIDs []string `json:"fileIds"`
	Size    int64    `json:"size"`
	ETag    string   `json:"etag"`
}

PutManifestTx records the manifest for one object. FileIDs names the content blobs (their ids in whatever blob store M1 wires in); Size and ETag are the object-level metadata an S3 HEAD returns. M0 commits these verbatim.

func NewPutManifestTx

func NewPutManifestTx(bucket, object string, fileIDs []string, size int64, etag string) *PutManifestTx

NewPutManifestTx builds a wire-ready PutManifest transaction. finalize stamps the deterministic wire bytes + TxID, so the returned tx is immediately Parse-round-trippable (mirrors every dexvm New*Tx constructor).

func (*PutManifestTx) Verify

func (tx *PutManifestTx) Verify() error

Verify validates a PutManifest in isolation: it must name an addressable (bucket, object) and at least one file blob. No state is consulted (Verify is pure — the same discipline the VM relies on for deterministic block Verify).

type Tx

type Tx interface {
	// ID returns the deterministic transaction identifier (checksum of wire bytes).
	ID() ids.ID
	// Type returns the transaction type.
	Type() TxType
	// Bytes returns the serialized transaction (type byte + JSON body).
	Bytes() []byte
	// Verify validates the transaction in isolation (no state access).
	Verify() error
}

Tx is the interface every S-Chain transaction satisfies.

type TxParser

type TxParser struct{}

TxParser parses raw transaction bytes off the wire.

func (*TxParser) Parse

func (p *TxParser) Parse(data []byte) (Tx, error)

Parse decodes a transaction from its wire bytes (type byte + JSON body).

type TxType

type TxType uint8

TxType is the transaction discriminator (the leading wire byte).

const (
	// TxPutManifest records a (bucket, object) -> manifest mapping. The single
	// mutation of M0.
	TxPutManifest TxType = iota
)

func (TxType) String

func (t TxType) String() string

Jump to

Keyboard shortcuts

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