MCPcopy Create free account
hub / github.com/cowprotocol/services / validate_app_data

Method validate_app_data

crates/shared/src/order_validation.rs:714–769  ·  view source on GitHub ↗

Validates the provided app data, returning an [`OrderAppData`] if valid. The validation entails verifying that the app data is well formed and its size. In the case the app data contains both a hash and the data, the data will be compared against the hash. The app data the override will be ignored unless the provided app data is a hash.

(
        &self,
        app_data: &OrderCreationAppData,
        full_app_data_override: &Option<String>,
    )

Source from the content-addressed store, hash-verified

712 /// * The app data the override will be ignored unless the provided app data
713 /// is a hash.
714 fn validate_app_data(
715 &self,
716 app_data: &OrderCreationAppData,
717 full_app_data_override: &Option<String>,
718 ) -> Result<OrderAppData, AppDataValidationError> {
719 let validate = |app_data: &str| -> Result<_, AppDataValidationError> {
720 let app_data = self
721 .app_data_validator
722 .validate(app_data.as_bytes())
723 .map_err(AppDataValidationError::Invalid)?;
724 Ok(app_data)
725 };
726
727 let app_data = match app_data {
728 OrderCreationAppData::Both { full, expected } => {
729 let validated = validate(full)?;
730 if validated.hash != *expected {
731 return Err(AppDataValidationError::Mismatch {
732 provided: *expected,
733 actual: validated.hash,
734 });
735 }
736 validated
737 }
738 OrderCreationAppData::Hash { hash } => {
739 // Eventually we're not going to accept orders that set only a
740 // hash and where we can't find full app data elsewhere.
741 let validated = if let Some(full) = full_app_data_override {
742 validate(full)?
743 } else {
744 return Err(AppDataValidationError::Invalid(anyhow!(
745 "Unknown pre-image for app data hash {:?}",
746 hash,
747 )));
748 };
749
750 // Keep the validated document, since the order creation simulator re-parses
751 // this document to rebuild the pre/post hooks, so dropping it
752 // makes the simulation skip the hooks (e.g. a permit approval)
753 // and revert spuriously.
754 ValidatedAppData {
755 hash: *hash,
756 document: validated.document,
757 protocol: validated.protocol,
758 }
759 }
760 OrderCreationAppData::Full { full } => validate(full)?,
761 };
762
763 let interactions = self.custom_interactions(&app_data.protocol.hooks);
764
765 Ok(OrderAppData {
766 inner: app_data,
767 interactions,
768 })
769 }
770
771 #[instrument(skip_all)]

Calls 3

as_bytesMethod · 0.80
custom_interactionsMethod · 0.80
validateMethod · 0.45