address comments
This commit is contained in:
parent
9f2f47a0a5
commit
896cd333f0
|
@ -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
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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()))
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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()))
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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()))
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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()))
|
||||
|
|
|
@ -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())))
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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()))
|
||||
|
|
|
@ -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())))
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in New Issue