mirror of
https://github.com/jimeh/go-base58.git
synced 2026-02-19 08:06:39 +00:00
Simplify error message from Decode()
This commit is contained in:
10
base58.go
10
base58.go
@@ -2,7 +2,6 @@ package base58
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
@@ -10,6 +9,8 @@ import (
|
||||
const Alphabet = "123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"
|
||||
const base = len(Alphabet)
|
||||
|
||||
var errInvalidBase58 = errors.New("invalid base58")
|
||||
|
||||
// Encode converts a base10 integer to a base58 string using the default
|
||||
// alphabet.
|
||||
func Encode(num int) string {
|
||||
@@ -33,7 +34,7 @@ func Decode(str string) (int, error) {
|
||||
char := string(str[i-1])
|
||||
index := strings.Index(Alphabet, char)
|
||||
if index == -1 {
|
||||
return -1, decodeError(str)
|
||||
return -1, errInvalidBase58
|
||||
}
|
||||
num += multi * index
|
||||
multi = multi * base
|
||||
@@ -41,8 +42,3 @@ func Decode(str string) (int, error) {
|
||||
|
||||
return num, nil
|
||||
}
|
||||
|
||||
func decodeError(str string) error {
|
||||
msg := fmt.Sprintf("\"%s\" is not a valid base58 string.", str)
|
||||
return errors.New(msg)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user