This commit is contained in:
Thomas Eizinger 2021-04-13 08:55:38 +10:00
parent 2f19222948
commit c3b8c7fbdb
No known key found for this signature in database
GPG Key ID: 651AC83A6C6C8B96
5 changed files with 87 additions and 2 deletions

12
Cargo.lock generated
View File

@ -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"

View File

@ -1,2 +1,2 @@
[workspace]
members = ["monero-harness", "monero-rpc", "swap"]
members = ["monero-harness", "monero-rpc", "swap", "monero-wallet"]

View File

@ -55,7 +55,7 @@ impl<'c> Monero {
/// miner wallet container name is: `miner`
pub async fn new(
cli: &'c Cli,
additional_wallets: Vec<String>,
additional_wallets: Vec<&'static str>,
) -> Result<(Self, Vec<Container<'c, Cli, image::Monero>>)> {
let prefix = format!("{}_", random_prefix());
let monerod_name = format!("{}{}", prefix, MONEROD_DAEMON_CONTAINER_NAME);

16
monero-wallet/Cargo.toml Normal file
View File

@ -0,0 +1,16 @@
[package]
name = "monero-wallet"
version = "0.1.0"
authors = ["CoBloX Team <team@coblox.tech>"]
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"

57
monero-wallet/src/lib.rs Normal file
View File

@ -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::<monero::Address>()
.unwrap()
.public_spend,
},
});
}
}