72 lines
2.0 KiB
Rust
72 lines
2.0 KiB
Rust
use crate::prelude::*;
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
use super::common::{Capacity, InitialAmounts};
|
|
|
|
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
|
pub struct Req {
|
|
pub currency: Currency,
|
|
pub initial_amounts: InitialAmounts,
|
|
pub response_period: Milliseconds,
|
|
pub capacity: Capacity,
|
|
pub key: VerificationKey,
|
|
}
|
|
|
|
impl Req {
|
|
/// A channel adhering to `self` will necessarily adhere to other
|
|
pub fn is_stricter(&self, other: &Self) -> bool {
|
|
&self.currency == &other.currency
|
|
&& self.initial_amounts.gte(&other.initial_amounts)
|
|
&& other.capacity.gte(&self.capacity)
|
|
}
|
|
}
|
|
|
|
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
|
pub enum Res {
|
|
Okay(VerificationKey),
|
|
Fail(Fail),
|
|
}
|
|
|
|
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
|
pub enum Fail {
|
|
Suggestion(Req),
|
|
Other(Option<Text>),
|
|
}
|
|
|
|
pub fn basic_bounds(min_terms: Req, proposed_terms: Req) -> Res {
|
|
// FIXME :: this is all faff.
|
|
//
|
|
// // Bad currency
|
|
// if min_terms.currency != proposed_terms.currency {
|
|
// return Res::Fail(ConferFail::Suggestion(Req {
|
|
// currency: min_terms.currency,
|
|
// ..proposed_terms
|
|
// }));
|
|
// }
|
|
// // Bad initialAmount
|
|
// if !proposed_terms
|
|
// .initial_amounts
|
|
// .gte(&min_terms.initial_amounts)
|
|
// {
|
|
// return Res::Fail(Fail::Suggestion(Req {
|
|
// initial_amounts: min_terms.initial_amounts,
|
|
// ..proposed_terms
|
|
// }));
|
|
// }
|
|
// // Bad response period
|
|
// if !proposed_terms
|
|
// .initial_amounts
|
|
// .gte(&min_terms.initial_amounts)
|
|
// {
|
|
// return Res::Fail(Fail::Suggestion(Req {
|
|
// initial_amounts: min_terms.initial_amounts,
|
|
// ..proposed_terms
|
|
// }));
|
|
// }
|
|
if min_terms.is_stricter(&proposed_terms) {
|
|
Res::Okay(min_terms.key)
|
|
} else {
|
|
Res::Fail(Fail::Other(Some("See terms".to_string())))
|
|
}
|
|
}
|