From c0884e98649a2c3a05d9e15136c0b1169ba09243 Mon Sep 17 00:00:00 2001 From: Lucas Soriano del Pino Date: Tue, 13 Apr 2021 15:19:37 +1000 Subject: [PATCH] WIP2 --- Cargo.lock | 2 ++ monero-harness/src/image.rs | 2 +- monero-harness/src/lib.rs | 2 +- monero-harness/tests/wallet.rs | 4 +--- monero-rpc/Cargo.toml | 1 + monero-rpc/src/rpc/wallet.rs | 20 ++++++++++++++++---- monero-wallet/Cargo.toml | 1 + monero-wallet/src/lib.rs | 17 +++++++++++------ swap/src/monero/wallet.rs | 7 ++++++- swap/tests/harness/mod.rs | 10 ++++------ 10 files changed, 44 insertions(+), 22 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index bb2afa37..0eb2eaa2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2126,6 +2126,7 @@ name = "monero-rpc" version = "0.1.0" dependencies = [ "anyhow", + "monero", "reqwest", "serde", "serde_json", @@ -2137,6 +2138,7 @@ name = "monero-wallet" version = "0.1.0" dependencies = [ "curve25519-dalek", + "hex 0.4.3", "monero", "monero-harness", "rand 0.7.3", diff --git a/monero-harness/src/image.rs b/monero-harness/src/image.rs index b2342602..f0cfe105 100644 --- a/monero-harness/src/image.rs +++ b/monero-harness/src/image.rs @@ -75,7 +75,7 @@ impl Image for Monero { impl Default for Monero { fn default() -> Self { Monero { - tag: "v0.16.0.3".into(), + tag: "v0.17.2.0".into(), args: Args::default(), entrypoint: Some("".into()), wait_for_message: "core RPC server started ok".to_string(), diff --git a/monero-harness/src/lib.rs b/monero-harness/src/lib.rs index 1b9a56be..2747bdf5 100644 --- a/monero-harness/src/lib.rs +++ b/monero-harness/src/lib.rs @@ -262,7 +262,7 @@ impl<'c> MoneroWalletRpc { /// Sends amount to address pub async fn transfer(&self, address: &str, amount: u64) -> Result { - self.client().transfer(0, amount, address).await + self.client().transfer(0, amount, address, false).await } pub async fn address(&self) -> Result { diff --git a/monero-harness/tests/wallet.rs b/monero-harness/tests/wallet.rs index 15fb3698..fe36e857 100644 --- a/monero-harness/tests/wallet.rs +++ b/monero-harness/tests/wallet.rs @@ -16,9 +16,7 @@ async fn fund_transfer_and_check_tx_key() { let send_to_bob = 5_000_000_000; let tc = Cli::default(); - let (monero, _containers) = Monero::new(&tc, vec!["alice".to_string(), "bob".to_string()]) - .await - .unwrap(); + let (monero, _containers) = Monero::new(&tc, vec!["alice", "bob"]).await.unwrap(); let alice_wallet = monero.wallet("alice").unwrap(); let bob_wallet = monero.wallet("bob").unwrap(); diff --git a/monero-rpc/Cargo.toml b/monero-rpc/Cargo.toml index c70f2797..398ccacc 100644 --- a/monero-rpc/Cargo.toml +++ b/monero-rpc/Cargo.toml @@ -6,6 +6,7 @@ edition = "2018" [dependencies] anyhow = "1" +monero = { version = "0.11", features = ["serde_support"] } reqwest = { version = "0.11", default-features = false, features = ["json"] } serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" diff --git a/monero-rpc/src/rpc/wallet.rs b/monero-rpc/src/rpc/wallet.rs index dad66764..a11ca2dc 100644 --- a/monero-rpc/src/rpc/wallet.rs +++ b/monero-rpc/src/rpc/wallet.rs @@ -201,12 +201,13 @@ impl Client { account_index: u32, amount: u64, address: &str, + do_not_relay: bool, ) -> Result { let dest = vec![Destination { amount, address: address.to_owned(), }]; - self.multi_transfer(account_index, dest).await + self.multi_transfer(account_index, dest, do_not_relay).await } /// Transfers moneroj from `account_index` to `destinations`. @@ -214,11 +215,15 @@ impl Client { &self, account_index: u32, destinations: Vec, + do_not_relay: bool, ) -> Result { let params = TransferParams { account_index, destinations, get_tx_key: true, + do_not_relay, + get_tx_hex: true, + get_tx_metadata: true, }; let request = Request::new("transfer", params); @@ -231,6 +236,7 @@ impl Client { .text() .await?; + dbg!("transfer RPC response: {}", &response); debug!("transfer RPC response: {}", response); let r = serde_json::from_str::>(&response)?; @@ -448,12 +454,18 @@ struct CreateWalletParams { #[derive(Serialize, Debug, Clone)] struct TransferParams { - // Transfer from this account. + /// Transfer from this account. account_index: u32, - // Destinations to receive XMR: + /// Destinations to receive XMR: destinations: Vec, - // Return the transaction key after sending. + /// Return the transaction key after sending. get_tx_key: bool, + /// Do not relay the transaction. + do_not_relay: bool, + /// Return the tx_blob. + get_tx_hex: bool, + /// Return the metadata needed to relay the transaction later. + get_tx_metadata: bool, } #[derive(Serialize, Debug, Clone)] diff --git a/monero-wallet/Cargo.toml b/monero-wallet/Cargo.toml index 0cd5518b..bba7e31c 100644 --- a/monero-wallet/Cargo.toml +++ b/monero-wallet/Cargo.toml @@ -8,6 +8,7 @@ edition = "2018" monero = "0.11" [dev-dependencies] +hex = "0.4" monero-harness = { path = "../monero-harness" } tokio = { version = "1", features = ["rt-multi-thread", "time", "macros", "sync", "process", "fs"] } testcontainers = "0.12" diff --git a/monero-wallet/src/lib.rs b/monero-wallet/src/lib.rs index f2477487..c0632004 100644 --- a/monero-wallet/src/lib.rs +++ b/monero-wallet/src/lib.rs @@ -2,8 +2,7 @@ mod tests { use curve25519_dalek::scalar::Scalar; use monero::blockdata::transaction::TxOutTarget; - use monero::blockdata::TransactionPrefix; - use monero::consensus::encode::VarInt; + use monero::consensus::encode::{deserialize, VarInt}; use monero::{TxIn, TxOut}; use monero_harness::Monero; use testcontainers::*; @@ -11,7 +10,8 @@ mod tests { #[tokio::test] async fn can_broadcast_locally_signed_transaction() { let cli = clients::Cli::default(); - let (monero, containers) = Monero::new(&cli, vec!["Alice"]).await.unwrap(); + let (monero, _containers) = Monero::new(&cli, vec!["alice"]).await.unwrap(); + monero.init(vec![("alice", 10_000_000_000)]).await.unwrap(); let view_key = monero::PrivateKey::from_scalar(Scalar::random(&mut rand::thread_rng())); let spend_key = monero::PrivateKey::from_scalar(Scalar::random(&mut rand::thread_rng())); @@ -20,15 +20,20 @@ mod tests { let public_spend_key = monero::PublicKey::from_private_key(&spend_key); let address = - monero::Address::standard(monero::Network::Stagenet, public_spend_key, public_view_key); + monero::Address::standard(monero::Network::Mainnet, public_spend_key, public_view_key); + let transfer = monero - .wallet("miner") + .wallet("alice") .unwrap() .client() - .transfer(0, 100_000, &address.to_string()) + .transfer(0, 1, &address.to_string(), false) .await .unwrap(); + let tx = hex::decode(&transfer.tx_blob).unwrap(); + let tx = deserialize::(&tx).unwrap(); + dbg!(tx); + // [k_image, k_image + offset_0, k_image + offset_0 + offset_1, ..] let mut transaction = monero::Transaction::default(); transaction.prefix.version = VarInt(2); diff --git a/swap/src/monero/wallet.rs b/swap/src/monero/wallet.rs index b3561281..68e5e809 100644 --- a/swap/src/monero/wallet.rs +++ b/swap/src/monero/wallet.rs @@ -178,7 +178,12 @@ impl Wallet { .inner .lock() .await - .transfer(0, amount.as_piconero(), &destination_address.to_string()) + .transfer( + 0, + amount.as_piconero(), + &destination_address.to_string(), + false, + ) .await?; tracing::debug!( diff --git a/swap/tests/harness/mod.rs b/swap/tests/harness/mod.rs index 9549d785..d30e8edd 100644 --- a/swap/tests/harness/mod.rs +++ b/swap/tests/harness/mod.rs @@ -752,12 +752,10 @@ async fn init_monero_container( Monero, Vec>, ) { - let (monero, monerods) = Monero::new(&cli, vec![ - MONERO_WALLET_NAME_ALICE.to_string(), - MONERO_WALLET_NAME_BOB.to_string(), - ]) - .await - .unwrap(); + let (monero, monerods) = + Monero::new(&cli, vec![MONERO_WALLET_NAME_ALICE, MONERO_WALLET_NAME_BOB]) + .await + .unwrap(); (monero, monerods) }