database

package
v0.1.22 Latest Latest
Warning

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

Go to latest
Published: May 16, 2023 License: AGPL-3.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Database

type Database interface {
	WriteBlock(context.Context, *enode.Node, *types.Block)
	WriteBlockHeaders(context.Context, []*types.Header)
	WriteBlockHashes(context.Context, *enode.Node, []common.Hash)
	WriteBlockBody(context.Context, *eth.BlockBody, common.Hash)
	WriteTransactions(context.Context, *enode.Node, []*types.Transaction)

	MaxConcurrentWrites() int
	ShouldWriteBlocks() bool
	ShouldWriteTransactions() bool
}

Database represents a database solution to write block and transaction data to. To use another database solution, just implement these methods and update the sensor to use the new connection.

func NewDatastore

func NewDatastore(ctx context.Context, projectID string, sensorID string, maxConcurrentWrites int, shouldWriteBlocks bool, shouldWriteTransactions bool) Database

NewDatastore connects to datastore and creates the client. This should only be called once unless trying to write to different databases.

type DatastoreBlock

type DatastoreBlock struct {
	*DatastoreHeader
	Transactions []*datastore.Key
	Uncles       []*datastore.Key
}

DatastoreBlock represents a block stored in datastore.

type DatastoreEvent

type DatastoreEvent struct {
	SensorId string
	PeerId   string
	Hash     *datastore.Key
	Time     time.Time
}

DatastoreEvent can represent a peer sending the sensor a transaction hash or a block hash. In this implementation, the block and transactions are written to different tables by specifying a kind during key creation see writeEvents for more.

type DatastoreHeader

type DatastoreHeader struct {
	ParentHash  *datastore.Key
	UncleHash   string
	Coinbase    string
	Root        string
	TxHash      string
	ReceiptHash string
	Bloom       []byte
	Difficulty  string
	Number      string
	GasLimit    string
	GasUsed     string
	Time        time.Time
	Extra       []byte
	MixDigest   string
	Nonce       string
	BaseFee     string
}

DatastoreHeader stores the data in manner that can be easily written without loss of precision.

type DatastoreTransaction

type DatastoreTransaction struct {
	Data      []byte `datastore:",noindex"`
	From      string
	Gas       string
	GasFeeCap string
	GasPrice  string
	GasTipCap string
	Nonce     string
	To        string
	Value     string
	V, R, S   string
	Time      time.Time
	Type      int16
}

DatastoreTransaction represents a transaction stored in datastore. Data is not indexed because there is a max sized for indexed byte slices, which Data will occasionally exceed.

Jump to

Keyboard shortcuts

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