From 79de805aa05e2e965968c6a728c7163770045fd4 Mon Sep 17 00:00:00 2001 From: Sergey <83376337+freak12techno@users.noreply.github.com> Date: Tue, 14 May 2024 23:39:58 +0300 Subject: [PATCH] fix: fixed checking responses (#51) --- pkg/fetchers/staking_params.go | 2 +- pkg/fetchers/validators.go | 2 +- pkg/tendermint/tendermint.go | 15 +++++++++++++++ pkg/types/tendermint.go | 2 ++ 4 files changed, 19 insertions(+), 2 deletions(-) diff --git a/pkg/fetchers/staking_params.go b/pkg/fetchers/staking_params.go index 1f15f68..358d657 100644 --- a/pkg/fetchers/staking_params.go +++ b/pkg/fetchers/staking_params.go @@ -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 } diff --git a/pkg/fetchers/validators.go b/pkg/fetchers/validators.go index ad558d6..c98ac4a 100644 --- a/pkg/fetchers/validators.go +++ b/pkg/fetchers/validators.go @@ -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, diff --git a/pkg/tendermint/tendermint.go b/pkg/tendermint/tendermint.go index 5e1651e..8fbd396 100644 --- a/pkg/tendermint/tendermint.go +++ b/pkg/tendermint/tendermint.go @@ -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 @@ -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 @@ -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 } diff --git a/pkg/types/tendermint.go b/pkg/types/tendermint.go index 2b5f3f4..a9414ab 100644 --- a/pkg/types/tendermint.go +++ b/pkg/types/tendermint.go @@ -92,6 +92,7 @@ type ValidatorsResponse struct { } type BalancesResponse struct { + Code int `json:"code"` Balances []ResponseAmount `json:"balances"` } @@ -120,6 +121,7 @@ type SigningInfoResponse struct { } type SlashingParamsResponse struct { + Code int `json:"code"` SlashingParams struct { SignedBlocksWindow string `json:"signed_blocks_window"` } `json:"params"`