-
Notifications
You must be signed in to change notification settings - Fork 39
/
destroy.rs
71 lines (56 loc) · 2.4 KB
/
destroy.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// Copyright 2022 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0
//! In this example we will try to destroy the first alias there is in the account. This is only possible if possible
//! foundry outputs have circulating supply of 0.
//!
//! Make sure that `STRONGHOLD_SNAPSHOT_PATH` and `WALLET_DB_PATH` already exist by
//! running the `./how_tos/accounts_and_addresses/create_account.rs` example!
//!
//! Rename `.env.example` to `.env` first, then run the command:
//! ```sh
//! cargo run --release --all-features --example destroy_alias
//! ```
use iota_sdk::{wallet::Result, Wallet};
#[tokio::main]
async fn main() -> Result<()> {
// This example uses secrets in environment variables for simplicity which should not be done in production.
dotenvy::dotenv().ok();
for var in ["WALLET_DB_PATH", "STRONGHOLD_PASSWORD", "EXPLORER_URL"] {
std::env::var(var).expect(&format!(".env variable '{var}' is undefined, see .env.example"));
}
let wallet = Wallet::builder()
.with_storage_path(&std::env::var("WALLET_DB_PATH").unwrap())
.finish()
.await?;
let alias = "Alice";
let account = wallet.get_account(alias).await?;
// May want to ensure the account is synced before sending a transaction.
let balance = account.sync(None).await?;
// Get the first alias
if let Some(alias_id) = balance.aliases().first() {
let aliases_before = balance.aliases();
println!("Aliases BEFORE destroying:\n{aliases_before:#?}",);
// Set the stronghold password
wallet
.set_stronghold_password(std::env::var("STRONGHOLD_PASSWORD").unwrap())
.await?;
println!("Sending alias burn transaction...");
let transaction = account.burn(*alias_id, None).await?;
println!("Transaction sent: {}", transaction.transaction_id);
let block_id = account
.retry_transaction_until_included(&transaction.transaction_id, None, None)
.await?;
println!(
"Block included: {}/block/{}",
std::env::var("EXPLORER_URL").unwrap(),
block_id
);
println!("Burned Alias '{}'", alias_id);
let balance = account.sync(None).await?;
let aliases_after = balance.aliases();
println!("Aliases AFTER destroying:\n{aliases_after:#?}",);
} else {
println!("No Alias available in account '{alias}'");
}
Ok(())
}