Skip to content

Commit

Permalink
fix: reuse SetAddressPrefixes and clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
ivivanov authored and Lockwarr committed Dec 22, 2023
1 parent 8eec3c6 commit b876375
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 41 deletions.
22 changes: 1 addition & 21 deletions app/params/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ package params

import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/address"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
)

const (
Expand Down Expand Up @@ -53,23 +51,5 @@ func SetAddressPrefixes() {
config.SetBech32PrefixForAccount(Bech32PrefixAccAddr, Bech32PrefixAccPub)
config.SetBech32PrefixForValidator(Bech32PrefixValAddr, Bech32PrefixValPub)
config.SetBech32PrefixForConsensusNode(Bech32PrefixConsAddr, Bech32PrefixConsPub)

// This is copied from the cosmos sdk v0.43.0-beta1
// source: https://github.com/cosmos/cosmos-sdk/blob/v0.43.0-beta1/types/address.go#L141
config.SetAddressVerifier(func(bytes []byte) error {
if len(bytes) == 0 {
return sdkerrors.Wrap(sdkerrors.ErrUnknownAddress, "addresses cannot be empty")
}

if len(bytes) > address.MaxAddrLen {
return sdkerrors.Wrapf(sdkerrors.ErrUnknownAddress, "address max length is %d, got %d", address.MaxAddrLen, len(bytes))
}

// TODO: Do we want to allow addresses of lengths other than 20 and 32 bytes?
if len(bytes) != 20 && len(bytes) != 32 {
return sdkerrors.Wrapf(sdkerrors.ErrUnknownAddress, "address length must be 20 or 32 bytes, got %d", len(bytes))
}

return nil
})
config.Seal()
}
19 changes: 0 additions & 19 deletions cmd/nolusd/prefix.go

This file was deleted.

3 changes: 2 additions & 1 deletion cmd/nolusd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import (
"github.com/spf13/pflag"

"github.com/Nolus-Protocol/nolus-core/app"
"github.com/Nolus-Protocol/nolus-core/app/params"
)

type (
Expand Down Expand Up @@ -132,7 +133,7 @@ func NewRootCmd(
rootOptions := newRootOptions(options...)

// Set config for prefixes
SetPrefixes(accountAddressPrefix)
params.SetAddressPrefixes()

encodingConfig := app.MakeEncodingConfig(moduleBasics)
initClientCtx := client.Context{}.
Expand Down

0 comments on commit b876375

Please sign in to comment.