utxo

package
v1.13.16 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2025 License: BSD-3-Clause Imports: 5 Imported by: 0

Documentation

Overview

Package utxo provides a generic UTXO (Unspent Transaction Output) management system that can be used across different blockchain architectures (Bitcoin, XRPL, Lux)

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUTXONotFound      = errors.New("UTXO not found")
	ErrInsufficientFunds = errors.New("insufficient funds")
	ErrInvalidChainType  = errors.New("invalid chain type")
	ErrInvalidAddress    = errors.New("invalid address format")
)

Functions

This section is empty.

Types

type BaseManager

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

BaseManager provides a basic implementation of UTXO management

func NewBaseManager

func NewBaseManager() *BaseManager

NewBaseManager creates a new base UTXO manager

func (*BaseManager) AddUTXO

func (m *BaseManager) AddUTXO(_ context.Context, utxo *UTXO) error

func (*BaseManager) GetBalance

func (m *BaseManager) GetBalance(_ context.Context, address string, assetID ids.ID) (*big.Int, error)

func (*BaseManager) GetUTXO

func (m *BaseManager) GetUTXO(_ context.Context, utxoID ids.ID) (*UTXO, error)

func (*BaseManager) GetUTXOs

func (m *BaseManager) GetUTXOs(_ context.Context, address string) ([]*UTXO, error)

func (*BaseManager) RemoveUTXO

func (m *BaseManager) RemoveUTXO(_ context.Context, utxoID ids.ID) error

func (*BaseManager) SelectUTXOs

func (m *BaseManager) SelectUTXOs(_ context.Context, address string, assetID ids.ID, targetAmount *big.Int) ([]*UTXO, *big.Int, error)

type ChainType

type ChainType int

ChainType represents different blockchain architectures

const (
	ChainTypeLux ChainType = iota
	ChainTypeBitcoin
	ChainTypeXRPL
	ChainTypeEVM
)

type Manager

type Manager interface {
	// AddUTXO adds a new UTXO to the set
	AddUTXO(ctx context.Context, utxo *UTXO) error

	// RemoveUTXO removes a UTXO from the set
	RemoveUTXO(ctx context.Context, utxoID ids.ID) error

	// GetUTXO retrieves a specific UTXO
	GetUTXO(ctx context.Context, utxoID ids.ID) (*UTXO, error)

	// GetUTXOs retrieves all UTXOs for a given address
	GetUTXOs(ctx context.Context, address string) ([]*UTXO, error)

	// GetBalance calculates the total balance for an address
	GetBalance(ctx context.Context, address string, assetID ids.ID) (*big.Int, error)

	// SelectUTXOs selects UTXOs to meet a target amount
	SelectUTXOs(ctx context.Context, address string, assetID ids.ID, targetAmount *big.Int) ([]*UTXO, *big.Int, error)
}

Manager provides chain-agnostic UTXO management

type UTXO

type UTXO struct {
	ID           ids.ID
	TxID         ids.ID
	OutputIndex  uint32
	AssetID      ids.ID
	Amount       *big.Int
	Address      string // Can be different formats based on chain type
	ScriptPubKey []byte // For Bitcoin-style chains
	Locktime     uint64
	ChainType    ChainType
	Extra        interface{} // Chain-specific data
}

UTXO represents a generic unspent transaction output

Jump to

Keyboard shortcuts

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