onchain

package
v1.0.1-alpha Latest Latest
Warning

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

Go to latest
Published: Dec 26, 2025 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultTransactionsLimit = 30

Variables

View Source
var ErrNotConfirmed = errors.New("lockup transaction not confirmed")
View Source
var RegtestElectrumConfig = ElectrumConfig{
	Btc:    &ElectrumOptions{Url: "localhost:19001"},
	Liquid: &ElectrumOptions{Url: "localhost:19002"},
}

Functions

func ValidateWalletCredentials

func ValidateWalletCredentials(backend WalletBackend, credentials *WalletCredentials) error

Types

type Balance

type Balance struct {
	Total       uint64
	Confirmed   uint64
	Unconfirmed uint64
}

type BlockEpoch

type BlockEpoch struct {
	Height uint32
}

type ChainProvider

type ChainProvider interface {
	EstimateFee() (float64, error)
	GetBlockHeight() (uint32, error)
	GetRawTransaction(txId string) (string, error)
	BroadcastTransaction(txHex string) (string, error)
	IsTransactionConfirmed(txId string) (bool, error)
	GetUnspentOutputs(address string) ([]*Output, error)
	Disconnect()
}

type Currency

type Currency struct {
	Chain ChainProvider
	// contains filtered or unexported fields
}

type ElectrumConfig

type ElectrumConfig struct {
	Btc    *ElectrumOptions
	Liquid *ElectrumOptions
}

type ElectrumOptions

type ElectrumOptions struct {
	Url string
	SSL bool
}

func (*ElectrumOptions) String

func (e *ElectrumOptions) String() string

type Id

type Id = uint64

type LightzProvider

type LightzProvider struct {
	*lightz.Api
	// contains filtered or unexported fields
}

func NewLightzChainProvider

func NewLightzChainProvider(lightzd *lightz.Api, currency lightz.Currency) *LightzProvider

func (LightzProvider) BroadcastTransaction

func (txProvider LightzProvider) BroadcastTransaction(txHex string) (string, error)

func (LightzProvider) Disconnect

func (txProvider LightzProvider) Disconnect()

func (LightzProvider) EstimateFee

func (txProvider LightzProvider) EstimateFee() (float64, error)

func (LightzProvider) GetBlockHeight

func (txProvider LightzProvider) GetBlockHeight() (uint32, error)

func (LightzProvider) GetRawTransaction

func (txProvider LightzProvider) GetRawTransaction(txId string) (string, error)

func (LightzProvider) GetUnspentOutputs

func (txProvider LightzProvider) GetUnspentOutputs(address string) ([]*Output, error)

func (LightzProvider) IsTransactionConfirmed

func (txProvider LightzProvider) IsTransactionConfirmed(txId string) (bool, error)

type MultiChainProvider

type MultiChainProvider struct {
	ChainProvider
	Providers []ChainProvider
	Lightz    ChainProvider
}

MultiChainProvider is a chain provider that can combine multiple third party providers into a single one, potentially using a lightzd chain provider as a fallback. Its a trust-minimized implementation where lightzd API is only ever trusted if every single provider is not reachable.

func (MultiChainProvider) BroadcastTransaction

func (m MultiChainProvider) BroadcastTransaction(txHex string) (txId string, err error)

func (MultiChainProvider) Disconnect

func (m MultiChainProvider) Disconnect()

func (MultiChainProvider) EstimateFee

func (m MultiChainProvider) EstimateFee() (float64, error)

func (MultiChainProvider) GetBlockHeight

func (m MultiChainProvider) GetBlockHeight() (uint32, error)

func (MultiChainProvider) GetRawTransaction

func (m MultiChainProvider) GetRawTransaction(txId string) (hex string, err error)

func (MultiChainProvider) GetUnspentOutputs

func (m MultiChainProvider) GetUnspentOutputs(address string) ([]*Output, error)

func (MultiChainProvider) IsTransactionConfirmed

func (m MultiChainProvider) IsTransactionConfirmed(txId string) (confirmed bool, err error)

type Onchain

type Onchain struct {
	Btc                 *Currency
	Liquid              *Currency
	Network             *lightz.Network
	Wallets             []Wallet
	OnWalletChange      *utils.ChannelForwarder[[]Wallet]
	WalletSyncIntervals map[lightz.Currency]time.Duration
	// contains filtered or unexported fields
}

func (*Onchain) AddWallet

func (onchain *Onchain) AddWallet(wallet Wallet)

func (*Onchain) BroadcastTransaction

func (onchain *Onchain) BroadcastTransaction(transaction lightz.Transaction) (string, error)

func (*Onchain) Disconnect

func (onchain *Onchain) Disconnect()

func (*Onchain) EstimateFee

func (onchain *Onchain) EstimateFee(currency lightz.Currency) (float64, error)

func (*Onchain) FindOutput

