Skip to content

Commit

Permalink
fix: activation scheme structure presumably was changed, not it do no…
Browse files Browse the repository at this point in the history
…t comply to mm2 - fixed
  • Loading branch information
rozhkovdmitrii committed Jul 19, 2023
1 parent 4ea7e31 commit 2421046
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
23 changes: 20 additions & 3 deletions mm2src/adex_cli/src/rpc_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
//!

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

#[derive(Debug, Deserialize, Serialize)]
#[serde(tag = "method", rename_all = "lowercase")]
Expand All @@ -16,8 +17,8 @@ pub(crate) enum ActivationRequest {
#[derive(Debug, Deserialize, Serialize)]
pub(crate) struct EnableRequest {
coin: String,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
urls: Vec<String>,
#[serde(default, serialize_with = "serialize_urls", skip_serializing_if = "Vec::is_empty")]
urls: Vec<EnableUrl>,
#[serde(skip_serializing_if = "Option::is_none")]
swap_contract_address: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
Expand All @@ -40,6 +41,22 @@ pub(crate) struct EnableRequest {
contract_supports_watchers: Option<bool>,
}

fn serialize_urls<S>(urls: &Vec<EnableUrl>, s: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
let mut s_seq = s.serialize_seq(None)?;
for url in urls {
s_seq.serialize_element(url.url.as_str())?;
}
s_seq.end()
}

#[derive(Debug, Deserialize)]
struct EnableUrl {
url: String,
}

#[derive(Debug, Deserialize, Serialize)]
pub(crate) struct ElectrumRequest {
coin: String,
Expand Down
2 changes: 1 addition & 1 deletion mm2src/adex_cli/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ async fn test_activation_scheme() {
let scheme = get_activation_scheme().unwrap();
let kmd_scheme = scheme.get_activation_method("KMD");
let Ok(ActivationRequest::Electrum(electrum)) = kmd_scheme else {
panic!("Failed to get electrum scheme")
panic!("Failed to get electrum scheme")
};
assert_ne!(electrum.servers.len(), 0);
}
Expand Down

0 comments on commit 2421046

Please sign in to comment.