Skip to content

Commit db4ba8e

Browse files
chore: handle edge case in shared parsePaginationParams function
parsePaginationParams is used for both address and treasury page. Both pages have different values as defaults. This commit ensures the correct default is used for each caller. Signed-off-by: Philemon Ukane <ukanephilemon@gmail.com>
1 parent 10b183d commit db4ba8e

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

cmd/dcrdata/internal/explorer/explorerroutes.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1758,7 +1758,7 @@ func parseAddressParams(r *http.Request) (address string, txnType dbtypes.AddrTx
17581758
return
17591759
}
17601760

1761-
tType, limitN, offsetAddrOuts, err := parsePaginationParams(r)
1761+
tType, limitN, offsetAddrOuts, err := parsePaginationParams(r, true)
17621762
txnType = dbtypes.AddrTxnViewTypeFromStr(tType)
17631763
if txnType == dbtypes.AddrTxnUnknown {
17641764
err = fmt.Errorf("unknown txntype query value")
@@ -1799,14 +1799,14 @@ func parseTreasuryTransactionType(txnTypeStr string) (txType stake.TxType) {
17991799
// parseTreasuryParams parses the tx filters for the treasury page. Used by both
18001800
// TreasuryPage and TreasuryTable.
18011801
func parseTreasuryParams(r *http.Request) (txType stake.TxType, txTypeStr string, limitN, offsetAddrOuts int64, err error) {
1802-
txTypeStr, limitN, offsetAddrOuts, err = parsePaginationParams(r)
1802+
txTypeStr, limitN, offsetAddrOuts, err = parsePaginationParams(r, false)
18031803
txType = parseTreasuryTransactionType(txTypeStr)
18041804
return
18051805
}
18061806

18071807
// parsePaginationParams parses the pagination parameters from the query. The
18081808
// txnType string is returned as-is. The caller must decipher the string.
1809-
func parsePaginationParams(r *http.Request) (txnType string, limitN, offset int64, err error) {
1809+
func parsePaginationParams(r *http.Request, isAddressPage bool) (txnType string, limitN, offset int64, err error) {
18101810
// Number of outputs for the address to query the database for. The URL
18111811
// query parameter "n" is used to specify the limit (e.g. "?n=20").
18121812
limitN = defaultAddressRows
@@ -1841,7 +1841,11 @@ func parsePaginationParams(r *http.Request) (txnType string, limitN, offset int6
18411841

18421842
// Transaction types to show.
18431843
if txnType = r.URL.Query().Get("txntype"); txnType == "" {
1844-
txnType = "tspend" // Default to tspend
1844+
if isAddressPage {
1845+
txnType = "all" // Default to all types for address page
1846+
} else {
1847+
txnType = "tspend" // Default to tspend for treasury page
1848+
}
18451849
}
18461850

18471851
return

0 commit comments

Comments
 (0)