pub struct Order {Show 43 fields
pub id: Uuid,
pub kind: String,
pub event_id: String,
pub hash: Option<String>,
pub preimage: Option<String>,
pub creator_pubkey: String,
pub cancel_initiator_pubkey: Option<String>,
pub buyer_pubkey: Option<String>,
pub master_buyer_pubkey: Option<String>,
pub seller_pubkey: Option<String>,
pub master_seller_pubkey: Option<String>,
pub status: String,
pub price_from_api: bool,
pub premium: i64,
pub payment_method: String,
pub amount: i64,
pub min_amount: Option<i64>,
pub max_amount: Option<i64>,
pub buyer_dispute: bool,
pub seller_dispute: bool,
pub buyer_cooperativecancel: bool,
pub seller_cooperativecancel: bool,
pub fee: i64,
pub routing_fee: i64,
pub dev_fee: i64,
pub dev_fee_paid: bool,
pub dev_fee_payment_hash: Option<String>,
pub fiat_code: String,
pub fiat_amount: i64,
pub buyer_invoice: Option<String>,
pub range_parent_id: Option<Uuid>,
pub invoice_held_at: i64,
pub taken_at: i64,
pub created_at: i64,
pub buyer_sent_rate: bool,
pub seller_sent_rate: bool,
pub failed_payment: bool,
pub payment_attempts: i64,
pub expires_at: i64,
pub trade_index_seller: Option<i64>,
pub trade_index_buyer: Option<i64>,
pub next_trade_pubkey: Option<String>,
pub next_trade_index: Option<i64>,
}Expand description
Persistent representation of a Mostro order.
This is the canonical on-disk record kept by a Mostro node. All fields
are stored so an order can be recomputed / restarted from its row alone;
clients usually work with the lighter SmallOrder view.
Timestamps are Unix seconds; hash / preimage refer to the hold
invoice used to lock the seller’s funds.
Fields§
§id: UuidUnique order identifier.
kind: StringOrder kind (Kind::Buy or Kind::Sell), serialized as
kebab-case.
event_id: StringNostr event id of the order publication.
hash: Option<String>Payment hash of the seller’s hold invoice, once generated.
preimage: Option<String>Preimage revealed when the hold invoice is settled.
creator_pubkey: StringTrade public key of the order creator (maker).
cancel_initiator_pubkey: Option<String>Trade public key of the party who initiated a cancel, if any.
buyer_pubkey: Option<String>Buyer trade public key.
master_buyer_pubkey: Option<String>Buyer master identity pubkey. Equal to buyer_pubkey when the
buyer operates in full-privacy mode.
seller_pubkey: Option<String>Seller trade public key.
master_seller_pubkey: Option<String>Seller master identity pubkey. Equal to seller_pubkey when the
seller operates in full-privacy mode.
status: StringCurrent Status of the order, serialized as kebab-case.
price_from_api: booltrue if the sats amount was computed from a live market price.
Premium percentage applied on top of the spot price.
payment_method: StringFree-form payment method description (e.g. “SEPA,Bank transfer”).
amount: i64Sats amount. 0 means the amount is computed at take-time from the
fiat amount and the current market price.
min_amount: Option<i64>Lower bound of a range order (fiat amount). None for fixed orders.
max_amount: Option<i64>Upper bound of a range order (fiat amount). None for fixed orders.
buyer_dispute: booltrue when the buyer has initiated a dispute on this order.
seller_dispute: booltrue when the seller has initiated a dispute on this order.
buyer_cooperativecancel: booltrue when the buyer has initiated a cooperative cancel.
seller_cooperativecancel: booltrue when the seller has initiated a cooperative cancel.
fee: i64Mostro fee charged for this trade, in sats.
routing_fee: i64Lightning routing fee observed when paying the buyer.
dev_fee: i64Optional developer-fee portion of fee.
dev_fee_paid: booltrue once the developer fee has been paid out.
dev_fee_payment_hash: Option<String>Payment hash of the developer-fee payment, when available.
fiat_code: StringFiat currency code (e.g. “EUR”, “USD”).
fiat_amount: i64Fiat amount of the trade.
buyer_invoice: Option<String>Buyer’s Lightning payout invoice, once provided.
range_parent_id: Option<Uuid>Parent order id for orders derived from a range parent.
invoice_held_at: i64Unix timestamp (seconds) when the hold invoice was locked in.
taken_at: i64Unix timestamp (seconds) when the order was taken.
created_at: i64Unix timestamp (seconds) when the order was created.
buyer_sent_rate: booltrue once the buyer has rated the counterpart.
seller_sent_rate: booltrue once the seller has rated the counterpart.
failed_payment: booltrue if the latest payment attempt to the buyer failed.
payment_attempts: i64Number of payment attempts performed so far.
expires_at: i64Unix timestamp (seconds) when the order expires automatically.
trade_index_seller: Option<i64>Trade index used by the seller when creating / taking the order.
trade_index_buyer: Option<i64>Trade index used by the buyer when creating / taking the order.
next_trade_pubkey: Option<String>Trade public key announced by a range-order maker for the next trade in the same range.
next_trade_index: Option<i64>Trade index announced by a range-order maker for the next trade.
Implementations§
Source§impl Order
impl Order
Sourcepub fn as_new_order(&self) -> SmallOrder
pub fn as_new_order(&self) -> SmallOrder
Build a SmallOrder suitable for broadcasting as a new order event.
Copies the tradable fields (amounts, payment method, premium, etc.)
from self. Trade pubkeys are left unset because a new order is
published before a counterpart is assigned.
Sourcepub fn get_order_kind(&self) -> Result<Kind, ServiceError>
pub fn get_order_kind(&self) -> Result<Kind, ServiceError>
Parse the order kind from the string-encoded field.
Returns ServiceError::InvalidOrderKind when self.kind does not
match a known Kind variant.
Sourcepub fn get_order_status(&self) -> Result<Status, ServiceError>
pub fn get_order_status(&self) -> Result<Status, ServiceError>
Parse the order status from the string-encoded field.
Returns ServiceError::InvalidOrderStatus when self.status does
not match a known Status variant.
Sourcepub fn check_status(&self, status: Status) -> Result<(), CantDoReason>
pub fn check_status(&self, status: Status) -> Result<(), CantDoReason>
Check that the order is currently in a specific Status.
Returns Ok(()) on match and CantDoReason::InvalidOrderStatus
either on mismatch or when the stored status cannot be parsed.
Sourcepub fn is_buy_order(&self) -> Result<(), CantDoReason>
pub fn is_buy_order(&self) -> Result<(), CantDoReason>
Assert that the order is a Kind::Buy order.
Sourcepub fn is_sell_order(&self) -> Result<(), CantDoReason>
pub fn is_sell_order(&self) -> Result<(), CantDoReason>
Assert that the order is a Kind::Sell order.
Sourcepub fn sent_from_maker(&self, sender: PublicKey) -> Result<(), CantDoReason>
pub fn sent_from_maker(&self, sender: PublicKey) -> Result<(), CantDoReason>
Assert that sender is the maker (creator) of the order.
Returns CantDoReason::InvalidPubkey when the pubkeys differ.
Sourcepub fn not_sent_from_maker(&self, sender: PublicKey) -> Result<(), CantDoReason>
pub fn not_sent_from_maker(&self, sender: PublicKey) -> Result<(), CantDoReason>
Assert that sender is not the maker of the order.
Returns CantDoReason::InvalidPubkey when sender matches
self.creator_pubkey.
Sourcepub fn get_creator_pubkey(&self) -> Result<PublicKey, ServiceError>
pub fn get_creator_pubkey(&self) -> Result<PublicKey, ServiceError>
Parse the maker’s public key as a Nostr PublicKey.
Sourcepub fn get_buyer_pubkey(&self) -> Result<PublicKey, ServiceError>
pub fn get_buyer_pubkey(&self) -> Result<PublicKey, ServiceError>
Parse the buyer trade public key.
Returns ServiceError::InvalidPubkey when the field is absent or
cannot be parsed.
Sourcepub fn get_seller_pubkey(&self) -> Result<PublicKey, ServiceError>
pub fn get_seller_pubkey(&self) -> Result<PublicKey, ServiceError>
Parse the seller trade public key.
Returns ServiceError::InvalidPubkey when the field is absent or
cannot be parsed.
Sourcepub fn get_master_buyer_pubkey(&self) -> Result<PublicKey, ServiceError>
pub fn get_master_buyer_pubkey(&self) -> Result<PublicKey, ServiceError>
Parse the buyer master identity public key.
Sourcepub fn get_master_seller_pubkey(&self) -> Result<PublicKey, ServiceError>
pub fn get_master_seller_pubkey(&self) -> Result<PublicKey, ServiceError>
Parse the seller master identity public key.
Sourcepub fn is_range_order(&self) -> bool
pub fn is_range_order(&self) -> bool
true when both min_amount and max_amount are set, i.e. this is
a range order.
Sourcepub fn count_failed_payment(&mut self, retries_number: i64)
pub fn count_failed_payment(&mut self, retries_number: i64)
Increment the payment-failure counter.
On the first failure, sets Self::failed_payment to true and
Self::payment_attempts to 1. On subsequent failures the counter
is bumped, capped at retries_number.
Sourcepub fn has_no_amount(&self) -> bool
pub fn has_no_amount(&self) -> bool
true when amount == 0, meaning the sats amount is not fixed and
will be computed from the fiat amount and market price.
Sourcepub fn set_timestamp_now(&mut self)
pub fn set_timestamp_now(&mut self)
Set Self::taken_at to the current Unix timestamp.
Sourcepub fn is_full_privacy_order(
&self,
) -> Result<(Option<String>, Option<String>), ServiceError>
pub fn is_full_privacy_order( &self, ) -> Result<(Option<String>, Option<String>), ServiceError>
Compare the trade pubkeys against the master pubkeys to detect which sides of the trade are operating in full privacy mode.
Returns a (buyer_normal_idkey, seller_normal_idkey) tuple. Each
value is Some(master_pubkey) when that side is running in normal
mode (trade key differs from master key, so the user is willing to
associate the trade with its reputation); None when the side is in
full privacy mode.
Sourcepub fn setup_dispute(
&mut self,
is_buyer_dispute: bool,
) -> Result<(), CantDoReason>
pub fn setup_dispute( &mut self, is_buyer_dispute: bool, ) -> Result<(), CantDoReason>
Mark the order as in dispute and record which side initiated it.
When is_buyer_dispute is true the buyer flag is set, otherwise
the seller flag. The order status is then transitioned to
Status::Dispute. Returns
CantDoReason::DisputeCreationError when the appropriate flag was
already set (avoids registering the same dispute twice).
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Order
impl<'de> Deserialize<'de> for Order
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>,
Source§impl From<Order> for SmallOrder
impl From<Order> for SmallOrder
Source§impl From<SmallOrder> for Order
impl From<SmallOrder> for Order
Source§fn from(small_order: SmallOrder) -> Self
fn from(small_order: SmallOrder) -> Self
Auto Trait Implementations§
impl Freeze for Order
impl RefUnwindSafe for Order
impl Send for Order
impl Sync for Order
impl Unpin for Order
impl UnsafeUnpin for Order
impl UnwindSafe for Order
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