helper

package
v1.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 26, 2021 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Neo3Magic_MainNet     uint32 = 860833102 // NEO3
	Neo3Magic_TestNet     uint32 = 877933390 // N3T4
	DefaultAddressVersion byte   = 0x35      // 53
)
View Source
const UINT160SIZE = 20
View Source
const UINT256SIZE = 32
View Source
const UINT32SIZE = 4
View Source
const UINT64SIZE = 8

Variables

View Source
var DefaultProtocolSettings = ProtocolSettings{
	Magic:          Neo3Magic_MainNet,
	AddressVersion: DefaultAddressVersion,
}
View Source
var UInt160Zero = NewUInt160()
View Source
var UInt256Zero = NewUInt256()

Functions

func Abs

func Abs(x int64) int64

func BigIntFromNeoBytes

func BigIntFromNeoBytes(ba []byte) *big.Int

func BigIntToNeoBytes

func BigIntToNeoBytes(data *big.Int) []byte

func BytesToHex

func BytesToHex(b []byte) string

bytes to hex string

func BytesToUInt32

func BytesToUInt32(bs []byte) uint32

func BytesToUInt64

func BytesToUInt64(bs []byte) uint64

func CompareTo

func CompareTo(a, b uint64) int

a>b, returns 1 a==b, returns 0 a<b, returns -1

func ConcatBytes

func ConcatBytes(b1 []byte, b2 []byte) []byte

ConcatBytes ...

func GenerateRandomBytes

func GenerateRandomBytes(size int) ([]byte, error)

GenerateRandomBytes returns securely generated random bytes. It will return an error if the system's secure random number generator fails to function correctly, in which case the caller should not continue.

func GetVarSize

func GetVarSize(value int) int

func HexToBytes

func HexToBytes(s string) (b []byte)

Simple hex string to bytes

func Int16ToBytes

func Int16ToBytes(n int16) []byte

Int16ToBytes ...

func Int64ToBytes

func Int64ToBytes(n int64) []byte

Int64ToBytes ...

func IntToBytes

func IntToBytes(n int) []byte

IntToBytes ...

func PadRight

func PadRight(data []byte, length int, negative bool) []byte

func ReverseBytes

func ReverseBytes(data []byte) []byte

ReverseBytes without change original slice

func ReverseString

func ReverseString(input string) string

ReverseString, "abcd" to "dcba"

func UInt16ToBytes

func UInt16ToBytes(n uint16) []byte

UInt16ToBytes converts uint16 to byte array

func UInt32ToBytes

func UInt32ToBytes(n uint32) []byte

UInt32ToBytes converts uint32 to byte array

func UInt64ToBytes

func UInt64ToBytes(n uint64) []byte

UInt64ToBytes converts uint32 to byte array

func XOR

func XOR(a, b []byte) []byte

Types

type ProtocolSettings

type ProtocolSettings struct {
	Magic          uint32
	AddressVersion byte
}

type UInt160

type UInt160 struct {
	Value1 uint64
	Value2 uint64
	Value3 uint32
}

/ This class stores a 160 bit unsigned int, represented as a 20-byte little-endian byte array / It is composed by ulong(64) + ulong(64) + uint(32) = UInt160(160)

func NewUInt160

func NewUInt160() *UInt160

func UInt160FromBytes

func UInt160FromBytes(b []byte) *UInt160

UInt160FromBytes attempts to decode the given little endian bytes into an UInt160.

func UInt160FromString

func UInt160FromString(s string) (*UInt160, error)

UInt160FromString attempts to decode the given big endian string into an UInt160.

func (*UInt160) CompareTo

func (u *UInt160) CompareTo(other *UInt160) int

/ Method CompareTo returns 1 if this UInt160 is bigger than other UInt160; -1 if it's smaller; 0 if it's equals / Example: assume this is 01ff00ff00ff00ff00ff00ff00ff00ff00ff00a4, this.CompareTo(02ff00ff00ff00ff00ff00ff00ff00ff00ff00a3) returns 1

func (*UInt160) Deserialize

func (u *UInt160) Deserialize(br *io.BinaryReader)

func (*UInt160) Equals

func (u *UInt160) Equals(other *UInt160) bool

Equals returns true if both UInt160 values are the same.

func (*UInt160) ExistsIn

func (u *UInt160) ExistsIn(list []UInt160) bool

ExistsIn checks if u exists in list

func (*UInt160) Less

func (u *UInt160) Less(other *UInt160) bool

Less returns true if this value is less than given UInt160 value. It's primarily intended to be used for sorting purposes.

