Skip to content

Commit

Permalink
initial logic to return block data (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
andynog committed May 18, 2023
1 parent 39065f9 commit 9c95bec
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/cometbft/cometbft/libs/json"
client "github.com/cometbft/cometbft/rpc/client/http"
ctypes "github.com/cometbft/cometbft/rpc/core/types"
"github.com/cometbft/cometbft/types"
_ "github.com/lib/pq"
"log"
"net/http"
Expand Down Expand Up @@ -139,12 +140,13 @@ func (c *PostgresStorage) InsertBlock(resultBlock ctypes.ResultBlock) (bool, err

func (c *PostgresStorage) GetBlock(height int64) (ctypes.ResultBlock, error) {
resultBlock := ctypes.ResultBlock{}
var rowHeight int64
row := c.Connection.QueryRow("SELECT block_header_height FROM comet.result_block WHERE block_header_height=$1", height)
err := row.Scan(&rowHeight)
b := new(types.Block)
row := c.Connection.QueryRow("SELECT block_header_height, block_header_chain_id, block_header_block_time FROM comet.result_block WHERE block_header_height=$1", height)
err := row.Scan(&b.Header.Height, &b.Header.ChainID, &b.Header.Time)
if err != nil {
resultBlock.Block.Height = rowHeight
return resultBlock, err
}
resultBlock.Block = b
return resultBlock, err
}

Expand Down Expand Up @@ -189,7 +191,7 @@ func main() {
panic(err)
}

for height := 1; height <= 20; height++ {
for height := 1; height <= 100; height++ {

blockFetched, err := fetcher.FetchBlock(int64(height))
if err != nil {
Expand Down

0 comments on commit 9c95bec

Please sign in to comment.