lnd

package
v0.2.97 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2022 License: MIT Imports: 35 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetBitcoinChain

func GetBitcoinChain(ctx context.Context, li lnrpc.LightningClient) (*chaincfg.Params, error)

func GetClientConnection

func GetClientConnection(ctx context.Context, cfg *peerswaplnd.LndConfig) (*grpc.ClientConn, error)

func IsContextError

func IsContextError(err error) bool

IsContextError returns true if the error is of grpc error type Canceled or DeadlineExceeded. A ContextError always indicates that a grpc stream was closed by the client side.

func LndShortChannelIdToCLShortChannelId

func LndShortChannelIdToCLShortChannelId(lndCI lnwire.ShortChannelID) string

func WaitForReady

func WaitForReady(conn *grpc.ClientConn, timeout time.Duration) error

WaitForReady checks on the status of a grpc client connection. We wait until the connection is READY or until timeout. Is a blocking call. Returns an error on timeout.

Types

type Client

type Client struct {
	sync.Mutex
	// contains filtered or unexported fields
}

Client combines multiple methods, functions and watchers to a service that is consumed by the swap service. Client fulfils the swap.LightningClient interface. TODO: Rework the swap.LightningClient interface to separate the watchers from the client service. This will make it easier to test and more modular to use.

func NewClient

func NewClient(
	ctx context.Context,
	cc *grpc.ClientConn,
	paymentWatcher *PaymentWatcher,
	messageListener *MessageListener,
	chain *onchain.BitcoinOnChain,
) (*Client, error)

func (*Client) AddMessageHandler

func (l *Client) AddMessageHandler(f func(peerId string, msgType string, payload []byte) error)

func (*Client) AddPaymentCallback

func (l *Client) AddPaymentCallback(f func(swapId string, invoiceType swap.InvoiceType))

func (*Client) AddPaymentNotifier

func (l *Client) AddPaymentNotifier(swapId string, payreq string, invoiceType swap.InvoiceType)

func (*Client) BroadcastOpeningTx

func (l *Client) BroadcastOpeningTx(unpreparedTxHex string) (txId, txHex string, error error)

func (*Client) CheckChannel

func (l *Client) CheckChannel(shortChannelId string, amountSat uint64) (*lnrpc.Channel, error)

func (*Client) CreateCoopSpendingTransaction

func (l *Client) CreateCoopSpendingTransaction(swapParams *swap.OpeningParams, claimParams *swap.ClaimParams, takerSigner swap.Signer) (txId, txHex string, error error)

func (*Client) CreateCsvSpendingTransaction

func (l *Client) CreateCsvSpendingTransaction(swapParams *swap.OpeningParams, claimParams *swap.ClaimParams) (string, string, error)

func (*Client) CreateOpeningTransaction

func (l *Client) CreateOpeningTransaction(swapParams *swap.OpeningParams) (unpreparedTxHex string, fee uint64, vout uint32, err error)

func (*Client) CreatePreimageSpendingTransaction

func (l *Client) CreatePreimageSpendingTransaction(swapParams *swap.OpeningParams, claimParams *swap.ClaimParams) (string, string, error)

func (*Client) DecodePayreq

func (l *Client) DecodePayreq(payreq string) (paymentHash string, amountMsat uint64, expiry int64, err error)

func (*Client) GetAsset

func (cl *Client) GetAsset() string

func (*Client) GetFlatSwapOutFee

func (l *Client) GetFlatSwapOutFee() (uint64, error)

GetFlatSwapOutFee returns an estimated size for the opening transaction. This can be used to calculate the amount of the fee invoice and should cover most but not all cases. For an explanation of the estimation see comments of the onchain.EstimatedOpeningTxSize.

func (*Client) GetNetwork

func (cl *Client) GetNetwork() string

func (*Client) GetOnchainBalance

func (l *Client) GetOnchainBalance() (uint64, error)

func (*Client) GetOutputScript

func (l *Client) GetOutputScript(params *swap.OpeningParams) ([]byte, error)

func (*Client) GetPayreq

func (l *Client) GetPayreq(msatAmount uint64, preimageString string, swapId string, memo string, invoiceType swap.InvoiceType, expirySeconds, expiryCltv uint64) (string, error)

func (*Client) GetPeers

func (l *Client) GetPeers() []string

func (*Client) GetRefundFee

func (l *Client) GetRefundFee() (uint64, error)

