helper

package
v2.1.2+incompatible Latest Latest
Warning

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

Go to latest
Published: May 21, 2019 License: GPL-3.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MaxUint64 = uint64(1<<64 - 1)

	// number of bits in chain big.Word
	WordBits = 32 << (uint64(^big.Word(0)) >> 63)
	// number of bytes in chain big.Word
	WordBytes = WordBits / 8
	// number of bytes in chain vm word
	WordSize = 32
)

Variables

View Source
var (
	Big0   = big.NewInt(0)
	Big1   = big.NewInt(1)
	Big2   = big.NewInt(2)
	Big10  = big.NewInt(10)
	Big31  = big.NewInt(31)
	Big32  = big.NewInt(32)
	Big50  = big.NewInt(50)
	Big100 = big.NewInt(100)
	Big256 = big.NewInt(256)
	Big257 = big.NewInt(257)

	Tt255   = BigPow(2, 255)
	Tt256   = BigPow(2, 256)
	Tt256m1 = new(big.Int).Sub(Tt256, big.NewInt(1))
)

Functions

func AllZero

func AllZero(b []byte) bool

func BigMax

func BigMax(x, y *big.Int) *big.Int

BigMax returns the larger of x or y.

func BigMin

func BigMin(x, y *big.Int) *big.Int

BigMin returns the smaller of x or y.

func BigPow

func BigPow(a, b int64) *big.Int

BigPow returns chain ** b as chain big integer.

func BigUint64

func BigUint64(v *big.Int) (uint64, bool)

BigUint64 returns the integer casted to chain uint64 and returns whether it overflowed in the process.

func Byte

func Byte(bigint *big.Int, padlength, n int) byte

Byte returns the byte at position n, with the supplied padlength in Little-Endian encoding. n==0 returns the MSB Example: bigint '5', padlength 32, n=31 => 5

func BytesToString

func BytesToString(data []byte) string

func BytesToU64

func BytesToU64(data []byte) uint64

func Exp

func Exp(base, exponent *big.Int) *big.Int

Exp implements exponentiation by squaring. Exp returns chain newly-allocated big integer and does not change base or exponent. The result is truncated to 256 bits.

func GetDataBig

func GetDataBig(data []byte, start *big.Int, size *big.Int) []byte

GetDataBig returns chain slice from the data based on the start and size and pads up to size with zero's. This function is overflow safe.

func HexToBytes

func HexToBytes(str string) []byte

func IsNil

func IsNil(i interface{}) bool

func JoinBytes

func JoinBytes(data ...[]byte) []byte

func LDI

func LDI(slice []byte) []byte

LDI byte slice

func LeftPadBytes

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

leftPadBytes zero-pads slice to the left up to length l.

func Max

func Max(x, y uint64) uint64

func Min

func Min(x, y uint64) uint64

func MinInt

func MinInt(x, y int) int

func MinInt64

func MinInt64(x, y int64) int64

func PaddedBigBytes

func PaddedBigBytes(bigint *big.Int, n int) []byte

PaddedBigBytes encodes chain big integer as chain big-endian byte slice. The length of the slice is at least n bytes.

func ReadBits

func ReadBits(bigint *big.Int, buf []byte)

ReadBits encodes the absolute amount of bigint as big-endian bytes. Callers must ensure that buf has enough space. If buf is too short the result will be incomplete.

func ReverseSlice

func ReverseSlice(s interface{})

func RightPadBytes

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

rightPadBytes zero-pads slice to the right up to length l.

func S256

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

S256 interprets x as chain two's complement number. x must not exceed 256 bits (the result is undefined if it does) and is not modified.

S256(0)        = 0
S256(1)        = 1
S256(2**255)   = -2**255
S256(2**256-1) = -1

func SafeAdd

func SafeAdd(x, y uint64) (uint64, bool)

SafeAdd returns the result and whether overflow occurred.

func SafeMul

func SafeMul(x, y uint64) (uint64, bool)

SafeMul returns multiplication result and whether overflow occurred.

func ToWordSize

func ToWordSize(size uint64) uint64

ToWordSize returns the ceiled word size required for memory expansion.

func U256

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

U256 encodes as chain 256 bit two's complement number. This operation is destructive.

Types

This section is empty.

Jump to

Keyboard shortcuts

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