Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ export async function accessReadOnlyMethods(): Promise<void> {
console.log("🔐 Lock metadata:", lockMetadata);
assert(lockMetadata === undefined, "Per default a dynamic Notarization has no lock metadata");

// 10. Get the whole OnChainNotarization at once and pretty print it
const onChainNotarization = await notarizationClientReadOnly
.getNotarizationById(dynamicNotarization.id);
console.log("📦 Complete dynamic OnChainNotarization:", onChainNotarization);

// Update the state to demonstrate version tracking
console.log("\n🔄 Updating state to demonstrate version tracking...");

Expand Down Expand Up @@ -153,7 +158,8 @@ export async function accessReadOnlyMethods(): Promise<void> {
.isDestroyAllowed(lockedNotarization.id);
const lockedLockMetadata = await notarizationClientReadOnly
.lockMetadata(lockedNotarization.id);

const lockedOnChainNotarization = await notarizationClientReadOnly
.getNotarizationById(lockedNotarization.id);
console.log("⚙️ Method:", lockedMethod);
assert(lockedMethod === "Locked", "method of a locked Notarization must be 'Locked'");
console.log("🔒 Transfer locked:", lockedTransferLocked);
Expand All @@ -164,6 +170,7 @@ export async function accessReadOnlyMethods(): Promise<void> {
assert(!lockedDestroyAllowed, "Destroying a delete-locked locked Notarization must be forbidden");
console.log("🔐 Lock metadata present:", lockedLockMetadata !== undefined);
assert(lockedLockMetadata !== undefined, "A locked Notarization must have lock metadata");
console.log("📦 Complete locked OnChainNotarization:", lockedOnChainNotarization);

// Compare methods between dynamic and locked
console.log("\n📊 Comparison Summary:");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use product_common::bindings::WasmObjectID;
use product_common::core_client::CoreClientReadOnly;
use wasm_bindgen::prelude::*;

use crate::wasm_notarization::WasmOnChainNotarization;
use crate::wasm_types::{WasmLockMetadata, WasmNotarizationMethod, WasmState};

/// A client to interact with Notarization objects on the IOTA ledger.
Expand Down Expand Up @@ -112,6 +113,26 @@ impl WasmNotarizationClientReadOnly {
self.0.chain_id().to_string()
}

/// Retrieves the [`OnChainNotarization`] of a notarized object.
///
/// This method returns the on-chain notarization object for the given object ID.
///
/// # Arguments
/// * `notarized_object_id` - The ID of the notarization object.
///
/// # Returns
/// The [`OnChainNotarization`] object for the given object ID.
#[wasm_bindgen(js_name = getNotarizationById)]
pub async fn get_notarization_by_id(&self, notarized_object_id: WasmObjectID) -> Result<WasmOnChainNotarization> {
let notarized_object_id = parse_wasm_object_id(&notarized_object_id)?;
self.0
.get_notarization_by_id(notarized_object_id)
.await
.map_err(wasm_error)
.wasm_result()
.map(Into::into)
}

/// Retrieves the timestamp of the last state change for a notarization.
///
/// # Arguments
Expand Down
10 changes: 10 additions & 0 deletions examples/08_access_read_only_methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,12 @@ async fn main() -> Result<()> {
.await?;
println!("🔐 Lock metadata: {lock_metadata:?}");

// 10. Get the whole OnChainNotarization at once and pretty print it
let on_chain_notarization = notarization_client
.get_notarization_by_id(*dynamic_notarization_id.object_id())
.await?;
println!("📦 Complete dynamic OnChainNotarization:\n{on_chain_notarization:#?}");

// Update the state to demonstrate version tracking
println!("\n🔄 Updating state to demonstrate version tracking...");

Expand Down Expand Up @@ -168,12 +174,16 @@ async fn main() -> Result<()> {
let locked_lock_metadata = notarization_client
.lock_metadata(*locked_notarization_id.object_id())
.await?;
let whole_locked_notarization = notarization_client
.get_notarization_by_id(*locked_notarization_id.object_id())
.await?;

println!("⚙️ Method: {locked_method:?}");
println!("🔒 Transfer locked: {locked_transfer_locked}");
println!("🔒 Update locked: {locked_update_locked}");
println!("🗑️ Destroy allowed: {locked_destroy_allowed}");
println!("🔐 Lock metadata present: {}", locked_lock_metadata.is_some());
println!("📦 Complete locked OnChainNotarization:\n{whole_locked_notarization:#?}");

// Compare methods between dynamic and locked
println!("\n📊 Comparison Summary:");
Expand Down
19 changes: 18 additions & 1 deletion notarization-rs/src/client/read_only.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ use serde::de::DeserializeOwned;
use super::network_id;
use crate::core::move_utils;
use crate::core::operations::{NotarizationImpl, NotarizationOperations};
use crate::core::types::{Data, LockMetadata, NotarizationMethod, State};
use crate::core::transactions::get_object_ref_by_id_with_bcs;
use crate::core::types::{Data, LockMetadata, NotarizationMethod, OnChainNotarization, State};
use crate::error::Error;
use crate::iota_interaction_adapter::IotaClientAdapter;
use crate::package;
Expand Down Expand Up @@ -167,6 +168,22 @@ impl NotarizationClientReadOnly {
Self::new_internal(client, network).await
}

/// Retrieves the [`OnChainNotarization`] of a notarized object.
///
/// This method returns the on-chain notarization object for the given object ID.
///
/// # Arguments
///
/// * `notarized_object_id`: The [`ObjectID`] of the notarized object.
///
/// # Returns
/// A `Result` containing the [`OnChainNotarization`] or an [`Error`].
pub async fn get_notarization_by_id(&self, notarized_object_id: ObjectID) -> Result<OnChainNotarization, Error> {
let notarization_object = get_object_ref_by_id_with_bcs(self, &notarized_object_id).await?;

Ok(notarization_object)
}

/// Retrieves the `last_state_change_at` timestamp of a notarized object.
///
/// This timestamp indicates the time of the most recent state change for the object.
Expand Down