2024-09-25 19:14:06 +00:00
|
|
|
use cosmrs::AccountId;
|
|
|
|
use quartz_common::enclave::types::Fmspc;
|
2024-08-28 23:45:09 +00:00
|
|
|
use tendermint::{block::Height, Hash};
|
|
|
|
use tracing::debug;
|
|
|
|
|
|
|
|
use crate::{
|
|
|
|
config::Config, error::Error, handler::utils::helpers::query_latest_height_hash,
|
|
|
|
request::Request,
|
|
|
|
};
|
2024-08-09 23:24:57 +00:00
|
|
|
|
|
|
|
#[derive(Clone, Debug)]
|
|
|
|
pub struct EnclaveStartRequest {
|
2024-09-13 13:28:32 +00:00
|
|
|
pub unsafe_trust_latest: bool,
|
2024-09-25 19:14:06 +00:00
|
|
|
pub fmspc: Option<Fmspc>,
|
|
|
|
pub tcbinfo_contract: Option<AccountId>,
|
|
|
|
pub dcap_verifier_contract: Option<AccountId>,
|
2024-08-09 23:24:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl From<EnclaveStartRequest> for Request {
|
|
|
|
fn from(request: EnclaveStartRequest) -> Self {
|
|
|
|
Self::EnclaveStart(request)
|
|
|
|
}
|
|
|
|
}
|
2024-08-28 23:45:09 +00:00
|
|
|
|
|
|
|
impl EnclaveStartRequest {
|
|
|
|
/// Returns the trusted hash and height
|
|
|
|
pub fn get_hash_height(&self, config: &Config) -> Result<(Height, Hash), Error> {
|
2024-09-13 13:28:32 +00:00
|
|
|
if self.unsafe_trust_latest || config.trusted_height == 0 || config.trusted_hash.is_empty()
|
|
|
|
{
|
2024-08-28 23:45:09 +00:00
|
|
|
debug!("querying latest trusted hash & height from node");
|
2024-10-03 17:50:54 +00:00
|
|
|
let (trusted_height, trusted_hash) = query_latest_height_hash(config.node_url.clone())?;
|
2024-08-28 23:45:09 +00:00
|
|
|
|
|
|
|
Ok((trusted_height, trusted_hash))
|
|
|
|
} else {
|
|
|
|
debug!("reusing config trusted hash & height");
|
|
|
|
Ok((
|
|
|
|
config.trusted_height.try_into()?,
|
|
|
|
config
|
|
|
|
.trusted_hash
|
|
|
|
.parse()
|
|
|
|
.map_err(|_| Error::GenericErr("invalid hash".to_string()))?,
|
|
|
|
))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|