diff --git a/client/lcd/lcd_test.go b/client/lcd/lcd_test.go index ad32fa6a2..b5800ca29 100644 --- a/client/lcd/lcd_test.go +++ b/client/lcd/lcd_test.go @@ -61,7 +61,7 @@ func TestKeys(t *testing.T) { require.Nil(t, err, body) addr2Bech32 := resp.Address.String() - _, err = sdk.GetAccAddressBech32(addr2Bech32) + _, err = sdk.AccAddressFromBech32(addr2Bech32) require.NoError(t, err, "Failed to return a correct bech32 address") // existing keys diff --git a/cmd/gaia/cmd/gaiadebug/main.go b/cmd/gaia/cmd/gaiadebug/main.go index f56a757a8..bff79870b 100644 --- a/cmd/gaia/cmd/gaiadebug/main.go +++ b/cmd/gaia/cmd/gaiadebug/main.go @@ -158,10 +158,10 @@ func runAddrCmd(cmd *cobra.Command, args []string) error { addr, err = hex.DecodeString(addrString) if err != nil { var err2 error - addr, err2 = sdk.GetAccAddressBech32(addrString) + addr, err2 = sdk.AccAddressFromBech32(addrString) if err2 != nil { var err3 error - addr, err3 = sdk.GetValAddressBech32(addrString) + addr, err3 = sdk.ValAddressFromBech32(addrString) if err3 != nil { return fmt.Errorf(`Expected hex or bech32. Got errors: diff --git a/types/account.go b/types/account.go index 4cfc7e9d4..daa3b614e 100644 --- a/types/account.go +++ b/types/account.go @@ -2,6 +2,7 @@ package types import ( "encoding/hex" + "encoding/json" "errors" "fmt" @@ -23,11 +24,12 @@ const ( //__________________________________________________________ -// AccAddress is a go crypto-style Address +// AccAddress a wrapper around bytes meant to represent an account address +// When marshaled to a string or json, it uses bech32 type AccAddress []byte -// create an Address from a hex string -func GetAccAddressHex(address string) (addr AccAddress, err error) { +// create an AccAddress from a hex string +func AccAddressFromHex(address string) (addr AccAddress, err error) { if len(address) == 0 { return addr, errors.New("decoding bech32 address failed: must provide an address") } @@ -38,8 +40,8 @@ func GetAccAddressHex(address string) (addr AccAddress, err error) { return AccAddress(bz), nil } -// create an Address from a bech32 string -func GetAccAddressBech32(address string) (addr AccAddress, err error) { +// create an AccAddress from a bech32 string +func AccAddressFromBech32(address string) (addr AccAddress, err error) { bz, err := GetFromBech32(address, Bech32PrefixAccAddr) if err != nil { return nil, err @@ -60,21 +62,18 @@ func (bz *AccAddress) Unmarshal(data []byte) error { // Marshals to JSON using Bech32 func (bz AccAddress) MarshalJSON() ([]byte, error) { - s := bz.String() - jbz := make([]byte, len(s)+2) - jbz[0] = '"' - copy(jbz[1:], []byte(s)) - jbz[len(jbz)-1] = '"' - return jbz, nil + return json.Marshal(bz.String()) } // Unmarshals from JSON assuming Bech32 encoding func (bz *AccAddress) UnmarshalJSON(data []byte) error { - if len(data) < 2 || data[0] != '"' || data[len(data)-1] != '"' { - return fmt.Errorf("Invalid bech32 string: %s", data) + var s string + err := json.Unmarshal(data, &s) + if err != nil { + return nil } - bz2, err := GetAccAddressBech32(string(data[1 : len(data)-1])) + bz2, err := AccAddressFromBech32(s) if err != nil { return err } @@ -109,11 +108,12 @@ func (bz AccAddress) Format(s fmt.State, verb rune) { //__________________________________________________________ -// Address is a go crypto-style Address +// AccAddress a wrapper around bytes meant to represent a validator address +// (from over ABCI). When marshaled to a string or json, it uses bech32 type ValAddress []byte // create a ValAddress from a hex string -func GetValAddressHex(address string) (addr ValAddress, err error) { +func ValAddressFromHex(address string) (addr ValAddress, err error) { if len(address) == 0 { return addr, errors.New("decoding bech32 address failed: must provide an address") } @@ -125,7 +125,7 @@ func GetValAddressHex(address string) (addr ValAddress, err error) { } // create a ValAddress from a bech32 string -func GetValAddressBech32(address string) (addr ValAddress, err error) { +func ValAddressFromBech32(address string) (addr ValAddress, err error) { bz, err := GetFromBech32(address, Bech32PrefixValAddr) if err != nil { return nil, err @@ -146,21 +146,18 @@ func (bz *ValAddress) Unmarshal(data []byte) error { // Marshals to JSON using Bech32 func (bz ValAddress) MarshalJSON() ([]byte, error) { - s := bz.String() - jbz := make([]byte, len(s)+2) - jbz[0] = '"' - copy(jbz[1:], []byte(s)) - jbz[len(jbz)-1] = '"' - return jbz, nil + return json.Marshal(bz.String()) } // Unmarshals from JSON assuming Bech32 encoding func (bz *ValAddress) UnmarshalJSON(data []byte) error { - if len(data) < 2 || data[0] != '"' || data[len(data)-1] != '"' { - return fmt.Errorf("Invalid bech32 string: %s", data) + var s string + err := json.Unmarshal(data, &s) + if err != nil { + return nil } - bz2, err := GetValAddressBech32(string(data[1 : len(data)-1])) + bz2, err := ValAddressFromBech32(s) if err != nil { return err } @@ -212,7 +209,7 @@ func Bech32ifyValPub(pub crypto.PubKey) (string, error) { return bech32.ConvertAndEncode(Bech32PrefixValPub, pub.Bytes()) } -// MustBech32ifyValPub pancis on bech32-encoding failure +// MustBech32ifyValPub panics on bech32-encoding failure func MustBech32ifyValPub(pub crypto.PubKey) string { enc, err := Bech32ifyValPub(pub) if err != nil { diff --git a/x/auth/client/cli/account.go b/x/auth/client/cli/account.go index 47980a64c..5fc8545b9 100644 --- a/x/auth/client/cli/account.go +++ b/x/auth/client/cli/account.go @@ -41,7 +41,7 @@ func GetAccountCmd(storeName string, cdc *wire.Codec, decoder auth.AccountDecode // find the key to look up the account addr := args[0] - key, err := sdk.GetAccAddressBech32(addr) + key, err := sdk.AccAddressFromBech32(addr) if err != nil { return err } diff --git a/x/auth/client/rest/query.go b/x/auth/client/rest/query.go index a5d6f328c..5cdc2ee25 100644 --- a/x/auth/client/rest/query.go +++ b/x/auth/client/rest/query.go @@ -27,7 +27,7 @@ func QueryAccountRequestHandlerFn(storeName string, cdc *wire.Codec, decoder aut vars := mux.Vars(r) bech32addr := vars["address"] - addr, err := sdk.GetAccAddressBech32(bech32addr) + addr, err := sdk.AccAddressFromBech32(bech32addr) if err != nil { w.WriteHeader(http.StatusBadRequest) w.Write([]byte(err.Error())) diff --git a/x/bank/client/cli/sendtx.go b/x/bank/client/cli/sendtx.go index 81a1f1fe2..b294e8cc7 100644 --- a/x/bank/client/cli/sendtx.go +++ b/x/bank/client/cli/sendtx.go @@ -44,7 +44,7 @@ func SendTxCmd(cdc *wire.Codec) *cobra.Command { toStr := viper.GetString(flagTo) - to, err := sdk.GetAccAddressBech32(toStr) + to, err := sdk.AccAddressFromBech32(toStr) if err != nil { return err } diff --git a/x/bank/client/rest/sendtx.go b/x/bank/client/rest/sendtx.go index 4029a42f4..872b3cfe3 100644 --- a/x/bank/client/rest/sendtx.go +++ b/x/bank/client/rest/sendtx.go @@ -44,7 +44,7 @@ func SendRequestHandlerFn(cdc *wire.Codec, kb keys.Keybase, ctx context.CoreCont vars := mux.Vars(r) bech32addr := vars["address"] - to, err := sdk.GetAccAddressBech32(bech32addr) + to, err := sdk.AccAddressFromBech32(bech32addr) if err != nil { w.WriteHeader(http.StatusBadRequest) w.Write([]byte(err.Error())) diff --git a/x/gov/client/cli/tx.go b/x/gov/client/cli/tx.go index 89b5c2eb1..1c5c11b71 100644 --- a/x/gov/client/cli/tx.go +++ b/x/gov/client/cli/tx.go @@ -38,7 +38,7 @@ func GetCmdSubmitProposal(cdc *wire.Codec) *cobra.Command { initialDeposit := viper.GetString(flagDeposit) // get the from address from the name flag - from, err := sdk.GetAccAddressBech32(viper.GetString(flagProposer)) + from, err := sdk.AccAddressFromBech32(viper.GetString(flagProposer)) if err != nil { return err } @@ -90,7 +90,7 @@ func GetCmdDeposit(cdc *wire.Codec) *cobra.Command { Short: "deposit tokens for activing proposal", RunE: func(cmd *cobra.Command, args []string) error { // get the from address from the name flag - depositer, err := sdk.GetAccAddressBech32(viper.GetString(flagDepositer)) + depositer, err := sdk.AccAddressFromBech32(viper.GetString(flagDepositer)) if err != nil { return err } @@ -136,7 +136,7 @@ func GetCmdVote(cdc *wire.Codec) *cobra.Command { RunE: func(cmd *cobra.Command, args []string) error { bechVoter := viper.GetString(flagVoter) - voter, err := sdk.GetAccAddressBech32(bechVoter) + voter, err := sdk.AccAddressFromBech32(bechVoter) if err != nil { return err } @@ -218,7 +218,7 @@ func GetCmdQueryVote(storeName string, cdc *wire.Codec) *cobra.Command { RunE: func(cmd *cobra.Command, args []string) error { proposalID := viper.GetInt64(flagProposalID) - voterAddr, err := sdk.GetAccAddressBech32(viper.GetString(flagVoter)) + voterAddr, err := sdk.AccAddressFromBech32(viper.GetString(flagVoter)) if err != nil { return err } diff --git a/x/gov/client/rest/rest.go b/x/gov/client/rest/rest.go index 6ffed71f3..d8a0acd8c 100644 --- a/x/gov/client/rest/rest.go +++ b/x/gov/client/rest/rest.go @@ -68,7 +68,7 @@ func postProposalHandlerFn(cdc *wire.Codec, ctx context.CoreContext) http.Handle return } - proposer, err := sdk.GetAccAddressBech32(req.Proposer) + proposer, err := sdk.AccAddressFromBech32(req.Proposer) if err != nil { writeErr(&w, http.StatusBadRequest, err.Error()) return @@ -122,7 +122,7 @@ func depositHandlerFn(cdc *wire.Codec, ctx context.CoreContext) http.HandlerFunc return } - depositer, err := sdk.GetAccAddressBech32(req.Depositer) + depositer, err := sdk.AccAddressFromBech32(req.Depositer) if err != nil { writeErr(&w, http.StatusBadRequest, err.Error()) return @@ -170,7 +170,7 @@ func voteHandlerFn(cdc *wire.Codec, ctx context.CoreContext) http.HandlerFunc { return } - voter, err := sdk.GetAccAddressBech32(req.Voter) + voter, err := sdk.AccAddressFromBech32(req.Voter) if err != nil { writeErr(&w, http.StatusBadRequest, err.Error()) return @@ -264,7 +264,7 @@ func queryDepositHandlerFn(cdc *wire.Codec) http.HandlerFunc { return } - depositerAddr, err := sdk.GetAccAddressBech32(bechDepositerAddr) + depositerAddr, err := sdk.AccAddressFromBech32(bechDepositerAddr) if err != nil { w.WriteHeader(http.StatusBadRequest) err := errors.Errorf("'%s' needs to be bech32 encoded", RestDepositer) @@ -330,7 +330,7 @@ func queryVoteHandlerFn(cdc *wire.Codec) http.HandlerFunc { return } - voterAddr, err := sdk.GetAccAddressBech32(bechVoterAddr) + voterAddr, err := sdk.AccAddressFromBech32(bechVoterAddr) if err != nil { w.WriteHeader(http.StatusBadRequest) err := errors.Errorf("'%s' needs to be bech32 encoded", RestVoter) @@ -379,7 +379,7 @@ func queryProposalsWithParameterFn(cdc *wire.Codec) http.HandlerFunc { var depositerAddr sdk.AccAddress if len(bechVoterAddr) != 0 { - voterAddr, err = sdk.GetAccAddressBech32(bechVoterAddr) + voterAddr, err = sdk.AccAddressFromBech32(bechVoterAddr) if err != nil { w.WriteHeader(http.StatusBadRequest) err := errors.Errorf("'%s' needs to be bech32 encoded", RestVoter) @@ -389,7 +389,7 @@ func queryProposalsWithParameterFn(cdc *wire.Codec) http.HandlerFunc { } if len(bechDepositerAddr) != 0 { - depositerAddr, err = sdk.GetAccAddressBech32(bechDepositerAddr) + depositerAddr, err = sdk.AccAddressFromBech32(bechDepositerAddr) if err != nil { w.WriteHeader(http.StatusBadRequest) err := errors.Errorf("'%s' needs to be bech32 encoded", RestDepositer) diff --git a/x/ibc/client/rest/transfer.go b/x/ibc/client/rest/transfer.go index 2540d1401..bee9f955f 100644 --- a/x/ibc/client/rest/transfer.go +++ b/x/ibc/client/rest/transfer.go @@ -38,7 +38,7 @@ func TransferRequestHandlerFn(cdc *wire.Codec, kb keys.Keybase, ctx context.Core destChainID := vars["destchain"] bech32addr := vars["address"] - to, err := sdk.GetAccAddressBech32(bech32addr) + to, err := sdk.AccAddressFromBech32(bech32addr) if err != nil { w.WriteHeader(http.StatusBadRequest) w.Write([]byte(err.Error())) diff --git a/x/slashing/client/cli/tx.go b/x/slashing/client/cli/tx.go index c73b2e162..15458ad1a 100644 --- a/x/slashing/client/cli/tx.go +++ b/x/slashing/client/cli/tx.go @@ -19,7 +19,7 @@ func GetCmdUnrevoke(cdc *wire.Codec) *cobra.Command { RunE: func(cmd *cobra.Command, args []string) error { ctx := context.NewCoreContextFromViper().WithDecoder(authcmd.GetAccountDecoder(cdc)) - validatorAddr, err := sdk.GetAccAddressBech32(args[0]) + validatorAddr, err := sdk.AccAddressFromBech32(args[0]) if err != nil { return err } diff --git a/x/slashing/client/rest/query.go b/x/slashing/client/rest/query.go index 9842ada73..123e235ce 100644 --- a/x/slashing/client/rest/query.go +++ b/x/slashing/client/rest/query.go @@ -27,7 +27,7 @@ func signingInfoHandlerFn(ctx context.CoreContext, storeName string, cdc *wire.C vars := mux.Vars(r) bech32validator := vars["validator"] - validatorAddr, err := sdk.GetValAddressBech32(bech32validator) + validatorAddr, err := sdk.ValAddressFromBech32(bech32validator) if err != nil { w.WriteHeader(http.StatusBadRequest) w.Write([]byte(err.Error())) diff --git a/x/slashing/client/rest/tx.go b/x/slashing/client/rest/tx.go index 212487ddf..f35807544 100644 --- a/x/slashing/client/rest/tx.go +++ b/x/slashing/client/rest/tx.go @@ -57,7 +57,7 @@ func unrevokeRequestHandlerFn(cdc *wire.Codec, kb keys.Keybase, ctx context.Core return } - validatorAddr, err := sdk.GetAccAddressBech32(m.ValidatorAddr) + validatorAddr, err := sdk.AccAddressFromBech32(m.ValidatorAddr) if err != nil { w.WriteHeader(http.StatusInternalServerError) w.Write([]byte(fmt.Sprintf("Couldn't decode validator. Error: %s", err.Error()))) diff --git a/x/stake/client/cli/query.go b/x/stake/client/cli/query.go index e703e8a54..c2d85d4b1 100644 --- a/x/stake/client/cli/query.go +++ b/x/stake/client/cli/query.go @@ -22,7 +22,7 @@ func GetCmdQueryValidator(storeName string, cdc *wire.Codec) *cobra.Command { Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { - addr, err := sdk.GetAccAddressBech32(args[0]) + addr, err := sdk.AccAddressFromBech32(args[0]) if err != nil { return err } @@ -114,12 +114,12 @@ func GetCmdQueryDelegation(storeName string, cdc *wire.Codec) *cobra.Command { Short: "Query a delegation based on address and validator address", RunE: func(cmd *cobra.Command, args []string) error { - valAddr, err := sdk.GetAccAddressBech32(viper.GetString(FlagAddressValidator)) + valAddr, err := sdk.AccAddressFromBech32(viper.GetString(FlagAddressValidator)) if err != nil { return err } - delAddr, err := sdk.GetAccAddressBech32(viper.GetString(FlagAddressDelegator)) + delAddr, err := sdk.AccAddressFromBech32(viper.GetString(FlagAddressDelegator)) if err != nil { return err } @@ -166,7 +166,7 @@ func GetCmdQueryDelegations(storeName string, cdc *wire.Codec) *cobra.Command { Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { - delegatorAddr, err := sdk.GetAccAddressBech32(args[0]) + delegatorAddr, err := sdk.AccAddressFromBech32(args[0]) if err != nil { return err } @@ -204,12 +204,12 @@ func GetCmdQueryUnbondingDelegation(storeName string, cdc *wire.Codec) *cobra.Co Short: "Query an unbonding-delegation record based on delegator and validator address", RunE: func(cmd *cobra.Command, args []string) error { - valAddr, err := sdk.GetAccAddressBech32(viper.GetString(FlagAddressValidator)) + valAddr, err := sdk.AccAddressFromBech32(viper.GetString(FlagAddressValidator)) if err != nil { return err } - delAddr, err := sdk.GetAccAddressBech32(viper.GetString(FlagAddressDelegator)) + delAddr, err := sdk.AccAddressFromBech32(viper.GetString(FlagAddressDelegator)) if err != nil { return err } @@ -256,7 +256,7 @@ func GetCmdQueryUnbondingDelegations(storeName string, cdc *wire.Codec) *cobra.C Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { - delegatorAddr, err := sdk.GetAccAddressBech32(args[0]) + delegatorAddr, err := sdk.AccAddressFromBech32(args[0]) if err != nil { return err } @@ -294,15 +294,15 @@ func GetCmdQueryRedelegation(storeName string, cdc *wire.Codec) *cobra.Command { Short: "Query an unbonding-delegation record based on delegator and validator address", RunE: func(cmd *cobra.Command, args []string) error { - valSrcAddr, err := sdk.GetAccAddressBech32(viper.GetString(FlagAddressValidatorSrc)) + valSrcAddr, err := sdk.AccAddressFromBech32(viper.GetString(FlagAddressValidatorSrc)) if err != nil { return err } - valDstAddr, err := sdk.GetAccAddressBech32(viper.GetString(FlagAddressValidatorDst)) + valDstAddr, err := sdk.AccAddressFromBech32(viper.GetString(FlagAddressValidatorDst)) if err != nil { return err } - delAddr, err := sdk.GetAccAddressBech32(viper.GetString(FlagAddressDelegator)) + delAddr, err := sdk.AccAddressFromBech32(viper.GetString(FlagAddressDelegator)) if err != nil { return err } @@ -349,7 +349,7 @@ func GetCmdQueryRedelegations(storeName string, cdc *wire.Codec) *cobra.Command Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { - delegatorAddr, err := sdk.GetAccAddressBech32(args[0]) + delegatorAddr, err := sdk.AccAddressFromBech32(args[0]) if err != nil { return err } diff --git a/x/stake/client/cli/tx.go b/x/stake/client/cli/tx.go index 7b4d11db5..801710fc3 100644 --- a/x/stake/client/cli/tx.go +++ b/x/stake/client/cli/tx.go @@ -28,7 +28,7 @@ func GetCmdCreateValidator(cdc *wire.Codec) *cobra.Command { if err != nil { return err } - validatorAddr, err := sdk.GetAccAddressBech32(viper.GetString(FlagAddressValidator)) + validatorAddr, err := sdk.AccAddressFromBech32(viper.GetString(FlagAddressValidator)) if err != nil { return err } @@ -75,7 +75,7 @@ func GetCmdEditValidator(cdc *wire.Codec) *cobra.Command { Short: "edit and existing validator account", RunE: func(cmd *cobra.Command, args []string) error { - validatorAddr, err := sdk.GetAccAddressBech32(viper.GetString(FlagAddressValidator)) + validatorAddr, err := sdk.AccAddressFromBech32(viper.GetString(FlagAddressValidator)) if err != nil { return err } @@ -115,11 +115,11 @@ func GetCmdDelegate(cdc *wire.Codec) *cobra.Command { return err } - delegatorAddr, err := sdk.GetAccAddressBech32(viper.GetString(FlagAddressDelegator)) + delegatorAddr, err := sdk.AccAddressFromBech32(viper.GetString(FlagAddressDelegator)) if err != nil { return err } - validatorAddr, err := sdk.GetAccAddressBech32(viper.GetString(FlagAddressValidator)) + validatorAddr, err := sdk.AccAddressFromBech32(viper.GetString(FlagAddressValidator)) if err != nil { return err } @@ -166,15 +166,15 @@ func GetCmdBeginRedelegate(storeName string, cdc *wire.Codec) *cobra.Command { RunE: func(cmd *cobra.Command, args []string) error { var err error - delegatorAddr, err := sdk.GetAccAddressBech32(viper.GetString(FlagAddressDelegator)) + delegatorAddr, err := sdk.AccAddressFromBech32(viper.GetString(FlagAddressDelegator)) if err != nil { return err } - validatorSrcAddr, err := sdk.GetAccAddressBech32(viper.GetString(FlagAddressValidatorSrc)) + validatorSrcAddr, err := sdk.AccAddressFromBech32(viper.GetString(FlagAddressValidatorSrc)) if err != nil { return err } - validatorDstAddr, err := sdk.GetAccAddressBech32(viper.GetString(FlagAddressValidatorDst)) + validatorDstAddr, err := sdk.AccAddressFromBech32(viper.GetString(FlagAddressValidatorDst)) if err != nil { return err } @@ -259,15 +259,15 @@ func GetCmdCompleteRedelegate(cdc *wire.Codec) *cobra.Command { Short: "complete redelegation", RunE: func(cmd *cobra.Command, args []string) error { - delegatorAddr, err := sdk.GetAccAddressBech32(viper.GetString(FlagAddressDelegator)) + delegatorAddr, err := sdk.AccAddressFromBech32(viper.GetString(FlagAddressDelegator)) if err != nil { return err } - validatorSrcAddr, err := sdk.GetAccAddressBech32(viper.GetString(FlagAddressValidatorSrc)) + validatorSrcAddr, err := sdk.AccAddressFromBech32(viper.GetString(FlagAddressValidatorSrc)) if err != nil { return err } - validatorDstAddr, err := sdk.GetAccAddressBech32(viper.GetString(FlagAddressValidatorDst)) + validatorDstAddr, err := sdk.AccAddressFromBech32(viper.GetString(FlagAddressValidatorDst)) if err != nil { return err } @@ -311,11 +311,11 @@ func GetCmdBeginUnbonding(storeName string, cdc *wire.Codec) *cobra.Command { Short: "begin unbonding", RunE: func(cmd *cobra.Command, args []string) error { - delegatorAddr, err := sdk.GetAccAddressBech32(viper.GetString(FlagAddressDelegator)) + delegatorAddr, err := sdk.AccAddressFromBech32(viper.GetString(FlagAddressDelegator)) if err != nil { return err } - validatorAddr, err := sdk.GetAccAddressBech32(viper.GetString(FlagAddressValidator)) + validatorAddr, err := sdk.AccAddressFromBech32(viper.GetString(FlagAddressValidator)) if err != nil { return err } @@ -356,11 +356,11 @@ func GetCmdCompleteUnbonding(cdc *wire.Codec) *cobra.Command { Short: "complete unbonding", RunE: func(cmd *cobra.Command, args []string) error { - delegatorAddr, err := sdk.GetAccAddressBech32(viper.GetString(FlagAddressDelegator)) + delegatorAddr, err := sdk.AccAddressFromBech32(viper.GetString(FlagAddressDelegator)) if err != nil { return err } - validatorAddr, err := sdk.GetAccAddressBech32(viper.GetString(FlagAddressValidator)) + validatorAddr, err := sdk.AccAddressFromBech32(viper.GetString(FlagAddressValidator)) if err != nil { return err } diff --git a/x/stake/client/rest/query.go b/x/stake/client/rest/query.go index be6a21f78..a2893ee9b 100644 --- a/x/stake/client/rest/query.go +++ b/x/stake/client/rest/query.go @@ -48,14 +48,14 @@ func delegationHandlerFn(ctx context.CoreContext, cdc *wire.Codec) http.HandlerF bech32delegator := vars["delegator"] bech32validator := vars["validator"] - delegatorAddr, err := sdk.GetAccAddressBech32(bech32delegator) + delegatorAddr, err := sdk.AccAddressFromBech32(bech32delegator) if err != nil { w.WriteHeader(http.StatusBadRequest) w.Write([]byte(err.Error())) return } - validatorAddr, err := sdk.GetAccAddressBech32(bech32validator) + validatorAddr, err := sdk.AccAddressFromBech32(bech32validator) if err != nil { w.WriteHeader(http.StatusBadRequest) w.Write([]byte(err.Error())) @@ -104,14 +104,14 @@ func ubdHandlerFn(ctx context.CoreContext, cdc *wire.Codec) http.HandlerFunc { bech32delegator := vars["delegator"] bech32validator := vars["validator"] - delegatorAddr, err := sdk.GetAccAddressBech32(bech32delegator) + delegatorAddr, err := sdk.AccAddressFromBech32(bech32delegator) if err != nil { w.WriteHeader(http.StatusBadRequest) w.Write([]byte(err.Error())) return } - validatorAddr, err := sdk.GetAccAddressBech32(bech32validator) + validatorAddr, err := sdk.AccAddressFromBech32(bech32validator) if err != nil { w.WriteHeader(http.StatusBadRequest) w.Write([]byte(err.Error())) @@ -161,21 +161,21 @@ func redHandlerFn(ctx context.CoreContext, cdc *wire.Codec) http.HandlerFunc { bech32validatorSrc := vars["validator_src"] bech32validatorDst := vars["validator_dst"] - delegatorAddr, err := sdk.GetAccAddressBech32(bech32delegator) + delegatorAddr, err := sdk.AccAddressFromBech32(bech32delegator) if err != nil { w.WriteHeader(http.StatusBadRequest) w.Write([]byte(err.Error())) return } - validatorSrcAddr, err := sdk.GetAccAddressBech32(bech32validatorSrc) + validatorSrcAddr, err := sdk.AccAddressFromBech32(bech32validatorSrc) if err != nil { w.WriteHeader(http.StatusBadRequest) w.Write([]byte(err.Error())) return } - validatorDstAddr, err := sdk.GetAccAddressBech32(bech32validatorDst) + validatorDstAddr, err := sdk.AccAddressFromBech32(bech32validatorDst) if err != nil { w.WriteHeader(http.StatusBadRequest) w.Write([]byte(err.Error())) diff --git a/x/stake/client/rest/tx.go b/x/stake/client/rest/tx.go index 415a8af8b..b723c21c0 100644 --- a/x/stake/client/rest/tx.go +++ b/x/stake/client/rest/tx.go @@ -97,13 +97,13 @@ func editDelegationsRequestHandlerFn(cdc *wire.Codec, kb keys.Keybase, ctx conte i := 0 for _, msg := range m.Delegations { - delegatorAddr, err := sdk.GetAccAddressBech32(msg.DelegatorAddr) + delegatorAddr, err := sdk.AccAddressFromBech32(msg.DelegatorAddr) if err != nil { w.WriteHeader(http.StatusInternalServerError) w.Write([]byte(fmt.Sprintf("Couldn't decode delegator. Error: %s", err.Error()))) return } - validatorAddr, err := sdk.GetAccAddressBech32(msg.ValidatorAddr) + validatorAddr, err := sdk.AccAddressFromBech32(msg.ValidatorAddr) if err != nil { w.WriteHeader(http.StatusInternalServerError) w.Write([]byte(fmt.Sprintf("Couldn't decode validator. Error: %s", err.Error()))) @@ -123,7 +123,7 @@ func editDelegationsRequestHandlerFn(cdc *wire.Codec, kb keys.Keybase, ctx conte } for _, msg := range m.BeginRedelegates { - delegatorAddr, err := sdk.GetAccAddressBech32(msg.DelegatorAddr) + delegatorAddr, err := sdk.AccAddressFromBech32(msg.DelegatorAddr) if err != nil { w.WriteHeader(http.StatusInternalServerError) w.Write([]byte(fmt.Sprintf("Couldn't decode delegator. Error: %s", err.Error()))) @@ -134,13 +134,13 @@ func editDelegationsRequestHandlerFn(cdc *wire.Codec, kb keys.Keybase, ctx conte w.Write([]byte("Must use own delegator address")) return } - validatorSrcAddr, err := sdk.GetAccAddressBech32(msg.ValidatorSrcAddr) + validatorSrcAddr, err := sdk.AccAddressFromBech32(msg.ValidatorSrcAddr) if err != nil { w.WriteHeader(http.StatusInternalServerError) w.Write([]byte(fmt.Sprintf("Couldn't decode validator. Error: %s", err.Error()))) return } - validatorDstAddr, err := sdk.GetAccAddressBech32(msg.ValidatorDstAddr) + validatorDstAddr, err := sdk.AccAddressFromBech32(msg.ValidatorDstAddr) if err != nil { w.WriteHeader(http.StatusInternalServerError) w.Write([]byte(fmt.Sprintf("Couldn't decode validator. Error: %s", err.Error()))) @@ -162,19 +162,19 @@ func editDelegationsRequestHandlerFn(cdc *wire.Codec, kb keys.Keybase, ctx conte } for _, msg := range m.CompleteRedelegates { - delegatorAddr, err := sdk.GetAccAddressBech32(msg.DelegatorAddr) + delegatorAddr, err := sdk.AccAddressFromBech32(msg.DelegatorAddr) if err != nil { w.WriteHeader(http.StatusInternalServerError) w.Write([]byte(fmt.Sprintf("Couldn't decode delegator. Error: %s", err.Error()))) return } - validatorSrcAddr, err := sdk.GetAccAddressBech32(msg.ValidatorSrcAddr) + validatorSrcAddr, err := sdk.AccAddressFromBech32(msg.ValidatorSrcAddr) if err != nil { w.WriteHeader(http.StatusInternalServerError) w.Write([]byte(fmt.Sprintf("Couldn't decode validator. Error: %s", err.Error()))) return } - validatorDstAddr, err := sdk.GetAccAddressBech32(msg.ValidatorDstAddr) + validatorDstAddr, err := sdk.AccAddressFromBech32(msg.ValidatorDstAddr) if err != nil { w.WriteHeader(http.StatusInternalServerError) w.Write([]byte(fmt.Sprintf("Couldn't decode validator. Error: %s", err.Error()))) @@ -194,7 +194,7 @@ func editDelegationsRequestHandlerFn(cdc *wire.Codec, kb keys.Keybase, ctx conte } for _, msg := range m.BeginUnbondings { - delegatorAddr, err := sdk.GetAccAddressBech32(msg.DelegatorAddr) + delegatorAddr, err := sdk.AccAddressFromBech32(msg.DelegatorAddr) if err != nil { w.WriteHeader(http.StatusInternalServerError) w.Write([]byte(fmt.Sprintf("Couldn't decode delegator. Error: %s", err.Error()))) @@ -205,7 +205,7 @@ func editDelegationsRequestHandlerFn(cdc *wire.Codec, kb keys.Keybase, ctx conte w.Write([]byte("Must use own delegator address")) return } - validatorAddr, err := sdk.GetAccAddressBech32(msg.ValidatorAddr) + validatorAddr, err := sdk.AccAddressFromBech32(msg.ValidatorAddr) if err != nil { w.WriteHeader(http.StatusInternalServerError) w.Write([]byte(fmt.Sprintf("Couldn't decode validator. Error: %s", err.Error()))) @@ -226,13 +226,13 @@ func editDelegationsRequestHandlerFn(cdc *wire.Codec, kb keys.Keybase, ctx conte } for _, msg := range m.CompleteUnbondings { - delegatorAddr, err := sdk.GetAccAddressBech32(msg.DelegatorAddr) + delegatorAddr, err := sdk.AccAddressFromBech32(msg.DelegatorAddr) if err != nil { w.WriteHeader(http.StatusInternalServerError) w.Write([]byte(fmt.Sprintf("Couldn't decode delegator. Error: %s", err.Error()))) return } - validatorAddr, err := sdk.GetAccAddressBech32(msg.ValidatorAddr) + validatorAddr, err := sdk.AccAddressFromBech32(msg.ValidatorAddr) if err != nil { w.WriteHeader(http.StatusInternalServerError) w.Write([]byte(fmt.Sprintf("Couldn't decode validator. Error: %s", err.Error()))) diff --git a/x/stake/keeper/test_common.go b/x/stake/keeper/test_common.go index b367e5692..983933123 100644 --- a/x/stake/keeper/test_common.go +++ b/x/stake/keeper/test_common.go @@ -139,7 +139,7 @@ func NewPubKey(pk string) (res crypto.PubKey) { // for incode address generation func TestAddr(addr string, bech string) sdk.AccAddress { - res, err := sdk.GetAccAddressHex(addr) + res, err := sdk.AccAddressFromHex(addr) if err != nil { panic(err) } @@ -148,7 +148,7 @@ func TestAddr(addr string, bech string) sdk.AccAddress { panic("Bech encoding doesn't match reference") } - bechres, err := sdk.GetAccAddressBech32(bech) + bechres, err := sdk.AccAddressFromBech32(bech) if err != nil { panic(err) } @@ -170,7 +170,7 @@ func createTestAddrs(numAddrs int) []sdk.AccAddress { buffer.WriteString("A58856F0FD53BF058B4909A21AEC019107BA6") //base address string buffer.WriteString(numString) //adding on final two digits to make addresses unique - res, _ := sdk.GetAccAddressHex(buffer.String()) + res, _ := sdk.AccAddressFromHex(buffer.String()) bech := res.String() addresses = append(addresses, TestAddr(buffer.String(), bech)) buffer.Reset()