Skip to content

Commit

Permalink
fix: catch IOTA Client error
Browse files Browse the repository at this point in the history
  • Loading branch information
nanderstabel committed Feb 26, 2025
1 parent 7bb2c92 commit faff824
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 9 deletions.
24 changes: 22 additions & 2 deletions agent_identity/src/document/aggregate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ use identity_iota::{
verification::{MethodScope, MethodType, VerificationMethod},
};
use iota_sdk::client::api::input_selection::Error::MissingInputWithEd25519Address;
use iota_sdk::client::error::Error::{InputAddressNotFound, InputSelection};
use iota_sdk::client::error::Error::{Block, InputAddressNotFound, InputSelection};
use iota_sdk::types::block::Error::InsufficientStorageDepositAmount;
use iota_sdk::{
client::Client,
types::block::{
Expand Down Expand Up @@ -109,13 +110,21 @@ impl Aggregate for Document {
let controller = document.id().clone();
info!("Found an existing controller for DID method `{did_method}`: `{controller}`");

// Create a new DID Document from skratch.
// Create a new DID Document from scratch.
let document = IotaDocument::new_with_id(controller.clone());

let rent_structure: RentStructure =
iota_client.get_rent_structure().await.map_err(IotaClientError)?;

// Update the DID Document output with the latest state.
let alias_output: AliasOutput =
iota_client.update_did_output(document).await.map_err(IotaClientError)?;

let alias_output: AliasOutput = AliasOutputBuilder::from(&alias_output)
.with_minimum_storage_deposit(rent_structure)
.finish()
.map_err(|err| AliasOutputBuilderError(err.to_string()))?;

// Publish the updated Alias Output and get the published DID document.
let test_publish_result = iota_client
.publish_did_output(stronghold_storage.as_secret_manager(), alias_output)
Expand All @@ -138,6 +147,17 @@ impl Aggregate for Document {
// that later on a new DID Document will be created using the current
// wallet address.
None
} else if let Block(InsufficientStorageDepositAmount { amount, required }) =
&**error
{
warn!(
"The current `{did_method}` DID `{controller}` has insufficient storage deposit amount: `{amount}`, \
required: `{required}`."
);
return Err(InsufficientDepositError(
network_name.to_string(),
wallet_address.to_string(),
));
} else {
return Err(IotaClientError(test_publish_error));
}
Expand Down
12 changes: 7 additions & 5 deletions agent_identity/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,12 +193,14 @@ async fn initialize_documents(state: &IdentityState) -> anyhow::Result<()> {
if let Some((document_id, command)) = document_id_and_command {
command_handler(&document_id, &state.command.document, command).await?;

let command = DocumentCommand::UpdatePublicKeys {
document_id: document_id.clone(),
public_key_jwks: vec![],
};
if enabled {
let command = DocumentCommand::UpdatePublicKeys {
document_id: document_id.clone(),
public_key_jwks: vec![],
};

command_handler(&document_id, &state.command.document, command).await?;
command_handler(&document_id, &state.command.document, command).await?;
}
}
}

Expand Down
3 changes: 1 addition & 2 deletions agent_secret_manager/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use identity_iota::{
use iota_sdk::client::secret::stronghold::StrongholdSecretManager;
use jsonwebtoken::Algorithm;
use log::info;
use serde::Serialize;
use std::collections::HashMap;

pub mod service;
Expand Down Expand Up @@ -52,7 +51,7 @@ impl StrongholdManager {
}
}

#[derive(Serialize, Clone, Eq, PartialEq, Hash)]
#[derive(Clone, Eq, PartialEq, Hash)]
pub struct StorageKey {
pub did_method: SupportedDidMethod,
pub algorithm: Algorithm,
Expand Down

0 comments on commit faff824

Please sign in to comment.