Skip to content

Commit

Permalink
docs and touchups
Browse files Browse the repository at this point in the history
  • Loading branch information
buck54321 committed Aug 19, 2023
1 parent bc4ca4d commit 32fe289
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 27 deletions.
38 changes: 25 additions & 13 deletions client/asset/dcr/dcr.go
Original file line number Diff line number Diff line change
Expand Up @@ -632,15 +632,6 @@ type ExchangeWallet struct {
connected atomic.Bool

subsidyCache *blockchain.SubsidyCache

ticketHistory struct {
sync.RWMutex
lastScannedBlock uint32
nTickets uint32
nVotes uint32
costSum uint64
voteRewards uint64
}
}

func (dcr *ExchangeWallet) config() *exchangeWalletConfig {
Expand Down Expand Up @@ -5193,6 +5184,8 @@ func (dcr *ExchangeWallet) isNative() bool {
return dcr.walletType == walletTypeSPV
}

// currentAgendas gets the most recent agendas from the chain params. The caller
// must populate the CurrentChoice field of the agendas.
func currentAgendas(chainParams *chaincfg.Params) (agendas []*asset.TBAgenda) {
var bestID uint32
for deploymentID := range chainParams.Deployments {
Expand Down Expand Up @@ -5238,10 +5231,6 @@ func (dcr *ExchangeWallet) StakeStatus() (*asset.TicketStakingStatus, error) {
expectedBlocksToVote := int64(dcr.chainParams.TicketPoolSize)
voteHeightExpectationValue := dcr.cachedBestBlock().height + expectedBlocksToVote
voteSubsidy := dcr.subsidyCache.CalcStakeVoteSubsidyV3(voteHeightExpectationValue, blockchain.SSVDCP0012)
// expectedTimeToVote := time.Duration(expectedBlocksToVote) * dcr.chainParams.TargetTimePerBlock
// nCompound := float64((time.Hour * 24 * 365) / expectedTimeToVote)
// subsidyRate := float64(voteSubsidy) / float64(ticketPrice)
// apy := math.Pow(1+subsidyRate, nCompound) - 1
isRPC := !dcr.isNative()
var vspURL string
if !isRPC {
Expand Down Expand Up @@ -5283,6 +5272,22 @@ func (dcr *ExchangeWallet) StakeStatus() (*asset.TicketStakingStatus, error) {
}, nil
}

// tickets gets tickets from the wallet and changes the status of "unspent"
// tickets that haven't reached expiration "live".
// DRAFT NOTE: From dcrwallet:
//
// TicketStatusUnspent is a matured ticket that has not been spent. It
// is only used under SPV mode where it is unknown if a ticket is live,
// was missed, or expired.
//
// But if the ticket has not reached a certain number of confirmations, we
// can say for sure it's not expired. With auto-revocations, "missed" or
// "expired" tickets are actually "revoked", I think.
// The only thing I can't figure out is how SPV wallets set the spender in the
// case of an auto-revocation. It might be happening here
// https://github.com/decred/dcrwallet/blob/a87fa843495ec57c1d3b478c2ceb3876c3749af5/wallet/chainntfns.go#L770-L775
// If we're seeing auto-revocations, we're find to make the changes in this
// method.
func (dcr *ExchangeWallet) tickets(ctx context.Context) ([]*asset.Ticket, error) {
tickets, err := dcr.wallet.Tickets(ctx)
if err != nil {
Expand Down Expand Up @@ -5359,6 +5364,8 @@ func (dcr *ExchangeWallet) PurchaseTickets(n int, feeSuggestion uint64) ([]*asse
if !dcr.connected.Load() {
return nil, errors.New("not connected, login first")
}
// I think we need to set this, otherwise we probably end up with default
// of DefaultRelayFeePerKb = 1e4 => 10 atoms/byte.
feePerKB := dcrutil.Amount(dcr.feeRateWithFallback(feeSuggestion) * 1000)
if err := dcr.wallet.SetTxFee(dcr.ctx, feePerKB); err != nil {
return nil, fmt.Errorf("error setting wallet tx fee: %w", err)
Expand Down Expand Up @@ -5465,6 +5472,11 @@ func (dcr *ExchangeWallet) ListVSPs() ([]*asset.VotingServiceProvider, error) {
return vspds, nil
}

// TicketPage fetches a page of tickets within a range of block numbers with a
// target page size and optional offset. scanStart it the block in which to
// start the scan. The scan progresses in reverse block number order, starting
// at scanStart and going to progressively lower blocks. scanStart can be set to
// -1 to indicate the current chain tip.
func (dcr *ExchangeWallet) TicketPage(scanStart int32, n, skipN int) ([]*asset.Ticket, error) {
if !dcr.connected.Load() {
return nil, errors.New("not connected, login first")
Expand Down
2 changes: 1 addition & 1 deletion client/asset/dcr/rpcwallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -873,7 +873,7 @@ func (w *rpcWallet) AddressPrivKey(ctx context.Context, address stdaddr.Address)
return &priv, nil
}

// StakeDiff returns the current stake difficulty.
// StakeInfo returns the current gestakeinfo results.
func (w *rpcWallet) StakeInfo(ctx context.Context) (*wallet.StakeInfoData, error) {
res, err := w.rpcClient.GetStakeInfo(ctx)
if err != nil {
Expand Down
3 changes: 2 additions & 1 deletion client/asset/dcr/spv.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ func createSPVWallet(pw, seed []byte, dataDir string, extIdx, intIdx uint32, cha
return nil
}

// If we're running on simnet, add some tspends and treasury keys.
func (w *spvWallet) initializeSimnetTspends(ctx context.Context) {
if w.chainParams.Net != wire.SimNet {
return
Expand Down Expand Up @@ -873,7 +874,7 @@ func (w *spvWallet) AddressPrivKey(ctx context.Context, addr stdaddr.Address) (*
return privKey, err
}

// StakeDiff returns the current stake difficulty.
// StakeInfo returns the current stake info.
func (w *spvWallet) StakeInfo(ctx context.Context) (*wallet.StakeInfoData, error) {
return w.dcrWallet.StakeInfo(ctx)
}
Expand Down
7 changes: 6 additions & 1 deletion client/asset/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -914,25 +914,28 @@ type Ticket struct {
Spender string `json:"spender"`
}

// TBChoice is a possible agenda choice for a TicketBuyer.
type TBChoice struct {
ID string `json:"id"`
Description string `json:"description"`
}

// TBAgenda is an agenda that the TicketBuyer can vote on.
type TBAgenda struct {
ID string `json:"id"`
Description string `json:"description"`
CurrentChoice string `json:"currentChoice"`
Choices []*TBChoice `json:"choices"`
}

// TBTreasurySpend represents a treasury spend that the TicketBuyer can vote on.
type TBTreasurySpend struct {
Hash string `json:"hash"`
Value uint64 `json:"value"`
CurrentPolicy string `json:"currentPolicy"`
}

// Stances are vote choices.
// Stances are current policy preferences for the TicketBuyer.
type Stances struct {
Agendas []*TBAgenda `json:"agendas"`
TreasurySpends []*TBTreasurySpend `json:"tspends"`
Expand All @@ -956,6 +959,8 @@ type VotingServiceProvider struct {
NetShare float32 `json:"netShare"`
}

// TicketStats sums up some statistics for historical staking data for a
// TicketBuyer.
type TicketStats struct {
TotalRewards uint64 `json:"totalRewards"`
TicketCount uint32 `json:"ticketCount"`
Expand Down
5 changes: 5 additions & 0 deletions client/core/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -10602,6 +10602,11 @@ func (c *Core) ListVSPs(assetID uint32) ([]*asset.VotingServiceProvider, error)
return tb.ListVSPs()
}

// TicketPage fetches a page of TicketBuyer tickets within a range of block
// numbers with a target page size and optional offset. scanStart it the block
// in which to start the scan. The scan progresses in reverse block number
// order, starting at scanStart and going to progressively lower blocks.
// scanStart can be set to -1 to indicate the current chain tip.
func (c *Core) TicketPage(assetID uint32, scanStart int32, n, skipN int) ([]*asset.Ticket, error) {
_, tb, err := c.stakingWallet(assetID)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion client/webserver/site/src/html/bodybuilder.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
{{end}}

{{define "bottom"}}
<script src="/js/entry.js?v=0c4cd158|05e1f5f4"></script>
<script src="/js/entry.js?v=a325bf70|dc83cdc7"></script>
</body>
</html>
{{end}}
20 changes: 10 additions & 10 deletions client/webserver/site/src/js/wallets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -891,16 +891,16 @@ export default class WalletsPage extends BasePage {
return
}
Doc.show(page.stakingSummary, page.ticketPriceBox)
const status = res.status as TicketStakingStatus
this.stakeStatus = status
page.ticketPrice.textContent = Doc.formatFourSigFigs(status.ticketPrice / ui.conventional.conversionFactor)
page.votingSubsidy.textContent = Doc.formatFourSigFigs(status.votingSubsidy / ui.conventional.conversionFactor)
page.stakingAgendaCount.textContent = String(status.stances.agendas.length)
page.stakingTspendCount.textContent = String(status.stances.tspends.length)
page.purchaserCurrentPrice.textContent = Doc.formatFourSigFigs(status.ticketPrice / ui.conventional.conversionFactor)
const stakeStatus = res.status as TicketStakingStatus
this.stakeStatus = stakeStatus
page.ticketPrice.textContent = Doc.formatFourSigFigs(stakeStatus.ticketPrice / ui.conventional.conversionFactor)
page.votingSubsidy.textContent = Doc.formatFourSigFigs(stakeStatus.votingSubsidy / ui.conventional.conversionFactor)
page.stakingAgendaCount.textContent = String(stakeStatus.stances.agendas.length)
page.stakingTspendCount.textContent = String(stakeStatus.stances.tspends.length)
page.purchaserCurrentPrice.textContent = Doc.formatFourSigFigs(stakeStatus.ticketPrice / ui.conventional.conversionFactor)
page.purchaserBal.textContent = Doc.formatCoinValue(wallet.balance.available, ui)
this.updateTicketStats(status.stats, ui)
this.setVSPViz(status.vsp)
this.updateTicketStats(stakeStatus.stats, ui)
this.setVSPViz(stakeStatus.vsp)
}

setVSPViz (vsp: string) {
Expand Down Expand Up @@ -956,7 +956,7 @@ export default class WalletsPage extends BasePage {

showPurchaseTicketsDialog () {
const page = this.page
page.purchaserInput.value = '1'
page.purchaserInput.value = ''
page.purchaserAppPW.value = ''
Doc.hide(page.purchaserErr)
Doc.setVis(!State.passwordIsCached(), page.purchaserAppPWBox)
Expand Down

0 comments on commit 32fe289

Please sign in to comment.