feat: config pass by ref (#162)

This commit is contained in:
Daniel Gushchyan 2024-08-15 13:54:55 -07:00 committed by GitHub
parent 72c7702719
commit 25d0edf316
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 55 additions and 14 deletions

View file

@ -83,3 +83,9 @@ impl Default for Config {
} }
} }
} }
impl AsRef<Config> for Config {
fn as_ref(&self) -> &Config {
self
}
}

View file

@ -16,7 +16,10 @@ pub trait Handler {
type Error; type Error;
type Response; type Response;
async fn handle(self, config: Config) -> Result<Self::Response, Self::Error>; async fn handle<C: AsRef<Config> + Send>(
self,
config: C,
) -> Result<Self::Response, Self::Error>;
} }
#[async_trait] #[async_trait]
@ -24,7 +27,10 @@ impl Handler for Request {
type Error = Error; type Error = Error;
type Response = Response; type Response = Response;
async fn handle(self, config: Config) -> Result<Self::Response, Self::Error> { async fn handle<C: AsRef<Config> + Send>(
self,
config: C,
) -> Result<Self::Response, Self::Error> {
match self { match self {
Request::Init(request) => request.handle(config).await, Request::Init(request) => request.handle(config).await,
Request::Handshake(request) => request.handle(config).await, Request::Handshake(request) => request.handle(config).await,

View file

@ -16,7 +16,12 @@ impl Handler for ContractBuildRequest {
type Error = Error; type Error = Error;
type Response = Response; type Response = Response;
async fn handle(self, config: Config) -> Result<Self::Response, Self::Error> { async fn handle<C: AsRef<Config> + Send>(
self,
config: C,
) -> Result<Self::Response, Self::Error> {
let config = config.as_ref();
let mut cargo = Command::new("cargo"); let mut cargo = Command::new("cargo");
let command = cargo let command = cargo
.arg("wasm") .arg("wasm")

View file

@ -29,7 +29,12 @@ impl Handler for ContractDeployRequest {
type Error = Error; type Error = Error;
type Response = Response; type Response = Response;
async fn handle(self, config: Config) -> Result<Self::Response, Self::Error> { async fn handle<C: AsRef<Config> + Send>(
self,
config: C,
) -> Result<Self::Response, Self::Error> {
let config = config.as_ref();
trace!("initializing directory structure..."); trace!("initializing directory structure...");
let (code_id, contract_addr) = if config.mock_sgx { let (code_id, contract_addr) = if config.mock_sgx {
@ -52,7 +57,7 @@ impl Handler for ContractDeployRequest {
async fn deploy<DA: Serialize + DeserializeOwned>( async fn deploy<DA: Serialize + DeserializeOwned>(
args: ContractDeployRequest, args: ContractDeployRequest,
config: Config, config: &Config,
) -> Result<(u64, String), anyhow::Error> { ) -> Result<(u64, String), anyhow::Error> {
// TODO: Replace with call to Rust package // TODO: Replace with call to Rust package
let relay_path = current_dir()?.join("../"); let relay_path = current_dir()?.join("../");
@ -74,7 +79,7 @@ async fn deploy<DA: Serialize + DeserializeOwned>(
let res = block_tx_commit(&tmrpc_client, deploy_output.txhash).await?; let res = block_tx_commit(&tmrpc_client, deploy_output.txhash).await?;
let log: Vec<Log> = serde_json::from_str(&res.tx_result.log)?; let log: Vec<Log> = serde_json::from_str(&res.tx_result.log)?;
let code_id: usize = log[0].events[1].attributes[1].value.parse()?; let code_id: u64 = log[0].events[1].attributes[1].value.parse()?;
info!("\n🚀 Communicating with Relay to Instantiate...\n"); info!("\n🚀 Communicating with Relay to Instantiate...\n");
let raw_init_msg = run_relay::<QuartzInstantiateMsg<DA>>( let raw_init_msg = run_relay::<QuartzInstantiateMsg<DA>>(
@ -106,7 +111,7 @@ async fn deploy<DA: Serialize + DeserializeOwned>(
debug!("{contract_addr}"); debug!("{contract_addr}");
Ok((code_id as u64, contract_addr.to_owned())) Ok((code_id, contract_addr.to_owned()))
} }
//RES=$($CMD tx wasm instantiate "$CODE_ID" "$INSTANTIATE_MSG" --from "$USER_ADDR" --label $LABEL $TXFLAG -y --no-admin --output json) //RES=$($CMD tx wasm instantiate "$CODE_ID" "$INSTANTIATE_MSG" --from "$USER_ADDR" --label $LABEL $TXFLAG -y --no-admin --output json)

View file

@ -16,7 +16,12 @@ impl Handler for EnclaveBuildRequest {
type Error = Error; type Error = Error;
type Response = Response; type Response = Response;
async fn handle(self, config: Config) -> Result<Self::Response, Self::Error> { async fn handle<C: AsRef<Config> + Send>(
self,
config: C,
) -> Result<Self::Response, Self::Error> {
let config = config.as_ref();
let mut cargo = Command::new("cargo"); let mut cargo = Command::new("cargo");
let command = cargo let command = cargo
.args(["build", "--release"]) .args(["build", "--release"])

View file

@ -17,7 +17,11 @@ impl Handler for EnclaveStartRequest {
type Error = Error; type Error = Error;
type Response = Response; type Response = Response;
async fn handle(self, mut config: Config) -> Result<Self::Response, Self::Error> { async fn handle<C: AsRef<Config> + Send>(
self,
config: C,
) -> Result<Self::Response, Self::Error> {
let mut config = config.as_ref().clone();
// Get trusted height and hash // Get trusted height and hash
let (trusted_height, trusted_hash) = get_hash_height(self.use_latest_trusted, &mut config)?; let (trusted_height, trusted_hash) = get_hash_height(self.use_latest_trusted, &mut config)?;

View file

@ -32,7 +32,12 @@ impl Handler for HandshakeRequest {
type Error = Error; type Error = Error;
type Response = Response; type Response = Response;
async fn handle(self, config: Config) -> Result<Self::Response, Self::Error> { async fn handle<C: AsRef<Config> + Send>(
self,
config: C,
) -> Result<Self::Response, Self::Error> {
let config = config.as_ref().clone();
trace!("starting handshake..."); trace!("starting handshake...");
// TODO: may need to import verbosity here // TODO: may need to import verbosity here

View file

@ -18,7 +18,12 @@ impl Handler for InitRequest {
type Error = Error; type Error = Error;
type Response = Response; type Response = Response;
async fn handle(self, config: Config) -> Result<Self::Response, Self::Error> { async fn handle<C: AsRef<Config> + Send>(
self,
config: C,
) -> Result<Self::Response, Self::Error> {
let config = config.as_ref();
trace!("initializing directory structure..."); trace!("initializing directory structure...");
let root_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join(".."); let root_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("..");

View file

@ -5,7 +5,7 @@ use cosmwasm_std::{
}; };
use cw2::set_contract_version; use cw2::set_contract_version;
use der::{DateTime, DecodePem}; use der::{DateTime, DecodePem};
use mc_attestation_verifier::{CertificateChainVerifier, SignedTcbInfo, TcbInfo as McTcbInfo}; use mc_attestation_verifier::{CertificateChainVerifier, SignedTcbInfo};
use p256::ecdsa::VerifyingKey; use p256::ecdsa::VerifyingKey;
use quartz_tee_ra::intel_sgx::dcap::certificate_chain::TlsCertificateChainVerifier; use quartz_tee_ra::intel_sgx::dcap::certificate_chain::TlsCertificateChainVerifier;
use serde_json::Value; use serde_json::Value;

View file

@ -47,7 +47,7 @@ pub trait WasmdClient {
&self, &self,
chain_id: &Id, chain_id: &Id,
sender: &str, sender: &str,
code_id: usize, code_id: u64,
init_msg: M, init_msg: M,
label: &str, label: &str,
) -> Result<String, Self::Error>; ) -> Result<String, Self::Error>;
@ -201,7 +201,7 @@ impl WasmdClient for CliWasmdClient {
&self, &self,
chain_id: &Id, chain_id: &Id,
sender: &str, sender: &str,
code_id: usize, code_id: u64,
init_msg: M, init_msg: M,
label: &str, label: &str,
) -> Result<String, Self::Error> { ) -> Result<String, Self::Error> {