summaryrefslogtreecommitdiff
path: root/impls/monero.rs/example/src
diff options
context:
space:
mode:
authorsneurlax <sneurlax@gmail.com>2024-10-20 20:44:03 -0500
committersneurlax <sneurlax@gmail.com>2024-10-20 20:44:03 -0500
commit06beb39b2e62c585b29fa5b435ee645dbfa1bca5 (patch)
treec666392935cc6d66297ef9fd1b451ccafd9f4d26 /impls/monero.rs/example/src
parent1c1e0f2a4fcc33324a7d06c3e60d3bf796884e9c (diff)
update example
Diffstat (limited to 'impls/monero.rs/example/src')
-rw-r--r--impls/monero.rs/example/src/main.rs38
1 files changed, 22 insertions, 16 deletions
diff --git a/impls/monero.rs/example/src/main.rs b/impls/monero.rs/example/src/main.rs
index 099c6d4..603f790 100644
--- a/impls/monero.rs/example/src/main.rs
+++ b/impls/monero.rs/example/src/main.rs
@@ -1,26 +1,32 @@
-use monero_rust::{network, WalletError, WalletManager};
+use monero_c_rust::{NetworkType, WalletError, WalletManager};
+use tempfile::TempDir;
fn main() -> Result<(), WalletError> {
- let wallet_manager = WalletManager::new(None)?;
+ let manager = WalletManager::new()?;
- let wallet = wallet_manager.create_wallet(
- "wallet_name",
- "password",
- "English",
- network::MAINNET,
- )?;
+ let temp_dir = TempDir::new().expect("Failed to create temporary directory");
+ let wallet_path = temp_dir.path().join("test_wallet");
+ let wallet_str = wallet_path.to_str().unwrap();
+
+ let wallet = manager.restore_polyseed(
+ wallet_str.to_string(),
+ "password".to_string(),
+ "capital chief route liar question fix clutch water outside pave hamster occur always learn license knife".to_string(),
+ NetworkType::Mainnet,
+ 0, // Restore from the beginning of the blockchain.
+ 1, // Default KDF rounds.
+ "".to_string(), // No seed offset.
+ true, // Create a new wallet.
+ );
println!("Wallet created successfully.");
- match wallet.get_seed("") {
- Ok(seed) => println!("Seed: {}", seed),
- Err(e) => eprintln!("Failed to get seed: {:?}", e),
- }
+ // Print the primary address.
+ println!("Primary address: {}", wallet?.get_address(0, 0)?);
- match wallet.get_address(0, 0) {
- Ok(address) => println!("Primary address: {}", address),
- Err(e) => eprintln!("Failed to get address: {:?}", e),
- }
+ // Clean up the wallet.
+ std::fs::remove_file(wallet_str).expect("Failed to delete test wallet");
+ std::fs::remove_file(format!("{}.keys", wallet_str)).expect("Failed to delete test wallet keys");
Ok(())
}