lndrpc

package
v0.7.0-rc.9 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2026 License: AGPL-3.0 Imports: 24 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package lndrpc provides a gRPC client for LND.

Ordinary credential reads use root-staged files readable by the admin user. Initialization and reconnect repair may ask the helper to refresh those files. The client holds the macaroon in memory and injects it into authenticated RPCs; reconnect can replace the loaded credentials.

Connections use TLS to the loopback address. Close shuts down the current transport; it does not provide secure credential erasure.

Read queries and fund-moving RPCs share this one client; every fund-moving call sits behind an explicit confirmation flow in its caller.

Index

Constants

This section is empty.

Variables

View Source
var ErrInvoiceNotFound = errors.New("invoice not found")

ErrInvoiceNotFound means LND has no record for the queried payment hash.

Functions

func NormalizeChannelPoint

func NormalizeChannelPoint(point string) (string, error)

NormalizeChannelPoint validates an exact funding outpoint and returns its canonical display form for request and identity comparisons.

Types

type Channel

type Channel struct {
	ChanID         uint64
	ChannelPoint   string // "txid:index"
	RemotePubkey   string
	Capacity       int64
	LocalBalance   int64
	RemoteBalance  int64
	Active         bool
	Private        bool
	Initiator      bool
	PeerAlias      string
	CommitmentType string // "TAPROOT", "ANCHORS", etc.
}

type ChannelCloseRequest

type ChannelCloseRequest struct {
	ChannelPoint string
	Force        bool
	SatPerVbyte  uint64
}

type ChannelCloseResult

type ChannelCloseResult struct {
	Submitted   bool
	Confirmed   bool
	ClosingTxid string
	Err         error
}

Submitted means the RPC was attempted, not that LND accepted the close. A pending transaction is a candidate, and confirmation does not prove that force-close outputs have matured or been swept.

type ChannelCloseState

type ChannelCloseState struct {
	Found        bool
	Active       bool
	StatusFlags  string
	PendingHTLCs int
	Closing      bool
}

type ChannelOpenRequest

type ChannelOpenRequest struct {
	Pubkey                    string
	AmountSats                int64
	Private, Taproot, FundMax bool
	Outpoints                 []string
	SatPerVbyte               uint64
	MinConfs                  int32
	SpendUnconfirmed          bool
}

type ChannelOpenResult

type ChannelOpenResult struct {
	FundingTxID string
	OutputIndex uint32
	Submitted   bool
	Err         error
}

Submitted means the funding RPC was attempted, even if its response was lost. It does not imply that LND accepted or broadcast the transaction.

type Client

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

Client wraps an LND gRPC connection with macaroon authentication.

func NewContext

func NewContext(ctx context.Context) (*Client, error)

NewContext initializes an existing wallet's client with the caller's lifetime. An unavailable GetInfo response retains the transport for normal queries; unreadable staged credentials and cancellation return no client. Startup uses the existing probe and rate-limited repair policy, not the creation path.

func NewStagedClient

func NewStagedClient() (*Client, error)

NewStagedClient opens a lazy transport from credentials already staged by the wallet workflow. It does no GetInfo probe or repair and does not claim RPC readiness. Normal queries observe readiness using the existing client policy.

func (*Client) AddInvoice

func (c *Client) AddInvoice(amountSats int64, memo string, blind bool) (*Invoice, error)

AddInvoice creates a new Lightning invoice. When blind is true, LND generates blinded paths that hide the node's pubkey from the sender. Requires at least one active channel with sufficient inbound capacity.

func (*Client) ChannelCloseState

func (c *Client) ChannelCloseState(point string) (ChannelCloseState, error)

ChannelCloseState reads only close eligibility facts, without alias lookups. Both reads share a timeout, but they are not an atomic snapshot or a lock.

func (*Client) Close

func (c *Client) Close()

Close shuts down the current gRPC transport. It does not cancel or retire queued background reconnects, which may establish a later connection.

func (*Client) CloseChannel

func (c *Client) CloseChannel(input ChannelCloseRequest) ChannelCloseResult

CloseChannel makes one bounded submission and waits for a pending or confirmed transaction. Canceling the stream is not evidence that LND canceled the close.

func (*Client) ConnectPeer

func (c *Client) ConnectPeer(pubkey, host string) error

ConnectPeer connects to a Lightning peer. Uses perm=true for persistent connection. Does not fail if already connected.

func (*Client) DecodePayReq

func (c *Client) DecodePayReq(payReq string) (*DecodedPayReq, error)

DecodePayReq decodes a bolt11 payment request without paying it.

func (*Client) GetInfo

func (c *Client) GetInfo() (*NodeInfo, error)

func (*Client) GetInfoContext

func (c *Client) GetInfoContext(parent context.Context) (*NodeInfo, error)

func (*Client) GetNewAddress

func (c *Client) GetNewAddress() (*OnChainAddress, error)

func (*Client) GetPendingChannels

func (c *Client) GetPendingChannels() (*PendingChannelInfo, error)

func (*Client) GetPendingChannelsContext

