common

package
Version: v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2019 License: Apache-2.0 Imports: 13 Imported by: 4

Documentation

Index

Constants

View Source
const (
	HashLength    = 32
	AddressLength = 20
)

Lengths of hashes and addresses in bytes.

Variables

This section is empty.

Functions

func BytesToAddress

func BytesToAddress(b []byte) types.Address

BytesToAddress returns Address with value b. If b is larger than len(h), b will be cropped from the left.

func BytesToHash

func BytesToHash(b []byte) types.Hash

BytesToHash sets b to hash. If b is larger than len(h), b will be cropped from the left.

func FromHex

func FromHex(s string) []byte

FromHex returns the bytes represented by the hexadecimal string s. s may be prefixed with "0x".

func HashAlg added in v1.0.0

func HashAlg() hash.Hash

get hash algorithm by global config

func HeaderHash

func HeaderHash(block *types.Block) (hash types.Hash)

HeaderHash calculate block's hash

func Hex2Bytes

func Hex2Bytes(str string) []byte

Hex2Bytes returns the bytes represented by the hexadecimal string str.

func HexToAddress

func HexToAddress(s string) types.Address

HexToAddress returns Address with byte values of s. If s is larger than len(h), s will be cropped from the left.

func HexToHash

func HexToHash(s string) types.Hash

HexToHash sets byte representation of s to hash. If b is larger than len(h), b will be cropped from the left.

func TxHash

func TxHash(tx *types.Transaction) (hash types.Hash)

TxHash calculate tx's hash

Types

type NetAddress

type NetAddress struct {
	Protocol string
	IP       string
	Port     int32
}

NetAddress network address

func NewNetAddress

func NewNetAddress(proto, ip string, port int32) *NetAddress

NewNetAddress create a new net address instance

func ParseNetAddress

func ParseNetAddress(addrStr string) (*NetAddress, error)

ParseNetAddress parse net address from address string

func (*NetAddress) Equal

func (addr *NetAddress) Equal(another *NetAddress) bool

Equal check wheter two is equal

func (*NetAddress) IsLoopback

func (addr *NetAddress) IsLoopback() bool

IsLoopback reports whether ip is a loopback address.

func (*NetAddress) ToString

func (addr *NetAddress) ToString() string

ToString encode netaddress to string

type RingBuffer

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

RingBuffer is a ring buffer implementation.

func NewRingBuffer

func NewRingBuffer(size int) *RingBuffer

NewRingBuffer create a ring buffer instance

func (*RingBuffer) AddElement

func (ring *RingBuffer) AddElement(hash types.Hash, elem interface{})

AddElement add a element to ring buffer

func (*RingBuffer) Exist

func (ring *RingBuffer) Exist(hash types.Hash) bool

Exist check if the element is already in the ring buffer

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL