From b792b899401ae3438bc7170f374950dbd7732949 Mon Sep 17 00:00:00 2001 From: jholdstock Date: Fri, 7 May 2021 17:30:25 +0100 Subject: [PATCH 1/4] Use a proper type for admin page search results. --- webapi/admin.go | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/webapi/admin.go b/webapi/admin.go index 9418e83f..291adb1f 100644 --- a/webapi/admin.go +++ b/webapi/admin.go @@ -7,6 +7,7 @@ package webapi import ( "net/http" + "github.com/decred/vspd/database" "github.com/decred/vspd/rpc" "github.com/gin-gonic/gin" "github.com/gorilla/sessions" @@ -26,6 +27,14 @@ type WalletStatus struct { BestBlockHeight int64 `json:"bestblockheight"` } +type searchResult struct { + Hash string + Found bool + Ticket database.Ticket + VoteChanges map[uint32]database.VoteChangeRecord + MaxVoteChanges int +} + func walletStatus(c *gin.Context) map[string]WalletStatus { walletClients := c.MustGet("WalletClients").([]*rpc.WalletRPC) failedWalletClients := c.MustGet("FailedWalletClients").([]string) @@ -113,12 +122,12 @@ func ticketSearch(c *gin.Context) { } c.HTML(http.StatusOK, "admin.html", gin.H{ - "SearchResult": gin.H{ - "Hash": hash, - "Found": found, - "Ticket": ticket, - "VoteChanges": voteChanges, - "MaxVoteChanges": cfg.MaxVoteChangeRecords, + "SearchResult": searchResult{ + Hash: hash, + Found: found, + Ticket: ticket, + VoteChanges: voteChanges, + MaxVoteChanges: cfg.MaxVoteChangeRecords, }, "VspStats": getVSPStats(), "WalletStatus": walletStatus(c), From b75e24eecb806046d77ccc73385056def484c935 Mon Sep 17 00:00:00 2001 From: jholdstock Date: Fri, 7 May 2021 18:17:18 +0100 Subject: [PATCH 2/4] 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 5fdf516d..d502ca52 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 b667c3cc..b9ee11bd 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 00000000..1cbe120a --- /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 0a9c6a4b..35da78d9 100644 --- a/webapi/templates/admin.html +++ b/webapi/templates/admin.html @@ -97,7 +97,11 @@

Search Result

- + @@ -109,7 +113,11 @@

Search Result

- + @@ -173,12 +181,16 @@

Search Result

- - + + - - + + diff --git a/webapi/webapi.go b/webapi/webapi.go index 3f9e03c5..8e716096 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 From e422ea232f71b9afa8842d79d6fb3ec7ba99860c Mon Sep 17 00:00:00 2001 From: jholdstock Date: Sat, 8 May 2021 09:45:37 +0100 Subject: [PATCH 3/4] Show formatted date for fee expiry --- webapi/formatting.go | 6 ++++++ webapi/homepage.go | 2 +- webapi/templates/admin.html | 2 +- webapi/webapi.go | 2 +- 4 files changed, 9 insertions(+), 3 deletions(-) diff --git a/webapi/formatting.go b/webapi/formatting.go index 1cbe120a..b3489c8e 100644 --- a/webapi/formatting.go +++ b/webapi/formatting.go @@ -1,5 +1,7 @@ package webapi +import "time" + func addressURL(blockExplorerURL string) func(string) string { return func(addr string) string { return blockExplorerURL + "/address/" + addr @@ -11,3 +13,7 @@ func txURL(blockExplorerURL string) func(string) string { return blockExplorerURL + "/tx/" + txID } } + +func dateTime(t int64) string { + return time.Unix(t, 0).Format("2 Jan 2006 15:04:05") +} diff --git a/webapi/homepage.go b/webapi/homepage.go index b3168f00..626f82b8 100644 --- a/webapi/homepage.go +++ b/webapi/homepage.go @@ -55,7 +55,7 @@ func updateVSPStats(db *database.VspDatabase, cfg Config) error { Revoked: revoked, VSPFee: cfg.VSPFee, Network: cfg.NetParams.Name, - UpdateTime: time.Now().Format("Mon Jan _2 15:04:05 2006"), + UpdateTime: dateTime(time.Now().Unix()), SupportEmail: cfg.SupportEmail, VspClosed: cfg.VspClosed, Debug: cfg.Debug, diff --git a/webapi/templates/admin.html b/webapi/templates/admin.html index 35da78d9..d7f71915 100644 --- a/webapi/templates/admin.html +++ b/webapi/templates/admin.html @@ -125,7 +125,7 @@

Search Result

- + diff --git a/webapi/webapi.go b/webapi/webapi.go index 8e716096..9aecd3b0 100644 --- a/webapi/webapi.go +++ b/webapi/webapi.go @@ -179,8 +179,8 @@ func router(debugMode bool, cookieSecret []byte, dcrd rpc.DcrdConnect, wallets r // Add custom functions for use in templates. router.SetFuncMap(template.FuncMap{ "txURL": txURL(cfg.BlockExplorerURL), - "blockURL": blockURL(cfg.BlockExplorerURL), "addressURL": addressURL(cfg.BlockExplorerURL), + "dateTime": dateTime, }) router.LoadHTMLGlob("webapi/templates/*.html") From 4a484d063977f7d39d757791261f81c44458471c Mon Sep 17 00:00:00 2001 From: Jamie Holdstock Date: Thu, 13 May 2021 03:02:59 +0100 Subject: [PATCH 4/4] Remove non-existent simnet block explorer. --- params.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/params.go b/params.go index d502ca52..56ff829a 100644 --- a/params.go +++ b/params.go @@ -33,5 +33,5 @@ var simNetParams = netParams{ Params: chaincfg.SimNetParams(), DcrdRPCServerPort: "19556", WalletRPCServerPort: "19557", - BlockExplorerURL: "https://dcrdata.decred.org", + BlockExplorerURL: "...", }
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
Fee Expiration{{ .Ticket.FeeExpiration }}{{ .Ticket.FeeExpiration }} ({{ dateTime .Ticket.FeeExpiration }})
Confirmed