Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: use address.Codec to replace deprecated function #7797

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
2 changes: 1 addition & 1 deletion modules/light-clients/08-wasm/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ require (
github.com/cosmos/ibc-go/v9 v9.0.0
github.com/golang/protobuf v1.5.4
github.com/grpc-ecosystem/grpc-gateway v1.16.0
github.com/hashicorp/golang-lru v1.0.2
github.com/spf13/cast v1.7.1
github.com/spf13/cobra v1.8.1
github.com/spf13/viper v1.19.0
Expand Down Expand Up @@ -143,7 +144,6 @@ require (
github.com/hashicorp/go-plugin v1.6.2 // indirect
github.com/hashicorp/go-safetemp v1.0.0 // indirect
github.com/hashicorp/go-version v1.7.0 // indirect
github.com/hashicorp/golang-lru v1.0.2 // indirect
github.com/hashicorp/golang-lru/v2 v2.0.7 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/hashicorp/yamux v0.1.2 // indirect
Expand Down