Skip to content

Commit

Permalink
Adapt to IOTA sandbox (#1290)
Browse files Browse the repository at this point in the history
  • Loading branch information
eike-hass authored Feb 2, 2024
1 parent a929510 commit c0f15f6
Show file tree
Hide file tree
Showing 12 changed files with 77 additions and 87 deletions.
36 changes: 36 additions & 0 deletions .github/actions/iota-sandbox/setup/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: 'iota-sandbox-setup'
description: 'Setup IOTA Sandbox'
runs:
using: "composite"
steps:
- name: Setup iota sandbox
shell: bash
run: |
# Use next lines for using the GitHub release
mkdir iota-sandbox
cd iota-sandbox
mkdir sandbox
cd sandbox
# Use the output of https://api.github.com/repos/iotaledger/iota-sandbox/releases/latest
DOWNLOAD_URL=$(curl "https://api.github.com/repos/iotaledger/iota-sandbox/releases" | jq -r '.[0].assets[] | select(.name | contains("iota_sandbox")) | .browser_download_url')
echo "Downloading sandbox from $DOWNLOAD_URL"
curl -L -o iota_sandbox.tar.gz $DOWNLOAD_URL
tar -xf iota_sandbox.tar.gz
# Use the next lines to use the main branch
# git clone https://github.com/iotaledger/iota-sandbox
# cd iota-sandbox/sandbox
# Start Tangle
sudo ./bootstrap.sh
docker compose up -d
- name: Wait for tangle to start
shell: bash
run: wget -qO- https://raw.githubusercontent.com/eficode/wait-for/$WAIT_FOR_VERSION/wait-for | sh -s -- -t 60 http://localhost/health -- echo "Tangle is up"
env:
WAIT_FOR_VERSION: 4df3f9262d84cab0039c07bf861045fbb3c20ab7 # v2.2.3
- name: Wait for faucet to start
shell: bash
run: wget -qO- https://raw.githubusercontent.com/eficode/wait-for/$WAIT_FOR_VERSION/wait-for | sh -s -- -t 60 http://localhost/faucet/api/info -- echo "Faucet is up"
env:
WAIT_FOR_VERSION: 4df3f9262d84cab0039c07bf861045fbb3c20ab7 # v2.2.3
12 changes: 12 additions & 0 deletions .github/actions/iota-sandbox/tear-down/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: 'iota-sandbox-tear-down'
description: 'tear-down a iota sandbox'
runs:
using: "composite"
steps:
- name: Tear down iota sandbox
shell: bash
run: |
cd iota-sandbox/sandbox
docker-compose down
cd ../..
sudo rm -rf iota-sandbox
44 changes: 0 additions & 44 deletions .github/actions/private-tangle/setup/action.yml

This file was deleted.

16 changes: 0 additions & 16 deletions .github/actions/private-tangle/tear-down/action.yml

This file was deleted.

16 changes: 8 additions & 8 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,9 @@ jobs:
- name: Build with all features
run: cargo build --workspace --tests --examples --all-features --release

- name: Start private tangle
- name: Start iota sandbox
if: matrix.os == 'ubuntu-latest'
uses: './.github/actions/private-tangle/setup'
uses: './.github/actions/iota-sandbox/setup'

- name: Run tests
run: cargo test --workspace --all-features --release
Expand All @@ -148,9 +148,9 @@ jobs:
npm ci
npm run test:readme:rust
- name: Tear down private tangle
- name: Tear down iota sandbox
if: matrix.os == 'ubuntu-latest' && always()
uses: './.github/actions/private-tangle/tear-down'
uses: './.github/actions/iota-sandbox/tear-down'

- name: Stop sccache
uses: './.github/actions/rust/sccache/stop-sccache'
Expand Down Expand Up @@ -194,13 +194,13 @@ jobs:
name: identity-wasm-bindings-build
path: bindings/wasm

- name: Start private tangle
uses: './.github/actions/private-tangle/setup'
- name: Start iota sandbox
uses: './.github/actions/iota-sandbox/setup'

- name: Run Wasm examples
run: npm run test:examples
working-directory: bindings/wasm

- name: Tear down private tangle
- name: Tear down iota sandbox
if: always()
uses: './.github/actions/private-tangle/tear-down'
uses: './.github/actions/iota-sandbox/tear-down'
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,13 @@ identity_iota = { version = "1.0.0" }
To try out the [examples](https://github.com/iotaledger/identity.rs/blob/HEAD/examples), you can also do this:

1. Clone the repository, e.g. through `git clone https://github.com/iotaledger/identity.rs`
2. Start a private Tangle as described in the [next section](#example-creating-an-identity)
2. Start IOTA Sandbox as described in the [next section](#example-creating-an-identity)
3. Run the example to create a DID using `cargo run --release --example 0_create_did`

## Example: Creating an Identity

The following code creates and publishes a new IOTA DID Document to a locally running private network.
See the [instructions](https://github.com/iotaledger/hornet/tree/develop/private_tangle) on running your own private network.
See the [instructions](https://github.com/iotaledger/iota-sandbox) on running your own private network for development.

_Cargo.toml_

Expand Down Expand Up @@ -130,7 +130,7 @@ use iota_sdk::types::block::output::dto::AliasOutputDto;
use tokio::io::AsyncReadExt;
// The endpoint of the IOTA node to use.
static API_ENDPOINT: &str = "http://127.0.0.1:14265";
static API_ENDPOINT: &str = "http://localhost";
/// Demonstrates how to create a DID Document and publish it in a new Alias Output.
#[tokio::main]
Expand Down Expand Up @@ -168,7 +168,7 @@ async fn main() -> anyhow::Result<()> {
.await?[0];
println!("Your wallet address is: {}", address);
println!("Please request funds from http://127.0.0.1:8091/, wait for a couple of seconds and then press Enter.");
println!("Please request funds from http://localhost/faucet/, wait for a couple of seconds and then press Enter.");
tokio::io::stdin().read_u8().await?;
// Create a new DID document with a placeholder DID.
Expand Down
4 changes: 2 additions & 2 deletions bindings/wasm/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ const EXAMPLE_JWK = new Jwk({
});

// The endpoint of the IOTA node to use.
const API_ENDPOINT = "http://127.0.0.1:14265";
const API_ENDPOINT = "http://localhost";

/** Demonstrate how to create a DID Document. */
async function main() {
Expand Down Expand Up @@ -230,7 +230,7 @@ import init, { Client } from "@iota/sdk-wasm/web";
import * as identity from "@iota/identity-wasm/web";

// The endpoint of the IOTA node to use.
const API_ENDPOINT = "http://127.0.0.1:14265";
const API_ENDPOINT = "http://localhost";

const EXAMPLE_JWK = new identity.Jwk({
kty: identity.JwkType.Okp,
Expand Down
4 changes: 2 additions & 2 deletions bindings/wasm/examples/src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import {
Utils,
} from "@iota/sdk-wasm/node";

export const API_ENDPOINT = "http://localhost:14265";
export const FAUCET_ENDPOINT = "http://localhost:8091/api/enqueue";
export const API_ENDPOINT = "http://localhost";
export const FAUCET_ENDPOINT = "http://localhost/faucet/api/enqueue";

/** Creates a DID Document and publishes it in a new Alias Output.
Expand Down
4 changes: 2 additions & 2 deletions examples/0_basic/0_create_did.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ use iota_sdk::types::block::output::AliasOutput;
#[tokio::main]
async fn main() -> anyhow::Result<()> {
// The API endpoint of an IOTA node, e.g. Hornet.
let api_endpoint: &str = "http://127.0.0.1:14265";
let api_endpoint: &str = "http://localhost";

// The faucet endpoint allows requesting funds for testing purposes.
let faucet_endpoint: &str = "http://127.0.0.1:8091/api/enqueue";
let faucet_endpoint: &str = "http://localhost/faucet/api/enqueue";

// Create a new client to interact with the IOTA ledger.
let client: Client = Client::builder()
Expand Down
4 changes: 2 additions & 2 deletions examples/0_basic/8_stronghold.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ use iota_sdk::types::block::output::AliasOutput;
#[tokio::main]
async fn main() -> anyhow::Result<()> {
// The API endpoint of an IOTA node, e.g. Hornet.
let api_endpoint: &str = "http://127.0.0.1:14265";
let api_endpoint: &str = "http://localhost";

// The faucet endpoint allows requesting funds for testing purposes.
let faucet_endpoint: &str = "http://127.0.0.1:8091/api/enqueue";
let faucet_endpoint: &str = "http://localhost/faucet/api/enqueue";

// Stronghold snapshot path.
let path = random_stronghold_path();
Expand Down
4 changes: 2 additions & 2 deletions examples/utils/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ use iota_sdk::types::block::address::Hrp;
use rand::distributions::DistString;
use serde_json::Value;

pub static API_ENDPOINT: &str = "http://localhost:14265";
pub static FAUCET_ENDPOINT: &str = "http://localhost:8091/api/enqueue";
pub static API_ENDPOINT: &str = "http://localhost";
pub static FAUCET_ENDPOINT: &str = "http://localhost/faucet/api/enqueue";

pub type MemStorage = Storage<JwkMemStore, KeyIdMemstore>;

Expand Down
12 changes: 7 additions & 5 deletions identity_iota/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,13 @@ identity_iota = { version = "1.0.0" }
To try out the [examples](https://github.com/iotaledger/identity.rs/blob/HEAD/examples), you can also do this:

1. Clone the repository, e.g. through `git clone https://github.com/iotaledger/identity.rs`
2. Start a private Tangle as described in the [next section](#example-creating-an-identity)
2. Start IOTA Sandbox as described in the [next section](#example-creating-an-identity)
3. Run the example to create a DID using `cargo run --release --example 0_create_did`

## Example: Creating an Identity

The following code creates and publishes a new IOTA DID Document to a locally running private network.
See the [instructions](https://github.com/iotaledger/hornet/tree/develop/private_tangle) on running your own private network.
See the [instructions](https://github.com/iotaledger/iota-sandbox) on running your own private network for development.

_Cargo.toml_

Expand All @@ -74,9 +74,11 @@ version = "1.0.0"
edition = "2021"

[dependencies]
identity_iota = { version = "1.0.0" }
identity_iota = {version = "1.0.0", features = ["memstore"]}
iota-sdk = { version = "1.0.2", default-features = true, features = ["tls", "client", "stronghold"] }
tokio = { version = "1", features = ["full"] }
anyhow = "1.0.62"
rand = "0.8.5"
```

_main._<span></span>_rs_
Expand Down Expand Up @@ -104,7 +106,7 @@ use iota_sdk::types::block::output::dto::AliasOutputDto;
use tokio::io::AsyncReadExt;
// The endpoint of the IOTA node to use.
static API_ENDPOINT: &str = "http://127.0.0.1:14265";
static API_ENDPOINT: &str = "http://localhost";
/// Demonstrates how to create a DID Document and publish it in a new Alias Output.
#[tokio::main]
Expand Down Expand Up @@ -142,7 +144,7 @@ async fn main() -> anyhow::Result<()> {
.await?[0];
println!("Your wallet address is: {}", address);
println!("Please request funds from http://127.0.0.1:8091/, wait for a couple of seconds and then press Enter.");
println!("Please request funds from http://localhost/faucet/, wait for a couple of seconds and then press Enter.");
tokio::io::stdin().read_u8().await?;
// Create a new DID document with a placeholder DID.
Expand Down

0 comments on commit c0f15f6

Please sign in to comment.