-
Notifications
You must be signed in to change notification settings - Fork 3
/
cln_entities.go
331 lines (279 loc) · 9.08 KB
/
cln_entities.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
package lightning
import (
"encoding/json"
"errors"
"math"
entities "github.com/bolt-observer/go_common/entities"
)
var (
// ErrNoNode means node was not found.
ErrNoNode = errors.New("node not found")
// ErrNoChan means channel was not found.
ErrNoChan = errors.New("channel not found")
// ErrInvalidResponse indicates invaid response.
ErrInvalidResponse = errors.New("invalid response")
)
// ClnResp struct is the base type for all responses.
type ClnResp struct{}
// ClnInfo struct.
type ClnInfo struct {
PubKey string `json:"id"`
Alias string `json:"alias"`
Color string `json:"color"`
Network string `json:"network"`
Addresses []ClnListNodeAddr `json:"address,omitempty"`
Features ClnFeatures `json:"our_features"`
Version string `json:"version"`
Blockheight uint32 `json:"blockheight"`
WarningBitcoindSync string `json:"warning_bitcoind_sync,omitempty"`
WarningLightningdSync string `json:"warning_lightningd_sync,omitempty"`
}
// ClnFeatures struct.
type ClnFeatures struct {
Init string `json:"init"`
Node string `json:"node"`
Channel string `json:"channe"`
Invoice string `json:"invoice"`
}
// ClnSetChan struct.
type ClnSetChan struct {
PeerID string `json:"peer_id"`
LongChanID string `json:"channel_id"`
FeeBase string `json:"fee_base_msat"`
FeePpm string `json:"fee_proportional_milli"`
MiHtlc string `json:"minimum_htlc_out_msat"`
MaxHtlc string `json:"maximum_htlc_out_msat"`
ShortChannelID string `json:"short_channel_id,omitempty"`
}
// ClnSetChanResp struct.
type ClnSetChanResp struct {
Settings []ClnSetChan `json:"channels,omitempty"`
ClnResp
}
// ClnListChan struct.
type ClnListChan struct {
Source string `json:"source"`
Destination string `json:"destination"`
Public bool `json:"public"`
Capacity uint64 `json:"satoshis"`
Active bool `json:"active"`
LastUpdate entities.JsonTime `json:"last_update"`
FeeBase uint64 `json:"base_fee_millisatoshi"`
FeePpm uint64 `json:"fee_per_millionth"`
MinHtlc string `json:"htlc_minimum_msat"`
MaxHtlc string `json:"htlc_maximum_msat"`
ShortChannelID string `json:"short_channel_id,omitempty"`
Delay uint64 `json:"delay"`
}
// ClnListChanResp struct.
type ClnListChanResp struct {
Channels []ClnListChan `json:"channels,omitempty"`
ClnResp
}
// ClnFundsChan struct.
type ClnFundsChan struct {
PeerID string `json:"peer_id"`
Connected bool `json:"connected,omitempty"`
ShortChannelID string `json:"short_channel_id"`
State string `json:"state"`
Capacity uint64 `json:"channel_total_sat"`
OurAmount uint64 `json:"channel_sat"`
FundingTxID string `json:"funding_txid"`
FundingOutput int `json:"funding_output"`
}
// ClnFundsChanResp struct.
type ClnFundsChanResp struct {
Channels []ClnFundsChan `json:"channels,omitempty"`
ClnResp
}
// ClnListNodeAddr struct.
type ClnListNodeAddr struct {
Type string `json:"type"`
Address string `json:"address"`
Port int `json:"port"`
}
// ClnListNode struct.
type ClnListNode struct {
PubKey string `json:"nodeid"`
Alias string `json:"alias,omitempty"`
Color string `json:"color,omitempty"`
Features string `json:"features,omitempty"`
Addresses []ClnListNodeAddr `json:"addresses,omitempty"`
LastUpdate *entities.JsonTime `json:"last_update,omitempty"`
}
// ClnListNodeResp struct.
type ClnListNodeResp struct {
Nodes []ClnListNode `json:"nodes,omitempty"`
ClnResp
}
// ClnForwardEntry struct.
type ClnForwardEntry struct {
InChannel string `json:"in_channel"`
InMsat string `json:"in_msat"`
Status string `json:"status"` // one of "offered", "settled", "local_failed", "failed"
ReceivedTime entities.JsonTime `json:"received_time"`
OutChannel string `json:"out_channel,omitempty"`
OutMsat string `json:"out_msat,omitempty"`
FeeMsat string `json:"fee_msat,omitempty"`
FailCode uint32 `json:"fail_code,omitempty"`
FailReason string `json:"fail_reason,omitempty"`
}
// ClnForwardEntries struct.
type ClnForwardEntries struct {
Entries []ClnForwardEntry `json:"forwards,omitempty"`
}
// ClnPaymentEntries struct.
type ClnPaymentEntries struct {
Entries []ClnPaymentEntry `json:"payments,omitempty"`
}
// ClnInvoiceEntries struct.
type ClnInvoiceEntries struct {
Entries []ClnInvoiceEntry `json:"invoices,omitempty"`
}
// ClnPaymentEntry struct.
type ClnPaymentEntry struct {
PaymentHash string `json:"payment_hash,omitempty"`
Status string `json:"status"` // (one of "pending", "failed", "complete")
PaymentPreimage string `json:"payment_preimage,omitempty"`
}
// ClnInvoiceEntry struct.
type ClnInvoiceEntry struct {
Status string `json:"status"` // (one of "unpaid", "paid", "expired")
PaymentHash string `json:"payment_hash,omitempty"`
}
// ClnRawMessageItf interface.
type ClnRawMessageItf interface {
GetEntries() []json.RawMessage
}
// ClnRawTimeItf interface.
type ClnRawTimeItf interface {
GetUnixTimeMs() uint64
}
// ClnRawForwardEntries struct.
type ClnRawForwardEntries struct {
Entries []json.RawMessage `json:"forwards,omitempty"`
}
// GetEntries to comply with ClnRawMessageItf.
func (r ClnRawForwardEntries) GetEntries() []json.RawMessage {
return r.Entries
}
// ClnRawInvoices struct.
type ClnRawInvoices struct {
Entries []json.RawMessage `json:"invoices,omitempty"`
}
// GetEntries to comply with ClnRawMessageItf.
func (r ClnRawInvoices) GetEntries() []json.RawMessage {
return r.Entries
}
// ClnRawPayments struct.
type ClnRawPayments struct {
Entries []json.RawMessage `json:"payments,omitempty"`
}
// GetEntries to comply with ClnRawMessageItf.
func (r ClnRawPayments) GetEntries() []json.RawMessage {
return r.Entries
}
// ClnRawPayTime struct.
type ClnRawPayTime struct {
Time uint64 `json:"created_at,omitempty"`
}
// GetUnixTimeMs to comply with ClnRawTimeItf.
func (r ClnRawPayTime) GetUnixTimeMs() uint64 {
return r.Time * 1000
}
// ClnRawInvoiceTime struct.
type ClnRawInvoiceTime struct {
Time uint64 `json:"expires_at,omitempty"`
}
// GetUnixTimeMs to comply with ClnRawTimeItf.
func (r ClnRawInvoiceTime) GetUnixTimeMs() uint64 {
return r.Time * 1000
}
// ClnRawForwardsTime struct.
type ClnRawForwardsTime struct {
Time float64 `json:"received_time,omitempty"`
}
// GetUnixTimeMs to comply with ClnRawTimeItf.
func (r ClnRawForwardsTime) GetUnixTimeMs() uint64 {
return uint64(math.Round(r.Time * 1000))
}
// ClnErrorResp struct.
type ClnErrorResp struct {
ClnResp
Error struct {
Code int `json:"code,omitempty"`
Message string `json:"message,omitempty"`
} `json:"error"`
}
// ClnSuccessResp struct.
type ClnSuccessResp struct {
ClnResp
Result json.RawMessage `json:"result,omitempty"`
}
// ClnConnectResp struct.
type ClnConnectResp struct {
ID string `json:"id"`
ClnResp
}
// ClnNewAddrResp struct.
type ClnNewAddrResp struct {
Bech32 string `json:"bech32,omitempty"`
ClnResp
}
// ClnFundsChainResp struct.
type ClnFundsChainResp struct {
Outputs []ClnFundsOutput `json:"outputs,omitempty"`
ClnResp
}
// ClnFundsOutput struct.
type ClnFundsOutput struct {
AmountMsat string `json:"amount_msat,omitempty"`
Status string `json:"status,omitempty"`
Reserved bool `json:"reserved,omitempty"`
}
// ClnWithdrawResp struct.
type ClnWithdrawResp struct {
TxID string `json:"txid,omitempty"`
ClnResp
}
// ClnPayResp struct.
type ClnPayResp struct {
PaymentPreimage string `json:"payment_preimage,omitempty"`
PaymentHash string `json:"payment_hash,omitempty"`
AmountMsat string `json:"amount_msat,omitempty"`
AmountSentMsat string `json:"amount_sent_msat,omitempty"`
Status string `json:"status,omitempty"`
Destination string `json:"destination,omitempty"`
ClnResp
}
// ClnInvoiceResp struct.
type ClnInvoiceResp struct {
Bolt11 string `json:"bolt11,omitempty"`
PaymentHash string `json:"payment_hash,omitempty"`
// omitted stuff
ClnResp
}
// ClnClosedChannelEntires struct.
type ClnClosedChannelEntires struct {
Entries []ClnClosedChannelEntry `json:"closedchannels,omitempty"`
ClnResp
}
// ClnClosedChannelEntry struct.
type ClnClosedChannelEntry struct {
ShortChannelID string `json:"short_channel_id,omitempty"`
Closer string `json:"closer,omitempty"` // local, remote
Opener string `json:"opener,omitempty"` // local, remote
CloseCause string `json:"close_cause,omitempty"` // close_cause (string): What caused the channel to close (one of "unknown", "local", "user", "remote", "protocol", "onchain")
}
// ClnRouteResp struct.
type ClnRouteResp struct {
Route []ClnRoute `json:"route,omitempty"`
ClnResp
}
// ClnRoute struct.
type ClnRoute struct {
PubKey string `json:"id"`
Channel string `json:"channel"`
Direction int `json:"direction"`
/* ... */
}