-
Notifications
You must be signed in to change notification settings - Fork 91
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Move Object] Public Object transfer, borrow, borrow_mut #989
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎ 1 Ignored Deployment
|
@@ -50,6 +50,10 @@ module moveos_std::object { | |||
&self.value | |||
} | |||
|
|||
public fun public_borrow<T: key + store>(self: &Object<T>): &T { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about we remove the private_generics
from borrow
and borrow_mut
? Because Context::borrow_object
and Context::borrow_object_mut
has the private_generics
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And should we support borrowing Object<T: key+store> from Context without private_generics
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And should we support borrowing Object<T: key+store> from Context without
private_generics
?
Maybe this shouldn't be the case, it would mean that other modules could borrow arbitrary Object
This may cause security issues
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about we remove the
private_generics
fromborrow
andborrow_mut
? BecauseContext::borrow_object
andContext::borrow_object_mut
has theprivate_generics
.
@stevenlaw123 @pause125 @baichuan3
I think it's reasonable
Because there is no way to get &Object<T>
or Object<T>
except context and current module.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
borrowing Object<T: key+store>
The reference of Object can only be obtained through context. I think it can be removed and there is no security issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In my understanding, borrow Object<T: key> and borrow Object<T: key + store> satisfy two types of scenarios respectively?
- If Object<T: key> is only a key capability, it can only be accessed through context::borrow_object (with private_generics(T) restriction) or object:borrow (need to pass Object reference);
- If Object<T: key+store> also has store capability, in addition to option 1, it can also be called through context::public_borrow_object* (there is no private_generics(T) restriction, and there is no need to pass the Object reference).
@@ -70,6 +78,10 @@ module moveos_std::object { | |||
self.owner = recipient; | |||
} | |||
|
|||
public fun public_transfer<T: key + store>(self: &mut Object<T>, recipient: address) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make the transfer
to key + store
and remove #[private_generics(T)]
, public_transfer
to transfer_extend
? Keep consistency with coin
and account_coin_store
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does xxx_extend
always have #[private_generics(T)] check? Is it more appropriate to put the object public_transfer
function in the transfer module?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The transfer function in the transfer module needs to use object_id as the argument.
public entry transfer_object<T:key+store>(ctx, object_id, to){
let object = context::borrow_object_mut<T>(ctx, object_id);
object::transfer(object, to);
}
So, it depends on how to support the public borrow object from context.
0338734
to
242c8da
Compare
Summary
Object should be freely borrowable or transferable
Therefore, the borrow and transfer of Object with Key + store are added
Public_add and public_remove have not been added for the time being because they may destabilize the life cycle of Object, so these two functions will not be added for the time being.