clightning

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: 31 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrWaitingForReady = fmt.Errorf("peerswap is still in the process of starting up")

Functions

func MppPayment

func MppPayment(spw SendPayPartWaiter, payreq string, channel string, bolt11 *glightning.DecodedBolt11) (string, error)

MppPayment splits the payment in parts and waits for the payments to finish. We split in 10 parts as this will always result in a set of payments that dont have a "rest" and are all of the exact same size. They match the total amount that we want to transfer. As we only send over a direct channel to a direct peer we also dont need to optimize on a small number of subpayments.

Types

type AddPeer

type AddPeer struct {
	PeerPubkey string `json:"peer_pubkey"`
	// contains filtered or unexported fields
}

func (*AddPeer) Call

func (g *AddPeer) Call() (jrpc2.Result, error)

func (AddPeer) Description

func (c AddPeer) Description() string

func (*AddPeer) Get

func (g *AddPeer) Get(client *ClightningClient) jrpc2.ServerMethod

func (AddPeer) LongDescription

func (c AddPeer) LongDescription() string

func (*AddPeer) Name

func (g *AddPeer) Name() string

func (*AddPeer) New

func (g *AddPeer) New() interface{}

type AddSuspiciousPeer

type AddSuspiciousPeer struct {
	PeerPubkey string `json:"peer_pubkey"`
	// contains filtered or unexported fields
}

func (*AddSuspiciousPeer) Call

func (g *AddSuspiciousPeer) Call() (jrpc2.Result, error)

func (AddSuspiciousPeer) Description

func (c AddSuspiciousPeer) Description() string

func (*AddSuspiciousPeer) Get

func (AddSuspiciousPeer) LongDescription

func (c AddSuspiciousPeer) LongDescription() string

func (*AddSuspiciousPeer) Name

func (g *AddSuspiciousPeer) Name() string

func (*AddSuspiciousPeer) New

func (g *AddSuspiciousPeer) New() interface{}

type AllowSwapRequests

type AllowSwapRequests struct {
	AllowSwapRequestsString string `json:"allow_swap_requests"`
	// contains filtered or unexported fields
}

func (*AllowSwapRequests) Call

func (g *AllowSwapRequests) Call() (jrpc2.Result, error)

func (AllowSwapRequests) Description

func (c AllowSwapRequests) Description() string

func (*AllowSwapRequests) Get

func (AllowSwapRequests) LongDescription

func (c AllowSwapRequests) LongDescription() string

func (*AllowSwapRequests) Name

func (g *AllowSwapRequests) Name() string

func (*AllowSwapRequests) New

func (g *AllowSwapRequests) New() interface{}

type ClightningClient

type ClightningClient struct {
	Plugin *glightning.Plugin

	Gelements *gelements.Elements
	// contains filtered or unexported fields
}

ClightningClient is the main driver behind c-lightnings plugins system it handles rpc calls and messages

func NewClightningClient

func NewClightningClient(ctx context.Context) (*ClightningClient, <-chan interface{}, error)

NewClightningClient returns a new clightning cl and channel which get closed when the Plugin is initialized

func (*ClightningClient) AddMessageHandler

func (cl *ClightningClient) AddMessageHandler(f func(peerId string, msgType string, payload []byte) error)

AddMessageHandler adds a listener for incoming peermessages

func (*ClightningClient) AddPaymentCallback

func (cl *ClightningClient) AddPaymentCallback(f func(swapId string, invoiceType swap.InvoiceType))

func (*ClightningClient) AddPaymentNotifier

func (cl *ClightningClient) AddPaymentNotifier(swapId string, payreq string, invoiceType swap.InvoiceType)

func (*ClightningClient) BroadcastOpeningTx

func (cl *ClightningClient) BroadcastOpeningTx(unpreparedTxHex string) (txId, txHex string, error error)

func (*ClightningClient) CheckChannel

func (cl *ClightningClient) CheckChannel(channelId string, amountSat uint64) error

CheckChannel checks if a channel is eligable for a swap

func (*ClightningClient) CreateCoopSpendingTransaction

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

func (*ClightningClient) CreateCsvSpendingTransaction

func (cl *ClightningClient) CreateCsvSpendingTransaction(swapParams *swap.OpeningParams, claimParams *swap.ClaimParams) (txId, txHex string, error error)

func (*ClightningClient) CreateOpeningTransaction

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

func (*ClightningClient) CreatePreimageSpendingTransaction

func (cl *ClightningClient) CreatePreimageSpendingTransaction(swapParams *swap.OpeningParams, claimParams *swap.ClaimParams) (txId, txHex string, err error)

