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!: Rename AccAddressFromHex #11888

Merged
merged 9 commits into from
May 6, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ Ref: https://keepachangelog.com/en/1.0.0/

### API Breaking Changes

* (types ) [#11881](https://github.com/cosmos/cosmos-sdk/issues/11881) Rename `AccAddressFromHex` to `AccAddressFromHexUnsafe`.
* (types) [#11788](https://github.com/cosmos/cosmos-sdk/pull/11788) The `Int` and `Uint` types have been moved to their own dedicated module, `math`. Aliases are kept in the SDK's root `types` package, however, it is encouraged to utilize the new `math` module. As a result, the `Int#ToDec` API has been removed.
* (grpc) [\#11642](https://github.com/cosmos/cosmos-sdk/pull/11642) The `RegisterTendermintService` method in the `tmservice` package now requires a `abciQueryFn` query function parameter.
* [\#11496](https://github.com/cosmos/cosmos-sdk/pull/11496) Refactor abstractions for snapshot and pruning; snapshot intervals eventually pruned; unit tests.
Expand Down
4 changes: 2 additions & 2 deletions simapp/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ func createIncrementalAccounts(accNum int) []sdk.AccAddress {
buffer.WriteString("A58856F0FD53BF058B4909A21AEC019107BA6") // base address string

buffer.WriteString(numString) // adding on final two digits to make addresses unique
res, _ := sdk.AccAddressFromHex(buffer.String())
res, _ := sdk.AccAddressFromHexUnsafe(buffer.String())
bech := res.String()
addr, _ := TestAddr(buffer.String(), bech)

Expand Down Expand Up @@ -377,7 +377,7 @@ func ConvertAddrsToValAddrs(addrs []sdk.AccAddress) []sdk.ValAddress {
}

func TestAddr(addr string, bech string) (sdk.AccAddress, error) {
res, err := sdk.AccAddressFromHex(addr)
res, err := sdk.AccAddressFromHexUnsafe(addr)
if err != nil {
return nil, err
}
Expand Down
8 changes: 6 additions & 2 deletions types/address.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,12 @@ var _ Address = ConsAddress{}
// When marshaled to a string or JSON, it uses Bech32.
type AccAddress []byte

// AccAddressFromHex creates an AccAddress from a hex string.
func AccAddressFromHex(address string) (addr AccAddress, err error) {
// AccAddressFromHexUnsafe creates an AccAddress from a HEX-encoded string.
//
// Note, this function is considered unsafe as it may produce an AccAddress from
// otherwise invalid input, such as a transaction hash. Please use
// AccAddressFromBech32.
func AccAddressFromHexUnsafe(address string) (addr AccAddress, err error) {
bz, err := addressBytesFromHexString(address)
alexanderbez marked this conversation as resolved.
Show resolved Hide resolved
return AccAddress(bz), err
}
Expand Down
6 changes: 3 additions & 3 deletions types/address_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,13 @@ func (s *addressTestSuite) TestRandBech32AccAddrConsistency() {
s.Require().Equal(acc, res)

str = hex.EncodeToString(acc)
res, err = types.AccAddressFromHex(str)
res, err = types.AccAddressFromHexUnsafe(str)
s.Require().Nil(err)
s.Require().Equal(acc, res)
}

for _, str := range invalidStrs {
_, err := types.AccAddressFromHex(str)
_, err := types.AccAddressFromHexUnsafe(str)
s.Require().NotNil(err)

_, err = types.AccAddressFromBech32(str)
Expand All @@ -121,7 +121,7 @@ func (s *addressTestSuite) TestRandBech32AccAddrConsistency() {
s.Require().NotNil(err)
}

_, err := types.AccAddressFromHex("")
_, err := types.AccAddressFromHexUnsafe("")
s.Require().Equal("decoding Bech32 address failed: must provide an address", err.Error())
}

Expand Down
2 changes: 1 addition & 1 deletion x/auth/client/cli/tx_multisign.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ func makeMultiSignCmd() func(cmd *cobra.Command, args []string) (err error) {

err = signing.VerifySignature(sig.PubKey, signingData, sig.Data, txCfg.SignModeHandler(), txBuilder.GetTx())
if err != nil {
addr, _ := sdk.AccAddressFromHex(sig.PubKey.Address().String())
addr, _ := sdk.AccAddressFromHexUnsafe(sig.PubKey.Address().String())
return fmt.Errorf("couldn't verify signature for address %s", addr)
}

Expand Down