cycles-quartz/cosmwasm/packages/quartz-cw/src/handler/instantiate.rs

43 lines
1.4 KiB
Rust
Raw Normal View History

use cosmwasm_std::{DepsMut, Env, MessageInfo, Response, Uint64};
2024-02-19 15:55:46 +00:00
use quartz_tee_ra::Error as RaVerificationError;
use crate::{
error::Error,
handler::Handler,
msg::{
execute::attested::{Attestation, EpidAttestation, MockAttestation},
instantiate::{CoreInstantiate, Instantiate},
},
state::{RawConfig, CONFIG, EPOCH_COUNTER},
};
2024-02-19 15:55:46 +00:00
impl Handler for Instantiate<EpidAttestation> {
fn handle(self, deps: DepsMut<'_>, env: &Env, info: &MessageInfo) -> Result<Response, Error> {
2024-03-19 21:19:38 +00:00
if self.0.msg().config().mr_enclave() != self.0.attestation().mr_enclave() {
2024-02-19 15:55:46 +00:00
return Err(RaVerificationError::MrEnclaveMismatch.into());
}
self.0.handle(deps, env, info)
}
}
2024-03-19 21:19:38 +00:00
impl Handler for Instantiate<MockAttestation> {
fn handle(self, deps: DepsMut<'_>, env: &Env, info: &MessageInfo) -> Result<Response, Error> {
self.0.handle(deps, env, info)
}
}
2024-02-19 15:55:46 +00:00
impl Handler for CoreInstantiate {
fn handle(self, deps: DepsMut<'_>, _env: &Env, _info: &MessageInfo) -> Result<Response, Error> {
CONFIG
2024-03-19 21:19:38 +00:00
.save(deps.storage, &RawConfig::from(self.config().clone()))
2024-02-19 15:55:46 +00:00
.map_err(Error::Std)?;
let epoch_counter = Uint64::new(1);
2024-03-19 21:19:38 +00:00
EPOCH_COUNTER
.save(deps.storage, &epoch_counter)
.map_err(Error::Std)?;
2024-03-19 21:19:38 +00:00
2024-02-19 15:55:46 +00:00
Ok(Response::new().add_attribute("action", "instantiate"))
}
}