func (c *Client) GetPendingChannelsContext(parent context.Context) (*PendingChannelInfo, error)

func (*Client) GetState

func (c *Client) GetState() (WalletState, error)

GetState uses LND's state service, which remains available while the wallet is locked. This lets status distinguish an intentionally running-but-locked daemon from a stopped daemon or a generic RPC outage.

func (*Client) GetStateContext

func (c *Client) GetStateContext(parent context.Context) (WalletState, error)

func (*Client) GetTransactions

func (c *Client) GetTransactions() ([]OnChainTx, error)

func (*Client) GetTransactionsContext

func (c *Client) GetTransactionsContext(parent context.Context) ([]OnChainTx, error)

func (*Client) GetWalletBalance

func (c *Client) GetWalletBalance() (*WalletBalance, error)

func (*Client) GetWalletBalanceContext

func (c *Client) GetWalletBalanceContext(parent context.Context) (*WalletBalance, error)

func (*Client) ListChannels

func (c *Client) ListChannels() ([]Channel, error)

func (*Client) ListChannelsContext

func (c *Client) ListChannelsContext(parent context.Context) ([]Channel, error)

func (*Client) ListClosedChannels

func (c *Client) ListClosedChannels() (
	[]ClosedChannel, error,
)

ListClosedChannels returns all historically closed channels with close type and peer info.

func (*Client) ListClosedChannelsContext

func (c *Client) ListClosedChannelsContext(parent context.Context) ([]ClosedChannel, error)

func (*Client) ListInvoicesContext

func (c *Client) ListInvoicesContext(parent context.Context, limit uint64) ([]PaymentEntry, error)

ListInvoicesContext returns the recent invoice window, including unsettled invoices.

func (*Client) ListPaymentsContext

func (c *Client) ListPaymentsContext(parent context.Context, limit uint64) ([]PaymentEntry, error)

ListPaymentsContext returns recent outgoing payments, including incomplete attempts.

func (*Client) ListPeers

func (c *Client) ListPeers() ([]PeerInfo, error)

ListPeers returns currently connected peers.

func (*Client) ListUnspent

func (c *Client) ListUnspent(
	minConfs, maxConfs int32,
) ([]UTXO, error)

func (*Client) ListUnspentContext

func (c *Client) ListUnspentContext(parent context.Context, minConfs, maxConfs int32) ([]UTXO, error)

func (*Client) LookupInvoice

func (c *Client) LookupInvoice(paymentHash []byte) (*Invoice, error)

LookupInvoice checks the status of an invoice by payment hash.

func (*Client) OpenChannel

func (c *Client) OpenChannel(input ChannelOpenRequest) ChannelOpenResult

OpenChannel submits one funding request. The explicit outpoints restrict LND's funding pool; LND determines which coins to use and whether change is needed.

func (*Client) Reconnect

func (c *Client) Reconnect()

Reconnect attempts to re-establish the gRPC connection. Called when an RPC fails, indicating LND may have restarted.

func (*Client) ReconnectContext

func (c *Client) ReconnectContext(ctx context.Context)

ReconnectContext observes the caller's lifetime for the connection probe and credential restaging. A cancelled caller cannot schedule a later reconnect.

func (*Client) SendCoins

func (c *Client) SendCoins(input SendCoinsRequest) (*SendCoinsResult, error)

func (*Client) SendPayment

func (c *Client) SendPayment(payReq string) (*SendPaymentResult, error)

SendPayment sends a payment using SendPaymentV2 (streaming). Blocks until the payment succeeds, fails, or times out. Returns route hops on success for visualization.

If the update stream drops before a terminal status, the payment may still be running inside LND, and the one wrong answer is reporting failure — an operator who retries a payment that later settles has paid twice. The stream is re-attached by payment hash instead, and if no terminal status arrives before the deadline the result says IN_FLIGHT with an instruction to check history before retrying.

func (*Client) SetTransactionLabel

func (c *Client) SetTransactionLabel(input TransactionLabelRequest) TransactionLabelResult

func (*Client) WaitForPeer

func (c *Client) WaitForPeer(pubkey string, timeout time.Duration) error

WaitForPeer polls ListPeers until the pubkey appears. The timeout limits starting new polls, not lock waits or an in-flight RPC. The last poll can succeed after the interval, so this is not a total wall-clock bound.

type ClosedChannel

type ClosedChannel struct {
	ChannelPoint string
	RemotePubkey string
	Capacity     int64
	CloseType    string
	ClosingTxid  string
	PeerAlias    string
	SettledBal   int64
	CloseHeight  int32
}

type DecodedPayReq

type DecodedPayReq struct {
	Destination string
	AmountSats  int64
	Description string
	PaymentHash string
	Expiry      int64
	Timestamp   int64
	IsExpired   bool
}

type Invoice

type Invoice struct {
	PaymentRequest string
	PaymentHash    string
	AmountSats     int64
	Memo           string
	Settled        bool
	Canceled       bool
	CreationDate   int64
	SettleDate     int64
	Expiry         int64
	IsExpired      bool
}

