Skip to main content

SessionRequest

Struct SessionRequest 

Source
pub struct SessionRequest {
    pub amount: String,
    pub unit_type: Option<String>,
    pub currency: String,
    pub decimals: Option<u8>,
    pub recipient: Option<String>,
    pub suggested_deposit: Option<String>,
    pub method_details: Option<Value>,
}
Expand description

Session request (for session intent).

Represents a pay-as-you-go session payment request. All fields are strings to remain method-agnostic. Use the methods layer for typed accessors.

§Examples

use mpp::protocol::intents::SessionRequest;

let req = SessionRequest {
    amount: "1000".to_string(),
    unit_type: Some("second".to_string()),
    currency: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48".to_string(),
    decimals: None,
    recipient: Some("0x742d35Cc6634C0532925a3b844Bc9e7595f1B0F2".to_string()),
    suggested_deposit: Some("60000".to_string()),
    method_details: None,
};

assert_eq!(req.amount, "1000");
assert_eq!(req.unit_type, Some("second".to_string()));

Fields§

§amount: String

Amount per unit in base units (e.g., wei per second)

§unit_type: Option<String>

Unit type for the session rate (e.g., “second”, “minute”, “request”). Optional.

§currency: String

Currency/asset identifier (token address, ISO 4217 code, or symbol)

§decimals: Option<u8>

Token decimals for amount conversion (e.g., 6 for pathUSD).

When set, amount and suggested_deposit are treated as human-readable values and will be scaled by 10^decimals during challenge creation. The field is stripped from wire serialization.

§recipient: Option<String>

Recipient address (optional, server may be recipient)

§suggested_deposit: Option<String>

Suggested deposit amount in base units

§method_details: Option<Value>

Method-specific extension fields (interpreted by methods layer)

Implementations§

Source§

impl SessionRequest

Source

pub fn with_base_units(self) -> Result<Self>

Apply the decimals transform, converting human-readable amounts to base units.

Transforms both amount and suggested_deposit (if present). If decimals is None, returns self unchanged.

Source

pub fn parse_amount(&self) -> Result<u128>

Parse the amount as u128.

Returns an error if the amount is not a valid unsigned integer.

Source

pub fn validate_max_amount(&self, max_amount: &str) -> Result<()>

Validate that the session amount does not exceed a maximum.

§Arguments
  • max_amount - Maximum allowed amount as a string (atomic units)
§Returns
  • Ok(()) if amount is within limit
  • Err(AmountExceedsMax) if amount exceeds the maximum

Trait Implementations§

Source§

impl Clone for SessionRequest

Source§

fn clone(&self) -> SessionRequest

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 SessionRequest

Source§

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

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

impl Default for SessionRequest

Source§

fn default() -> SessionRequest

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

impl<'de> Deserialize<'de> for SessionRequest

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 Serialize for SessionRequest

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§

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, 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> 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<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,