1- // Copyright (c) 2018-2024 , The Decred developers
1+ // Copyright (c) 2018-2025 , The Decred developers
22// Copyright (c) 2017, The dcrdata developers
33// See LICENSE for details.
44
@@ -1408,62 +1408,40 @@ type TreasuryInfo struct {
14081408 Path string
14091409 Limit , Offset int64 // ?n=Limit&start=Offset
14101410 TxnType string // ?txntype=TxnType
1411-
1412- // TODO: tadd and tspend can be unconfirmed. tspend for a very long time.
1413- // NumUnconfirmed is the number of unconfirmed txns
1414- // NumUnconfirmed int64
1415- // UnconfirmedTxns []*dbtypes.TreasuryTx
1416-
14171411 // Transactions on the current page
14181412 Transactions []* dbtypes.TreasuryTx
14191413 NumTransactions int64 // len(Transactions) but int64 for dumb template
14201414
14211415 Balance * dbtypes.TreasuryBalance
14221416 ConvertedBalance * exchanges.Conversion
14231417 TypeCount int64
1418+
1419+ // tadd and tspend can be unconfirmed. tspend for a very long time.
1420+ Mempool * TreasuryMempoolInfo
1421+ }
1422+
1423+ // TreasuryMempoolInfo holds the treasury-related mempool transactions that are
1424+ // not yet confirmed in a block. It is used to display treasury mempool
1425+ // information on the treasury page.
1426+ type TreasuryMempoolInfo struct {
1427+ NumTSpends int
1428+ NumTAdds int
1429+ TSpends []types.MempoolTx
1430+ TAdds []types.MempoolTx
14241431}
14251432
14261433// TreasuryPage is the page handler for the "/treasury" path
14271434func (exp * explorerUI ) TreasuryPage (w http.ResponseWriter , r * http.Request ) {
1428- ctx := context .WithValue (r .Context (), ctxAddress , exp .pageData .HomeInfo .DevAddress )
1429- r = r .WithContext (ctx )
1430- if queryVals := r .URL .Query (); queryVals .Get ("txntype" ) == "" {
1431- queryVals .Set ("txntype" , "tspend" )
1432- r .URL .RawQuery = queryVals .Encode ()
1433- }
1434-
1435- limitN := defaultAddressRows
1436- if nParam := r .URL .Query ().Get ("n" ); nParam != "" {
1437- val , err := strconv .ParseUint (nParam , 10 , 64 )
1438- if err != nil {
1439- exp .StatusPage (w , defaultErrorCode , "invalid n value" , "" , ExpStatusError )
1440- return
1441- }
1442- if int64 (val ) > MaxTreasuryRows {
1443- log .Warnf ("TreasuryPage: requested up to %d address rows, " +
1444- "limiting to %d" , limitN , MaxTreasuryRows )
1445- limitN = MaxTreasuryRows
1446- } else {
1447- limitN = int64 (val )
1448- }
1449- }
1435+ ctx := r .Context ()
14501436
1451- // Number of txns to skip (OFFSET in database query). For UX reasons, the
1452- // "start" URL query parameter is used.
1453- var offset int64
1454- if startParam := r .URL .Query ().Get ("start" ); startParam != "" {
1455- val , err := strconv .ParseUint (startParam , 10 , 64 )
1456- if err != nil {
1457- exp .StatusPage (w , defaultErrorCode , "invalid start value" , "" , ExpStatusError )
1458- return
1459- }
1460- offset = int64 (val )
1437+ // Grab the URL query parameters
1438+ txType , txTypeStr , limitN , offset , err := parseTreasuryParams (r )
1439+ if err != nil {
1440+ log .Errorf ("TreasuryPage request error: %v" , err )
1441+ http .Error (w , http .StatusText (http .StatusBadRequest ), http .StatusBadRequest )
1442+ return
14611443 }
14621444
1463- // Transaction types to show.
1464- txTypeStr := r .URL .Query ().Get ("txntype" )
1465- txType := parseTreasuryTransactionType (txTypeStr )
1466-
14671445 txns , err := exp .dataSource .TreasuryTxns (ctx , limitN , offset , txType )
14681446 if exp .timeoutErrorPage (w , err , "TreasuryTxns" ) {
14691447 return
@@ -1477,6 +1455,7 @@ func (exp *explorerUI) TreasuryPage(w http.ResponseWriter, r *http.Request) {
14771455 exp .pageData .RUnlock ()
14781456
14791457 typeCount := treasuryTypeCount (treasuryBalance , txType )
1458+ inv := exp .MempoolInventory ()
14801459
14811460 treasuryData := & TreasuryInfo {
14821461 Net : exp .ChainParams .Net .String (),
@@ -1489,6 +1468,12 @@ func (exp *explorerUI) TreasuryPage(w http.ResponseWriter, r *http.Request) {
14891468 Transactions : txns ,
14901469 Balance : treasuryBalance ,
14911470 TypeCount : typeCount ,
1471+ Mempool : & TreasuryMempoolInfo {
1472+ NumTSpends : inv .NumTSpends ,
1473+ NumTAdds : inv .NumTAdds ,
1474+ TSpends : inv .TSpends ,
1475+ TAdds : inv .TAdds ,
1476+ },
14921477 }
14931478
14941479 xcBot := exp .xcBot
@@ -1497,7 +1482,7 @@ func (exp *explorerUI) TreasuryPage(w http.ResponseWriter, r *http.Request) {
14971482 }
14981483
14991484 // Execute the HTML template.
1500- linkTemplate := fmt .Sprintf ("/treasury?start=%%d&n=%d&txntype=%v " , limitN , txType )
1485+ linkTemplate := fmt .Sprintf ("/treasury?start=%%d&n=%d&txntype=%s " , limitN , txTypeStr )
15011486 pageData := struct {
15021487 * CommonPageData
15031488 Data * TreasuryInfo
@@ -1704,7 +1689,7 @@ func (exp *explorerUI) TreasuryTable(w http.ResponseWriter, r *http.Request) {
17041689 ctx := r .Context ()
17051690
17061691 // Grab the URL query parameters
1707- txType , limitN , offset , err := parseTreasuryParams (r )
1692+ txType , txTypeStr , limitN , offset , err := parseTreasuryParams (r )
17081693 if err != nil {
17091694 log .Errorf ("TreasuryTable request error: %v" , err )
17101695 http .Error (w , http .StatusText (http .StatusBadRequest ), http .StatusBadRequest )
@@ -1723,7 +1708,7 @@ func (exp *explorerUI) TreasuryTable(w http.ResponseWriter, r *http.Request) {
17231708 bal := exp .pageData .HomeInfo .TreasuryBalance
17241709 exp .pageData .RUnlock ()
17251710
1726- linkTemplate := "/treasury" + "?start=%d&n=" + strconv .FormatInt (limitN , 10 ) + "&txntype=" + fmt .Sprintf ("%v " , txType )
1711+ linkTemplate := "/treasury" + "?start=%d&n=" + strconv .FormatInt (limitN , 10 ) + "&txntype=" + fmt .Sprintf ("%s " , txTypeStr )
17271712
17281713 response := struct {
17291714 TxnCount int64 `json:"tx_count"`
@@ -1816,9 +1801,9 @@ func parseTreasuryTransactionType(txnTypeStr string) (txType stake.TxType) {
18161801
18171802// parseTreasuryParams parses the tx filters for the treasury page. Used by both
18181803// TreasuryPage and TreasuryTable.
1819- func parseTreasuryParams (r * http.Request ) (txType stake.TxType , limitN , offsetAddrOuts int64 , err error ) {
1820- tType , limitN , offsetAddrOuts , err : = parsePaginationParams (r )
1821- txType = parseTreasuryTransactionType (tType )
1804+ func parseTreasuryParams (r * http.Request ) (txType stake.TxType , txTypeStr string , limitN , offsetAddrOuts int64 , err error ) {
1805+ txTypeStr , limitN , offsetAddrOuts , err = parsePaginationParams (r )
1806+ txType = parseTreasuryTransactionType (txTypeStr )
18221807 return
18231808}
18241809
@@ -1830,7 +1815,6 @@ func parsePaginationParams(r *http.Request) (txnType string, limitN, offset int6
18301815 limitN = defaultAddressRows
18311816
18321817 if nParam := r .URL .Query ().Get ("n" ); nParam != "" {
1833-
18341818 var val uint64
18351819 val , err = strconv .ParseUint (nParam , 10 , 64 )
18361820 if err != nil {
@@ -1859,9 +1843,8 @@ func parsePaginationParams(r *http.Request) (txnType string, limitN, offset int6
18591843 }
18601844
18611845 // Transaction types to show.
1862- txnType = r .URL .Query ().Get ("txntype" )
1863- if txnType == "" {
1864- txnType = "all"
1846+ if txnType = r .URL .Query ().Get ("txntype" ); txnType == "" {
1847+ txnType = "tspend" // Default to tspend
18651848 }
18661849
18671850 return
0 commit comments