feat: config pass by ref (#162)
This commit is contained in:
parent
72c7702719
commit
25d0edf316
10 changed files with 55 additions and 14 deletions
|
@ -83,3 +83,9 @@ impl Default for Config {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl AsRef<Config> for Config {
|
||||
fn as_ref(&self) -> &Config {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,7 +16,10 @@ pub trait Handler {
|
|||
type Error;
|
||||
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]
|
||||
|
@ -24,7 +27,10 @@ impl Handler for Request {
|
|||
type Error = Error;
|
||||
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 {
|
||||
Request::Init(request) => request.handle(config).await,
|
||||
Request::Handshake(request) => request.handle(config).await,
|
||||
|
|
|
@ -16,7 +16,12 @@ impl Handler for ContractBuildRequest {
|
|||
type Error = Error;
|
||||
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 command = cargo
|
||||
.arg("wasm")
|
||||
|
|
|
@ -29,7 +29,12 @@ impl Handler for ContractDeployRequest {
|
|||
type Error = Error;
|
||||
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...");
|
||||
|
||||
let (code_id, contract_addr) = if config.mock_sgx {
|
||||
|
@ -52,7 +57,7 @@ impl Handler for ContractDeployRequest {
|
|||
|
||||
async fn deploy<DA: Serialize + DeserializeOwned>(
|
||||
args: ContractDeployRequest,
|
||||
config: Config,
|
||||
config: &Config,
|
||||
) -> Result<(u64, String), anyhow::Error> {
|
||||
// TODO: Replace with call to Rust package
|
||||
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 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");
|
||||
let raw_init_msg = run_relay::<QuartzInstantiateMsg<DA>>(
|
||||
|
@ -106,7 +111,7 @@ async fn deploy<DA: Serialize + DeserializeOwned>(
|
|||
|
||||
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)
|
||||
|
|
|
@ -16,7 +16,12 @@ impl Handler for EnclaveBuildRequest {
|
|||
type Error = Error;
|
||||
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 command = cargo
|
||||
.args(["build", "--release"])
|
||||
|
|
|
@ -17,7 +17,11 @@ impl Handler for EnclaveStartRequest {
|
|||
type Error = Error;
|
||||
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
|
||||
let (trusted_height, trusted_hash) = get_hash_height(self.use_latest_trusted, &mut config)?;
|
||||
|
||||
|
|
|
@ -32,7 +32,12 @@ impl Handler for HandshakeRequest {
|
|||
type Error = Error;
|
||||
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...");
|
||||
|
||||
// TODO: may need to import verbosity here
|
||||
|
|
|
@ -18,7 +18,12 @@ impl Handler for InitRequest {
|
|||
type Error = Error;
|
||||
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...");
|
||||
|
||||
let root_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("..");
|
||||
|
|
|
@ -5,7 +5,7 @@ use cosmwasm_std::{
|
|||
};
|
||||
use cw2::set_contract_version;
|
||||
use der::{DateTime, DecodePem};
|
||||
use mc_attestation_verifier::{CertificateChainVerifier, SignedTcbInfo, TcbInfo as McTcbInfo};
|
||||
use mc_attestation_verifier::{CertificateChainVerifier, SignedTcbInfo};
|
||||
use p256::ecdsa::VerifyingKey;
|
||||
use quartz_tee_ra::intel_sgx::dcap::certificate_chain::TlsCertificateChainVerifier;
|
||||
use serde_json::Value;
|
||||
|
|
|
@ -47,7 +47,7 @@ pub trait WasmdClient {
|
|||
&self,
|
||||
chain_id: &Id,
|
||||
sender: &str,
|
||||
code_id: usize,
|
||||
code_id: u64,
|
||||
init_msg: M,
|
||||
label: &str,
|
||||
) -> Result<String, Self::Error>;
|
||||
|
@ -201,7 +201,7 @@ impl WasmdClient for CliWasmdClient {
|
|||
&self,
|
||||
chain_id: &Id,
|
||||
sender: &str,
|
||||
code_id: usize,
|
||||
code_id: u64,
|
||||
init_msg: M,
|
||||
label: &str,
|
||||
) -> Result<String, Self::Error> {
|
||||
|
|
Loading…
Reference in a new issue