Skip to content

Commit

Permalink
chore(merge): added a Stardust system package with basic unlock condi…
Browse files Browse the repository at this point in the history
…tions
  • Loading branch information
valeriyr authored Apr 23, 2024
2 parents 1d186fa + 0c5709a commit f1846e5
Show file tree
Hide file tree
Showing 15 changed files with 757 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Move.lock
!crates/sui-framework/packages/sui-framework/Move.lock
!crates/sui-framework/packages/sui-system/Move.lock
!crates/sui-framework/packages/deepbook/Move.lock
!crates/sui-framework/packages/stardust/Move.lock
.trace
.coverage_map.mvcov

Expand Down
10 changes: 10 additions & 0 deletions crates/sui-framework-tests/src/unit_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,16 @@ fn run_deepbook_tests() {
});
}

#[test]
#[cfg_attr(msim, ignore)]
fn run_stardust_tests() {
check_move_unit_tests({
let mut buf = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
buf.extend(["..", "sui-framework", "packages", "stardust"]);
buf
});
}

#[test]
#[cfg_attr(msim, ignore)]
fn run_examples_move_unit_tests() {
Expand Down
34 changes: 33 additions & 1 deletion crates/sui-framework/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,18 @@ fn main() {
let deepbook_path = packages_path.join("deepbook");
let sui_system_path = packages_path.join("sui-system");
let sui_framework_path = packages_path.join("sui-framework");
let stardust_path = packages_path.join("stardust");
let deepbook_path_clone = deepbook_path.clone();
let sui_system_path_clone = sui_system_path.clone();
let sui_framework_path_clone = sui_framework_path.clone();
let stardust_path_clone = stardust_path.clone();
let move_stdlib_path = packages_path.join("move-stdlib");

build_packages(
deepbook_path_clone,
sui_system_path_clone,
sui_framework_path_clone,
stardust_path_clone,
out_dir,
);

Expand Down Expand Up @@ -69,12 +72,21 @@ fn main() {
"cargo:rerun-if-changed={}",
move_stdlib_path.join("sources").display()
);
println!(
"cargo:rerun-if-changed={}",
stardust_path.join("Move.toml").display()
);
println!(
"cargo:rerun-if-changed={}",
stardust_path.join("sources").display()
);
}

fn build_packages(
deepbook_path: PathBuf,
sui_system_path: PathBuf,
sui_framework_path: PathBuf,
stardust_path: PathBuf,
out_dir: PathBuf,
) {
let config = MoveBuildConfig {
Expand All @@ -90,11 +102,13 @@ fn build_packages(
deepbook_path.clone(),
sui_system_path.clone(),
sui_framework_path.clone(),
stardust_path.clone(),
out_dir.clone(),
"deepbook",
"sui-system",
"sui-framework",
"move-stdlib",
"stardust",
config,
true,
);
Expand All @@ -111,11 +125,13 @@ fn build_packages(
deepbook_path,
sui_system_path,
sui_framework_path,
stardust_path,
out_dir,
"deepbook-test",
"sui-system-test",
"sui-framework-test",
"move-stdlib-test",
"stardust-test",
config,
false,
);
Expand All @@ -125,11 +141,13 @@ fn build_packages_with_move_config(
deepbook_path: PathBuf,
sui_system_path: PathBuf,
sui_framework_path: PathBuf,
stardust_path: PathBuf,
out_dir: PathBuf,
deepbook_dir: &str,
system_dir: &str,
framework_dir: &str,
stdlib_dir: &str,
stardust_dir: &str,
config: MoveBuildConfig,
write_docs: bool,
) {
Expand All @@ -148,22 +166,31 @@ fn build_packages_with_move_config(
.build(sui_system_path)
.unwrap();
let deepbook_pkg = BuildConfig {
config,
config: config.clone(),
run_bytecode_verifier: true,
print_diags_to_stderr: false,
}
.build(deepbook_path)
.unwrap();
let stardust_pkg = BuildConfig {
config,
run_bytecode_verifier: true,
print_diags_to_stderr: false,
}
.build(stardust_path)
.unwrap();

let sui_system = system_pkg.get_sui_system_modules();
let sui_framework = framework_pkg.get_sui_framework_modules();
let deepbook = deepbook_pkg.get_deepbook_modules();
let move_stdlib = framework_pkg.get_stdlib_modules();
let stardust = stardust_pkg.get_stdlib_modules();

serialize_modules_to_file(sui_system, &out_dir.join(system_dir)).unwrap();
serialize_modules_to_file(sui_framework, &out_dir.join(framework_dir)).unwrap();
serialize_modules_to_file(deepbook, &out_dir.join(deepbook_dir)).unwrap();
serialize_modules_to_file(move_stdlib, &out_dir.join(stdlib_dir)).unwrap();
serialize_modules_to_file(stardust, &out_dir.join(stardust_dir)).unwrap();
// write out generated docs
if write_docs {
// Remove the old docs directory -- in case there was a module that was deleted (could
Expand All @@ -187,6 +214,11 @@ fn build_packages_with_move_config(
&framework_pkg.package.compiled_docs.unwrap(),
&mut files_to_write,
);
relocate_docs(
stardust_dir,
&stardust_pkg.package.compiled_docs.unwrap(),
&mut files_to_write,
);
for (fname, doc) in files_to_write {
let mut dst_path = PathBuf::from(DOCS_DIR);
dst_path.push(fname);
Expand Down
214 changes: 214 additions & 0 deletions crates/sui-framework/docs/stardust/expiration_unlock_condition.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,214 @@
---
title: Module `0x107a::expiration_unlock_condition`
---



- [Struct `ExpirationUnlockCondition`](#0x107a_expiration_unlock_condition_ExpirationUnlockCondition)
- [Constants](#@Constants_0)
- [Function `unlock`](#0x107a_expiration_unlock_condition_unlock)
- [Function `can_be_unlocked_by`](#0x107a_expiration_unlock_condition_can_be_unlocked_by)
- [Function `owner`](#0x107a_expiration_unlock_condition_owner)
- [Function `return_address`](#0x107a_expiration_unlock_condition_return_address)
- [Function `unix_time`](#0x107a_expiration_unlock_condition_unix_time)


<pre><code><b>use</b> <a href="../sui-framework/tx_context.md#0x2_tx_context">0x2::tx_context</a>;
</code></pre>



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

## Struct `ExpirationUnlockCondition`

The Stardust expiration unlock condition.


<pre><code><b>struct</b> <a href="expiration_unlock_condition.md#0x107a_expiration_unlock_condition_ExpirationUnlockCondition">ExpirationUnlockCondition</a> <b>has</b> store
</code></pre>



<details>
<summary>Fields</summary>


<dl>
<dt>
<code>owner: <b>address</b></code>
</dt>
<dd>
The address who owns the output before the timestamp has passed.
</dd>
<dt>
<code>return_address: <b>address</b></code>
</dt>
<dd>
The address that is allowed to spend the locked funds after the timestamp has passed.
</dd>
<dt>
<code>unix_time: u32</code>
</dt>
<dd>
Before this unix time, Address Unlock Condition is allowed to unlock the output, after that only the address defined in Return Address.
</dd>
</dl>


</details>

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

## Constants


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

The output can not be unlocked by the sender error.


<pre><code><b>const</b> <a href="expiration_unlock_condition.md#0x107a_expiration_unlock_condition_EWrongSender">EWrongSender</a>: u64 = 0;
</code></pre>



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

## Function `unlock`

Check the unlock condition.


<pre><code><b>public</b> <b>fun</b> <a href="expiration_unlock_condition.md#0x107a_expiration_unlock_condition_unlock">unlock</a>(condition: <a href="expiration_unlock_condition.md#0x107a_expiration_unlock_condition_ExpirationUnlockCondition">expiration_unlock_condition::ExpirationUnlockCondition</a>, ctx: &<b>mut</b> <a href="../sui-framework/tx_context.md#0x2_tx_context_TxContext">tx_context::TxContext</a>)
</code></pre>



<details>
<summary>Implementation</summary>


<pre><code><b>public</b> <b>fun</b> <a href="expiration_unlock_condition.md#0x107a_expiration_unlock_condition_unlock">unlock</a>(condition: <a href="expiration_unlock_condition.md#0x107a_expiration_unlock_condition_ExpirationUnlockCondition">ExpirationUnlockCondition</a>, ctx: &<b>mut</b> TxContext) {
<b>let</b> unlock_address = condition.<a href="expiration_unlock_condition.md#0x107a_expiration_unlock_condition_can_be_unlocked_by">can_be_unlocked_by</a>(ctx);

<b>assert</b>!(unlock_address == ctx.sender(), <a href="expiration_unlock_condition.md#0x107a_expiration_unlock_condition_EWrongSender">EWrongSender</a>);

<b>let</b> <a href="expiration_unlock_condition.md#0x107a_expiration_unlock_condition_ExpirationUnlockCondition">ExpirationUnlockCondition</a> {
owner: _,
return_address: _,
unix_time: _,
} = condition;
}
</code></pre>



</details>

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

## Function `can_be_unlocked_by`

Return the address that can unlock the related output.


<pre><code><b>public</b> <b>fun</b> <a href="expiration_unlock_condition.md#0x107a_expiration_unlock_condition_can_be_unlocked_by">can_be_unlocked_by</a>(condition: &<a href="expiration_unlock_condition.md#0x107a_expiration_unlock_condition_ExpirationUnlockCondition">expiration_unlock_condition::ExpirationUnlockCondition</a>, ctx: &<a href="../sui-framework/tx_context.md#0x2_tx_context_TxContext">tx_context::TxContext</a>): <b>address</b>
</code></pre>



<details>
<summary>Implementation</summary>


<pre><code><b>public</b> <b>fun</b> <a href="expiration_unlock_condition.md#0x107a_expiration_unlock_condition_can_be_unlocked_by">can_be_unlocked_by</a>(condition: &<a href="expiration_unlock_condition.md#0x107a_expiration_unlock_condition_ExpirationUnlockCondition">ExpirationUnlockCondition</a>, ctx: &TxContext): <b>address</b> {
// Unix time in seconds.
<b>let</b> current_time = ((<a href="../sui-framework/tx_context.md#0x2_tx_context_epoch_timestamp_ms">tx_context::epoch_timestamp_ms</a>(ctx) / 1000) <b>as</b> u32);

<b>if</b> (condition.<a href="expiration_unlock_condition.md#0x107a_expiration_unlock_condition_unix_time">unix_time</a>() &lt; current_time) {
condition.<a href="expiration_unlock_condition.md#0x107a_expiration_unlock_condition_return_address">return_address</a>()
} <b>else</b> {
condition.<a href="expiration_unlock_condition.md#0x107a_expiration_unlock_condition_owner">owner</a>()
}
}
</code></pre>



</details>

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

## Function `owner`

Get the unlock condition's <code>owner</code>.


<pre><code><b>public</b> <b>fun</b> <a href="expiration_unlock_condition.md#0x107a_expiration_unlock_condition_owner">owner</a>(condition: &<a href="expiration_unlock_condition.md#0x107a_expiration_unlock_condition_ExpirationUnlockCondition">expiration_unlock_condition::ExpirationUnlockCondition</a>): <b>address</b>
</code></pre>



<details>
<summary>Implementation</summary>


<pre><code><b>public</b> <b>fun</b> <a href="expiration_unlock_condition.md#0x107a_expiration_unlock_condition_owner">owner</a>(condition: &<a href="expiration_unlock_condition.md#0x107a_expiration_unlock_condition_ExpirationUnlockCondition">ExpirationUnlockCondition</a>): <b>address</b> {
condition.owner
}
</code></pre>



</details>

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

## Function `return_address`

Get the unlock condition's <code>return_address</code>.


<pre><code><b>public</b> <b>fun</b> <a href="expiration_unlock_condition.md#0x107a_expiration_unlock_condition_return_address">return_address</a>(condition: &<a href="expiration_unlock_condition.md#0x107a_expiration_unlock_condition_ExpirationUnlockCondition">expiration_unlock_condition::ExpirationUnlockCondition</a>): <b>address</b>
</code></pre>



<details>
<summary>Implementation</summary>


<pre><code><b>public</b> <b>fun</b> <a href="expiration_unlock_condition.md#0x107a_expiration_unlock_condition_return_address">return_address</a>(condition: &<a href="expiration_unlock_condition.md#0x107a_expiration_unlock_condition_ExpirationUnlockCondition">ExpirationUnlockCondition</a>): <b>address</b> {
condition.return_address
}
</code></pre>



</details>

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

## Function `unix_time`

Get the unlock condition's <code>unix_time</code>.


<pre><code><b>public</b> <b>fun</b> <a href="expiration_unlock_condition.md#0x107a_expiration_unlock_condition_unix_time">unix_time</a>(condition: &<a href="expiration_unlock_condition.md#0x107a_expiration_unlock_condition_ExpirationUnlockCondition">expiration_unlock_condition::ExpirationUnlockCondition</a>): u32
</code></pre>



<details>
<summary>Implementation</summary>


<pre><code><b>public</b> <b>fun</b> <a href="expiration_unlock_condition.md#0x107a_expiration_unlock_condition_unix_time">unix_time</a>(condition: &<a href="expiration_unlock_condition.md#0x107a_expiration_unlock_condition_ExpirationUnlockCondition">ExpirationUnlockCondition</a>): u32 {
condition.unix_time
}
</code></pre>



</details>
Loading

0 comments on commit f1846e5

Please sign in to comment.