Skip to content

Commit

Permalink
add tx "tree" to apitypes.Tx
Browse files Browse the repository at this point in the history
  • Loading branch information
ukane-philemon committed Dec 9, 2022
1 parent 5d2df4b commit 2314ecc
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
6 changes: 4 additions & 2 deletions api/types/apitypes.go
Expand Up @@ -11,6 +11,7 @@ import (
"sync"
"time"

"github.com/decred/dcrd/blockchain/stake/v4"
chainjson "github.com/decred/dcrd/rpc/jsonrpc/types/v3"
"github.com/decred/dcrd/txscript/v4/stdscript"
"github.com/decred/dcrdata/v8/db/dbtypes"
Expand Down Expand Up @@ -84,8 +85,9 @@ type BlockTransactions struct {
// Tx models TxShort with the number of confirmations and block info Block
type Tx struct {
TxShort
Confirmations int64 `json:"confirmations"`
Block *BlockID `json:"block,omitempty"`
Tree stake.TxType `json:"tree"`
Confirmations int64 `json:"confirmations"`
Block *BlockID `json:"block,omitempty"`
}

// Vin is an alias for dcrd's rpc/jsonrpc/types/v3.Vin type.
Expand Down
14 changes: 14 additions & 0 deletions db/dcrpg/pgblockchain.go
Expand Up @@ -4827,6 +4827,19 @@ func (pgb *ChainDB) GetAPITransaction(txid *chainhash.Hash) *apitypes.Tx {
return nil
}

msgTx, err := txhelpers.MsgTxFromHex(txraw.Hex)
if err != nil {
log.Errorf("Cannot create MsgTx for tx %v: %v", txid.String(), err)
return nil
}

treasuryActive := true
if txraw.BlockHeight > 0 {
treasuryActive = txhelpers.IsTreasuryActive(pgb.chainParams.Net, txraw.BlockHeight)
}

txType := txhelpers.DetermineTxType(msgTx, treasuryActive)

tx := &apitypes.Tx{
TxShort: apitypes.TxShort{
TxID: txraw.Txid,
Expand All @@ -4837,6 +4850,7 @@ func (pgb *ChainDB) GetAPITransaction(txid *chainhash.Hash) *apitypes.Tx {
Vin: make([]apitypes.Vin, len(txraw.Vin)),
Vout: make([]apitypes.Vout, len(txraw.Vout)),
},
Tree: txType,
Confirmations: txraw.Confirmations,
Block: &apitypes.BlockID{
BlockHash: txraw.BlockHash,
Expand Down

0 comments on commit 2314ecc

Please sign in to comment.