From c3b8c7fbdb577b5da07fa1f44b1502b37fbabe98 Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Tue, 13 Apr 2021 08:55:38 +1000 Subject: [PATCH] WIP --- Cargo.lock | 12 +++++++++ Cargo.toml | 2 +- monero-harness/src/lib.rs | 2 +- monero-wallet/Cargo.toml | 16 +++++++++++ monero-wallet/src/lib.rs | 57 +++++++++++++++++++++++++++++++++++++++ 5 files changed, 87 insertions(+), 2 deletions(-) create mode 100644 monero-wallet/Cargo.toml create mode 100644 monero-wallet/src/lib.rs diff --git a/Cargo.lock b/Cargo.lock index 4c5d0ee7..bb2afa37 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2132,6 +2132,18 @@ dependencies = [ "tracing", ] +[[package]] +name = "monero-wallet" +version = "0.1.0" +dependencies = [ + "curve25519-dalek", + "monero", + "monero-harness", + "rand 0.7.3", + "testcontainers 0.12.0", + "tokio 1.4.0", +] + [[package]] name = "multihash" version = "0.13.2" diff --git a/Cargo.toml b/Cargo.toml index 8ddab59e..02e9cc6f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,2 +1,2 @@ [workspace] -members = ["monero-harness", "monero-rpc", "swap"] +members = ["monero-harness", "monero-rpc", "swap", "monero-wallet"] diff --git a/monero-harness/src/lib.rs b/monero-harness/src/lib.rs index f635da63..1b9a56be 100644 --- a/monero-harness/src/lib.rs +++ b/monero-harness/src/lib.rs @@ -55,7 +55,7 @@ impl<'c> Monero { /// miner wallet container name is: `miner` pub async fn new( cli: &'c Cli, - additional_wallets: Vec, + additional_wallets: Vec<&'static str>, ) -> Result<(Self, Vec>)> { let prefix = format!("{}_", random_prefix()); let monerod_name = format!("{}{}", prefix, MONEROD_DAEMON_CONTAINER_NAME); diff --git a/monero-wallet/Cargo.toml b/monero-wallet/Cargo.toml new file mode 100644 index 00000000..0cd5518b --- /dev/null +++ b/monero-wallet/Cargo.toml @@ -0,0 +1,16 @@ +[package] +name = "monero-wallet" +version = "0.1.0" +authors = ["CoBloX Team "] +edition = "2018" + +[dependencies] +monero = "0.11" + +[dev-dependencies] +monero-harness = { path = "../monero-harness" } +tokio = { version = "1", features = ["rt-multi-thread", "time", "macros", "sync", "process", "fs"] } +testcontainers = "0.12" +monero = "0.11" +curve25519-dalek = "3" +rand = "0.7" diff --git a/monero-wallet/src/lib.rs b/monero-wallet/src/lib.rs new file mode 100644 index 00000000..f2477487 --- /dev/null +++ b/monero-wallet/src/lib.rs @@ -0,0 +1,57 @@ +#[cfg(test)] +mod tests { + use curve25519_dalek::scalar::Scalar; + use monero::blockdata::transaction::TxOutTarget; + use monero::blockdata::TransactionPrefix; + use monero::consensus::encode::VarInt; + use monero::{TxIn, TxOut}; + use monero_harness::Monero; + use testcontainers::*; + + #[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 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 public_view_key = monero::PublicKey::from_private_key(&view_key); + 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); + let transfer = monero + .wallet("miner") + .unwrap() + .client() + .transfer(0, 100_000, &address.to_string()) + .await + .unwrap(); + + // [k_image, k_image + offset_0, k_image + offset_0 + offset_1, ..] + let mut transaction = monero::Transaction::default(); + transaction.prefix.version = VarInt(2); + transaction.prefix.inputs.push(TxIn::ToKey { + amount: VarInt(0), + k_image: todo!(), + key_offsets: Vec::new(), + }); + transaction.prefix.outputs.push(TxOut { + amount: VarInt(0), + target: TxOutTarget::ToKey { + key: monero + .wallet("alice") + .unwrap() + .client() + .get_address(0) + .await + .unwrap() + .address + .parse::() + .unwrap() + .public_spend, + }, + }); + } +}