nexus_sdk/move_bindings/extensions/
shared_object_ref.rs1use crate::{
8 move_bindings::{primitives::shared_object::SharedObjectRef, sui_framework::object::ID},
9 sui,
10};
11
12impl SharedObjectRef {
13 pub fn new_imm(id: sui::types::Address) -> Self {
15 Self {
16 id: ID { bytes: id },
17 ref_mut: false,
18 }
19 }
20
21 pub fn new_mut(id: sui::types::Address) -> Self {
23 Self {
24 id: ID { bytes: id },
25 ref_mut: true,
26 }
27 }
28
29 pub fn id_address(&self) -> sui::types::Address {
30 self.id.bytes
31 }
32}
33
34#[cfg(test)]
35mod tests {
36 use super::*;
37
38 #[test]
39 fn constructors_set_mutability_and_id_address() {
40 let immutable_id = sui::types::Address::from_static("0x123");
41 let mutable_id = sui::types::Address::from_static("0x456");
42
43 let immutable = SharedObjectRef::new_imm(immutable_id);
44 let mutable = SharedObjectRef::new_mut(mutable_id);
45
46 assert_eq!(immutable.id_address(), immutable_id);
47 assert!(!immutable.ref_mut);
48 assert_eq!(mutable.id_address(), mutable_id);
49 assert!(mutable.ref_mut);
50 }
51}