common

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2018 License: MIT Imports: 8 Imported by: 3

Documentation

Index

Constants

View Source
const (
	// Uint128Bytes defines the number of bytes for Uint128 type.
	Uint128Bytes = 16

	// Uint128Bits defines the number of bits for Uint128 type.
	Uint128Bits = 128
)

Variables

View Source
var (
	// ErrUint128Overflow indicates the value is greater than uint128 maximum value 2^128.
	ErrUint128Overflow = errors.New("uint128: overflow")

	// ErrUint128Underflow indicates the value is smaller then uint128 minimum value 0.
	ErrUint128Underflow = errors.New("uint128: underflow")

	// ErrUint128InvalidBytesSize indicates the bytes size is not equal to Uint128Bytes.
	ErrUint128InvalidBytesSize = errors.New("uint128: invalid bytes")

	// ErrUint128InvalidString indicates the string is not valid when converted to uin128.
	ErrUint128InvalidString = errors.New("uint128: invalid string to uint128")
)
View Source
var EmptyBlockID = BlockID{}

Functions

func CopyBytes

func CopyBytes(b []byte) []byte

func Fatalf

func Fatalf(format string, args ...interface{})

Fatalf formats a message to standard error and exits the program. The message is also printed to standard output if standard error is redirected to a different file.

func GetBucket

func GetBucket(timestamp uint32) uint32

func Int2Bytes

func Int2Bytes(n uint32) []byte

Types

type BlockID

type BlockID struct {
	Data [32]byte
}

BlockID is a sha256 byte array, the first 2 byte is replaced by the block number

func (BlockID) BlockNum

func (bid BlockID) BlockNum() uint64

BlockNum returns the block num

type IBlockHeader

type IBlockHeader interface {
	Previous() BlockID
	Timestamp() uint64
}

BlockHeader ...

type ISignedBlock

type ISignedBlock interface {
	ISignedBlockHeader
	Marshaller
}

SignedBlock ...

type ISignedBlockHeader

type ISignedBlockHeader interface {
	IBlockHeader
	Id() BlockID
	GetSignee() (interface{}, error)
}

SignedBlockHeader ...

type ISignedTransaction

type ISignedTransaction interface {
	ITransaction
}

type ITransaction

type ITransaction interface {
	Validate() error
}

type ITransactionInvoice

type ITransactionInvoice interface {
}

type Marshaller

type Marshaller interface {
	Marshall() ([]byte, error)
	Unmarshall([]byte) error
}

Marshaller ...

type Uint128

type Uint128 struct {
	// contains filtered or unexported fields
}

Uint128 defines uint128 type, based on big.Int.

For arithmetic operations, use uint128.Int.Add()/Sub()/Mul()/Div()/etc. For example, u1.Add(u1.Int, u2.Int) sets u1 to u1 + u2.

func NewUint128

func NewUint128() *Uint128

NewUint128 returns a new Uint128 struct with default value.

func NewUint128FromBigInt

func NewUint128FromBigInt(i *big.Int) (*Uint128, error)

NewUint128FromBigInt returns a new Uint128 struct with given value and have a check.

func NewUint128FromFixedSizeByteSlice

func NewUint128FromFixedSizeByteSlice(bytes []byte) (*Uint128, error)

NewUint128FromFixedSizeByteSlice returns a new Uint128 struct with given fixed size byte slice.

func NewUint128FromFixedSizeBytes

func NewUint128FromFixedSizeBytes(bytes [16]byte) *Uint128

NewUint128FromFixedSizeBytes returns a new Uint128 struct with given fixed size byte array.

func NewUint128FromInt

func NewUint128FromInt(i int64) (*Uint128, error)

NewUint128FromInt returns a new Uint128 struct with given value and have a check.

func NewUint128FromString

func NewUint128FromString(str string) (*Uint128, error)

NewUint128FromString returns a new Uint128 struct with given value and have a check.

func NewUint128FromUint

func NewUint128FromUint(i uint64) *Uint128

NewUint128FromUint returns a new Uint128 with given value

func Uint128Zero

func Uint128Zero() *Uint128

Uint128Zero zero of uint128

func (*Uint128) Add

func (u *Uint128) Add(x *Uint128) (*Uint128, error)

Add returns u + x

func (*Uint128) Bytes

func (u *Uint128) Bytes() []byte

Bytes absolute value of u as a big-endian byte slice.

func (*Uint128) Cmp

func (u *Uint128) Cmp(x *Uint128) int

Cmp compares u and x and returns:

-1 if u <  x
 0 if u == x
+1 if u >  x

func (*Uint128) DeepCopy

func (u *Uint128) DeepCopy() *Uint128

DeepCopy returns a deep copy of u

func (*Uint128) Div

func (u *Uint128) Div(x *Uint128) (*Uint128, error)

Div returns u / x

func (*Uint128) Exp

func (u *Uint128) Exp(x *Uint128) (*Uint128, error)

Exp returns u^x

func (*Uint128) FromFixedSizeByteSlice

func (u *Uint128) FromFixedSizeByteSlice(bytes []byte) (*Uint128, error)

FromFixedSizeByteSlice converts Big-Endian fixed size bytes to Uint128.

func (*Uint128) FromFixedSizeBytes

func (u *Uint128) FromFixedSizeBytes(bytes [16]byte) *Uint128

FromFixedSizeBytes converts Big-Endian fixed size bytes to Uint128.

func (*Uint128) Mul

func (u *Uint128) Mul(x *Uint128) (*Uint128, error)

Mul returns u * x

func (*Uint128) String

func (u *Uint128) String() string

String returns the string representation of x.

func (*Uint128) Sub

func (u *Uint128) Sub(x *Uint128) (*Uint128, error)

Sub returns u - x

func (*Uint128) ToFixedSizeByteSlice

func (u *Uint128) ToFixedSizeByteSlice() ([]byte, error)

ToFixedSizeByteSlice converts Uint128 to Big-Endian fixed size byte slice.

func (*Uint128) ToFixedSizeBytes

func (u *Uint128) ToFixedSizeBytes() ([16]byte, error)

ToFixedSizeBytes converts Uint128 to Big-Endian fixed size bytes.

func (*Uint128) Uint64

func (u *Uint128) Uint64() uint64

Uint64 returns the uint64 representation of x. If x cannot be represented in a uint64, the result is undefined.

func (*Uint128) Validate

func (u *Uint128) Validate() error

Validate returns error if u is not a valid uint128, otherwise returns nil.

Directories

Path Synopsis
secp256k1
Package secp256k1 wraps the bitcoin secp256k1 C library.
Package secp256k1 wraps the bitcoin secp256k1 C library.
sha3
Package sha3 implements the SHA-3 fixed-output-length hash functions and the SHAKE variable-output-length hash functions defined by FIPS-202.
Package sha3 implements the SHA-3 fixed-output-length hash functions and the SHAKE variable-output-length hash functions defined by FIPS-202.
encoding
Package math provides integer math utilities.
Package math provides integer math utilities.

Jump to

Keyboard shortcuts

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