Skip to content

Commit

Permalink
api: fetch blocks from indexer rather than app BlockStore
Browse files Browse the repository at this point in the history
  • Loading branch information
altergui committed Jul 8, 2024
1 parent 6d0baa7 commit 62478aa
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 31 deletions.
4 changes: 1 addition & 3 deletions api/api_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"encoding/json"
"time"

comettypes "github.com/cometbft/cometbft/types"
"github.com/google/uuid"
"go.vocdoni.io/dvote/types"
"go.vocdoni.io/dvote/vochain/indexer/indexertypes"
Expand Down Expand Up @@ -358,6 +357,5 @@ func CensusTypeToOrigin(ctype CensusTypeDescription) (models.CensusOrigin, []byt
}

type Block struct {
comettypes.Block `json:",inline"`
Hash types.HexBytes `json:"hash" `
*indexertypes.Block
}
42 changes: 14 additions & 28 deletions api/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,9 @@ import (
"strconv"
"time"

comettypes "github.com/cometbft/cometbft/types"
"go.vocdoni.io/dvote/crypto/zk/circuit"
"go.vocdoni.io/dvote/httprouter"
"go.vocdoni.io/dvote/httprouter/apirest"
"go.vocdoni.io/dvote/types"
"go.vocdoni.io/dvote/util"
"go.vocdoni.io/dvote/vochain"
"go.vocdoni.io/dvote/vochain/genesis"
Expand Down Expand Up @@ -818,20 +816,14 @@ func (a *API) chainBlockHandler(_ *apirest.APIdata, ctx *httprouter.HTTPContext)
if err != nil {
return err
}
tmblock := a.vocapp.GetBlockByHeight(int64(height))
if tmblock == nil {
return ErrBlockNotFound
}
block := &Block{
Block: comettypes.Block{
Header: tmblock.Header,
Data: tmblock.Data,
Evidence: tmblock.Evidence,
LastCommit: tmblock.LastCommit,
},
Hash: types.HexBytes(tmblock.Hash()),
block, err := a.indexer.BlockByHeight(int64(height))
if err != nil {
if errors.Is(err, indexer.ErrBlockNotFound) {
return ErrBlockNotFound
}
return ErrBlockNotFound.WithErr(err)
}
data, err := json.Marshal(block)
data, err := json.Marshal(&Block{block})
if err != nil {
return err
}
Expand All @@ -853,20 +845,14 @@ func (a *API) chainBlockByHashHandler(_ *apirest.APIdata, ctx *httprouter.HTTPCo
if err != nil {
return err
}
tmblock := a.vocapp.GetBlockByHash(hash)
if tmblock == nil {
return ErrBlockNotFound
}
block := &Block{
Block: comettypes.Block{
Header: tmblock.Header,
Data: tmblock.Data,
Evidence: tmblock.Evidence,
LastCommit: tmblock.LastCommit,
},
Hash: types.HexBytes(tmblock.Hash()),
block, err := a.indexer.BlockByHash(hash)
if err != nil {
if errors.Is(err, indexer.ErrBlockNotFound) {
return ErrBlockNotFound
}
return ErrBlockNotFound.WithErr(err)
}
data, err := json.Marshal(block)
data, err := json.Marshal(&Block{block})
if err != nil {
return err
}
Expand Down

0 comments on commit 62478aa

Please sign in to comment.