forked from iotaledger/wallet.rs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
logger.rs
64 lines (52 loc) · 1.96 KB
/
logger.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
// Copyright 2021 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0
//! cargo run --example logger --release
use std::{env, time::Instant};
use iota_wallet::{
account_manager::AccountManager,
iota_client::constants::SHIMMER_COIN_TYPE,
secret::{mnemonic::MnemonicSecretManager, SecretManager},
ClientOptions, Result,
};
#[tokio::main]
async fn main() -> Result<()> {
// Generates a wallet.log file with logs for debugging
let logger_output_config = fern_logger::LoggerOutputConfigBuilder::new()
.name("wallet.log")
.target_exclusions(&["h2", "hyper", "rustls"])
.level_filter(log::LevelFilter::Debug);
let config = fern_logger::LoggerConfig::build()
.with_output(logger_output_config)
.finish();
fern_logger::logger_init(config).unwrap();
let client_options = ClientOptions::new()
.with_node(&env::var("NODE_URL").unwrap())?
.with_node_sync_disabled();
let secret_manager =
MnemonicSecretManager::try_from_mnemonic(&env::var("NON_SECURE_USE_OF_DEVELOPMENT_MNEMONIC").unwrap())?;
let manager = AccountManager::builder()
.with_secret_manager(SecretManager::Mnemonic(secret_manager))
.with_client_options(client_options)
.with_coin_type(SHIMMER_COIN_TYPE)
.finish()
.await?;
// Get account or create a new one
let account_alias = "logger";
let account = match manager.get_account(account_alias).await {
Ok(account) => account,
_ => {
// first we'll create an example account and store it
manager
.create_account()
.with_alias(account_alias.to_string())
.finish()
.await?
}
};
let _address = account.generate_addresses(5, None).await?;
let now = Instant::now();
let balance = account.sync(None).await?;
println!("Syncing took: {:.2?}", now.elapsed());
println!("Balance: {:?}", balance);
Ok(())
}