Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ LIBP2P_BOOT_NODES=
BTC_RPC=http://localhost:8332
BTC_RPC_USER=
BTC_RPC_PASS=
# If BTC_RPC_API_KEY is set and user/pass are empty, dummy basic auth is applied.
BTC_RPC_API_KEY=
BTC_START_HEIGHT=0
BTC_CONFIRMATIONS=6
BTC_NETWORK_TYPE=regtest
Expand Down Expand Up @@ -38,4 +40,4 @@ RELAYER_BLS_SK=
BLS_SIG_TIMEOUT=300s
MIN_DEPOSIT_AMOUNT=1000000

GIN_MODE=release
GIN_MODE=release
29 changes: 25 additions & 4 deletions cmd/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"context"
"net/url"
"os"
"os/signal"
"sync"
Expand Down Expand Up @@ -39,13 +40,33 @@ type Application struct {

func NewApplication() *Application {
config.InitConfig()
// Allow BTC_RPC to be either host:port or full URL so TLS can be inferred.
rpcHost := config.AppConfig.BTCRPC
disableTLS := true
if parsed, err := url.Parse(rpcHost); err == nil && parsed.Host != "" {
rpcHost = parsed.Host
disableTLS = parsed.Scheme != "https"
}
var extraHeaders map[string]string
if config.AppConfig.BTCRPCApiKey != "" {
extraHeaders = map[string]string{
"x-api-key": config.AppConfig.BTCRPCApiKey,
}
}
rpcUser := config.AppConfig.BTCRPC_USER
rpcPass := config.AppConfig.BTCRPC_PASS
if config.AppConfig.BTCRPCApiKey != "" && rpcUser == "" && rpcPass == "" {
rpcUser = "api"
rpcPass = "api"
}
// create bitcoin client using btc module connection
connConfig := &rpcclient.ConnConfig{
Host: config.AppConfig.BTCRPC,
User: config.AppConfig.BTCRPC_USER,
Pass: config.AppConfig.BTCRPC_PASS,
Host: rpcHost,
User: rpcUser,
Pass: rpcPass,
HTTPPostMode: true,
DisableTLS: true,
DisableTLS: disableTLS,
ExtraHeaders: extraHeaders,
}
btcClient, err := rpcclient.New(connConfig, nil)
if err != nil {
Expand Down
3 changes: 3 additions & 0 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ func InitConfig() {
viper.SetDefault("BTC_RPC", "http://localhost:8332")
viper.SetDefault("BTC_RPC_USER", "")
viper.SetDefault("BTC_RPC_PASS", "")
viper.SetDefault("BTC_RPC_API_KEY", "")
viper.SetDefault("BTC_CONFIRMATIONS", 6)
viper.SetDefault("BTC_START_HEIGHT", 0)
viper.SetDefault("BTC_NETWORK_TYPE", "")
Expand Down Expand Up @@ -84,6 +85,7 @@ func InitConfig() {
BTCRPC: viper.GetString("BTC_RPC"),
BTCRPC_USER: viper.GetString("BTC_RPC_USER"),
BTCRPC_PASS: viper.GetString("BTC_RPC_PASS"),
BTCRPCApiKey: viper.GetString("BTC_RPC_API_KEY"),
BTCStartHeight: viper.GetInt("BTC_START_HEIGHT"),
BTCReindexBlocks: viper.GetString("BTC_REINDEX_BLOCKS"),
BTCConfirmations: viper.GetInt("BTC_CONFIRMATIONS"),
Expand Down Expand Up @@ -142,6 +144,7 @@ type Config struct {
BTCRPC string
BTCRPC_USER string
BTCRPC_PASS string
BTCRPCApiKey string
BTCStartHeight int
BTCConfirmations int
BTCNetworkType string
Expand Down
Loading