Skip to content

Commit

Permalink
multi: remove /statistics, /stats and redirect /stats to homepage
Browse files Browse the repository at this point in the history
Signed-off-by: Philemon Ukane <[email protected]>
  • Loading branch information
ukane-philemon committed Sep 19, 2024
1 parent 1f13820 commit 9526082
Show file tree
Hide file tree
Showing 7 changed files with 7 additions and 437 deletions.
6 changes: 2 additions & 4 deletions cmd/dcrdata/internal/explorer/explorer.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2018-2022, The Decred developers
// Copyright (c) 2018-2024, The Decred developers
// Copyright (c) 2017, The dcrdata developers
// See LICENSE for details.

Expand Down Expand Up @@ -366,7 +366,7 @@ func New(cfg *ExplorerConfig) *explorerUI {

tmpls := []string{"home", "blocks", "mempool", "block", "tx", "address",
"rawtx", "status", "parameters", "agenda", "agendas", "charts",
"sidechains", "disapproved", "ticketpool", "visualblocks", "statistics",
"sidechains", "disapproved", "ticketpool", "visualblocks",
"windows", "timelisting", "addresstable", "proposals", "proposal",
"market", "insight_root", "attackcost", "treasury", "treasurytable", "verify_message"}

Expand Down Expand Up @@ -671,8 +671,6 @@ func (exp *explorerUI) addRoutes() {
exp.Mux.Get("/address/{x}", redirect("address"))

exp.Mux.Get("/decodetx", redirect("decodetx"))

exp.Mux.Get("/stats", redirect("statistics"))
}

// Simulate ticket purchase and re-investment over a full year for a given
Expand Down
89 changes: 1 addition & 88 deletions cmd/dcrdata/internal/explorer/explorerroutes.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2018-2022, The Decred developers
// Copyright (c) 2018-2024, The Decred developers
// Copyright (c) 2017, The dcrdata developers
// See LICENSE for details.

Expand Down Expand Up @@ -2458,93 +2458,6 @@ func (exp *explorerUI) HandleApiRequestsOnSync(w http.ResponseWriter, r *http.Re
io.WriteString(w, str)
}

// StatsPage is the page handler for the "/stats" path.
func (exp *explorerUI) StatsPage(w http.ResponseWriter, r *http.Request) {
// Get current PoW difficulty.
powDiff, err := exp.dataSource.CurrentDifficulty()
if err != nil {
log.Errorf("Failed to get Difficulty: %v", err)
}

// Subsidies
dcp0010Height := exp.dataSource.DCP0010ActivationHeight()
dcp0012Height := exp.dataSource.DCP0012ActivationHeight()
ultSubsidy := txhelpers.UltimateSubsidy(exp.ChainParams, dcp0010Height, dcp0012Height)
bestBlockHeight, err := exp.dataSource.GetHeight()
if err != nil {
log.Errorf("GetHeight failed: %v", err)
exp.StatusPage(w, defaultErrorCode, defaultErrorMessage, "",
ExpStatusError)
return
}
blockSubsidy := exp.dataSource.BlockSubsidy(bestBlockHeight,
exp.ChainParams.TicketsPerBlock)

// Safely retrieve the inventory pointer, which can be reset in StoreMPData.
inv := exp.MempoolInventory()

// Prevent modifications to the shared inventory struct (e.g. in the
// MempoolMonitor) while we retrieve the number of votes and tickets.
inv.RLock()
numVotes := inv.NumVotes
numTickets := inv.NumTickets
inv.RUnlock()

exp.pageData.RLock()
stats := types.StatsInfo{
TotalSupply: exp.pageData.HomeInfo.CoinSupply,
UltimateSupply: ultSubsidy,
TotalSupplyPercentage: float64(exp.pageData.HomeInfo.CoinSupply) /
float64(ultSubsidy) * 100,
ProjectFunds: exp.pageData.HomeInfo.DevFund,
ProjectAddress: exp.pageData.HomeInfo.DevAddress,
PoWDiff: exp.pageData.HomeInfo.Difficulty,
BlockReward: blockSubsidy.Total,
NextBlockReward: exp.pageData.HomeInfo.NBlockSubsidy.Total,
PoWReward: exp.pageData.HomeInfo.NBlockSubsidy.PoW,
PoSReward: exp.pageData.HomeInfo.NBlockSubsidy.PoS,
ProjectFundReward: exp.pageData.HomeInfo.NBlockSubsidy.Dev,
VotesInMempool: numVotes,
TicketsInMempool: numTickets,
TicketPrice: exp.pageData.HomeInfo.StakeDiff,
NextEstimatedTicketPrice: exp.pageData.HomeInfo.NextExpectedStakeDiff,
TicketPoolSize: exp.pageData.HomeInfo.PoolInfo.Size,
TicketPoolSizePerToTarget: float64(exp.pageData.HomeInfo.PoolInfo.Size) /
float64(exp.ChainParams.TicketPoolSize*exp.ChainParams.TicketsPerBlock) * 100,
TicketPoolValue: exp.pageData.HomeInfo.PoolInfo.Value,
TPVOfTotalSupplyPeecentage: exp.pageData.HomeInfo.PoolInfo.Percentage,
TicketsROI: exp.pageData.HomeInfo.TicketReward,
RewardPeriod: exp.pageData.HomeInfo.RewardPeriod,
ASR: exp.pageData.HomeInfo.ASR,
APR: exp.pageData.HomeInfo.ASR,
IdxBlockInWindow: exp.pageData.HomeInfo.IdxBlockInWindow,
WindowSize: exp.pageData.HomeInfo.Params.WindowSize,
BlockTime: exp.pageData.HomeInfo.Params.BlockTime,
IdxInRewardWindow: exp.pageData.HomeInfo.IdxInRewardWindow,
RewardWindowSize: exp.pageData.HomeInfo.Params.RewardWindowSize,
HashRate: powDiff * math.Pow(2, 32) /
exp.ChainParams.TargetTimePerBlock.Seconds() / math.Pow(10, 15),
}
exp.pageData.RUnlock()

str, err := exp.templates.exec("statistics", struct {
*CommonPageData
Stats types.StatsInfo
}{
CommonPageData: exp.commonData(r),
Stats: stats,
})

if err != nil {
log.Errorf("Template execute failure: %v", err)
exp.StatusPage(w, defaultErrorCode, defaultErrorMessage, "", ExpStatusError)
return
}
w.Header().Set("Content-Type", "text/html")
w.WriteHeader(http.StatusOK)
io.WriteString(w, str)
}

// MarketPage is the page handler for the "/market" path.
func (exp *explorerUI) MarketPage(w http.ResponseWriter, r *http.Request) {
str, err := exp.templates.exec("market", struct {
Expand Down
7 changes: 3 additions & 4 deletions cmd/dcrdata/main.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2018-2022, The Decred developers
// Copyright (c) 2018-2024, The Decred developers
// Copyright (c) 2017, Jonathan Chappelow
// See LICENSE for details.

Expand Down Expand Up @@ -779,10 +779,9 @@ func _main(ctx context.Context) error {
r.Get("/search", explore.Search)
r.Get("/charts", explore.Charts)
r.Get("/ticketpool", explore.Ticketpool)
r.Get("/stats", explore.StatsPage)
r.Get("/market", explore.MarketPage)
r.Get("/statistics", func(w http.ResponseWriter, r *http.Request) {
http.Redirect(w, r, "/stats", http.StatusPermanentRedirect)
r.Get("/stats", func(w http.ResponseWriter, r *http.Request) {
http.Redirect(w, r, "/", http.StatusPermanentRedirect)
})
// MenuFormParser will typically redirect, but going to the homepage as a
// fallback.
Expand Down
1 change: 0 additions & 1 deletion cmd/dcrdata/public/scss/application.scss
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
@import "./table";
@import "./keyboard_navigation";
@import "./connection";
@import "./stats_page";
@import "./animation";
@import "./voting";
@import "./transaction";
Expand Down
115 changes: 0 additions & 115 deletions cmd/dcrdata/public/scss/stats_page.scss

This file was deleted.

2 changes: 1 addition & 1 deletion cmd/dcrdata/views/extras.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
<link rel="preload" href="/images/connected.svg?x=65tv3" as="image" type="image/svg+xml" />
<link rel="preload" href="/images/disconnected.svg?x=65tv3" as="image" type="image/svg+xml" />

<link href="/dist/css/style.2ec149a327053ac3.css" rel="stylesheet">
<link href="/dist/css/style.5838f86cfc8bbb39.css" rel="stylesheet">

<script src="/js/vendor/turbolinks.min.js?v=65DCG"></script>
</head>
Expand Down
Loading

0 comments on commit 9526082

Please sign in to comment.