From d52ed235023c120b1700fe92b6d50fda91d326cd Mon Sep 17 00:00:00 2001 From: Gui Iribarren Date: Mon, 22 Jul 2024 11:16:11 +0200 Subject: [PATCH] indexer: rename GetTransaction* methods -> GetTxReference* --- api/chain.go | 4 ++-- vochain/indexer/bench_test.go | 6 +++--- vochain/indexer/indexer_test.go | 4 ++-- vochain/indexer/transaction.go | 8 ++++---- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/api/chain.go b/api/chain.go index 62bed37b5..543f3bb60 100644 --- a/api/chain.go +++ b/api/chain.go @@ -605,7 +605,7 @@ func (a *API) chainTxRefByHashHandler(_ *apirest.APIdata, ctx *httprouter.HTTPCo 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 @@ -684,7 +684,7 @@ func (a *API) chainTxRefByIndexHandler(_ *apirest.APIdata, ctx *httprouter.HTTPC 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 diff --git a/vochain/indexer/bench_test.go b/vochain/indexer/bench_test.go index e47a77c63..d5619127a 100644 --- a/vochain/indexer/bench_test.go +++ b/vochain/indexer/bench_test.go @@ -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) @@ -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", diff --git a/vochain/indexer/indexer_test.go b/vochain/indexer/indexer_test.go index 4d9945f0b..3b7624251 100644 --- a/vochain/indexer/indexer_test.go +++ b/vochain/indexer/indexer_test.go @@ -1405,7 +1405,7 @@ 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)) @@ -1413,7 +1413,7 @@ func TestTxIndexer(t *testing.T) { 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)) diff --git a/vochain/indexer/transaction.go b/vochain/indexer/transaction.go index 86bdf0590..059333704 100644 --- a/vochain/indexer/transaction.go +++ b/vochain/indexer/transaction.go @@ -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) { @@ -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) {