Set and display ticket purchase height (#250)

* Ensure purchase height set for confirmed tickets.

* Show purchase height in admin screen.

Only show purchase height when the ticket is confirmed, because if a ticket is not confirmed, its purchase height is not yet known.
This commit is contained in:
Jamie Holdstock 2021-05-15 03:19:01 +01:00 committed by GitHub
parent 08fafdaf31
commit b050fc3100
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 34 additions and 9 deletions

View File

@ -1,16 +1,25 @@
package webapi
import "time"
import (
"fmt"
"time"
)
func addressURL(blockExplorerURL string) func(string) string {
return func(addr string) string {
return blockExplorerURL + "/address/" + addr
return fmt.Sprintf("%s/address/%s", blockExplorerURL, addr)
}
}
func txURL(blockExplorerURL string) func(string) string {
return func(txID string) string {
return blockExplorerURL + "/tx/" + txID
return fmt.Sprintf("%s/tx/%s", blockExplorerURL, txID)
}
}
func blockURL(blockExplorerURL string) func(int64) string {
return func(height int64) string {
return fmt.Sprintf("%s/block/%d", blockExplorerURL, height)
}
}

View File

@ -176,10 +176,18 @@ func feeAddress(c *gin.Context) {
now := time.Now()
expire := now.Add(feeAddressExpiration).Unix()
confirmed := rawTicket.Confirmations >= requiredConfs
// Only set purchase height if the ticket already has 6 confs, otherwise its
// purchase height may change due to reorgs.
confirmed := false
purchaseHeight := int64(0)
if rawTicket.Confirmations >= requiredConfs {
confirmed = true
purchaseHeight = rawTicket.BlockHeight
}
dbTicket := database.Ticket{
Hash: ticketHash,
PurchaseHeight: purchaseHeight,
CommitmentAddress: commitmentAddress,
FeeAddressIndex: newAddressIdx,
FeeAddress: newAddress,

View File

@ -214,7 +214,7 @@ findAddress:
// At this point we are satisfied that the request is valid and the fee tx
// pays sufficient fees to the expected address. Proceed to update the
// database, and if the ticket is confirmed broadcast the transaction.
// database, and if the ticket is confirmed broadcast the fee transaction.
ticket.VotingWIF = votingWIF.String()
ticket.FeeTxHex = request.FeeTx

View File

@ -103,6 +103,17 @@
</a>
</td>
</tr>
<tr>
<th>Status</th>
{{ if .Ticket.Confirmed }}
<td>
Confirmed (purchase height:
<a href="{{ blockURL .Ticket.PurchaseHeight }}">{{ .Ticket.PurchaseHeight }}</a>)
</td>
{{ else }}
<td>Not confirmed</td>
{{ end }}
</tr>
<tr>
<th>Commitment Address</th>
<td>{{ .Ticket.CommitmentAddress }}</td>
@ -127,10 +138,6 @@
<th>Fee Expiration</th>
<td>{{ .Ticket.FeeExpiration }} ({{ dateTime .Ticket.FeeExpiration }}) </td>
</tr>
<tr>
<th>Confirmed</th>
<td>{{ .Ticket.Confirmed }}</td>
</tr>
<tr>
<th>Current Vote Choices</th>
<td>

View File

@ -179,6 +179,7 @@ func router(debugMode bool, cookieSecret []byte, dcrd rpc.DcrdConnect, wallets r
router.SetFuncMap(template.FuncMap{
"txURL": txURL(cfg.BlockExplorerURL),
"addressURL": addressURL(cfg.BlockExplorerURL),
"blockURL": blockURL(cfg.BlockExplorerURL),
"dateTime": dateTime,
})