func (*ClightningClient) DecodePayreq

func (cl *ClightningClient) DecodePayreq(payreq string) (paymentHash string, amountMsat uint64, expiry int64, err error)

DecodePayreq decodes a Bolt11 Invoice

func (*ClightningClient) GetAsset

func (cl *ClightningClient) GetAsset() string

func (*ClightningClient) GetConfig

func (cl *ClightningClient) GetConfig() (*PeerswapClightningConfig, error)

GetConfig returns the peerswap config

func (*ClightningClient) GetFlatSwapOutFee

func (cl *ClightningClient) 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 (*ClightningClient) GetLightningRpc

func (cl *ClightningClient) GetLightningRpc() *glightning.Lightning

func (*ClightningClient) GetNetwork

func (cl *ClightningClient) GetNetwork() string

func (*ClightningClient) GetNodeId

func (cl *ClightningClient) GetNodeId() string

GetNodeId returns the lightning nodes pubkey

func (*ClightningClient) GetOnchainBalance

func (cl *ClightningClient) GetOnchainBalance() (uint64, error)

func (*ClightningClient) GetOutputScript

func (cl *ClightningClient) GetOutputScript(params *swap.OpeningParams) ([]byte, error)

func (*ClightningClient) GetPayreq

func (cl *ClightningClient) GetPayreq(amountMsat uint64, preImage string, swapId string, memo string, invoiceType swap.InvoiceType, expirySeconds, expiryCltv uint64) (string, error)

GetPayreq returns a Bolt11 Invoice

func (*ClightningClient) GetPeers

func (cl *ClightningClient) GetPeers() []string

func (*ClightningClient) GetPreimage

func (cl *ClightningClient) GetPreimage() (lightning.Preimage, error)

GetPreimage returns a random preimage

func (*ClightningClient) GetRefundFee

func (cl *ClightningClient) GetRefundFee() (uint64, error)

func (*ClightningClient) NewAddress

func (cl *ClightningClient) NewAddress() (string, error)

func (*ClightningClient) OnConnect

func (cl *ClightningClient) OnConnect(connectEvent *glightning.ConnectEvent)

OnConnect is called after the connect event. The handler sends out a poll to the peer it connected to.

func (*ClightningClient) OnCustomMsg

OnCustomMsg is the hook that c-lightning calls

func (*ClightningClient) PayInvoice

func (cl *ClightningClient) PayInvoice(payreq string) (preimage string, err error)

PayInvoice tries to pay a Bolt11 Invoice

func (*ClightningClient) PayInvoiceViaChannel

func (cl *ClightningClient) PayInvoiceViaChannel(payreq string, scid string) (preimage string, err error)

PayInvoiceViaChannel ensures that the invoice is payed via the direct channel to the peer.

func (*ClightningClient) RebalancePayment

func (cl *ClightningClient) RebalancePayment(payreq string, channel string) (preimage string, err error)

RebalancePayment handles the lightning payment that should rebalance the channel if the payment is larger than 4mm sats it forces a mpp payment through the channel

func (*ClightningClient) RegisterMethods

func (cl *ClightningClient) RegisterMethods() error

RegisterMethods registeres rpc methods to c-lightning

func (*ClightningClient) RegisterOptions

func (cl *ClightningClient) RegisterOptions() error

RegisterOptions adds options to clightning

func (*ClightningClient) SendMessage

func (cl *ClightningClient) SendMessage(peerId string, message []byte, messageType int) error

SendMessage sends a hexmessage to a peer

func (*ClightningClient) SendPayPart

func (cl *ClightningClient) SendPayPart(payreq string, bolt11 *glightning.DecodedBolt11, amountMsat uint64, channel string, label string, partId uint64) (*glightning.SendPayResult, error)

SendPayPart sends a payment through a specific channel. If the partId is not 0 it sends only the part of the payment that is set on amountMsat. the final amount is read from the bolt11.

func (*ClightningClient) SendPayPartAndWait

func (cl *ClightningClient) SendPayPartAndWait(paymentRequest string, bolt11 *glightning.DecodedBolt11, amountMsat uint64, channel string, label string, partId uint64) (*glightning.SendPayFields, error)

func (*ClightningClient) SetReady

func (cl *ClightningClient) SetReady()

func (*ClightningClient) SetupClients

