Conversation
courtesy of cypherstack/flutter_libmonero and MrCyjaneK & julian-CStack's work there remove wownero update docs and script add gitignore
and touch gitignore
and document the required placement
just to match the style in impls and sneurlax/monero_c -> MrCyjaneK/monero_c
This comment was marked as resolved.
This comment was marked as resolved.
and resolve 2 clippy issues need to test on other platforms gestured-towards here in lib.rs
in response to (but not resolving) MrCyjaneK#67 (comment)
|
Again, this is a really cool proof of concept. I'm currently compiling this branch and testing it out. I'll try to leave some feedback on this PR over the next few days. I'd love to use this for our atomic swaps implementation to replace monero-wallet-rpc. I'll just throw all the api calls we'd need to replace with your wrapper in here. You don't have to implement all this but perhaps it's interesting to you. #[jsonrpc_client::api(version = "2.0")]
pub trait MoneroWalletRpc {
async fn get_address(&self, account_index: u32) -> GetAddress;
async fn get_balance(&self, account_index: u32) -> GetBalance;
async fn create_account(&self, label: String) -> CreateAccount;
async fn get_accounts(&self, tag: String) -> GetAccounts;
async fn open_wallet(&self, filename: String) -> WalletOpened;
async fn close_wallet(&self) -> WalletClosed;
async fn create_wallet(&self, filename: String, language: String) -> WalletCreated;
async fn transfer(
&self,
account_index: u32,
destinations: Vec<Destination>,
get_tx_key: bool,
) -> Transfer;
async fn get_height(&self) -> BlockHeight;
async fn check_tx_key(&self, txid: String, tx_key: String, address: String) -> CheckTxKey;
#[allow(clippy::too_many_arguments)]
async fn generate_from_keys(
&self,
filename: String,
address: String,
spendkey: String,
viewkey: String,
restore_height: u32,
password: String,
autosave_current: bool,
) -> GenerateFromKeys;
async fn refresh(&self) -> Refreshed;
async fn sweep_all(&self, address: String) -> SweepAll;
async fn get_version(&self) -> Version;
} |
|
Thanks @binarybaron, that's a good initial list of methods to wrap, I appreciate the targets. Do note that I've been pushing changes before and after your comment so things may be changing. You can get a lib from https://github.com/MrCyjaneK/monero_c/releases rather than building it with the script, which has now been removed IAW MrCyjaneK's requested changes |
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
|
Running Edit: This is a known issue |
|
Thanks for that, I'll update the bindings etc after a rebuild. I'm working on getting the example app working now in order to complete the testing tasks, then will work on macos, windows, etc |
|
As of now, check_tx_key doesn't work as expected. I was expecting it to work without being synced (I think it should be able to tell if a txid & tx key pair are related without being able to tell if the tx is in the pool, etc., but I'm not sure about this). I just pushed failing tests, I think it's an FFI error and will have to dig in deeper another time. The example app in monero_c/impls/monero.rs/example runs almost as expected, it generates the expected address but fails to ever connect to a node or sync. I'll be looking into this eventually but if anyone reading this can get it fixed you're more than welcome to the change in that wallet as pushed :) swiper no swiping if you're not going to fix it (on your honor) |
|
binarybaron mentioned on Matrix that the monero-harness crate and testcontainers-rs will be helpful for testing on private nets: https://github.com/UnstoppableSwap/core/tree/master/monero-harness |
|
@sneurlax FYI: We haven't forgotten this, we had a lot on our plate with our 1.0 release. We are still very eager to use this :) I'll get to this hopefully soon. |
|
I haven't been able to compile |
|
@binarybaron you need to run |
I get this error when building: Any idea how to fix? :/ |
|
Could you try building the binaries from develop branch? There has been couple improvements made and this PR is out of date, I'll merge develop to this branch in a bit. |
|
|
Could I get write access to the branch? @MrCyjaneK @sneurlax |
|
I got this compiling on my machine. The example is not syncing the wallet properly for me. I'm using a stagenet wallet and a local node. 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,
1767926, // 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: " 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(),
};
// 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()?;
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");
std::fs::remove_file(format!("{}.keys", wallet_str))
.expect("Failed to delete test wallet keys");
Ok(())
} |
|
Perhaps the issue is that in let c_daemon_address = CString::new(config.daemon_address)
.map_err(|_| WalletError::FfiError("Invalid daemon address".to_string()))?;
....
unsafe {
...
let result = bindings::MONERO_Wallet_init(
self.ptr.as_ptr(),
c_daemon_address.as_ptr(),
config.upper_transaction_size_limit,
c_daemon_username.as_ptr(),
c_daemon_password.as_ptr(),
config.use_ssl,
config.light_wallet,
c_proxy_address.as_ptr(),
);
if result {
// After returning c_daemon_address will be freed
Ok(())
} else {
// Retrieve the last error from the wallet
Err(self.get_last_error())
}
}I tried using |
|
|
||
| // Wait for the refresh to complete. | ||
| loop { | ||
| let height = manager.get_height().expect("Failed to get blockchain height"); |
There was a problem hiding this comment.
You are checking WalletManager's height, but you forgot to set MONERO_WalletManager_setDaemonAddress before that, Wallet_init doesn't do that for you
There was a problem hiding this comment.
That's odd. Why are we passing on the daemon address if it is not used?
There was a problem hiding this comment.
@binarybaron right, we shouldn't be checking manager's height but wallet's height instead
There was a problem hiding this comment.
I don't believe the wallet is synced properly. I sent funds to the wallet but they are not detected (balance is zero).
There was a problem hiding this comment.
that's correct, because that function is asking the node about the height, and not the wallet
There was a problem hiding this comment.
How would I check how far the sync is?
There was a problem hiding this comment.
monero.Wallet_blockchainHeight()
and
if the difference is zero - you are synced
There was a problem hiding this comment.
also current example uses refresh, instead I would recommend using
|
Is there a difference between |
|
No, it is the same file - I'm not sure why rust needs all of them. The general convention is to use {prefix}monero_libwallet2_api_c.{suffix} where suffix is so/dll/dylib and prefix is lib on android |
|
@binarybaron maybe polyseed doesn't know how to handle that for stagenet? I'm not sure, can you try using extern ADDAPI void MONERO_Wallet_setRefreshFromBlockHeight(void* wallet_ptr, uint64_t refresh_from_block_height); to verify that it contains correct restore height? |
Yes, calling |
Proof of concept Rust bindings. TODO:
get_statusclippywarnings (format, etc.)Ensure cross-platform compatibility:
and so we don't overload our upstream:
We may also want to: (optional)
Optionally, improve the build script:- [x] Don't clone a brand new repo, build in place (unless passed-c|--clean)Build script removed