mirror of
https://github.com/getAlby/lndhub.go.git
synced 2026-02-23 13:54:25 +01:00
Merge main
This commit is contained in:
@@ -2,6 +2,7 @@ package migrations
|
||||
|
||||
import (
|
||||
"embed"
|
||||
"log"
|
||||
|
||||
"github.com/uptrace/bun/migrate"
|
||||
)
|
||||
@@ -13,6 +14,6 @@ var sqlMigrations embed.FS
|
||||
|
||||
func init() {
|
||||
if err := Migrations.Discover(sqlMigrations); err != nil {
|
||||
panic(err)
|
||||
log.Fatalf("Error discovering migrations: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,10 +76,9 @@ func (svc *LndhubService) PayInvoice(invoice *models.Invoice) (*models.Transacti
|
||||
Amt: invoice.Amount,
|
||||
FeeLimit: &feeLimit,
|
||||
}
|
||||
lndClient := *svc.LndClient
|
||||
|
||||
// Execute the payment
|
||||
sendPaymentResult, err := lndClient.SendPaymentSync(context.TODO(), &sendPaymentRequest)
|
||||
sendPaymentResult, err := svc.LndClient.SendPaymentSync(context.TODO(), &sendPaymentRequest)
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
return &entry, err
|
||||
@@ -167,9 +166,8 @@ func (svc *LndhubService) AddIncomingInvoice(userID int64, amount int64, memo, d
|
||||
RPreimage: makePreimageHex(),
|
||||
Expiry: 3600 * 24, // 24h
|
||||
}
|
||||
lndClient := *svc.LndClient
|
||||
// Call LND
|
||||
lnInvoiceResult, err := lndClient.AddInvoice(context.TODO(), &lnInvoice)
|
||||
lnInvoiceResult, err := svc.LndClient.AddInvoice(context.TODO(), &lnInvoice)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -7,6 +7,5 @@ import (
|
||||
)
|
||||
|
||||
func (svc *LndhubService) GetInfo(ctx context.Context) (*lnrpc.GetInfoResponse, error) {
|
||||
lndClient := *svc.LndClient
|
||||
return lndClient.GetInfo(ctx, &lnrpc.GetInfoRequest{})
|
||||
return svc.LndClient.GetInfo(ctx, &lnrpc.GetInfoRequest{})
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ const alphaNumBytes = random.Alphanumeric
|
||||
type LndhubService struct {
|
||||
Config *Config
|
||||
DB *bun.DB
|
||||
LndClient *lnrpc.LightningClient
|
||||
LndClient lnrpc.LightningClient
|
||||
}
|
||||
|
||||
func (svc *LndhubService) GenerateToken(login, password, inRefreshToken string) (accessToken, refreshToken string, err error) {
|
||||
|
||||
20
main.go
20
main.go
@@ -3,6 +3,7 @@ package main
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"os/signal"
|
||||
@@ -37,13 +38,16 @@ func main() {
|
||||
}
|
||||
err = envconfig.Process("", c)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
log.Fatalf("Error loading environment variables: %v", err)
|
||||
}
|
||||
|
||||
// Setup logging to STDOUT or a configrued log file
|
||||
logger := lib.Logger(c.LogFilePath)
|
||||
|
||||
// Open a DB connection based on the configured DATABASE_URI
|
||||
dbConn, err := db.Open(c.DatabaseUri)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
logger.Fatalf("Error initializing db connection: %v", err)
|
||||
}
|
||||
|
||||
// Migrate the DB
|
||||
@@ -51,11 +55,11 @@ func main() {
|
||||
migrator := migrate.NewMigrator(dbConn, migrations.Migrations)
|
||||
err = migrator.Init(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
logger.Fatalf("Error initializing db migrator: %v", err)
|
||||
}
|
||||
_, err = migrator.Migrate(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
logger.Fatalf("Error migrating database: %v", err)
|
||||
}
|
||||
|
||||
// New Echo app
|
||||
@@ -68,8 +72,6 @@ func main() {
|
||||
e.Use(middleware.BodyLimit("250K"))
|
||||
e.Use(middleware.RateLimiter(middleware.NewRateLimiterMemoryStore(20)))
|
||||
|
||||
// Setup logging to STDOUT or a configrued log file
|
||||
logger := lib.Logger(c.LogFilePath)
|
||||
e.Logger = logger
|
||||
e.Use(middleware.RequestID())
|
||||
e.Use(lecho.Middleware(lecho.Config{
|
||||
@@ -94,18 +96,18 @@ func main() {
|
||||
CertHex: c.LNDCertHex,
|
||||
})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
e.Logger.Fatalf("Error initializing the LND connection: %v", err)
|
||||
}
|
||||
getInfo, err := lndClient.GetInfo(ctx, &lnrpc.GetInfoRequest{})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
e.Logger.Fatalf("Error getting node info: %v", err)
|
||||
}
|
||||
logger.Infof("Connected to LND: %s - %s", getInfo.Alias, getInfo.IdentityPubkey)
|
||||
|
||||
svc := &service.LndhubService{
|
||||
Config: c,
|
||||
DB: dbConn,
|
||||
LndClient: &lndClient,
|
||||
LndClient: lndClient,
|
||||
}
|
||||
|
||||
// Public endpoints for account creation and authentication
|
||||
|
||||
Reference in New Issue
Block a user