forked from breez/server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.go
586 lines (507 loc) · 24.1 KB
/
server.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
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
package main
// To generate breez/breez.pb.go run:
// protoc -I breez breez/breez.proto --go_out=plugins=grpc:breez
import (
"bytes"
"context"
"crypto/sha256"
"crypto/x509"
"encoding/hex"
"errors"
"fmt"
"image/png"
"log"
"net"
"net/http"
"os"
"strconv"
"strings"
"time"
"cloud.google.com/go/storage"
"github.com/breez/server/auth"
"github.com/breez/server/breez"
"github.com/breez/server/captcha"
"github.com/breez/server/lsp"
"github.com/breez/server/ratelimit"
"github.com/breez/server/signer"
"github.com/breez/server/swapper"
"github.com/btcsuite/btcd/chaincfg"
"github.com/btcsuite/btcutil"
grpc_middleware "github.com/grpc-ecosystem/go-grpc-middleware"
"github.com/lightningnetwork/lnd/lnrpc"
"github.com/lightningnetwork/lnd/lnrpc/chainrpc"
"github.com/lightningnetwork/lnd/lnrpc/routerrpc"
"github.com/lightningnetwork/lnd/lnrpc/signrpc"
"github.com/lightningnetwork/lnd/lnrpc/submarineswaprpc"
"github.com/lightningnetwork/lnd/lnrpc/walletrpc"
"golang.org/x/sync/singleflight"
"golang.org/x/text/message"
"google.golang.org/api/option"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/credentials"
"google.golang.org/grpc/metadata"
"google.golang.org/grpc/reflection"
"google.golang.org/grpc/status"
"github.com/golang-migrate/migrate/v4"
_ "github.com/golang-migrate/migrate/v4/database/postgres"
_ "github.com/golang-migrate/migrate/v4/source/file"
)
const (
imageDimensionLength = 200
channelAmount = 1000000
minRemoveFund = 50000
)
var client, ssClient lnrpc.LightningClient
var subswapClient submarineswaprpc.SubmarineSwapperClient
var signerClient signrpc.SignerClient
var walletKitClient, ssWalletKitClient walletrpc.WalletKitClient
var chainNotifierClient chainrpc.ChainNotifierClient
var ssRouterClient routerrpc.RouterClient
var network *chaincfg.Params
var openChannelReqGroup singleflight.Group
var swapperServer *swapper.Server
// server is used to implement breez.InvoicerServer and breez.PosServer
type server struct{}
// RegisterDevice implements breez.InvoicerServer
func (s *server) RegisterDevice(ctx context.Context, in *breez.RegisterRequest) (*breez.RegisterReply, error) {
if in.LightningID != "" {
nodeID, err := hex.DecodeString(in.LightningID)
if err != nil {
log.Printf("hex.DecodeString(%v) error: %v", in.LightningID, err)
return nil, fmt.Errorf("hex.DecodeString(%v) error: %w", in.LightningID, err)
}
err = deviceNode(nodeID, in.DeviceID)
if err != nil {
log.Printf("deviceNode(%x, %v) error: %v", nodeID, in.DeviceID, err)
return nil, fmt.Errorf("deviceNode(%x, %v) error: %w", nodeID, in.DeviceID, err)
}
}
return &breez.RegisterReply{BreezID: in.DeviceID}, nil
}
func (s *server) SendInvoice(ctx context.Context, in *breez.PaymentRequest) (*breez.InvoiceReply, error) {
notificationData := map[string]string{
"msg": "Payment request",
"payee": in.Payee,
"amount": strconv.FormatInt(in.Amount, 10),
"payment_request": in.Invoice,
}
err := notifyAlertMessage(
in.Payee,
"is requesting you to pay "+strconv.FormatInt(in.Amount, 10)+" Sat",
notificationData,
in.BreezID)
if err != nil {
log.Println(err)
return &breez.InvoiceReply{Error: err.Error()}, err
}
return &breez.InvoiceReply{Error: ""}, nil
}
func (s *server) UploadLogo(ctx context.Context, in *breez.UploadFileRequest) (*breez.UploadFileReply, error) {
//validate png image
fileDataReader := bytes.NewReader(in.Content)
img, err := png.Decode(fileDataReader)
if err != nil {
log.Println("Failes to decode image", err)
return nil, status.Errorf(codes.InvalidArgument, "Image must be of type png")
}
//validate image size
imageMaxBounds := img.Bounds().Max
if imageMaxBounds.X != imageDimensionLength || imageMaxBounds.Y != imageDimensionLength {
log.Println("Image not in right required dimensions", imageMaxBounds)
return nil, status.Errorf(codes.InvalidArgument, "Image size must be 200 X 200 pixels")
}
//hash content and calculate file path
fileHash := sha256.Sum256(in.Content)
hashHex := hex.EncodeToString(fileHash[0:])
objectPath := fmt.Sprintf("%v/%v/%v.png", hashHex[:4], hashHex[4:8], hashHex[8:])
gcContext := context.Background()
gcCredsFile := os.Getenv("GOOGLE_CLOUD_SERVICE_FILE")
gcBucketName := os.Getenv("GOOGLE_CLOUD_IMAGES_BUCKET_NAME")
gcClient, err := storage.NewClient(gcContext, option.WithCredentialsFile(gcCredsFile))
if err != nil {
log.Println("Failed to create google cloud client", err)
return nil, status.Errorf(codes.Internal, "Failed to save image")
}
bucket := gcClient.Bucket(gcBucketName)
obj := bucket.Object(objectPath)
writer := obj.NewWriter(gcContext)
if _, err := writer.Write(in.Content); err != nil {
log.Println("Failed to write to bucket stream", err)
return nil, status.Errorf(codes.Internal, "Failed to save image")
}
if err := writer.Close(); err != nil {
log.Println("Failed to close bucket stream", err)
return nil, status.Errorf(codes.Internal, "Failed to save image")
}
if err := obj.ACL().Set(gcContext, storage.AllUsers, storage.RoleReader); err != nil {
log.Println("Failed to set read permissions on object", err)
return nil, status.Errorf(codes.Internal, "Failed to save image")
}
objAttrs, err := obj.Attrs(gcContext)
if err != nil {
log.Println("Failed read object attributes", err)
return nil, status.Errorf(codes.Internal, "Failed to save image")
}
log.Println("Succesfully uploaded image", objAttrs.MediaLink)
return &breez.UploadFileReply{Url: objAttrs.MediaLink}, nil
}
// Workaround until LND PR #1595 is merged
func (s *server) UpdateChannelPolicy(ctx context.Context, in *breez.UpdateChannelPolicyRequest) (*breez.UpdateChannelPolicyReply, error) {
clientCtx := metadata.AppendToOutgoingContext(context.Background(), "macaroon", os.Getenv("LND_MACAROON_HEX"))
nodeChannels, err := getNodeChannels(in.PubKey)
if err != nil {
return nil, err
}
for _, c := range nodeChannels {
var channelPoint lnrpc.ChannelPoint
outputIndex, err := strconv.ParseUint(strings.Split(c.ChannelPoint, ":")[1], 10, 32)
if err != nil {
return nil, err
}
channelPoint.OutputIndex = uint32(outputIndex)
channelPoint.FundingTxid = &lnrpc.ChannelPoint_FundingTxidStr{FundingTxidStr: strings.Split(c.ChannelPoint, ":")[0]}
client.UpdateChannelPolicy(clientCtx, &lnrpc.PolicyUpdateRequest{BaseFeeMsat: 1000, FeeRate: 0.000001, TimeLockDelta: 144, Scope: &lnrpc.PolicyUpdateRequest_ChanPoint{ChanPoint: &channelPoint}})
if err != nil {
return nil, err
}
}
return &breez.UpdateChannelPolicyReply{}, nil
}
func (s *server) OpenChannel(ctx context.Context, in *breez.OpenChannelRequest) (*breez.OpenChannelReply, error) {
return nil, fmt.Errorf("disabled")
}
func (s *server) AddFundInit(ctx context.Context, in *breez.AddFundInitRequest) (*breez.AddFundInitReply, error) {
return swapperServer.AddFundInitLegacy(ctx, in)
}
func (s *server) AddFundStatus(ctx context.Context, in *breez.AddFundStatusRequest) (*breez.AddFundStatusReply, error) {
return swapperServer.AddFundStatus(ctx, in)
}
func (s *server) GetSwapPayment(ctx context.Context, in *breez.GetSwapPaymentRequest) (*breez.GetSwapPaymentReply, error) {
return swapperServer.GetSwapPaymentLegacy(ctx, in)
}
func (s *server) RemoveFund(ctx context.Context, in *breez.RemoveFundRequest) (*breez.RemoveFundReply, error) {
address := in.Address
amount := in.Amount
if address == "" {
return nil, errors.New("Destination address must not be empty")
}
_, err := btcutil.DecodeAddress(address, network)
if err != nil {
log.Println("Destination address must be a valid bitcoin address")
return nil, err
}
if amount <= 0 {
return nil, errors.New("Amount must be positive")
}
if amount < minRemoveFund {
p := message.NewPrinter(message.MatchLanguage("en"))
satFormatted := strings.Replace(p.Sprintf("%d", minRemoveFund), ",", " ", 1)
btcFormatted := strconv.FormatFloat(float64(minRemoveFund)/float64(100000000), 'f', -1, 64)
errorStr := fmt.Sprintf("Removed funds must be more than %v BTC (%v Sat).", btcFormatted, satFormatted)
return &breez.RemoveFundReply{ErrorMessage: errorStr}, nil
}
paymentRequest, err := createRemoveFundPaymentRequest(amount, address)
if err != nil {
log.Printf("createRemoveFundPaymentRequest: failed %v", err)
return nil, err
}
return &breez.RemoveFundReply{PaymentRequest: paymentRequest}, nil
}
func (s *server) RedeemRemovedFunds(ctx context.Context, in *breez.RedeemRemovedFundsRequest) (*breez.RedeemRemovedFundsReply, error) {
txID, err := ensureOnChainPaymentSent(in.Paymenthash)
if err != nil {
log.Printf("ReceiveOnChainPayment failed: %v", err)
return nil, err
}
return &breez.RedeemRemovedFundsReply{Txid: txID}, nil
}
// RegisterDevice implements breez.InvoicerServer
func (s *server) Order(ctx context.Context, in *breez.OrderRequest) (*breez.OrderReply, error) {
log.Printf("Order a card for: %#v", *in)
err := sendCardOrderNotification(in)
if err != nil {
log.Printf("Error in sendCardOrderNotification: %v", err)
}
return &breez.OrderReply{}, nil
}
// InactiveNotify send a notification to an inactive nodeid
func (s *server) InactiveNotify(ctx context.Context, in *breez.InactiveNotifyRequest) (*breez.InactiveNotifyResponse, error) {
data := make(map[string]string)
token, err := getDeviceToken(in.Pubkey)
if err != nil {
return nil, err
}
if token == "" {
return nil, fmt.Errorf("Unknown nodeID: %v", in.Pubkey)
}
body := fmt.Sprintf("You haven't made any payments with Breez for %v days, so your LSP might have to close your channels. Open Breez for more information.", in.Days)
err = notifyAlertMessage("Inactive Channels", body, data, token)
if err != nil {
return nil, err
}
return &breez.InactiveNotifyResponse{}, nil
}
// JoinCTPSession is used by both payer/payee to join a CTP session.
func (s *server) JoinCTPSession(ctx context.Context, in *breez.JoinCTPSessionRequest) (*breez.JoinCTPSessionResponse, error) {
sessionID, expiry, err := joinSession(in.SessionID, in.NotificationToken, in.PartyName, in.PartyType == breez.JoinCTPSessionRequest_PAYER)
if err != nil {
return nil, err
}
return &breez.JoinCTPSessionResponse{SessionID: sessionID, Expiry: expiry}, nil
}
func (s *server) TerminateCTPSession(ctx context.Context, in *breez.TerminateCTPSessionRequest) (*breez.TerminateCTPSessionResponse, error) {
err := terminateSession(in.SessionID)
if err != nil {
return nil, err
}
return &breez.TerminateCTPSessionResponse{}, nil
}
func (s *server) RegisterTransactionConfirmation(ctx context.Context, in *breez.RegisterTransactionConfirmationRequest) (*breez.RegisterTransactionConfirmationResponse, error) {
var notifyType string
if in.NotificationType == breez.RegisterTransactionConfirmationRequest_READY_RECEIVE_PAYMENT {
notifyType = receivePaymentType
}
if in.NotificationType == breez.RegisterTransactionConfirmationRequest_CHANNEL_OPENED {
notifyType = channelOpenedType
}
if notifyType == "" {
return nil, errors.New("Invalid notification type")
}
err := registerTransacionConfirmation(in.TxID, in.NotificationToken, notifyType)
if err != nil {
return nil, err
}
return &breez.RegisterTransactionConfirmationResponse{}, nil
}
func (s *server) RegisterPeriodicSync(ctx context.Context, in *breez.RegisterPeriodicSyncRequest) (*breez.RegisterPeriodicSyncResponse, error) {
if err := registerSyncNotification(in.NotificationToken); err != nil {
return nil, err
}
return &breez.RegisterPeriodicSyncResponse{}, nil
}
func getNodeChannels(nodeID string) ([]*lnrpc.Channel, error) {
clientCtx := metadata.AppendToOutgoingContext(context.Background(), "macaroon", os.Getenv("LND_MACAROON_HEX"))
listResponse, err := client.ListChannels(clientCtx, &lnrpc.ListChannelsRequest{})
if err != nil {
return nil, err
}
var nodeChannels []*lnrpc.Channel
for _, channel := range listResponse.Channels {
if channel.RemotePubkey == nodeID {
nodeChannels = append(nodeChannels, channel)
}
}
return nodeChannels, nil
}
func getPendingNodeChannels(nodeID string) ([]*lnrpc.PendingChannelsResponse_PendingOpenChannel, error) {
clientCtx := metadata.AppendToOutgoingContext(context.Background(), "macaroon", os.Getenv("LND_MACAROON_HEX"))
pendingResponse, err := client.PendingChannels(clientCtx, &lnrpc.PendingChannelsRequest{})
if err != nil {
return nil, err
}
var pendingChannels []*lnrpc.PendingChannelsResponse_PendingOpenChannel
for _, p := range pendingResponse.PendingOpenChannels {
if p.Channel.RemoteNodePub == nodeID {
pendingChannels = append(pendingChannels, p)
}
}
return pendingChannels, nil
}
func main() {
switch os.Getenv("NETWORK") {
case "simnet":
network = &chaincfg.SimNetParams
case "testnet":
network = &chaincfg.TestNet3Params
case "regtest":
network = &chaincfg.RegressionNetParams
default:
network = &chaincfg.MainNetParams
}
lisGRPC, err := net.Listen("tcp", os.Getenv("GRPC_LISTEN_ADDRESS"))
if err != nil {
log.Fatalf("Failed to listen: %v", err)
}
lisHTTP, err := net.Listen("tcp", os.Getenv("HTTP_LISTEN_ADDRESS"))
if err != nil {
log.Fatalf("Failed to listen: %v", err)
}
mux := http.NewServeMux()
mux.HandleFunc("/fees/v1/btc-fee-estimates.json", func(w http.ResponseWriter, req *http.Request) {
w.Header().Set("Content-Type", "application/json")
w.Write([]byte(feeEstimates))
})
HTTPServer := &http.Server{
Handler: mux,
ReadTimeout: 10 * time.Second,
WriteTimeout: 10 * time.Second,
MaxHeaderBytes: 1 << 20,
}
go HTTPServer.Serve(lisHTTP)
// Creds file to connect to LND gRPC
cp := x509.NewCertPool()
if !cp.AppendCertsFromPEM([]byte(strings.Replace(os.Getenv("LND_CERT"), "\\n", "\n", -1))) {
log.Fatalf("credentials: failed to append certificates")
}
creds := credentials.NewClientTLSFromCert(cp, "")
// Address of an LND instance
conn, err := grpc.Dial(os.Getenv("LND_ADDRESS"), grpc.WithTransportCredentials(creds))
if err != nil {
log.Fatalf("Failed to connect to LND gRPC: %v", err)
}
defer conn.Close()
client = lnrpc.NewLightningClient(conn)
signerClient = signrpc.NewSignerClient(conn)
walletKitClient = walletrpc.NewWalletKitClient(conn)
chainNotifierClient = chainrpc.NewChainNotifierClient(conn)
ssCp := x509.NewCertPool()
if !ssCp.AppendCertsFromPEM([]byte(strings.Replace(os.Getenv("SUBSWAPPER_LND_CERT"), "\\n", "\n", -1))) {
log.Fatalf("credentials: failed to append certificates")
}
ssCreds := credentials.NewClientTLSFromCert(ssCp, "")
// Address of an LND instance
subswapConn, err := grpc.Dial(os.Getenv("SUBSWAPPER_LND_ADDRESS"), grpc.WithTransportCredentials(ssCreds))
if err != nil {
log.Fatalf("Failed to connect to LND gRPC: %v", err)
}
defer subswapConn.Close()
ssClient = lnrpc.NewLightningClient(subswapConn)
subswapClient = submarineswaprpc.NewSubmarineSwapperClient(subswapConn)
ssWalletKitClient = walletrpc.NewWalletKitClient(subswapConn)
ssRouterClient = routerrpc.NewRouterClient(subswapConn)
ctx := metadata.AppendToOutgoingContext(context.Background(), "macaroon", os.Getenv("LND_MACAROON_HEX"))
go subscribeTransactions(ctx, client)
go handlePastTransactions(ctx, client)
go subscribeChannelAcceptor(ctx, client, os.Getenv("LND_CHANNEL_ACCEPTOR"))
ssCtx := metadata.AppendToOutgoingContext(context.Background(), "macaroon", os.Getenv("SUBSWAPPER_LND_MACAROON_HEX"))
go subscribeTransactions(ssCtx, ssClient)
go handlePastTransactions(ssCtx, ssClient)
go subscribeChannelAcceptor(ssCtx, ssClient, os.Getenv("SUBSWAPPER_LND_CHANNEL_ACCEPTOR"))
startFeeEstimates()
err = redisConnect()
if err != nil {
log.Println("redisConnect error:", err)
}
go deliverSyncNotifications()
// DB Migrations
log.Println("Starting migrations...")
migrationsPath, envSet := os.LookupEnv("MIGRATIONS_PATH")
if !envSet {
log.Fatalf("MIGRATIONS_PATH environment variable not set")
}
migrationsPath = fmt.Sprintf("file://%v", migrationsPath)
m, err := migrate.New(
migrationsPath,
os.Getenv("DATABASE_URL"))
if err != nil {
log.Fatal(err)
}
if err := m.Up(); err != nil {
if !strings.Contains(err.Error(), "no change") {
log.Fatal(err)
} else {
log.Println("No changes to apply")
}
}
log.Println("Migrations completed")
// Start the server
err = pgConnect()
if err != nil {
log.Printf("pgConnect error: %v", err)
}
go registerPastBoltzReverseSwapTxNotifications()
lsp.InitLSP()
s := grpc.NewServer(
grpc_middleware.WithUnaryServerChain(
auth.UnaryMultiAuth("/breez.PublicChannelOpener/", os.Getenv("PUBLIC_CHANNEL_TOKENS")),
auth.UnaryAuth("/breez.InactiveNotifier/", os.Getenv("INACTIVE_NOTIFIER_TOKEN")),
captcha.UnaryCaptchaAuth("/breez.ChannelOpener/OpenLSPChannel", os.Getenv("CAPTCHA_CONFIG")),
ratelimit.PerIPUnaryRateLimiter(redisPool, "rate-limit", "/breez.Invoicer/RegisterDevice", 3, 10, 86400),
ratelimit.UnaryRateLimiter(redisPool, "rate-limit", "/breez.Invoicer/RegisterDevice", 100, 10000, 86400),
ratelimit.PerIPUnaryRateLimiter(redisPool, "rate-limit", "/breez.Invoicer/SendInvoice", 3, 100, 86400),
ratelimit.UnaryRateLimiter(redisPool, "rate-limit", "/breez.Invoicer/SendInvoice", 100, 10000, 86400),
ratelimit.PerIPUnaryRateLimiter(redisPool, "rate-limit", "/breez.CardOrderer/Order", 3, 10, 86400),
ratelimit.UnaryRateLimiter(redisPool, "rate-limit", "/breez.CardOrderer/Order", 100, 10000, 86400),
ratelimit.PerIPUnaryRateLimiter(redisPool, "rate-limit", "/breez.Pos/RegisterDevice", 10, 20, 86400),
ratelimit.UnaryRateLimiter(redisPool, "rate-limit", "/breez.Pos/RegisterDevice", 100, 10000, 86400),
ratelimit.PerIPUnaryRateLimiter(redisPool, "rate-limit", "/breez.Pos/UploadLogo", 100, 1000, 86400),
ratelimit.UnaryRateLimiter(redisPool, "rate-limit", "/breez.Pos/UploadLogo", 10000, 100000, 86400),
ratelimit.PerIPUnaryRateLimiter(redisPool, "rate-limit", "/breez.Information/Ping", 10000, 100000, 86400),
ratelimit.UnaryRateLimiter(redisPool, "rate-limit", "/breez.Information/Ping", 100000, 10000000, 86400),
ratelimit.PerIPUnaryRateLimiter(redisPool, "rate-limit", "/breez.Information/Rates", 10000, 100000, 86400),
ratelimit.UnaryRateLimiter(redisPool, "rate-limit", "/breez.Information/Rates", 100000, 10000000, 86400),
ratelimit.PerIPUnaryRateLimiter(redisPool, "rate-limit", "/breez.Information/ReceiverInfo", 10000, 100000, 86400),
ratelimit.UnaryRateLimiter(redisPool, "rate-limit", "/breez.Information/ReceiverInfo", 100000, 10000000, 86400),
ratelimit.PerIPUnaryRateLimiter(redisPool, "rate-limit", "/breez.FundManager/OpenChannel", 5, 10, 86400),
ratelimit.UnaryRateLimiter(redisPool, "rate-limit", "/breez.FundManager/OpenChannel", 500, 1000, 86400),
ratelimit.PerIPUnaryRateLimiter(redisPool, "rate-limit", "/breez.FundManager/UpdateChannelPolicy", 1000, 100000, 86400),
ratelimit.UnaryRateLimiter(redisPool, "rate-limit", "/breez.FundManager/UpdateChannelPolicy", 100000, 1000000, 86400),
ratelimit.PerIPUnaryRateLimiter(redisPool, "rate-limit", "/breez.FundManager/AddFundInit", 20, 200, 86400),
ratelimit.UnaryRateLimiter(redisPool, "rate-limit", "/breez.FundManager/AddFundInit", 1000, 100000, 86400),
ratelimit.PerIPUnaryRateLimiter(redisPool, "rate-limit", "/breez.FundManager/AddFundStatus", 100, 1000, 86400),
ratelimit.UnaryRateLimiter(redisPool, "rate-limit", "/breez.FundManager/AddFundStatus", 1000, 10000, 86400),
ratelimit.PerIPUnaryRateLimiter(redisPool, "rate-limit", "/breez.FundManager/RemoveFund", 3, 10, 86400),
ratelimit.UnaryRateLimiter(redisPool, "rate-limit", "/breez.FundManager/RemoveFund", 100, 10000, 86400),
ratelimit.PerIPUnaryRateLimiter(redisPool, "rate-limit", "/breez.FundManager/RedeemRemovedFunds", 10, 100, 86400),
ratelimit.UnaryRateLimiter(redisPool, "rate-limit", "/breez.FundManager/RedeemRemovedFunds", 100, 10000, 86400),
ratelimit.PerIPUnaryRateLimiter(redisPool, "rate-limit", "/breez.FundManager/GetSwapPayment", 100, 1000, 86400),
ratelimit.UnaryRateLimiter(redisPool, "rate-limit", "/breez.FundManager/GetSwapPayment", 1000, 10000, 86400),
ratelimit.PerIPUnaryRateLimiter(redisPool, "rate-limit", "/breez.FundManager/RegisterTransactionConfirmation", 10, 100, 86400),
ratelimit.UnaryRateLimiter(redisPool, "rate-limit", "/breez.FundManager/RegisterTransactionConfirmation", 100, 10000, 86400),
ratelimit.PerIPUnaryRateLimiter(redisPool, "rate-limit", "/breez.Swapper/AddFundInit", 20, 200, 86400),
ratelimit.UnaryRateLimiter(redisPool, "rate-limit", "/breez.Swapper/AddFundInit", 1000, 100000, 86400),
ratelimit.PerIPUnaryRateLimiter(redisPool, "rate-limit", "/breez.Swapper/AddFundStatus", 100, 1000, 86400),
ratelimit.UnaryRateLimiter(redisPool, "rate-limit", "/breez.Swapper/AddFundStatus", 1000, 10000, 86400),
ratelimit.PerIPUnaryRateLimiter(redisPool, "rate-limit", "/breez.Swapper/GetSwapPayment", 100, 1000, 86400),
ratelimit.UnaryRateLimiter(redisPool, "rate-limit", "/breez.Swapper/GetSwapPayment", 1000, 10000, 86400),
ratelimit.PerIPUnaryRateLimiter(redisPool, "rate-limit", "/breez.Swapper/GetReverseRoutingNode", 100, 1000, 86400),
ratelimit.UnaryRateLimiter(redisPool, "rate-limit", "/breez.Swapper/GetReverseRoutingNode", 1000, 10000, 86400),
ratelimit.PerIPUnaryRateLimiter(redisPool, "rate-limit", "/breez.CTP/JoinCTPSession", 1000, 10000, 86400),
ratelimit.UnaryRateLimiter(redisPool, "rate-limit", "/breez.CTP/JoinCTPSession", 1000, 100000, 86400),
ratelimit.PerIPUnaryRateLimiter(redisPool, "rate-limit", "/breez.CTP/TerminateCTPSession", 1000, 10000, 86400),
ratelimit.UnaryRateLimiter(redisPool, "rate-limit", "/breez.CTP/TerminateCTPSession", 1000, 100000, 86400),
ratelimit.PerIPUnaryRateLimiter(redisPool, "rate-limit", "/breez.ChannelOpener/LSPList", 10000, 10000000, 86400),
ratelimit.UnaryRateLimiter(redisPool, "rate-limit", "/breez.ChannelOpener/LSPList", 10000, 10000000, 86400),
ratelimit.PerIPUnaryRateLimiter(redisPool, "rate-limit", "/breez.ChannelOpener/OpenLSPChannel", 10, 10000, 86400),
ratelimit.UnaryRateLimiter(redisPool, "rate-limit", "/breez.ChannelOpener/OpenLSPChannel", 1000, 1000, 86400),
ratelimit.PerIPUnaryRateLimiter(redisPool, "rate-limit", "/breez.PushTxNotifier/RegisterTxNotification", 10, 10000, 86400),
ratelimit.UnaryRateLimiter(redisPool, "rate-limit", "/breez.PushTxNotifier/RegisterTxNotification", 1000, 1000, 86400),
ratelimit.PerIPUnaryRateLimiter(redisPool, "rate-limit", "/breez/PublicChannelOpener/OpenPublicChannel", 10, 10000, 86400),
ratelimit.UnaryRateLimiter(redisPool, "rate-limit", "/breez/PublicChannelOpener/OpenPublicChannel", 1000, 1000, 86400),
ratelimit.PerIPUnaryRateLimiter(redisPool, "rate-limit", "/breez/InactiveNotifier/InactiveNotify", 1000, 10000, 86400),
ratelimit.UnaryRateLimiter(redisPool, "rate-limit", "/breez/InactiveNotifier/InactiveNotify", 1000, 1000, 86400),
ratelimit.PerIPUnaryRateLimiter(redisPool, "rate-limit", "/breez.NodeInfo/SetNodeInfo", 1000, 10000, 86400),
ratelimit.UnaryRateLimiter(redisPool, "rate-limit", "/breez.NodeInfo/SetNodeInfo", 1000, 100000, 86400),
ratelimit.PerIPUnaryRateLimiter(redisPool, "rate-limit", "/breez.NodeInfo/GetNodeInfo", 1000, 10000, 86400),
ratelimit.UnaryRateLimiter(redisPool, "rate-limit", "/breez.NodeInfo/GetNodeInfo", 1000, 100000, 86400),
ratelimit.PerIPUnaryRateLimiter(redisPool, "rate-limit", "/breez.Signer/SignUrl", 10, 10000, 86400),
ratelimit.UnaryRateLimiter(redisPool, "rate-limit", "/breez.Signer/SignUrl", 1000, 1000, 86400),
),
)
swapperServer = swapper.NewServer(network, redisPool, client, ssClient, subswapClient, ssWalletKitClient, ssRouterClient,
insertSubswapPayment, updateSubswapPayment)
breez.RegisterSwapperServer(s, swapperServer)
lspServer := &lsp.Server{
EmailNotifier: sendOpenChannelNotification,
DBLSPList: lspList,
}
breez.RegisterChannelOpenerServer(s, lspServer)
breez.RegisterPublicChannelOpenerServer(s, lspServer)
breez.RegisterInvoicerServer(s, &server{})
breez.RegisterPosServer(s, &server{})
breez.RegisterInformationServer(s, &server{})
breez.RegisterCardOrdererServer(s, &server{})
breez.RegisterFundManagerServer(s, &server{})
breez.RegisterCTPServer(s, &server{})
breez.RegisterSyncNotifierServer(s, &server{})
breez.RegisterPushTxNotifierServer(s, &server{})
breez.RegisterInactiveNotifierServer(s, &server{})
breez.RegisterNodeInfoServer(s, &server{})
breez.RegisterSignerServer(s, &signer.Server{})
// Register reflection service on gRPC server.
reflection.Register(s)
if err := s.Serve(lisGRPC); err != nil {
log.Fatalf("failed to serve: %v", err)
}
}