base

package
v0.0.119 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2023 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package base contains the base sql implementation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ChainIDFieldName gets the chain id field name.
	ChainIDFieldName string
	// DestinationFieldName is the field name of the destination.
	DestinationFieldName string
	// NonceFieldName is the field name of the tx hash.
	NonceFieldName string
	// RootFieldName is the name of the block number field.
	RootFieldName string
	// BlockNumberFieldName is the index field name.
	BlockNumberFieldName string
	// ExecutedFieldName is the executed field name.
	ExecutedFieldName string
	// MinimumTimeSetFieldName is the minimum time set field name.
	MinimumTimeSetFieldName string
	// MinimumTimeFieldName is the minimum time field name.
	MinimumTimeFieldName string
)
View Source
var PageSize = 50_000

PageSize is the amount of entries per page of logs.

Functions

func AttestationToDBAttestation added in v0.0.63

func AttestationToDBAttestation(attestation Attestation) types.DBAttestation

AttestationToDBAttestation converts an Attestation to a DBAttestation.

func GetAllModels

func GetAllModels() (allModels []interface{})

GetAllModels gets all models to migrate see: https://medium.com/@SaifAbid/slice-interfaces-8c78f8b6345d for an explanation of why we can't do this at initialization time

func MessageToDBMessage

func MessageToDBMessage(message Message) types.DBMessage

MessageToDBMessage converts a Message to a DBMessage.

Types

type Attestation added in v0.0.63

type Attestation struct {
	// ChainID is the chain id.
	ChainID uint32 `gorm:"column:chain_id;primaryKey"`
	// Destination is the destination.
	Destination uint32 `gorm:"column:destination;primaryKey"`
	// Nonce is the nonce.
	Nonce uint32 `gorm:"column:nonce;primaryKey"`
	// Root is the root.
	Root string `gorm:"column:root;primaryKey"`
	// DestinationBlockNumber is the block number that the attestation was submitted on the destination.
	DestinationBlockNumber uint64 `gorm:"column:block_number"`
	// DestinationBlockTime is the timestamp of the block that the attestation was submitted on the destination.
	DestinationBlockTime uint64 `gorm:"column:destination_block_time"`
}

Attestation is the information about an attestation parsed by the Executor.

func DBAttestationToAttestation added in v0.0.63

func DBAttestationToAttestation(dbAttestation types.DBAttestation) Attestation

DBAttestationToAttestation converts a DBAttestation to an Attestation.

type Message

type Message struct {
	// ChainID is the chain id.
	ChainID uint32 `gorm:"column:chain_id;primaryKey"`
	// Destination is the destination.
	Destination uint32 `gorm:"column:destination;primaryKey"`
	// Nonce is the nonce.
	Nonce uint32 `gorm:"column:nonce;primaryKey"`
	// Message is the message.
	Message []byte `gorm:"column:message"`
	// BlockNumber is the block number.
	BlockNumber uint64 `gorm:"column:block_number"`
	// Executed is if the message has been executed.
	Executed bool `gorm:"column:executed"`
	// MinimumTimeSet is if the MinimumTime field has been set from an Attestation.
	MinimumTimeSet bool `gorm:"column:minimum_time_set"`
	// MinimumTime is the minimum time that the message can be executed.
	MinimumTime uint64 `gorm:"column:minimum_time"`
}

Message is the information about a message parsed by the Executor.

func AgentsTypesMessageToMessage

func AgentsTypesMessageToMessage(message agentsTypes.Message, blockNumber uint64, minimumTimeSet bool, minimumTime uint64) (Message, error)

AgentsTypesMessageToMessage converts an agentsTypes.Message to a Message.

func DBMessageToMessage

func DBMessageToMessage(dbMessage types.DBMessage) Message

DBMessageToMessage converts a DBMessage to a Message.

type Store

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

Store is the sqlite store. It extends the base store for sqlite specific queries.

func NewStore

func NewStore(db *gorm.DB) *Store

NewStore creates a new store.

func (Store) DB

func (s Store) DB() *gorm.DB

DB gets the database.

func (Store) ExecuteMessage added in v0.0.86

func (s Store) ExecuteMessage(ctx context.Context, messageMask types.DBMessage) error

