mirror of
https://github.com/getAlby/lndhub.go.git
synced 2026-01-19 21:05:45 +01:00
@@ -8,6 +8,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/getAlby/lndhub.go/db/models"
|
||||
"github.com/getAlby/lndhub.go/lnd"
|
||||
"github.com/getsentry/sentry-go"
|
||||
"github.com/lightningnetwork/lnd/lnrpc"
|
||||
"github.com/uptrace/bun"
|
||||
@@ -95,7 +96,7 @@ func (svc *LndhubService) ProcessInvoiceUpdate(ctx context.Context, rawInvoice *
|
||||
return nil
|
||||
}
|
||||
|
||||
func (svc *LndhubService) ConnectInvoiceSubscription(ctx context.Context) (lnrpc.Lightning_SubscribeInvoicesClient, error) {
|
||||
func (svc *LndhubService) ConnectInvoiceSubscription(ctx context.Context) (lnd.SubscribeInvoicesWrapper, error) {
|
||||
var invoice models.Invoice
|
||||
invoiceSubscriptionOptions := lnrpc.InvoiceSubscription{}
|
||||
// Find the oldest NOT settled invoice with an add_index
|
||||
|
||||
@@ -8,8 +8,8 @@ import (
|
||||
"github.com/btcsuite/btcd/btcec"
|
||||
"github.com/getAlby/lndhub.go/db/models"
|
||||
"github.com/getAlby/lndhub.go/lib/tokens"
|
||||
"github.com/getAlby/lndhub.go/lnd"
|
||||
"github.com/labstack/gommon/random"
|
||||
"github.com/lightningnetwork/lnd/lnrpc"
|
||||
"github.com/uptrace/bun"
|
||||
"github.com/ziflex/lecho/v3"
|
||||
"golang.org/x/crypto/bcrypt"
|
||||
@@ -20,7 +20,7 @@ const alphaNumBytes = random.Alphanumeric
|
||||
type LndhubService struct {
|
||||
Config *Config
|
||||
DB *bun.DB
|
||||
LndClient lnrpc.LightningClient
|
||||
LndClient lnd.LightningClientWrapper
|
||||
Logger *lecho.Logger
|
||||
IdentityPubkey *btcec.PublicKey
|
||||
}
|
||||
|
||||
20
lnd/interface.go
Normal file
20
lnd/interface.go
Normal file
@@ -0,0 +1,20 @@
|
||||
package lnd
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/lightningnetwork/lnd/lnrpc"
|
||||
"google.golang.org/grpc"
|
||||
)
|
||||
|
||||
type LightningClientWrapper interface {
|
||||
ListChannels(ctx context.Context, req *lnrpc.ListChannelsRequest, options ...grpc.CallOption) (*lnrpc.ListChannelsResponse, error)
|
||||
SendPaymentSync(ctx context.Context, req *lnrpc.SendRequest, options ...grpc.CallOption) (*lnrpc.SendResponse, error)
|
||||
AddInvoice(ctx context.Context, req *lnrpc.Invoice, options ...grpc.CallOption) (*lnrpc.AddInvoiceResponse, error)
|
||||
SubscribeInvoices(ctx context.Context, req *lnrpc.InvoiceSubscription, options ...grpc.CallOption) (SubscribeInvoicesWrapper, error)
|
||||
GetInfo(ctx context.Context, req *lnrpc.GetInfoRequest, options ...grpc.CallOption) (*lnrpc.GetInfoResponse, error)
|
||||
}
|
||||
|
||||
type SubscribeInvoicesWrapper interface {
|
||||
Recv() (*lnrpc.Invoice, error)
|
||||
}
|
||||
30
lnd/lnd.go
30
lnd/lnd.go
@@ -1,6 +1,7 @@
|
||||
package lnd
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto/tls"
|
||||
"crypto/x509"
|
||||
"encoding/hex"
|
||||
@@ -23,8 +24,11 @@ type LNDoptions struct {
|
||||
MacaroonHex string
|
||||
}
|
||||
|
||||
func NewLNDclient(lndOptions LNDoptions) (lnrpc.LightningClient, error) {
|
||||
type LNDWrapper struct {
|
||||
client lnrpc.LightningClient
|
||||
}
|
||||
|
||||
func NewLNDclient(lndOptions LNDoptions) (result *LNDWrapper, err error) {
|
||||
// Get credentials either from a hex string, a file or the system's certificate store
|
||||
var creds credentials.TransportCredentials
|
||||
// if a hex string is provided
|
||||
@@ -82,5 +86,27 @@ func NewLNDclient(lndOptions LNDoptions) (lnrpc.LightningClient, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return lnrpc.NewLightningClient(conn), nil
|
||||
return &LNDWrapper{
|
||||
client: lnrpc.NewLightningClient(conn),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (wrapper *LNDWrapper) ListChannels(ctx context.Context, req *lnrpc.ListChannelsRequest, options ...grpc.CallOption) (*lnrpc.ListChannelsResponse, error) {
|
||||
return wrapper.client.ListChannels(ctx, req, options...)
|
||||
}
|
||||
|
||||
func (wrapper *LNDWrapper) SendPaymentSync(ctx context.Context, req *lnrpc.SendRequest, options ...grpc.CallOption) (*lnrpc.SendResponse, error) {
|
||||
return wrapper.client.SendPaymentSync(ctx, req, options...)
|
||||
}
|
||||
|
||||
func (wrapper *LNDWrapper) AddInvoice(ctx context.Context, req *lnrpc.Invoice, options ...grpc.CallOption) (*lnrpc.AddInvoiceResponse, error) {
|
||||
return wrapper.client.AddInvoice(ctx, req, options...)
|
||||
}
|
||||
|
||||
func (wrapper *LNDWrapper) SubscribeInvoices(ctx context.Context, req *lnrpc.InvoiceSubscription, options ...grpc.CallOption) (SubscribeInvoicesWrapper, error) {
|
||||
return wrapper.client.SubscribeInvoices(ctx, req, options...)
|
||||
}
|
||||
|
||||
func (wrapper *LNDWrapper) GetInfo(ctx context.Context, req *lnrpc.GetInfoRequest, options ...grpc.CallOption) (*lnrpc.GetInfoResponse, error) {
|
||||
return wrapper.client.GetInfo(ctx, req, options...)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user