type NodeInfo

type NodeInfo struct {
	Pubkey      string
	Alias       string
	Channels    int
	Peers       int
	BlockHeight int
	SyncedChain bool
	SyncedGraph bool
	Version     string
	URIs        []string // LND's advertised node URIs
}

type OnChainAddress

type OnChainAddress struct {
	Address string
}

type OnChainTx

type OnChainTx struct {
	Txid           string
	Amount         int64
	Fee            int64
	Confirmations  int32
	BlockHeight    int32
	Timestamp      int64
	Label          string
	RawTxHex       string
	TxType         string // "send", "receive", "channel_open", "channel_close"
	ChannelPeer    string // peer alias for channel open/close
	Inputs         []TxInput
	Outputs        []TxOutput
	TotalInputSats int64
	IsAnchorSweep  bool // abandoned anchor sweep (0 confs, ≤330 sats)
}

type PaymentEntry

type PaymentEntry struct {
	Index          uint64 // LND invoice add index or outgoing payment index.
	PaymentHash    string
	AmountSats     int64
	FeeSats        int64
	Status         string // Native payment/invoice state, with EXPIRED derived for open invoices.
	CreationDate   int64
	Preimage       string
	PaymentRequest string
	IsIncoming     bool
	Memo           string
	Hops           []RouteHop
}

type PeerInfo

type PeerInfo struct {
	PubKey  string
	Address string
	Inbound bool
	SatSent int64
	SatRecv int64
}

type PendingChannel

type PendingChannel struct {
	ChannelPoint string
	RemotePubkey string
	Capacity     int64
	LocalBalance int64
	PeerAlias    string
}

type PendingChannelInfo

type PendingChannelInfo struct {
	PendingOpen               int
	ForceClose                int
	WaitingClose              int
	PendingOpenChannels       []PendingChannel
	PendingForceCloseChannels []PendingForceCloseChannel
	WaitingCloseChannels      []WaitingCloseChannel
}

type PendingForceCloseChannel

type PendingForceCloseChannel struct {
	RemotePubkey     string
	ChannelPoint     string
	Capacity         int64
	LocalBalance     int64
	LimboBalance     int64
	RecoveredBalance int64
	ClosingTxid      string
	MaturityHeight   int32
	BlocksRemaining  int32
	PeerAlias        string
}

type RouteHop

type RouteHop struct {
	PubKey   string
	Alias    string
	ChanID   uint64
	FeeSats  int64
	AmtToFwd int64
}

type SendCoinsRequest

type SendCoinsRequest struct {
	Address          string
	AmountSats       int64
	SatPerVbyte      int64
	SendAll          bool
	Label            string
	Outpoints        []string
	MinConfs         int32
	SpendUnconfirmed bool
}

type SendCoinsResult

type SendCoinsResult struct {
	Txid string
}

type SendPaymentResult

type SendPaymentResult struct {
	Preimage string
	FeeSats  int64
	Status   string
	Hops     []RouteHop
	Error    string
}

SendPaymentResult holds the outcome of a payment attempt.

type TransactionLabelRequest

type TransactionLabelRequest struct {
	Txid  chainhash.Hash
	Label string
}

TransactionLabelRequest carries app-validated intent in wallet byte order.

type TransactionLabelResult

type TransactionLabelResult struct {
	Submitted bool
	Err       error
}

TransactionLabelResult distinguishes a local refusal from an attempted RPC. Submitted alone does not confirm a wallet write.

type TxInput

type TxInput struct {
	Outpoint string // "txid:vout" format
	PrevTxid string
	PrevVout uint32
	IsOurs   bool
	Amount   int64
}

type TxOutput

type TxOutput struct {
	Address string
	Amount  int64
	IsLocal bool   // true if address belongs to our wallet
	Label   string // "destination", "change", "channel"
}

type UTXO

type UTXO struct {
	Txid          string
	Vout          int
	AmountSats    int64
	Confirmations int64
	Address       string
	PkScript      string
}

type WaitingCloseChannel

type WaitingCloseChannel struct {
	RemotePubkey string
	ChannelPoint string
	Capacity     int64
	LocalBalance int64
	LimboBalance int64
	ClosingTxid  string
	PeerAlias    string
}

type WalletBalance

type WalletBalance struct {
	TotalBalance       string
	ConfirmedBalance   string
	UnconfirmedBalance string
}

type WalletState

type WalletState string

WalletState is LND's live readiness state, exposed without leaking the generated protobuf type into the TUI.

const (
	WalletStateUnknown WalletState = "UNKNOWN"
	WalletStateLocked  WalletState = "LOCKED"
	WalletStateActive  WalletState = "SERVER_ACTIVE"
)

func ReadWalletSetupState

func ReadWalletSetupState(parent context.Context) (WalletState, error)

ReadWalletSetupState uses the unauthenticated State service. Wallet creation cannot require a macaroon that only exists after the wallet is initialized. It neither probes GetInfo nor requests credential repair.

Jump to

Keyboard shortcuts

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