use nym_mixnet_contract_common::{GatewayBond, MixNodeDetails, NodeId};
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use utoipa::ToSchema;
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema, ToSchema)]
pub struct LegacyGatewayBondWithId {
#[serde(flatten)]
pub bond: GatewayBond,
pub node_id: NodeId,
}
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema, ToSchema)]
pub struct LegacyMixnodesResponse {
pub count: usize,
pub nodes: Vec<MixNodeDetails>,
}
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema, ToSchema)]
pub struct LegacyGatewaysResponse {
pub count: usize,
pub nodes: Vec<LegacyGatewayBondWithId>,
}
#[cfg(test)]
mod tests {
use super::*;
use cosmwasm_std::{coin, Addr};
use nym_mixnet_contract_common::Gateway;
#[test]
fn gateway_bond_with_id_serialises_flat() {
let with_id = LegacyGatewayBondWithId {
bond: GatewayBond::new(
coin(100_000_000, "unym"),
Addr::unchecked("n1owner"),
1234,
Gateway {
host: "1.1.1.1".to_string(),
mix_port: 1789,
clients_port: 9000,
location: "GB".to_string(),
sphinx_key: "sphinx".to_string(),
identity_key: "identity".to_string(),
version: "1.1.5".to_string(),
},
),
node_id: 42,
};
let json = serde_json::to_value(&with_id).unwrap();
assert_eq!(json["node_id"], 42);
assert!(
json.get("bond").is_none(),
"the bond must stay flattened, got: {json}"
);
assert_eq!(json["block_height"], 1234);
assert_eq!(json["owner"], "n1owner");
assert_eq!(json["pledge_amount"]["denom"], "unym");
assert_eq!(json["gateway"]["identity_key"], "identity");
}
}