Merge pull request #222 from tendermint/dev/bech32_err_msg

Bech32: Wrap error messages
This commit is contained in:
Dev Ojha 2018-06-11 10:20:51 -07:00 committed by GitHub
commit 0c98d10b4f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 3 deletions

View File

@ -2,13 +2,14 @@ package bech32
import (
"github.com/btcsuite/btcutil/bech32"
"github.com/pkg/errors"
)
//ConvertAndEncode converts from a base64 encoded byte string to base32 encoded byte string and then to bech32
func ConvertAndEncode(hrp string, data []byte) (string, error) {
converted, err := bech32.ConvertBits(data, 8, 5, true)
if err != nil {
return "", err
return "", errors.Wrap(err, "encoding bech32 failed")
}
return bech32.Encode(hrp, converted)
@ -18,11 +19,11 @@ func ConvertAndEncode(hrp string, data []byte) (string, error) {
func DecodeAndConvert(bech string) (string, []byte, error) {
hrp, data, err := bech32.Decode(bech)
if err != nil {
return "", nil, err
return "", nil, errors.Wrap(err, "decoding bech32 failed")
}
converted, err := bech32.ConvertBits(data, 5, 8, false)
if err != nil {
return "", nil, err
return "", nil, errors.Wrap(err, "decoding bech32 failed")
}
return hrp, converted, nil
}