hash

package
v0.0.0-...-168a2c3 Latest Latest
Warning

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

Go to latest
Published: May 30, 2019 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// HashLength is the expected length of the hash
	HashLength = sha256.Size
)

Variables

View Source
var EmptyPeer = Peer{}

EmptyPeer is empty peer identifier.

View Source
var (
	// EventNameDict is an optional dictionary to make events human readable in log.
	EventNameDict = make(map[Event]string)
)
View Source
var (
	// NodeNameDict is an optional dictionary to make node address human readable in log.
	NodeNameDict = make(map[Peer]string)
)
View Source
var (
	// ZeroEvent is a hash of virtual initial event.
	ZeroEvent = Event{}
)
View Source
var (
	// ZeroTransaction is a hash of virtual initial transaction.
	ZeroTransaction = Transaction{}
)

Functions

This section is empty.

Types

type Event

type Event Hash

Event is a unique identifier of event. It is a hash of Event.

func BytesToEventHash

func BytesToEventHash(b []byte) Event

BytesToEventHash converts bytes to event hash. If b is larger than len(h), b will be cropped from the left.

func FakeEvent

func FakeEvent() (h Event)

FakeEvent generates random fake event hash for testing purpose.

func HexToEventHash

func HexToEventHash(s string) Event

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

func (Event) Bytes

func (h Event) Bytes() []byte

Bytes returns value as byte slice.

func (Event) Hex

func (h Event) Hex() string

Hex converts an event hash to a hex string.

func (*Event) IsZero

func (h *Event) IsZero() bool

IsZero returns true if hash is empty.

func (*Event) SetBytes

func (h *Event) SetBytes(raw []byte)

SetBytes converts bytes to event hash. If b is larger than len(h), b will be cropped from the left.

func (Event) String

func (h Event) String() string

String returns human readable string representation.

type Events

type Events map[Event]struct{}

Events provides additional methods of event hash index.

func FakeEvents

func FakeEvents(n int) Events

FakeEvents generates random fake event hashes for testing purpose.

func NewEvents

func NewEvents(h ...Event) Events

NewEvents makes event hash index.

func WireToEventHashes

func WireToEventHashes(buf [][]byte) Events

WireToEventHashes converts from simple slice.

func (Events) Add

func (hh Events) Add(hash ...Event) (changed bool)

Add appends hash to the index.

func (Events) Contains

func (hh Events) Contains(hash Event) bool

Contains returns true if hash is in.

func (Events) Slice

func (hh Events) Slice() EventsSlice

Slice returns whole index as slice.

func (Events) String

func (hh Events) String() string

String returns human readable string representation.

func (Events) ToWire

func (hh Events) ToWire() [][]byte

ToWire converts to simple slice.

type EventsSlice

type EventsSlice []Event

EventsSlice is a sortable slice of event hash.

func WireToEventHashSlice

func WireToEventHashSlice(buf [][]byte) EventsSlice

WireToEventHashSlice converts from simple slice.

func (EventsSlice) Len

func (hh EventsSlice) Len() int

func (EventsSlice) Less

func (hh EventsSlice) Less(i, j int) bool

func (EventsSlice) Swap

func (hh EventsSlice) Swap(i, j int)

func (EventsSlice) ToWire

func (hh EventsSlice) ToWire() [][]byte

ToWire converts to simple slice.

type Hash

type Hash [HashLength]byte

Hash represents the 32 byte Keccak256 hash of arbitrary data.

func BigToHash

func BigToHash(b *big.Int) Hash

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

func FakeHash

func FakeHash() (h Hash)

FakeHash generates random fake hash for testing purpose.

func FromBytes

func FromBytes(b []byte) Hash

FromBytes converts bytes to hash. If b is larger than len(h), b will be cropped from the left.

func HexToHash

func HexToHash(s string) Hash

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

func Of

func Of(data ...[]byte) (hash Hash)

func (Hash) Big

func (h Hash) Big() *big.Int

Big converts a hash to a big integer.

func (Hash) Bytes

func (h Hash) Bytes() []byte

Bytes gets the byte representation of the underlying hash.

func (Hash) Format

func (h Hash) Format(s fmt.State, c rune)

Format implements fmt.Formatter, forcing the byte slice to be formatted as is, without going through the stringer interface used for logging.

func (Hash) Generate

func (h Hash) Generate(rand *rand.Rand, size int) reflect.Value

Generate implements testing/quick.Generator.

func (Hash) Hex

func (h Hash) Hex() string

Hex converts a hash to a hex string.

func (Hash) MarshalText

func (h Hash) MarshalText() ([]byte, error)

MarshalText returns the hex representation of h.

func (*Hash) Scan

func (h *Hash) Scan(src interface{}) error

Scan implements Scanner for database/sql.

func (*Hash) SetBytes

func (h *Hash) SetBytes(raw []byte)

SetBytes converts bytes to hash. If b is larger than len(h), b will be cropped from the left.

func (Hash) ShortString

func (h Hash) ShortString() string

ShortString returns short string representation.

func (Hash) String

func (h Hash) String() string

String implements the stringer interface and is used also by the logger when doing full logging into a file.

func (Hash) TerminalString

func (h Hash) TerminalString() string

TerminalString implements log.TerminalStringer, formatting a string for console output during logging.

func (*Hash) UnmarshalJSON

func (h *Hash) UnmarshalJSON(input []byte) error

UnmarshalJSON parses a hash in hex syntax.

func (*Hash) UnmarshalText

func (h *Hash) UnmarshalText(input []byte) error

UnmarshalText parses a hash in hex syntax.

type Peer

type Peer Hash

Peer is a unique peer identifier. It is a hash of peer's PubKey.

func BytesToPeer

func BytesToPeer(b []byte) Peer

BytesToPeer converts bytes to peer id. If b is larger than len(h), b will be cropped from the left.

func FakePeer

func FakePeer() Peer

FakePeer generates random fake peer id for testing purpose.

func HexToPeer

func HexToPeer(s string) Peer

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

func PeerOfPubkey

func PeerOfPubkey(pub *common.PublicKey) Peer

PeerOfPubkey calcs peer id from pub key.

func PeerOfPubkeyBytes

func PeerOfPubkeyBytes(b []byte) Peer

PeerOfPubkeyBytes calcs peer id from pub key bytes.

func (*Peer) Bytes

func (p *Peer) Bytes() []byte

Bytes returns value as byte slice.

func (*Peer) Hex

func (p *Peer) Hex() string

Hex converts a hash to a hex string.

func (*Peer) IsEmpty

func (p *Peer) IsEmpty() bool

IsEmpty returns true if hash is empty.

func (*Peer) String

func (p *Peer) String() string

String returns human readable string representation.

type Transaction

type Transaction Hash

Transaction is a unique identifier of internal transaction. It is a hash of Transaction.

func FakeTransaction

func FakeTransaction() Transaction

FakeTransaction generates random fake hash for testing purpose.

func HexToTransactionHash

func HexToTransactionHash(s string) Transaction

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

func (Transaction) Bytes

func (h Transaction) Bytes() []byte

Bytes returns value as byte slice.

func (Transaction) Hex

func (h Transaction) Hex() string

Hex converts an event hash to a hex string.

func (*Transaction) IsZero

func (h *Transaction) IsZero() bool

IsZero returns true if hash is empty.

Jump to

Keyboard shortcuts

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