common

package
v2.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2023 License: Apache-2.0 Imports: 16 Imported by: 9

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 BytesToInt

func BytesToInt(b []byte) []int

func BytesToInt16

func BytesToInt16(b []byte) int16

func ClearBytes

func ClearBytes(b []byte)

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 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

func U256Equal added in v2.1.6

func U256Equal(a, b Uint256) bool

Types

type Cache

type Cache interface {
	Add(key []byte, value interface{}) error
	Get(key []byte) (value interface{}, ok bool)
	Set(key []byte, value interface{}) error
	SetWithExpiration(key []byte, value interface{}, expiration time.Duration) error
	Delete(key []byte) 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 {
	*gocache.Cache
}

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) Delete

func (gc *GoCache) Delete(key []byte) error

Delete deletes an item from the cache. Does nothing if the key is not in the cache.

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.

func (*GoCache) SetWithExpiration

func (gc *GoCache) SetWithExpiration(key []byte, value interface{}, expiration time.Duration) error

SetWithExpiration adds an item to the cache, replacing any existing item, with a given expiration.

type HexStr

type HexStr []byte

func (HexStr) MarshalJSON

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

type PriorityQueue added in v2.1.7

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

PriorityQueue represents the queue

func NewPrque added in v2.1.7

func NewPrque() *PriorityQueue

NewPrque initializes an empty priority queue.

func (*PriorityQueue) Empty added in v2.1.7

func (p *PriorityQueue) Empty() bool

func (*PriorityQueue) Len added in v2.1.7

func (p *PriorityQueue) Len() int

Len returns the number of elements in the queue.

func (*PriorityQueue) Pop added in v2.1.7

func (p *PriorityQueue) Pop() (interface{}, int64)

Pop removes the element with the highest priority from the queue and returns it.

func (*PriorityQueue) Push added in v2.1.7

func (p *PriorityQueue) Push(v interface{}, priority int64)

Push insert a new element into the queue. No action is performed on duplicate elements.

func (*PriorityQueue) UpdatePriority added in v2.1.7

func (p *PriorityQueue) UpdatePriority(x interface{}, newPriority int64)

UpdatePriority changes the priority of a given item. If the specified item is not present in the queue, no action is performed.

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)

Uint160ParseFromBytes create an Uint160 from f slice

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

SetBytes u itself with b slice. 1. Drop high-order bytes if b overflow 160bits 2. Keep leading zero if b not enough 160bits

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