Skip to content

Commit

Permalink
Merge pull request #36 from UnstoppableSwap/fix-rpc-tests
Browse files Browse the repository at this point in the history
refactor(cli): Refactor RPC server and fix tests
  • Loading branch information
binarybaron authored Aug 28, 2024
2 parents ca25e04 + 66d1e7d commit aac366f
Show file tree
Hide file tree
Showing 10 changed files with 111 additions and 339 deletions.
53 changes: 8 additions & 45 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion monero-harness/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ rand = "0.7"
testcontainers = "0.15"
tokio = { version = "1", default-features = false, features = [ "rt-multi-thread", "time", "macros" ] }
tracing = "0.1"
tracing-subscriber = { version = "0.2", default-features = false, features = [ "fmt", "ansi", "env-filter", "tracing-log" ] }
tracing-subscriber = { version = "0.3", default-features = false, features = [ "fmt", "ansi", "env-filter", "tracing-log" ] }
2 changes: 1 addition & 1 deletion monero-wallet/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ monero-harness = { path = "../monero-harness" }
rand = "0.7"
testcontainers = "0.15"
tokio = { version = "1", features = [ "rt-multi-thread", "time", "macros", "sync", "process", "fs" ] }
tracing-subscriber = { version = "0.2", default-features = false, features = [ "fmt", "ansi", "env-filter", "chrono", "tracing-log" ] }
tracing-subscriber = { version = "0.3", default-features = false, features = [ "fmt", "ansi", "env-filter", "chrono", "tracing-log" ] }
24 changes: 0 additions & 24 deletions swap/sqlx-data.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,30 +80,6 @@
},
"query": "\n insert into peers (\n swap_id,\n peer_id\n ) values (?, ?);\n "
},
"3f2bfdd2d134586ccad22171cd85a465800fc5c4fdaf191d206974e530240c87": {
"describe": {
"columns": [
{
"name": "swap_id",
"ordinal": 0,
"type_info": "Text"
},
{
"name": "state",
"ordinal": 1,
"type_info": "Text"
}
],
"nullable": [
false,
false
],
"parameters": {
"Right": 0
}
},
"query": "\n SELECT swap_id, state\n FROM swap_states\n "
},
"50a5764546f69c118fa0b64120da50f51073d36257d49768de99ff863e3511e0": {
"describe": {
"columns": [],
Expand Down
1 change: 0 additions & 1 deletion swap/src/cli/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,6 @@ pub mod api_test {
Self {
tor_socks5_port: 9050,
namespace: XmrBtcNamespace::from_is_testnet(is_testnet),
server_address: None,
env_config,
seed: Some(seed),
debug,
Expand Down
13 changes: 3 additions & 10 deletions swap/src/cli/api/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,9 +304,9 @@ impl Request for SuspendCurrentSwapArgs {
}
}

pub struct GetCurrentSwap;
pub struct GetCurrentSwapArgs;

impl Request for GetCurrentSwap {
impl Request for GetCurrentSwapArgs {
type Response = serde_json::Value;

async fn request(self, ctx: Arc<Context>) -> Result<Self::Response> {
Expand Down Expand Up @@ -860,13 +860,6 @@ pub async fn get_history(context: Arc<Context>) -> Result<GetHistoryResponse> {
Ok(GetHistoryResponse { swaps: vec })
}

#[tracing::instrument(fields(method = "get_raw_states"), skip(context))]
pub async fn get_raw_states(context: Arc<Context>) -> Result<serde_json::Value> {
let raw_history = context.db.raw_all().await?;

Ok(json!({ "raw_states": raw_history }))
}

#[tracing::instrument(fields(method = "get_config"), skip(context))]
pub async fn get_config(context: Arc<Context>) -> Result<serde_json::Value> {
let data_dir_display = context.config.data_dir.display();
Expand Down Expand Up @@ -1164,7 +1157,7 @@ where
min_deposit_until_swap_will_start,
max_deposit_until_maximum_amount_is_reached,
min_bitcoin_lock_tx_fee,
quote: bid_quote.clone(),
quote: bid_quote,
},
);
}
Expand Down
31 changes: 0 additions & 31 deletions swap/src/database/sqlite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use async_trait::async_trait;
use libp2p::{Multiaddr, PeerId};
use sqlx::sqlite::Sqlite;
use sqlx::{Pool, SqlitePool};
use std::collections::HashMap;
use std::path::Path;
use std::str::FromStr;
use time::OffsetDateTime;
Expand Down Expand Up @@ -352,36 +351,6 @@ impl Database for SqliteDatabase {

Ok(Some(proof))
}

async fn raw_all(&self) -> Result<HashMap<Uuid, Vec<serde_json::Value>>> {
let mut conn = self.pool.acquire().await?;
let rows = sqlx::query!(
r#"
SELECT swap_id, state
FROM swap_states
"#
)
.fetch_all(&mut conn)
.await?;

let mut swaps: HashMap<Uuid, Vec<serde_json::Value>> = HashMap::new();

for row in &rows {
let swap_id = Uuid::from_str(&row.swap_id)?;
let state = serde_json::from_str(&row.state)?;

if let std::collections::hash_map::Entry::Vacant(e) = swaps.entry(swap_id) {
e.insert(vec![state]);
} else {
swaps
.get_mut(&swap_id)
.ok_or_else(|| anyhow!("Error while retrieving the swap"))?
.push(state);
}
}

Ok(swaps)
}
}

#[cfg(test)]
Expand Down
2 changes: 0 additions & 2 deletions swap/src/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ use serde::{Deserialize, Serialize};
use sha2::Sha256;
use sigma_fun::ext::dl_secp256k1_ed25519_eq::{CrossCurveDLEQ, CrossCurveDLEQProof};
use sigma_fun::HashTranscript;
use std::collections::HashMap;
use std::convert::TryInto;
use uuid::Uuid;

Expand Down Expand Up @@ -145,7 +144,6 @@ pub trait Database {
async fn get_state(&self, swap_id: Uuid) -> Result<State>;
async fn get_states(&self, swap_id: Uuid) -> Result<Vec<State>>;
async fn all(&self) -> Result<Vec<(Uuid, State)>>;
async fn raw_all(&self) -> Result<HashMap<Uuid, Vec<serde_json::Value>>>;
async fn insert_buffered_transfer_proof(
&self,
swap_id: Uuid,
Expand Down
Loading

0 comments on commit aac366f

Please sign in to comment.