Documentation
¶
Index ¶
- Constants
- type Database
- type Datastore
- func (d *Datastore) HasBlock(ctx context.Context, hash common.Hash) bool
- func (d *Datastore) MaxConcurrentWrites() int
- func (d *Datastore) NodeList(ctx context.Context, limit int) ([]string, error)
- func (d *Datastore) ShouldWriteBlockEvents() bool
- func (d *Datastore) ShouldWriteBlocks() bool
- func (d *Datastore) ShouldWritePeers() 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, tfs time.Time)
- func (d *Datastore) WriteBlockHashes(ctx context.Context, peer *enode.Node, hashes []common.Hash, tfs time.Time)
- func (d *Datastore) WriteBlockHeaders(ctx context.Context, headers []*types.Header, tfs time.Time)
- func (d *Datastore) WritePeers(ctx context.Context, peers []*p2p.Peer, tls time.Time)
- func (d *Datastore) WriteTransactions(ctx context.Context, peer *enode.Node, txs []*types.Transaction, tfs time.Time)
- type DatastoreBlock
- type DatastoreEvent
- type DatastoreHeader
- type DatastoreOptions
- type DatastorePeer
- type DatastoreTransaction
- type JSONBlock
- type JSONBlockEvent
- type JSONDatabase
- func (j *JSONDatabase) HasBlock(ctx context.Context, hash common.Hash) bool
- func (j *JSONDatabase) MaxConcurrentWrites() int
- func (j *JSONDatabase) NodeList(ctx context.Context, limit int) ([]string, error)
- func (j *JSONDatabase) ShouldWriteBlockEvents() bool
- func (j *JSONDatabase) ShouldWriteBlocks() bool
- func (j *JSONDatabase) ShouldWritePeers() bool
- func (j *JSONDatabase) ShouldWriteTransactionEvents() bool
- func (j *JSONDatabase) ShouldWriteTransactions() bool
- func (j *JSONDatabase) Write(v any)
- func (j *JSONDatabase) WriteBlock(_ context.Context, peer *enode.Node, block *types.Block, td *big.Int, ...)
- func (j *JSONDatabase) WriteBlockBody(ctx context.Context, body *eth.BlockBody, hash common.Hash, tfs time.Time)
- func (j *JSONDatabase) WriteBlockHashes(ctx context.Context, peer *enode.Node, hashes []common.Hash, tfs time.Time)
- func (j *JSONDatabase) WriteBlockHeaders(ctx context.Context, headers []*types.Header, tfs time.Time)
- func (j *JSONDatabase) WritePeers(ctx context.Context, peers []*p2p.Peer, tls time.Time)
- func (j *JSONDatabase) WriteTransactions(_ context.Context, peer *enode.Node, txs []*types.Transaction, tfs time.Time)
- type JSONDatabaseOptions
- type JSONPeer
- type JSONTransaction
- type JSONTransactionEvent
Constants ¶
const ( // Kinds are the datastore equivalent of tables. BlocksKind = "blocks" BlockEventsKind = "block_events" TransactionsKind = "transactions" TransactionEventsKind = "transaction_events" PeersKind = "peers" MaxAttempts = 3 )
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, time.Time)
// WriteBlockHeaders will write the block headers if ShouldWriteBlocks
// returns true.
WriteBlockHeaders(context.Context, []*types.Header, time.Time)
// WriteBlockHashes will write the block hashes if ShouldWriteBlockEvents
// returns true.
WriteBlockHashes(context.Context, *enode.Node, []common.Hash, time.Time)
// WriteBlockBody will write the block bodies if ShouldWriteBlocks returns
// true.
WriteBlockBody(context.Context, *eth.BlockBody, common.Hash, time.Time)
// 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, time.Time)
// WritePeers will write the connected peers to the database.
WritePeers(context.Context, []*p2p.Peer, time.Time)
// HasBlock will return whether the block is in the database. If the database
// client has not been initialized this will always return true.
HasBlock(context.Context, common.Hash) bool
MaxConcurrentWrites() int
ShouldWriteBlocks() bool
ShouldWriteBlockEvents() bool
ShouldWriteTransactions() bool
ShouldWriteTransactionEvents() bool
ShouldWritePeers() bool
// NodeList will return a list of enode URLs.
NodeList(ctx context.Context, limit int) ([]string, error)
}
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.
func NewJSONDatabase ¶ added in v0.1.88
func NewJSONDatabase(opts JSONDatabaseOptions) Database
NewJSONDatabase creates a new JSONDatabase instance.
func NoDatabase ¶ added in v0.1.88
func NoDatabase() Database
NoDatabase creates a new nodb instance.
type Datastore ¶
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) MaxConcurrentWrites ¶
func (*Datastore) ShouldWriteBlockEvents ¶
func (*Datastore) ShouldWriteBlocks ¶
func (*Datastore) ShouldWritePeers ¶
func (*Datastore) ShouldWriteTransactionEvents ¶
func (*Datastore) ShouldWriteTransactions ¶
func (*Datastore) WriteBlock ¶
func (d *Datastore) WriteBlock(ctx context.Context, peer *enode.Node, block *types.Block, td *big.Int, tfs time.Time)
WriteBlock writes the block and the block event to datastore.
func (*Datastore) WriteBlockBody ¶
func (d *Datastore) WriteBlockBody(ctx context.Context, body *eth.BlockBody, hash common.Hash, tfs time.Time)
WriteBlockBody 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 ¶
func (d *Datastore) WriteBlockHashes(ctx context.Context, peer *enode.Node, hashes []common.Hash, tfs time.Time)
WriteBlockHashes will write the block events to datastore.
func (*Datastore) WriteBlockHeaders ¶
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) WritePeers ¶
WritePeers writes the connected peers 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 ¶
type DatastoreEvent struct {
SensorId string
PeerId string
Hash *datastore.Key
Time time.Time
TTL 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 `datastore:",noindex"`
Difficulty string
Number string
GasLimit string
GasUsed string
Time time.Time
Extra []byte `datastore:",noindex"`
MixDigest string
Nonce string
BaseFee string
TimeFirstSeen time.Time
TTL time.Time
}
DatastoreHeader stores the data in manner that can be easily written without loss of precision.
type DatastoreOptions ¶
type DatastoreOptions struct {
ProjectID string
DatabaseID string
SensorID string
ChainID uint64
MaxConcurrency int
ShouldWriteBlocks bool
ShouldWriteBlockEvents bool
ShouldWriteTransactions bool
ShouldWriteTransactionEvents bool
ShouldWritePeers bool
TTL time.Duration
}
DatastoreOptions is used when creating a NewDatastore.
type DatastorePeer ¶
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
TimeFirstSeen time.Time
TTL 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.
type JSONBlock ¶ added in v0.1.88
type JSONBlock struct {
Type string `json:"type"`
SensorID string `json:"sensor_id"`
Hash string `json:"hash"`
ParentHash string `json:"parent_hash"`
Number uint64 `json:"number"`
Timestamp uint64 `json:"timestamp"`
GasLimit uint64 `json:"gas_limit"`
GasUsed uint64 `json:"gas_used"`
Difficulty string `json:"difficulty,omitempty"`
TotalDifficulty string `json:"total_difficulty,omitempty"`
BaseFee string `json:"base_fee,omitempty"`
TxCount int `json:"tx_count"`
UncleCount int `json:"uncle_count"`
TimeFirstSeen time.Time `json:"time_first_seen"`
}
JSONBlock represents a block in JSON format.
type JSONBlockEvent ¶ added in v0.1.88
type JSONBlockEvent struct {
Type string `json:"type"`
SensorID string `json:"sensor_id"`
PeerID string `json:"peer_id"`
Hash string `json:"hash"`
Timestamp time.Time `json:"timestamp"`
}
JSONBlockEvent represents a block event in JSON format.
type JSONDatabase ¶ added in v0.1.88
type JSONDatabase struct {
// contains filtered or unexported fields
}
JSONDatabase outputs data as JSON to stdout. Each record is output as a single line of JSON (newline-delimited JSON).
func (*JSONDatabase) HasBlock ¶ added in v0.1.88
HasBlock always returns true to avoid unnecessary parent block fetching for JSON output.
func (*JSONDatabase) MaxConcurrentWrites ¶ added in v0.1.88
func (j *JSONDatabase) MaxConcurrentWrites() int
MaxConcurrentWrites returns the max concurrency.
func (*JSONDatabase) NodeList ¶ added in v0.1.88
NodeList returns an empty list as JSON database doesn't store nodes.
func (*JSONDatabase) ShouldWriteBlockEvents ¶ added in v0.1.88
func (j *JSONDatabase) ShouldWriteBlockEvents() bool
ShouldWriteBlockEvents returns the configured value.
func (*JSONDatabase) ShouldWriteBlocks ¶ added in v0.1.88
func (j *JSONDatabase) ShouldWriteBlocks() bool
ShouldWriteBlocks returns the configured value.
func (*JSONDatabase) ShouldWritePeers ¶ added in v0.1.88
func (j *JSONDatabase) ShouldWritePeers() bool
ShouldWritePeers returns the configured value.
func (*JSONDatabase) ShouldWriteTransactionEvents ¶ added in v0.1.88
func (j *JSONDatabase) ShouldWriteTransactionEvents() bool
ShouldWriteTransactionEvents returns the configured value.
func (*JSONDatabase) ShouldWriteTransactions ¶ added in v0.1.88
func (j *JSONDatabase) ShouldWriteTransactions() bool
ShouldWriteTransactions returns the configured value.
func (*JSONDatabase) Write ¶ added in v0.1.88
func (j *JSONDatabase) Write(v any)
Write safely outputs JSON to stdout.
func (*JSONDatabase) WriteBlock ¶ added in v0.1.88
func (j *JSONDatabase) WriteBlock(_ context.Context, peer *enode.Node, block *types.Block, td *big.Int, tfs time.Time)
WriteBlock writes the block and the block event as JSON.
func (*JSONDatabase) WriteBlockBody ¶ added in v0.1.88
func (j *JSONDatabase) WriteBlockBody(ctx context.Context, body *eth.BlockBody, hash common.Hash, tfs time.Time)
WriteBlockBody writes the block body as JSON.
func (*JSONDatabase) WriteBlockHashes ¶ added in v0.1.88
func (j *JSONDatabase) WriteBlockHashes(ctx context.Context, peer *enode.Node, hashes []common.Hash, tfs time.Time)
WriteBlockHashes writes the block events as JSON.
func (*JSONDatabase) WriteBlockHeaders ¶ added in v0.1.88
func (j *JSONDatabase) WriteBlockHeaders(ctx context.Context, headers []*types.Header, tfs time.Time)
WriteBlockHeaders writes the block headers as JSON.
func (*JSONDatabase) WritePeers ¶ added in v0.1.88
WritePeers writes the connected peers as JSON.
func (*JSONDatabase) WriteTransactions ¶ added in v0.1.88
func (j *JSONDatabase) WriteTransactions(_ context.Context, peer *enode.Node, txs []*types.Transaction, tfs time.Time)
WriteTransactions writes the transactions and transaction events as JSON.
type JSONDatabaseOptions ¶ added in v0.1.88
type JSONDatabaseOptions struct {
SensorID string
ChainID uint64
MaxConcurrency int
ShouldWriteBlocks bool
ShouldWriteBlockEvents bool
ShouldWriteTransactions bool
ShouldWriteTransactionEvents bool
ShouldWritePeers bool
}
JSONDatabaseOptions is used when creating a NewJSONDatabase.
type JSONPeer ¶ added in v0.1.88
type JSONPeer struct {
Type string `json:"type"`
SensorID string `json:"sensor_id"`
ID string `json:"id"`
Name string `json:"name"`
URL string `json:"url"`
Caps []string `json:"caps"`
TimeLastSeen time.Time `json:"time_last_seen"`
}
JSONPeer represents a peer in JSON format.
type JSONTransaction ¶ added in v0.1.88
type JSONTransaction struct {
Type string `json:"type"`
SensorID string `json:"sensor_id"`
Hash string `json:"hash"`
From string `json:"from,omitempty"`
To string `json:"to,omitempty"`
Value string `json:"value"`
Gas uint64 `json:"gas"`
GasPrice string `json:"gas_price"`
GasFeeCap string `json:"gas_fee_cap,omitempty"`
GasTipCap string `json:"gas_tip_cap,omitempty"`
Nonce uint64 `json:"nonce"`
TxType uint8 `json:"tx_type"`
TimeFirstSeen time.Time `json:"time_first_seen"`
}
JSONTransaction represents a transaction in JSON format.
type JSONTransactionEvent ¶ added in v0.1.88
type JSONTransactionEvent struct {
Type string `json:"type"`
SensorID string `json:"sensor_id"`
PeerID string `json:"peer_id"`
Hash string `json:"hash"`
Timestamp time.Time `json:"timestamp"`
}
JSONTransactionEvent represents a transaction event in JSON format.