binary

package
v0.29.4 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2019 License: Apache-2.0 Imports: 7 Imported by: 59

Documentation

Index

Constants

View Source
const Word160Length = 20
View Source
const Word256Bits = Word256Bytes * 8
View Source
const Word256Bytes = 32
View Source
const Word256Word160Delta = 12

Variables

View Source
var (
	Zero256 = Word256{}
	One256  = LeftPadWord256([]byte{1})
)
View Source
var Big256 = big.NewInt(256)
View Source
var BigWord256Bytes = big.NewInt(Word256Bytes)
View Source
var Zero160 = Word160{}

Functions

func BigIntFromWord256 added in v0.29.0

func BigIntFromWord256(word Word256) *big.Int

func Fingerprint

func Fingerprint(slice []byte) []byte

func FromTwosComplement added in v0.29.0

func FromTwosComplement(x *big.Int, n uint) *big.Int

Interprets a positive big.Int as a n-bit two's complement signed integer

func Int64FromWord256

func Int64FromWord256(word Word256) int64

func IsUint64SumOverflow

func IsUint64SumOverflow(a, b uint64) bool

Returns whether a + b would be a uint64 overflow

func IsZeros

func IsZeros(slice []byte) bool

func LeftPadBytes

func LeftPadBytes(slice []byte, l int) []byte

func RightPadBytes

func RightPadBytes(slice []byte, l int) []byte

func S256

func S256(x *big.Int) *big.Int

Interprets a positive big.Int as a 256-bit two's complement signed integer

func SignExtend

func SignExtend(x *big.Int, n uint) *big.Int

Treats the positive big int x as if it contains an embedded n bit signed integer in its least significant bits and extends that sign

func ToTwosComplement added in v0.29.0

func ToTwosComplement(x *big.Int, n uint) *big.Int

Convert a possibly negative big.Int x to a positive big.Int encoded in two's complement

func Tuple256Split

func Tuple256Split(t Tuple256) (Word256, Word256)

func U256

func U256(x *big.Int) *big.Int

Converts a possibly negative big int x into a positive big int encoding a twos complement representation of x truncated to 32 bytes

func Uint64FromWord256

func Uint64FromWord256(word Word256) uint64

Types

type HexBytes added in v0.19.0

type HexBytes []byte

func (HexBytes) Bytes added in v0.20.0

func (hb HexBytes) Bytes() []byte

func (HexBytes) Marshal added in v0.20.0

func (hb HexBytes) Marshal() ([]byte, error)

Protobuf support

func (HexBytes) MarshalText added in v0.19.0

func (hb HexBytes) MarshalText() ([]byte, error)

func (HexBytes) MarshalTo added in v0.20.0

func (hb HexBytes) MarshalTo(data []byte) (int, error)

func (HexBytes) Size added in v0.20.0

func (hb HexBytes) Size() int

func (HexBytes) String added in v0.19.0

func (hb HexBytes) String() string

func (*HexBytes) Unmarshal added in v0.20.0

func (hb *HexBytes) Unmarshal(data []byte) error

func (*HexBytes) UnmarshalText added in v0.19.0

func (hb *HexBytes) UnmarshalText(hexBytes []byte) error

type Tuple256

type Tuple256 struct {
	First  Word256
	Second Word256
}

func (Tuple256) Compare

func (tuple Tuple256) Compare(other Tuple256) int

type Tuple256Slice

type Tuple256Slice []Tuple256

func (Tuple256Slice) Len

func (p Tuple256Slice) Len() int

func (Tuple256Slice) Less

func (p Tuple256Slice) Less(i, j int) bool

func (Tuple256Slice) Sort

func (p Tuple256Slice) Sort()

func (Tuple256Slice) Swap

func (p Tuple256Slice) Swap(i, j int)

type Word160

type Word160 [Word160Length]byte

func (Word160) Bytes

func (w Word160) Bytes() []byte

func (Word160) Word256

func (w Word160) Word256() (word256 Word256)

Pad a Word160 on the left and embed it in a Word256 (as it is for account addresses in EVM)

type Word256

type Word256 [Word256Bytes]byte

func BigIntToWord256 added in v0.29.0

func BigIntToWord256(x *big.Int) Word256

func Int64ToWord256

func Int64ToWord256(i int64) Word256

func LeftPadWord256

func LeftPadWord256(bz []byte) (word Word256)

func RightPadWord256

func RightPadWord256(bz []byte) (word Word256)

func Uint64ToWord256

func Uint64ToWord256(i uint64) (word Word256)

func (Word256) Bytes

func (w Word256) Bytes() []byte

func (Word256) Compare

func (w Word256) Compare(other Word256) int

func (Word256) Copy

func (w Word256) Copy() Word256

func (Word256) IsZero

func (w Word256) IsZero() bool

func (*Word256) Marshal added in v0.20.0

func (w *Word256) Marshal() ([]byte, error)

Gogo proto support

func (Word256) MarshalText added in v0.19.0

func (w Word256) MarshalText() ([]byte, error)

func (*Word256) MarshalTo added in v0.20.0

func (w *Word256) MarshalTo(data []byte) (int, error)

func (Word256) Postfix

func (w Word256) Postfix(n int) []byte

func (Word256) Prefix

func (w Word256) Prefix(n int) []byte

copied.

func (Word256) Size added in v0.20.0

func (w Word256) Size() int

func (Word256) String

func (w Word256) String() string

func (*Word256) Unmarshal added in v0.20.0

func (w *Word256) Unmarshal(data []byte) error

func (*Word256) UnmarshalText added in v0.19.0

func (w *Word256) UnmarshalText(hexBytes []byte) error

func (Word256) UnpadLeft

func (w Word256) UnpadLeft() []byte

func (Word256) UnpadRight

func (w Word256) UnpadRight() []byte

func (Word256) Word160

func (w Word256) Word160() (w160 Word160)

Get a Word160 embedded a Word256 and padded on the left (as it is for account addresses in EVM)

type Words256

type Words256 []Word256

func (Words256) Len

func (ws Words256) Len() int

func (Words256) Less

func (ws Words256) Less(i, j int) bool

func (Words256) Swap

func (ws Words256) Swap(i, j int)

Jump to

Keyboard shortcuts

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