use std::future::Future;
use std::pin::Pin;
use std::sync::Arc;
use super::filter::MppPaymentContext;
type GateFuture<'a, T> = Pin<Box<dyn Future<Output = T> + Send + 'a>>;
pub trait PaymentGate: Send + Sync {
fn verify_payment(
&self,
chain: Option<String>,
auth_header: Option<String>,
) -> GateFuture<'_, Result<MppPaymentContext, warp::Rejection>>;
fn deduct<'a>(
&'a self,
backend_key: &'a str,
channel_id: &'a str,
amount: u128,
) -> GateFuture<'a, Result<(), mpp::server::VerificationError>>;
fn wait_for_update<'a>(
&'a self,
backend_key: &'a str,
channel_id: &'a str,
) -> GateFuture<'a, ()>;
fn channel_balance<'a>(
&'a self,
backend_key: &'a str,
channel_id: &'a str,
) -> GateFuture<'a, Option<(u128, u128, u128)>>;
fn close_channel<'a>(
&'a self,
backend_key: &'a str,
channel_id: &'a str,
) -> GateFuture<'a, Result<(), String>>;
}
impl PaymentGate for Arc<dyn PaymentGate> {
fn verify_payment(
&self,
chain: Option<String>,
auth_header: Option<String>,
) -> GateFuture<'_, Result<MppPaymentContext, warp::Rejection>> {
(**self).verify_payment(chain, auth_header)
}
fn deduct<'a>(
&'a self,
backend_key: &'a str,
channel_id: &'a str,
amount: u128,
) -> GateFuture<'a, Result<(), mpp::server::VerificationError>> {
(**self).deduct(backend_key, channel_id, amount)
}
fn wait_for_update<'a>(
&'a self,
backend_key: &'a str,
channel_id: &'a str,
) -> GateFuture<'a, ()> {
(**self).wait_for_update(backend_key, channel_id)
}
fn channel_balance<'a>(
&'a self,
backend_key: &'a str,
channel_id: &'a str,
) -> GateFuture<'a, Option<(u128, u128, u128)>> {
(**self).channel_balance(backend_key, channel_id)
}
fn close_channel<'a>(
&'a self,
backend_key: &'a str,
channel_id: &'a str,
) -> GateFuture<'a, Result<(), String>> {
(**self).close_channel(backend_key, channel_id)
}
}