hash

package
v0.0.0-...-59e56fa Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2020 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// Zero is an empty hash.
	Zero = common.Hash{}
)
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

func FakeEpoch

func FakeEpoch() idx.Epoch

FakeEpoch gives fixed value of fake epoch for testing purpose.

func FakeHash

func FakeHash(seed ...int64) (h common.Hash)

FakeHash generates random fake hash for testing purpose.

func FakePeer

func FakePeer(seed ...int64) idx.StakerID

FakePeer generates random fake peer id for testing purpose.

func FromBytes

func FromBytes(b []byte) common.Hash

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

func GetEventName

func GetEventName(e Event) string

GetEventName gets an optional human readable alias of event hash.

func GetNodeName

func GetNodeName(n idx.StakerID) string

GetNodeName gets an optional human readable alias of node address.

func Of

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

Of returns hash of data

func SetEventName

func SetEventName(e Event, name string)

SetEventName sets an optional human readable alias of event hash in log.

func SetNodeName

func SetNodeName(n idx.StakerID, name string)

SetNodeName sets an optional human readable alias of node address in log.

Types

type Event

type Event common.Hash

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

func BytesToEvent

func BytesToEvent(b []byte) Event

BytesToEvent 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 with the same epoch 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) Big

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

Big converts a hash to a big integer.

func (Event) Bytes

func (h Event) Bytes() []byte

Bytes returns value as byte slice.

func (Event) Epoch

func (h Event) Epoch() idx.Epoch

Epoch returns [0:4] bytes, which store event's Epoch.

func (Event) FullID

func (h Event) FullID() string

FullID returns human readable string representation with no information loss.

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

func (h Event) Lamport() idx.Lamport

Lamport returns [4:8] bytes, which store event's Lamport.

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

func (h Event) ShortID(precision int) string

ShortID returns human readable ID representation, suitable for API calls.

func (Event) String

func (h Event) String() string

String returns human readable string representation.

type Events

type Events []Event

Events is a slice of event hashes.

func FakeEvents

func FakeEvents(n int) Events

FakeEvents generates random hashes of fake event with the same epoch for testing purpose.

func NewEvents

func NewEvents(h ...Event) Events

NewEvents makes event hash slice.

func WireToEvents

func WireToEvents(buf [][]byte) Events

WireToEvents converts from simple slice.

func (*Events) Add

func (hh *Events) Add(hash ...Event)

Add appends hash to the slice.

func (Events) Copy

func (hh Events) Copy() Events

Copy copies events to a new structure.

func (Events) Set

func (hh Events) Set() EventsSet

Set returns whole index as a EventsSet.

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 EventsSet

type EventsSet map[Event]struct{}

EventsSet provides additional methods of event hash index.

func NewEventsSet

func NewEventsSet(h ...Event) EventsSet

NewEventsSet makes event hash index.

func (EventsSet) Add

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

Add appends hash to the index.

func (EventsSet) Contains

func (hh EventsSet) Contains(hash Event) bool

Contains returns true if hash is in.

func (EventsSet) Copy

func (hh EventsSet) Copy() EventsSet

Copy copies events to a new structure.

func (EventsSet) Erase

func (hh EventsSet) Erase(hash ...Event) (changed bool)

Erase erase hash from the index.

func (EventsSet) Slice

func (hh EventsSet) Slice() Events

Slice returns whole index as slice.

func (EventsSet) String

func (hh EventsSet) String() string

String returns human readable string representation.

type EventsStack

type EventsStack []Event

func (*EventsStack) Pop

func (s *EventsStack) Pop() *Event

Pop event ID from top. Erases element.

func (*EventsStack) Push

func (s *EventsStack) Push(v Event)

Push event ID on top

func (*EventsStack) PushAll

func (s *EventsStack) PushAll(vv Events)

PushAll event IDs on top

type OrderedEvents

type OrderedEvents []Event

OrderedEvents is a sortable slice of event hashes.

func WireToOrderedEvents

func WireToOrderedEvents(buf [][]byte) OrderedEvents

WireToOrderedEvents converts from simple slice.

func (OrderedEvents) Len

func (hh OrderedEvents) Len() int

func (OrderedEvents) Less

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

func (OrderedEvents) String

func (hh OrderedEvents) String() string

String returns string representation.

func (OrderedEvents) Swap

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

func (OrderedEvents) ToWire

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

ToWire converts to simple slice.

type Transaction

type Transaction common.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