pub struct StellarTransactionValidator;Expand description
Validator for Stellar transactions and policies
Implementations§
Source§impl StellarTransactionValidator
impl StellarTransactionValidator
Sourcepub fn validate_fee_token_structure(
fee_token: &str,
) -> Result<(), StellarTransactionValidationError>
pub fn validate_fee_token_structure( fee_token: &str, ) -> Result<(), StellarTransactionValidationError>
Validate fee_token structure
Validates that the fee_token is in a valid format:
- “native” or “XLM” for native XLM
- “CODE:ISSUER” for classic assets (CODE: 1-12 chars, ISSUER: 56 chars starting with ‘G’)
- Contract address starting with “C” (56 chars) for Soroban contract tokens
Sourcepub fn validate_allowed_token(
asset: &str,
policy: &RelayerStellarPolicy,
) -> Result<(), StellarTransactionValidationError>
pub fn validate_allowed_token( asset: &str, policy: &RelayerStellarPolicy, ) -> Result<(), StellarTransactionValidationError>
Validate that an asset identifier is in the allowed tokens list
Sourcepub fn validate_max_fee(
fee: u64,
policy: &RelayerStellarPolicy,
) -> Result<(), StellarTransactionValidationError>
pub fn validate_max_fee( fee: u64, policy: &RelayerStellarPolicy, ) -> Result<(), StellarTransactionValidationError>
Validate that a fee amount doesn’t exceed the maximum allowed fee
Sourcepub fn validate_token_max_fee(
asset_id: &str,
fee: u64,
policy: &RelayerStellarPolicy,
) -> Result<(), StellarTransactionValidationError>
pub fn validate_token_max_fee( asset_id: &str, fee: u64, policy: &RelayerStellarPolicy, ) -> Result<(), StellarTransactionValidationError>
Validate that a specific token’s max_allowed_fee is not exceeded
Sourcepub fn extract_relayer_payments(
envelope: &TransactionEnvelope,
relayer_address: &str,
) -> Result<Vec<(String, u64)>, StellarTransactionValidationError>
pub fn extract_relayer_payments( envelope: &TransactionEnvelope, relayer_address: &str, ) -> Result<Vec<(String, u64)>, StellarTransactionValidationError>
Extract payment operations from a transaction envelope that pay to the relayer
Returns a vector of (asset_id, amount) tuples for payments to the relayer
Sourcepub fn validate_token_payment(
envelope: &TransactionEnvelope,
relayer_address: &str,
expected_fee_token: &str,
expected_fee_amount: u64,
policy: &RelayerStellarPolicy,
) -> Result<(), StellarTransactionValidationError>
pub fn validate_token_payment( envelope: &TransactionEnvelope, relayer_address: &str, expected_fee_token: &str, expected_fee_amount: u64, policy: &RelayerStellarPolicy, ) -> Result<(), StellarTransactionValidationError>
Validate token payment in transaction
Checks that:
- Payment operation to relayer exists
- Token is in allowed_tokens list
- Payment amount matches expected fee (within tolerance)
Sourcepub async fn validate_sequence_number<P>(
envelope: &TransactionEnvelope,
provider: &P,
) -> Result<(), StellarTransactionValidationError>
pub async fn validate_sequence_number<P>( envelope: &TransactionEnvelope, provider: &P, ) -> Result<(), StellarTransactionValidationError>
Validate sequence number
Validates that the transaction sequence number is valid for the source account. Note: The relayer will fee-bump this transaction, so the relayer’s sequence will be consumed. However, the inner transaction (user’s tx) must still have a valid sequence number.
The transaction sequence must be strictly greater than the account’s current sequence number. Future sequence numbers are allowed (user can queue transactions), but equal sequences are rejected.
Sourcepub async fn gasless_transaction_validation<P>(
envelope: &TransactionEnvelope,
relayer_address: &str,
policy: &RelayerStellarPolicy,
provider: &P,
max_validity_duration: Option<Duration>,
) -> Result<(), StellarTransactionValidationError>
pub async fn gasless_transaction_validation<P>( envelope: &TransactionEnvelope, relayer_address: &str, policy: &RelayerStellarPolicy, provider: &P, max_validity_duration: Option<Duration>, ) -> Result<(), StellarTransactionValidationError>
Comprehensive validation for gasless transactions
Performs all security and policy validations on a transaction envelope before it’s processed for gasless execution.
This includes:
- Validating source account is not relayer
- Validating transaction type
- Validating operations don’t target relayer (except fee payment)
- Validating operations count
- Validating operation types
- Validating sequence number
- Validating transaction validity duration (if max_validity_duration is provided)
§Arguments
envelope- The transaction envelope to validaterelayer_address- The relayer’s Stellar addresspolicy- The relayer policyprovider- Provider for Stellar RPC operationsmax_validity_duration- Optional maximum allowed transaction validity duration. If provided, validates that the transaction’s time bounds don’t exceed this duration. This protects against price fluctuations for user-paid fee transactions.
Sourcepub fn validate_time_bounds_not_expired(
envelope: &TransactionEnvelope,
) -> Result<(), StellarTransactionValidationError>
pub fn validate_time_bounds_not_expired( envelope: &TransactionEnvelope, ) -> Result<(), StellarTransactionValidationError>
Validate that transaction time bounds are valid and not expired
Checks that:
- Time bounds exist (if envelope has them)
- Current time is within the bounds (min_time <= now <= max_time)
- Transaction has not expired (now <= max_time)
§Arguments
envelope- The transaction envelope to validate
§Returns
Ok(()) if validation passes, StellarTransactionValidationError if validation fails
Sourcepub fn validate_transaction_validity_duration(
envelope: &TransactionEnvelope,
max_duration: Duration,
) -> Result<(), StellarTransactionValidationError>
pub fn validate_transaction_validity_duration( envelope: &TransactionEnvelope, max_duration: Duration, ) -> Result<(), StellarTransactionValidationError>
Validate that transaction validity duration is within the maximum allowed time
This prevents price fluctuations and protects the relayer from losses. The transaction must have time bounds set and the validity duration must not exceed the maximum allowed duration.
§Arguments
envelope- The transaction envelope to validatemax_duration- Maximum allowed validity duration
§Returns
Ok(()) if validation passes, StellarTransactionValidationError if validation fails
Sourcepub async fn validate_user_fee_payment_transaction<P, D>(
envelope: &TransactionEnvelope,
relayer_address: &str,
policy: &RelayerStellarPolicy,
provider: &P,
dex_service: &D,
max_validity_duration: Option<Duration>,
) -> Result<(), StellarTransactionValidationError>
pub async fn validate_user_fee_payment_transaction<P, D>( envelope: &TransactionEnvelope, relayer_address: &str, policy: &RelayerStellarPolicy, provider: &P, dex_service: &D, max_validity_duration: Option<Duration>, ) -> Result<(), StellarTransactionValidationError>
Comprehensive validation for user fee payment transactions
This function performs all validations required for user-paid fee transactions. It validates:
- Transaction structure and operations (via gasless_transaction_validation)
- Fee payment operations exist and are valid
- Allowed token validation
- Token max fee validation
- Payment amount is sufficient (compares with required fee including margin)
- Transaction validity duration (if max_validity_duration is provided)
This function is used by both fee-bump and sign-transaction flows.
For sign-transaction flows, pass max_validity_duration to enforce time bounds.
For fee-bump flows, pass None as transactions may not have time bounds set yet.
§Arguments
envelope- The transaction envelope to validaterelayer_address- The relayer’s Stellar addresspolicy- The relayer policy containing fee payment strategy and token settingsprovider- Provider for Stellar RPC operationsdex_service- DEX service for fetching quotes to validate payment amountsmax_validity_duration- Optional maximum allowed transaction validity duration. If provided, validates that the transaction’s time bounds don’t exceed this duration. This protects against price fluctuations for user-paid fee transactions when signing. PassNonefor fee-bump flows where time bounds may not be set yet.
§Returns
Ok(()) if validation passes, StellarTransactionValidationError if validation fails
Sourcepub async fn validate_user_token_balance<P>(
envelope: &TransactionEnvelope,
fee_token: &str,
required_fee_amount: u64,
provider: &P,
) -> Result<(), StellarTransactionValidationError>
pub async fn validate_user_token_balance<P>( envelope: &TransactionEnvelope, fee_token: &str, required_fee_amount: u64, provider: &P, ) -> Result<(), StellarTransactionValidationError>
Validate that user has sufficient token balance to pay the transaction fee
This function checks that the user’s account has enough balance of the specified fee token to cover the required transaction fee. This prevents users from getting quotes or building transactions they cannot afford.
§Arguments
envelope- The transaction envelope to extract source account fromfee_token- The token identifier (e.g., “native” or “USDC:GA5Z…”)required_fee_amount- The required fee amount in token’s smallest unit (stroops)provider- Provider for Stellar RPC operations to fetch balance
§Returns
Ok(()) if validation passes, StellarTransactionValidationError if validation fails
Auto Trait Implementations§
impl Freeze for StellarTransactionValidator
impl RefUnwindSafe for StellarTransactionValidator
impl Send for StellarTransactionValidator
impl Sync for StellarTransactionValidator
impl Unpin for StellarTransactionValidator
impl UnwindSafe for StellarTransactionValidator
Blanket Implementations§
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§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§impl<D> OwoColorize for D
impl<D> OwoColorize for D
§fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
§fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
§fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
§fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
§fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
§fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
§fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
§fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
§fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
§fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
§fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
§fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
§fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
§fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
§fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
§fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
§fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
§fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
§fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
§fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
§fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
§fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
§fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
§fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
§fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
§fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::fg] or
a color-specific method, such as [OwoColorize::green], Read more§fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::bg] or
a color-specific method, such as [OwoColorize::on_yellow], Read more