-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from getAlby/publish-invoices
republish invoices cmd
- Loading branch information
Showing
11 changed files
with
224 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"encoding/hex" | ||
"github.com/getAlby/ln-event-publisher/config" | ||
"github.com/getAlby/ln-event-publisher/lnd" | ||
"github.com/getAlby/ln-event-publisher/service" | ||
"github.com/getsentry/sentry-go" | ||
"github.com/joho/godotenv" | ||
"github.com/kelseyhightower/envconfig" | ||
"github.com/lightningnetwork/lnd/lnrpc" | ||
"github.com/sirupsen/logrus" | ||
"os" | ||
"os/signal" | ||
) | ||
|
||
func main() { | ||
c := &config.Config{} | ||
logrus.SetFormatter(&logrus.JSONFormatter{}) | ||
|
||
// Load configruation from environment variables | ||
err := godotenv.Load(".env") | ||
if err != nil { | ||
logrus.Warn("Failed to load .env file") | ||
} | ||
err = envconfig.Process("", c) | ||
if err != nil { | ||
logrus.Fatalf("Error loading environment variables: %v", err) | ||
} | ||
|
||
// Setup exception tracking with Sentry if configured | ||
if c.SentryDSN != "" { | ||
if err = sentry.Init(sentry.ClientOptions{ | ||
Dsn: c.SentryDSN, | ||
}); err != nil { | ||
logrus.Error(err) | ||
} | ||
} | ||
client, err := lnd.NewLNDclient(lnd.LNDoptions{ | ||
Address: c.LNDAddress, | ||
MacaroonFile: c.LNDMacaroonFile, | ||
CertFile: c.LNDCertFile, | ||
}) | ||
if err != nil { | ||
sentry.CaptureException(err) | ||
logrus.Fatalf("Error loading environment variables: %v", err) | ||
} | ||
resp, err := client.GetInfo(context.Background(), &lnrpc.GetInfoRequest{}) | ||
if err != nil { | ||
sentry.CaptureException(err) | ||
logrus.Fatal(err) | ||
} | ||
logrus.Infof("Connected to LND: %s - %s", resp.Alias, resp.IdentityPubkey) | ||
svc := &service.Service{ | ||
Cfg: c, | ||
Lnd: client, | ||
} | ||
err = svc.InitRabbitMq() | ||
if err != nil { | ||
sentry.CaptureException(err) | ||
logrus.Fatal(err) | ||
} | ||
backgroundCtx := context.Background() | ||
ctx, _ := signal.NotifyContext(backgroundCtx, os.Interrupt) | ||
|
||
for i := 0; i < len(c.RepublishInvoiceHashes); i++ { | ||
hashBytes, err := hex.DecodeString(c.RepublishInvoiceHashes[i]) | ||
if err != nil { | ||
logrus.Error("Invalid Hash ", c.RepublishInvoiceHashes[i], " ", err) | ||
continue | ||
} | ||
|
||
// Create a PaymentHash struct | ||
paymentHash := &lnrpc.PaymentHash{ | ||
RHash: hashBytes, | ||
} | ||
svc.RepublishInvoice(ctx, paymentHash) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package config | ||
|
||
type Config struct { | ||
LNDAddress string `envconfig:"LND_ADDRESS" required:"true"` | ||
LNDMacaroonFile string `envconfig:"LND_MACAROON_FILE"` | ||
LNDCertFile string `envconfig:"LND_CERT_FILE"` | ||
DatabaseUri string `envconfig:"DATABASE_URI" required:"true"` | ||
DatabaseMaxConns int `envconfig:"DATABASE_MAX_CONNS" default:"10"` | ||
DatabaseMaxIdleConns int `envconfig:"DATABASE_MAX_IDLE_CONNS" default:"5"` | ||
DatabaseConnMaxLifetime int `envconfig:"DATABASE_CONN_MAX_LIFETIME" default:"1800"` // 30 minutes | ||
RabbitMQUri string `envconfig:"RABBITMQ_URI" required:"true"` | ||
RabbitMQTimeoutSeconds int `envconfig:"RABBITMQ_TIMEOUT_SECONDS" default:"10"` | ||
SentryDSN string `envconfig:"SENTRY_DSN"` | ||
RepublishInvoiceHashes []string `envconfig:"REPUBLISH_INVOICE_HASHES"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.