ExecuteMessage marks a message as executed in the database. TODO: Make batch update.

func (Store) GetAttestation added in v0.0.63

func (s Store) GetAttestation(ctx context.Context, attestationMask types.DBAttestation) (*agentsTypes.Attestation, error)

GetAttestation gets an attestation from the database.

func (Store) GetAttestationBlockNumber added in v0.0.63

func (s Store) GetAttestationBlockNumber(ctx context.Context, attestationMask types.DBAttestation) (*uint64, error)

GetAttestationBlockNumber gets the block number of an attestation.

func (Store) GetAttestationBlockTime added in v0.0.63

func (s Store) GetAttestationBlockTime(ctx context.Context, attestationMask types.DBAttestation) (*uint64, error)

GetAttestationBlockTime gets the block time of an attestation.

func (Store) GetAttestationForNonceOrGreater added in v0.0.86

func (s Store) GetAttestationForNonceOrGreater(ctx context.Context, attestationMask types.DBAttestation) (nonce *uint32, blockTime *uint64, err error)

GetAttestationForNonceOrGreater gets the lowest nonce attestation that is greater than or equal to the given nonce.

func (Store) GetAttestationsAboveOrEqualNonce added in v0.0.86

func (s Store) GetAttestationsAboveOrEqualNonce(ctx context.Context, attestationMask types.DBAttestation, minNonce uint32, page int) ([]types.DBAttestation, error)

GetAttestationsAboveOrEqualNonce gets attestations in a nonce range.

func (Store) GetBlockNumber added in v0.0.63

func (s Store) GetBlockNumber(ctx context.Context, messageMask types.DBMessage) (uint64, error)

GetBlockNumber gets the block number of a message from the database.

func (Store) GetEarliestAttestationsNonceInNonceRange added in v0.0.94

func (s Store) GetEarliestAttestationsNonceInNonceRange(ctx context.Context, attestationMask types.DBAttestation, minNonce uint32, maxNonce uint32) (*uint32, error)

GetEarliestAttestationsNonceInNonceRange gets the earliest attestation (by block number) in a nonce range.

func (Store) GetExecutableMessages added in v0.0.86

func (s Store) GetExecutableMessages(ctx context.Context, messageMask types.DBMessage, currentTime uint64, page int) ([]agentsTypes.Message, error)

GetExecutableMessages gets executable messages from the database.

func (Store) GetLastBlockNumber

func (s Store) GetLastBlockNumber(ctx context.Context, chainID uint32) (uint64, error)

GetLastBlockNumber gets the last block number that had a message in the database.

func (Store) GetMessage

func (s Store) GetMessage(ctx context.Context, messageMask types.DBMessage) (*agentsTypes.Message, error)

GetMessage gets a message from the database.

func (Store) GetMessageMinimumTime added in v0.0.86

func (s Store) GetMessageMinimumTime(ctx context.Context, messageMask types.DBMessage) (*uint64, error)

GetMessageMinimumTime gets the minimum time for a message to be executed.

func (Store) GetMessages

func (s Store) GetMessages(ctx context.Context, messageMask types.DBMessage, page int) ([]agentsTypes.Message, error)

GetMessages gets messages from the database, paginated and ordered in ascending order by nonce.

func (Store) GetUnsetMinimumTimeMessages added in v0.0.86

func (s Store) GetUnsetMinimumTimeMessages(ctx context.Context, messageMask types.DBMessage, page int) ([]agentsTypes.Message, error)

GetUnsetMinimumTimeMessages gets messages from the database that have not had their minimum time set.

func (Store) SetMinimumTime added in v0.0.86

func (s Store) SetMinimumTime(ctx context.Context, messageMask types.DBMessage, minimumTime uint64) error

SetMinimumTime sets the minimum time of a message.

func (Store) StoreAttestation added in v0.0.63

func (s Store) StoreAttestation(ctx context.Context, attestation agentsTypes.Attestation, blockNumber uint64, blockTime uint64) error

StoreAttestation stores an attestation.

func (Store) StoreMessage

func (s Store) StoreMessage(ctx context.Context, message agentsTypes.Message, blockNumber uint64, minimumTimeSet bool, minimumTime uint64) error

StoreMessage stores a message in the database.

Jump to

Keyboard shortcuts

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