diff --git a/api/chain.go b/api/chain.go index 771b03cbc..089a193a3 100644 --- a/api/chain.go +++ b/api/chain.go @@ -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 @@ -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 @@ -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 } 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 0c9716cca..c02671088 100644 --- a/vochain/indexer/indexer_test.go +++ b/vochain/indexer/indexer_test.go @@ -1378,7 +1378,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)) @@ -1386,7 +1386,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 b312f2313..79feeb319 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) {