Skip to content

Commit

Permalink
refactor(x/auth): rm dependency on x/staking (cosmos#16545)
Browse files Browse the repository at this point in the history
  • Loading branch information
kocubinski authored Jun 15, 2023
1 parent 5a612ef commit fe458e0
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 12 deletions.
File renamed without changes.
35 changes: 23 additions & 12 deletions x/auth/migrations/v2/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,22 @@ package v2
import (
"errors"
"fmt"
"strconv"

stakingv1beta1 "cosmossdk.io/api/cosmos/staking/v1beta1"
abci "github.com/cometbft/cometbft/abci/types"
"github.com/cosmos/gogoproto/grpc"
"github.com/cosmos/gogoproto/proto"
gogoproto "github.com/cosmos/gogoproto/proto"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"google.golang.org/protobuf/proto"

"github.com/cosmos/cosmos-sdk/baseapp"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/x/auth/vesting/exported"
vestingtypes "github.com/cosmos/cosmos-sdk/x/auth/vesting/types"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
)

const (
Expand Down Expand Up @@ -135,7 +137,7 @@ func getDelegatorDelegationsSum(ctx sdk.Context, address string, queryServer grp

queryFn := querier.Route(delegatorDelegationPath)

q := &stakingtypes.QueryDelegatorDelegationsRequest{
q := &stakingv1beta1.QueryDelegatorDelegationsRequest{
DelegatorAddr: address,
}

Expand All @@ -156,14 +158,19 @@ func getDelegatorDelegationsSum(ctx sdk.Context, address string, queryServer grp
return nil, fmt.Errorf("staking query error, %w", err)
}

balance := new(stakingtypes.QueryDelegatorDelegationsResponse)
balance := new(stakingv1beta1.QueryDelegatorDelegationsResponse)
if err := proto.Unmarshal(resp.Value, balance); err != nil {
return nil, fmt.Errorf("unable to unmarshal delegator query delegations: %w", err)
}

res := sdk.NewCoins()
for _, i := range balance.DelegationResponses {
res = res.Add(i.Balance)
bal, err := strconv.Atoi(i.Balance.Amount)
if err != nil {
return nil, fmt.Errorf("cannot convert balance amount to int, %w", err)
}
coin := sdk.NewCoin(i.Balance.Denom, sdk.NewInt(int64(bal)))
res = res.Add(coin)
}

return res, nil
Expand All @@ -179,7 +186,7 @@ func getDelegatorUnbondingDelegationsSum(ctx sdk.Context, address, bondDenom str

queryFn := querier.Route(delegatorUnbondingDelegationsPath)

q := &stakingtypes.QueryDelegatorUnbondingDelegationsRequest{
q := &stakingv1beta1.QueryDelegatorUnbondingDelegationsRequest{
DelegatorAddr: address,
}

Expand All @@ -200,15 +207,19 @@ func getDelegatorUnbondingDelegationsSum(ctx sdk.Context, address, bondDenom str
return nil, fmt.Errorf("staking query error, %w", err)
}

balance := new(stakingtypes.QueryDelegatorUnbondingDelegationsResponse)
balance := new(stakingv1beta1.QueryDelegatorUnbondingDelegationsResponse)
if err := proto.Unmarshal(resp.Value, balance); err != nil {
return nil, fmt.Errorf("unable to unmarshal delegator query delegations: %w", err)
}

res := sdk.NewCoins()
for _, i := range balance.UnbondingResponses {
for _, r := range i.Entries {
res = res.Add(sdk.NewCoin(bondDenom, r.Balance))
bal, err := strconv.Atoi(r.Balance)
if err != nil {
return nil, fmt.Errorf("unable to convert unbonding balance to int: %w", err)
}
res = res.Add(sdk.NewCoin(bondDenom, sdk.NewInt(int64(bal))))
}
}

Expand All @@ -229,7 +240,7 @@ func getBalance(ctx sdk.Context, address string, queryServer grpc.Server) (sdk.C
Address: address,
Pagination: nil,
}
b, err := proto.Marshal(q)
b, err := gogoproto.Marshal(q)
if err != nil {
return nil, fmt.Errorf("cannot marshal bank type query request, %w", err)
}
Expand All @@ -243,7 +254,7 @@ func getBalance(ctx sdk.Context, address string, queryServer grpc.Server) (sdk.C
return nil, fmt.Errorf("bank query error, %w", err)
}
balance := new(banktypes.QueryAllBalancesResponse)
if err := proto.Unmarshal(resp.Value, balance); err != nil {
if err := gogoproto.Unmarshal(resp.Value, balance); err != nil {
return nil, fmt.Errorf("unable to unmarshal bank balance response: %w", err)
}
return balance.Balances, nil
Expand All @@ -259,7 +270,7 @@ func getBondDenom(ctx sdk.Context, queryServer grpc.Server) (string, error) {

queryFn := querier.Route(stakingParamsPath)

q := &stakingtypes.QueryParamsRequest{}
q := &stakingv1beta1.QueryParamsRequest{}

b, err := proto.Marshal(q)
if err != nil {
Expand All @@ -275,7 +286,7 @@ func getBondDenom(ctx sdk.Context, queryServer grpc.Server) (string, error) {
return "", fmt.Errorf("staking query error, %w", err)
}

params := new(stakingtypes.QueryParamsResponse)
params := new(stakingv1beta1.QueryParamsResponse)
if err := proto.Unmarshal(resp.Value, params); err != nil {
return "", fmt.Errorf("unable to unmarshal delegator query delegations: %w", err)
}
Expand Down
1 change: 1 addition & 0 deletions x/staking/keeper/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"time"

abci "github.com/cometbft/cometbft/abci/types"

"github.com/cosmos/cosmos-sdk/telemetry"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/staking/types"
Expand Down

0 comments on commit fe458e0

Please sign in to comment.