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

chore(types): deprecate acc address stringer (backport #21435) #21438

Merged
merged 2 commits into from
Aug 28, 2024
Merged
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ Every module contains its own CHANGELOG.md. Please refer to the module you are i

* (client) [#21436](https://github.com/cosmos/cosmos-sdk/pull/21436) Use `address.Codec` from client.Context in `tx.Sign`.

### Deprecated

* (types) [#21435](https://github.com/cosmos/cosmos-sdk/pull/21435) The `String()` method on `AccAddress`, `ValAddress` and `ConsAddress` have been deprecated. This is done because those are still using the deprecated global `sdk.Config`. Use an `address.Codec` instead.

## [v0.52.0](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.52.0) - 2024-XX-XX

Every module contains its own CHANGELOG.md. Please refer to the module you are interested in.
Expand Down
5 changes: 1 addition & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ include scripts/build/build.mk

.DEFAULT_GOAL := help

###############################################################################
### Tools & Dependencies ###
###############################################################################

#? go.sum: Run go mod tidy and ensure dependencies have not been modified
go.sum: go.mod
echo "Ensure dependencies have not been modified ..." >&2
go mod verify
Expand Down
9 changes: 9 additions & 0 deletions types/address.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ type Address interface {
Marshal() ([]byte, error)
MarshalJSON() ([]byte, error)
Bytes() []byte
// Deprecated: Use an address.Codec to convert addresses from and to string/bytes.
String() string
Format(s fmt.State, verb rune)
}
Expand Down Expand Up @@ -179,6 +180,7 @@ func AccAddressFromHexUnsafe(address string) (addr AccAddress, err error) {
}

// MustAccAddressFromBech32 calls AccAddressFromBech32 and panics on error.
// Deprecated: Use an address.Codec to convert addresses from and to string/bytes.
func MustAccAddressFromBech32(address string) AccAddress {
addr, err := AccAddressFromBech32(address)
if err != nil {
Expand All @@ -189,6 +191,7 @@ func MustAccAddressFromBech32(address string) AccAddress {
}

// AccAddressFromBech32 creates an AccAddress from a Bech32 string.
// Deprecated: Use an address.Codec to convert addresses from and to string/bytes.
func AccAddressFromBech32(address string) (addr AccAddress, err error) {
bech32PrefixAccAddr := GetConfig().GetBech32AccountAddrPrefix()

Expand Down Expand Up @@ -281,6 +284,7 @@ func (aa AccAddress) Bytes() []byte {
}

// String implements the Stringer interface.
// Deprecated: Use an address.Codec to convert addresses from and to string/bytes.
func (aa AccAddress) String() string {
if aa.Empty() {
return ""
Expand Down Expand Up @@ -328,6 +332,7 @@ func ValAddressFromHex(address string) (addr ValAddress, err error) {
}

// ValAddressFromBech32 creates a ValAddress from a Bech32 string.
// Deprecated: Use an address.Codec to convert addresses from and to string/bytes.
func ValAddressFromBech32(address string) (addr ValAddress, err error) {
bech32PrefixValAddr := GetConfig().GetBech32ValidatorAddrPrefix()

Expand All @@ -336,6 +341,7 @@ func ValAddressFromBech32(address string) (addr ValAddress, err error) {
}

// MustValAddressFromBech32 calls ValAddressFromBech32 and panics on error.
// Deprecated: Use an address.Codec to convert addresses from and to string/bytes.
func MustValAddressFromBech32(address string) ValAddress {
addr, err := ValAddressFromBech32(address)
if err != nil {
Expand Down Expand Up @@ -432,6 +438,7 @@ func (va ValAddress) Bytes() []byte {
}

// String implements the Stringer interface.
// Deprecated: Use an address.Codec to convert addresses from and to string/bytes.
func (va ValAddress) String() string {
if va.Empty() {
return ""
Expand Down Expand Up @@ -480,6 +487,7 @@ func ConsAddressFromHex(address string) (addr ConsAddress, err error) {
}

// ConsAddressFromBech32 creates a ConsAddress from a Bech32 string.
// Deprecated: Use an address.Codec to convert addresses from and to string/bytes.
func ConsAddressFromBech32(address string) (addr ConsAddress, err error) {
bech32PrefixConsAddr := GetConfig().GetBech32ConsensusAddrPrefix()

Expand Down Expand Up @@ -579,6 +587,7 @@ func (ca ConsAddress) Bytes() []byte {
}

// String implements the Stringer interface.
// Deprecated: Use an address.Codec to convert addresses from and to string/bytes.
func (ca ConsAddress) String() string {
if ca.Empty() {
return ""
Expand Down
17 changes: 9 additions & 8 deletions types/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,16 @@ import (
// DefaultKeyringServiceName defines a default service name for the keyring.
const DefaultKeyringServiceName = "cosmos"

func KeyringServiceName() string {
if len(version.Name) == 0 {
return DefaultKeyringServiceName
}
return version.Name
}

// Config is the structure that holds the SDK configuration parameters.
// This could be used to initialize certain configuration parameters for the SDK.
// Deprecated: The global SDK config is deprecated and users should prefer using an address codec.
// Users must still set the global config until the Stringer interface on `AccAddress`, `ValAddress`, and `ConsAddress` is removed.
type Config struct {
bech32AddressPrefix map[string]string
mtx sync.RWMutex
Expand Down Expand Up @@ -140,10 +148,3 @@ func (config *Config) GetBech32ValidatorPubPrefix() string {
func (config *Config) GetBech32ConsensusPubPrefix() string {
return config.bech32AddressPrefix["consensus_pub"]
}

func KeyringServiceName() string {
if len(version.Name) == 0 {
return DefaultKeyringServiceName
}
return version.Name
}
Loading