@@ -61,6 +61,7 @@ const (
6161 pathMemoryWrongFeeBlocks = "/memory/wrongfeeblocks"
6262 pathMemoryDonations = "/memory/donations"
6363 pathMemoryPoolStatistics = "/memory/statistics"
64+ pathMemoryValidatorBlocks = "/memory/validatorblocks"
6465
6566 // Onchain endpoints: what is submitted to the contract
6667 pathOnchainValidators = "/onchain/validators" // TODO
@@ -178,6 +179,19 @@ type httpOkProofs struct {
178179 PendingRewardsWei string `json:"pending_rewards_wei"`
179180}
180181
182+ type SimplifiedValidatorInfo struct {
183+ Status oracle.ValidatorStatus `json:"status"`
184+ AccumulatedRewards * big.Int `json:"accumulated_rewards_wei"`
185+ PendingRewards * big.Int `json:"pending_rewards_wei"`
186+ Collateral * big.Int `json:"collateral_wei"`
187+ WithdrawalAddress string `json:"withdrawal_address"`
188+ ValidatorIndex uint64 `json:"validator_index"`
189+ ValidatorKey string `json:"validator_key"`
190+ ProposedBlocks []oracle.Block `json:"proposed_block"`
191+ MissedBlocks []oracle.Block `json:"missed_blocks"`
192+ WrongFeeBlocks []oracle.Block `json:"wrong_fee_blocks"`
193+ }
194+
181195type ApiService struct {
182196 srv * http.Server
183197 cfg * config.Config
@@ -243,6 +257,7 @@ func (m *ApiService) getRouter() http.Handler {
243257 r .HandleFunc (pathMemoryMissedBlocks , m .handleMemoryMissedBlocks ).Methods (http .MethodGet )
244258 r .HandleFunc (pathMemoryWrongFeeBlocks , m .handleMemoryWrongFeeBlocks ).Methods (http .MethodGet )
245259 r .HandleFunc (pathMemoryDonations , m .handleMemoryDonations ).Methods (http .MethodGet )
260+ r .HandleFunc (pathMemoryValidatorBlocks , m .handleMemoryValidatorBlocks ).Methods (http .MethodGet )
246261
247262 // Onchain endpoints
248263 r .HandleFunc (pathOnchainMerkleProof , m .handleOnchainMerkleProof ).Methods (http .MethodGet )
@@ -305,6 +320,62 @@ func (m *ApiService) handleRoot(w http.ResponseWriter, req *http.Request) {
305320 m .respondOK (w , "see api doc for available endpoints" )
306321}
307322
323+ func (m * ApiService ) handleMemoryValidatorBlocks (w http.ResponseWriter , r * http.Request ) {
324+ // Access the existing OracleState instance from the ApiService
325+ oracleState := m .oracle .State ()
326+
327+ // Retrieve the ProposedBlocks, MissedBlocks, and WrongFeeBlocks from the OracleState
328+ proposedBlocks := oracleState .ProposedBlocks
329+ missedBlocks := oracleState .MissedBlocks
330+ wrongFeeBlocks := oracleState .WrongFeeBlocks
331+
332+ // Sort the blocks by ValidatorKey
333+ sort .Slice (proposedBlocks , func (i , j int ) bool {
334+ return proposedBlocks [i ].ValidatorKey < proposedBlocks [j ].ValidatorKey
335+ })
336+ sort .Slice (missedBlocks , func (i , j int ) bool {
337+ return missedBlocks [i ].ValidatorKey < missedBlocks [j ].ValidatorKey
338+ })
339+ sort .Slice (wrongFeeBlocks , func (i , j int ) bool {
340+ return wrongFeeBlocks [i ].ValidatorKey < wrongFeeBlocks [j ].ValidatorKey
341+ })
342+
343+ // Create a map to hold the ordered blocks, with the ValidatorKey as the key
344+ orderedBlocks := make (map [string ]interface {})
345+
346+ // Add the ordered blocks to the map
347+ for _ , block := range proposedBlocks {
348+ validatorKey := block .ValidatorKey
349+ if orderedBlocks [validatorKey ] == nil {
350+ orderedBlocks [validatorKey ] = make (map [string ]interface {})
351+ }
352+ orderedBlocks [validatorKey ].(map [string ]interface {})["proposed_block" ] = append (orderedBlocks [validatorKey ].(map [string ]interface {})["proposed_block" ].([]oracle.Block ), block )
353+ }
354+ for _ , block := range missedBlocks {
355+ validatorKey := block .ValidatorKey
356+ if orderedBlocks [validatorKey ] == nil {
357+ orderedBlocks [validatorKey ] = make (map [string ]interface {})
358+ }
359+ orderedBlocks [validatorKey ].(map [string ]interface {})["missed_blocks" ] = append (orderedBlocks [validatorKey ].(map [string ]interface {})["missed_blocks" ].([]oracle.Block ), block )
360+ }
361+ for _ , block := range wrongFeeBlocks {
362+ validatorKey := block .ValidatorKey
363+ if orderedBlocks [validatorKey ] == nil {
364+ orderedBlocks [validatorKey ] = make (map [string ]interface {})
365+ }
366+ orderedBlocks [validatorKey ].(map [string ]interface {})["wrong_fee_blocks" ] = append (orderedBlocks [validatorKey ].(map [string ]interface {})["wrong_fee_blocks" ].([]oracle.Block ), block )
367+ }
368+
369+ // Convert the map to JSON
370+ responseJSON , err := json .Marshal (orderedBlocks )
371+ if err != nil {
372+ // Handle error
373+ w .WriteHeader (http .StatusInternalServerError )
374+ return
375+ }
376+ m .respondOK (w , string (responseJSON ))
377+ }
378+
308379func (m * ApiService ) handleMemoryStatistics (w http.ResponseWriter , req * http.Request ) {
309380 totalSubscribed := uint64 (0 )
310381 totalActive := uint64 (0 )
0 commit comments