gaiad: Genesis txs now use bech32 encoding of address and pubkey

* `gaiad init gen-tx` makes the outputted file use bech32, with acct prefix
* `gaiad init --gen-txs` only reads bech32 with acct prefixes

The reason for using the account prefix is that in principle you could
have genesis transactions for non-validators.

Closes #1475
This commit is contained in:
ValarDragon
2018-07-07 14:23:19 -07:00
parent 4d303ce745
commit 611e4faa3a
5 changed files with 65 additions and 27 deletions
+36
View File
@@ -102,6 +102,15 @@ func GetAccAddressBech32(address string) (addr Address, err error) {
return Address(bz), nil
}
// create an Address from a string, panics on error
func MustGetAccAddressBech32(address string) (addr Address) {
addr, err := GetAccAddressBech32(address)
if err != nil {
panic(err)
}
return addr
}
// create a Pubkey from a string
func GetAccPubKeyBech32(address string) (pk crypto.PubKey, err error) {
bz, err := GetFromBech32(address, Bech32PrefixAccPub)
@@ -117,6 +126,15 @@ func GetAccPubKeyBech32(address string) (pk crypto.PubKey, err error) {
return pk, nil
}
// create an Pubkey from a string, panics on error
func MustGetAccPubKeyBech32(address string) (pk crypto.PubKey) {
pk, err := GetAccPubKeyBech32(address)
if err != nil {
panic(err)
}
return pk
}
// create an Address from a hex string
func GetValAddressHex(address string) (addr Address, err error) {
if len(address) == 0 {
@@ -138,6 +156,15 @@ func GetValAddressBech32(address string) (addr Address, err error) {
return Address(bz), nil
}
// create an Address from a string, panics on error
func MustGetValAddressBech32(address string) (addr Address) {
addr, err := GetValAddressBech32(address)
if err != nil {
panic(err)
}
return addr
}
// decode a validator public key into a PubKey
func GetValPubKeyBech32(pubkey string) (pk crypto.PubKey, err error) {
bz, err := GetFromBech32(pubkey, Bech32PrefixValPub)
@@ -153,6 +180,15 @@ func GetValPubKeyBech32(pubkey string) (pk crypto.PubKey, err error) {
return pk, nil
}
// create an Pubkey from a string, panics on error
func MustGetValPubKeyBech32(address string) (pk crypto.PubKey) {
pk, err := GetValPubKeyBech32(address)
if err != nil {
panic(err)
}
return pk
}
// decode a bytestring from a bech32-encoded string
func GetFromBech32(bech32str, prefix string) ([]byte, error) {
if len(bech32str) == 0 {