use crate::types::GasPrice;
use fuel_core_services::stream::BoxStream;
use fuel_core_storage::Result as StorageResult;
use fuel_core_types::{
entities::{
coins::coin::CompressedCoin,
relayer::message::Message,
},
fuel_tx::{
ConsensusParameters,
Transaction,
UtxoId,
},
fuel_types::{
BlockHeight,
ContractId,
Nonce,
},
fuel_vm::interpreter::Memory,
services::{
block_importer::SharedImportResult,
p2p::{
GossipsubMessageAcceptance,
GossipsubMessageInfo,
NetworkData,
},
},
};
use std::{
ops::Deref,
sync::Arc,
};
pub trait PeerToPeer: Send + Sync {
type GossipedTransaction: NetworkData<Transaction>;
fn broadcast_transaction(&self, transaction: Arc<Transaction>) -> anyhow::Result<()>;
fn gossiped_transaction_events(&self) -> BoxStream<Self::GossipedTransaction>;
fn notify_gossip_transaction_validity(
&self,
message_info: GossipsubMessageInfo,
validity: GossipsubMessageAcceptance,
) -> anyhow::Result<()>;
}
pub trait BlockImporter: Send + Sync {
fn block_events(&self) -> BoxStream<SharedImportResult>;
}
pub trait TxPoolDb: Send + Sync {
fn utxo(&self, utxo_id: &UtxoId) -> StorageResult<Option<CompressedCoin>>;
fn contract_exist(&self, contract_id: &ContractId) -> StorageResult<bool>;
fn message(&self, message_id: &Nonce) -> StorageResult<Option<Message>>;
}
pub trait GasPriceProvider {
fn gas_price(&self, block_height: BlockHeight) -> Option<GasPrice>;
}
#[async_trait::async_trait]
pub trait MemoryPool {
type Memory: Memory + Send + Sync + 'static;
async fn get_memory(&self) -> Self::Memory;
}
#[cfg_attr(feature = "test-helpers", mockall::automock)]
pub trait ConsensusParametersProvider {
fn latest_consensus_parameters(&self) -> Arc<ConsensusParameters>;
}
impl<T: GasPriceProvider> GasPriceProvider for Arc<T> {
fn gas_price(&self, block_height: BlockHeight) -> Option<GasPrice> {
self.deref().gas_price(block_height)
}
}