Skip to content

Commit

Permalink
refactor(docs/examples): Create a utility methods lib (#1821)
Browse files Browse the repository at this point in the history
* refactor(docs/examples): create a utility methods lib

* refactor(docs/examples): update examples

* refactor(docs/content): update examples code lines in docs

* fix(docs/examples): move module path

* fix(docs/examples): address uc name

* Update docs/examples/rust/src/lib.rs

Co-authored-by: Thoralf-M <[email protected]>

* Update docs/content/developer/stardust/claiming/nft.mdx

Co-authored-by: Thoralf-M <[email protected]>

* fix(docs/examples): move utils out of lib

---------

Co-authored-by: Thoralf-M <[email protected]>
  • Loading branch information
miker83z and Thoralf-M authored Aug 14, 2024
1 parent fb392c4 commit 3a45555
Show file tree
Hide file tree
Showing 17 changed files with 271 additions and 525 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ For this example, we're using an `AliasOutput` to extract an `Alias` object that
<Tabs>
<TabItem value="rs" label="Rust">

```rust file=<rootDir>/docs/examples/rust/stardust/address_unlock_condition.rs#L74-L90
```rust file=<rootDir>/docs/examples/rust/stardust/address-unlock-condition.rs#L70-L88
```

</TabItem>
Expand All @@ -27,7 +27,7 @@ For this example, we're using an `AliasOutput` to extract an `Alias` object that
<Tabs>
<TabItem value="rs" label="Rust">

```rust file=<rootDir>/docs/examples/rust/stardust/address_unlock_condition.rs#L95-L105
```rust file=<rootDir>/docs/examples/rust/stardust/address-unlock-condition.rs#L90-L103
```

</TabItem>
Expand All @@ -42,7 +42,7 @@ Applying the filter to get `NftOutput`s owned by the `Alias`.
<Tabs>
<TabItem value="rs" label="Rust">

```rust file=<rootDir>/docs/examples/rust/stardust/address_unlock_condition.rs#L109-L130
```rust file=<rootDir>/docs/examples/rust/stardust/address-unlock-condition.rs#L105-L128
```

</TabItem>
Expand All @@ -56,7 +56,7 @@ Applying the filter to get `NftOutput`s owned by the `Alias`.
<Tabs>
<TabItem value="rs" label="Rust">

```rust file=<rootDir>/docs/examples/rust/stardust/address_unlock_condition.rs#L132-L241
```rust file=<rootDir>/docs/examples/rust/stardust/address-unlock-condition.rs#L130-L239
```

</TabItem>
Expand Down
10 changes: 4 additions & 6 deletions docs/content/developer/stardust/claiming/alias.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ A Governor address can claim the `AliasOutput` assets at any time:
<Tabs>
<TabItem value="rs" label="Rust">

```rust file=<rootDir>/docs/examples/rust/stardust/alias-output-claim.rs#L74-L99
```rust file=<rootDir>/docs/examples/rust/stardust/alias-output-claim.rs#L56-L81
```

</TabItem>
Expand All @@ -32,7 +32,7 @@ In the case of the native tokens, the keys are strings representing the [`OTW`](
<Tabs>
<TabItem value="rs" label="Rust">

```rust file=<rootDir>/docs/examples/rust/stardust/alias-output-claim.rs#L101-L128
```rust file=<rootDir>/docs/examples/rust/stardust/alias-output-claim.rs#L83-L110
```

</TabItem>
Expand All @@ -48,7 +48,7 @@ In fact, the main purpose of claiming is extracting the `Alias` object from the
<Tabs>
<TabItem value="rs" label="Rust">

```rust file=<rootDir>/docs/examples/rust/stardust/alias-output-claim.rs#L130-L198
```rust file=<rootDir>/docs/examples/rust/stardust/alias-output-claim.rs#L112-L180
```

</TabItem>
Expand Down Expand Up @@ -80,9 +80,7 @@ Also, the `nft.move` module was extended with the following function:
```

</TabItem>
<TabItem value="ts" label="TypeScript">

</TabItem>
</Tabs>

Once the package is prepared, we can extract and use a Stardust `Alias` in a single transaction to create a `CollectionControllerCap`.
Expand All @@ -91,7 +89,7 @@ This capability is then used in later transactions for managing new collections.
<Tabs>
<TabItem value="rs" label="Rust">

```rust file=<rootDir>/docs/examples/rust/stardust/alias-migration.rs#L122-L247
```rust file=<rootDir>/docs/examples/rust/stardust/alias-migration.rs#L119-L244
```

</TabItem>
Expand Down
6 changes: 3 additions & 3 deletions docs/content/developer/stardust/claiming/basic.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Once a Basic Output can be unlocked the claim of its assets can start
<Tabs>
<TabItem value="rs" label="Rust">

```rust file=<rootDir>/docs/examples/rust/stardust/basic-output-claim.rs#L74-L99
```rust file=<rootDir>/docs/examples/rust/stardust/basic-output-claim.rs#L56-L81
```

</TabItem>
Expand All @@ -43,7 +43,7 @@ TODO
<Tabs>
<TabItem value="rs" label="Rust">

```rust file=<rootDir>/docs/examples/rust/stardust/basic-output-claim.rs#L101-L128
```rust file=<rootDir>/docs/examples/rust/stardust/basic-output-claim.rs#L83-L110
```

</TabItem>
Expand All @@ -59,7 +59,7 @@ TODO
<Tabs>
<TabItem value="rs" label="Rust">

```rust file=<rootDir>/docs/examples/rust/stardust/basic-output-claim.rs#L131-L195
```rust file=<rootDir>/docs/examples/rust/stardust/basic-output-claim.rs#L113-L177
```

</TabItem>
Expand Down
10 changes: 5 additions & 5 deletions docs/content/developer/stardust/claiming/foundry.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ As seen in the [Move Models](../move-models) page, the Foundry Output does not h
<Tabs>
<TabItem value="rs" label="Rust">

```rust file=<rootDir>/docs/examples/rust/stardust/foundry-output-claim.rs#L147-L159
```rust file=<rootDir>/docs/examples/rust/stardust/foundry-output-claim.rs#L60-L74
```

</TabItem>
Expand All @@ -26,7 +26,7 @@ As seen in the [Move Models](../move-models) page, the Foundry Output does not h
<Tabs>
<TabItem value="rs" label="Rust">

```rust file=<rootDir>/docs/examples/rust/stardust/foundry-output-claim.rs#L164-L174
```rust file=<rootDir>/docs/examples/rust/stardust/foundry-output-claim.rs#L76-L89
```

</TabItem>
Expand All @@ -40,7 +40,7 @@ As seen in the [Move Models](../move-models) page, the Foundry Output does not h
<Tabs>
<TabItem value="rs" label="Rust">

```rust file=<rootDir>/docs/examples/rust/stardust/foundry-output-claim.rs#L178-L216
```rust file=<rootDir>/docs/examples/rust/stardust/foundry-output-claim.rs#L91-L131
```

</TabItem>
Expand All @@ -54,7 +54,7 @@ As seen in the [Move Models](../move-models) page, the Foundry Output does not h
<Tabs>
<TabItem value="rs" label="Rust">

```rust file=<rootDir>/docs/examples/rust/stardust/foundry-output-claim.rs#L220-L227
```rust file=<rootDir>/docs/examples/rust/stardust/foundry-output-claim.rs#L133-L142
```

</TabItem>
Expand All @@ -69,7 +69,7 @@ As seen in the [Move Models](../move-models) page, the Foundry Output does not h
<Tabs>
<TabItem value="rs" label="Rust">

```rust file=<rootDir>/docs/examples/rust/stardust/foundry-output-claim.rs#L231-L300
```rust file=<rootDir>/docs/examples/rust/stardust/foundry-output-claim.rs#L144-L215
```

</TabItem>
Expand Down
26 changes: 5 additions & 21 deletions docs/content/developer/stardust/claiming/nft.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Once an Nft Output can be unlocked the claim of its assets can start
<Tabs>
<TabItem value="rs" label="Rust">

```rust file=<rootDir>/docs/examples/rust/stardust/nft-output-claim.rs#L54-L78
```rust file=<rootDir>/docs/examples/rust/stardust/nft-output-claim.rs#L56-L80
```

</TabItem>
Expand All @@ -29,7 +29,7 @@ Once an Nft Output can be unlocked the claim of its assets can start
<Tabs>
<TabItem value="rs" label="Rust">

```rust file=<rootDir>/docs/examples/rust/stardust/nft-output-claim.rs#L80-L105
```rust file=<rootDir>/docs/examples/rust/stardust/nft-output-claim.rs#L82-L107
```

</TabItem>
Expand All @@ -45,7 +45,7 @@ In fact, the main purpose of claiming is extracting the `Nft` object from the `N
<Tabs>
<TabItem value="rs" label="Rust">

```rust file=<rootDir>/docs/examples/rust/stardust/nft-output-claim.rs#L107-L173
```rust file=<rootDir>/docs/examples/rust/stardust/nft-output-claim.rs#L109-L175
```

</TabItem>
Expand All @@ -67,33 +67,17 @@ The following is an example of a simple module for representing a custom NFT, mi
```

</TabItem>
<TabItem value="ts" label="TypeScript">

</TabItem>
</Tabs>


1. Publish a custom Nft package, and retrieve its package ID.

<Tabs>
<TabItem value="rs" label="Rust">

```rust file=<rootDir>/docs/examples/rust/stardust/nft-migration.rs#L210-L227
```

</TabItem>
<TabItem value="ts" label="TypeScript">

</TabItem>
</Tabs>

2. Create a PTB that extracts the Stardust `Nft` from an `NftOutput` and then calls the `custom_nft::nft::convert` method for converting it into a `custom_nft::nft::Nft` of the collection just published.
Create a PTB that extracts the Stardust `Nft` from an `NftOutput` and then converts it into a custom NFT of the collection just published.
This conversion method extracts the Stardust `Nft` metadata and uses it for minting a new NFT.

<Tabs>
<TabItem value="rs" label="Rust">

```rust file=<rootDir>/docs/examples/rust/stardust/nft-migration.rs#L84-L141
```rust file=<rootDir>/docs/examples/rust/stardust/nft-migration.rs#L77-L137
```

</TabItem>
Expand Down
6 changes: 3 additions & 3 deletions docs/content/developer/stardust/claiming/self-sponsor.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ This is useful for Shimmer assets, because none of the Move objects obtained fro
<Tabs>
<TabItem value="rs" label="Rust">

```rust file=<rootDir>/docs/examples/rust/stardust/shimmer-self-sponsor.rs#L61-L67
```rust file=<rootDir>/docs/examples/rust/stardust/shimmer-self-sponsor.rs#L44-L50
```

</TabItem>
Expand All @@ -31,7 +31,7 @@ TODO
<Tabs>
<TabItem value="rs" label="Rust">

```rust file=<rootDir>/docs/examples/rust/stardust/shimmer-self-sponsor.rs#L103-L152
```rust file=<rootDir>/docs/examples/rust/stardust/shimmer-self-sponsor.rs#L85-L135
```

</TabItem>
Expand All @@ -47,7 +47,7 @@ TODO
<Tabs>
<TabItem value="rs" label="Rust">

```rust file=<rootDir>/docs/examples/rust/stardust/shimmer-self-sponsor.rs#L168-L194
```rust file=<rootDir>/docs/examples/rust/stardust/shimmer-self-sponsor.rs#L151-L177
```

</TabItem>
Expand Down
17 changes: 10 additions & 7 deletions docs/examples/rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,25 @@ edition = "2021"
license = "Apache-2.0"
publish = false

[dev-dependencies]
[dependencies]
anyhow.workspace = true

iota-keys.workspace = true
iota-move-build.workspace = true
iota-sdk.workspace = true
shared-crypto.workspace = true

[dev-dependencies]
bcs.workspace = true
bip32.workspace = true
serde_json.workspace = true
tokio.workspace = true

iota-keys.workspace = true
iota-move-build.workspace = true
iota-sdk.workspace = true
move-core-types.workspace = true
shared-crypto.workspace = true

[[example]]
name = "address_unlock_condition"
path = "stardust/address_unlock_condition.rs"
name = "address-unlock-condition"
path = "stardust/address-unlock-condition.rs"

[[example]]
name = "nft-output-claim"
Expand Down
4 changes: 4 additions & 0 deletions docs/examples/rust/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// Copyright (c) 2024 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

pub mod utils;
Loading

0 comments on commit 3a45555

Please sign in to comment.