Skip to content

Commit

Permalink
feat(dataverse): properly persists claims in related exec msg
Browse files Browse the repository at this point in the history
  • Loading branch information
amimart committed Feb 13, 2024
1 parent 385426e commit 6abb559
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 6 deletions.
24 changes: 19 additions & 5 deletions contracts/okp4-dataverse/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,34 +67,48 @@ pub fn instantiate(
pub fn execute(
deps: DepsMut<'_>,
_env: Env,
_info: MessageInfo,
info: MessageInfo,
msg: ExecuteMsg,
) -> Result<Response, ContractError> {
match msg {
ExecuteMsg::SubmitClaims {
metadata,
format: _,
} => execute::submit_claims(deps, metadata),
} => execute::submit_claims(deps, info, metadata),
_ => Err(StdError::generic_err("Not implemented").into()),
}
}

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<Response, ContractError> {
pub fn submit_claims(
deps: DepsMut<'_>,
info: MessageInfo,
data: Binary,
) -> Result<Response, ContractError> {
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)?))
}
}

Expand Down
8 changes: 7 additions & 1 deletion contracts/okp4-dataverse/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
1 change: 1 addition & 0 deletions contracts/okp4-dataverse/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ pub mod contract;
mod credential;
mod error;
pub mod msg;
mod registrar;
pub mod state;
mod testutil;

Expand Down

0 comments on commit 6abb559

Please sign in to comment.