models.go raw
1 package lnclient
2
3 import (
4 "context"
5 "errors"
6 )
7
8 // TLVRecord JSON tags are kept because values flow through the freeform
9 // transaction Metadata blob and are surfaced to NIP-47 clients via
10 // lookup_invoice / list_transactions.
11 type TLVRecord struct {
12 Type uint64 `json:"type"`
13 // hex-encoded value
14 Value string `json:"value"`
15 }
16
17 type Metadata = map[string]interface{}
18
19 type NodeInfo struct {
20 Alias string
21 Color string
22 Pubkey string
23 Network string
24 BlockHeight uint32
25 BlockHash string
26 }
27
28 // TODO: use uint for fields that cannot be negative
29 type Transaction struct {
30 Type string
31 Invoice string
32 Description string
33 DescriptionHash string
34 Preimage string
35 PaymentHash string
36 AmountMsat int64
37 FeesPaidMsat int64
38 CreatedAt int64
39 ExpiresAt *int64
40 SettledAt *int64
41 Metadata Metadata
42 SettleDeadline *uint32 // block number for accepted hold invoices
43 }
44
45 type OnchainTransaction struct {
46 AmountSat uint64
47 CreatedAt uint64
48 State string
49 Type string
50 NumConfirmations uint32
51 TxId string
52 }
53
54 type NodeConnectionInfo struct {
55 Pubkey string
56 Address string
57 Port int
58 }
59
60 type LNClient interface {
61 SendPaymentSync(payReq string, amountMsat *uint64) (*PayInvoiceResponse, error)
62 SendKeysend(amountMsat uint64, destination string, customRecords []TLVRecord, preimage string) (*PayKeysendResponse, error)
63 GetPubkey() string
64 GetInfo(ctx context.Context) (info *NodeInfo, err error)
65 MakeInvoice(ctx context.Context, amountMsat int64, description string, descriptionHash string, expiry int64, throughNodePubkey *string) (transaction *Transaction, err error)
66 MakeHoldInvoice(ctx context.Context, amountMsat int64, description string, descriptionHash string, expiry int64, paymentHash string, minCltvExpiryDelta *uint64) (transaction *Transaction, err error)
67 SettleHoldInvoice(ctx context.Context, preimage string) (err error)
68 CancelHoldInvoice(ctx context.Context, paymentHash string) (err error)
69 LookupInvoice(ctx context.Context, paymentHash string) (transaction *Transaction, err error)
70 ListOnchainTransactions(ctx context.Context) ([]OnchainTransaction, error)
71 Shutdown() error
72 ListChannels(ctx context.Context) (channels []Channel, err error)
73 GetNodeConnectionInfo(ctx context.Context) (nodeConnectionInfo *NodeConnectionInfo, err error)
74 GetNodeStatus(ctx context.Context) (nodeStatus *NodeStatus, err error)
75 ConnectPeer(ctx context.Context, connectPeerRequest *ConnectPeerRequest) error
76 OpenChannel(ctx context.Context, openChannelRequest *OpenChannelRequest) (*OpenChannelResponse, error)
77 CloseChannel(ctx context.Context, closeChannelRequest *CloseChannelRequest) error
78 UpdateChannel(ctx context.Context, updateChannelRequest *UpdateChannelRequest) error
79 DisconnectPeer(ctx context.Context, peerId string) error
80 MakeOffer(ctx context.Context, description string) (string, error)
81 GetNewOnchainAddress(ctx context.Context) (string, error)
82 ResetRouter(key string) error
83 GetOnchainBalance(ctx context.Context) (*OnchainBalanceResponse, error)
84 GetBalances(ctx context.Context, includeInactiveChannels bool) (*BalancesResponse, error)
85 RedeemOnchainFunds(ctx context.Context, toAddress string, amountSat uint64, feeRate *uint64, sendAll bool) (txId string, err error)
86 ListPeers(ctx context.Context) ([]PeerDetails, error)
87 GetLogOutput(ctx context.Context, maxLen int) ([]byte, error)
88 SignMessage(ctx context.Context, message string) (string, error)
89 GetStorageDir() (string, error)
90 GetNetworkGraph(ctx context.Context, nodeIds []string) (NetworkGraphResponse, error)
91 UpdateLastWalletSyncRequest()
92 GetSupportedNIP47Methods() []string
93 GetSupportedNIP47NotificationTypes() []string
94 GetCustomNodeCommandDefinitions() []CustomNodeCommandDef
95 ExecuteCustomNodeCommand(ctx context.Context, command *CustomNodeCommandRequest) (*CustomNodeCommandResponse, error)
96 }
97
98 type Channel struct {
99 LocalBalanceMsat int64
100 LocalSpendableBalanceMsat int64
101 RemoteBalanceMsat int64
102 Id string
103 RemotePubkey string
104 FundingTxId string
105 FundingTxVout uint32
106 Active bool
107 Public bool
108 InternalChannel interface{}
109 Confirmations *uint32
110 ConfirmationsRequired *uint32
111 ForwardingFeeBaseMsat uint32
112 ForwardingFeeProportionalMillionths uint32
113 UnspendablePunishmentReserveSat uint64
114 CounterpartyUnspendablePunishmentReserveSat uint64
115 Error *string
116 IsOutbound bool
117 }
118
119 type NodeStatus struct {
120 IsReady bool
121 InternalNodeStatus interface{}
122 }
123
124 type ConnectPeerRequest struct {
125 Pubkey string
126 Address string
127 Port uint16
128 }
129
130 type OpenChannelRequest struct {
131 Pubkey string
132 AmountSats int64
133 Public bool
134 }
135
136 type OpenChannelResponse struct {
137 FundingTxId string
138 }
139
140 type CloseChannelRequest struct {
141 ChannelId string
142 NodeId string
143 Force bool
144 }
145
146 type UpdateChannelRequest struct {
147 ChannelId string
148 NodeId string
149 ForwardingFeeBaseMsat uint32
150 ForwardingFeeProportionalMillionths uint32
151 MaxDustHtlcExposureFromFeeRateMultiplier uint64
152 }
153
154 type PendingBalanceDetails struct {
155 ChannelId string
156 NodeId string
157 AmountSat uint64
158 FundingTxId string
159 FundingTxVout uint32
160 }
161
162 type OnchainBalanceResponse struct {
163 SpendableSat int64
164 TotalSat int64
165 ReservedSat int64
166 PendingBalancesFromChannelClosuresSat uint64
167 PendingBalancesDetails []PendingBalanceDetails
168 PendingSweepBalancesDetails []PendingBalanceDetails
169 InternalBalances interface{}
170 }
171
172 type PeerDetails struct {
173 NodeId string
174 Address string
175 IsPersisted bool
176 IsConnected bool
177 }
178 type LightningBalanceResponse struct {
179 TotalSpendableMsat int64
180 TotalReceivableMsat int64
181 NextMaxSpendableMsat int64
182 NextMaxReceivableMsat int64
183 NextMaxSpendableMPPMsat int64
184 NextMaxReceivableMPPMsat int64
185 }
186
187 type PayInvoiceResponse struct {
188 Preimage string
189 FeeMsat uint64
190 }
191
192 type PayOfferResponse = struct {
193 Preimage string
194 FeeMsat uint64
195 PaymentHash string
196 }
197
198 type PayKeysendResponse struct {
199 FeeMsat uint64
200 }
201
202 type BalancesResponse struct {
203 Onchain OnchainBalanceResponse
204 Lightning LightningBalanceResponse
205 }
206
207 type NetworkGraphResponse = interface{}
208
209 type PaymentFailedEventProperties struct {
210 Transaction *Transaction
211 Reason string
212 }
213
214 type PaymentForwardedEventProperties struct {
215 TotalFeeEarnedMsat uint64
216 OutboundAmountForwardedMsat uint64
217 }
218
219 type CustomNodeCommandArgDef struct {
220 Name string
221 Description string
222 }
223
224 type CustomNodeCommandDef struct {
225 Name string
226 Description string
227 Args []CustomNodeCommandArgDef
228 }
229
230 type CustomNodeCommandArg struct {
231 Name string
232 Value string
233 }
234
235 type CustomNodeCommandRequest struct {
236 Name string
237 Args []CustomNodeCommandArg
238 }
239
240 type CustomNodeCommandResponse struct {
241 Response interface{}
242 }
243
244 func NewCustomNodeCommandResponseEmpty() *CustomNodeCommandResponse {
245 return &CustomNodeCommandResponse{
246 Response: struct{}{},
247 }
248 }
249
250 var ErrUnknownCustomNodeCommand = errors.New("unknown custom node command")
251
252 // default invoice expiry in seconds (1 day)
253 const DEFAULT_INVOICE_EXPIRY = 86400
254
255 type holdInvoiceCanceledError struct {
256 }
257
258 func NewHoldInvoiceCanceledError() error {
259 return &holdInvoiceCanceledError{}
260 }
261
262 func (err *holdInvoiceCanceledError) Error() string {
263 return "Hold invoice canceled"
264 }
265