[sui-framework] Macros for dynamic fields and dynamic object fields#26166
[sui-framework] Macros for dynamic fields and dynamic object fields#26166tnowacki wants to merge 7 commits intoMystenLabs:mainfrom
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
| ) { | ||
| let o = $object; | ||
| let name = $name; | ||
| if (exists_with_type<$Name, $Value>(o, name)) { $f(borrow(o, name)); } |
There was a problem hiding this comment.
is it not an error to call this when the field does not exist? at least in debug mode etc.
There was a problem hiding this comment.
What is? Both exists_* calls are safe to call, that's their goal.
There was a problem hiding this comment.
i meant if element does not exist, should we do nothing or emit an error
crates/sui-framework/packages/sui-framework/tests/dynamic_object_field_tests.move
Outdated
Show resolved
Hide resolved
|
|
||
| /// If the field exists, call `$f` on an immutable reference to the value. | ||
| /// This is like getting an `Option<&Value>` then calling `std::option::do`. | ||
| public macro fun get_do<$Name: copy + drop + store, $Value: key + store, $R: drop>( |
There was a problem hiding this comment.
I'm sure we've discussed this, but I can't recall why is it not get_ref_do?
There was a problem hiding this comment.
Is it that get_ always returns a Ref? And then the value would be remove_*?
There was a problem hiding this comment.
Correct yeah, it is basically get_do_ref but since it is always a ref we are eliding it.
Similarly it will be remove_opt_do, but since it is always opt we are skipping it
There was a problem hiding this comment.
errr actually no. It is option::do not do_ref. Because it is Option<T> and |T| -> R, the issue is that today you can't have T = &_
| fun borrow_or_add_existing() { | ||
| let sender = @0x0; | ||
| let mut scenario = test_scenario::begin(sender); | ||
| let mut id = scenario.new_object(); |
There was a problem hiding this comment.
TIL. Didn't know we have it on scenario.
Description
Test plan
Release notes
Check each box that your changes affect. If none of the boxes relate to your changes, release notes aren't required.
For each box you select, include information after the relevant heading that describes the impact of your changes that a user might notice and any actions they must take to implement updates.
Protocol:
Adds
sui::dynamic_field::borrow_or_addAdds
sui::dynamic_field::borrow_mut_or_addAdds
sui::dynamic_field::get_doAdds
sui::dynamic_field::get_mut_doAdds
sui::dynamic_field::get_foldAdds
sui::dynamic_field::get_mut_foldAdds
sui::dynamic_object_field::borrow_or_addAdds
sui::dynamic_object_field::borrow_mut_or_addAdds
sui::dynamic_object_field::get_doAdds
sui::dynamic_object_field::get_mut_doAdds
sui::dynamic_object_field::get_foldAdds
sui::dynamic_object_field::get_mut_foldNodes (Validators and Full nodes):
gRPC:
JSON-RPC:
GraphQL:
CLI:
Rust SDK:
Indexing Framework: