model

package
v0.0.0-...-2646333 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2020 License: Apache-2.0 Imports: 16 Imported by: 3

Documentation

Overview

Package model contains the general data models and interfaces for the crawler.

Package model contains the general data models and interfaces.

Package model contains the general data models and interfaces.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AbiJSON

func AbiJSON(contractName string) (abi.ABI, error)

AbiJSON returns parsed abi of this particular contract.

func ReturnEventFromABI

func ReturnEventFromABI(_abi abi.ABI, eventType string) (abi.Event, error)

ReturnEventFromABI returns abi.Event struct from the ABI

Types

type ContractFilterers

type ContractFilterers interface {
	ContractName() string
	ContractAddress() common.Address
	EventTypes() []string
	UpdateStartBlock(eventType string, startBlock uint64)
	LastEvents() []*Event
	StartFilterers(client bind.ContractBackend, pastEvents []*Event, nonSubOnly bool) ([]*Event, error)
}

ContractFilterers defines an interface that starts up a particular set of filterers

type ContractWatchers

type ContractWatchers interface {
	ContractName() string
	ContractAddress() common.Address
	StartWatchers(client bind.ContractBackend, eventRecvChan chan *Event,
		errs chan error) ([]utils.WatcherSubscription, error)
	StopWatchers(unsub bool) error
}

ContractWatchers defines an interface that starts up a particular set of listeners watcher loops.

type Event

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

Event represents a single smart contract event log item. Represents any event type from the sol/abi generated code and creates a single type to handle in the watcher/filterer.

func NewEvent

func NewEvent(eventType string, contractName string, contractAddress common.Address, timestamp int64,
	retrievalMethod RetrievalMethod, eventPayload map[string]interface{}, logPayload *types.Log) (*Event, error)

NewEvent is a convenience function to create a new Event

func NewEventFromContractEvent

func NewEventFromContractEvent(eventType string, contractName string, contractAddress common.Address,
	eventData interface{}, timestamp int64, retrievalMethod RetrievalMethod) (*Event, error)

NewEventFromContractEvent creates a new event after converting eventData to interface{}

func (*Event) BlockHash

func (e *Event) BlockHash() common.Hash

BlockHash gets the block hash from the Event Payload

func (*Event) BlockNumber

func (e *Event) BlockNumber() uint64

BlockNumber is the block number for this event

func (*Event) ContractAddress

func (e *Event) ContractAddress() common.Address

ContractAddress returns the contractAddress for the Event

func (*Event) ContractName

func (e *Event) ContractName() string

ContractName returns the contract name

func (*Event) EventPayload

func (e *Event) EventPayload() map[string]interface{}

EventPayload returns the event payload for the Event

func (*Event) EventType

func (e *Event) EventType() string

EventType returns the eventType for the Event

func (*Event) Hash

func (e *Event) Hash() string

Hash returns the hash of the Event

func (*Event) LogData

func (e *Event) LogData() []byte

LogData is data provided by the contract, ABI encoded

func (*Event) LogIndex

func (e *Event) LogIndex() uint

LogIndex is the log index position in the block

func (*Event) LogPayload

func (e *Event) LogPayload() *types.Log

LogPayload returns the log payload from the block

func (*Event) LogPayloadToString

func (e *Event) LogPayloadToString() string

LogPayloadToString is a string representation of some fields of log

func (*Event) LogRemoved

func (e *Event) LogRemoved() bool

LogRemoved is true if log was reverted due to chain reorganization.

func (*Event) LogTopics

func (e *Event) LogTopics() []common.Hash

LogTopics returns the list of topics provided by the contract

func (*Event) RetrievalMethod

func (e *Event) RetrievalMethod() RetrievalMethod

RetrievalMethod returns the method that was used to retrieve this event

func (*Event) SetTimestamp

func (e *Event) SetTimestamp(ts int64)

SetTimestamp returns the timestamp for the Event

func (*Event) Timestamp

func (e *Event) Timestamp() int64

Timestamp returns the timestamp for the Event

func (*Event) TxHash

func (e *Event) TxHash() common.Hash

TxHash is the hash of the transaction

func (*Event) TxIndex

func (e *Event) TxIndex() uint

TxIndex is the index of the transaction in the block

type EventDataPersister

type EventDataPersister interface {
	// SaveEvents stores a list of Event(s)
	SaveEvents(events []*Event) []error

	// RetrieveEvents retrieves the Events from the persistence layer based
	// on date in which it was received
	RetrieveEvents(criteria *RetrieveEventsCriteria) ([]*Event, error)
}

EventDataPersister handles storing the received Event data.

type EventPayload

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

EventPayload represents the data from a contract event

