pub struct MessageKind {
pub version: u8,
pub request_id: Option<u64>,
pub trade_index: Option<i64>,
pub id: Option<Uuid>,
pub action: Action,
pub payload: Option<Payload>,
}Expand description
Fields§
§version: u8Mostro protocol version. Set to
PROTOCOL_VER by MessageKind::new.
request_id: Option<u64>Client-chosen correlation id, echoed back on responses so the client can match them to in-flight requests.
trade_index: Option<i64>Trade index attached to this message. Must be strictly greater than the last trade index Mostro has seen for the sender.
id: Option<Uuid>Optional target identifier (usually the id of an crate::order::Order
or crate::dispute::Dispute).
action: ActionVerb of the message.
payload: Option<Payload>Payload attached to the action. The allowed shape for a given action
is enforced by MessageKind::verify.
Implementations§
Source§impl MessageKind
impl MessageKind
Sourcepub fn new(
id: Option<Uuid>,
request_id: Option<u64>,
trade_index: Option<i64>,
action: Action,
payload: Option<Payload>,
) -> Self
pub fn new( id: Option<Uuid>, request_id: Option<u64>, trade_index: Option<i64>, action: Action, payload: Option<Payload>, ) -> Self
Build a new MessageKind stamped with the current protocol
version (PROTOCOL_VER).
Sourcepub fn from_json(json: &str) -> Result<Self, ServiceError>
pub fn from_json(json: &str) -> Result<Self, ServiceError>
Parse a MessageKind from its JSON representation.
Sourcepub fn as_json(&self) -> Result<String, ServiceError>
pub fn as_json(&self) -> Result<String, ServiceError>
Serialize the MessageKind to a JSON string.
Sourcepub fn get_action(&self) -> Action
pub fn get_action(&self) -> Action
Return a clone of the Action carried by this message.
Sourcepub fn get_next_trade_key(&self) -> Result<Option<(String, u32)>, ServiceError>
pub fn get_next_trade_key(&self) -> Result<Option<(String, u32)>, ServiceError>
Extract the (next_trade_pubkey, next_trade_index) pair from a
Payload::NextTrade payload.
Returns Ok(None) when there is no payload at all and
ServiceError::InvalidPayload when the payload is present but of
a different variant.
Sourcepub fn get_rating(&self) -> Result<u8, ServiceError>
pub fn get_rating(&self) -> Result<u8, ServiceError>
Extract the rating value from a Payload::RatingUser payload,
validating it against
MIN_RATING..=MAX_RATING.
Returns ServiceError::InvalidRating when the payload shape is
wrong and ServiceError::InvalidRatingValue when the value is out
of range.
Sourcepub fn verify(&self) -> bool
pub fn verify(&self) -> bool
Check that the payload, id and trade index are consistent with the action carried by this message.
Returns true when the combination is well-formed and false
otherwise; Mostro uses this method to reject malformed requests
before processing them.
Sourcepub fn get_order(&self) -> Option<&SmallOrder>
pub fn get_order(&self) -> Option<&SmallOrder>
Return the SmallOrder carried by a Action::NewOrder message.
Yields None if the action is not NewOrder or the payload is of a
different variant.
Sourcepub fn get_payment_request(&self) -> Option<String>
pub fn get_payment_request(&self) -> Option<String>
Return the Lightning payment request embedded in a message.
Valid only for Action::TakeSell, Action::AddInvoice and
Action::NewOrder. For NewOrder, the invoice is read from the
SmallOrder::buyer_invoice field. Returns None otherwise.
Sourcepub fn get_amount(&self) -> Option<i64>
pub fn get_amount(&self) -> Option<i64>
Return the amount override embedded in a Action::TakeSell or
Action::TakeBuy message, either from a Payload::Amount or
from the third element of a Payload::PaymentRequest.
Sourcepub fn get_payload(&self) -> Option<&Payload>
pub fn get_payload(&self) -> Option<&Payload>
Borrow the optional payload.
Sourcepub fn has_trade_index(&self) -> (bool, i64)
pub fn has_trade_index(&self) -> (bool, i64)
Return (true, index) when the message carries a trade index,
(false, 0) otherwise.
Sourcepub fn trade_index(&self) -> i64
pub fn trade_index(&self) -> i64
Return the trade index carried by the message, or 0 when absent.
Trait Implementations§
Source§impl Clone for MessageKind
impl Clone for MessageKind
Source§fn clone(&self) -> MessageKind
fn clone(&self) -> MessageKind
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for MessageKind
impl Debug for MessageKind
Source§impl<'de> Deserialize<'de> for MessageKind
impl<'de> Deserialize<'de> for MessageKind
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Auto Trait Implementations§
impl Freeze for MessageKind
impl RefUnwindSafe for MessageKind
impl Send for MessageKind
impl Sync for MessageKind
impl Unpin for MessageKind
impl UnsafeUnpin for MessageKind
impl UnwindSafe for MessageKind
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more