-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge PR: add validator address prefix converting function && tag v0.…
…18.1 (#134) * FINISH: add val prefix converting * FINISH: ut of val addr prefix converting * remove useless code * FIX: ut bug
- Loading branch information
1 parent
a41bfcc
commit 960b28e
Showing
4 changed files
with
51 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,37 @@ | ||
package utils | ||
|
||
import sdk "github.com/cosmos/cosmos-sdk/types" | ||
import ( | ||
"fmt" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
) | ||
|
||
// AccAddrPrefixConvert converts the account address between two different prefixes | ||
func AccAddrPrefixConvert(srcPrefx, srcAccAddrStr, dstPrefix string) (dstAccAddrStr string, err error) { | ||
config := sdk.GetConfig() | ||
// set source prefix | ||
config.SetBech32PrefixForAccount(srcPrefx, srcPrefx+"pub") | ||
config.SetBech32PrefixForAccount(srcPrefx, fmt.Sprintf("%s%s", srcPrefx, sdk.PrefixPublic)) | ||
accAddr, err := sdk.AccAddressFromBech32(srcAccAddrStr) | ||
if err != nil { | ||
return | ||
} | ||
|
||
// set destination prefix | ||
config.SetBech32PrefixForAccount(dstPrefix, dstPrefix+"pub") | ||
config.SetBech32PrefixForAccount(dstPrefix, fmt.Sprintf("%s%s", dstPrefix, sdk.PrefixPublic)) | ||
return accAddr.String(), err | ||
} | ||
|
||
// ValAddrPrefixConvert converts the validator address between two different prefixes | ||
func ValAddrPrefixConvert(srcPrefx, srcValAddrStr, dstPrefix string) (dstValAddrStr string, err error) { | ||
config := sdk.GetConfig() | ||
// set source prefix | ||
config.SetBech32PrefixForValidator(srcPrefx, fmt.Sprintf("%s%s", srcPrefx, sdk.PrefixPublic)) | ||
valAddr, err := sdk.ValAddressFromBech32(srcValAddrStr) | ||
if err != nil { | ||
return | ||
} | ||
|
||
// set destination prefix | ||
config.SetBech32PrefixForValidator(dstPrefix, fmt.Sprintf("%s%s", dstPrefix, sdk.PrefixPublic)) | ||
return valAddr.String(), err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters