Skip to content

Commit

Permalink
fix: fixed checking responses (#51)
Browse files Browse the repository at this point in the history
  • Loading branch information
freak12techno authored May 14, 2024
1 parent 47d1fc8 commit 79de805
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pkg/fetchers/staking_params.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func (q *StakingParamsFetcher) Fetch(
q.Logger.Error().
Err(err).
Str("chain", chain.Name).
Msg("Error querying slashing params")
Msg("Error querying staking params")
return
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/fetchers/validators.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func NewValidatorsFetcher(
tracer trace.Tracer,
) *ValidatorsFetcher {
return &ValidatorsFetcher{
Logger: logger.With().Str("component", "commission_fetcher").Logger(),
Logger: logger.With().Str("component", "validators_fetcher").Logger(),
Config: config,
RPCs: rpcs,
Tracer: tracer,
Expand Down
15 changes: 15 additions & 0 deletions pkg/tendermint/tendermint.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,11 @@ func (rpc *RPC) GetValidatorCommission(
return []types.Amount{}, &info, err
}

if response.Code != 0 {
info.Success = false
return []types.Amount{}, &info, fmt.Errorf("expected code 0, but got %d", response.Code)
}

return utils.Map(response.Commission.Commission, func(amount types.ResponseAmount) types.Amount {
return amount.ToAmount()
}), &info, nil
Expand Down Expand Up @@ -286,6 +291,11 @@ func (rpc *RPC) GetWalletBalance(
return []types.Amount{}, &info, err
}

if response.Code != 0 {
info.Success = false
return nil, &info, fmt.Errorf("expected code 0, but got %d", response.Code)
}

return utils.Map(response.Balances, func(amount types.ResponseAmount) types.Amount {
return amount.ToAmount()
}), &info, nil
Expand Down Expand Up @@ -343,6 +353,11 @@ func (rpc *RPC) GetSlashingParams(
return nil, &info, err
}

if response.Code != 0 {
info.Success = false
return nil, &info, fmt.Errorf("expected code 0, but got %d", response.Code)
}

return response, &info, nil
}

Expand Down
2 changes: 2 additions & 0 deletions pkg/types/tendermint.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ type ValidatorsResponse struct {
}

type BalancesResponse struct {
Code int `json:"code"`
Balances []ResponseAmount `json:"balances"`
}

Expand Down Expand Up @@ -120,6 +121,7 @@ type SigningInfoResponse struct {
}

type SlashingParamsResponse struct {
Code int `json:"code"`
SlashingParams struct {
SignedBlocksWindow string `json:"signed_blocks_window"`
} `json:"params"`
Expand Down

0 comments on commit 79de805

Please sign in to comment.