diff --git a/contracts/okp4-dataverse/src/contract.rs b/contracts/okp4-dataverse/src/contract.rs index 53ba357d..ca206386 100644 --- a/contracts/okp4-dataverse/src/contract.rs +++ b/contracts/okp4-dataverse/src/contract.rs @@ -67,14 +67,14 @@ pub fn instantiate( pub fn execute( deps: DepsMut<'_>, _env: Env, - _info: MessageInfo, + info: MessageInfo, msg: ExecuteMsg, ) -> Result { match msg { ExecuteMsg::SubmitClaims { metadata, format: _, - } => execute::submit_claims(deps, metadata), + } => execute::submit_claims(deps, info, metadata), _ => Err(StdError::generic_err("Not implemented").into()), } } @@ -82,19 +82,33 @@ pub fn execute( pub mod execute { use super::*; use crate::credential::vc::VerifiableCredential; + use crate::registrar::credential::DataverseCredential; + use crate::registrar::registry::ClaimRegistrar; use okp4_rdf::dataset::Dataset; use okp4_rdf::serde::NQuadsReader; use std::io::BufReader; - pub fn submit_claims(deps: DepsMut<'_>, data: Binary) -> Result { + pub fn submit_claims( + deps: DepsMut<'_>, + info: MessageInfo, + data: Binary, + ) -> Result { let buf = BufReader::new(data.as_slice()); let mut reader = NQuadsReader::new(buf); let rdf_quads = reader.read_all()?; let vc_dataset = Dataset::from(rdf_quads.as_slice()); let vc = VerifiableCredential::try_from(&vc_dataset)?; - vc.verify(deps)?; + vc.verify(&deps)?; + + let credential = DataverseCredential::try_from((info.sender, &vc))?; + let registrar = ClaimRegistrar::try_new(deps.storage)?; - Ok(Response::default()) + Ok(Response::default() + .add_attribute("action", "submit_claims") + .add_attribute("credential", credential.id) + .add_attribute("subject", credential.subject) + .add_attribute("type", credential.r#type) + .add_message(registrar.submit_claim(&deps, &credential)?)) } } diff --git a/contracts/okp4-dataverse/src/error.rs b/contracts/okp4-dataverse/src/error.rs index 1e62f163..f0df3721 100644 --- a/contracts/okp4-dataverse/src/error.rs +++ b/contracts/okp4-dataverse/src/error.rs @@ -17,6 +17,12 @@ pub enum ContractError { #[error("Invalid credential: '{0}'")] InvalidCredential(#[from] InvalidCredentialError), - #[error("Credential verification failed: {0}")] + #[error("Credential verification failed: '{0}'")] CredentialVerification(#[from] VerificationError), + + #[error("Credential not supported: '{0}'")] + UnsupportedCredential(String), + + #[error("Credential already exists: '{0}'")] + CredentialAlreadyExists(String), } diff --git a/contracts/okp4-dataverse/src/lib.rs b/contracts/okp4-dataverse/src/lib.rs index 300fb02f..6ea2e762 100644 --- a/contracts/okp4-dataverse/src/lib.rs +++ b/contracts/okp4-dataverse/src/lib.rs @@ -14,6 +14,7 @@ pub mod contract; mod credential; mod error; pub mod msg; +mod registrar; pub mod state; mod testutil;