Skip to content

Commit

Permalink
chore(types): audit (#17075)
Browse files Browse the repository at this point in the history
  • Loading branch information
julienrbrt authored Jul 20, 2023
1 parent 3ad0ca5 commit e3482f2
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 15 deletions.
2 changes: 1 addition & 1 deletion types/dec_coin.go
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ func (coins DecCoins) Equal(coinsB DecCoins) bool {
coinsB = coinsB.Sort()

for i := 0; i < len(coins); i++ {
if !coins[i].IsEqual(coinsB[i]) {
if !coins[i].Equal(coinsB[i]) {
return false
}
}
Expand Down
2 changes: 2 additions & 0 deletions types/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ func ChainPostDecorators(chain ...PostDecorator) PostHandler {
// \ '\ / \ | | _/ /
// \ \ \ | | / /
// snd \ \ \ /
//
// Deprecated: Terminator is retired (ref https://github.com/cosmos/cosmos-sdk/pull/16076).
type Terminator struct{}

// AnteHandle returns the provided Context and nil error
Expand Down
1 change: 0 additions & 1 deletion types/module/genesis.go

This file was deleted.

13 changes: 9 additions & 4 deletions types/tx/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,15 @@ func (t *Tx) FeePayer(cdc codec.Codec) []byte {
return signers[0]
}

func (t *Tx) FeeGranter() sdk.AccAddress {
feePayer := t.AuthInfo.Fee.Granter
if feePayer != "" {
return sdk.MustAccAddressFromBech32(feePayer)
func (t *Tx) FeeGranter(cdc codec.Codec) []byte {
feeGranter := t.AuthInfo.Fee.Granter
if feeGranter != "" {
feeGranterAddr, err := cdc.InterfaceRegistry().SigningContext().AddressCodec().StringToBytes(feeGranter)
if err != nil {
panic(err)
}

return feeGranterAddr
}
return nil
}
Expand Down
6 changes: 1 addition & 5 deletions x/auth/tx/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,11 +211,7 @@ func (w *wrapper) FeePayer() []byte {
}

func (w *wrapper) FeeGranter() []byte {
feeGranter := w.tx.AuthInfo.Fee.Granter
if feeGranter != "" {
return sdk.MustAccAddressFromBech32(feeGranter)
}
return nil
return w.tx.FeeGranter(w.cdc)
}

func (w *wrapper) GetTip() *tx.Tip {
Expand Down
2 changes: 1 addition & 1 deletion x/auth/tx/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ func TestBuilderFeeGranter(t *testing.T) {
feeAmount := testdata.NewTestFeeAmount()
msgs := []sdk.Msg{msg1}

txBuilder := newBuilder(nil)
txBuilder := newBuilder(testutil.CodecOptions{}.NewCodec())
err := txBuilder.SetMsgs(msgs...)
require.NoError(t, err)
txBuilder.SetGasLimit(200000)
Expand Down
12 changes: 10 additions & 2 deletions x/bank/simulation/operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,11 @@ func sendMsgMultiSend(
accountNumbers := make([]uint64, len(msg.Inputs))
sequenceNumbers := make([]uint64, len(msg.Inputs))
for i := 0; i < len(msg.Inputs); i++ {
addr := sdk.MustAccAddressFromBech32(msg.Inputs[i].Address)
addr, err := ak.AddressCodec().StringToBytes(msg.Inputs[i].Address)
if err != nil {
panic(err)
}

acc := ak.GetAccount(ctx, addr)
accountNumbers[i] = acc.GetAccountNumber()
sequenceNumbers[i] = acc.GetSequence()
Expand All @@ -357,7 +361,11 @@ func sendMsgMultiSend(
fees sdk.Coins
err error
)
addr := sdk.MustAccAddressFromBech32(msg.Inputs[0].Address)

addr, err := ak.AddressCodec().StringToBytes(msg.Inputs[0].Address)
if err != nil {
panic(err)
}
// feePayer is the first signer, i.e. first input address
feePayer := ak.GetAccount(ctx, addr)
spendable := bk.SpendableCoins(ctx, feePayer.GetAddress())
Expand Down
7 changes: 6 additions & 1 deletion x/group/migrations/v2/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,13 @@ func Migrate(
}

for _, policy := range groupPolicies {
addr, err := accountKeeper.AddressCodec().StringToBytes(policy.Address)
if err != nil {
return fmt.Errorf("failed to convert group policy account address: %w", err)
}

// get the account address by acc id
oldAcc := accountKeeper.GetAccount(ctx, sdk.MustAccAddressFromBech32(policy.Address))
oldAcc := accountKeeper.GetAccount(ctx, addr)
// remove the old account
accountKeeper.RemoveAccount(ctx, oldAcc)

Expand Down

0 comments on commit e3482f2

Please sign in to comment.