From 1d6dc089be4208a6f1693aa3d602665cecdfff54 Mon Sep 17 00:00:00 2001 From: sneurlax Date: Sun, 20 Oct 2024 21:03:09 -0500 Subject: WIP scanning example once this is fixed it should show a live balance --- impls/monero.rs/example/src/main.rs | 41 +++++++++++++++++++++++++++--- impls/monero.rs/tests/integration_tests.rs | 2 +- 2 files changed, 39 insertions(+), 4 deletions(-) diff --git a/impls/monero.rs/example/src/main.rs b/impls/monero.rs/example/src/main.rs index 603f790..245013a 100644 --- a/impls/monero.rs/example/src/main.rs +++ b/impls/monero.rs/example/src/main.rs @@ -1,4 +1,4 @@ -use monero_c_rust::{NetworkType, WalletError, WalletManager}; +use monero_c_rust::{NetworkType, WalletError, WalletManager, WalletConfig}; use tempfile::TempDir; fn main() -> Result<(), WalletError> { @@ -17,12 +17,47 @@ fn main() -> Result<(), WalletError> { 1, // Default KDF rounds. "".to_string(), // No seed offset. true, // Create a new wallet. - ); + )?; println!("Wallet created successfully."); // Print the primary address. - println!("Primary address: {}", wallet?.get_address(0, 0)?); + println!("Primary address: {}", wallet.get_address(0, 0)?); + + // Initialize the wallet. + let config = WalletConfig { + daemon_address: "https://monero.stackwallet.com:18081".to_string(), + upper_transaction_size_limit: 10000, // TODO: use sane value. + daemon_username: "".to_string(), + daemon_password: "".to_string(), + use_ssl: true, + light_wallet: false, + proxy_address: "".to_string(), + }; + + // Perform the initialization. + wallet.init(config)?; + wallet.throw_if_error()?; + + // Refresh the wallet. + wallet.refresh()?; + wallet.throw_if_error()?; + + // Wait for the refresh to complete. + loop { + let height = manager.get_height().expect("Failed to get blockchain height"); + println!("Current blockchain height: {}", height); + if height > 3263501 { // After this height we can get_balance. + break (); + } + // Wait one second. + std::thread::sleep(std::time::Duration::from_secs(1)); + } + + // Get the balance. + let balance_result = wallet.get_balance(0); // Account index 0. + let balance = balance_result.unwrap(); + println!("Balance: {:?}", balance); // Clean up the wallet. std::fs::remove_file(wallet_str).expect("Failed to delete test wallet"); diff --git a/impls/monero.rs/tests/integration_tests.rs b/impls/monero.rs/tests/integration_tests.rs index 6dea846..6ce7a30 100644 --- a/impls/monero.rs/tests/integration_tests.rs +++ b/impls/monero.rs/tests/integration_tests.rs @@ -504,7 +504,7 @@ fn test_get_balance_integration() { // Fetch the balance. println!("Fetching wallet balance..."); let start = Instant::now(); - let balance_result = wallet.get_balance(0); // Account index 0 + let balance_result = wallet.get_balance(0); // Account index 0. println!("Fetching balance took {:?}", start.elapsed()); assert!(balance_result.is_ok(), "Failed to fetch balance: {:?}", balance_result.err()); -- cgit v1.2.3