Skip to main content

Order

Struct Order 

Source
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: Uuid

Unique order identifier.

§kind: String

Order kind (Kind::Buy or Kind::Sell), serialized as kebab-case.

§event_id: String

Nostr 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: String

Trade 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: String

Current Status of the order, serialized as kebab-case.

§price_from_api: bool

true if the sats amount was computed from a live market price.

§premium: i64

Premium percentage applied on top of the spot price.

§payment_method: String

Free-form payment method description (e.g. “SEPA,Bank transfer”).

§amount: i64

Sats 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: bool

true when the buyer has initiated a dispute on this order.

§seller_dispute: bool

true when the seller has initiated a dispute on this order.

§buyer_cooperativecancel: bool

true when the buyer has initiated a cooperative cancel.

§seller_cooperativecancel: bool

true when the seller has initiated a cooperative cancel.

§fee: i64

Mostro fee charged for this trade, in sats.

§routing_fee: i64

Lightning routing fee observed when paying the buyer.

§dev_fee: i64

Optional developer-fee portion of fee.

§dev_fee_paid: bool

true 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: String

Fiat currency code (e.g. “EUR”, “USD”).

§fiat_amount: i64

Fiat 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: i64

Unix timestamp (seconds) when the hold invoice was locked in.

§taken_at: i64

Unix timestamp (seconds) when the order was taken.

§created_at: i64

Unix timestamp (seconds) when the order was created.

§buyer_sent_rate: bool

true once the buyer has rated the counterpart.

§seller_sent_rate: bool

true once the seller has rated the counterpart.

§failed_payment: bool

true if the latest payment attempt to the buyer failed.

§payment_attempts: i64

Number of payment attempts performed so far.

§expires_at: i64

Unix 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

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn is_buy_order(&self) -> Result<(), CantDoReason>

Assert that the order is a Kind::Buy order.

Source

pub fn is_sell_order(&self) -> Result<(), CantDoReason>

Assert that the order is a Kind::Sell order.

Source

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.

Source

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.

Source

pub fn get_creator_pubkey(&self) -> Result<PublicKey, ServiceError>

Parse the maker’s public key as a Nostr PublicKey.

Source

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.

Source

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.

Source

pub fn get_master_buyer_pubkey(&self) -> Result<PublicKey, ServiceError>

Parse the buyer master identity public key.

Source

pub fn get_master_seller_pubkey(&self) -> Result<PublicKey, ServiceError>

Parse the seller master identity public key.

Source

pub fn is_range_order(&self) -> bool

true when both min_amount and max_amount are set, i.e. this is a range order.

Source

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.

Source

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.

Source

pub fn set_timestamp_now(&mut self)

Set Self::taken_at to the current Unix timestamp.

Source

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.

Source

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 Clone for Order

Source§

fn clone(&self) -> Order

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Order

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Order

Source§

fn default() -> Order

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for Order

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl From<Order> for SmallOrder

Source§

fn from(order: Order) -> Self

Converts to this type from the input type.
Source§

impl From<SmallOrder> for Order

Source§

fn from(small_order: SmallOrder) -> Self

Converts to this type from the input type.
Source§

impl Serialize for Order

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<S, T> Upcast<T> for S
where T: UpcastFrom<S> + ?Sized, S: ?Sized,

Source§

fn upcast(&self) -> &T
where Self: ErasableGeneric, T: ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider ref type within the Wasm bindgen generics type system. Read more
Source§

fn upcast_into(self) -> T
where Self: Sized + ErasableGeneric, T: ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider type within the Wasm bindgen generics type system. Read more
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,