saving to wip branch

This commit is contained in:
Lorenzo Tucci 2022-11-11 20:14:45 +01:00 committed by binarybaron
parent e279b20629
commit 229ee5a65b
5 changed files with 186 additions and 6 deletions

151
Cargo.lock generated
View File

@ -262,6 +262,15 @@ version = "0.9.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d86b93f97252c47b41663388e6d155714a9d0c398b99f1005cbc5f978b29f445"
[[package]]
name = "beef"
version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3a8241f3ebb85c056b509d4327ad0358fbbba6ffb340bf388f26350aeda225b1"
dependencies = [
"serde",
]
[[package]]
name = "big-bytes"
version = "1.0.0"
@ -467,6 +476,15 @@ version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "771fe0050b883fcc3ea2359b1a96bcfbc090b7116eae7c3c512c7a083fdf23d3"
[[package]]
name = "bstr"
version = "0.2.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ba3569f383e8f1598449f1a423e72e99569137b47740b1da11ef19af3d5c3223"
dependencies = [
"memchr",
]
[[package]]
name = "bumpalo"
version = "3.6.1"
@ -1431,6 +1449,19 @@ dependencies = [
"url",
]
[[package]]
name = "globset"
version = "0.4.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0a1e17342619edbc21a964c2afbeb6c820c6a2560032872f397bb97ea127bd0a"
dependencies = [
"aho-corasick",
"bstr",
"fnv",
"log",
"regex",
]
[[package]]
name = "h2"
version = "0.3.11"
@ -1564,13 +1595,13 @@ dependencies = [
[[package]]
name = "http"
version = "0.2.3"
version = "0.2.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7245cd7449cc792608c3c8a9eaf69bd4eabbabf802713748fd739c98b82f0747"
checksum = "75f43d41e26995c17e71ee126451dd3941010b0514a81a9d11f3b341debc2399"
dependencies = [
"bytes",
"fnv",
"itoa 0.4.7",
"itoa 1.0.1",
]
[[package]]
@ -1783,6 +1814,99 @@ dependencies = [
"syn",
]
[[package]]
name = "jsonrpsee"
version = "0.15.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8bd0d559d5e679b1ab2f869b486a11182923863b1b3ee8b421763cdd707b783a"
dependencies = [
"jsonrpsee-core",
"jsonrpsee-http-server",
"jsonrpsee-types",
"jsonrpsee-ws-server",
]
[[package]]
name = "jsonrpsee-core"
version = "0.15.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f3dc3e9cf2ba50b7b1d7d76a667619f82846caa39e8e8daa8a4962d74acaddca"
dependencies = [
"anyhow",
"arrayvec 0.7.2",
"async-trait",
"beef",
"futures-channel",
"futures-util",
"globset",
"http",
"hyper",
"jsonrpsee-types",
"lazy_static",
"parking_lot 0.12.0",
"rand 0.8.3",
"rustc-hash",
"serde",
"serde_json",
"soketto",
"thiserror",
"tokio",
"tracing",
"unicase",
]
[[package]]
name = "jsonrpsee-http-server"
version = "0.15.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "03802f0373a38c2420c70b5144742d800b509e2937edc4afb116434f07120117"
dependencies = [
"futures-channel",
"futures-util",
"hyper",
"jsonrpsee-core",
"jsonrpsee-types",
"serde",
"serde_json",
"tokio",
"tracing",
"tracing-futures",
]
[[package]]
name = "jsonrpsee-types"
version = "0.15.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e290bba767401b646812f608c099b922d8142603c9e73a50fb192d3ac86f4a0d"
dependencies = [
"anyhow",
"beef",
"serde",
"serde_json",
"thiserror",
"tracing",
]
[[package]]
name = "jsonrpsee-ws-server"
version = "0.15.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d488ba74fb369e5ab68926feb75a483458b88e768d44319f37e4ecad283c7325"
dependencies = [
"futures-channel",
"futures-util",
"http",
"jsonrpsee-core",
"jsonrpsee-types",
"serde_json",
"soketto",
"tokio",
"tokio-stream",
"tokio-util 0.7.2",
"tracing",
"tracing-futures",
]
[[package]]
name = "keccak"
version = "0.1.0"
@ -3282,6 +3406,12 @@ dependencies = [
"rust_decimal",
]
[[package]]
name = "rustc-hash"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2"
[[package]]
name = "rustc-hex"
version = "2.1.0"
@ -3761,9 +3891,9 @@ dependencies = [
[[package]]
name = "soketto"
version = "0.7.0"
version = "0.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "083624472e8817d44d02c0e55df043737ff11f279af924abdf93845717c2b75c"
checksum = "41d1c5305e39e09653383c2c7244f2f78b3bcae37cf50c64cb4789c9f5096ec2"
dependencies = [
"base64 0.13.1",
"bytes",
@ -4021,6 +4151,7 @@ dependencies = [
"hex",
"hyper",
"itertools",
"jsonrpsee",
"libp2p",
"monero",
"monero-harness",
@ -4374,6 +4505,7 @@ checksum = "cc463cd8deddc3770d20f9852143d50bf6094e640b485cb2e189a2099085ff45"
dependencies = [
"bytes",
"futures-core",
"futures-io",
"futures-sink",
"pin-project-lite 0.2.9",
"tokio",
@ -4626,6 +4758,15 @@ dependencies = [
"static_assertions",
]
[[package]]
name = "unicase"
version = "2.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "50f37be617794602aabbeee0be4f259dc1778fabe05e2d67ee8f79326d5cb4f6"
dependencies = [
"version_check",
]
[[package]]
name = "unicode-bidi"
version = "0.3.4"

View File

@ -31,6 +31,7 @@ ed25519-dalek = "1"
futures = { version = "0.3", default-features = false }
hex = "0.4"
itertools = "0.10"
jsonrpsee = { version = "0.15.1", features = [ "server"] }
libp2p = { version = "0.42.2", default-features = false, features = [ "tcp-tokio", "yamux", "mplex", "dns-tokio", "noise", "request-response", "websocket", "ping", "rendezvous", "identify" ] }
monero = { version = "0.12", features = [ "serde_support" ] }
monero-rpc = { path = "../monero-rpc" }

View File

@ -14,6 +14,7 @@
use anyhow::{bail, Context, Result};
use comfy_table::Table;
use jsonrpsee::http_server::{HttpServerHandle};
use qrcode::render::unicode;
use qrcode::QrCode;
use std::cmp::min;
@ -23,6 +24,7 @@ use std::future::Future;
use std::path::PathBuf;
use std::sync::Arc;
use std::time::Duration;
use std::net::SocketAddr;
use swap::bitcoin::TxLock;
use swap::cli::command::{parse_args_and_apply_defaults, Arguments, Command, ParseResult};
use swap::cli::{list_sellers, EventLoop, SellerStatus};
@ -35,6 +37,7 @@ use swap::network::swarm;
use swap::protocol::bob;
use swap::protocol::bob::{BobState, Swap};
use swap::seed::Seed;
use swap::rpc;
use swap::{bitcoin, cli, monero};
use url::Url;
use uuid::Uuid;
@ -254,6 +257,15 @@ async fn main() -> Result<()> {
"Checked Bitcoin balance",
);
}
Command::StartDaemon {
server_address,
} => {
let handle = rpc::run_server(server_address).await?;
loop {
}
},
Command::Resume {
swap_id,
bitcoin_electrum_rpc_url,
@ -516,6 +528,7 @@ async fn main() -> Result<()> {
Ok(())
}
async fn init_bitcoin_wallet(
electrum_rpc_url: Url,
seed: &Seed,

View File

@ -13,6 +13,7 @@ use std::str::FromStr;
use structopt::{clap, StructOpt};
use url::Url;
use uuid::Uuid;
use std::net::SocketAddr;
// See: https://moneroworld.com/
pub const DEFAULT_MONERO_DAEMON_ADDRESS: &str = "node.community.rino.io:18081";
@ -138,6 +139,21 @@ where
},
}
}
RawCommand::StartDaemon {
server_address,
} => {
let server_address = "127.0.0.1:1234".parse()?;
Arguments {
env_config: env_config_from(is_testnet),
debug,
json,
data_dir: data::data_dir_from(data, is_testnet)?,
cmd: Command::StartDaemon {
server_address,
},
}
}
RawCommand::WithdrawBtc {
bitcoin,
amount,
@ -250,7 +266,7 @@ where
bitcoin_target_block,
},
}
}
},
RawCommand::MoneroRecovery { swap_id } => Arguments {
env_config: env_config_from(is_testnet),
debug,
@ -289,6 +305,10 @@ pub enum Command {
bitcoin_electrum_rpc_url: Url,
bitcoin_target_block: usize,
},
StartDaemon {
server_address: SocketAddr,
},
Resume {
swap_id: Uuid,
bitcoin_electrum_rpc_url: Url,
@ -408,6 +428,10 @@ enum RawCommand {
#[structopt(long = "electrum-rpc", help = "Provide the Bitcoin Electrum RPC URL")]
bitcoin_electrum_rpc_url: Option<Url>,
},
#[structopt(about="Starts a JSON-RPC server")]
StartDaemon {
server_address: Option<SocketAddr>,
},
/// Resume a swap
Resume {
#[structopt(flatten)]

View File

@ -28,6 +28,7 @@ pub mod libp2p_ext;
pub mod monero;
pub mod network;
pub mod protocol;
pub mod rpc;
pub mod seed;
pub mod tor;
pub mod tracing_ext;