2023-09-10 15:39:34 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"log"
|
|
|
|
"net/http"
|
|
|
|
|
2023-10-04 11:36:54 +00:00
|
|
|
"git.ekzyis.com/ekzyis/delphi.market/db"
|
2023-09-10 15:39:34 +00:00
|
|
|
"git.ekzyis.com/ekzyis/delphi.market/env"
|
2023-10-04 11:36:54 +00:00
|
|
|
"git.ekzyis.com/ekzyis/delphi.market/lnd"
|
2023-09-10 15:39:34 +00:00
|
|
|
"git.ekzyis.com/ekzyis/delphi.market/server"
|
2023-10-04 11:36:54 +00:00
|
|
|
"git.ekzyis.com/ekzyis/delphi.market/server/router"
|
|
|
|
"github.com/lightninglabs/lndclient"
|
|
|
|
"github.com/namsral/flag"
|
2023-09-10 15:39:34 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
s *server.Server
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
2023-10-04 11:36:54 +00:00
|
|
|
var (
|
|
|
|
dbUrl string
|
|
|
|
lndAddress string
|
|
|
|
lndCert string
|
|
|
|
lndMacaroonDir string
|
2023-11-22 23:13:51 +00:00
|
|
|
lndNetwork string
|
2023-10-04 11:36:54 +00:00
|
|
|
db_ *db.DB
|
|
|
|
lnd_ *lnd.LNDClient
|
|
|
|
ctx router.ServerContext
|
|
|
|
err error
|
|
|
|
)
|
|
|
|
if err = env.Load(); err != nil {
|
|
|
|
log.Fatalf("error loading env vars: %v", err)
|
|
|
|
}
|
|
|
|
flag.StringVar(&dbUrl, "DATABASE_URL", "delphi.market", "Public URL of website")
|
|
|
|
flag.StringVar(&lndAddress, "LND_ADDRESS", "localhost:10001", "LND gRPC server address")
|
|
|
|
flag.StringVar(&lndCert, "LND_CERT", "", "Path to LND TLS certificate")
|
|
|
|
flag.StringVar(&lndMacaroonDir, "LND_MACAROON_DIR", "", "LND macaroon directory")
|
2023-11-22 23:13:51 +00:00
|
|
|
flag.StringVar(&lndNetwork, "LND_NETWORK", "regtest", "LND network")
|
2023-10-04 11:36:54 +00:00
|
|
|
env.Parse()
|
|
|
|
figlet()
|
2023-09-10 15:39:34 +00:00
|
|
|
log.Printf("Commit: %s", env.CommitShortSha)
|
|
|
|
log.Printf("Public URL: %s", env.PublicURL)
|
|
|
|
log.Printf("Environment: %s", env.Env)
|
|
|
|
|
2023-10-04 11:36:54 +00:00
|
|
|
if db_, err = db.New(dbUrl); err != nil {
|
|
|
|
log.Fatalf("error connecting to database: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if lnd_, err = lnd.New(&lnd.LNDConfig{
|
|
|
|
LndAddress: lndAddress,
|
|
|
|
TLSPath: lndCert,
|
|
|
|
MacaroonDir: lndMacaroonDir,
|
2023-11-22 23:13:51 +00:00
|
|
|
Network: lndclient.Network(lndNetwork),
|
2023-10-04 11:36:54 +00:00
|
|
|
}); err != nil {
|
|
|
|
log.Printf("[warn] error connecting to LND: %v\n", err)
|
|
|
|
lnd_ = nil
|
2023-11-09 03:10:30 +00:00
|
|
|
} else {
|
|
|
|
lnd_.CheckInvoices(db_)
|
2023-10-04 11:36:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ctx = server.ServerContext{
|
|
|
|
PublicURL: env.PublicURL,
|
|
|
|
CommitShortSha: env.CommitShortSha,
|
|
|
|
CommitLongSha: env.CommitLongSha,
|
|
|
|
Version: env.Version,
|
|
|
|
Db: db_,
|
|
|
|
Lnd: lnd_,
|
|
|
|
}
|
|
|
|
s = server.New(ctx)
|
|
|
|
}
|
|
|
|
|
|
|
|
func figlet() {
|
|
|
|
log.Println(
|
|
|
|
"\n" +
|
|
|
|
" _ _ _ _ \n" +
|
|
|
|
" __| | ___| |_ __ | |__ (_)\n" +
|
|
|
|
" / _` |/ _ \\ | '_ \\| '_ \\| |\n" +
|
|
|
|
"| (_| | __/ | |_) | | | | |\n" +
|
|
|
|
" \\__,_|\\___|_| .__/|_| |_|_|\n" +
|
|
|
|
" |_| .market \n" +
|
|
|
|
"----------------------------",
|
|
|
|
)
|
2023-09-10 15:39:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
if err := s.Start(fmt.Sprintf("%s:%d", "127.0.0.1", env.Port)); err != http.ErrServerClosed {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|