Skip to content

Commit

Permalink
refactor: redistribute legacy datatypes
Browse files Browse the repository at this point in the history
  • Loading branch information
rozhkovdmitrii committed Jul 17, 2023
1 parent b45e9d2 commit 92a429c
Show file tree
Hide file tree
Showing 10 changed files with 396 additions and 373 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ use serde_json::Value as Json;
use std::collections::HashMap;

use common::log::{debug, error};
use mm2_rpc::data::legacy::ActivationRequest;

use super::init_activation_scheme::get_activation_scheme_path;
use crate::helpers::read_json_file;
use crate::logging::{error_anyhow, error_bail};
use crate::rpc_data::ActivationRequest;

#[derive(Default)]
pub(crate) struct ActivationScheme {
Expand Down
1 change: 1 addition & 0 deletions mm2src/adex_cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#[cfg(not(target_arch = "wasm32"))] mod cli;
#[cfg(not(target_arch = "wasm32"))] mod helpers;
mod logging;
#[cfg(not(target_arch = "wasm32"))] mod rpc_data;
#[cfg(not(target_arch = "wasm32"))] mod scenarios;
#[cfg(all(not(target_arch = "wasm32"), test))] mod tests;
#[cfg(not(target_arch = "wasm32"))] mod transport;
Expand Down
71 changes: 71 additions & 0 deletions mm2src/adex_cli/src/rpc_data.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
//! Contains rpc data layer structures that are not ready to become a part of the mm2_rpc::data module
//!
//! *Note: it's expected that the following data types will be moved to mm2_rpc::data when mm2 is refactored to be able to handle them*
//!

use mm2_rpc::data::legacy::{ElectrumProtocol, GasStationPricePolicy, UtxoMergeParams};
use serde::{Deserialize, Serialize};

#[derive(Debug, Deserialize, Serialize)]
#[serde(tag = "method", rename_all = "lowercase")]
pub(crate) enum ActivationRequest {
Enable(EnableRequest),
Electrum(ElectrumRequest),
}

#[derive(Debug, Deserialize, Serialize)]
pub(crate) struct EnableRequest {
coin: String,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
urls: Vec<String>,
#[serde(skip_serializing_if = "Option::is_none")]
swap_contract_address: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
fallback_swap_contract: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
gas_station_url: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
gas_station_decimals: Option<u8>,
#[serde(skip_serializing_if = "Option::is_none")]
gas_station_policy: Option<GasStationPricePolicy>,
#[serde(skip_serializing_if = "Option::is_none")]
mm2: Option<u8>,
#[serde(default)]
tx_history: bool,
#[serde(skip_serializing_if = "Option::is_none")]
required_confirmations: Option<u64>,
#[serde(skip_serializing_if = "Option::is_none")]
requires_notarization: Option<bool>,
#[serde(default)]
contract_supports_watchers: Option<bool>,
}

#[derive(Debug, Deserialize, Serialize)]
pub(crate) struct ElectrumRequest {
coin: String,
#[serde(skip_serializing_if = "Vec::is_empty")]
servers: Vec<Server>,
#[serde(skip_serializing_if = "Option::is_none")]
mm2: Option<u8>,
#[serde(default)]
tx_history: bool,
#[serde(skip_serializing_if = "Option::is_none")]
required_confirmations: Option<u64>,
#[serde(default)]
requires_notarization: bool,
#[serde(skip_serializing_if = "Option::is_none")]
swap_contract_address: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
fallback_swap_contract: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
utxo_merge_params: Option<UtxoMergeParams>,
}

#[derive(Debug, Deserialize, Serialize)]
struct Server {
url: String,
#[serde(default)]
protocol: ElectrumProtocol,
#[serde(default)]
disable_cert_verification: bool,
}
25 changes: 1 addition & 24 deletions mm2src/coins/utxo/rpc_clients.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ use keys::hash::H256;
use keys::{Address, Type as ScriptType};
use mm2_err_handle::prelude::*;
use mm2_number::{BigDecimal, BigInt, MmNumber};
use mm2_rpc::data::legacy::ElectrumProtocol;
#[cfg(test)] use mocktopus::macros::*;
use rpc::v1::types::{Bytes as BytesJson, Transaction as RpcTransaction, H256 as H256Json};
use serde_json::{self as json, Value as Json};
Expand Down Expand Up @@ -1384,30 +1385,6 @@ pub fn electrum_script_hash(script: &[u8]) -> Vec<u8> {
result
}

#[allow(clippy::upper_case_acronyms)]
#[derive(Clone, Debug, Deserialize, Serialize)]
/// Deserializable Electrum protocol representation for RPC
pub enum ElectrumProtocol {
/// TCP
TCP,
/// SSL/TLS
SSL,
/// Insecure WebSocket.
WS,
/// Secure WebSocket.
WSS,
}

#[cfg(not(target_arch = "wasm32"))]
impl Default for ElectrumProtocol {
fn default() -> Self { ElectrumProtocol::TCP }
}

#[cfg(target_arch = "wasm32")]
impl Default for ElectrumProtocol {
fn default() -> Self { ElectrumProtocol::WS }
}

#[derive(Debug, Deserialize, Serialize)]
/// Deserializable Electrum protocol version representation for RPC
/// https://electrumx-spesmilo.readthedocs.io/en/latest/protocol-methods.html#server.version
Expand Down
Loading

0 comments on commit 92a429c

Please sign in to comment.