#![warn(clippy::expect_used)]
#![warn(clippy::unwrap_used)]
use async_trait::async_trait;
use nym_crypto::asymmetric::ed25519;
use std::error::Error;
pub mod backend;
pub mod error;
pub mod types;
pub use crate::types::*;
pub use backend::mem_backend::{InMemGatewaysDetails, InMemStorageError};
pub use error::BadGateway;
#[cfg(all(not(target_arch = "wasm32"), feature = "fs-gateways-storage"))]
pub use backend::fs_backend::{error::StorageError, OnDiskGatewaysDetails};
#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
pub trait GatewaysDetailsStore {
type StorageError: Error + From<error::BadGateway>;
async fn active_gateway(&self) -> Result<ActiveGateway, Self::StorageError>;
async fn set_active_gateway(&self, gateway_id: &str) -> Result<(), Self::StorageError>;
async fn all_gateways(&self) -> Result<Vec<GatewayRegistration>, Self::StorageError>;
async fn all_gateways_identities(&self) -> Result<Vec<ed25519::PublicKey>, Self::StorageError> {
Ok(self
.all_gateways()
.await?
.into_iter()
.map(|gateway| gateway.details.gateway_id())
.collect())
}
async fn has_gateway_details(&self, gateway_id: &str) -> Result<bool, Self::StorageError>;
async fn load_gateway_details(
&self,
gateway_id: &str,
) -> Result<GatewayRegistration, Self::StorageError>;
async fn store_gateway_details(
&self,
details: &GatewayRegistration,
) -> Result<(), Self::StorageError>;
async fn update_gateway_published_data(
&self,
gateway_id: &ed25519::PublicKey,
published_data: &GatewayPublishedData,
) -> Result<(), Self::StorageError>;
async fn remove_gateway_details(&self, gateway_id: &str) -> Result<(), Self::StorageError>;
}