Documentation
¶
Index ¶
- Constants
- Variables
- func GetTaprootAddressFromScript(pkScript []byte, chainParams *chaincfg.Params) (*btcutil.AddressTaproot, error)
- func UseLogger(logger btclog.Logger)
- type AddressParameters
- type Manager
- func (m *Manager) ActivateChangeAddress(ctx context.Context, params *AddressParameters) error
- func (m *Manager) EnsureStaticAddressRoot(ctx context.Context) (*AddressParameters, error)
- func (m *Manager) GetAllAddresses(ctx context.Context) ([]*AddressParameters, error)
- func (m *Manager) GetLegacyParameters(ctx context.Context) (*AddressParameters, error)
- func (m *Manager) GetParameters(pkScript []byte) *AddressParameters
- func (m *Manager) GetStaticAddress(ctx context.Context) (*script.StaticAddress, error)
- func (m *Manager) GetStaticAddressID(ctx context.Context, pkScript []byte) (int32, error)
- func (m *Manager) GetStaticAddressParameters(ctx context.Context) (*script.Parameters, error)
- func (m *Manager) GetTaprootAddress(clientPubkey, serverPubkey *btcec.PublicKey, expiry int64) (*btcutil.AddressTaproot, error)
- func (m *Manager) ListUnspent(ctx context.Context, minConfs, maxConfs int32) ([]*lnwallet.Utxo, error)
- func (m *Manager) NewAddress(ctx context.Context) (*btcutil.AddressTaproot, int64, error)
- func (m *Manager) NewChangeAddress(ctx context.Context) (*AddressParameters, error)
- func (m *Manager) NewReceiveAddress(ctx context.Context) (*AddressParameters, error)
- func (m *Manager) PrepareChangeAddress(ctx context.Context) (*AddressParameters, error)
- func (m *Manager) Run(ctx context.Context, initChan chan struct{}) error
- type ManagerConfig
- type SqlStore
- func (s *SqlStore) CreateStaticAddress(ctx context.Context, addrParams *AddressParameters) error
- func (s *SqlStore) GetAllStaticAddresses(ctx context.Context) ([]*AddressParameters, error)
- func (s *SqlStore) GetLegacyParameters(ctx context.Context) (*AddressParameters, error)
- func (s *SqlStore) GetMaxStaticAddressHtlcKeyIndex(ctx context.Context, family keychain.KeyFamily) (uint32, bool, error)
- func (s *SqlStore) GetStaticAddressID(ctx context.Context, pkScript []byte) (int32, error)
- func (s *SqlStore) ListStaticAddresses(ctx context.Context, afterID, limit int32) ([]*AddressParameters, error)
- type Store
Constants ¶
const Subsystem = "SADDR"
Subsystem defines the sub system name of this package.
Variables ¶
var ( // ErrNoStaticAddress is returned when no static address parameters are // present in the store. ErrNoStaticAddress = errors.New("no static address parameters found") )
Functions ¶
func GetTaprootAddressFromScript ¶
func GetTaprootAddressFromScript(pkScript []byte, chainParams *chaincfg.Params) ( *btcutil.AddressTaproot, error)
GetTaprootAddressFromScript encodes a canonical P2TR output script for the given network without reconstructing its keys or checking script ownership.
Types ¶
type AddressParameters ¶
type AddressParameters = script.Parameters
AddressParameters describes one static address for callers of the address manager API. It aliases the script-level parameters used to spend that address.
func ParametersFromRow ¶
func ParametersFromRow(row sqlc.StaticAddress) ( *AddressParameters, error)
ParametersFromRow restores static address parameters from a database row. Joined address rows use this same conversion after unpacking nullable fields.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager manages the address state machines.
func NewManager ¶
func NewManager(cfg *ManagerConfig, currentHeight int32) (*Manager, error)
NewManager creates a new address manager.
func (*Manager) ActivateChangeAddress ¶
func (m *Manager) ActivateChangeAddress(ctx context.Context, params *AddressParameters) error
ActivateChangeAddress persists and imports prepared change parameters before publishing them in the active address index. An import failure retains the row and its ID so a retry or startup can repair the same address.
func (*Manager) EnsureStaticAddressRoot ¶
func (m *Manager) EnsureStaticAddressRoot(ctx context.Context) (*AddressParameters, error)
EnsureStaticAddressRoot loads or creates the legacy/root static address parameters. The root address is the only address that requires a ServerNewAddress call; all receive/change addresses derive client keys locally and reuse the root address's server pubkey and expiry.
func (*Manager) GetAllAddresses ¶
func (m *Manager) GetAllAddresses(ctx context.Context) ([]*AddressParameters, error)
GetAllAddresses returns all persisted static address parameters.
func (*Manager) GetLegacyParameters ¶
func (m *Manager) GetLegacyParameters(ctx context.Context) (*AddressParameters, error)
GetLegacyParameters returns the legacy/root static address parameters.
func (*Manager) GetParameters ¶
func (m *Manager) GetParameters(pkScript []byte) *AddressParameters
GetParameters returns active static address parameters for a pkScript.
func (*Manager) GetStaticAddress ¶
GetStaticAddress returns a taproot address for the given client and server public keys and expiry.
func (*Manager) GetStaticAddressID ¶
GetStaticAddressID returns the database row ID for a static address script.
func (*Manager) GetStaticAddressParameters ¶
GetStaticAddressParameters returns the legacy/root static-address parameters.
func (*Manager) GetTaprootAddress ¶
func (m *Manager) GetTaprootAddress(clientPubkey, serverPubkey *btcec.PublicKey, expiry int64) (*btcutil.AddressTaproot, error)
GetTaprootAddress returns a taproot address for the given client and server public keys and expiry.
func (*Manager) ListUnspent ¶
func (m *Manager) ListUnspent(ctx context.Context, minConfs, maxConfs int32) ([]*lnwallet.Utxo, error)
ListUnspent returns wallet UTXOs matching any active static address within the requested confirmation range.
func (*Manager) NewAddress ¶
NewAddress creates the next externally visible receive static address.
The first call also makes sure the legacy/root static address exists, because receive and change addresses are derived from the server pubkey and expiry returned for that root.
func (*Manager) NewChangeAddress ¶
func (m *Manager) NewChangeAddress(ctx context.Context) (*AddressParameters, error)
NewChangeAddress derives, stores, imports and activates the next change family static address for callers requiring immediate activation.
func (*Manager) NewReceiveAddress ¶
func (m *Manager) NewReceiveAddress(ctx context.Context) (*AddressParameters, error)
NewReceiveAddress derives, stores, imports and activates the next receive family static address. It is used by `loop static new`.
func (*Manager) PrepareChangeAddress ¶
func (m *Manager) PrepareChangeAddress(ctx context.Context) (*AddressParameters, error)
PrepareChangeAddress derives the next change address without persisting or importing it. It first ensures that the shared static address root exists. The caller must activate these same parameters before signing a spend to it.
type ManagerConfig ¶
type ManagerConfig struct {
// AddressClient is the client that communicates with the loop server
// to manage static addresses.
AddressClient staticaddressrpc.StaticAddressServerClient
// FetchL402 is the function used to fetch the l402 token.
FetchL402 func(context.Context) error
// Store is the database store that is used to store static address
// related records.
Store Store
// WalletKit is the wallet client that is used to derive new keys from
// lnd's wallet.
WalletKit lndclient.WalletKitClient
// ChainParams is the chain configuration(mainnet, testnet...) this
// manager uses.
ChainParams *chaincfg.Params
// ChainNotifier is the chain notifier that is used to listen for new
// blocks.
ChainNotifier lndclient.ChainNotifierClient
}
ManagerConfig holds the configuration for the address manager.
type SqlStore ¶
type SqlStore struct {
// contains filtered or unexported fields
}
SqlStore is the backing store for static addresses.
func NewSqlStore ¶
NewSqlStore constructs a new SQLStore from a BaseDB. The BaseDB is agnostic to the underlying driver which can be postgres or sqlite.
func (*SqlStore) CreateStaticAddress ¶
func (s *SqlStore) CreateStaticAddress(ctx context.Context, addrParams *AddressParameters) error
CreateStaticAddress creates a static address record in the database.
func (*SqlStore) GetAllStaticAddresses ¶
func (s *SqlStore) GetAllStaticAddresses(ctx context.Context) ( []*AddressParameters, error)
GetAllStaticAddresses returns all addresses known to the client.
func (*SqlStore) GetLegacyParameters ¶
func (s *SqlStore) GetLegacyParameters(ctx context.Context) (*AddressParameters, error)
GetLegacyParameters returns the first static address created for this L402.
func (*SqlStore) GetMaxStaticAddressHtlcKeyIndex ¶
func (s *SqlStore) GetMaxStaticAddressHtlcKeyIndex(ctx context.Context, family keychain.KeyFamily) (uint32, bool, error)
GetMaxStaticAddressHtlcKeyIndex returns the highest client key index of the given family used by a static address loop-in HTLC.
func (*SqlStore) GetStaticAddressID ¶
GetStaticAddressID retrieves the database ID for a static address script.
func (*SqlStore) ListStaticAddresses ¶
func (s *SqlStore) ListStaticAddresses(ctx context.Context, afterID, limit int32) ([]*AddressParameters, error)
ListStaticAddresses loads one bounded page without offset scans.
type Store ¶
type Store interface {
// CreateStaticAddress inserts a new static address with its parameters
// into the store.
CreateStaticAddress(ctx context.Context, addrParams *AddressParameters) error
// GetStaticAddressID retrieves the static address row ID for the
// address script.
GetStaticAddressID(ctx context.Context, pkScript []byte) (int32, error)
// ListStaticAddresses retrieves up to limit addresses in ascending ID
// order, strictly after afterID. Use zero to start from the beginning.
ListStaticAddresses(ctx context.Context, afterID, limit int32) (
[]*AddressParameters, error)
// GetAllStaticAddresses retrieves all static addresses from the store.
GetAllStaticAddresses(ctx context.Context) ([]*AddressParameters, error)
// GetLegacyParameters retrieves the first static address created for the
// L402. This is the immutable legacy/root address that anchors existing
// single-address deposits.
GetLegacyParameters(ctx context.Context) (*AddressParameters, error)
// GetMaxStaticAddressHtlcKeyIndex returns the highest client key index
// of the given family used by a static address loop-in HTLC. The boolean
// is false if no such HTLC key exists.
GetMaxStaticAddressHtlcKeyIndex(ctx context.Context,
family keychain.KeyFamily) (uint32, bool, error)
}
Store is the database interface that is used to store and retrieve static addresses.