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 26, 2024
1 parent 5c198f3 commit d52ed23
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
4 changes: 2 additions & 2 deletions api/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
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 @@ -1405,15 +1405,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 d52ed23

Please sign in to comment.