Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rust develop #103

Open
wants to merge 65 commits into
base: develop
Choose a base branch
from
Open

Rust develop #103

wants to merge 65 commits into from

Conversation

MrCyjaneK
Copy link
Owner

No description provided.

sneurlax and others added 30 commits October 9, 2024 19:07
courtesy of cypherstack/flutter_libmonero and MrCyjaneK & julian-CStack's work there

remove wownero

update docs and script

add gitignore
and document the required placement
just to match the style in impls

and sneurlax/monero_c -> MrCyjaneK/monero_c
and resolve 2 clippy issues

need to test on other platforms gestured-towards here in lib.rs
see #67 (comment)

I'm tired >.>
and update docs
@MrCyjaneK MrCyjaneK mentioned this pull request Jan 5, 2025
35 tasks
@MrCyjaneK
Copy link
Owner Author

note: checksums do not update in the bindings file

fix build
Copy link

github-actions bot commented Jan 5, 2025

@binarybaron
Copy link
Collaborator

I'm attempting a POC integration of this Rust wrapper here: UnstoppableSwap/core#244. To get things running I have simply copied the wrapper into our workspace. I'll try to find a better way as we make progress with our integration. I'll also try to push changes I make to this branch as well.

@MrCyjaneK
Copy link
Owner Author

Great, there are some things i want to fix (don't log to file, allow to load the library from any directory and use proper name for it).

@binarybaron
Copy link
Collaborator

use monero_c_rust::{NetworkType, WalletConfig, WalletError, WalletManager};
use tempfile::TempDir;

fn main() -> Result<(), WalletError> {
    let manager = WalletManager::new()?;

    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::Stagenet,
        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.");

    // Print the primary address.
    println!("Primary address: {}", wallet.get_address(0, 0)?);

    // Initialize the wallet.
    let config = WalletConfig {
        daemon_address: "http://localhost:38081".to_string(),
        upper_transaction_size_limit: 10000, // TODO: use sane value.
        daemon_username: "".to_string(),
        daemon_password: "".to_string(),
        use_ssl: false,
        light_wallet: false,
        proxy_address: "".to_string(),
    };

    // Set WalletManager's daemon address
    manager.set_daemon_address(&config.daemon_address);

    // Perform the initialization.
    wallet.init(config)?;
    wallet.throw_if_error()?;

    let target_block = manager.get_height_target()?;
    println!("Target block: {}", target_block);

    // Refresh the wallet.
    wallet.refresh()?; // This calls MONERO_Wallet_startRefresh
    wallet.throw_if_error()?;

    // Wait for the refresh to complete.
    loop {
        let height = wallet
            .get_current_sync_height() // This calls MONERO_Wallet_blockChainHeight
            .expect("Failed to get blockchain height");

        let daemon_height = wallet
            .get_daemon_height() // This calls MONERO_Wallet_daemonBlockChainHeight
            .expect("Failed to get daemon height");

        println!("Current blockchain height: {} / {}", height, daemon_height);
        if height >= daemon_height {
            // 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");
    std::fs::remove_file(format!("{}.keys", wallet_str))
        .expect("Failed to delete test wallet keys");

    Ok(())
}
2025-01-07 11:54:36,507 D Device 0 Created
2025-01-07 11:54:36,508 T refreshThreadFunc: starting refresh thread
2025-01-07 11:54:36,508 T refreshThreadFunc: waiting for refresh...
2025-01-07 11:54:36,548 I caching ringdb key
2025-01-07 11:54:36,562 D Calculated blockchain height: 1766275
2025-01-07 11:54:36,563 D Reconnecting...
2025-01-07 11:54:36,564 D Some problems at connect, message: resolve: Host not found (authoritative) [asio.netdb:1 at /Users/****/Development/monero_c/contrib/depends/aarch64-apple-darwin/include/boost/asio/detail/resolver_service.hpp:84:33 in function 'resolve']
2025-01-07 11:54:36,564 D Failed to connect to :
2025-01-07 11:54:36,564 I Failed to invoke http request to  /json_rpc
2025-01-07 11:54:36,564 E Failed to connect to daemon
2025-01-07 11:54:36,564 D Reconnecting...
2025-01-07 11:54:36,564 D Some problems at connect, message: resolve: Host not found (authoritative) [asio.netdb:1 at /Users/****/Development/monero_c/contrib/depends/aarch64-apple-darwin/include/boost/asio/detail/resolver_service.hpp:84:33 in function 'resolve']
2025-01-07 11:54:36,564 D Failed to connect to :
2025-01-07 11:54:36,564 I Failed to invoke http request to  /json_rpc
2025-01-07 11:54:36,564 E Failed to connect to daemon
2025-01-07 11:54:36,590 D /var/folders/q3/96gvm8255230tvzw3szbj0yr0000gn/T/.tmp0hltdN/test_wallet.keys is already unlocked.
Wallet created successfully.
Primary address: 56HeZM3u6xYCV8oVVh7CuWWHs7yeB1oxhNPrsEM5FKSqadTXmobLqsNEtRnyGsbN1rbDuBtWdtxtXhTJda1Lm9vcH73iSWn
2025-01-07 11:54:36,731 I [PARSE URI] regex not matched for uri: ^(([^:]*?)://)?(\[(.*)\](:(\d+))?)(.*)?
2025-01-07 11:54:36,731 I Generating SSL certificate
...
Current blockchain height: 1 / 1769997
Current blockchain height: 1769997 / 1769997

I still haven't gotten the syncing to work. Not sure why. It's also syncing way too fast. Either the restore height is not being set correctly or we are not actually syncing but only polling blocks?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants