Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/reconciliation invoices #484

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
21 changes: 21 additions & 0 deletions .github/workflows/build_reconciliation.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Reconciliation Docker build & push
on:
push:
jobs:
build:
env:
REGISTRY: ghcr.io
IMAGENAME: lndhub-reconciliation
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
name: Check out code
- name: Docker build
uses: mr-smithers-excellent/docker-build-push@v5
id: build
with:
dockerfile: reconciliation.Dockerfile
image: ${{ env.IMAGENAME }}
registry: ${{ env.REGISTRY }}
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
4 changes: 4 additions & 0 deletions lnd/lnd.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,3 +137,7 @@ func (wrapper *LNDWrapper) IsIdentityPubkey(pubkey string) (isOurPubkey bool) {
func (wrapper *LNDWrapper) GetMainPubkey() (pubkey string) {
return wrapper.IdentityPubkey
}

func (wrapper *LNDWrapper) ListInvoices(ctx context.Context, req *lnrpc.ListInvoiceRequest, options ...grpc.CallOption) (*lnrpc.ListInvoiceResponse, error) {
return wrapper.client.ListInvoices(ctx, req, options...)
}
24 changes: 24 additions & 0 deletions reconciliation.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
FROM golang:1.20-alpine as builder

# Move to working directory /build
WORKDIR /build

# Copy and download dependency using go mod
COPY go.mod .
COPY go.sum .
RUN go mod download

# Copy the code into the container
COPY . .

# Build the application
WORKDIR /build/reconciliation_lost_invoices
RUN go build -o main

# Start a new, final image to reduce size.
FROM alpine as final

# Copy the binaries and entrypoint from the builder image.
COPY --from=builder /build/reconciliation_lost_invoices/main /bin/

ENTRYPOINT [ "/bin/main" ]
79 changes: 79 additions & 0 deletions reconciliation_lost_invoices/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package main

import (
"context"
"fmt"
"log"

"github.com/getAlby/lndhub.go/db"
"github.com/getAlby/lndhub.go/lib"
"github.com/getAlby/lndhub.go/lib/service"
"github.com/getAlby/lndhub.go/lnd"
"github.com/getsentry/sentry-go"
"github.com/joho/godotenv"
"github.com/kelseyhightower/envconfig"
"github.com/labstack/echo/v4"
)

// script to reconcile pending payments between the backup node and the database
func main() {

c := &service.Config{}

// Load configruation from environment variables
err := godotenv.Load(".env")
if err != nil {
fmt.Println("Failed to load .env file")
}
err = envconfig.Process("", c)
if err != nil {
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)
if err != nil {
logger.Fatalf("Error initializing db connection: %v", err)
}

// Migrate the DB
//Todo: use timeout for startupcontext
startupCtx := context.Background()

// New Echo app
e := echo.New()

//// Init new LND client
lnCfg, err := lnd.LoadConfig()
if err != nil {
logger.Fatalf("Error loading LN config: %v", err)
}
lndClient, err := lnd.InitLNClient(lnCfg, logger, startupCtx)

if err != nil {
e.Logger.Fatalf("Error initializing the LND connection: %v", err)
}
logger.Infof("Connected to LND: %s ", lndClient.GetMainPubkey())

svc := &service.LndhubService{
Config: c,
DB: dbConn,
LndClient: lndClient,
Logger: logger,
InvoicePubSub: service.NewPubsub(),
}

pendingPayments, err := svc.GetAllPendingPayments(startupCtx)
if err != nil {
return
}

err = svc.CheckPendingOutgoingPayments(startupCtx, pendingPayments)
if err != nil {
sentry.CaptureException(err)
svc.Logger.Error(err)
}
}
Loading