func (onchain *Onchain) FindOutput(info OutputArgs) (*OutputResult, error)

func (*Onchain) GetAnyWallet

func (onchain *Onchain) GetAnyWallet(checker WalletChecker) (Wallet, error)

func (*Onchain) GetBlockHeight

func (onchain *Onchain) GetBlockHeight(currency lightz.Currency) (uint32, error)

func (*Onchain) GetBlockProvider

func (onchain *Onchain) GetBlockProvider(currency lightz.Currency) ChainProvider

func (*Onchain) GetCurrency

func (onchain *Onchain) GetCurrency(currency lightz.Currency) (*Currency, error)

func (*Onchain) GetTransaction

func (onchain *Onchain) GetTransaction(currency lightz.Currency, txId string, ourOutputBlindingKey *btcec.PrivateKey, retry bool) (lightz.Transaction, error)

func (*Onchain) GetTransactionFee

func (onchain *Onchain) GetTransactionFee(transaction lightz.Transaction) (uint64, error)

func (*Onchain) GetUnspentOutputs

func (onchain *Onchain) GetUnspentOutputs(currency lightz.Currency, address string) ([]*Output, error)

func (*Onchain) GetWallets

func (onchain *Onchain) GetWallets(checker WalletChecker) []Wallet

func (*Onchain) Init

func (onchain *Onchain) Init()

func (*Onchain) IsTransactionConfirmed

func (onchain *Onchain) IsTransactionConfirmed(currency lightz.Currency, txId string, retry bool) (bool, error)

func (*Onchain) RegisterBlockListener

func (onchain *Onchain) RegisterBlockListener(ctx context.Context, currency lightz.Currency) *utils.ChannelForwarder[*BlockEpoch]

func (*Onchain) RemoveWallet

func (onchain *Onchain) RemoveWallet(id Id)

type Output

type Output struct {
	TxId  string
	Value uint64
}

type OutputArgs

type OutputArgs struct {
	TransactionId  string
	Currency       lightz.Currency
	Address        string
	BlindingKey    *btcec.PrivateKey
	ExpectedAmount uint64
}

type OutputResult

type OutputResult struct {
	Transaction lightz.Transaction
	Vout        uint32
	Value       uint64
}

type TransactionOutput

type TransactionOutput struct {
	Address      string
	Amount       uint64
	IsOurAddress bool
}

type Wallet

type Wallet interface {
	NewAddress() (string, error)
	SendToAddress(args WalletSendArgs) (string, error)
	Ready() bool
	GetBalance() (*Balance, error)
	GetWalletInfo() WalletInfo
	Disconnect() error
	GetTransactions(limit, offset uint64) ([]*WalletTransaction, error)
	BumpTransactionFee(txId string, satPerVbyte float64) (string, error)
	GetSendFee(args WalletSendArgs) (send uint64, fee uint64, err error)
	GetOutputs(address string) ([]*Output, error)
	Sync() error
	FullScan() error
	ApplyTransaction(txHex string) error
}

type WalletBackend

type WalletBackend interface {
	NewWallet(credentials *WalletCredentials) (Wallet, error)
	DeriveDefaultDescriptor(mnemonic string) (string, error)
}

type WalletChecker

type WalletChecker struct {
	Id            *Id
	Name          *string
	Currency      lightz.Currency
	AllowReadonly bool
	TenantId      *Id
}

func (*WalletChecker) Allowed

func (walletChecker *WalletChecker) Allowed(wallet Wallet) bool

type WalletCredentials

type WalletCredentials struct {
	WalletInfo
	Mnemonic       string
	Subaccount     *uint64
	Xpub           string
	CoreDescriptor string
	Salt           string
	Legacy         bool
}

func (*WalletCredentials) Decrypt

func (c *WalletCredentials) Decrypt(password string) (*WalletCredentials, error)

func (*WalletCredentials) Encrypt

func (c *WalletCredentials) Encrypt(password string) (*WalletCredentials, error)

func (*WalletCredentials) Encrypted

func (c *WalletCredentials) Encrypted() bool

type WalletInfo

type WalletInfo struct {
	Id       Id
	Name     string
	Currency lightz.Currency
	Readonly bool
	TenantId Id
}

func (WalletInfo) InsufficientBalanceError

func (info WalletInfo) InsufficientBalanceError(amount uint64) error

func (WalletInfo) String

func (info WalletInfo) String() string

type WalletSendArgs

type WalletSendArgs struct {
	Address     string
	Amount      uint64
	SatPerVbyte float64
	SendAll     bool
}

type WalletTransaction

type WalletTransaction struct {
	Id              string
	Timestamp       time.Time
	Outputs         []TransactionOutput
	BlockHeight     uint32
	BalanceChange   int64
	IsConsolidation bool
}

Directories

Path Synopsis
bdk
lwk

Jump to

Keyboard shortcuts

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