pub struct SingleNodePayment {
pub quotes: [QuotePaymentInfo; 7],
}Expand description
Single node payment structure for a chunk.
Contains exactly CLOSE_GROUP_SIZE quotes where only the median-priced one
receives payment (3x), and the remaining quotes have Amount::ZERO.
The fixed-size array ensures compile-time enforcement of the quote count, making the median index always valid.
Fields§
§quotes: [QuotePaymentInfo; 7]All quotes (sorted by price) - fixed size ensures median index is always valid
Implementations§
Source§impl SingleNodePayment
impl SingleNodePayment
Sourcepub fn from_quotes(
quotes_with_prices: Vec<(PaymentQuote, Amount)>,
) -> Result<Self>
pub fn from_quotes( quotes_with_prices: Vec<(PaymentQuote, Amount)>, ) -> Result<Self>
Create a SingleNode payment from CLOSE_GROUP_SIZE quotes and their prices.
The quotes are automatically sorted by price (cheapest first).
The median (index CLOSE_GROUP_SIZE / 2) gets 3x its quote price.
The others get Amount::ZERO.
§Arguments
quotes_with_prices- Vec of (PaymentQuote, Amount) tuples (will be sorted internally)
§Errors
Returns error if not exactly CLOSE_GROUP_SIZE quotes are provided.
Sourcepub fn total_amount(&self) -> Amount
pub fn total_amount(&self) -> Amount
Get the total payment amount (should be 3x median price)
Sourcepub fn paid_quote(&self) -> Option<&QuotePaymentInfo>
pub fn paid_quote(&self) -> Option<&QuotePaymentInfo>
Get the median quote that receives payment.
Returns None only if the internal array is somehow shorter than MEDIAN_INDEX,
which should never happen since the array is fixed-size [_; CLOSE_GROUP_SIZE].
Sourcepub async fn pay(&self, wallet: &Wallet) -> Result<Vec<TxHash>>
pub async fn pay(&self, wallet: &Wallet) -> Result<Vec<TxHash>>
Pay for all quotes on-chain using the wallet.
Pays 3x to the median quote and 0 to the others.
§Errors
Returns an error if the payment transaction fails.
Sourcepub async fn verify(&self, network: &EvmNetwork) -> Result<Amount>
pub async fn verify(&self, network: &EvmNetwork) -> Result<Amount>
Verify that a median-priced quote was paid at least 3× its price on-chain.
When multiple quotes share the median price (a tie), the client and verifier may sort them in different order. This method checks all quotes tied at the median price and accepts the payment if any one of them was paid the correct amount.
§Returns
The on-chain payment amount for the verified quote.
§Errors
Returns an error if the on-chain lookup fails or none of the median-priced quotes were paid at least 3× the median price.
Trait Implementations§
Source§impl Clone for SingleNodePayment
impl Clone for SingleNodePayment
Source§fn clone(&self) -> SingleNodePayment
fn clone(&self) -> SingleNodePayment
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for SingleNodePayment
impl RefUnwindSafe for SingleNodePayment
impl Send for SingleNodePayment
impl Sync for SingleNodePayment
impl Unpin for SingleNodePayment
impl UnsafeUnpin for SingleNodePayment
impl UnwindSafe for SingleNodePayment
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