func (cl *ClightningClient) SetupClients(liquidWallet *wallet.ElementsRpcWallet,
	swaps *swap.SwapService,
	policy PolicyReloader, requestedSwaps *swap.RequestedSwapsPrinter, elements *gelements.Elements,
	bitcoin *gbitcoin.Bitcoin, bitcoinChain *onchain.BitcoinOnChain, pollService *poll.Service)

SetupClients injects the required services

func (*ClightningClient) Start

func (cl *ClightningClient) Start() error

Start starts the Plugin

type GetAddressResponse

type GetAddressResponse struct {
	LiquidAddress string `json:"lbtc_address"`
}

type GetBalanceResponse

type GetBalanceResponse struct {
	LiquidBalance uint64 `json:"lbtc_balance_sat"`
}

type GetRequestedSwaps

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

func (GetRequestedSwaps) Call

func (c GetRequestedSwaps) Call() (jrpc2.Result, error)

func (GetRequestedSwaps) Description

func (c GetRequestedSwaps) Description() string

func (*GetRequestedSwaps) Get

func (GetRequestedSwaps) LongDescription

func (c GetRequestedSwaps) LongDescription() string

func (GetRequestedSwaps) Name

func (c GetRequestedSwaps) Name() string

func (GetRequestedSwaps) New

func (c GetRequestedSwaps) New() interface{}

type GetSwap

type GetSwap struct {
	SwapId string `json:"swap_id"`
	// contains filtered or unexported fields
}

func (*GetSwap) Call

func (g *GetSwap) Call() (jrpc2.Result, error)

func (*GetSwap) Description

func (g *GetSwap) Description() string

func (*GetSwap) Get

func (g *GetSwap) Get(client *ClightningClient) jrpc2.ServerMethod

func (*GetSwap) LongDescription

func (g *GetSwap) LongDescription() string

func (*GetSwap) Name

func (g *GetSwap) Name() string

func (*GetSwap) New

func (g *GetSwap) New() interface{}

type Glightninglogger

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

func NewGlightninglogger

func NewGlightninglogger(plugin *glightning.Plugin) *Glightninglogger

func (*Glightninglogger) Debugf

func (g *Glightninglogger) Debugf(format string, v ...interface{})

func (*Glightninglogger) Infof

func (g *Glightninglogger) Infof(format string, v ...interface{})

type LiquidGetAddress

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

LiquidGetAddress returns a new liquid address

func (*LiquidGetAddress) Call

func (g *LiquidGetAddress) Call() (jrpc2.Result, error)

func (*LiquidGetAddress) Description

func (g *LiquidGetAddress) Description() string

func (*LiquidGetAddress) Get

func (*LiquidGetAddress) LongDescription

func (g *LiquidGetAddress) LongDescription() string

func (*LiquidGetAddress) Name

func (g *LiquidGetAddress) Name() string

func (*LiquidGetAddress) New

func (g *LiquidGetAddress) New() interface{}

type LiquidGetBalance

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

GetBalance returns the liquid balance

func (*LiquidGetBalance) Call

func (g *LiquidGetBalance) Call() (jrpc2.Result, error)

func (*LiquidGetBalance) Description

func (g *LiquidGetBalance) Description() string

func (*LiquidGetBalance) Get

func (*LiquidGetBalance) LongDescription

func (g *LiquidGetBalance) LongDescription() string

func (*LiquidGetBalance) Name

func (g *LiquidGetBalance) Name() string

func (*LiquidGetBalance) New

func (g *LiquidGetBalance) New() interface{}

type LiquidSendToAddress

type LiquidSendToAddress struct {
	Address   string `json:"address"`
	AmountSat uint64 `json:"amount_sat"`
	// contains filtered or unexported fields
}

LiquidSendToAddress sends

func (*LiquidSendToAddress) Call

func (s *LiquidSendToAddress) Call() (jrpc2.Result, error)

func (*LiquidSendToAddress) Description

func (s *LiquidSendToAddress) Description() string

func (*LiquidSendToAddress) Get

func (*LiquidSendToAddress) LongDescription

func (s *LiquidSendToAddress) LongDescription() string

func (*LiquidSendToAddress) Name

func (s *LiquidSendToAddress) Name() string

func (*LiquidSendToAddress) New

func (s *LiquidSendToAddress) New() interface{}

type ListActiveSwaps

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

func (*ListActiveSwaps) Call

func (g *ListActiveSwaps) Call() (jrpc2.Result, error)

func (ListActiveSwaps) Description

func (c ListActiveSwaps) Description() string

func (*ListActiveSwaps) Get

func (ListActiveSwaps) LongDescription

func (c ListActiveSwaps) LongDescription() string

