Skip to content

Commit

Permalink
fix: fail commission query if it is not supported
Browse files Browse the repository at this point in the history
  • Loading branch information
freak12techno committed Dec 10, 2023
1 parent 8b1c843 commit 35be6fd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
17 changes: 5 additions & 12 deletions pkg/tendermint/tendermint.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import (
"main/pkg/types"
"main/pkg/utils"

cosmosTypes "github.com/cosmos/cosmos-sdk/types"
distributionTypes "github.com/cosmos/cosmos-sdk/x/distribution/types"
"github.com/rs/zerolog"
)

Expand Down Expand Up @@ -126,10 +124,8 @@ func (rpc *RPC) GetSingleDelegation(validator, wallet string) (*types.Amount, *t
return &types.Amount{}, &info, fmt.Errorf("expected code 0, but got %d", response.Code)
}

return &types.Amount{
Amount: utils.StrToFloat64(response.DelegationResponse.Balance.Amount),
Denom: response.DelegationResponse.Balance.Denom,
}, &info, nil
amount := response.DelegationResponse.Balance.ToAmount()
return &amount, &info, nil
}

func (rpc *RPC) GetAllValidators() (*types.ValidatorsResponse, *types.QueryInfo, error) {
Expand Down Expand Up @@ -164,17 +160,14 @@ func (rpc *RPC) GetValidatorCommission(address string) ([]types.Amount, *types.Q
address,
)

var response *distributionTypes.QueryValidatorCommissionResponse
var response *types.CommissionResponse
info, err := rpc.Client.Get(url, &response)
if err != nil {
return []types.Amount{}, &info, err
}

return utils.Map(response.Commission.Commission, func(balance cosmosTypes.DecCoin) types.Amount {
return types.Amount{
Amount: balance.Amount.MustFloat64(),
Denom: balance.Denom,
}
return utils.Map(response.Commission.Commission, func(amount types.ResponseAmount) types.Amount {
return amount.ToAmount()
}), &info, nil
}

Expand Down
7 changes: 7 additions & 0 deletions pkg/types/tendermint.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,3 +172,10 @@ type RewardsResponse struct {
Code int `json:"code"`
Rewards []ResponseAmount `json:"rewards"`
}

type CommissionResponse struct {
Code int `json:"code"`
Commission struct {
Commission []ResponseAmount `json:"commission"`
} `json:"commission"`
}

0 comments on commit 35be6fd

Please sign in to comment.