Skip to content

Commit

Permalink
(lts-backport) remove leftovers
Browse files Browse the repository at this point in the history
  • Loading branch information
altergui committed Sep 9, 2024
1 parent bb04035 commit a9cc093
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 55 deletions.
48 changes: 4 additions & 44 deletions api/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,6 @@ func (a *API) enableChainHandlers() error {
); err != nil {
return err
}
if err := a.Endpoint.RegisterMethod(
"/chain/transactions/reference/index/{index}",
"GET",
apirest.MethodAccessTypePublic,
a.chainTxByIndexHandler,
); err != nil {
return err
}
if err := a.Endpoint.RegisterMethod(
"/chain/blocks/{height}/transactions/page/{page}",
"GET",
Expand Down Expand Up @@ -275,7 +267,6 @@ func (a *API) organizationCountHandler(_ *apirest.APIdata, ctx *httprouter.HTTPC
return err
}
return ctx.Send(data, apirest.HTTPstatusOK)

}

// chainInfoHandler
Expand Down Expand Up @@ -606,36 +597,6 @@ func (a *API) chainTxHandler(_ *apirest.APIdata, ctx *httprouter.HTTPContext) er
return ctx.Send(data, apirest.HTTPstatusOK)
}

// chainTxByIndexHandler
//
// @Summary Transaction by index
// @Description Get transaction by its index. This is not transaction reference (hash), and neither the block height and block index. The transaction index is an incremental counter for each transaction. You could use the transaction `block` and `index` to retrieve full info using [transaction by block and index](transaction-by-block-index).
// @Tags Chain
// @Accept json
// @Produce json
// @Param index path int true "Index of the transaction"
// @Success 200 {object} indexertypes.Transaction
// @Success 204 "See [errors](vocdoni-api#errors) section"
// @Router /chain/transactions/reference/index/{index} [get]
func (a *API) chainTxByIndexHandler(_ *apirest.APIdata, ctx *httprouter.HTTPContext) error {
index, err := strconv.ParseUint(ctx.URLParam("index"), 10, 64)
if err != nil {
return err
}
ref, err := a.indexer.GetTransaction(index)
if err != nil {
if errors.Is(err, indexer.ErrTransactionNotFound) {
return ErrTransactionNotFound
}
return ErrVochainGetTxFailed.WithErr(err)
}
data, err := json.Marshal(ref)
if err != nil {
return err
}
return ctx.Send(data, apirest.HTTPstatusOK)
}

// chainTxByHeightHandler
//
// @Summary Transactions in a block
Expand Down Expand Up @@ -689,15 +650,14 @@ 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())
_, err = a.indexer.GetTxHashReference(block.Txs[i].Hash())
if err != nil {
return ErrTransactionNotFound
}
blockTxs.Transactions = append(blockTxs.Transactions, TransactionMetadata{
Type: txType,
Index: int32(i),
Number: uint32(txRef.Index),
Hash: block.Txs[i].Hash(),
Type: txType,
Index: int32(i),
Hash: block.Txs[i].Hash(),
})
count++
}
Expand Down
12 changes: 1 addition & 11 deletions vochain/indexer/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"fmt"
"time"

"go.vocdoni.io/dvote/log"
indexerdb "go.vocdoni.io/dvote/vochain/indexer/db"
"go.vocdoni.io/dvote/vochain/indexer/indexertypes"
"go.vocdoni.io/dvote/vochain/state"
Expand All @@ -17,16 +16,7 @@ import (
var ErrBlockNotFound = fmt.Errorf("block not found")

func (idx *Indexer) OnBeginBlock(bb state.BeginBlock) {
idx.blockMu.Lock()
defer idx.blockMu.Unlock()
queries := idx.blockTxQueries()
if _, err := queries.CreateBlock(context.TODO(), indexerdb.CreateBlockParams{
Height: bb.Height,
Time: bb.Time,
DataHash: nonNullBytes(bb.DataHash),
}); err != nil {
log.Errorw(err, "cannot index new block")
}
// don't index anything, we're just interested in reindexing old blocks
}

// BlockTimestamp returns the timestamp of the block at the given height
Expand Down

0 comments on commit a9cc093

Please sign in to comment.