Skip to content

Commit

Permalink
Call the more reliable GetStakeDifficulty for ticket prices (#232)
Browse files Browse the repository at this point in the history
Tickets could sometimes be purchased at the wrong price if the
wallet was not yet synced to the best block. Instead, fetch the next
price from the daemon and use that instead.
  • Loading branch information
cjepson authored and alexlyp committed May 10, 2016
1 parent 6b2fbf8 commit 08936c5
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions wallet/createtx.go
Original file line number Diff line number Diff line change
Expand Up @@ -1120,10 +1120,14 @@ func (w *Wallet) purchaseTicket(req purchaseTicketRequest) (interface{},
// address this better and prevent address burning.
account := req.account

// Get the current ticket price.
ticketPrice := dcrutil.Amount(w.GetStakeDifficulty().StakeDifficulty)
if ticketPrice == -1 {
return nil, ErrTicketPriceNotSet
// Get the current ticket price from the daemon.
ticketPricesF64, err := w.ChainClient().GetStakeDifficulty()
if err != nil {
return nil, err
}
ticketPrice, err := dcrutil.NewAmount(ticketPricesF64.NextStakeDifficulty)
if err != nil {
return nil, err
}

// Ensure the ticket price does not exceed the spend limit if set.
Expand Down

0 comments on commit 08936c5

Please sign in to comment.