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
6 changes: 3 additions & 3 deletions notarization-move/Move.lock
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ flavor = "iota"
[env]

[env.localnet]
chain-id = "c7a0abbd"
original-published-id = "0x7fab7adeb06a0087b65cd6712e270d338d39f002f8abfb3d252f88c843b61070"
latest-published-id = "0x7fab7adeb06a0087b65cd6712e270d338d39f002f8abfb3d252f88c843b61070"
chain-id = "002d6fb7"
original-published-id = "0x760def1fd86d216536bb3f8809baed9e075a73c428aeb776e4d47ad88e9fc6b4"
latest-published-id = "0x760def1fd86d216536bb3f8809baed9e075a73c428aeb776e4d47ad88e9fc6b4"
published-version = "1"

[env.devnet]
Expand Down
4 changes: 2 additions & 2 deletions notarization-move/sources/dynamic_notarization.move
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public fun new<D: store + drop + copy>(
state: notarization::State<D>,
immutable_description: Option<String>,
updatable_metadata: Option<String>,
transfer_lock: Option<TimeLock>,
transfer_lock: TimeLock,
clock: &Clock,
ctx: &mut TxContext,
): notarization::Notarization<D> {
Expand All @@ -50,7 +50,7 @@ public fun create<D: store + drop + copy>(
state: notarization::State<D>,
immutable_description: Option<String>,
updatable_metadata: Option<String>,
transfer_lock: Option<TimeLock>,
transfer_lock: TimeLock,
clock: &Clock,
ctx: &mut TxContext,
) {
Expand Down
12 changes: 7 additions & 5 deletions notarization-move/sources/notarization.move
Original file line number Diff line number Diff line change
Expand Up @@ -186,14 +186,16 @@ public(package) fun new_dynamic_notarization<D: store + drop + copy>(
state: State<D>,
immutable_description: Option<String>,
updatable_metadata: Option<String>,
transfer_lock: Option<TimeLock>,
transfer_lock: TimeLock,
clock: &Clock,
ctx: &mut TxContext,
): Notarization<D> {
let locking = option::map!(
transfer_lock,
|transfer_lock| new_lock_metadata(timelock::none(), timelock::none(), transfer_lock),
);
let locking = if (timelock::is_none(&transfer_lock)) {
timelock::destroy(transfer_lock, clock);
option::none()
} else {
option::some(new_lock_metadata(timelock::none(), timelock::none(), transfer_lock))
};

let immutable_metadata = ImmutableMetadata {
created_at: clock::timestamp_ms(clock),
Expand Down
19 changes: 10 additions & 9 deletions notarization-move/tests/dynamic_notarization_tests.move
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public fun test_create_dynamic_notarization_with_string_data() {
state,
std::option::some(string::utf8(b"Test Description")),
std::option::some(string::utf8(b"Test Updatable Metadata")),
std::option::none(),
timelock::none(),
&clock,
ctx,
);
Expand Down Expand Up @@ -84,7 +84,7 @@ public fun test_create_dynamic_notarization_with_vector_data() {
state,
std::option::some(string::utf8(b"Test Description")),
std::option::some(string::utf8(b"Test Updatable Metadata")),
std::option::none(),
timelock::none(),
&clock,
ctx,
);
Expand Down Expand Up @@ -139,7 +139,7 @@ public fun test_create_dynamic_notarization_with_transfer_lock() {
state,
std::option::some(string::utf8(b"Test Description")),
std::option::some(string::utf8(b"Test Updatable Metadata")),
std::option::some(transfer_lock),
transfer_lock,
&clock,
ctx,
);
Expand Down Expand Up @@ -183,7 +183,7 @@ public fun test_transfer_dynamic_notarization() {
state,
std::option::none(),
std::option::none(),
std::option::none(),
timelock::none(),
&clock,
scenario.ctx(),
);
Expand Down Expand Up @@ -242,7 +242,7 @@ public fun test_transfer_locked_dynamic_notarization() {
state,
std::option::none(),
std::option::none(),
std::option::some(transfer_lock),
transfer_lock,
&clock,
scenario.ctx(),
);
Expand Down Expand Up @@ -285,7 +285,7 @@ public fun test_update_dynamic_notarization() {
state,
std::option::none(),
std::option::none(),
std::option::none(),
timelock::none(),
&clock,
ctx,
);
Expand Down Expand Up @@ -344,7 +344,7 @@ public fun test_dynamic_notarization_with_until_destroyed_lock() {
state,
std::option::none(),
std::option::none(),
std::option::some(transfer_lock),
transfer_lock,
&clock,
ctx,
);
Expand All @@ -368,7 +368,7 @@ public fun test_dynamic_notarization_with_until_destroyed_lock() {
scenario.end();
}

#[test, expected_failure(abort_code = notarization::EDynamicNotarizationInvariants)]
#[test]
public fun test_dynamic_notarization_with_none_lock() {
let mut scenario = ts::begin(ADMIN_ADDRESS);
let ctx = scenario.ctx();
Expand All @@ -388,7 +388,7 @@ public fun test_dynamic_notarization_with_none_lock() {
state,
std::option::none(),
std::option::none(),
std::option::some(transfer_lock),
transfer_lock,
&clock,
ctx,
);
Expand All @@ -400,6 +400,7 @@ public fun test_dynamic_notarization_with_none_lock() {

// Verify it's transferable (has none transfer lock)
assert!(dynamic_notarization::is_transferable(&notarization, &clock), 0);
assert!(notarization.lock_metadata().is_none(), 0);

// Clean up
notarization::destroy(notarization, &clock);
Expand Down
10 changes: 5 additions & 5 deletions notarization-move/tests/notarization_tests.move
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public fun test_create_notarization_with_complex_object() {
state,
std::option::some(string::utf8(b"Test Description")),
std::option::some(string::utf8(b"Test Updateable Metadata")),
std::option::none(),
timelock::none(),
&clock,
ctx,
);
Expand Down Expand Up @@ -153,7 +153,7 @@ public fun test_state_updates_and_versioning() {
state,
std::option::some(string::utf8(b"Test Description")),
std::option::some(string::utf8(b"Test Updateable Metadata")),
std::option::none(),
timelock::none(),
&clock,
ctx,
);
Expand Down Expand Up @@ -316,7 +316,7 @@ public fun test_method_type_checks() {
state,
std::option::none(),
std::option::none(),
std::option::none(),
timelock::none(),
&clock,
ctx,
);
Expand Down Expand Up @@ -363,7 +363,7 @@ public fun test_is_destroy_allowed() {
state,
std::option::none(),
std::option::none(),
std::option::none(),
timelock::none(),
&clock,
ctx,
);
Expand Down Expand Up @@ -408,7 +408,7 @@ public fun test_method_specific_invariants() {
state,
std::option::none(),
std::option::none(),
std::option::none(),
timelock::none(),
&clock,
ctx,
);
Expand Down
3 changes: 0 additions & 3 deletions notarization-rs/src/core/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,6 @@ impl NotarizationBuilder<Locked> {
}

pub fn finish(self) -> Result<TransactionBuilder<CreateNotarization<Locked>>, Error> {
if self.delete_lock.is_none() {
return Err(Error::InvalidArgument("Locked needs delete_at()".to_string()));
}
Ok(TransactionBuilder::new(CreateNotarization::new(self)))
}
}
Expand Down
34 changes: 3 additions & 31 deletions notarization-rs/src/core/move_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@
use std::str::FromStr;

use iota_interaction::rpc_types::IotaObjectDataOptions;
use iota_interaction::types::base_types::{ObjectID, ObjectRef, STD_OPTION_MODULE_NAME};
use iota_interaction::types::base_types::{ObjectID, ObjectRef};
use iota_interaction::types::programmable_transaction_builder::ProgrammableTransactionBuilder as Ptb;
use iota_interaction::types::transaction::{Argument, ObjectArg};
use iota_interaction::types::{
IOTA_CLOCK_OBJECT_ID, IOTA_CLOCK_OBJECT_SHARED_VERSION, MOVE_STDLIB_PACKAGE_ID, TypeTag,
};
use iota_interaction::{IotaClientTrait, OptionalSync, ident_str};
use iota_interaction::types::{IOTA_CLOCK_OBJECT_ID, IOTA_CLOCK_OBJECT_SHARED_VERSION, TypeTag};
use iota_interaction::{IotaClientTrait, OptionalSync};
use product_common::core_client::CoreClientReadOnly;
use serde::Serialize;

Expand All @@ -26,32 +24,6 @@ pub(crate) fn get_clock_ref(ptb: &mut Ptb) -> Argument {
.expect("network has a singleton clock instantiated")
}

pub(crate) fn option_to_move_with_tag(
option: Option<Argument>,
tag: TypeTag,
ptb: &mut Ptb,
) -> Result<Argument, Error> {
let arg = if let Some(t) = option {
ptb.programmable_move_call(
MOVE_STDLIB_PACKAGE_ID,
STD_OPTION_MODULE_NAME.into(),
ident_str!("some").into(),
vec![tag],
vec![t],
)
} else {
ptb.programmable_move_call(
MOVE_STDLIB_PACKAGE_ID,
STD_OPTION_MODULE_NAME.into(),
ident_str!("none").into(),
vec![tag],
vec![],
)
};

Ok(arg)
}

pub(crate) fn ptb_pure<T>(ptb: &mut Ptb, name: &str, value: T) -> Result<Argument, Error>
where
T: Serialize + core::fmt::Debug,
Expand Down
18 changes: 6 additions & 12 deletions notarization-rs/src/core/notarization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,9 @@ impl<M: Clone> CreateNotarization<M> {

/// Indicates if the invariants for `NotarizationMethod::Dynamic` are satisfied:
///
/// - Dynamic notarization can only have transfer locking or no
/// `immutable_metadata.locking`.
/// If `immutable_metadata.locking` exists, all locks except `transfer_lock`
/// must be `TimeLock::None`
/// and the `transfer_lock` must not be `TimeLock::None`.
/// - Dynamic notarization can only have transfer locking or no `immutable_metadata.locking`. If
/// `immutable_metadata.locking` exists, all locks except `transfer_lock` must be `TimeLock::None` and the
/// `transfer_lock` must not be `TimeLock::None`.
fn are_dynamic_notarization_invariants_ok(locking: &Option<LockMetadata>) -> bool {
match locking {
Some(lock_metadata) => {
Expand Down Expand Up @@ -126,7 +124,7 @@ impl<M: Clone> CreateNotarization<M> {
state,
immutable_description,
updatable_metadata,
transfer_lock,
transfer_lock.unwrap_or(TimeLock::None),
)
}
NotarizationMethod::Locked => {
Expand All @@ -136,14 +134,10 @@ impl<M: Clone> CreateNotarization<M> {
));
}

let delete_lock = delete_lock.ok_or_else(|| {
Error::InvalidArgument("Delete lock is required for locked notarizations".to_string())
})?;

// Construct the locking metadata for locked notarization
let locking = Some(LockMetadata {
update_lock: TimeLock::UntilDestroyed,
delete_lock: delete_lock.clone(),
delete_lock: delete_lock.clone().unwrap_or(TimeLock::None),
transfer_lock: TimeLock::UntilDestroyed,
});

Expand All @@ -159,7 +153,7 @@ impl<M: Clone> CreateNotarization<M> {
state,
immutable_description,
updatable_metadata,
delete_lock,
delete_lock.unwrap_or(TimeLock::None),
)
}
}
Expand Down
10 changes: 3 additions & 7 deletions notarization-rs/src/core/operations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use iota_interaction::types::Identifier;
use iota_interaction::types::base_types::{IotaAddress, ObjectID};
use iota_interaction::types::programmable_transaction_builder::ProgrammableTransactionBuilder;
use iota_interaction::types::transaction::{Argument, ObjectArg, ProgrammableTransaction};
use iota_interaction::{MoveType, OptionalSync, ident_str};
use iota_interaction::{OptionalSync, ident_str};
use product_common::core_client::CoreClientReadOnly;

use super::move_utils;
Expand Down Expand Up @@ -121,7 +121,7 @@ pub trait NotarizationOperations {
state: State,
immutable_description: Option<String>,
updatable_metadata: Option<String>,
transfer_lock: Option<TimeLock>,
transfer_lock: TimeLock,
) -> Result<ProgrammableTransaction, Error> {
let mut ptb = ProgrammableTransactionBuilder::new();

Expand All @@ -130,11 +130,7 @@ pub trait NotarizationOperations {
let state_arg = state.into_ptb(&mut ptb, package_id)?;
let immutable_description = move_utils::ptb_pure(&mut ptb, "immutable_description", immutable_description)?;
let updatable_metadata = move_utils::ptb_pure(&mut ptb, "updatable_metadata", updatable_metadata)?;
let transfer_lock = transfer_lock
.map(|lock| lock.to_ptb(&mut ptb, package_id))
.transpose()?;
let transfer_lock =
move_utils::option_to_move_with_tag(transfer_lock, TimeLock::move_type(package_id), &mut ptb)?;
let transfer_lock = transfer_lock.to_ptb(&mut ptb, package_id)?;

ptb.programmable_move_call(
package_id,
Expand Down
Loading