mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2025-02-02 10:35:22 -05:00
WIP2
This commit is contained in:
parent
c3b8c7fbdb
commit
c0884e9864
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -2126,6 +2126,7 @@ name = "monero-rpc"
|
|||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
|
"monero",
|
||||||
"reqwest",
|
"reqwest",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
@ -2137,6 +2138,7 @@ name = "monero-wallet"
|
|||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"curve25519-dalek",
|
"curve25519-dalek",
|
||||||
|
"hex 0.4.3",
|
||||||
"monero",
|
"monero",
|
||||||
"monero-harness",
|
"monero-harness",
|
||||||
"rand 0.7.3",
|
"rand 0.7.3",
|
||||||
|
@ -75,7 +75,7 @@ impl Image for Monero {
|
|||||||
impl Default for Monero {
|
impl Default for Monero {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Monero {
|
Monero {
|
||||||
tag: "v0.16.0.3".into(),
|
tag: "v0.17.2.0".into(),
|
||||||
args: Args::default(),
|
args: Args::default(),
|
||||||
entrypoint: Some("".into()),
|
entrypoint: Some("".into()),
|
||||||
wait_for_message: "core RPC server started ok".to_string(),
|
wait_for_message: "core RPC server started ok".to_string(),
|
||||||
|
@ -262,7 +262,7 @@ impl<'c> MoneroWalletRpc {
|
|||||||
|
|
||||||
/// Sends amount to address
|
/// Sends amount to address
|
||||||
pub async fn transfer(&self, address: &str, amount: u64) -> Result<Transfer> {
|
pub async fn transfer(&self, address: &str, amount: u64) -> Result<Transfer> {
|
||||||
self.client().transfer(0, amount, address).await
|
self.client().transfer(0, amount, address, false).await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn address(&self) -> Result<GetAddress> {
|
pub async fn address(&self) -> Result<GetAddress> {
|
||||||
|
@ -16,9 +16,7 @@ async fn fund_transfer_and_check_tx_key() {
|
|||||||
let send_to_bob = 5_000_000_000;
|
let send_to_bob = 5_000_000_000;
|
||||||
|
|
||||||
let tc = Cli::default();
|
let tc = Cli::default();
|
||||||
let (monero, _containers) = Monero::new(&tc, vec!["alice".to_string(), "bob".to_string()])
|
let (monero, _containers) = Monero::new(&tc, vec!["alice", "bob"]).await.unwrap();
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
let alice_wallet = monero.wallet("alice").unwrap();
|
let alice_wallet = monero.wallet("alice").unwrap();
|
||||||
let bob_wallet = monero.wallet("bob").unwrap();
|
let bob_wallet = monero.wallet("bob").unwrap();
|
||||||
|
|
||||||
|
@ -6,6 +6,7 @@ edition = "2018"
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
anyhow = "1"
|
anyhow = "1"
|
||||||
|
monero = { version = "0.11", features = ["serde_support"] }
|
||||||
reqwest = { version = "0.11", default-features = false, features = ["json"] }
|
reqwest = { version = "0.11", default-features = false, features = ["json"] }
|
||||||
serde = { version = "1.0", features = ["derive"] }
|
serde = { version = "1.0", features = ["derive"] }
|
||||||
serde_json = "1.0"
|
serde_json = "1.0"
|
||||||
|
@ -201,12 +201,13 @@ impl Client {
|
|||||||
account_index: u32,
|
account_index: u32,
|
||||||
amount: u64,
|
amount: u64,
|
||||||
address: &str,
|
address: &str,
|
||||||
|
do_not_relay: bool,
|
||||||
) -> Result<Transfer> {
|
) -> Result<Transfer> {
|
||||||
let dest = vec![Destination {
|
let dest = vec![Destination {
|
||||||
amount,
|
amount,
|
||||||
address: address.to_owned(),
|
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`.
|
/// Transfers moneroj from `account_index` to `destinations`.
|
||||||
@ -214,11 +215,15 @@ impl Client {
|
|||||||
&self,
|
&self,
|
||||||
account_index: u32,
|
account_index: u32,
|
||||||
destinations: Vec<Destination>,
|
destinations: Vec<Destination>,
|
||||||
|
do_not_relay: bool,
|
||||||
) -> Result<Transfer> {
|
) -> Result<Transfer> {
|
||||||
let params = TransferParams {
|
let params = TransferParams {
|
||||||
account_index,
|
account_index,
|
||||||
destinations,
|
destinations,
|
||||||
get_tx_key: true,
|
get_tx_key: true,
|
||||||
|
do_not_relay,
|
||||||
|
get_tx_hex: true,
|
||||||
|
get_tx_metadata: true,
|
||||||
};
|
};
|
||||||
let request = Request::new("transfer", params);
|
let request = Request::new("transfer", params);
|
||||||
|
|
||||||
@ -231,6 +236,7 @@ impl Client {
|
|||||||
.text()
|
.text()
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
|
dbg!("transfer RPC response: {}", &response);
|
||||||
debug!("transfer RPC response: {}", response);
|
debug!("transfer RPC response: {}", response);
|
||||||
|
|
||||||
let r = serde_json::from_str::<Response<Transfer>>(&response)?;
|
let r = serde_json::from_str::<Response<Transfer>>(&response)?;
|
||||||
@ -448,12 +454,18 @@ struct CreateWalletParams {
|
|||||||
|
|
||||||
#[derive(Serialize, Debug, Clone)]
|
#[derive(Serialize, Debug, Clone)]
|
||||||
struct TransferParams {
|
struct TransferParams {
|
||||||
// Transfer from this account.
|
/// Transfer from this account.
|
||||||
account_index: u32,
|
account_index: u32,
|
||||||
// Destinations to receive XMR:
|
/// Destinations to receive XMR:
|
||||||
destinations: Vec<Destination>,
|
destinations: Vec<Destination>,
|
||||||
// Return the transaction key after sending.
|
/// Return the transaction key after sending.
|
||||||
get_tx_key: bool,
|
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)]
|
#[derive(Serialize, Debug, Clone)]
|
||||||
|
@ -8,6 +8,7 @@ edition = "2018"
|
|||||||
monero = "0.11"
|
monero = "0.11"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
|
hex = "0.4"
|
||||||
monero-harness = { path = "../monero-harness" }
|
monero-harness = { path = "../monero-harness" }
|
||||||
tokio = { version = "1", features = ["rt-multi-thread", "time", "macros", "sync", "process", "fs"] }
|
tokio = { version = "1", features = ["rt-multi-thread", "time", "macros", "sync", "process", "fs"] }
|
||||||
testcontainers = "0.12"
|
testcontainers = "0.12"
|
||||||
|
@ -2,8 +2,7 @@
|
|||||||
mod tests {
|
mod tests {
|
||||||
use curve25519_dalek::scalar::Scalar;
|
use curve25519_dalek::scalar::Scalar;
|
||||||
use monero::blockdata::transaction::TxOutTarget;
|
use monero::blockdata::transaction::TxOutTarget;
|
||||||
use monero::blockdata::TransactionPrefix;
|
use monero::consensus::encode::{deserialize, VarInt};
|
||||||
use monero::consensus::encode::VarInt;
|
|
||||||
use monero::{TxIn, TxOut};
|
use monero::{TxIn, TxOut};
|
||||||
use monero_harness::Monero;
|
use monero_harness::Monero;
|
||||||
use testcontainers::*;
|
use testcontainers::*;
|
||||||
@ -11,7 +10,8 @@ mod tests {
|
|||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn can_broadcast_locally_signed_transaction() {
|
async fn can_broadcast_locally_signed_transaction() {
|
||||||
let cli = clients::Cli::default();
|
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 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()));
|
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 public_spend_key = monero::PublicKey::from_private_key(&spend_key);
|
||||||
|
|
||||||
let address =
|
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
|
let transfer = monero
|
||||||
.wallet("miner")
|
.wallet("alice")
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.client()
|
.client()
|
||||||
.transfer(0, 100_000, &address.to_string())
|
.transfer(0, 1, &address.to_string(), false)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
let tx = hex::decode(&transfer.tx_blob).unwrap();
|
||||||
|
let tx = deserialize::<monero::Transaction>(&tx).unwrap();
|
||||||
|
dbg!(tx);
|
||||||
|
|
||||||
// [k_image, k_image + offset_0, k_image + offset_0 + offset_1, ..]
|
// [k_image, k_image + offset_0, k_image + offset_0 + offset_1, ..]
|
||||||
let mut transaction = monero::Transaction::default();
|
let mut transaction = monero::Transaction::default();
|
||||||
transaction.prefix.version = VarInt(2);
|
transaction.prefix.version = VarInt(2);
|
||||||
|
@ -178,7 +178,12 @@ impl Wallet {
|
|||||||
.inner
|
.inner
|
||||||
.lock()
|
.lock()
|
||||||
.await
|
.await
|
||||||
.transfer(0, amount.as_piconero(), &destination_address.to_string())
|
.transfer(
|
||||||
|
0,
|
||||||
|
amount.as_piconero(),
|
||||||
|
&destination_address.to_string(),
|
||||||
|
false,
|
||||||
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
tracing::debug!(
|
tracing::debug!(
|
||||||
|
@ -752,10 +752,8 @@ async fn init_monero_container(
|
|||||||
Monero,
|
Monero,
|
||||||
Vec<Container<'_, Cli, monero_harness::image::Monero>>,
|
Vec<Container<'_, Cli, monero_harness::image::Monero>>,
|
||||||
) {
|
) {
|
||||||
let (monero, monerods) = Monero::new(&cli, vec![
|
let (monero, monerods) =
|
||||||
MONERO_WALLET_NAME_ALICE.to_string(),
|
Monero::new(&cli, vec![MONERO_WALLET_NAME_ALICE, MONERO_WALLET_NAME_BOB])
|
||||||
MONERO_WALLET_NAME_BOB.to_string(),
|
|
||||||
])
|
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user