func (*ListActiveSwaps) Name

func (g *ListActiveSwaps) Name() string

func (*ListActiveSwaps) New

func (g *ListActiveSwaps) New() interface{}

type ListNodes

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

func (*ListNodes) Call

func (l *ListNodes) Call() (jrpc2.Result, error)

func (*ListNodes) Description

func (l *ListNodes) Description() string

func (*ListNodes) Get

func (l *ListNodes) Get(client *ClightningClient) jrpc2.ServerMethod

func (*ListNodes) LongDescription

func (l *ListNodes) LongDescription() string

func (*ListNodes) Name

func (l *ListNodes) Name() string

func (*ListNodes) New

func (l *ListNodes) New() interface{}

type ListPeers

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

ListPeers lists all peerswap-ready peers

func (*ListPeers) Call

func (l *ListPeers) Call() (jrpc2.Result, error)

func (*ListPeers) Description

func (l *ListPeers) Description() string

func (*ListPeers) Get

func (l *ListPeers) Get(client *ClightningClient) jrpc2.ServerMethod

func (*ListPeers) LongDescription

func (l *ListPeers) LongDescription() string

func (*ListPeers) Name

func (l *ListPeers) Name() string

func (*ListPeers) New

func (l *ListPeers) New() interface{}

type ListSwaps

type ListSwaps struct {
	DetailedPrint bool `json:"detailed,omitempty"`
	// contains filtered or unexported fields
}

ListSwaps list all active and finished swaps

func (*ListSwaps) Call

func (l *ListSwaps) Call() (jrpc2.Result, error)

func (*ListSwaps) Description

func (l *ListSwaps) Description() string

func (*ListSwaps) Get

func (g *ListSwaps) Get(client *ClightningClient) jrpc2.ServerMethod

func (*ListSwaps) LongDescription

func (l *ListSwaps) LongDescription() string

func (*ListSwaps) Name

func (l *ListSwaps) Name() string

func (*ListSwaps) New

func (l *ListSwaps) New() interface{}

type PeerSwapNodes

type PeerSwapNodes struct {
	Nodes []*glightning.Node `json:"nodes"`
}

type PeerSwapPeer

type PeerSwapPeer struct {
	NodeId          string                 `json:"nodeid"`
	SwapsAllowed    bool                   `json:"swaps_allowed"`
	SupportedAssets []string               `json:"supported_assets"`
	Channels        []*PeerSwapPeerChannel `json:"channels"`
	AsSender        *SwapStats             `json:"sent,omitempty"`
	AsReceiver      *SwapStats             `json:"received,omitempty"`
	PaidFee         uint64                 `json:"total_fee_paid"`
}

type PeerSwapPeerChannel

type PeerSwapPeerChannel struct {
	ChannelId       string  `json:"short_channel_id"`
	LocalBalance    uint64  `json:"local_balance"`
	RemoteBalance   uint64  `json:"remote_balance"`
	LocalPercentage float64 `json:"local_percentage"`
	State           string  `json:"state"`
}

type PeerswapClightningConfig

type PeerswapClightningConfig struct {
	DbPath string

	BitcoinRpcUser         string
	BitcoinRpcPassword     string
	BitcoinRpcPasswordFile string
	BitcoinRpcHost         string
	BitcoinRpcPort         uint
	BitcoinCookieFilePath  string

	LiquidRpcUser         string
	LiquidRpcPassword     string
	LiquidRpcPasswordFile string
	LiquidRpcHost         string
	LiquidRpcPort         uint
	LiquidRpcWallet       string
	LiquidEnabled         bool

	PolicyPath string
}

PeerswapClightningConfig contains relevant config params for peerswap

type PolicyReloader

type PolicyReloader interface {
	AddToAllowlist(pubkey string) error
	RemoveFromAllowlist(pubkey string) error
	AddToSuspiciousPeerList(pubkey string) error
	RemoveFromSuspiciousPeerList(pubkey string) error
	NewSwapsAllowed() bool
	DisableSwaps() error
	EnableSwaps() error
	ReloadFile() error
	Get() policy.Policy
}

type ReloadPolicyFile

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

func (ReloadPolicyFile) Call

func (c ReloadPolicyFile) Call() (jrpc2.Result, error)

func (ReloadPolicyFile) Description

func (c ReloadPolicyFile) Description() string

func (*ReloadPolicyFile) Get

func (*ReloadPolicyFile) LongDescription

func (c *ReloadPolicyFile) LongDescription() string

func (ReloadPolicyFile) Name

