Skip to content

Commit

Permalink
resolve comments
Browse files Browse the repository at this point in the history
  • Loading branch information
jrwbabylonlab committed Oct 15, 2024
1 parent ab117c0 commit 0bc195b
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 10 deletions.
24 changes: 19 additions & 5 deletions internal/clients/bbnclient/bbnclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,22 @@ func (c *BbnClient) GetCheckpointParams(ctx context.Context) (*CheckpointParams,
if err != nil {
return nil, types.NewErrorWithMsg(
http.StatusInternalServerError,
types.InternalServiceError,
types.ClientRequestError,
fmt.Sprintf("failed to get checkpoint params: %s", err.Error()),
)
}
if err := params.Params.Validate(); err != nil {
return nil, types.NewErrorWithMsg(
http.StatusInternalServerError,
types.ValidationError,
fmt.Sprintf("failed to validate checkpoint params: %s", err.Error()),
)
}
return &params.Params, nil
}

func (c *BbnClient) GetAllStakingParams(ctx context.Context) (map[uint32]StakingParams, *types.Error) {
allParams := make(map[uint32]StakingParams) // Map to store versioned staking parameters
func (c *BbnClient) GetAllStakingParams(ctx context.Context) (map[uint32]*StakingParams, *types.Error) {
allParams := make(map[uint32]*StakingParams) // Map to store versioned staking parameters
version := uint32(0)

for {
Expand All @@ -75,11 +82,18 @@ func (c *BbnClient) GetAllStakingParams(ctx context.Context) (map[uint32]Staking
}
return nil, types.NewErrorWithMsg(
http.StatusInternalServerError,
types.InternalServiceError,
types.ClientRequestError,
fmt.Sprintf("failed to get staking params for version %d: %s", version, err.Error()),
)
}
allParams[version] = *FromBbnStakingParams(params.Params)
if err := params.Params.Validate(); err != nil {
return nil, types.NewErrorWithMsg(
http.StatusInternalServerError,
types.ValidationError,
fmt.Sprintf("failed to validate staking params for version %d: %s", version, err.Error()),
)
}
allParams[version] = FromBbnStakingParams(params.Params)
version++
}
if len(allParams) == 0 {
Expand Down
2 changes: 1 addition & 1 deletion internal/clients/bbnclient/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

type BbnInterface interface {
GetCheckpointParams(ctx context.Context) (*CheckpointParams, *types.Error)
GetAllStakingParams(ctx context.Context) (map[uint32]StakingParams, *types.Error)
GetAllStakingParams(ctx context.Context) (map[uint32]*StakingParams, *types.Error)
GetLatestBlockNumber(ctx context.Context) (int64, *types.Error)
GetBlockResults(
ctx context.Context, blockHeight int64,
Expand Down
5 changes: 5 additions & 0 deletions internal/services/global-params.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ func (s *Service) fetchAndSaveParams(ctx context.Context) *types.Error {
)
}
for version, params := range allStakingParams {
if params == nil {
return types.NewInternalServiceError(
fmt.Errorf("nil staking params for version %d", version),
)
}
if err := s.db.SaveGlobalParams(ctx, &model.GolablParamDocument{
Type: STAKING_PARAMS_TYPE,
Version: version,
Expand Down
8 changes: 4 additions & 4 deletions internal/services/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ func (s *Service) StartIndexerSync(ctx context.Context) {
// Sync global parameters
s.SyncGlobalParams(ctx)
// Start the bootstrap process
// s.BootstrapBbn(ctx)
// // Start the websocket event subscription process
// s.SubscribeToBbnEvents(ctx)
// // Keep processing events in the main thread
s.BootstrapBbn(ctx)
// Start the websocket event subscription process
s.SubscribeToBbnEvents(ctx)
// Keep processing events in the main thread
s.StartBbnEventProcessor(ctx)
}
1 change: 1 addition & 0 deletions internal/types/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const (
Forbidden ErrorCode = "FORBIDDEN"
UnprocessableEntity ErrorCode = "UNPROCESSABLE_ENTITY"
RequestTimeout ErrorCode = "REQUEST_TIMEOUT"
ClientRequestError ErrorCode = "CLIENT_REQUEST_ERROR"
)

// ApiError represents an error with an HTTP status code and an application-specific error code.
Expand Down

0 comments on commit 0bc195b

Please sign in to comment.