forked from iotaledger/wallet.rs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
16_destroy_alias.rs
51 lines (38 loc) · 1.68 KB
/
16_destroy_alias.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
// Copyright 2022 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0
//! cargo run --example destroy_alias --release
// In this example we will destroy an existing alias output. This is only possible if possible foundry outputs have
// circulating supply of 0. Rename `.env.example` to `.env` first
use std::{env, str::FromStr};
use dotenv::dotenv;
use iota_client::block::output::AliasId;
use iota_wallet::{account_manager::AccountManager, Result};
#[tokio::main]
async fn main() -> Result<()> {
// This example uses dotenv, which is not safe for use in production
dotenv().ok();
// Create the account manager
let manager = AccountManager::builder().finish().await?;
// Get the account we generated with `01_create_wallet`
let account = manager.get_account("Alice").await?;
let balance = account.balance().await?;
println!("Balance before destroying:\n{balance:?}",);
// Set the stronghold password
manager
.set_stronghold_password(&env::var("STRONGHOLD_PASSWORD").unwrap())
.await?;
// Replace with an AliasId that is available in the account
let alias_id = AliasId::from_str("0x57f1bafae0ef43190597a0dfe72ef1477b769560203c1854c6fb427c486e6530")?;
let transaction = account.destroy_alias(alias_id, None).await?;
let _ = match transaction.block_id {
Some(block_id) => account.retry_until_included(&block_id, None, None).await?,
None => {
return Err(iota_wallet::Error::BurningOrMeltingFailed(
"burn nft failed to submitted".to_string(),
));
}
};
let balance = account.sync(None).await?;
println!("Balance after destroying:\n{balance:?}",);
Ok(())
}