From b5a65a9e7886497ad2df6fcc3fe978a24c31caea Mon Sep 17 00:00:00 2001 From: jholdstock Date: Fri, 7 May 2021 18:17:18 +0100 Subject: [PATCH] Add block explorer links to tx hashes and fee addr --- params.go | 4 ++++ vspd.go | 1 + webapi/formatting.go | 13 +++++++++++++ webapi/templates/admin.html | 24 ++++++++++++++++++------ webapi/webapi.go | 10 ++++++++++ 5 files changed, 46 insertions(+), 6 deletions(-) create mode 100644 webapi/formatting.go diff --git a/params.go b/params.go index 5fdf516..d502ca5 100644 --- a/params.go +++ b/params.go @@ -12,22 +12,26 @@ type netParams struct { *chaincfg.Params DcrdRPCServerPort string WalletRPCServerPort string + BlockExplorerURL string } var mainNetParams = netParams{ Params: chaincfg.MainNetParams(), DcrdRPCServerPort: "9109", WalletRPCServerPort: "9110", + BlockExplorerURL: "https://dcrdata.decred.org", } var testNet3Params = netParams{ Params: chaincfg.TestNet3Params(), DcrdRPCServerPort: "19109", WalletRPCServerPort: "19110", + BlockExplorerURL: "https://testnet.dcrdata.org", } var simNetParams = netParams{ Params: chaincfg.SimNetParams(), DcrdRPCServerPort: "19556", WalletRPCServerPort: "19557", + BlockExplorerURL: "https://dcrdata.decred.org", } diff --git a/vspd.go b/vspd.go index b667c3c..b9ee11b 100644 --- a/vspd.go +++ b/vspd.go @@ -87,6 +87,7 @@ func run(ctx context.Context) error { apiCfg := webapi.Config{ VSPFee: cfg.VSPFee, NetParams: cfg.netParams.Params, + BlockExplorerURL: cfg.netParams.BlockExplorerURL, SupportEmail: cfg.SupportEmail, VspClosed: cfg.VspClosed, AdminPass: cfg.AdminPass, diff --git a/webapi/formatting.go b/webapi/formatting.go new file mode 100644 index 0000000..1cbe120 --- /dev/null +++ b/webapi/formatting.go @@ -0,0 +1,13 @@ +package webapi + +func addressURL(blockExplorerURL string) func(string) string { + return func(addr string) string { + return blockExplorerURL + "/address/" + addr + } +} + +func txURL(blockExplorerURL string) func(string) string { + return func(txID string) string { + return blockExplorerURL + "/tx/" + txID + } +} diff --git a/webapi/templates/admin.html b/webapi/templates/admin.html index 0a9c6a4..35da78d 100644 --- a/webapi/templates/admin.html +++ b/webapi/templates/admin.html @@ -97,7 +97,11 @@ - + @@ -109,7 +113,11 @@ - + @@ -173,12 +181,16 @@ - - + + - - + + diff --git a/webapi/webapi.go b/webapi/webapi.go index 3f9e03c..8e71609 100644 --- a/webapi/webapi.go +++ b/webapi/webapi.go @@ -11,6 +11,7 @@ import ( "encoding/json" "errors" "fmt" + "html/template" "net" "net/http" "sync" @@ -26,6 +27,7 @@ import ( type Config struct { VSPFee float64 NetParams *chaincfg.Params + BlockExplorerURL string FeeAccountName string SupportEmail string VspClosed bool @@ -173,6 +175,14 @@ func router(debugMode bool, cookieSecret []byte, dcrd rpc.DcrdConnect, wallets r } router := gin.New() + + // Add custom functions for use in templates. + router.SetFuncMap(template.FuncMap{ + "txURL": txURL(cfg.BlockExplorerURL), + "blockURL": blockURL(cfg.BlockExplorerURL), + "addressURL": addressURL(cfg.BlockExplorerURL), + }) + router.LoadHTMLGlob("webapi/templates/*.html") // Recovery middleware handles any go panics generated while processing web
Hash{{ .Ticket.Hash }} + + {{ .Ticket.Hash }} + +
Commitment Address
Fee Address{{ .Ticket.FeeAddress }} + + {{ .Ticket.FeeAddress }} + +
Fee Amount{{ .Ticket.VotingWIF }}
Fee Tx{{ .Ticket.FeeTxHex }}Fee Tx Hash + + {{ .Ticket.FeeTxHash }} + +
Fee Tx Hash{{ .Ticket.FeeTxHash }}Fee Tx{{ .Ticket.FeeTxHex }}
Fee Tx Status