chore: add NETWORK to config

This commit is contained in:
im-adithya 2025-05-14 18:56:39 +05:30
parent 89ce1fcb69
commit 4990eeff35
6 changed files with 31 additions and 13 deletions

View file

@ -38,4 +38,5 @@ FRONTEND_URL=http://localhost:5173
#LDK_VSS_URL="http://localhost:8090/vss"
# Boltz API
#BOLTZ_API=https://api.testnet.boltz.exchange
#BOLTZ_API=https://api.testnet.boltz.exchange
#NETWORK=testnet

View file

@ -159,13 +159,14 @@ For more information refer to:
The following configuration options can be set as environment variables or in a .env file
- `RELAY`: default: "wss://relay.getalby.com/v1"
- `JWT_SECRET`: a randomly generated secret string. (only needed in http mode)
- `DATABASE_URI`: a sqlite filename or postgres URL. Default is SQLite DB `nwc.db` without a path, which will be put in the user home directory: $XDG_DATA_HOME/albyhub/nwc.db
- `PORT`: the port on which the app should listen on (default: 8080)
- `WORK_DIR`: directory to store NWC data files. Default: $XDG_DATA_HOME/albyhub
- `LOG_LEVEL`: log level for the application. Higher is more verbose. Default: 4 (info)
- `AUTO_UNLOCK_PASSWORD`: provide unlock password to auto-unlock Alby Hub on startup (e.g. after a machine restart). Unlock password still be required to access the interface.
- `BOLTZ_API`: the api which provides auto swaps functionality. Default: "https://api.boltz.exchange"
- `JWT_SECRET`: A randomly generated secret string. (only needed in http mode)
- `DATABASE_URI`: A sqlite filename or postgres URL. Default is SQLite DB `nwc.db` without a path, which will be put in the user home directory: $XDG_DATA_HOME/albyhub/nwc.db
- `PORT`: The port on which the app should listen on (default: 8080)
- `WORK_DIR`: Directory to store NWC data files. Default: $XDG_DATA_HOME/albyhub
- `LOG_LEVEL`: Log level for the application. Higher is more verbose. Default: 4 (info)
- `AUTO_UNLOCK_PASSWORD`: Provide unlock password to auto-unlock Alby Hub on startup (e.g. after a machine restart). Unlock password still be required to access the interface.
- `BOLTZ_API`: The api which provides auto swaps functionality. Default: "https://api.boltz.exchange"
- `NETWORK`: On-chain network used for auto swaps. Should match the backend network. Default: "bitcoin"
### Migrating the database (Sqlite <-> Postgres)
@ -205,14 +206,14 @@ _To configure via env, the following parameters must be provided:_
##### Mutinynet
- `MEMPOOL_API=https://mutinynet.com/api`
- `LDK_NETWORK=signet`
- `NETWORK=signet`
- `LDK_ESPLORA_SERVER=https://mutinynet.com/api`
- `LDK_GOSSIP_SOURCE=https://rgs.mutinynet.com/snapshot`
##### Testnet (Not recommended - try Mutinynet)
- `MEMPOOL_API=https://mempool.space/testnet/api`
- `LDK_NETWORK=testnet`
- `NETWORK=testnet`
- `LDK_ESPLORA_SERVER=https://mempool.space/testnet/api`
- `LDK_GOSSIP_SOURCE=https://rapidsync.lightningdevkit.org/testnet/snapshot`

View file

@ -146,6 +146,20 @@ func (cfg *config) GetRelayUrl() string {
return relayUrl
}
func (cfg *config) GetNetwork() string {
env := cfg.GetEnv()
if env.Network != "" {
return env.Network
}
if env.LDKNetwork != "" {
return env.LDKNetwork
}
return "bitcoin"
}
func (cfg *config) Get(key string, encryptionKey string) (string, error) {
return cfg.get(key, encryptionKey, cfg.db)
}

View file

@ -26,7 +26,8 @@ type AppConfig struct {
JWTSecret string `envconfig:"JWT_SECRET"`
LogLevel string `envconfig:"LOG_LEVEL" default:"4"`
LogToFile bool `envconfig:"LOG_TO_FILE" default:"true"`
LDKNetwork string `envconfig:"LDK_NETWORK" default:"bitcoin"`
Network string `envconfig:"NETWORK"`
LDKNetwork string `envconfig:"LDK_NETWORK"`
LDKEsploraServer string `envconfig:"LDK_ESPLORA_SERVER" default:"https://electrs.getalbypro.com"` // TODO: remove LDK prefix
LDKGossipSource string `envconfig:"LDK_GOSSIP_SOURCE"`
LDKLogLevel string `envconfig:"LDK_LOG_LEVEL" default:"3"`
@ -60,6 +61,7 @@ type Config interface {
SetUpdate(key string, value string, encryptionKey string) error
GetJWTSecret() string
GetRelayUrl() string
GetNetwork() string
GetEnv() *AppConfig
CheckUnlockPassword(password string) bool
ChangeUnlockPassword(currentUnlockPassword string, newUnlockPassword string) error

View file

@ -352,7 +352,7 @@ func (svc *service) launchLNBackend(ctx context.Context, encryptionKey string) e
setStartupState := func(startupState string) {
svc.startupState = startupState
}
lnClient, err = ldk.NewLDKService(ctx, svc.cfg, svc.eventPublisher, mnemonic, ldkWorkdir, svc.cfg.GetEnv().LDKNetwork, vssToken, setStartupState)
lnClient, err = ldk.NewLDKService(ctx, svc.cfg, svc.eventPublisher, mnemonic, ldkWorkdir, svc.cfg.GetNetwork(), vssToken, setStartupState)
case config.PhoenixBackendType:
PhoenixdAddress, _ := svc.cfg.Get("PhoenixdAddress", encryptionKey)
PhoenixdAuthorization, _ := svc.cfg.Get("PhoenixdAuthorization", encryptionKey)

View file

@ -138,7 +138,7 @@ func (svc *swapsService) StopAutoSwaps() {
}
func (svc *swapsService) ReverseSwap(ctx context.Context, amount uint64, destination string, lnClient lnclient.LNClient) error {
var network, err = boltz.ParseChain(svc.cfg.GetEnv().LDKNetwork)
var network, err = boltz.ParseChain(svc.cfg.GetNetwork())
if err != nil {
return err
}