Documentation
¶
Index ¶
- type Database
- type Datastore
- func (d *Datastore) HasParentBlock(ctx context.Context, hash common.Hash) bool
- func (d *Datastore) MaxConcurrentWrites() int
- func (d *Datastore) ShouldWriteBlockEvents() bool
- func (d *Datastore) ShouldWriteBlocks() bool
- func (d *Datastore) ShouldWriteTransactionEvents() bool
- func (d *Datastore) ShouldWriteTransactions() bool
- func (d *Datastore) WriteBlock(ctx context.Context, peer *enode.Node, block *types.Block, td *big.Int)
- func (d *Datastore) WriteBlockBody(ctx context.Context, body *eth.BlockBody, hash common.Hash)
- func (d *Datastore) WriteBlockHashes(ctx context.Context, peer *enode.Node, hashes []common.Hash)
- func (d *Datastore) WriteBlockHeaders(ctx context.Context, headers []*types.Header)
- func (d *Datastore) WriteTransactions(ctx context.Context, peer *enode.Node, txs []*types.Transaction)
- type DatastoreBlock
- type DatastoreEvent
- type DatastoreHeader
- type DatastoreOptions
- type DatastoreTransaction
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Database ¶
type Database interface {
// WriteBlock will write the both the block and block event to the database
// if ShouldWriteBlocks and ShouldWriteBlockEvents return true, respectively.
WriteBlock(context.Context, *enode.Node, *types.Block, *big.Int)
// WriteBlockHeaders will write the block headers if ShouldWriteBlocks
// returns true.
WriteBlockHeaders(context.Context, []*types.Header)
// WriteBlockHashes will write the block hashes if ShouldWriteBlockEvents
// returns true.
WriteBlockHashes(context.Context, *enode.Node, []common.Hash)
// WriteBlockBodies will write the block bodies if ShouldWriteBlocks returns
// true.
WriteBlockBody(context.Context, *eth.BlockBody, common.Hash)
// WriteTransactions will write the both the transaction and transaction
// event to the database if ShouldWriteTransactions and
// ShouldWriteTransactionEvents return true, respectively.
WriteTransactions(context.Context, *enode.Node, []*types.Transaction)
HasParentBlock(context.Context, common.Hash) bool
MaxConcurrentWrites() int
ShouldWriteBlocks() bool
ShouldWriteBlockEvents() bool
ShouldWriteTransactions() bool
ShouldWriteTransactionEvents() 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, opts DatastoreOptions) Database
NewDatastore connects to datastore and creates the client. This should only be called once unless trying to write to different databases.
type Datastore ¶ added in v0.1.28
type Datastore struct {
// contains filtered or unexported fields
}
Datastore wraps the datastore client, stores the sensorID, and other information needed when writing blocks and transactions.
func (*Datastore) HasParentBlock ¶ added in v0.1.28
func (*Datastore) MaxConcurrentWrites ¶ added in v0.1.28
func (*Datastore) ShouldWriteBlockEvents ¶ added in v0.1.28
func (*Datastore) ShouldWriteBlocks ¶ added in v0.1.28
func (*Datastore) ShouldWriteTransactionEvents ¶ added in v0.1.28
func (*Datastore) ShouldWriteTransactions ¶ added in v0.1.28
func (*Datastore) WriteBlock ¶ added in v0.1.28
func (d *Datastore) WriteBlock(ctx context.Context, peer *enode.Node, block *types.Block, td *big.Int)
WriteBlock writes the block and the block event to datastore.
func (*Datastore) WriteBlockBody ¶ added in v0.1.28
WriteBlockHeaders will write the block bodies to datastore. It will not write block events because bodies will only be sent to the sensor when requested. The block events will be written when the hash is received instead. It will write the uncles and transactions to datastore if they don't already exist.
func (*Datastore) WriteBlockHashes ¶ added in v0.1.28
WriteBlockHashes will write the block events to datastore.
func (*Datastore) WriteBlockHeaders ¶ added in v0.1.28
WriteBlockHeaders will write the block headers to datastore. It will not write block events because headers will only be sent to the sensor when requested. The block events will be written when the hash is received instead.
func (*Datastore) WriteTransactions ¶ added in v0.1.28
func (d *Datastore) WriteTransactions(ctx context.Context, peer *enode.Node, txs []*types.Transaction)
WriteTransactions will write the transactions and transaction events to datastore.
type DatastoreBlock ¶
type DatastoreBlock struct {
*DatastoreHeader
TotalDifficulty string
Transactions []*datastore.Key
Uncles []*datastore.Key
}
DatastoreBlock represents a block stored in datastore.
type DatastoreEvent ¶
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 DatastoreOptions ¶ added in v0.1.28
type DatastoreOptions struct {
ProjectID string
SensorID string
MaxConcurrentWrites int
ShouldWriteBlocks bool
ShouldWriteBlockEvents bool
ShouldWriteTransactions bool
ShouldWriteTransactionEvents bool
}
DatastoreOptions is used when creating a NewDatastore.
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.