@@ -4,28 +4,34 @@ import (
44 "github.com/gin-gonic/gin"
55 "github.com/rs/zerolog/log"
66 "github.com/thirdweb-dev/indexer/api"
7+ "github.com/thirdweb-dev/indexer/internal/common"
78 "github.com/thirdweb-dev/indexer/internal/storage"
89)
910
1011// BlockModel represents a simplified Block structure for Swagger documentation
1112type BlockModel struct {
12- ChainId string `json:"chain_id"`
13- Number string `json:"number"`
14- Hash string `json:"hash"`
15- ParentHash string `json:"parent_hash"`
16- Timestamp uint64 `json:"timestamp"`
17- Nonce string `json:"nonce"`
18- Sha3Uncles string `json:"sha3_uncles"`
19- LogsBloom string `json:"logs_bloom"`
20- ReceiptsRoot string `json:"receipts_root"`
21- Difficulty string `json:"difficulty"`
22- TotalDifficulty string `json:"total_difficulty"`
23- Size uint64 `json:"size"`
24- ExtraData string `json:"extra_data"`
25- GasLimit uint64 `json:"gas_limit"`
26- GasUsed uint64 `json:"gas_used"`
27- BaseFeePerGas string `json:"base_fee_per_gas"`
28- WithdrawalsRoot string `json:"withdrawals_root"`
13+ ChainId string `json:"chain_id"`
14+ Number uint64 `json:"number"`
15+ Hash string `json:"hash"`
16+ ParentHash string `json:"parent_hash"`
17+ Timestamp uint64 `json:"timestamp"`
18+ Nonce string `json:"nonce"`
19+ Sha3Uncles string `json:"sha3_uncles"`
20+ MixHash string `json:"mix_hash"`
21+ Miner string `json:"miner"`
22+ StateRoot string `json:"state_root"`
23+ TransactionsRoot string `json:"transactions_root"`
24+ ReceiptsRoot string `json:"receipts_root"`
25+ LogsBloom string `json:"logs_bloom"`
26+ Size uint64 `json:"size"`
27+ ExtraData string `json:"extra_data"`
28+ Difficulty string `json:"difficulty"`
29+ TotalDifficulty string `json:"total_difficulty"`
30+ TransactionCount uint64 `json:"transaction_count"`
31+ GasLimit uint64 `json:"gas_limit"`
32+ GasUsed uint64 `json:"gas_used"`
33+ WithdrawalsRoot string `json:"withdrawals_root"`
34+ BaseFeePerGas uint64 `json:"base_fee_per_gas"`
2935}
3036
3137// @Summary Get all blocks
@@ -118,9 +124,40 @@ func handleBlocksRequest(c *gin.Context) {
118124 return
119125 }
120126
121- queryResult .Data = blocksResult .Data
127+ queryResult .Data = serializeBlocks ( blocksResult .Data )
122128 queryResult .Meta .TotalItems = len (blocksResult .Data )
123129 }
124130
125131 sendJSONResponse (c , queryResult )
126132}
133+
134+ func serializeBlocks (blocks []common.Block ) []BlockModel {
135+ blockModels := make ([]BlockModel , len (blocks ))
136+ for i , block := range blocks {
137+ blockModels [i ] = BlockModel {
138+ ChainId : block .ChainId .String (),
139+ Number : block .Number .Uint64 (),
140+ Hash : block .Hash ,
141+ ParentHash : block .ParentHash ,
142+ Timestamp : block .Timestamp ,
143+ Nonce : block .Nonce ,
144+ Sha3Uncles : block .Sha3Uncles ,
145+ MixHash : block .MixHash ,
146+ Miner : block .Miner ,
147+ StateRoot : block .StateRoot ,
148+ TransactionsRoot : block .TransactionsRoot ,
149+ ReceiptsRoot : block .ReceiptsRoot ,
150+ LogsBloom : block .LogsBloom ,
151+ Size : block .Size ,
152+ ExtraData : block .ExtraData ,
153+ Difficulty : block .Difficulty .String (),
154+ TotalDifficulty : block .TotalDifficulty .String (),
155+ TransactionCount : block .TransactionCount ,
156+ GasLimit : block .GasLimit .Uint64 (),
157+ GasUsed : block .GasUsed .Uint64 (),
158+ WithdrawalsRoot : block .WithdrawalsRoot ,
159+ BaseFeePerGas : block .BaseFeePerGas ,
160+ }
161+ }
162+ return blockModels
163+ }
0 commit comments