Skip to content

Commit

Permalink
indexer: rename GetTransaction* methods -> GetTxReference*
Browse files Browse the repository at this point in the history
  • Loading branch information
altergui committed Jul 23, 2024
1 parent aa316a5 commit f4715f1
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
6 changes: 3 additions & 3 deletions api/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ func (a *API) chainTxbyHashHandler(_ *apirest.APIdata, ctx *httprouter.HTTPConte
if err != nil {
return err
}
ref, err := a.indexer.GetTxHashReference(hash)
ref, err := a.indexer.GetTxReferenceByHash(hash)
if err != nil {
if errors.Is(err, indexer.ErrTransactionNotFound) {
return ErrTransactionNotFound
Expand Down Expand Up @@ -635,7 +635,7 @@ func (a *API) chainTxByIndexHandler(_ *apirest.APIdata, ctx *httprouter.HTTPCont
if err != nil {
return err
}
ref, err := a.indexer.GetTransaction(index)
ref, err := a.indexer.GetTxReferenceByID(index)
if err != nil {
if errors.Is(err, indexer.ErrTransactionNotFound) {
return ErrTransactionNotFound
Expand Down Expand Up @@ -702,7 +702,7 @@ func (a *API) chainTxByHeightHandler(_ *apirest.APIdata, ctx *httprouter.HTTPCon
tx.ProtoReflect().Descriptor().Oneofs().Get(0)).Name())

// TODO: can we avoid indexer Get calls in a loop?
txRef, err := a.indexer.GetTxHashReference(block.Txs[i].Hash())
txRef, err := a.indexer.GetTxReferenceByHash(block.Txs[i].Hash())
if err != nil {
return ErrTransactionNotFound
}
Expand Down
6 changes: 3 additions & 3 deletions vochain/indexer/bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func BenchmarkIndexer(b *testing.B) {
qt.Check(b, bytes.Equal(voteRef.Meta.TxHash, tx.TxID[:]), qt.IsTrue)
}

txRef, err := idx.GetTxHashReference(tx.TxID[:])
txRef, err := idx.GetTxReferenceByHash(tx.TxID[:])
qt.Check(b, err, qt.IsNil)
if err == nil {
qt.Check(b, txRef.BlockHeight, qt.Equals, vote.Height)
Expand Down Expand Up @@ -152,14 +152,14 @@ func BenchmarkFetchTx(b *testing.B) {

startTime := time.Now()
for j := 0; j < numTxs; j++ {
_, err = idx.GetTransaction(uint64((i * numTxs) + j + 1))
_, err = idx.GetTxReferenceByID(uint64((i * numTxs) + j + 1))
qt.Assert(b, err, qt.IsNil)
}
log.Infof("fetched %d transactions (out of %d total) by index, took %s",
numTxs, (i+1)*numTxs, time.Since(startTime))
startTime = time.Now()
for j := 0; j < numTxs; j++ {
_, err = idx.GetTxHashReference([]byte(fmt.Sprintf("hash%d%d", i, j)))
_, err = idx.GetTxReferenceByHash([]byte(fmt.Sprintf("hash%d%d", i, j)))
qt.Assert(b, err, qt.IsNil)
}
log.Infof("fetched %d transactions (out of %d total) by hash, took %s",
Expand Down
4 changes: 2 additions & 2 deletions vochain/indexer/indexer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1378,15 +1378,15 @@ func TestTxIndexer(t *testing.T) {

for i := 0; i < totalBlocks; i++ {
for j := 0; j < txsPerBlock; j++ {
ref, err := idx.GetTransaction(uint64(i*txsPerBlock + j + 1))
ref, err := idx.GetTxReferenceByID(uint64(i*txsPerBlock + j + 1))
qt.Assert(t, err, qt.IsNil)
qt.Assert(t, ref.BlockHeight, qt.Equals, uint32(i))
qt.Assert(t, ref.TxBlockIndex, qt.Equals, int32(j))
qt.Assert(t, ref.TxType, qt.Equals, "setAccount")
h := make([]byte, 32)
id := getTxID(i, j)
copy(h, id[:])
hashRef, err := idx.GetTxHashReference(h)
hashRef, err := idx.GetTxReferenceByHash(h)
qt.Assert(t, err, qt.IsNil)
qt.Assert(t, hashRef.BlockHeight, qt.Equals, uint32(i))
qt.Assert(t, hashRef.TxBlockIndex, qt.Equals, int32(j))
Expand Down
8 changes: 4 additions & 4 deletions vochain/indexer/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ func (idx *Indexer) CountTransactionsByHeight(height int64) (int64, error) {
return idx.readOnlyQuery.CountTransactionsByHeight(context.TODO(), height)
}

// GetTransaction fetches the txReference for the given tx height
func (idx *Indexer) GetTransaction(id uint64) (*indexertypes.Transaction, error) {
// GetTxReferenceByID fetches the txReference for the given tx height
func (idx *Indexer) GetTxReferenceByID(id uint64) (*indexertypes.Transaction, error) {
sqlTxRef, err := idx.readOnlyQuery.GetTransaction(context.TODO(), int64(id))
if err != nil {
if errors.Is(err, sql.ErrNoRows) {
Expand All @@ -55,8 +55,8 @@ func (idx *Indexer) GetTxReferenceByBlockHeightAndBlockIndex(blockHeight, blockI
return indexertypes.TransactionFromDB(&sqlTxRef), nil
}

// GetTxHashReference fetches the txReference for the given tx hash
func (idx *Indexer) GetTxHashReference(hash types.HexBytes) (*indexertypes.Transaction, error) {
// GetTxReferenceByHash fetches the txReference for the given tx hash
func (idx *Indexer) GetTxReferenceByHash(hash types.HexBytes) (*indexertypes.Transaction, error) {
sqlTxRef, err := idx.readOnlyQuery.GetTransactionByHash(context.TODO(), hash)
if err != nil {
if errors.Is(err, sql.ErrNoRows) {
Expand Down

0 comments on commit f4715f1

Please sign in to comment.