refactor(cli): Refactor RPC server and fix tests

- Use the Request trait introduced in https://github.com/UnstoppableSwap/xmr-btc-swap/pull/10 for the RPC server
- Delegate deserialization of RPC server method parameters to serde by using structs like BuyXmrArgs
- Remove `get_raw_states` RPC server method because it's not used
- Fix RPC server tests including removing test for the "log reference id" feature which was removed as part of https://github.com/UnstoppableSwap/xmr-btc-swap/pull/10
- Rename GetCurrentSwap struct to GetCurrentSwapArgs
This commit is contained in:
binarybaron 2024-08-27 20:36:20 +02:00
parent ca25e0454f
commit 57c153de99
No known key found for this signature in database
GPG key ID: 99B75D3E1476A26E
7 changed files with 97 additions and 288 deletions

View file

@ -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> {
@ -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();
@ -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,
},
);
}