func NewEventPayload

func NewEventPayload(eventData interface{}) *EventPayload

NewEventPayload creates a new event payload

func (*EventPayload) Keys

func (p *EventPayload) Keys() []string

Keys retrieves all the available key names in the event payload

func (*EventPayload) ToString

func (p *EventPayload) ToString() string

ToString returns a string representation for the payload

func (*EventPayload) Value

func (p *EventPayload) Value(key string) (*EventPayloadValue, bool)

Value returns the EventPayloadValue of the given key

type EventPayloadValue

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

EventPayloadValue represents a single value for a key in the payload

func (*EventPayloadValue) Address

func (v *EventPayloadValue) Address() (common.Address, bool)

Address returns the value as common.Address Returns bool as false if unable to assert value as type common.Address

func (*EventPayloadValue) BigInt

func (v *EventPayloadValue) BigInt() (*big.Int, bool)

BigInt returns the value as a big.Int Returns bool as false if unable to assert value as type big.Int

func (*EventPayloadValue) Bytes32

func (v *EventPayloadValue) Bytes32() ([32]byte, bool)

Bytes32 returns the value as a bytes32 object Returns bool as false if unable to assert value

func (*EventPayloadValue) Int64

func (v *EventPayloadValue) Int64() (int64, bool)

Int64 returns the value as a int64. Returns bool as false if unable to assert value as type int64

func (*EventPayloadValue) Kind

func (v *EventPayloadValue) Kind() reflect.Kind

Kind returns the value's basic type as described with reflect.Kind

func (*EventPayloadValue) Log

func (v *EventPayloadValue) Log() (*types.Log, bool)

Log returns the value as types.Log Returns bool as false if unable to assert value as type types.Log

func (*EventPayloadValue) String

func (v *EventPayloadValue) String() (string, bool)

String returns the value as a string Returns bool as false if unable to assert value as type string

func (*EventPayloadValue) Val

func (v *EventPayloadValue) Val() interface{}

Val returns the value as an unknown type interface{}

type ListenerMetaDataPersister

type ListenerMetaDataPersister interface {
	// LastBlockNumber returns the last block number seen by the listener for
	// an event type and contract address
	LastBlockNumber(eventType string, contractAddress common.Address) uint64

	// LastBlockHash returns the last block hash seen by the listener for an
	// event type and contract address
	LastBlockHash(eventType string, contractAddress common.Address) common.Hash

	// UpdateLastBlockData should update the last block data from the Event(s)
	UpdateLastBlockData(events []*Event) error
}

ListenerMetaDataPersister handles storing any metadata related to running the listener.

type RetrievalMethod

type RetrievalMethod int

RetrievalMethod is the enum for the type of retrieval method

const (
	// Filterer is the enum value for a retrieval method of type "filterer"
	Filterer RetrievalMethod = iota
	// Watcher is the enum value for a retrieval method of type "watcher"
	Watcher
)

type RetrieveEventsCriteria

type RetrieveEventsCriteria struct {
	Hash            string   `db:"hash"`
	ContractAddress string   `db:"contract_address"`
	Offset          int      `db:"offset"`
	Count           int      `db:"count"`
	ExcludeHashes   []string `db:"exclude_hashes"`
	// Reverse reverses by id in DB
	Reverse   bool   `db:"reverse"`
	FromTs    int64  `db:"fromts"`
	BeforeTs  int64  `db:"beforets"`
	EventType string `db:"eventtype"`
}

RetrieveEventsCriteria contains the retrieval criteria for a RetrieveEvents query.

type RetrieverMetaDataPersister

type RetrieverMetaDataPersister interface {
	// LastBlockNumber returns the last block number seen by the retriever for
	// an event type and contract address
	LastBlockNumber(eventType string, contractAddress common.Address) uint64

	// LastBlockHash returns the last block hash seen by the retriever for an event
	// type and contract address
	LastBlockHash(eventType string, contractAddress common.Address) common.Hash

	// UpdateLastBlockData should update the last block Number from the Event(s)
	UpdateLastBlockData(events []*Event) error
}

RetrieverMetaDataPersister handles storing any metadata related to running the retriever.

type VersionDataPersister

type VersionDataPersister interface {
	// PersisterVersion retrieves the latest version for the table type
	PersisterVersion(tableType string) (string, error)

	// SaveVersion saves the version number for this table type with the current timestamp
	SaveVersion(tableType string, versionNumber string) error

	// OldVersions retrieves all the versions except for most recent for this service name
	OldVersions(serviceName string) ([]string, error)
}

VersionDataPersister handles storing and receiving version table data.

Jump to

Keyboard shortcuts

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