Skip to content

Commit

Permalink
Display the next expected ticket price and bounds (#617)
Browse files Browse the repository at this point in the history
This shows the expected ticket price for the next price window, along with the
min/max bounds, which narrow as the current windows progresses.
  • Loading branch information
hyhydra0 authored and chappjc committed Aug 28, 2018
1 parent 61a38fb commit ba0f9ee
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 42 deletions.
2 changes: 1 addition & 1 deletion blockdata/blockdata.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func (b *BlockData) ToBlockExplorerSummary() apitypes.BlockExplorerBasic {
FreshStake: b.Header.FreshStake,
StakeDiff: b.Header.SBits,
BlockExplorerExtraInfo: extra,
Time: b.Header.Time,
Time: b.Header.Time,
}
}

Expand Down
3 changes: 3 additions & 0 deletions explorer/explorer.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,9 @@ func (exp *explorerUI) Store(blockData *blockdata.BlockData, _ *wire.MsgBlock) e
// Update all ExtraInfo with latest data
exp.ExtraInfo.CoinSupply = blockData.ExtraInfo.CoinSupply
exp.ExtraInfo.StakeDiff = blockData.CurrentStakeDiff.CurrentStakeDifficulty
exp.ExtraInfo.NextExpectedStakeDiff = blockData.EstStakeDiff.Expected
exp.ExtraInfo.NextExpectedBoundsMin = blockData.EstStakeDiff.Min
exp.ExtraInfo.NextExpectedBoundsMax = blockData.EstStakeDiff.Max
exp.ExtraInfo.IdxBlockInWindow = blockData.IdxBlockInWindow
exp.ExtraInfo.IdxInRewardWindow = int(newBlockData.Height % exp.ChainParams.SubsidyReductionInterval)
exp.ExtraInfo.Difficulty = blockData.Header.Difficulty
Expand Down
29 changes: 16 additions & 13 deletions explorer/explorertypes.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,19 +298,22 @@ type AddressBalance struct {

// HomeInfo represents data used for the home page
type HomeInfo struct {
CoinSupply int64 `json:"coin_supply"`
StakeDiff float64 `json:"sdiff"`
IdxBlockInWindow int `json:"window_idx"`
IdxInRewardWindow int `json:"reward_idx"`
Difficulty float64 `json:"difficulty"`
DevFund int64 `json:"dev_fund"`
DevAddress string `json:"dev_address"`
TicketReward float64 `json:"reward"`
RewardPeriod string `json:"reward_period"`
ASR float64 `json:"ASR"`
NBlockSubsidy BlockSubsidy `json:"subsidy"`
Params ChainParams `json:"params"`
PoolInfo TicketPoolInfo `json:"pool_info"`
CoinSupply int64 `json:"coin_supply"`
StakeDiff float64 `json:"sdiff"`
NextExpectedStakeDiff float64 `json:"next_expected_sdiff"`
NextExpectedBoundsMin float64 `json:"next_expected_min"`
NextExpectedBoundsMax float64 `json:"next_expected_max"`
IdxBlockInWindow int `json:"window_idx"`
IdxInRewardWindow int `json:"reward_idx"`
Difficulty float64 `json:"difficulty"`
DevFund int64 `json:"dev_fund"`
DevAddress string `json:"dev_address"`
TicketReward float64 `json:"reward"`
RewardPeriod string `json:"reward_period"`
ASR float64 `json:"ASR"`
NBlockSubsidy BlockSubsidy `json:"subsidy"`
Params ChainParams `json:"params"`
PoolInfo TicketPoolInfo `json:"pool_info"`
}

// BlockSubsidy is an implementation of dcrjson.GetBlockSubsidyResult
Expand Down
5 changes: 3 additions & 2 deletions explorer/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,9 @@ func makeTemplateFuncMap(params *chaincfg.Params) template.FuncMap {
p := (float64(i) / float64(params.SubsidyReductionInterval)) * 100
return p
},
"float64AsDecimalParts": func(v float64, useCommas bool) []string {
clipped := fmt.Sprintf("%.8f", v)
"float64AsDecimalParts": func(v float64, numPlaces int, useCommas bool) []string {
format := "%." + strconv.Itoa(numPlaces) + "f"
clipped := fmt.Sprintf(format, v)
oldLength := len(clipped)
clipped = strings.TrimRight(clipped, "0")
trailingZeros := strings.Repeat("0", oldLength-len(clipped))
Expand Down
6 changes: 3 additions & 3 deletions views/address.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@
<td class="text-right">{{.MergedTxnCount}}</td>
{{else}}
{{if ne .ReceivedTotal 0.0}}
<td class="text-right">{{template "decimalParts" (float64AsDecimalParts .ReceivedTotal false)}}</td>
<td class="text-right">{{template "decimalParts" (float64AsDecimalParts .ReceivedTotal 8 false)}}</td>
{{else}}
{{if eq .SentTotal 0.0}}
<td class="text-right">sstxcommitment</td>
Expand All @@ -245,9 +245,9 @@
{{if ne .SentTotal 0.0}}
{{if lt 0.0 .SentTotal}}
{{if eq $txType "merged_debit"}}
<td class="text-right"> {{template "decimalParts" (float64AsDecimalParts .SentTotal false)}}</td>
<td class="text-right"> {{template "decimalParts" (float64AsDecimalParts .SentTotal 8 false)}}</td>
{{else}}
<td>{{template "decimalParts" (float64AsDecimalParts .SentTotal false)}}</td>
<td>{{template "decimalParts" (float64AsDecimalParts .SentTotal 8 false)}}</td>
{{end}}
{{else}}
<td class="text-right">N/A</td>
Expand Down
16 changes: 8 additions & 8 deletions views/block.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<table>
<tr class="h2rem">
<td class="pr-2 lh1rem vam text-right xs-w117 w120">TOTAL SENT</td>
<td class="fs28 mono fs16-decimal d-flex align-items-center">{{template "decimalParts" (float64AsDecimalParts .TotalSent false)}}<span class="pl-1 unit">DCR</span></td>
<td class="fs28 mono fs16-decimal d-flex align-items-center">{{template "decimalParts" (float64AsDecimalParts .TotalSent 8 false)}}<span class="pl-1 unit">DCR</span></td>
</tr>
</table>
</div>
Expand Down Expand Up @@ -129,7 +129,7 @@
<tr>
<td class="text-right pr-2 lh1rem p03rem0 xs-w117">TICKET PRICE</td>
<td class="lh1rem">
{{template "decimalParts" (float64AsDecimalParts .SBits false)}}
{{template "decimalParts" (float64AsDecimalParts .SBits 8 false)}}
</td>
</tr>
<tr>
Expand All @@ -139,7 +139,7 @@
<tr>
<td class="text-right pr-2 lh1rem nowrap p03rem0 xs-w91">POW DIFFICULTY</td>
<td class="lh1rem">
{{template "decimalParts" (float64AsDecimalParts .Difficulty true)}}
{{template "decimalParts" (float64AsDecimalParts .Difficulty 8 true)}}
</td>
</tr>
</table>
Expand All @@ -165,7 +165,7 @@
<a class="hash" href="/tx/{{.TxID}}">{{.TxID}}</a>
</span>
</td>
<td class="mono fs15 text-right">{{template "decimalParts" (float64AsDecimalParts .Total false)}}</td>
<td class="mono fs15 text-right">{{template "decimalParts" (float64AsDecimalParts .Total 8 false)}}</td>
<td class="mono fs15">{{.FormattedSize}}</td>
</tr>
</tbody>
Expand Down Expand Up @@ -208,7 +208,7 @@
</td>
<td class="mono fs15">{{.VoteInfo.Version}}</td>
<td>{{if .VoteInfo.Validation.Validity}}Valid{{else}}Invalid{{end}}</td>
<td class="mono fs15 text-right">{{template "decimalParts" (float64AsDecimalParts .Total false)}}</td>
<td class="mono fs15 text-right">{{template "decimalParts" (float64AsDecimalParts .Total 8 false)}}</td>
<td class="mono fs15 text-right">{{.FormattedSize}}</td>
</tr>
{{end}}
Expand Down Expand Up @@ -271,7 +271,7 @@
<a class="hash" href="/tx/{{.TxID}}">{{.TxID}}</a>
</span>
</td>
<td class="text-right dcr mono fs15">{{template "decimalParts" (float64AsDecimalParts .Total false)}}</td>
<td class="text-right dcr mono fs15">{{template "decimalParts" (float64AsDecimalParts .Total 8 false)}}</td>
<td class="mono fs15 text-right">{{.Fee}}</td>
<td class="mono fs15">{{.FormattedSize}}</td>
</tr>
Expand Down Expand Up @@ -302,7 +302,7 @@
<a class="hash" href="/tx/{{.TxID}}">{{.TxID}}</a>
</span>
</td>
<td class="mono fs15 text-right">{{template "decimalParts" (float64AsDecimalParts .Total false)}}</td>
<td class="mono fs15 text-right">{{template "decimalParts" (float64AsDecimalParts .Total 8 false)}}</td>
<td class="mono fs15 text-right">{{.Fee}}</td>
<td class="mono fs15">{{.FormattedSize}}</td>
</tr>
Expand Down Expand Up @@ -340,7 +340,7 @@
<a class="hash" href="/tx/{{.TxID}}">{{.TxID}}</a>
</span>
</td>
<td class="mono fs15 text-right">{{template "decimalParts" (float64AsDecimalParts .Total false)}}</td>
<td class="mono fs15 text-right">{{template "decimalParts" (float64AsDecimalParts .Total 8 false)}}</td>
<td class="mono fs15 text-right">{{.Fee}}</td>
<td class="mono fs15">{{.FormattedSize}}</td>
</tr>
Expand Down
23 changes: 16 additions & 7 deletions views/home.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,19 @@
<td class="text-right pr-2 lh1rem pt-1 pb-1">VOTES IN MEMPOOL</td>
<td><span data-target="homepageMempool.numVote" class="mono fs24">{{$.Mempool.NumVotes}}</span></td>
</tr>
<tr>
<td class="text-right pr-2 lh1rem pt-1 pb-1 vam">TICKET PRICE</td>
<td class="mono vam fs24 fs14-decimal font-weight-bold">
<span id="blocksdiff">{{template "decimalParts" (float64AsDecimalParts .StakeDiff 8 false)}}</span><span class="pl-1 unit">DCR</span>
</td>
</tr>
<tr>
<td class="text-right pr-2 lh1rem pt-1 pb-1 vam">NEXT TICKET PRICE ESTIMATE</td>
<td class="mono vam fs14-decimal">
<span class="fs24 font-weight-bold">{{template "decimalParts" (float64AsDecimalParts .NextExpectedStakeDiff 8 false)}}<span class="pl-1 unit font-weight-bold">DCR</span></span>,
<span class="fs18">bounds: [{{template "decimalParts" (float64AsDecimalParts .NextExpectedBoundsMin 2 false)}}, {{template "decimalParts" (float64AsDecimalParts .NextExpectedBoundsMax 2 false)}}]</span>
</td>
</tr>
<tr>
<td class="text-right pr-2 lh1rem pt-1 pb-1">TICKET WINDOW PROGRESS</td>
<td>
Expand All @@ -53,10 +66,6 @@
</div>
</td>
</tr>
<tr>
<td class="text-right pr-2 lh1rem pt-1 pb-1 vam">TICKET PRICE</td>
<td class="mono vam fs24 fs14-decimal font-weight-bold"><span id="blocksdiff">{{template "decimalParts" (float64AsDecimalParts .StakeDiff false)}}</span><span class="pl-1 unit">DCR</span></td>
</tr>
<tr>
<td class="text-right pr-2 lh1rem pt-1 pb-1 vam">TICKET REWARD</td>
<td class="mono vam fs24 fs14-decimal">+<span id="ticket_reward">{{printf "%.2f" .TicketReward}}</span>% <span class="mono lh1rem fs18">per ~{{.RewardPeriod}}</span> <span class="mono lh1rem fs18" title="Annual Stake Rewards">({{printf "%.2f" .ASR}}% / year)</span></td>
Expand All @@ -70,7 +79,7 @@
<tr>
<td class="text-right pr-2 lh1rem pt-1 pb-1">TICKET POOL VALUE</td>
<td>
<div class="mono lh1rem fs14-decimal fs18"><span id="pool_value">{{template "decimalParts" (float64AsDecimalParts .PoolInfo.Value true)}}</span><span class="unit"> DCR<br>(<span id="pool_size_percentage">{{printf "%.2f" .PoolInfo.Percentage}}</span>% of total supply)</span>
<div class="mono lh1rem fs14-decimal fs18"><span id="pool_value">{{template "decimalParts" (float64AsDecimalParts .PoolInfo.Value 8 true)}}</span><span class="unit"> DCR<br>(<span id="pool_size_percentage">{{printf "%.2f" .PoolInfo.Percentage}}</span>% of total supply)</span>
</td>
</tr>
<tr>
Expand Down Expand Up @@ -125,7 +134,7 @@
<td class="text-right pr-2 lh1rem pt-1 pb-1">PROOF OF WORK DIFFICULTY</td>
<td class="mono lh1rem p03rem0">
<span id="difficulty" class="fs24 fs14-decimal">
{{template "decimalParts" (float64AsDecimalParts .Difficulty true)}}
{{template "decimalParts" (float64AsDecimalParts .Difficulty 8 true)}}
</span>
</td>
</tr>
Expand Down Expand Up @@ -162,7 +171,7 @@
<div class="d-flex flex-table-row">
<a class="hash truncate-hash keyboard-target" style="flex: 1 1 auto" href="/tx/{{.Hash}}" title="{{.Hash}}">{{.Hash}}</a>
<span style="flex: 0 0 65px" class="mono text-right ml-1">{{.Type}}</span>
<span style="flex: 0 0 105px" class="mono text-right ml-1">{{template "decimalParts" (float64AsDecimalParts .TotalOut false)}}</span>
<span style="flex: 0 0 105px" class="mono text-right ml-1">{{template "decimalParts" (float64AsDecimalParts .TotalOut 8 false)}}</span>
<span style="flex: 0 0 50px" class="mono text-right ml-1">{{.Size}} B</span>
<span style="flex: 0 0 62px" class="mono text-right ml-1" data-target="main.age" data-age="{{.Time}}"></span>
</div>
Expand Down
10 changes: 5 additions & 5 deletions views/mempool.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<table>
<tr class="h2rem">
<td class="pr-2 lh1rem vam text-right xs-w117 w120">TOTAL SENT</td>
<td class="fs28 mono fs16-decimal d-flex align-items-center" data-target="mempool.totalOut" >{{template "decimalParts" (float64AsDecimalParts .TotalOut false)}}<span class="pl-1 unit">DCR</span></td>
<td class="fs28 mono fs16-decimal d-flex align-items-center" data-target="mempool.totalOut" >{{template "decimalParts" (float64AsDecimalParts .TotalOut 8 false)}}<span class="pl-1 unit">DCR</span></td>
</tr>
</table>
</div>
Expand Down Expand Up @@ -84,7 +84,7 @@
<td class="mono fs15 last_block">{{if .VoteInfo.ForLastBlock}}True{{else}}False{{end}}</td>
<td class="mono fs15"><a href="/tx/{{.VoteInfo.TicketSpent}}">{{.VoteInfo.MempoolTicketIndex}}</a></td>
<td class="mono fs15">{{.VoteInfo.Version}}</td>
<td class="mono fs15 text-right">{{template "decimalParts" (float64AsDecimalParts .TotalOut false)}}</td>
<td class="mono fs15 text-right">{{template "decimalParts" (float64AsDecimalParts .TotalOut 8 false)}}</td>
<td class="mono fs15 text-right">{{.Size}} B</td>
<td class="mono fs15 text-right" data-target="main.age" data-age="{{.Time}}"></td>
</tr>
Expand Down Expand Up @@ -117,7 +117,7 @@
<a class="hash" href="/tx/{{.Hash}}">{{.Hash}}</a>
</span>
</td>
<td class="mono fs15 text-right">{{template "decimalParts" (float64AsDecimalParts .TotalOut false)}}</td>
<td class="mono fs15 text-right">{{template "decimalParts" (float64AsDecimalParts .TotalOut 8 false)}}</td>
<td class="mono fs15 text-right">{{.Size}} B</td>
<td class="mono fs15 text-right" data-target="main.age" data-age="{{.Time}}"></td>
</tr>
Expand Down Expand Up @@ -151,7 +151,7 @@
<a class="hash" href="/tx/{{.Hash}}">{{.Hash}}</a>
</span>
</td>
<td class="mono fs15 text-right">{{template "decimalParts" (float64AsDecimalParts .TotalOut false)}}</td>
<td class="mono fs15 text-right">{{template "decimalParts" (float64AsDecimalParts .TotalOut 8 false)}}</td>
<td class="mono fs15 text-right">{{.Size}} B</td>
<td class="mono fs15 text-right" data-target="main.age" data-age="{{.Time}}"></td>
</tr>
Expand Down Expand Up @@ -185,7 +185,7 @@
<a class="hash" href="/tx/{{.Hash}}">{{.Hash}}</a>
</span>
</td>
<td class="mono fs15 text-right">{{template "decimalParts" (float64AsDecimalParts .TotalOut false)}}</td>
<td class="mono fs15 text-right">{{template "decimalParts" (float64AsDecimalParts .TotalOut 8 false)}}</td>
<td class="mono fs15 text-right">{{.Size}} B</td>
<td class="mono fs15 text-right" data-target="main.age" data-age="{{.Time}}"></td>
</tr>
Expand Down
6 changes: 3 additions & 3 deletions views/tx.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@
<table>
<tr class="h2rem">
<td class="pr-2 lh1rem vam text-right xs-w91">TOTAL SENT</td>
<td class="fs28 mono nowrap fs16-decimal d-flex align-items-center">{{template "decimalParts" (float64AsDecimalParts .Total false)}}<span class="pl-1 unit">DCR</span></td>
<td class="fs28 mono nowrap fs16-decimal d-flex align-items-center">{{template "decimalParts" (float64AsDecimalParts .Total 8 false)}}<span class="pl-1 unit">DCR</span></td>
</tr>
<tr>
<td class="text-right pr-2">TIME</td>
Expand Down Expand Up @@ -280,7 +280,7 @@
<a href="/block/{{.BlockHeight}}">{{.BlockHeight}}</a>
{{end}}
</td>
<td class="mono fs13 text-right">{{if lt .AmountIn 0.0}} N/A {{else}} {{template "decimalParts" (float64AsDecimalParts .AmountIn false)}} {{end}}</td>
<td class="mono fs13 text-right">{{if lt .AmountIn 0.0}} N/A {{else}} {{template "decimalParts" (float64AsDecimalParts .AmountIn 8 false)}} {{end}}</td>
</tr>
{{end}}
{{if and (eq .Type "Coinbase") (gt .BlockMiningFee 0)}}
Expand Down Expand Up @@ -339,7 +339,7 @@
{{end}}
</td>
<td class="text-right mono fs13">
{{template "decimalParts" (float64AsDecimalParts .Amount false)}}
{{template "decimalParts" (float64AsDecimalParts .Amount 8 false)}}
</td>
</tr>
{{end}}
Expand Down

0 comments on commit ba0f9ee

Please sign in to comment.