Browse Source

Bech32: Wrap error messages

pull/1780/head
ValarDragon 7 years ago
parent
commit
1d66e34dc8
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