Skip to content

Commit

Permalink
more docs
Browse files Browse the repository at this point in the history
  • Loading branch information
buck54321 committed May 10, 2021
1 parent 98ce03f commit eef4010
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 20 deletions.
15 changes: 12 additions & 3 deletions cmd/dcrdata/explorer/explorerroutes.go
Expand Up @@ -1632,6 +1632,7 @@ func (exp *explorerUI) AddressTable(w http.ResponseWriter, r *http.Request) {
}
}

// TreasuryTable is the handler for the "/treasurytable" path.
func (exp *explorerUI) TreasuryTable(w http.ResponseWriter, r *http.Request) {
// Grab the URL query parameters
txType, limitN, offset, err := parseTreasuryParams(r)
Expand Down Expand Up @@ -1694,7 +1695,8 @@ func (exp *explorerUI) TreasuryTable(w http.ResponseWriter, r *http.Request) {
}
}

// parseAddressParams is used by both /address and /addresstable.
// parseAddressParams parses tx filter parameters. Used by both /address and
// /addresstable.
func parseAddressParams(r *http.Request) (address string, txnType dbtypes.AddrTxnViewType, limitN, offsetAddrOuts int64, err error) {
// Get the address URL parameter, which should be set in the request context
// by the addressPathCtx middleware.
Expand All @@ -1713,6 +1715,8 @@ func parseAddressParams(r *http.Request) (address string, txnType dbtypes.AddrTx
return
}

// treasuryTypeCount returns the tx count for the type treasury tx type. The
// special value txType = -1 specifies all types combined.
func treasuryTypeCount(treasuryBalance *dbtypes.TreasuryBalance, txType stake.TxType) int64 {
typedCount := treasuryBalance.TxCount
switch txType {
Expand All @@ -1726,6 +1730,9 @@ func treasuryTypeCount(treasuryBalance *dbtypes.TreasuryBalance, txType stake.Tx
return typedCount
}

// parseTreasuryTransactionType parses a treasury transaction type from a
// string. If the provided string is not recognized as a treasury type, the
// special value -1, representing "all", will be returned.
func parseTreasuryTransactionType(txnTypeStr string) (txType stake.TxType) {
switch strings.ToLower(txnTypeStr) {
case "tspend":
Expand All @@ -1738,12 +1745,16 @@ func parseTreasuryTransactionType(txnTypeStr string) (txType stake.TxType) {
return stake.TxType(-1)
}

// parseTreasuryParams parses the tx filters for the treasury page. Used by both
// TreasuryPage and TreasuryTable.
func parseTreasuryParams(r *http.Request) (txType stake.TxType, limitN, offsetAddrOuts int64, err error) {
tType, limitN, offsetAddrOuts, err := parsePaginationParams(r)
txType = parseTreasuryTransactionType(tType)
return
}

// parsePaginationParams parses the pagination parameters from the query. The
// txnType string is returned as-is. The caller must decipher the string.
func parsePaginationParams(r *http.Request) (txnType string, limitN, offset int64, err error) {
// Number of outputs for the address to query the database for. The URL
// query parameter "n" is used to specify the limit (e.g. "?n=20").
Expand Down Expand Up @@ -1784,8 +1795,6 @@ func parsePaginationParams(r *http.Request) (txnType string, limitN, offset int6
txnType = "all"
}

// log.Debugf("Showing transaction types: %s (%d)", txntype, txnType)

return
}

Expand Down
1 change: 0 additions & 1 deletion cmd/dcrdata/views/address.tmpl
Expand Up @@ -111,7 +111,6 @@
<span class="col-24"><a href="{{$.Links.DownloadLink}}" title="Decred downloads" target="_blank" rel="noopener noreferrer">Get Decrediton</a>, the official desktop wallet.</span>
</div>
{{end}}

<div class="pb-1 fs14">
{{if .IsDummyAddress}}
*This a is dummy address, typically used for unspendable ticket change outputs.
Expand Down
18 changes: 2 additions & 16 deletions db/dcrpg/pgblockchain.go
Expand Up @@ -1805,6 +1805,7 @@ func (pgb *ChainDB) GetTicketInfo(txid string) (*apitypes.TicketInfo, error) {
}, nil
}

// TreasuryBalance calculates the *dbtypes.TreasuryBalance.
func (pgb *ChainDB) TreasuryBalance() (_ *dbtypes.TreasuryBalance, err error) {
var addCount, added, immatureCount, immature, spendCount, spent, genCount, gen int64

Expand Down Expand Up @@ -1854,6 +1855,7 @@ func (pgb *ChainDB) TreasuryBalance() (_ *dbtypes.TreasuryBalance, err error) {
}, nil
}

// TreasuryTxns fetches filtered treasury transactions.
func (pgb *ChainDB) TreasuryTxns(n, offset int64, txType stake.TxType) ([]*dbtypes.TreasuryTx, error) {
var rows *sql.Rows
var err error
Expand Down Expand Up @@ -1886,22 +1888,6 @@ func (pgb *ChainDB) TreasuryTxns(n, offset int64, txType stake.TxType) ([]*dbtyp
return txns, nil
}

func (pgb *ChainDB) TreasuryHistory(address string, n, offset int64,
txType stake.TxType) ([]*dbtypes.TreasuryTx, *dbtypes.TreasuryBalance, error) {

txns, err := pgb.TreasuryTxns(n, offset, txType)
if err != nil {
return nil, nil, err
}

bal, err := pgb.TreasuryBalance()
if err != nil {
return nil, nil, err
}

return txns, bal, nil
}

func (pgb *ChainDB) updateProjectFundCache() error {
_, _, err := pgb.AddressHistoryAll(pgb.devAddress, 1, 0)
return err
Expand Down

0 comments on commit eef4010

Please sign in to comment.