Skip to content

Commit

Permalink
tx_context move side
Browse files Browse the repository at this point in the history
  • Loading branch information
dariorussi committed Jan 16, 2025
1 parent 0598968 commit 3a82104
Show file tree
Hide file tree
Showing 9 changed files with 696 additions and 41 deletions.
279 changes: 270 additions & 9 deletions crates/sui-framework/docs/sui-framework/tx_context.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,27 @@ title: Module `0x2::tx_context`


- [Struct `TxContext`](#0x2_tx_context_TxContext)
- [Constants](#@Constants_0)
- [Function `sender`](#0x2_tx_context_sender)
- [Function `digest`](#0x2_tx_context_digest)
- [Function `epoch`](#0x2_tx_context_epoch)
- [Function `epoch_timestamp_ms`](#0x2_tx_context_epoch_timestamp_ms)
- [Function `sponsor`](#0x2_tx_context_sponsor)
- [Function `fresh_object_address`](#0x2_tx_context_fresh_object_address)
- [Function `increment_ids_created`](#0x2_tx_context_increment_ids_created)
- [Function `ids_created`](#0x2_tx_context_ids_created)
- [Function `derive_id`](#0x2_tx_context_derive_id)
- [Function `native_sender`](#0x2_tx_context_native_sender)
- [Function `native_digest`](#0x2_tx_context_native_digest)
- [Function `native_epoch`](#0x2_tx_context_native_epoch)
- [Function `native_epoch_timestamp_ms`](#0x2_tx_context_native_epoch_timestamp_ms)
- [Function `native_sponsor`](#0x2_tx_context_native_sponsor)
- [Function `native_ids_created`](#0x2_tx_context_native_ids_created)
- [Function `native_inc_ids_created`](#0x2_tx_context_native_inc_ids_created)


<pre><code></code></pre>
<pre><code><b>use</b> <a href="../move-stdlib/option.md#0x1_option">0x1::option</a>;
</code></pre>



Expand Down Expand Up @@ -73,6 +84,29 @@ the VM and passed in to the entrypoint of the transaction as <code>&<b>mut</b> <

</details>

<a name="@Constants_0"></a>

## Constants


<a name="0x2_tx_context_EUnsupportedFunction"></a>



<pre><code><b>const</b> <a href="tx_context.md#0x2_tx_context_EUnsupportedFunction">EUnsupportedFunction</a>: <a href="../move-stdlib/u64.md#0x1_u64">u64</a> = 2;
</code></pre>



<a name="0x2_tx_context_NATIVE_CONTEXT"></a>



<pre><code><b>const</b> <a href="tx_context.md#0x2_tx_context_NATIVE_CONTEXT">NATIVE_CONTEXT</a>: bool = <b>false</b>;
</code></pre>



<a name="0x2_tx_context_sender"></a>

## Function `sender`
Expand All @@ -91,7 +125,11 @@ transaction


<pre><code><b>public</b> <b>fun</b> <a href="tx_context.md#0x2_tx_context_sender">sender</a>(self: &<a href="tx_context.md#0x2_tx_context_TxContext">TxContext</a>): <b>address</b> {
self.sender
<b>if</b> (<a href="tx_context.md#0x2_tx_context_NATIVE_CONTEXT">NATIVE_CONTEXT</a>) {
<a href="tx_context.md#0x2_tx_context_native_sender">native_sender</a>()
} <b>else</b> {
self.sender
}
}
</code></pre>

Expand All @@ -117,7 +155,11 @@ Please do not use as a source of randomness.


<pre><code><b>public</b> <b>fun</b> <a href="tx_context.md#0x2_tx_context_digest">digest</a>(self: &<a href="tx_context.md#0x2_tx_context_TxContext">TxContext</a>): &<a href="../move-stdlib/vector.md#0x1_vector">vector</a>&lt;u8&gt; {
&self.tx_hash
<b>if</b> (<a href="tx_context.md#0x2_tx_context_NATIVE_CONTEXT">NATIVE_CONTEXT</a>) {
<a href="tx_context.md#0x2_tx_context_native_digest">native_digest</a>()
} <b>else</b> {
&self.tx_hash
}
}
</code></pre>

Expand All @@ -142,7 +184,11 @@ Return the current epoch


<pre><code><b>public</b> <b>fun</b> <a href="tx_context.md#0x2_tx_context_epoch">epoch</a>(self: &<a href="tx_context.md#0x2_tx_context_TxContext">TxContext</a>): <a href="../move-stdlib/u64.md#0x1_u64">u64</a> {
self.epoch
<b>if</b> (<a href="tx_context.md#0x2_tx_context_NATIVE_CONTEXT">NATIVE_CONTEXT</a>) {
<a href="tx_context.md#0x2_tx_context_native_epoch">native_epoch</a>()
} <b>else</b> {
self.epoch
}
}
</code></pre>

Expand All @@ -167,7 +213,36 @@ Return the epoch start time as a unix timestamp in milliseconds.


<pre><code><b>public</b> <b>fun</b> <a href="tx_context.md#0x2_tx_context_epoch_timestamp_ms">epoch_timestamp_ms</a>(self: &<a href="tx_context.md#0x2_tx_context_TxContext">TxContext</a>): <a href="../move-stdlib/u64.md#0x1_u64">u64</a> {
self.epoch_timestamp_ms
<b>if</b> (<a href="tx_context.md#0x2_tx_context_NATIVE_CONTEXT">NATIVE_CONTEXT</a>) {
<a href="tx_context.md#0x2_tx_context_native_epoch_timestamp_ms">native_epoch_timestamp_ms</a>()
} <b>else</b> {
self.epoch_timestamp_ms
}
}
</code></pre>



</details>

<a name="0x2_tx_context_sponsor"></a>

## Function `sponsor`



<pre><code><b>public</b> <b>fun</b> <a href="tx_context.md#0x2_tx_context_sponsor">sponsor</a>(_self: &<a href="tx_context.md#0x2_tx_context_TxContext">tx_context::TxContext</a>): <a href="../move-stdlib/option.md#0x1_option_Option">option::Option</a>&lt;<b>address</b>&gt;
</code></pre>



<details>
<summary>Implementation</summary>


<pre><code><b>public</b> <b>fun</b> <a href="tx_context.md#0x2_tx_context_sponsor">sponsor</a>(_self: &<a href="tx_context.md#0x2_tx_context_TxContext">TxContext</a>): Option&lt;<b>address</b>&gt; {
<b>assert</b>!(<a href="tx_context.md#0x2_tx_context_NATIVE_CONTEXT">NATIVE_CONTEXT</a>, <a href="tx_context.md#0x2_tx_context_EUnsupportedFunction">EUnsupportedFunction</a>);
<a href="tx_context.md#0x2_tx_context_native_sponsor">native_sponsor</a>()
}
</code></pre>

Expand All @@ -194,15 +269,43 @@ In other words, the generated address is a globally unique object ID.


<pre><code><b>public</b> <b>fun</b> <a href="tx_context.md#0x2_tx_context_fresh_object_address">fresh_object_address</a>(ctx: &<b>mut</b> <a href="tx_context.md#0x2_tx_context_TxContext">TxContext</a>): <b>address</b> {
<b>let</b> ids_created = ctx.ids_created;
<b>let</b> id = <a href="tx_context.md#0x2_tx_context_derive_id">derive_id</a>(*&ctx.tx_hash, ids_created);
ctx.ids_created = ids_created + 1;
<b>let</b> ids_created = ctx.<a href="tx_context.md#0x2_tx_context_ids_created">ids_created</a>();
<b>let</b> id = <a href="tx_context.md#0x2_tx_context_derive_id">derive_id</a>(*ctx.<a href="tx_context.md#0x2_tx_context_digest">digest</a>(), ids_created);
ctx.<a href="tx_context.md#0x2_tx_context_increment_ids_created">increment_ids_created</a>();
id
}
</code></pre>



</details>

<a name="0x2_tx_context_increment_ids_created"></a>

## Function `increment_ids_created`



<pre><code><b>fun</b> <a href="tx_context.md#0x2_tx_context_increment_ids_created">increment_ids_created</a>(self: &<b>mut</b> <a href="tx_context.md#0x2_tx_context_TxContext">tx_context::TxContext</a>)
</code></pre>



<details>
<summary>Implementation</summary>


<pre><code><b>fun</b> <a href="tx_context.md#0x2_tx_context_increment_ids_created">increment_ids_created</a>(self: &<b>mut</b> <a href="tx_context.md#0x2_tx_context_TxContext">TxContext</a>) {
<b>if</b> (<a href="tx_context.md#0x2_tx_context_NATIVE_CONTEXT">NATIVE_CONTEXT</a>) {
self.<a href="tx_context.md#0x2_tx_context_native_inc_ids_created">native_inc_ids_created</a>()
} <b>else</b> {
self.ids_created = self.ids_created + 1
}
}
</code></pre>



</details>

<a name="0x2_tx_context_ids_created"></a>
Expand All @@ -223,7 +326,11 @@ Hidden for now, but may expose later


<pre><code><b>fun</b> <a href="tx_context.md#0x2_tx_context_ids_created">ids_created</a>(self: &<a href="tx_context.md#0x2_tx_context_TxContext">TxContext</a>): <a href="../move-stdlib/u64.md#0x1_u64">u64</a> {
self.ids_created
<b>if</b> (<a href="tx_context.md#0x2_tx_context_NATIVE_CONTEXT">NATIVE_CONTEXT</a>) {
<a href="tx_context.md#0x2_tx_context_native_ids_created">native_ids_created</a>()
} <b>else</b> {
self.ids_created
}
}
</code></pre>

Expand Down Expand Up @@ -252,4 +359,158 @@ Native function for deriving an ID via hash(tx_hash || ids_created)



</details>

<a name="0x2_tx_context_native_sender"></a>

## Function `native_sender`



<pre><code><b>fun</b> <a href="tx_context.md#0x2_tx_context_native_sender">native_sender</a>(): <b>address</b>
</code></pre>



<details>
<summary>Implementation</summary>


<pre><code><b>native</b> <b>fun</b> <a href="tx_context.md#0x2_tx_context_native_sender">native_sender</a>(): <b>address</b>;
</code></pre>



</details>

<a name="0x2_tx_context_native_digest"></a>

## Function `native_digest`



<pre><code><b>fun</b> <a href="tx_context.md#0x2_tx_context_native_digest">native_digest</a>(): &<a href="../move-stdlib/vector.md#0x1_vector">vector</a>&lt;u8&gt;
</code></pre>



<details>
<summary>Implementation</summary>


<pre><code><b>native</b> <b>fun</b> <a href="tx_context.md#0x2_tx_context_native_digest">native_digest</a>(): &<a href="../move-stdlib/vector.md#0x1_vector">vector</a>&lt;u8&gt;;
</code></pre>



</details>

<a name="0x2_tx_context_native_epoch"></a>

## Function `native_epoch`



<pre><code><b>fun</b> <a href="tx_context.md#0x2_tx_context_native_epoch">native_epoch</a>(): <a href="../move-stdlib/u64.md#0x1_u64">u64</a>
</code></pre>



<details>
<summary>Implementation</summary>


<pre><code><b>native</b> <b>fun</b> <a href="tx_context.md#0x2_tx_context_native_epoch">native_epoch</a>(): <a href="../move-stdlib/u64.md#0x1_u64">u64</a>;
</code></pre>



</details>

<a name="0x2_tx_context_native_epoch_timestamp_ms"></a>

## Function `native_epoch_timestamp_ms`



<pre><code><b>fun</b> <a href="tx_context.md#0x2_tx_context_native_epoch_timestamp_ms">native_epoch_timestamp_ms</a>(): <a href="../move-stdlib/u64.md#0x1_u64">u64</a>
</code></pre>



<details>
<summary>Implementation</summary>


<pre><code><b>native</b> <b>fun</b> <a href="tx_context.md#0x2_tx_context_native_epoch_timestamp_ms">native_epoch_timestamp_ms</a>(): <a href="../move-stdlib/u64.md#0x1_u64">u64</a>;
</code></pre>



</details>

<a name="0x2_tx_context_native_sponsor"></a>

## Function `native_sponsor`



<pre><code><b>fun</b> <a href="tx_context.md#0x2_tx_context_native_sponsor">native_sponsor</a>(): <a href="../move-stdlib/option.md#0x1_option_Option">option::Option</a>&lt;<b>address</b>&gt;
</code></pre>



<details>
<summary>Implementation</summary>


<pre><code><b>native</b> <b>fun</b> <a href="tx_context.md#0x2_tx_context_native_sponsor">native_sponsor</a>(): Option&lt;<b>address</b>&gt;;
</code></pre>



</details>

<a name="0x2_tx_context_native_ids_created"></a>

## Function `native_ids_created`



<pre><code><b>fun</b> <a href="tx_context.md#0x2_tx_context_native_ids_created">native_ids_created</a>(): <a href="../move-stdlib/u64.md#0x1_u64">u64</a>
</code></pre>



<details>
<summary>Implementation</summary>


<pre><code><b>native</b> <b>fun</b> <a href="tx_context.md#0x2_tx_context_native_ids_created">native_ids_created</a>(): <a href="../move-stdlib/u64.md#0x1_u64">u64</a>;
</code></pre>



</details>

<a name="0x2_tx_context_native_inc_ids_created"></a>

## Function `native_inc_ids_created`



<pre><code><b>fun</b> <a href="tx_context.md#0x2_tx_context_native_inc_ids_created">native_inc_ids_created</a>(self: &<b>mut</b> <a href="tx_context.md#0x2_tx_context_TxContext">tx_context::TxContext</a>)
</code></pre>



<details>
<summary>Implementation</summary>


<pre><code><b>native</b> <b>fun</b> <a href="tx_context.md#0x2_tx_context_native_inc_ids_created">native_inc_ids_created</a>(self: &<b>mut</b> <a href="tx_context.md#0x2_tx_context_TxContext">TxContext</a>);
</code></pre>



</details>
8 changes: 4 additions & 4 deletions crates/sui-framework/packages/sui-framework/Move.lock
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
# @generated by Move, please check-in and do not edit manually.

[move]
version = 1
version = 3
manifest_digest = "ED5DEFBBF556EE89312E639A53F21DE24320F9B13C2087D3BFE2989D5B2B5DAF"
deps_digest = "F8BBB0CCB2491CA29A3DF03D6F92277A4F3574266507ACD77214D37ECA3F3082"

dependencies = [
{ name = "MoveStdlib" },
{ id = "MoveStdlib", name = "MoveStdlib" },
]

[[move.package]]
name = "MoveStdlib"
id = "MoveStdlib"
source = { local = "../move-stdlib" }

[move.toolchain-version]
compiler-version = "1.30.0"
compiler-version = "1.39.3"
edition = "2024.beta"
flavor = "sui"
Loading

0 comments on commit 3a82104

Please sign in to comment.