Documentation
¶
Index ¶
- type CachedValue
- type CapabilityManager
- type ChainCache
- func (cc *ChainCache) GetBaseFee(currentBlock *big.Int) (*big.Int, bool)
- func (cc *ChainCache) GetChainID() (*big.Int, bool)
- func (cc *ChainCache) GetClientVersion() (string, bool)
- func (cc *ChainCache) GetFeeHistory(ttl time.Duration) (*FeeHistoryResult, bool)
- func (cc *ChainCache) GetFinalizedBlock(ttl time.Duration) (*big.Int, bool)
- func (cc *ChainCache) GetGasPrice(ttl time.Duration) (*big.Int, bool)
- func (cc *ChainCache) GetPendingTxCount(ttl time.Duration) (*big.Int, bool)
- func (cc *ChainCache) GetQueuedTxCount(ttl time.Duration) (*big.Int, bool)
- func (cc *ChainCache) GetSafeBlock(ttl time.Duration) (*big.Int, bool)
- func (cc *ChainCache) GetSignatures(hexSignature string, ttl time.Duration) ([]Signature, bool)
- func (cc *ChainCache) GetSyncStatus(ttl time.Duration) (any, bool)
- func (cc *ChainCache) SetBaseFee(baseFee *big.Int, blockNumber *big.Int)
- func (cc *ChainCache) SetChainID(chainID *big.Int)
- func (cc *ChainCache) SetClientVersion(clientVersion string)
- func (cc *ChainCache) SetFeeHistory(feeHistory *FeeHistoryResult, ttl time.Duration)
- func (cc *ChainCache) SetFinalizedBlock(block *big.Int, ttl time.Duration)
- func (cc *ChainCache) SetGasPrice(gasPrice *big.Int, ttl time.Duration)
- func (cc *ChainCache) SetPendingTxCount(count *big.Int, ttl time.Duration)
- func (cc *ChainCache) SetQueuedTxCount(count *big.Int, ttl time.Duration)
- func (cc *ChainCache) SetSafeBlock(block *big.Int, ttl time.Duration)
- func (cc *ChainCache) SetSignatures(hexSignature string, signatures []Signature, ttl time.Duration)
- func (cc *ChainCache) SetSyncStatus(syncStatus any, ttl time.Duration)
- type ChainStore
- type ChainStoreConfig
- type FeeHistoryResult
- type PassthroughStore
- func (s *PassthroughStore) Close() error
- func (s *PassthroughStore) GetBaseFee(ctx context.Context) (*big.Int, error)
- func (s *PassthroughStore) GetBaseFeeForBlock(ctx context.Context, blockNumber *big.Int) (*big.Int, error)
- func (s *PassthroughStore) GetBlock(ctx context.Context, blockHashOrNumber any) (rpctypes.PolyBlock, error)
- func (s *PassthroughStore) GetBlockByHash(ctx context.Context, hash common.Hash) (rpctypes.PolyBlock, error)
- func (s *PassthroughStore) GetBlockByNumber(ctx context.Context, number *big.Int) (rpctypes.PolyBlock, error)
- func (s *PassthroughStore) GetChainID(ctx context.Context) (*big.Int, error)
- func (s *PassthroughStore) GetClientVersion(ctx context.Context) (string, error)
- func (s *PassthroughStore) GetFeeHistory(ctx context.Context, blockCount int, newestBlock string, ...) (*FeeHistoryResult, error)
- func (s *PassthroughStore) GetFinalizedBlock(ctx context.Context) (*big.Int, error)
- func (s *PassthroughStore) GetGasPrice(ctx context.Context) (*big.Int, error)
- func (s *PassthroughStore) GetLatestBlock(ctx context.Context) (rpctypes.PolyBlock, error)
- func (s *PassthroughStore) GetNetPeerCount(ctx context.Context) (*big.Int, error)
- func (s *PassthroughStore) GetPendingTransactionCount(ctx context.Context) (*big.Int, error)
- func (s *PassthroughStore) GetQueuedTransactionCount(ctx context.Context) (*big.Int, error)
- func (s *PassthroughStore) GetRPCURL() string
- func (s *PassthroughStore) GetReceipt(ctx context.Context, txHash common.Hash) (rpctypes.PolyReceipt, error)
- func (s *PassthroughStore) GetSafeBlock(ctx context.Context) (*big.Int, error)
- func (s *PassthroughStore) GetSignature(ctx context.Context, hexSignature string) ([]Signature, error)
- func (s *PassthroughStore) GetSupportedMethods() []string
- func (s *PassthroughStore) GetSyncStatus(ctx context.Context) (any, error)
- func (s *PassthroughStore) GetTransaction(ctx context.Context, txHash common.Hash) (rpctypes.PolyTransaction, error)
- func (s *PassthroughStore) GetTxPoolStatus(ctx context.Context) (map[string]any, error)
- func (s *PassthroughStore) IsMethodSupported(method string) bool
- func (s *PassthroughStore) MeasureConnectionLatency(ctx context.Context) (time.Duration, error)
- func (s *PassthroughStore) RefreshCapabilities(ctx context.Context) error
- type Signature
- type SignatureResponse
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CachedValue ¶
type CachedValue[T any] struct { // contains filtered or unexported fields }
CachedValue represents a cached value with TTL
func NewCachedValue ¶
func NewCachedValue[T any](value T, ttl time.Duration) *CachedValue[T]
NewCachedValue creates a new cached value
func (*CachedValue[T]) Get ¶
func (cv *CachedValue[T]) Get() (T, bool)
Get returns the cached value and whether it's valid
func (*CachedValue[T]) IsValid ¶
func (cv *CachedValue[T]) IsValid() bool
IsValid returns true if the cached value is still valid
type CapabilityManager ¶
type CapabilityManager struct {
// contains filtered or unexported fields
}
CapabilityManager manages RPC method capability detection
func NewCapabilityManager ¶
func NewCapabilityManager(client *rpc.Client, ttl time.Duration) *CapabilityManager
NewCapabilityManager creates a new capability manager
func (*CapabilityManager) GetSupportedMethods ¶
func (cm *CapabilityManager) GetSupportedMethods() []string
GetSupportedMethods returns all supported methods
func (*CapabilityManager) IsMethodSupported ¶
func (cm *CapabilityManager) IsMethodSupported(method string) bool
IsMethodSupported checks if a method is supported
func (*CapabilityManager) RefreshCapabilities ¶
func (cm *CapabilityManager) RefreshCapabilities(ctx context.Context) error
RefreshCapabilities tests and caches method capabilities
type ChainCache ¶
type ChainCache struct {
// contains filtered or unexported fields
}
ChainCache manages cached chain information with different TTLs
func (*ChainCache) GetBaseFee ¶
GetBaseFee gets cached base fee
func (*ChainCache) GetChainID ¶
func (cc *ChainCache) GetChainID() (*big.Int, bool)
GetChainID gets cached chain ID
func (*ChainCache) GetClientVersion ¶
func (cc *ChainCache) GetClientVersion() (string, bool)
GetClientVersion gets cached client version
func (*ChainCache) GetFeeHistory ¶
func (cc *ChainCache) GetFeeHistory(ttl time.Duration) (*FeeHistoryResult, bool)
GetFeeHistory gets cached fee history
func (*ChainCache) GetFinalizedBlock ¶
GetFinalizedBlock gets cached finalized block
func (*ChainCache) GetGasPrice ¶
GetGasPrice gets cached gas price
func (*ChainCache) GetPendingTxCount ¶
GetPendingTxCount gets cached pending transaction count
func (*ChainCache) GetQueuedTxCount ¶
GetQueuedTxCount gets cached queued transaction count
func (*ChainCache) GetSafeBlock ¶
GetSafeBlock gets cached safe block
func (*ChainCache) GetSignatures ¶
GetSignatures gets cached signatures for a hex signature
func (*ChainCache) GetSyncStatus ¶
func (cc *ChainCache) GetSyncStatus(ttl time.Duration) (any, bool)
GetSyncStatus gets cached sync status
func (*ChainCache) SetBaseFee ¶
func (cc *ChainCache) SetBaseFee(baseFee *big.Int, blockNumber *big.Int)
SetBaseFee caches base fee for a specific block
func (*ChainCache) SetChainID ¶
func (cc *ChainCache) SetChainID(chainID *big.Int)
SetChainID caches chain ID (never expires)
func (*ChainCache) SetClientVersion ¶
func (cc *ChainCache) SetClientVersion(clientVersion string)
SetClientVersion caches client version (never expires)
func (*ChainCache) SetFeeHistory ¶
func (cc *ChainCache) SetFeeHistory(feeHistory *FeeHistoryResult, ttl time.Duration)
SetFeeHistory caches fee history
func (*ChainCache) SetFinalizedBlock ¶
func (cc *ChainCache) SetFinalizedBlock(block *big.Int, ttl time.Duration)
SetFinalizedBlock caches finalized block
func (*ChainCache) SetGasPrice ¶
func (cc *ChainCache) SetGasPrice(gasPrice *big.Int, ttl time.Duration)
SetGasPrice caches gas price
func (*ChainCache) SetPendingTxCount ¶
func (cc *ChainCache) SetPendingTxCount(count *big.Int, ttl time.Duration)
SetPendingTxCount caches pending transaction count
func (*ChainCache) SetQueuedTxCount ¶
func (cc *ChainCache) SetQueuedTxCount(count *big.Int, ttl time.Duration)
SetQueuedTxCount caches queued transaction count
func (*ChainCache) SetSafeBlock ¶
func (cc *ChainCache) SetSafeBlock(block *big.Int, ttl time.Duration)
SetSafeBlock caches safe block
func (*ChainCache) SetSignatures ¶
func (cc *ChainCache) SetSignatures(hexSignature string, signatures []Signature, ttl time.Duration)
SetSignatures caches signatures for a hex signature
func (*ChainCache) SetSyncStatus ¶
func (cc *ChainCache) SetSyncStatus(syncStatus any, ttl time.Duration)
SetSyncStatus caches sync status with TTL
type ChainStore ¶
type ChainStore interface {
// GetBlock retrieves a block by hash or number
GetBlock(ctx context.Context, blockHashOrNumber any) (rpctypes.PolyBlock, error)
// GetTransaction retrieves a transaction by hash
GetTransaction(ctx context.Context, txHash common.Hash) (rpctypes.PolyTransaction, error)
// GetReceipt retrieves a transaction receipt by transaction hash
GetReceipt(ctx context.Context, txHash common.Hash) (rpctypes.PolyReceipt, error)
// GetLatestBlock retrieves the most recent block
GetLatestBlock(ctx context.Context) (rpctypes.PolyBlock, error)
// GetBlockByNumber retrieves a block by its number
GetBlockByNumber(ctx context.Context, number *big.Int) (rpctypes.PolyBlock, error)
// GetBlockByHash retrieves a block by its hash
GetBlockByHash(ctx context.Context, hash common.Hash) (rpctypes.PolyBlock, error)
// Static info (fetch once, cache indefinitely)
GetChainID(ctx context.Context) (*big.Int, error)
GetClientVersion(ctx context.Context) (string, error)
// Semi-static info (cache for minutes)
GetSyncStatus(ctx context.Context) (any, error)
GetSafeBlock(ctx context.Context) (*big.Int, error)
GetFinalizedBlock(ctx context.Context) (*big.Int, error)
// Block-aligned info (cache per block)
GetBaseFee(ctx context.Context) (*big.Int, error)
GetBaseFeeForBlock(ctx context.Context, blockNumber *big.Int) (*big.Int, error)
// Frequent info (cache for seconds)
GetGasPrice(ctx context.Context) (*big.Int, error)
GetFeeHistory(ctx context.Context, blockCount int, newestBlock string, rewardPercentiles []float64) (*FeeHistoryResult, error)
// Very frequent info (minimal cache)
GetPendingTransactionCount(ctx context.Context) (*big.Int, error)
GetQueuedTransactionCount(ctx context.Context) (*big.Int, error)
GetTxPoolStatus(ctx context.Context) (map[string]any, error)
GetNetPeerCount(ctx context.Context) (*big.Int, error)
// === CAPABILITY & MANAGEMENT ===
IsMethodSupported(method string) bool
RefreshCapabilities(ctx context.Context) error
GetSupportedMethods() []string
// === CONNECTION INFO ===
GetRPCURL() string
MeasureConnectionLatency(ctx context.Context) (time.Duration, error)
// === SIGNATURE LOOKUP ===
// GetSignature retrieves function/event signatures from 4byte.directory
GetSignature(ctx context.Context, hexSignature string) ([]Signature, error)
// Close closes the store and releases any resources
Close() error
}
ChainStore defines the unified interface for storing and retrieving all chain-related data
type ChainStoreConfig ¶
type ChainStoreConfig struct {
// Cache TTLs for different data types
StaticTTL time.Duration // Never expire (0)
SemiStaticTTL time.Duration // 5 minutes
FrequentTTL time.Duration // 30 seconds
VeryFrequentTTL time.Duration // 5 seconds
// Capability detection
CapabilityTTL time.Duration // 1 hour
// Feature toggles
EnableTxPoolMonitoring bool
EnableFinalityTracking bool
EnableFeeHistoryTracking bool
// Signature lookup configuration
EnableSignatureLookup bool // Enable 4byte.directory lookups
SignatureLookupTTL time.Duration // Cache TTL for signatures (1 hour)
SignatureLookupTimeout time.Duration // HTTP timeout for API calls (5 seconds)
SignatureLookupAPIURL string // 4byte.directory function signatures API endpoint
EventSignatureLookupAPIURL string // 4byte.directory event signatures API endpoint
}
ChainStoreConfig holds configuration for the ChainStore
func DefaultChainStoreConfig ¶
func DefaultChainStoreConfig() *ChainStoreConfig
DefaultChainStoreConfig returns default configuration
type FeeHistoryResult ¶
type FeeHistoryResult struct {
OldestBlock *big.Int `json:"oldestBlock"`
BaseFeePerGas []*big.Int `json:"baseFeePerGas"`
GasUsedRatio []float64 `json:"gasUsedRatio"`
Reward [][]*big.Int `json:"reward,omitempty"`
}
FeeHistoryResult represents the result of eth_feeHistory
type PassthroughStore ¶
type PassthroughStore struct {
// contains filtered or unexported fields
}
PassthroughStore is a chainstore implementation that doesn't store anything and passes through requests directly to the RPC endpoint with caching
func NewPassthroughStore ¶
func NewPassthroughStore(rpcURL string) (*PassthroughStore, error)
NewPassthroughStore creates a new passthrough store with the given RPC client
func NewPassthroughStoreWithConfig ¶
func NewPassthroughStoreWithConfig(rpcURL string, config *ChainStoreConfig) (*PassthroughStore, error)
NewPassthroughStoreWithConfig creates a new passthrough store with custom configuration
func (*PassthroughStore) Close ¶
func (s *PassthroughStore) Close() error
Close closes the store and releases any resources
func (*PassthroughStore) GetBaseFee ¶
GetBaseFee retrieves the current base fee (cached per block)
func (*PassthroughStore) GetBaseFeeForBlock ¶
func (s *PassthroughStore) GetBaseFeeForBlock(ctx context.Context, blockNumber *big.Int) (*big.Int, error)
GetBaseFeeForBlock retrieves the base fee for a specific block
func (*PassthroughStore) GetBlock ¶
func (s *PassthroughStore) GetBlock(ctx context.Context, blockHashOrNumber any) (rpctypes.PolyBlock, error)
GetBlock retrieves a block by hash or number
func (*PassthroughStore) GetBlockByHash ¶
func (s *PassthroughStore) GetBlockByHash(ctx context.Context, hash common.Hash) (rpctypes.PolyBlock, error)
GetBlockByHash retrieves a block by its hash
func (*PassthroughStore) GetBlockByNumber ¶
func (s *PassthroughStore) GetBlockByNumber(ctx context.Context, number *big.Int) (rpctypes.PolyBlock, error)
GetBlockByNumber retrieves a block by its number
func (*PassthroughStore) GetChainID ¶
GetChainID retrieves the chain ID (cached indefinitely)
func (*PassthroughStore) GetClientVersion ¶
func (s *PassthroughStore) GetClientVersion(ctx context.Context) (string, error)
GetClientVersion retrieves the client version (cached indefinitely)
func (*PassthroughStore) GetFeeHistory ¶
func (s *PassthroughStore) GetFeeHistory(ctx context.Context, blockCount int, newestBlock string, rewardPercentiles []float64) (*FeeHistoryResult, error)
GetFeeHistory retrieves fee history (cached frequently)
func (*PassthroughStore) GetFinalizedBlock ¶
GetFinalizedBlock retrieves the finalized block number (cached semi-statically)
func (*PassthroughStore) GetGasPrice ¶
GetGasPrice retrieves the current gas price (cached frequently)
func (*PassthroughStore) GetLatestBlock ¶
GetLatestBlock retrieves the most recent block
func (*PassthroughStore) GetNetPeerCount ¶
GetNetPeerCount retrieves the number of connected peers (cached very frequently)
func (*PassthroughStore) GetPendingTransactionCount ¶
GetPendingTransactionCount retrieves pending transaction count (cached very frequently)
func (*PassthroughStore) GetQueuedTransactionCount ¶
GetQueuedTransactionCount retrieves queued transaction count (cached very frequently)
func (*PassthroughStore) GetRPCURL ¶
func (s *PassthroughStore) GetRPCURL() string
GetRPCURL returns the RPC endpoint URL
func (*PassthroughStore) GetReceipt ¶
func (s *PassthroughStore) GetReceipt(ctx context.Context, txHash common.Hash) (rpctypes.PolyReceipt, error)
GetReceipt retrieves a transaction receipt by transaction hash
func (*PassthroughStore) GetSafeBlock ¶
GetSafeBlock retrieves the safe block number (cached semi-statically)
func (*PassthroughStore) GetSignature ¶
func (s *PassthroughStore) GetSignature(ctx context.Context, hexSignature string) ([]Signature, error)
GetSignature retrieves function/event signatures from 4byte.directory
func (*PassthroughStore) GetSupportedMethods ¶
func (s *PassthroughStore) GetSupportedMethods() []string
GetSupportedMethods returns all supported methods
func (*PassthroughStore) GetSyncStatus ¶
func (s *PassthroughStore) GetSyncStatus(ctx context.Context) (any, error)
GetSyncStatus retrieves the sync status (cached semi-statically)
func (*PassthroughStore) GetTransaction ¶
func (s *PassthroughStore) GetTransaction(ctx context.Context, txHash common.Hash) (rpctypes.PolyTransaction, error)
GetTransaction retrieves a transaction by hash
func (*PassthroughStore) GetTxPoolStatus ¶
GetTxPoolStatus retrieves the full txpool status (cached very frequently)
func (*PassthroughStore) IsMethodSupported ¶
func (s *PassthroughStore) IsMethodSupported(method string) bool
IsMethodSupported checks if a method is supported
func (*PassthroughStore) MeasureConnectionLatency ¶
MeasureConnectionLatency measures the connection latency to the RPC endpoint
func (*PassthroughStore) RefreshCapabilities ¶
func (s *PassthroughStore) RefreshCapabilities(ctx context.Context) error
RefreshCapabilities refreshes the capability cache
type Signature ¶
type Signature struct {
ID int `json:"id"`
CreatedAt time.Time `json:"created_at"`
TextSignature string `json:"text_signature"`
HexSignature string `json:"hex_signature"`
BytesSignature string `json:"bytes_signature"`
}
Signature represents a function or event signature from 4byte.directory