|
| 1 | +//! Swift order subscriber and serialization utilities |
1 | 2 | use std::time::{SystemTime, UNIX_EPOCH}; |
2 | 3 |
|
3 | 4 | use anchor_lang::{AnchorDeserialize, AnchorSerialize, Space}; |
@@ -59,6 +60,13 @@ pub enum SignedOrderType { |
59 | 60 | } |
60 | 61 |
|
61 | 62 | impl SignedOrderType { |
| 63 | + /// Return the original, hexified message |
| 64 | + pub fn raw(&self) -> &Option<String> { |
| 65 | + match self { |
| 66 | + Self::Authority { inner: _, ref raw } => raw, |
| 67 | + Self::Delegated { inner: _, ref raw } => raw, |
| 68 | + } |
| 69 | + } |
62 | 70 | pub fn delegated(order: SignedDelegateOrder) -> Self { |
63 | 71 | Self::Delegated { |
64 | 72 | inner: order, |
@@ -102,7 +110,7 @@ impl SignedOrderType { |
102 | 110 |
|
103 | 111 | buf |
104 | 112 | } |
105 | | - |
| 113 | + /// Returns order details |
106 | 114 | pub fn info(&self, taker_authority: &Pubkey) -> SignedMessageInfo { |
107 | 115 | match self { |
108 | 116 | Self::Authority { inner, .. } => SignedMessageInfo { |
@@ -131,6 +139,7 @@ struct OrderNotification<'a> { |
131 | 139 | } |
132 | 140 |
|
133 | 141 | /// Error notification from Websocket |
| 142 | +#[allow(unused)] |
134 | 143 | #[derive(Clone, Debug, Deserialize)] |
135 | 144 | struct ErrorNotification<'a> { |
136 | 145 | channel: &'a str, |
@@ -575,18 +584,17 @@ pub fn deser_signed_msg_type<'de, D>(deserializer: D) -> Result<SignedOrderType, |
575 | 584 | where |
576 | 585 | D: serde::Deserializer<'de>, |
577 | 586 | { |
578 | | - let payload: &str = serde::Deserialize::deserialize(deserializer)?; |
| 587 | + let payload: std::borrow::Cow<String> = serde::Deserialize::deserialize(deserializer)?; |
579 | 588 | if payload.len() % 2 != 0 { |
580 | 589 | return Err(serde::de::Error::custom("Hex string length must be even")); |
581 | 590 | } |
582 | | - |
583 | | - // decode expecting the largest possible variant |
584 | | - if (payload.len() / 2) > SignedDelegateOrder::INIT_SPACE + 8 || payload.is_empty() { |
| 591 | + if payload.is_empty() { |
585 | 592 | return Err(serde::de::Error::custom("invalid signed message hex")); |
586 | 593 | } |
587 | 594 |
|
| 595 | + // decode expecting the largest possible variant |
588 | 596 | let mut borsh_buf = [0u8; SignedDelegateOrder::INIT_SPACE + 8]; |
589 | | - hex::decode_to_slice(payload, &mut borsh_buf[..payload.len() / 2]) |
| 597 | + hex::decode_to_slice(payload.as_bytes(), &mut borsh_buf[..payload.len() / 2]) |
590 | 598 | .map_err(serde::de::Error::custom)?; |
591 | 599 |
|
592 | 600 | // this is basically the same as if we derived AnchorDeserialize on `SignedOrderType` _expect_ it does not |
|
0 commit comments