diff --git a/api/types/apitypes.go b/api/types/apitypes.go index d9cb9347e..2aff6c6ac 100644 --- a/api/types/apitypes.go +++ b/api/types/apitypes.go @@ -11,6 +11,7 @@ import ( "sync" "time" + "github.com/decred/dcrd/dcrutil/v4" chainjson "github.com/decred/dcrd/rpc/jsonrpc/types/v4" "github.com/decred/dcrd/txscript/v4/stdscript" "github.com/decred/dcrdata/v8/db/dbtypes" @@ -93,15 +94,17 @@ type Vin = chainjson.Vin // TxShort models info about transaction TxID type TxShort struct { - TxID string `json:"txid"` - Size int32 `json:"size"` - Version int32 `json:"version"` - Locktime uint32 `json:"locktime"` - Expiry uint32 `json:"expiry"` - Vin []Vin `json:"vin"` - Vout []Vout `json:"vout"` - Tree int8 `json:"tree"` - Type string `json:"type"` + TxID string `json:"txid"` + Size int32 `json:"size"` + Version int32 `json:"version"` + Locktime uint32 `json:"locktime"` + Expiry uint32 `json:"expiry"` + Fee dcrutil.Amount `json:"fee"` + FeeRate dcrutil.Amount `json:"feerate"` + Vin []Vin `json:"vin"` + Vout []Vout `json:"vout"` + Tree int8 `json:"tree"` + Type string `json:"type"` } // AgendasInfo holds the high level details about an agenda. @@ -121,12 +124,14 @@ type AgendaAPIResponse struct { // TrimmedTx models data to resemble to result of the decoderawtransaction RPC. type TrimmedTx struct { - TxID string `json:"txid"` - Version int32 `json:"version"` - Locktime uint32 `json:"locktime"` - Expiry uint32 `json:"expiry"` - Vin []Vin `json:"vin"` - Vout []Vout `json:"vout"` + TxID string `json:"txid"` + Version int32 `json:"version"` + Locktime uint32 `json:"locktime"` + Expiry uint32 `json:"expiry"` + Fee dcrutil.Amount `json:"fee"` + FeeRate dcrutil.Amount `json:"feerate"` + Vin []Vin `json:"vin"` + Vout []Vout `json:"vout"` } // Txns models the multi transaction post data structure diff --git a/cmd/dcrdata/internal/api/apiroutes.go b/cmd/dcrdata/internal/api/apiroutes.go index 82dfd509e..54fdd6f1b 100644 --- a/cmd/dcrdata/internal/api/apiroutes.go +++ b/cmd/dcrdata/internal/api/apiroutes.go @@ -840,7 +840,7 @@ func (c *appContext) getTxSwapsInfo(w http.ResponseWriter, r *http.Request) { writeJSON(w, swapsInfo, m.GetIndentCtx(r)) } -// getTransactions handles the /txns POST API endpoint. +// getTransactions handles the /txs POST API endpoint. func (c *appContext) getTransactions(w http.ResponseWriter, r *http.Request) { ctx := r.Context() diff --git a/db/dcrpg/pgblockchain.go b/db/dcrpg/pgblockchain.go index e4f776a70..721dec779 100644 --- a/db/dcrpg/pgblockchain.go +++ b/db/dcrpg/pgblockchain.go @@ -4983,6 +4983,7 @@ func (pgb *ChainDB) GetAPITransaction(ctx context.Context, txid *chainhash.Hash) }, } + tx.Fee, tx.FeeRate = txhelpers.TxFeeRate(msgTx) copy(tx.Vin, txraw.Vin) for i := range txraw.Vout { @@ -5024,6 +5025,8 @@ func (pgb *ChainDB) GetTrimmedTransaction(ctx context.Context, txid *chainhash.H Expiry: tx.Expiry, Vin: tx.Vin, Vout: tx.Vout, + Fee: tx.Fee, + FeeRate: tx.FeeRate, } }