Skip to content

Commit

Permalink
Offer Reject will currently fail without Trade Engine Specifics. Auto…
Browse files Browse the repository at this point in the history
…matically place in a placeholder in that case
  • Loading branch information
nobu-maeda committed Jan 2, 2024
1 parent 9ab9511 commit bcd694a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
10 changes: 10 additions & 0 deletions src/common/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,16 @@ impl dyn SerdeGenericTrait {
}
}

#[derive(Clone, Debug, Serialize, Deserialize)]
pub(crate) struct SerdeGenericsPlaceholder {}

#[typetag::serde(name = "n3xB-placeholder")]
impl SerdeGenericTrait for SerdeGenericsPlaceholder {
fn any_ref(&self) -> &dyn Any {
self
}
}

#[derive(
Serialize, Deserialize, PartialEq, Eq, Hash, Clone, Debug, EnumString, Display, IntoStaticStr,
)]
Expand Down
19 changes: 12 additions & 7 deletions src/trade_rsp/builder.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::common::{
error::{N3xbError, OfferInvalidReason},
types::{EventIdString, SerdeGenericTrait},
types::{EventIdString, SerdeGenericTrait, SerdeGenericsPlaceholder},
};

use super::{TradeResponse, TradeResponseStatus};
Expand Down Expand Up @@ -47,11 +47,13 @@ impl TradeResponseBuilder {

pub fn build(&self) -> Result<TradeResponse, N3xbError> {
let Some(offer_event_id) = self.offer_event_id.as_ref() else {
return Err(N3xbError::Simple("No Offer Event ID defined".to_string())); // TODO: Error handling?
return Err(N3xbError::Simple("No Offer Event ID defined".to_string()));
// TODO: Error handling?
};

let Some(trade_response) = self.trade_response.as_ref() else {
return Err(N3xbError::Simple("No Trade Response defined".to_string())); // TODO: Error handling?
return Err(N3xbError::Simple("No Trade Response defined".to_string()));
// TODO: Error handling?
};

let trade_response = trade_response.to_owned();
Expand All @@ -60,15 +62,18 @@ impl TradeResponseBuilder {
// TODO: Error handling?
}

let Some(trade_engine_specifics) = self.trade_engine_specifics.as_ref() else {
return Err(N3xbError::Simple("No Trade Engine Specifics defined".to_string()));
};
let trade_engine_specifics =
if let Some(trade_engine_specifics) = self.trade_engine_specifics.as_ref() {
trade_engine_specifics.to_owned()
} else {
Box::new(SerdeGenericsPlaceholder {})
};

let trade_rsp = TradeResponse {
offer_event_id: offer_event_id.to_owned(),
trade_response: trade_response,
reject_reason: self.reject_reason.to_owned(),
trade_engine_specifics: trade_engine_specifics.to_owned(),
trade_engine_specifics: trade_engine_specifics,
};

Ok(trade_rsp)
Expand Down

0 comments on commit bcd694a

Please sign in to comment.