mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2025-01-05 12:51:04 -05:00
[WIP] More done
This commit is contained in:
parent
64a0bd7f8a
commit
134287d195
@ -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<VarInt> {
|
||||
|
@ -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::<SendRawTransactionResponse>().await?;
|
||||
|
||||
if response.status == Status::Failed {
|
||||
anyhow::bail!("Response status failed")
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn binary_request<Req, Res>(&self, url: reqwest::Url, request: Req) -> Result<Res>
|
||||
where
|
||||
Req: Serialize,
|
||||
@ -182,6 +209,17 @@ pub struct GetOutsResponse {
|
||||
pub outs: Vec<OutKey>,
|
||||
}
|
||||
|
||||
#[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,
|
||||
|
@ -16,10 +16,6 @@ pub trait MoneroWalletRpc {
|
||||
destinations: Vec<Destination>,
|
||||
get_tx_key: bool,
|
||||
) -> Transfer;
|
||||
async fn submit_transfer(
|
||||
&self,
|
||||
tx_data_hex: String,
|
||||
) -> Vec<String>;
|
||||
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)]
|
||||
|
@ -1,4 +1,4 @@
|
||||
[toolchain]
|
||||
channel = "nightly-2021-05-04"
|
||||
components = ["rustfmt", "clippy"]
|
||||
components = ["clippy"]
|
||||
targets = ["armv7-unknown-linux-gnueabihf"]
|
||||
|
Loading…
Reference in New Issue
Block a user