diff options
| author | sneurlax <sneurlax@gmail.com> | 2024-10-10 17:44:10 -0500 |
|---|---|---|
| committer | sneurlax <sneurlax@gmail.com> | 2024-10-10 17:44:10 -0500 |
| commit | a42cbbe83120bd4724a050e03fb95802a4a5ff42 (patch) | |
| tree | 34b69abe03eea0baa42bdb30aadf301c5228fa9f /impls/monero_rust/src/main.rs | |
| parent | 440f6c31c764296f5b6856dcd8ba759cfd17d1a0 (diff) | |
prove integration
Diffstat (limited to 'impls/monero_rust/src/main.rs')
| -rw-r--r-- | impls/monero_rust/src/main.rs | 85 |
1 files changed, 79 insertions, 6 deletions
diff --git a/impls/monero_rust/src/main.rs b/impls/monero_rust/src/main.rs index 0e76a13..a51e542 100644 --- a/impls/monero_rust/src/main.rs +++ b/impls/monero_rust/src/main.rs @@ -1,10 +1,83 @@ +#![allow(non_upper_case_globals)] +#![allow(non_camel_case_types)] +#![allow(non_snake_case)] + +use std::ffi::{CStr, CString}; +use std::os::raw::{c_char, c_int, c_void}; + +const NetworkType_MAINNET: c_int = 0; +// const NetworkType_TESTNET: c_int = 1; +// const NetworkType_STAGENET: c_int = 2; + +extern "C" { + // Get the wallet manager instance. + pub fn MONERO_WalletManagerFactory_getWalletManager() -> *mut c_void; + + // Create a new wallet. + pub fn MONERO_WalletManager_createWallet( + wm_ptr: *mut c_void, + path: *const c_char, + password: *const c_char, + language: *const c_char, + networkType: c_int, + ) -> *mut c_void; + + // Retrieve the seed from the wallet. + pub fn MONERO_Wallet_seed( + wallet_ptr: *mut c_void, + seed_offset: *const c_char, + ) -> *const c_char; + + // Close the wallet. + pub fn MONERO_WalletManager_closeWallet( + wm_ptr: *mut c_void, + wallet_ptr: *mut c_void, + store: bool, + ) -> bool; +} + fn main() { unsafe { - MONERO_DEBUG_test0(); - } - println!("Called MONERO_DEBUG_test0 successfully."); -} + // Initialize the Wallet Manager. + let wm_ptr = MONERO_WalletManagerFactory_getWalletManager(); + if wm_ptr.is_null() { + eprintln!("Failed to get WalletManager"); + return; + } -extern "C" { - fn MONERO_DEBUG_test0(); + // Set up parameters for the new wallet. + let path = CString::new("my_wallet").expect("CString::new failed"); + let password = CString::new("password").expect("CString::new failed"); + let language = CString::new("English").expect("CString::new failed"); + let network_type = NetworkType_MAINNET; + + // Create a new wallet. + let wallet_ptr = MONERO_WalletManager_createWallet( + wm_ptr, + path.as_ptr(), + password.as_ptr(), + language.as_ptr(), + network_type, + ); + if wallet_ptr.is_null() { + eprintln!("Failed to create wallet"); + return; + } + + // Get the seed. + let seed_offset = CString::new("").expect("CString::new failed"); + let seed_cstr = MONERO_Wallet_seed(wallet_ptr, seed_offset.as_ptr()); + if seed_cstr.is_null() { + eprintln!("Failed to get seed"); + } else { + let seed = CStr::from_ptr(seed_cstr).to_string_lossy().into_owned(); + println!("Seed: {}", seed); + } + + // Close the wallet. + let result = MONERO_WalletManager_closeWallet(wm_ptr, wallet_ptr, false); + if !result { + eprintln!("Failed to close wallet"); + } + } } |
