From 134287d195309eaa19349c961acbb7ca54eb359d Mon Sep 17 00:00:00 2001 From: Lucas Soriano del Pino Date: Thu, 6 May 2021 17:25:53 +1000 Subject: [PATCH] [WIP] More done --- monero-adaptor/tests/integration_test.rs | 8 +---- monero-rpc/src/monerod.rs | 38 ++++++++++++++++++++++++ monero-rpc/src/wallet.rs | 4 --- rust-toolchain | 2 +- 4 files changed, 40 insertions(+), 12 deletions(-) diff --git a/monero-adaptor/tests/integration_test.rs b/monero-adaptor/tests/integration_test.rs index 00de3893..af56661a 100644 --- a/monero-adaptor/tests/integration_test.rs +++ b/monero-adaptor/tests/integration_test.rs @@ -13,7 +13,6 @@ use monero::cryptonote::onetime_key::KeyGenerator; use monero::util::ringct::{EcdhInfo, RctSig, RctSigBase, RctSigPrunable, RctType}; use monero::{PrivateKey, PublicKey}; use monero::{Transaction, TransactionPrefix, TxIn, TxOut, VarInt}; -use monero_rpc::wallet::MoneroWalletRpc as _; use monero_rpc::monerod; use monero_rpc::monerod::{GetOutputsOut, MonerodRpc}; use monero_wallet::{MonerodClientExt, Wallet}; @@ -183,12 +182,7 @@ async fn monerod_integration_test() { }, }; - let wallet_client = monero_rpc::wallet::Client::localhost(0).unwrap(); - - let tx_hex = hex::encode(monero::consensus::encode::serialize(&transaction)); - let tx_hash = wallet_client.submit_transfer(tx_hex).await.unwrap(); - - dbg!(tx_hash); + client.send_raw_transaction(transaction).await.unwrap(); } fn to_relative_offsets(offsets: &[VarInt]) -> Vec { diff --git a/monero-rpc/src/monerod.rs b/monero-rpc/src/monerod.rs index 43bd094a..7e62e9e1 100644 --- a/monero-rpc/src/monerod.rs +++ b/monero-rpc/src/monerod.rs @@ -19,6 +19,7 @@ pub struct Client { get_o_indexes_bin_url: reqwest::Url, get_outs_bin_url: reqwest::Url, get_transactions: reqwest::Url, + send_raw_transaction: reqwest::Url, } impl Client { @@ -44,6 +45,9 @@ impl Client { get_transactions: format!("http://{}:{}/get_transactions", host, port) .parse() .context("url is well formed")?, + send_raw_transaction: format!("http://{}:{}/send_raw_transaction", host, port) + .parse() + .context("url is well formed")?, }) } @@ -79,6 +83,29 @@ impl Client { .await } + pub async fn send_raw_transaction(&self, tx: Transaction) -> Result<()> { + let tx_as_hex = hex::encode(monero::consensus::encode::serialize(&tx)); + + let response = self + .inner + .post(self.send_raw_transaction.clone()) + .json(&SendRawTransactionRequest { tx_as_hex }) + .send() + .await?; + + if !response.status().is_success() { + anyhow::bail!("Request failed with status code {}", response.status()) + } + + let response = response.json::().await?; + + if response.status == Status::Failed { + anyhow::bail!("Response status failed") + } + + Ok(()) + } + async fn binary_request(&self, url: reqwest::Url, request: Req) -> Result where Req: Serialize, @@ -182,6 +209,17 @@ pub struct GetOutsResponse { pub outs: Vec, } +#[derive(Clone, Debug, Serialize, PartialEq)] +pub struct SendRawTransactionRequest { + pub tx_as_hex: String, +} + +#[derive(Clone, Debug, Deserialize, PartialEq)] +pub struct SendRawTransactionResponse { + pub status: Status, + pub reason: String, +} + #[derive(Clone, Copy, Debug, Deserialize, PartialEq)] pub struct OutKey { pub height: u64, diff --git a/monero-rpc/src/wallet.rs b/monero-rpc/src/wallet.rs index eb3751f0..ed2c78f0 100644 --- a/monero-rpc/src/wallet.rs +++ b/monero-rpc/src/wallet.rs @@ -16,10 +16,6 @@ pub trait MoneroWalletRpc { destinations: Vec, get_tx_key: bool, ) -> Transfer; - async fn submit_transfer( - &self, - tx_data_hex: String, - ) -> Vec; 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)] diff --git a/rust-toolchain b/rust-toolchain index 42a494a3..8fc862b0 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1,4 +1,4 @@ [toolchain] channel = "nightly-2021-05-04" -components = ["rustfmt", "clippy"] +components = ["clippy"] targets = ["armv7-unknown-linux-gnueabihf"]