Browse Source

Merge pull request #222 from tendermint/dev/bech32_err_msg

Bech32: Wrap error messages
pull/1780/head
Dev Ojha 6 years ago
committed by GitHub
parent
commit
0c98d10b4f
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 3 deletions
  1. +4
    -3
      bech32/bech32.go

+ 4
- 3
bech32/bech32.go View File

@ -2,13 +2,14 @@ package bech32
import ( import (
"github.com/btcsuite/btcutil/bech32" "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 //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) { func ConvertAndEncode(hrp string, data []byte) (string, error) {
converted, err := bech32.ConvertBits(data, 8, 5, true) converted, err := bech32.ConvertBits(data, 8, 5, true)
if err != nil { if err != nil {
return "", err
return "", errors.Wrap(err, "encoding bech32 failed")
} }
return bech32.Encode(hrp, converted) return bech32.Encode(hrp, converted)
@ -18,11 +19,11 @@ func ConvertAndEncode(hrp string, data []byte) (string, error) {
func DecodeAndConvert(bech string) (string, []byte, error) { func DecodeAndConvert(bech string) (string, []byte, error) {
hrp, data, err := bech32.Decode(bech) hrp, data, err := bech32.Decode(bech)
if err != nil { if err != nil {
return "", nil, err
return "", nil, errors.Wrap(err, "decoding bech32 failed")
} }
converted, err := bech32.ConvertBits(data, 5, 8, false) converted, err := bech32.ConvertBits(data, 5, 8, false)
if err != nil { if err != nil {
return "", nil, err
return "", nil, errors.Wrap(err, "decoding bech32 failed")
} }
return hrp, converted, nil return hrp, converted, nil
} }

Loading…
Cancel
Save