use crate::types::ContractId;
use fuel_core_types::{
fuel_tx::{
Address,
UtxoId,
},
fuel_types::Nonce,
};
use std::{
collections::HashSet,
time::Duration,
};
#[derive(Default, Debug, Clone, PartialEq, Eq)]
pub struct BlackList {
pub(crate) owners: HashSet<Address>,
pub(crate) coins: HashSet<UtxoId>,
pub(crate) messages: HashSet<Nonce>,
pub(crate) contracts: HashSet<ContractId>,
}
impl BlackList {
pub fn new(
owners: Vec<Address>,
utxo_ids: Vec<UtxoId>,
messages: Vec<Nonce>,
contracts: Vec<ContractId>,
) -> Self {
Self {
owners: owners.into_iter().collect(),
coins: utxo_ids.into_iter().collect(),
messages: messages.into_iter().collect(),
contracts: contracts.into_iter().collect(),
}
}
pub fn contains_address(&self, address: &Address) -> bool {
self.owners.contains(address)
}
pub fn contains_coin(&self, utxo_id: &UtxoId) -> bool {
self.coins.contains(utxo_id)
}
pub fn contains_message(&self, nonce: &Nonce) -> bool {
self.messages.contains(nonce)
}
pub fn contains_contract(&self, contract_id: &ContractId) -> bool {
self.contracts.contains(contract_id)
}
}
#[derive(Debug, Clone)]
pub struct Config {
pub max_tx: usize,
pub max_depth: usize,
pub utxo_validation: bool,
pub metrics: bool,
pub transaction_ttl: Duration,
pub number_of_active_subscription: usize,
pub blacklist: BlackList,
}
#[cfg(feature = "test-helpers")]
impl Default for Config {
fn default() -> Self {
let max_tx = 4064;
let max_depth = 10;
let utxo_validation = true;
let metrics = false;
let transaction_ttl = Duration::from_secs(60 * 5);
let number_of_active_subscription = max_tx;
Self::new(
max_tx,
max_depth,
utxo_validation,
metrics,
transaction_ttl,
number_of_active_subscription,
Default::default(),
)
}
}
impl Config {
#[allow(clippy::too_many_arguments)]
pub fn new(
max_tx: usize,
max_depth: usize,
utxo_validation: bool,
metrics: bool,
transaction_ttl: Duration,
number_of_active_subscription: usize,
blacklist: BlackList,
) -> Self {
Self {
max_tx,
max_depth,
utxo_validation,
metrics,
transaction_ttl,
number_of_active_subscription,
blacklist,
}
}
}