cycles-quartz/enclaves/quartz/src/main.rs

65 lines
1.7 KiB
Rust
Raw Normal View History

2024-02-20 11:27:10 +00:00
#![doc = include_str!("../README.md")]
#![forbid(unsafe_code)]
#![warn(
clippy::checked_conversions,
clippy::panic,
clippy::panic_in_result_fn,
clippy::unwrap_used,
missing_docs,
trivial_casts,
trivial_numeric_casts,
rust_2018_idioms,
unused_lifetimes,
unused_import_braces,
unused_qualifications
)]
2024-02-26 10:56:55 +00:00
mod attestor;
2024-02-22 20:48:13 +00:00
mod cli;
2024-02-20 11:27:10 +00:00
mod server;
2024-02-27 21:28:59 +00:00
use std::{process::Command, time::Duration};
2024-02-22 20:48:13 +00:00
use clap::Parser;
2024-02-27 21:28:59 +00:00
use cosmwasm_std::HexBinary;
2024-02-23 20:51:20 +00:00
use quartz_cw::state::{Config, LightClientOpts};
2024-02-20 16:34:42 +00:00
use quartz_proto::quartz::core_server::CoreServer;
2024-02-20 11:27:10 +00:00
use tonic::transport::Server;
2024-02-27 20:01:18 +00:00
use crate::{attestor::EpidAttestor, cli::Cli, server::CoreService};
2024-02-20 11:27:10 +00:00
#[tokio::main(flavor = "current_thread")]
2024-02-20 11:27:10 +00:00
async fn main() -> Result<(), Box<dyn std::error::Error>> {
2024-02-22 20:48:13 +00:00
let args = Cli::parse();
2024-02-27 21:28:59 +00:00
let gramine_sgx_sigstruct_view = Command::new("gramine-sgx-sigstruct-view")
.args(["--output-format", "json"])
.arg(args.sigfile)
.output()?;
let sigstruct_json: serde_json::Value =
serde_json::from_str(&String::from_utf8(gramine_sgx_sigstruct_view.stdout)?)?;
let mr_enclave = HexBinary::from_hex(&sigstruct_json["mr_enclave"].to_string())?.to_array()?;
2024-02-22 20:48:13 +00:00
let light_client_opts = LightClientOpts::new(
args.chain_id,
args.trusted_height,
args.trusted_hash,
args.trust_threshold,
args.trusting_period,
args.max_clock_drift,
args.max_block_lag,
);
2024-02-23 20:51:20 +00:00
let config = Config::new(
2024-02-27 21:28:59 +00:00
mr_enclave,
2024-02-23 20:51:20 +00:00
Duration::from_secs(30 * 24 * 60),
light_client_opts,
);
2024-02-20 11:27:10 +00:00
Server::builder()
2024-02-27 20:01:18 +00:00
.add_service(CoreServer::new(CoreService::new(config, EpidAttestor)))
2024-02-22 20:48:13 +00:00
.serve(args.rpc_addr)
2024-02-20 11:27:10 +00:00
.await?;
Ok(())
}