Skip to content

Commit

Permalink
refactor: use address.Codec to replace deprecated function
Browse files Browse the repository at this point in the history
  • Loading branch information
1ch0 committed Dec 24, 2024
1 parent f29db43 commit 51760a0
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions modules/light-clients/08-wasm/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import (
"encoding/hex"
"fmt"
"os"
"sync"

"github.com/hashicorp/golang-lru/simplelru"
"github.com/spf13/cobra"

govcli "cosmossdk.io/x/gov/client/cli"
Expand All @@ -13,6 +15,7 @@ import (
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/client/tx"
addresscodec "github.com/cosmos/cosmos-sdk/codec/address"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/address"
"github.com/cosmos/cosmos-sdk/version"
Expand Down Expand Up @@ -42,13 +45,29 @@ func newSubmitStoreCodeProposalCmd() *cobra.Command {
return err
}

bech32PrefixAccAddr := sdk.GetConfig().GetBech32AccountAddrPrefix()
lru, err := simplelru.NewLRU(60000, nil)
if err != nil {
panic(err)
}
addrCdc, err := addresscodec.NewCachedBech32Codec(
bech32PrefixAccAddr,
addresscodec.CachedCodecOptions{
Mu: &sync.Mutex{},
Lru: lru})
if err != nil {
panic(err)
}
authority, _ := cmd.Flags().GetString(FlagAuthority)
if authority != "" {
if _, err = sdk.AccAddressFromBech32(authority); err != nil {
if _, err = addrCdc.StringToBytes(authority); err != nil {
return fmt.Errorf("invalid authority address: %w", err)
}
} else {
authority = sdk.AccAddress(address.Module(govtypes.ModuleName)).String()
authority, err = addrCdc.BytesToString(address.Module(govtypes.ModuleName))
if err != nil {
return fmt.Errorf("invalid authority address: %w", err)
}
}

code, err := os.ReadFile(args[0])
Expand Down

0 comments on commit 51760a0

Please sign in to comment.