Skip to content

Commit

Permalink
add timestamp support for tx_search
Browse files Browse the repository at this point in the history
  • Loading branch information
tubackkhoa committed Jun 27, 2023
1 parent fe4894f commit f4cb62f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 13 deletions.
24 changes: 17 additions & 7 deletions rpc/core/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"errors"
"fmt"
"sort"
"time"

cmtmath "github.com/tendermint/tendermint/libs/math"
cmtquery "github.com/tendermint/tendermint/libs/pubsub/query"
Expand Down Expand Up @@ -112,22 +113,31 @@ func TxSearch(
pageSize := cmtmath.MinInt(perPage, totalCount-skipCount)

apiResults := make([]*ctypes.ResultTx, 0, pageSize)

blocks := make(map[int64]*types.Block)

for i := skipCount; i < skipCount+pageSize; i++ {
r := results[i]

if _, ok := blocks[r.Height]; !ok {
blocks[r.Height] = env.BlockStore.LoadBlock(r.Height)
}

block := blocks[r.Height]

var proof types.TxProof
if prove {
block := env.BlockStore.LoadBlock(r.Height)
proof = block.Data.Txs.Proof(int(r.Index)) // XXX: overflow on 32-bit machines
}

apiResults = append(apiResults, &ctypes.ResultTx{
Hash: types.Tx(r.Tx).Hash(),
Height: r.Height,
Index: r.Index,
TxResult: r.Result,
Tx: r.Tx,
Proof: proof,
Hash: types.Tx(r.Tx).Hash(),
Height: r.Height,
Index: r.Index,
TxResult: r.Result,
Timestamp: block.Time.Format(time.RFC3339),
Tx: r.Tx,
Proof: proof,
})
}

Expand Down
13 changes: 7 additions & 6 deletions rpc/core/types/responses.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,12 +191,13 @@ type ResultCheckTx struct {

// Result of querying for a tx
type ResultTx struct {
Hash bytes.HexBytes `json:"hash"`
Height int64 `json:"height"`
Index uint32 `json:"index"`
TxResult abci.ResponseDeliverTx `json:"tx_result"`
Tx types.Tx `json:"tx"`
Proof types.TxProof `json:"proof,omitempty"`
Hash bytes.HexBytes `json:"hash"`
Height int64 `json:"height"`
Index uint32 `json:"index"`
TxResult abci.ResponseDeliverTx `json:"tx_result"`
Timestamp string `json:"timestamp,omitempty"`
Tx types.Tx `json:"tx"`
Proof types.TxProof `json:"proof,omitempty"`
}

// Result of searching for txs
Expand Down

0 comments on commit f4cb62f

Please sign in to comment.