cycles-quartz/crates/cli/src/request/enclave_start.rs
Daniel Gushchyan df40e592c8
feat: error reporting with eyre ()
Co-authored-by: hu55a1n1 <sufialhussaini@gmail.com>
2024-10-08 12:53:49 +04:00

41 lines
1.3 KiB
Rust

use color_eyre::Result;
use cosmrs::AccountId;
use quartz_common::enclave::types::Fmspc;
use tendermint::{block::Height, Hash};
use tracing::debug;
use crate::{config::Config, handler::utils::helpers::query_latest_height_hash, request::Request};
#[derive(Clone, Debug)]
pub struct EnclaveStartRequest {
pub unsafe_trust_latest: bool,
pub fmspc: Option<Fmspc>,
pub tcbinfo_contract: Option<AccountId>,
pub dcap_verifier_contract: Option<AccountId>,
}
impl From<EnclaveStartRequest> for Request {
fn from(request: EnclaveStartRequest) -> Self {
Self::EnclaveStart(request)
}
}
impl EnclaveStartRequest {
/// Returns the trusted hash and height
pub fn get_hash_height(&self, config: &Config) -> Result<(Height, Hash)> {
if self.unsafe_trust_latest || config.trusted_height == 0 || config.trusted_hash.is_empty()
{
debug!("querying latest trusted hash & height from node");
let (trusted_height, trusted_hash) = query_latest_height_hash(config.node_url.clone())?;
Ok((trusted_height, trusted_hash))
} else {
debug!("reusing config trusted hash & height");
Ok((
config.trusted_height.try_into()?,
config.trusted_hash.parse()?,
))
}
}
}