func (c ReloadPolicyFile) Name() string

func (ReloadPolicyFile) New

func (c ReloadPolicyFile) New() interface{}

type RemovePeer

type RemovePeer struct {
	PeerPubkey string `json:"peer_pubkey"`
	// contains filtered or unexported fields
}

func (*RemovePeer) Call

func (g *RemovePeer) Call() (jrpc2.Result, error)

func (RemovePeer) Description

func (c RemovePeer) Description() string

func (*RemovePeer) Get

func (RemovePeer) LongDescription

func (c RemovePeer) LongDescription() string

func (*RemovePeer) Name

func (g *RemovePeer) Name() string

func (*RemovePeer) New

func (g *RemovePeer) New() interface{}

type RemoveSuspiciousPeer

type RemoveSuspiciousPeer struct {
	PeerPubkey string `json:"peer_pubkey"`
	// contains filtered or unexported fields
}

func (*RemoveSuspiciousPeer) Call

func (g *RemoveSuspiciousPeer) Call() (jrpc2.Result, error)

func (RemoveSuspiciousPeer) Description

func (c RemoveSuspiciousPeer) Description() string

func (*RemoveSuspiciousPeer) Get

func (RemoveSuspiciousPeer) LongDescription

func (c RemoveSuspiciousPeer) LongDescription() string

func (*RemoveSuspiciousPeer) Name

func (g *RemoveSuspiciousPeer) Name() string

func (*RemoveSuspiciousPeer) New

func (g *RemoveSuspiciousPeer) New() interface{}

type SendPayPartWaiter

type SendPayPartWaiter interface {
	SendPayPartAndWait(paymentRequest string, bolt11 *glightning.DecodedBolt11, amountMsat uint64, channel string, label string, partId uint64) (*glightning.SendPayFields, error)
}

type SendToAddressResponse

type SendToAddressResponse struct {
	TxId string `json:"txid"`
}

type SerializedSwapStateMachine

type SerializedSwapStateMachine struct {
	*swap.SwapStateMachine
	Type string `json:"type"`
	Role string `json:"role"`
}

SerializedSwapStateMachine is the serialized representation of the internal state machine with all these massive (and unnecessary) amounts of data.

func MSerializedSwapStateMachine

func MSerializedSwapStateMachine(swapStateMachine *swap.SwapStateMachine) *SerializedSwapStateMachine

type SwapCanceledError

type SwapCanceledError string

func (SwapCanceledError) Error

func (e SwapCanceledError) Error() string

type SwapIn

type SwapIn struct {
	SatAmt         uint64 `json:"amt_sat"`
	ShortChannelId string `json:"short_channel_id"`
	Asset          string `json:"asset"`
	Force          bool   `json:"force"`
	// contains filtered or unexported fields
}

SwapIn Starts a new swap in(providing onchain liquidity)

func (*SwapIn) Call

func (l *SwapIn) Call() (jrpc2.Result, error)

func (*SwapIn) Description

func (l *SwapIn) Description() string

func (*SwapIn) Get

func (g *SwapIn) Get(client *ClightningClient) jrpc2.ServerMethod

func (*SwapIn) LongDescription

func (l *SwapIn) LongDescription() string

func (*SwapIn) Name

func (l *SwapIn) Name() string

func (*SwapIn) New

func (l *SwapIn) New() interface{}

type SwapOut

type SwapOut struct {
	SatAmt         uint64 `json:"amt_sat"`
	ShortChannelId string `json:"short_channel_id"`
	Asset          string `json:"asset"`
	Force          bool   `json:"force"`
	// contains filtered or unexported fields
}

SwapOut starts a new swapout (paying an Invoice for onchain liquidity)

func (*SwapOut) Call

func (l *SwapOut) Call() (jrpc2.Result, error)

func (*SwapOut) Description

func (l *SwapOut) Description() string

func (*SwapOut) Get

func (g *SwapOut) Get(client *ClightningClient) jrpc2.ServerMethod

func (*SwapOut) LongDescription

func (l *SwapOut) LongDescription() string

func (*SwapOut) Name

func (l *SwapOut) Name() string

func (*SwapOut) New

func (l *SwapOut) New() interface{}

type SwapStats

type SwapStats struct {
	SwapsOut uint64 `json:"total_swaps_out"`
	SwapsIn  uint64 `json:"total_swaps_in"`
	SatsOut  uint64 `json:"total_sats_swapped_out"`
	SatsIn   uint64 `json:"total_sats_swapped_in"`
}

Jump to

Keyboard shortcuts

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