func (*Client) NewAddress

func (l *Client) NewAddress() (string, error)

func (*Client) PayInvoice

func (l *Client) PayInvoice(payreq string) (preImage string, err error)

func (*Client) PayInvoiceViaChannel

func (l *Client) PayInvoiceViaChannel(payreq, scid string) (preimage string, err error)

func (*Client) PrepareOpeningTransaction

func (l *Client) PrepareOpeningTransaction(address string, amount uint64) (txId string, txHex string, err error)

func (*Client) RebalancePayment

func (l *Client) RebalancePayment(payreq string, channelId string) (preimage string, err error)

func (*Client) SendMessage

func (l *Client) SendMessage(peerId string, message []byte, messageType int) error

func (*Client) StartListening

func (l *Client) StartListening() error

type LndFeeEstimator

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

func NewLndFeeEstimator

func NewLndFeeEstimator(ctx context.Context, walletkit walletrpc.WalletKitClient) *LndFeeEstimator

type MessageListener

type MessageListener struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func NewMessageListener

func NewMessageListener(ctx context.Context, cc *grpc.ClientConn) (*MessageListener, error)

func (*MessageListener) AddMessageHandler

func (m *MessageListener) AddMessageHandler(f func(peerId string, msgType string, payload []byte) error)

func (*MessageListener) Start

func (m *MessageListener) Start() error

func (*MessageListener) Stop

func (m *MessageListener) Stop()

type PaymentWatcher

type PaymentWatcher struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func NewPaymentWatcher

func NewPaymentWatcher(ctx context.Context, cc *grpc.ClientConn) (*PaymentWatcher, error)

func (*PaymentWatcher) AddPaymentCallback

func (p *PaymentWatcher) AddPaymentCallback(f func(swapId string, invoiceType swap.InvoiceType))

func (*PaymentWatcher) AddWaitForPayment

func (p *PaymentWatcher) AddWaitForPayment(swapId string, payreq string, invoiceType swap.InvoiceType)

func (*PaymentWatcher) Stop

func (p *PaymentWatcher) Stop() error

type PeerListener

type PeerListener struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func NewPeerListener

func NewPeerListener(ctx context.Context, cc *grpc.ClientConn) (*PeerListener, error)

func (*PeerListener) AddHandler

func (p *PeerListener) AddHandler(evt lnrpc.PeerEvent_EventType, f func(string)) error

func (*PeerListener) Stop

func (p *PeerListener) Stop()

type TxWatcher

type TxWatcher struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func NewTxWatcher

func NewTxWatcher(ctx context.Context, cc *grpc.ClientConn, network *chaincfg.Params, targetConfirmation, targetCsv uint32) (*TxWatcher, error)

func (*TxWatcher) AddConfirmationCallback

func (t *TxWatcher) AddConfirmationCallback(cb func(swapId string, txHex string) error)

AddConfirmationCallback adds a callback to the watcher that will be called in the case that an active "wait for confirmation" watcher reached the confirmation limit for a swap.

func (*TxWatcher) AddCsvCallback

func (t *TxWatcher) AddCsvCallback(cb func(swapId string) error)

AddCsvCallback adds a callback to the watcher that will be called in the case that an active "wait for csv limit reached" watcher reached the csv limit for a swap.

func (*TxWatcher) AddWaitForConfirmationTx

func (t *TxWatcher) AddWaitForConfirmationTx(swapId string, txId string, _ uint32, heightHint uint32, script []byte)

AddWaitForConfirmationTx subscribes to the lnd onchain tx watcher and calls the callback as soon as the tx is confirmed. The empty uint32 parameter is due to the Watcher interface of swap expecting a signature with a vout parameter.

func (*TxWatcher) AddWaitForCsvTx

func (t *TxWatcher) AddWaitForCsvTx(swapId string, txId string, vout uint32, heightHint uint32, script []byte)

AddWaitForConfirmationTx subscribes to the lnd onchain tx watcher and calls the callback as soon as the tx is above the csv limit.

func (*TxWatcher) GetBlockHeight

func (t *TxWatcher) GetBlockHeight() (uint32, error)

GetBlockHeight returns the current best block from the GetInfo call. Beware that this hight is the best block from the nodes view.

func (*TxWatcher) Start

func (t *TxWatcher) Start() error

func (*TxWatcher) Stop

func (t *TxWatcher) Stop() error

Jump to

Keyboard shortcuts

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