use alloy_sol_types::{Eip712Domain, SolStruct};
use serde_json::Value;
use super::details::{self, differs, unsupported};
use crate::{
deployments,
error::VerificationError,
protocol::eip712::{self, Parsed, QuoteSet, Schema},
types::{EscrowEnvironment, VenueId},
};
pub(crate) fn signing_domain(
venue: &VenueId,
environment: EscrowEnvironment,
) -> Result<Eip712Domain, VerificationError> {
let chain = deployments::chain(venue).ok_or(unsupported(details::VENUE))?;
let contract = deployments::contract(venue, environment).ok_or(unsupported(details::VENUE))?;
Ok(eip712::lamarge_domain(chain.id, contract))
}
pub(crate) fn check_escrow_typed<T: Schema>(
raw: &Value,
venue: &VenueId,
environment: EscrowEnvironment,
) -> Result<(Parsed<T>, Eip712Domain), VerificationError> {
if deployments::is_venue_settled(venue) && T::PRIMARY != QuoteSet::NAME {
return Err(differs(details::PRIMARY_TYPE));
}
let domain = signing_domain(venue, environment)?;
Ok((eip712::parse_in::<T>(raw, &domain)?, domain))
}
#[cfg(test)]
mod tests;