diff --git a/Cargo.lock b/Cargo.lock index e62fb2b1..5e558e44 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -439,9 +439,9 @@ checksum = "771fe0050b883fcc3ea2359b1a96bcfbc090b7116eae7c3c512c7a083fdf23d3" [[package]] name = "bstr" -version = "0.2.14" +version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "473fc6b38233f9af7baa94fb5852dca389e3d95b8e21c8e3719301462c5d9faf" +checksum = "a40b47ad93e1a5404e6c18dec46b628214fee441c70f4ab5d6942142cc268a3d" dependencies = [ "lazy_static", "memchr", @@ -801,19 +801,6 @@ dependencies = [ "generic-array 0.14.4", ] -[[package]] -name = "digest_auth" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d4bce617b8491dd210e3fcbc939e2c5bbeb27355f8adf7da335b87d6cc8d5482" -dependencies = [ - "digest 0.8.1", - "hex 0.4.2", - "md-5", - "rand 0.7.3", - "sha2 0.8.2", -] - [[package]] name = "directories-next" version = "2.0.0" @@ -1876,17 +1863,6 @@ version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7ffc5c5338469d4d3ea17d269fa8ea3512ad247247c30bd2df69e68309ed0a08" -[[package]] -name = "md-5" -version = "0.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a18af3dcaf2b0219366cdb4e2af65a6101457b415c3d1a5c71dd9c2b7c77b9c8" -dependencies = [ - "block-buffer 0.7.3", - "digest 0.8.1", - "opaque-debug 0.2.3", -] - [[package]] name = "memchr" version = "2.3.4" @@ -1983,20 +1959,27 @@ name = "monero-harness" version = "0.1.0" dependencies = [ "anyhow", - "digest_auth", "futures", + "monero-rpc", "port_check", "rand 0.7.3", - "reqwest", - "serde", - "serde_json", "spectral", "testcontainers 0.12.0", "tokio", "tracing", "tracing-log", "tracing-subscriber", - "url", +] + +[[package]] +name = "monero-rpc" +version = "0.1.0" +dependencies = [ + "anyhow", + "reqwest", + "serde", + "serde_json", + "tracing", ] [[package]] @@ -3488,6 +3471,7 @@ dependencies = [ "miniscript", "monero", "monero-harness", + "monero-rpc", "pem", "port_check", "prettytable-rs", diff --git a/Cargo.toml b/Cargo.toml index 976a7b53..8ddab59e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,2 +1,2 @@ [workspace] -members = ["monero-harness", "swap"] +members = ["monero-harness", "monero-rpc", "swap"] diff --git a/monero-harness/Cargo.toml b/monero-harness/Cargo.toml index a9704b0a..f4ff5b12 100644 --- a/monero-harness/Cargo.toml +++ b/monero-harness/Cargo.toml @@ -6,17 +6,13 @@ edition = "2018" [dependencies] anyhow = "1" -digest_auth = "0.2.3" futures = "0.3" +monero-rpc = { path = "../monero-rpc" } port_check = "0.1" rand = "0.7" -reqwest = { version = "0.11", default-features = false, features = ["json", "native-tls"] } -serde = { version = "1.0", features = ["derive"] } -serde_json = "1.0" spectral = "0.6" testcontainers = "0.12" tokio = { version = "1.0", default-features = false, features = ["rt-multi-thread", "time", "macros"] } tracing = "0.1" tracing-log = "0.1" tracing-subscriber = { version = "0.2", default-features = false, features = ["fmt", "ansi", "env-filter"] } -url = "2" diff --git a/monero-harness/src/lib.rs b/monero-harness/src/lib.rs index 2601fae3..ab528564 100644 --- a/monero-harness/src/lib.rs +++ b/monero-harness/src/lib.rs @@ -21,18 +21,15 @@ //! //! Also provides standalone JSON RPC clients for monerod and monero-wallet-rpc. pub mod image; -pub mod rpc; -use crate::{ - image::{ - MONEROD_DAEMON_CONTAINER_NAME, MONEROD_DEFAULT_NETWORK, MONEROD_RPC_PORT, WALLET_RPC_PORT, - }, - rpc::{ - monerod, - wallet::{self, GetAddress, Refreshed, Transfer}, - }, +use crate::image::{ + MONEROD_DAEMON_CONTAINER_NAME, MONEROD_DEFAULT_NETWORK, MONEROD_RPC_PORT, WALLET_RPC_PORT, }; use anyhow::{anyhow, bail, Result}; +use monero_rpc::{ + monerod, + wallet::{self, GetAddress, Refreshed, Transfer}, +}; use std::time::Duration; use testcontainers::{clients::Cli, core::Port, Container, Docker, RunArgs}; use tokio::time; diff --git a/monero-rpc/Cargo.toml b/monero-rpc/Cargo.toml new file mode 100644 index 00000000..cf2c7a6f --- /dev/null +++ b/monero-rpc/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "monero-rpc" +version = "0.1.0" +authors = ["CoBloX Team "] +edition = "2018" + +[dependencies] +anyhow = "1" +reqwest = { version = "0.11", default-features = false, features = ["json", "native-tls"] } +serde = { version = "1.0", features = ["derive"] } +serde_json = "1.0" +tracing = "0.1" diff --git a/monero-rpc/README.md b/monero-rpc/README.md new file mode 100644 index 00000000..ee15783a --- /dev/null +++ b/monero-rpc/README.md @@ -0,0 +1,12 @@ +Monero Harness +============== + +Provides an implementation of `testcontainers::Image` for a monero image to run +`monerod` and `monero-wallet-rpc` in a docker container. + +Also provides two standalone JSON RPC clients, one each for `monerod` and `monero-wallet-rpc`. + +Example Usage +------------- + +Please see `tests/*` for example usage. diff --git a/monero-rpc/rust-toolchain b/monero-rpc/rust-toolchain new file mode 100644 index 00000000..0a3db35b --- /dev/null +++ b/monero-rpc/rust-toolchain @@ -0,0 +1 @@ +1.46.0 diff --git a/monero-rpc/rustfmt.toml b/monero-rpc/rustfmt.toml new file mode 100644 index 00000000..d973e35c --- /dev/null +++ b/monero-rpc/rustfmt.toml @@ -0,0 +1,9 @@ +edition = "2018" +condense_wildcard_suffixes = true +format_macro_matchers = true +imports_granularity = "Crate" +use_field_init_shorthand = true +format_code_in_doc_comments = true +normalize_comments = true +wrap_comments = true +overflow_delimited_expr = true diff --git a/monero-rpc/src/lib.rs b/monero-rpc/src/lib.rs new file mode 100644 index 00000000..1a83b3e1 --- /dev/null +++ b/monero-rpc/src/lib.rs @@ -0,0 +1,17 @@ +#![warn( + unused_extern_crates, + missing_debug_implementations, + missing_copy_implementations, + rust_2018_idioms, + clippy::cast_possible_truncation, + clippy::cast_sign_loss, + clippy::fallible_impl_from, + clippy::cast_precision_loss, + clippy::cast_possible_wrap, + clippy::dbg_macro +)] +#![forbid(unsafe_code)] + +mod rpc; + +pub use self::rpc::*; diff --git a/monero-harness/src/rpc.rs b/monero-rpc/src/rpc.rs similarity index 95% rename from monero-harness/src/rpc.rs rename to monero-rpc/src/rpc.rs index eae827c1..e0e58ed7 100644 --- a/monero-harness/src/rpc.rs +++ b/monero-rpc/src/rpc.rs @@ -39,7 +39,6 @@ struct Response { #[cfg(test)] mod tests { use super::*; - use spectral::prelude::*; #[derive(Serialize, Debug, Clone)] struct Params { @@ -58,6 +57,7 @@ mod tests { let want = "{\"jsonrpc\":\"2.0\",\"id\":\"1\",\"method\":\"get_block\",\"params\":{\"val\":0}}" .to_string(); - assert_that!(got).is_equal_to(want); + + assert_eq!(got, want); } } diff --git a/monero-harness/src/rpc/monerod.rs b/monero-rpc/src/rpc/monerod.rs similarity index 99% rename from monero-harness/src/rpc/monerod.rs rename to monero-rpc/src/rpc/monerod.rs index e27f2556..a98300a7 100644 --- a/monero-harness/src/rpc/monerod.rs +++ b/monero-rpc/src/rpc/monerod.rs @@ -1,5 +1,4 @@ use crate::rpc::{Request, Response}; - use anyhow::Result; use reqwest::Url; use serde::{Deserialize, Serialize}; diff --git a/monero-harness/src/rpc/wallet.rs b/monero-rpc/src/rpc/wallet.rs similarity index 100% rename from monero-harness/src/rpc/wallet.rs rename to monero-rpc/src/rpc/wallet.rs diff --git a/swap/Cargo.toml b/swap/Cargo.toml index 6309c3b0..f849e027 100644 --- a/swap/Cargo.toml +++ b/swap/Cargo.toml @@ -20,7 +20,6 @@ backoff = { version = "0.3", features = ["tokio"] } base64 = "0.12" bdk = { version = "0.4" } bitcoin = { version = "0.26", features = ["rand", "use-serde"] } -bitcoin-harness = { git = "https://github.com/coblox/bitcoin-harness-rs" } config = { version = "0.10", default-features = false, features = ["toml"] } conquer-once = "0.3" curve25519-dalek = "3" @@ -33,7 +32,7 @@ libp2p-async-await = { git = "https://github.com/comit-network/rust-libp2p-async log = { version = "0.4", features = ["serde"] } miniscript = { version = "5", features = ["serde"] } monero = { version = "0.10", features = ["serde_support"] } -monero-harness = { path = "../monero-harness" } +monero-rpc = { path = "../monero-rpc" } pem = "0.8" prettytable-rs = "0.8" rand = "0.7" @@ -62,8 +61,10 @@ uuid = { version = "0.8", features = ["serde", "v4"] } void = "1" [dev-dependencies] +bitcoin-harness = { git = "https://github.com/coblox/bitcoin-harness-rs" } get-port = "3" hyper = "0.14" +monero-harness = { path = "../monero-harness" } port_check = "0.1" serde_cbor = "0.11" spectral = "0.6" diff --git a/swap/src/database/bob.rs b/swap/src/database/bob.rs index 260f6d84..4ee796e4 100644 --- a/swap/src/database/bob.rs +++ b/swap/src/database/bob.rs @@ -3,7 +3,7 @@ use crate::{ protocol::{bob, bob::BobState}, }; use ::bitcoin::hashes::core::fmt::Display; -use monero_harness::rpc::wallet::BlockHeight; +use monero_rpc::wallet::BlockHeight; use serde::{Deserialize, Serialize}; #[derive(Clone, Debug, Deserialize, Serialize, PartialEq)] diff --git a/swap/src/monero/wallet.rs b/swap/src/monero/wallet.rs index 06cc02e6..ce1d1a97 100644 --- a/swap/src/monero/wallet.rs +++ b/swap/src/monero/wallet.rs @@ -7,7 +7,7 @@ use anyhow::Result; use async_trait::async_trait; use backoff::{backoff::Constant as ConstantBackoff, future::retry}; use bitcoin::hashes::core::sync::atomic::AtomicU32; -use monero_harness::rpc::wallet; +use monero_rpc::wallet; use std::{ str::FromStr, sync::{atomic::Ordering, Arc}, diff --git a/swap/src/protocol/bob/state.rs b/swap/src/protocol/bob/state.rs index ee30275f..0d6349e7 100644 --- a/swap/src/protocol/bob/state.rs +++ b/swap/src/protocol/bob/state.rs @@ -21,7 +21,7 @@ use ecdsa_fun::{ nonce::Deterministic, Signature, }; -use monero_harness::rpc::wallet::BlockHeight; +use monero_rpc::wallet::BlockHeight; use rand::{CryptoRng, RngCore}; use serde::{Deserialize, Serialize}; use sha2::Sha256;