Skip to content

Commit

Permalink
Extract hard-coded dcrdata urls from GUI code. (#328)
Browse files Browse the repository at this point in the history
dcrdata URLs are moved into `params.go` with the other hard-coded, network-specific values.

This change also removes the `dcrpool/gui` dependency on `dcrd/chaincfg` by updating `Config` to accept just the network name, rather than the `chaincfg.Params` struct.
  • Loading branch information
jholdstock committed May 7, 2021
1 parent 3260b64 commit ce3e89b
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 15 deletions.
3 changes: 2 additions & 1 deletion dcrpool.go
Expand Up @@ -99,7 +99,8 @@ func newPool(db pool.Database, cfg *config) (*miningPool, error) {
Domain: cfg.Domain,
TLSCertFile: cfg.GUITLSCert,
TLSKeyFile: cfg.GUITLSKey,
ActiveNet: cfg.net.Params,
ActiveNetName: cfg.net.Params.Name,
BlockExplorerURL: cfg.net.BlockExplorerURL,
PaymentMethod: cfg.PaymentMethod,
Designation: cfg.Designation,
PoolFee: cfg.PoolFee,
Expand Down
2 changes: 1 addition & 1 deletion gui/admin.go
Expand Up @@ -66,7 +66,7 @@ func (ui *GUI) adminPage(w http.ResponseWriter, r *http.Request) {
LastPaymentHeight: lastPaymentHeight,
PoolHashRate: ui.cache.getPoolHash(),
PaymentMethod: ui.cfg.PaymentMethod,
Network: ui.cfg.ActiveNet.Name,
Network: ui.cfg.ActiveNetName,
PoolFee: ui.cfg.PoolFee,
SoloPool: ui.cfg.SoloPool,
},
Expand Down
14 changes: 2 additions & 12 deletions gui/gui.go
Expand Up @@ -22,7 +22,6 @@ import (
"github.com/gorilla/mux"
"github.com/gorilla/sessions"

"github.com/decred/dcrd/chaincfg/v3"
"github.com/decred/dcrpool/pool"
)

Expand Down Expand Up @@ -51,8 +50,8 @@ type Config struct {
NoGUITLS bool
// Domain represents the domain name of the pool.
Domain string
// ActiveNet represents the active network being mined on.
ActiveNet *chaincfg.Params
// ActiveNetName is the name of the active network being mined on.
ActiveNetName string
// BlockExplorerURL represents the active network block explorer.
BlockExplorerURL string
// Designation represents the codename of the pool.
Expand Down Expand Up @@ -187,15 +186,6 @@ func NewGUI(cfg *Config) (*GUI, error) {
limiter: pool.NewRateLimiter(),
}

switch cfg.ActiveNet.Name {
case chaincfg.TestNet3Params().Name:
ui.cfg.BlockExplorerURL = "https://testnet.dcrdata.org"
case chaincfg.SimNetParams().Name:
ui.cfg.BlockExplorerURL = "..."
default:
ui.cfg.BlockExplorerURL = "https://dcrdata.decred.org"
}

ui.cookieStore = sessions.NewCookieStore(cfg.CSRFSecret)
ui.websocketServer = NewWebsocketServer()

Expand Down
2 changes: 1 addition & 1 deletion gui/index.go
Expand Up @@ -62,7 +62,7 @@ func (ui *GUI) renderIndex(w http.ResponseWriter, r *http.Request, modalError st
LastPaymentHeight: lastPaymentHeight,
PoolHashRate: ui.cache.getPoolHash(),
PaymentMethod: ui.cfg.PaymentMethod,
Network: ui.cfg.ActiveNet.Name,
Network: ui.cfg.ActiveNetName,
PoolFee: ui.cfg.PoolFee,
SoloPool: ui.cfg.SoloPool,
},
Expand Down
4 changes: 4 additions & 0 deletions params.go
Expand Up @@ -12,22 +12,26 @@ type params struct {
*chaincfg.Params
DcrdRPCServerPort string
WalletGRPCServerPort string
BlockExplorerURL string
}

var mainNetParams = params{
Params: chaincfg.MainNetParams(),
DcrdRPCServerPort: "9109",
WalletGRPCServerPort: "9111",
BlockExplorerURL: "https://dcrdata.decred.org",
}

var testNet3Params = params{
Params: chaincfg.TestNet3Params(),
DcrdRPCServerPort: "19109",
WalletGRPCServerPort: "19111",
BlockExplorerURL: "https://testnet.dcrdata.org",
}

var simNetParams = params{
Params: chaincfg.SimNetParams(),
DcrdRPCServerPort: "19556",
WalletGRPCServerPort: "19558",
BlockExplorerURL: "...",
}

0 comments on commit ce3e89b

Please sign in to comment.