common

package
v0.0.0-...-0c41aae Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2020 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// supported max asset precision is 8
	MaximumPrecision = 8
	StorageFactor    = 100000000
)
View Source
const FOOLPROOFPREFIX = 0x02b824 + 1 // +1 for avoid affected by lower 192bits shift-add

FOOLPROOFPREFIX used for fool-proof prefix base58.BitcoinEncoding[21] = 'N', base58.BitcoinEncoding[18] = 'K' 33 = len(base58.Encode( (2**192).Bytes() )), 192 = 8bit * (UINT160SIZE + SHA256CHKSUM) ((21 * 58**35) + (18 * 58**34) + (21 * 58**33)) >> 192 = 0x02b824

View Source
const PREFIXLEN = 3

PREFIXLEN = len( 0x02b825.Bytes() )

View Source
const SHA256CHKSUM = 4
View Source
const UINT160SIZE = 20
View Source
const UINT256SIZE = 32

Variables

View Source
var MaxUint256 = Uint256{
	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
}

Functions

func AbsUint

func AbsUint(n1 uint, n2 uint) uint

func BytesToHexString

func BytesToHexString(data []byte) string

func BytesToInt

func BytesToInt(b []byte) []int

func BytesToInt16

func BytesToInt16(b []byte) int16

func ClearBytes

func ClearBytes(arr []byte, len int)

func CompareHeight

func CompareHeight(blockHeight uint32, heights []uint32) bool

func FileExisted

func FileExisted(filename string) bool

func GetUint16Array

func GetUint16Array(source []byte) ([]uint16, error)

func HexStringToBytes

func HexStringToBytes(value string) ([]byte, error)

func IntToBytes

func IntToBytes(n int) []byte

func IsValidHexAddr

func IsValidHexAddr(s []byte) bool

func SliceRemove

func SliceRemove(slice []uint32, h uint32) []uint32

func ToByteArray

func ToByteArray(source []uint16) []byte

Types

type Cache

type Cache interface {
	Add([]byte, interface{}) error
	Get([]byte) (interface{}, bool)
	Set([]byte, interface{}) error
}

Cache is an anstract cache layer

type Fixed64

type Fixed64 int64

the 64 bit fixed-point number, precise 10^-8

func StringToFixed64

func StringToFixed64(s string) (Fixed64, error)

func (*Fixed64) Deserialize

func (f *Fixed64) Deserialize(r io.Reader) error

func (Fixed64) GetData

func (f Fixed64) GetData() int64

func (*Fixed64) Serialize

func (f *Fixed64) Serialize(w io.Writer) error

func (Fixed64) String

func (f Fixed64) String() string

type GoCache

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

GoCache is the caching layer implemented by go-cache.

func NewGoCache

func NewGoCache(defaultExpiration, cleanupInterval time.Duration) *GoCache

NewGoCache creates a go-cache cache with a given default expiration duration and cleanup interval.

func (*GoCache) Add

func (gc *GoCache) Add(key []byte, value interface{}) error

Add adds an item to the cache only if an item doesn't already exist for the given key, or if the existing item has expired. Returns an error otherwise.

func (*GoCache) Get

func (gc *GoCache) Get(key []byte) (interface{}, bool)

Get gets an item from the cache. Returns the item or nil, and a bool indicating whether the key was found.

func (*GoCache) Set

func (gc *GoCache) Set(key []byte, value interface{}) error

Set adds an item to the cache, replacing any existing item, using the default expiration.

type HexStr

type HexStr []byte

func (HexStr) MarshalJSON

func (b HexStr) MarshalJSON() ([]byte, error)

type Uint160

type Uint160 [UINT160SIZE]uint8
var EmptyUint160 Uint160

func BigToUint160

func BigToUint160(b *big.Int) Uint160

func BytesToUint160

func BytesToUint160(b []byte) Uint160

func ToCodeHash

func ToCodeHash(code []byte) (Uint160, error)

func ToScriptHash

func ToScriptHash(address string) (Uint160, error)

func Uint160ParseFromBytes

func Uint160ParseFromBytes(f []byte) (Uint160, error)

func (*Uint160) Big

func (u *Uint160) Big() *big.Int

func (*Uint160) CompareTo

func (u *Uint160) CompareTo(o Uint160) int

func (*Uint160) Deserialize

func (f *Uint160) Deserialize(r io.Reader) error

func (Uint160) MarshalJSON

func (f Uint160) MarshalJSON() ([]byte, error)

func (*Uint160) Serialize

func (u *Uint160) Serialize(w io.Writer) (int, error)

func (*Uint160) SetBytes

func (u *Uint160) SetBytes(b []byte) *Uint160

func (*Uint160) ToAddress

func (f *Uint160) ToAddress() (string, error)

func (*Uint160) ToArray

func (u *Uint160) ToArray() []byte

func (*Uint160) ToHexString

func (u *Uint160) ToHexString() string

type Uint256

type Uint256 [UINT256SIZE]uint8
var EmptyUint256 Uint256

func Uint256ParseFromBytes

func Uint256ParseFromBytes(f []byte) (hash Uint256, err error)

func (*Uint256) CompareTo

func (u *Uint256) CompareTo(o Uint256) int

func (*Uint256) Deserialize

func (u *Uint256) Deserialize(r io.Reader) error

func (*Uint256) Serialize

func (u *Uint256) Serialize(w io.Writer) (int, error)

func (*Uint256) ToArray

func (u *Uint256) ToArray() []byte

func (*Uint256) ToHexString

func (u *Uint256) ToHexString() string

func (*Uint256) ToString

func (u *Uint256) ToString() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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