func (*UInt160) MarshalJSON

func (u *UInt160) MarshalJSON() ([]byte, error)

MarshalJSON implements the json marshaller interface.

func (*UInt160) Serialize

func (u *UInt160) Serialize(bw *io.BinaryWriter)

func (*UInt160) Size

func (u *UInt160) Size() int

Size returns the size of a UInt160 object in byte

func (UInt160) String

func (u UInt160) String() string

String implements the stringer interface. Return big endian hex string.

func (*UInt160) ToByteArray

func (u *UInt160) ToByteArray() []byte

ToByteArray returns the little endian byte slice representation of u.

func (*UInt160) UnmarshalJSON

func (u *UInt160) UnmarshalJSON(data []byte) (err error)

UnmarshalJSON implements the json unmarshaller interface.

type UInt160Slice

type UInt160Slice []UInt160

func (UInt160Slice) GetVarSize

func (us UInt160Slice) GetVarSize() int

func (UInt160Slice) Len

func (us UInt160Slice) Len() int

func (UInt160Slice) Less

func (us UInt160Slice) Less(i int, j int) bool

func (UInt160Slice) Swap

func (us UInt160Slice) Swap(i, j int)

type UInt256

type UInt256 struct {
	Value1 uint64
	Value2 uint64
	Value3 uint64
	Value4 uint64
}

/ This class stores a 256 bit unsigned int, represented as a 32-byte little-endian byte array / Composed by ulong(64) + ulong(64) + ulong(64) + ulong(64) = UInt256(256)

func NewUInt256

func NewUInt256() *UInt256

func UInt256FromBytes

func UInt256FromBytes(b []byte) *UInt256

UInt256FromBytes attempts to decode the given bytes (in LE representation) into an UInt256.

func UInt256FromString

func UInt256FromString(s string) (u *UInt256, err error)

UInt256FromString attempts to decode the given string (in BE representation) into an UInt256.

func (*UInt256) CompareTo

func (u *UInt256) CompareTo(other *UInt256) int

/ Method CompareTo returns 1 if this UInt256 is bigger than other UInt256; -1 if it's smaller; 0 if it's equals / Example: assume this is 01ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00a4, this.CompareTo(02ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00a3) returns 1

func (*UInt256) Deserialize

func (u *UInt256) Deserialize(br *io.BinaryReader)

func (*UInt256) Equals

func (u *UInt256) Equals(other *UInt256) bool

Equals returns true if both UInt256 values are the same.

func (UInt256) ExistsIn

func (u UInt256) ExistsIn(list []UInt256) bool

ExistsIn checks if u exists in list

func (*UInt256) Less

func (u *UInt256) Less(other *UInt256) bool

func (UInt256) MarshalJSON

func (u UInt256) MarshalJSON() ([]byte, error)

MarshalJSON implements the json marshaller interface.

func (*UInt256) Serialize

func (u *UInt256) Serialize(bw *io.BinaryWriter)

func (*UInt256) Size

func (u *UInt256) Size() int

Size returns the size of a UInt256 object in byte

func (UInt256) String

func (u UInt256) String() string

String implements the stringer interface. Return big endian hex string.

func (*UInt256) ToByteArray

func (u *UInt256) ToByteArray() []byte

ToByteArray returns a byte slice representation of u.

func (*UInt256) UnmarshalJSON

func (u *UInt256) UnmarshalJSON(data []byte) (err error)

UnmarshalJSON implements the json unmarshaller interface.

type UInt256Slice

type UInt256Slice []UInt256

func (UInt256Slice) GetVarSize

func (us UInt256Slice) GetVarSize() int

func (UInt256Slice) Len

func (us UInt256Slice) Len() int

func (UInt256Slice) Less

func (us UInt256Slice) Less(i int, j int) bool

func (UInt256Slice) Swap

func (us UInt256Slice) Swap(i, j int)

type VarInt

type VarInt struct {
	Value uint64
}

VarInt

func ParseVarInt

func ParseVarInt(bytes []byte) (VarInt, error)

ParseVarInt parse the serialized bytes of the var int and return VarInt

func VarIntFromInt

func VarIntFromInt(input int) VarInt

func VarIntFromInt16

func VarIntFromInt16(input int16) VarInt

func VarIntFromUInt64

func VarIntFromUInt64(input uint64) VarInt

func (VarInt) Bytes

func (v VarInt) Bytes() []byte

Bytes returns the serialized bytes of the var int

func (VarInt) Length

func (v VarInt) Length() int

Length returns the serialized bytes length of the var int

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL