Skip to content

Commit

Permalink
let this be all ... or I'll go crazy
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex6323 committed Jun 21, 2023
1 parent 34ae198 commit 6eca6dd
Show file tree
Hide file tree
Showing 13 changed files with 44 additions and 84 deletions.
9 changes: 2 additions & 7 deletions sdk/examples/client/node_api_core/06_get_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,7 @@
//! cargo run --release --example node_api_core_get_block [BLOCK ID] [NODE URL]
//! ```

use std::str::FromStr;

use iota_sdk::{
client::{Client, Result},
types::block::BlockId,
};
use iota_sdk::client::{Client, Result};

#[tokio::main]
async fn main() -> Result<()> {
Expand All @@ -29,7 +24,7 @@ async fn main() -> Result<()> {
let client = Client::builder().with_node(&node_url)?.finish().await?;

// Take the block ID from command line argument or...
let block_id = if let Some(Ok(block_id)) = std::env::args().nth(1).map(|s| BlockId::from_str(&s)) {
let block_id = if let Some(Ok(block_id)) = std::env::args().nth(1).map(|s| s.parse()) {
block_id
} else {
// ... fetch one from the node.
Expand Down
9 changes: 2 additions & 7 deletions sdk/examples/client/node_api_core/07_get_block_raw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,7 @@
//! cargo run --release --example node_api_core_get_block_raw [BLOCK ID] [NODE URL]
//! ```

use std::str::FromStr;

use iota_sdk::{
client::{Client, Result},
types::block::BlockId,
};
use iota_sdk::client::{Client, Result};

#[tokio::main]
async fn main() -> Result<()> {
Expand All @@ -29,7 +24,7 @@ async fn main() -> Result<()> {
let client = Client::builder().with_node(&node_url)?.finish().await?;

// Take the block ID from command line argument or...
let block_id = if let Some(Ok(block_id)) = std::env::args().nth(1).map(|s| BlockId::from_str(&s)) {
let block_id = if let Some(Ok(block_id)) = std::env::args().nth(1).map(|s| s.parse()) {
block_id
} else {
// ... fetch one from the node.
Expand Down
9 changes: 2 additions & 7 deletions sdk/examples/client/node_api_core/08_get_block_metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,7 @@
//! cargo run --release --example node_api_core_get_block_metadata [BLOCK ID] [NODE URL]
//! ```

use std::str::FromStr;

use iota_sdk::{
client::{Client, Result},
types::block::BlockId,
};
use iota_sdk::client::{Client, Result};

#[tokio::main]
async fn main() -> Result<()> {
Expand All @@ -29,7 +24,7 @@ async fn main() -> Result<()> {
let client = Client::builder().with_node(&node_url)?.finish().await?;

// Take the block ID from command line argument or...
let block_id = if let Some(Ok(block_id)) = std::env::args().nth(1).map(|s| BlockId::from_str(&s)) {
let block_id = if let Some(Ok(block_id)) = std::env::args().nth(1).map(|s| s.parse()) {
block_id
} else {
// ... fetch one from the node.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
//!
//! `cargo run --release --all-features --example advanced_transaction`

use std::time::{Duration, SystemTime, UNIX_EPOCH};

use iota_sdk::{
types::block::{
address::Bech32Address,
Expand Down Expand Up @@ -40,8 +38,8 @@ async fn main() -> Result<()> {
.await?;

// Create an ouput with amount 1_000_000 and a timelock of 1 hour
let in_an_hour = (SystemTime::now() + Duration::from_secs(3600))
.duration_since(UNIX_EPOCH)
let in_an_hour = (std::time::SystemTime::now() + std::time::Duration::from_secs(3600))
.duration_since(std::time::UNIX_EPOCH)
.expect("clock went backwards")
.as_secs()
.try_into()
Expand Down
8 changes: 3 additions & 5 deletions sdk/examples/wallet/11_decrease_native_token_supply.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@
//! cargo run --release --all-features --example decrease_native_token_supply
//! ```

use std::{env::var, str::FromStr};

use iota_sdk::{types::block::output::TokenId, wallet::Result, Wallet, U256};
use iota_sdk::{wallet::Result, Wallet, U256};

// The native token id. Replace it with a TokenId that is available in the account, the foundry output which minted it,
// also needs to be available. You can check this by running the `get_balance` example. You can mint a new native token
Expand All @@ -38,7 +36,7 @@ async fn main() -> Result<()> {
.await?;
let account = wallet.get_account("Alice").await?;

let token_id = TokenId::from_str(TOKEN_ID)?;
let token_id = TOKEN_ID.parse()?;

// May want to ensure the account is synced before sending a transaction.
account.sync(None).await?;
Expand Down Expand Up @@ -76,7 +74,7 @@ async fn main() -> Result<()> {

println!(
"Transaction included: {}/block/{}",
var("EXPLORER_URL").unwrap(),
std::env::var("EXPLORER_URL").unwrap(),
block_id
);
println!("Melted {} native tokens ({})", melt_amount, token_id);
Expand Down
8 changes: 3 additions & 5 deletions sdk/examples/wallet/12_increase_native_token_supply.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@
//! cargo run --release --all-features --example increase_native_token_supply
//! ```

use std::{env::var, str::FromStr};

use iota_sdk::{types::block::output::TokenId, wallet::Result, Wallet, U256};
use iota_sdk::{wallet::Result, Wallet, U256};

// The native token id. Replace it with a TokenId that is available in the account, the foundry output which minted it,
// also needs to be available. You can check this by running the `get_balance` example. You can mint a new native token
Expand All @@ -38,7 +36,7 @@ async fn main() -> Result<()> {
.await?;
let account = wallet.get_account("Alice").await?;

let token_id = TokenId::from_str(TOKEN_ID)?;
let token_id = TOKEN_ID.parse()?;

// May want to ensure the account is synced before sending a transaction.
let balance = account.sync(None).await?;
Expand Down Expand Up @@ -73,7 +71,7 @@ async fn main() -> Result<()> {
.await?;
println!(
"Transaction included: {}/block/{}",
var("EXPLORER_URL").unwrap(),
std::env::var("EXPLORER_URL").unwrap(),
block_id
);
println!("Minted {} native tokens ({})", mint_amount, transaction.token_id);
Expand Down
12 changes: 3 additions & 9 deletions sdk/examples/wallet/13_burn_native_token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,7 @@
//! cargo run --release --all-features --example burn_native_token
//! ```

use std::{env::var, str::FromStr};

use iota_sdk::{
types::block::output::{NativeToken, TokenId},
wallet::Result,
Wallet, U256,
};
use iota_sdk::{types::block::output::NativeToken, wallet::Result, Wallet, U256};

// The native token id. Replace it with a TokenId that is available in the account, the foundry output which minted it,
// also needs to be available. You can check this by running the `get_balance` example. You can mint a new native token
Expand Down Expand Up @@ -47,7 +41,7 @@ async fn main() -> Result<()> {
let alias = "Alice";
let account = wallet.get_account(alias.to_string()).await?;

let token_id = TokenId::from_str(TOKEN_ID)?;
let token_id = TOKEN_ID.parse()?;

// May want to ensure the account is synced before sending a transaction.
let balance = account.sync(None).await?;
Expand All @@ -74,7 +68,7 @@ async fn main() -> Result<()> {
.await?;
println!(
"Transaction included: {}/block/{}",
var("EXPLORER_URL").unwrap(),
std::env::var("EXPLORER_URL").unwrap(),
block_id
);
println!(
Expand Down
10 changes: 4 additions & 6 deletions sdk/examples/wallet/ledger_nano.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
//! cargo run --release --all-features --example ledger_nano
//! ```

use std::{env::var, time::Instant};

use iota_sdk::{
client::{
constants::SHIMMER_COIN_TYPE,
Expand Down Expand Up @@ -59,15 +57,15 @@ async fn main() -> Result<()> {
};

println!("Generating {NUM_ADDRESSES_TO_GENERATE} addresses...");
let now = Instant::now();
let now = tokio::time::Instant::now();
let addresses = account
.generate_ed25519_addresses(NUM_ADDRESSES_TO_GENERATE, None)
.await?;
println!("took: {:.2?}", now.elapsed());

println!("ADDRESSES:\n{addresses:#?}");

let now = Instant::now();
let now = tokio::time::Instant::now();
let balance = account.sync(None).await?;
println!("Account synced in: {:.2?}", now.elapsed());

Expand All @@ -83,11 +81,11 @@ async fn main() -> Result<()> {
.await?;
println!(
"Transaction included: {}/block/{}",
var("EXPLORER_URL").unwrap(),
std::env::var("EXPLORER_URL").unwrap(),
block_id
);

let now = Instant::now();
let now = tokio::time::Instant::now();
let balance = account.sync(None).await?;
println!("Account synced in: {:.2?}", now.elapsed());

Expand Down
8 changes: 3 additions & 5 deletions sdk/examples/wallet/nft_collection/01_mint_collection_nft.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
//! cargo run --release --all-features --example mint_collection_nft
//! ```

use std::{env::var, str::FromStr};

use iota_sdk::{
types::block::{
address::{Bech32Address, NftAddress},
Expand All @@ -36,7 +34,7 @@ async fn main() -> Result<()> {
let issuer_nft_id = if ISSUER_NFT_ID == "0x13c490ac052e575cffd40e170c2d46c6029b8b68cdf0e899b34cde93d2a7b28a" {
panic!("You need to change the ISSUER_NFT_ID constant before you can run this example successfully!");
} else {
NftId::from_str(ISSUER_NFT_ID)?
ISSUER_NFT_ID.parse()?
};

// This example uses secrets in environment variables for simplicity which should not be done in production.
Expand Down Expand Up @@ -105,7 +103,7 @@ fn get_immutable_metadata(index: usize, issuer_nft_id: NftId) -> String {
async fn wait_for_inclusion(transaction_id: &TransactionId, account: &Account) -> Result<()> {
println!(
"Transaction sent: {}/transaction/{}",
var("EXPLORER_URL").unwrap(),
std::env::var("EXPLORER_URL").unwrap(),
transaction_id
);
// Wait for transaction to get included
Expand All @@ -114,7 +112,7 @@ async fn wait_for_inclusion(transaction_id: &TransactionId, account: &Account) -
.await?;
println!(
"Transaction included: {}/block/{}",
var("EXPLORER_URL").unwrap(),
std::env::var("EXPLORER_URL").unwrap(),
block_id
);
Ok(())
Expand Down
19 changes: 8 additions & 11 deletions sdk/examples/wallet/participation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,8 @@
//! cargo run --release --all-features --example wallet_participation
//! ```

use std::{env::var, str::FromStr};

use iota_sdk::{
client::node_manager::node::Node,
types::api::plugins::participation::types::ParticipationEventId,
wallet::{account::types::participation::ParticipationEventRegistrationOptions, Result},
Url, Wallet,
};
Expand Down Expand Up @@ -55,7 +52,7 @@ async fn main() -> Result<()> {
.set_stronghold_password(std::env::var("STRONGHOLD_PASSWORD").unwrap())
.await?;

let event_id = ParticipationEventId::from_str(PARTICIPATION_EVENT_ID_1)?;
let event_id = PARTICIPATION_EVENT_ID_1.parse()?;
let node = Node {
url: Url::parse(PARTICPATION_NODE_URL).map_err(iota_sdk::client::Error::Url)?,
auth: None,
Expand All @@ -66,7 +63,7 @@ async fn main() -> Result<()> {
node,
// We ignore this particular event
events_to_ignore: (!IGNORED_PARTICIPATION_EVENT_ID.is_empty())
.then_some(vec![ParticipationEventId::from_str(IGNORED_PARTICIPATION_EVENT_ID)?]),
.then_some(vec![IGNORED_PARTICIPATION_EVENT_ID.parse()?]),
// We register all others. If you want to register only particular events provide their ids with a
// `Some(vec![...])`
events_to_register: None,
Expand Down Expand Up @@ -103,7 +100,7 @@ async fn main() -> Result<()> {
////////////////////////////////////////////////
if !DEREGISTERED_PARTICIPATION_EVENT.is_empty() {
account
.deregister_participation_event(&ParticipationEventId::from_str(DEREGISTERED_PARTICIPATION_EVENT)?)
.deregister_participation_event(&DEREGISTERED_PARTICIPATION_EVENT.parse()?)
.await?;

println!("Registered events (updated):");
Expand Down Expand Up @@ -140,7 +137,7 @@ async fn main() -> Result<()> {
.await?;
println!(
"Transaction included: {}/block/{}",
var("EXPLORER_URL").unwrap(),
std::env::var("EXPLORER_URL").unwrap(),
block_id
);

Expand All @@ -165,7 +162,7 @@ async fn main() -> Result<()> {
.await?;
println!(
"Transaction included: {}/block/{}",
var("EXPLORER_URL").unwrap(),
std::env::var("EXPLORER_URL").unwrap(),
block_id
);

Expand All @@ -190,7 +187,7 @@ async fn main() -> Result<()> {
.await?;
println!(
"Transaction included: {}/block/{}",
var("EXPLORER_URL").unwrap(),
std::env::var("EXPLORER_URL").unwrap(),
block_id
);

Expand All @@ -217,7 +214,7 @@ async fn main() -> Result<()> {
.await?;
println!(
"Transaction included: {}/block/{}",
var("EXPLORER_URL").unwrap(),
std::env::var("EXPLORER_URL").unwrap(),
block_id
);

Expand All @@ -241,7 +238,7 @@ async fn main() -> Result<()> {
.await?;
println!(
"Transaction included: {}/block/{}",
var("EXPLORER_URL").unwrap(),
std::env::var("EXPLORER_URL").unwrap(),
block_id
);

Expand Down
8 changes: 3 additions & 5 deletions sdk/examples/wallet/split_funds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
//! cargo run --release --all-features --example split_funds
//! ```

use std::{env::var, time::Instant};

use iota_sdk::{
client::{
constants::SHIMMER_COIN_TYPE,
Expand Down Expand Up @@ -83,7 +81,7 @@ async fn main() -> Result<()> {
let transaction = account.send(outputs_per_transaction, None).await?;
println!(
"Transaction sent: {}/transaction/{}",
var("EXPLORER_URL").unwrap(),
std::env::var("EXPLORER_URL").unwrap(),
transaction.transaction_id
);

Expand All @@ -94,7 +92,7 @@ async fn main() -> Result<()> {

println!(
"Transaction included: {}/block/{}",
var("EXPLORER_URL").unwrap(),
std::env::var("EXPLORER_URL").unwrap(),
block_id
);
}
Expand Down Expand Up @@ -123,7 +121,7 @@ async fn create_account(wallet: &Wallet, alias: &str) -> Result<Account> {

async fn sync_print_balance(account: &Account) -> Result<()> {
let alias = account.alias().await;
let now = Instant::now();
let now = tokio::time::Instant::now();
let balance = account.sync(None).await?;
println!("{alias}'s account synced in: {:.2?}", now.elapsed());
println!("{alias}'s balance:\n{:#?}", balance.base_coin());
Expand Down
Loading

0 comments on commit 6eca6dd

Please sign in to comment.