Skip to content

Commit

Permalink
fix: register schema works but cred def is broken
Browse files Browse the repository at this point in the history
Signed-off-by: blu3beri <[email protected]>
  • Loading branch information
berendsliedrecht committed Mar 10, 2023
1 parent 524b538 commit 3b80638
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
2 changes: 1 addition & 1 deletion crates/agent/src/modules/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use async_trait::async_trait;
use serde::{Deserialize, Serialize};

/// Schema response from the ledger
#[derive(Debug, Deserialize, Serialize)]
#[derive(Debug, Deserialize, Serialize, Default)]
pub struct Schema {
/// Version of the schema
pub ver: String,
Expand Down
25 changes: 22 additions & 3 deletions crates/automations/src/automations/create_credential_definition.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
use siera_agent::modules::credential_definition::CredentialDefinitionCreateOptions;
use siera_agent::modules::credential_definition::CredentialDefinitionCreateResponse;
use siera_agent::modules::credential_definition::CredentialDefinitionModule;
use siera_agent::modules::schema::Schema;
use siera_agent::modules::schema::{SchemaCreateOptions, SchemaModule};

use colored::Colorize;

use crate::error::Error;
use crate::error::Result;

/// Automation for creating a credential definition
Expand Down Expand Up @@ -32,7 +34,7 @@ impl<'a> CreateCredentialDefinition<'a> {
&self,
agent: &(impl SchemaModule + CredentialDefinitionModule + Send + Sync),
) -> Result<CredentialDefinitionCreateResponse> {
let schema = SchemaModule::create(
let s = SchemaModule::create(
agent,
SchemaCreateOptions {
name: self.name.to_owned(),
Expand All @@ -44,10 +46,27 @@ impl<'a> CreateCredentialDefinition<'a> {
.collect(),
},
)
.await?;
.await;

let schema_id = match s {
Ok(s) => Ok(s.id),
Err(_ )=> {
let schemas = SchemaModule::get_all(agent).await?;
let mut schema_id: Option<String> = None;

for sid in schemas.schema_ids {
let schema = SchemaModule::get_by_id(agent, sid).await?;
if schema.name == self.name && schema.version == self.version {
schema_id = Some(schema.id);
break
}
}
schema_id.ok_or(Error::ConnectionNotReady)
}
}?;

let options = CredentialDefinitionCreateOptions {
schema_id: schema.id,
schema_id,
..CredentialDefinitionCreateOptions::default()
};

Expand Down

0 comments on commit 3b80638

Please sign in to comment.