Skip to content

Commit

Permalink
[MoveosStd] unpack the object when context::remove_object
Browse files Browse the repository at this point in the history
  • Loading branch information
jolestar committed Oct 11, 2023
1 parent 5e63abe commit 5e9e1fa
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
9 changes: 5 additions & 4 deletions moveos/moveos-stdlib/moveos-stdlib/doc/context.md
Original file line number Diff line number Diff line change
Expand Up @@ -432,10 +432,10 @@ Borrow mut Object from object store with object_id

## Function `remove_object`

Remove object from object store
Remove object from object store, and unpack the Object


<pre><code><b>public</b> <b>fun</b> <a href="context.md#0x2_context_remove_object">remove_object</a>&lt;T: key&gt;(self: &<b>mut</b> <a href="context.md#0x2_context_Context">context::Context</a>, <a href="object_id.md#0x2_object_id">object_id</a>: <a href="object_id.md#0x2_object_id_ObjectID">object_id::ObjectID</a>): <a href="object.md#0x2_object_Object">object::Object</a>&lt;T&gt;
<pre><code><b>public</b> <b>fun</b> <a href="context.md#0x2_context_remove_object">remove_object</a>&lt;T: key&gt;(self: &<b>mut</b> <a href="context.md#0x2_context_Context">context::Context</a>, <a href="object_id.md#0x2_object_id">object_id</a>: <a href="object_id.md#0x2_object_id_ObjectID">object_id::ObjectID</a>): (<a href="object_id.md#0x2_object_id_ObjectID">object_id::ObjectID</a>, <b>address</b>, T)
</code></pre>


Expand All @@ -444,8 +444,9 @@ Remove object from object store
<summary>Implementation</summary>


<pre><code><b>public</b> <b>fun</b> <a href="context.md#0x2_context_remove_object">remove_object</a>&lt;T: key&gt;(self: &<b>mut</b> <a href="context.md#0x2_context_Context">Context</a>, <a href="object_id.md#0x2_object_id">object_id</a>: ObjectID): Object&lt;T&gt; {
<a href="storage_context.md#0x2_storage_context_remove">storage_context::remove</a>&lt;T&gt;(&<b>mut</b> self.<a href="storage_context.md#0x2_storage_context">storage_context</a>, <a href="object_id.md#0x2_object_id">object_id</a>)
<pre><code><b>public</b> <b>fun</b> <a href="context.md#0x2_context_remove_object">remove_object</a>&lt;T: key&gt;(self: &<b>mut</b> <a href="context.md#0x2_context_Context">Context</a>, <a href="object_id.md#0x2_object_id">object_id</a>: ObjectID): (ObjectID, <b>address</b>, T) {
<b>let</b> obj = <a href="storage_context.md#0x2_storage_context_remove">storage_context::remove</a>&lt;T&gt;(&<b>mut</b> self.<a href="storage_context.md#0x2_storage_context">storage_context</a>, <a href="object_id.md#0x2_object_id">object_id</a>);
<a href="object.md#0x2_object_unpack_internal">object::unpack_internal</a>(obj)
}
</code></pre>

Expand Down
7 changes: 4 additions & 3 deletions moveos/moveos-stdlib/moveos-stdlib/sources/context.move
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,10 @@ module moveos_std::context {
}

#[private_generics(T)]
/// Remove object from object store
public fun remove_object<T: key>(self: &mut Context, object_id: ObjectID): Object<T> {
storage_context::remove<T>(&mut self.storage_context, object_id)
/// Remove object from object store, and unpack the Object
public fun remove_object<T: key>(self: &mut Context, object_id: ObjectID): (ObjectID, address, T) {
let obj = storage_context::remove<T>(&mut self.storage_context, object_id);
object::unpack_internal(obj)
}

public fun contains_object(self: &Context, object_id: ObjectID): bool {
Expand Down

0 comments on commit 5e9e1fa

Please sign in to comment.