util: make Uint160Size public
This commit is contained in:
parent
7179e4ba9f
commit
9e04e61533
1 changed files with 7 additions and 6 deletions
|
@ -7,16 +7,17 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
const uint160Size = 20
|
// Uint160Size is the size of Uint160 in bytes.
|
||||||
|
const Uint160Size = 20
|
||||||
|
|
||||||
// Uint160 is a 20 byte long unsigned integer.
|
// Uint160 is a 20 byte long unsigned integer.
|
||||||
type Uint160 [uint160Size]uint8
|
type Uint160 [Uint160Size]uint8
|
||||||
|
|
||||||
// Uint160DecodeStringBE attempts to decode the given string into an Uint160.
|
// Uint160DecodeStringBE attempts to decode the given string into an Uint160.
|
||||||
func Uint160DecodeStringBE(s string) (Uint160, error) {
|
func Uint160DecodeStringBE(s string) (Uint160, error) {
|
||||||
var u Uint160
|
var u Uint160
|
||||||
if len(s) != uint160Size*2 {
|
if len(s) != Uint160Size*2 {
|
||||||
return u, fmt.Errorf("expected string size of %d got %d", uint160Size*2, len(s))
|
return u, fmt.Errorf("expected string size of %d got %d", Uint160Size*2, len(s))
|
||||||
}
|
}
|
||||||
b, err := hex.DecodeString(s)
|
b, err := hex.DecodeString(s)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -27,8 +28,8 @@ func Uint160DecodeStringBE(s string) (Uint160, error) {
|
||||||
|
|
||||||
// Uint160DecodeBytesBE attempts to decode the given bytes into an Uint160.
|
// Uint160DecodeBytesBE attempts to decode the given bytes into an Uint160.
|
||||||
func Uint160DecodeBytesBE(b []byte) (u Uint160, err error) {
|
func Uint160DecodeBytesBE(b []byte) (u Uint160, err error) {
|
||||||
if len(b) != uint160Size {
|
if len(b) != Uint160Size {
|
||||||
return u, fmt.Errorf("expected byte size of %d got %d", uint160Size, len(b))
|
return u, fmt.Errorf("expected byte size of %d got %d", Uint160Size, len(b))
|
||||||
}
|
}
|
||||||
copy(u[:], b)
|
copy(u[:], b)
|
||||||
return
|
return
|
||||||
|
|
Loading…
Reference in a new issue