Skip to content

Commit

Permalink
Improved TrustedQueryAPI signatures (#6129)
Browse files Browse the repository at this point in the history
Changed returned type of API methods from `Result<bool,
xcm_runtime_apis::trusted_query::Error>` to a typed one `type
XcmTrustedQueryResult = Result<bool,
xcm_runtime_apis::trusted_query::Error>;`
Follow-up of
[PR-6039](#6039)

---------

Co-authored-by: Bastian Köcher <[email protected]>
Co-authored-by: Adrian Catangiu <[email protected]>
  • Loading branch information
3 people authored Oct 21, 2024
1 parent a538ac1 commit 95483a8
Show file tree
Hide file tree
Showing 13 changed files with 59 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1103,8 +1103,6 @@ pub type Executive = frame_executive::Executive<
Migrations,
>;

type XcmTrustedQueryResult = Result<bool, xcm_runtime_apis::trusted_query::Error>;

#[cfg(feature = "runtime-benchmarks")]
pub struct AssetConversionTxHelper;

Expand Down Expand Up @@ -1877,10 +1875,10 @@ impl_runtime_apis! {
}

impl xcm_runtime_apis::trusted_query::TrustedQueryApi<Block> for Runtime {
fn is_trusted_reserve(asset: VersionedAsset, location: VersionedLocation) -> XcmTrustedQueryResult {
fn is_trusted_reserve(asset: VersionedAsset, location: VersionedLocation) -> xcm_runtime_apis::trusted_query::XcmTrustedQueryResult {
PolkadotXcm::is_trusted_reserve(asset, location)
}
fn is_trusted_teleporter(asset: VersionedAsset, location: VersionedLocation) -> XcmTrustedQueryResult {
fn is_trusted_teleporter(asset: VersionedAsset, location: VersionedLocation) -> xcm_runtime_apis::trusted_query::XcmTrustedQueryResult {
PolkadotXcm::is_trusted_teleporter(asset, location)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1976,10 +1976,10 @@ impl_runtime_apis! {
}

impl xcm_runtime_apis::trusted_query::TrustedQueryApi<Block> for Runtime {
fn is_trusted_reserve(asset: VersionedAsset, location: VersionedLocation) -> Result<bool, xcm_runtime_apis::trusted_query::Error> {
fn is_trusted_reserve(asset: VersionedAsset, location: VersionedLocation) -> xcm_runtime_apis::trusted_query::XcmTrustedQueryResult {
PolkadotXcm::is_trusted_reserve(asset, location)
}
fn is_trusted_teleporter(asset: VersionedAsset, location: VersionedLocation) -> Result<bool, xcm_runtime_apis::trusted_query::Error> {
fn is_trusted_teleporter(asset: VersionedAsset, location: VersionedLocation) -> xcm_runtime_apis::trusted_query::XcmTrustedQueryResult {
PolkadotXcm::is_trusted_teleporter(asset, location)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1530,10 +1530,10 @@ impl_runtime_apis! {
}

impl xcm_runtime_apis::trusted_query::TrustedQueryApi<Block> for Runtime {
fn is_trusted_reserve(asset: VersionedAsset, location: VersionedLocation) -> Result<bool, xcm_runtime_apis::trusted_query::Error> {
fn is_trusted_reserve(asset: VersionedAsset, location: VersionedLocation) -> xcm_runtime_apis::trusted_query::XcmTrustedQueryResult {
PolkadotXcm::is_trusted_reserve(asset, location)
}
fn is_trusted_teleporter(asset: VersionedAsset, location: VersionedLocation) -> Result<bool, xcm_runtime_apis::trusted_query::Error> {
fn is_trusted_teleporter(asset: VersionedAsset, location: VersionedLocation) -> xcm_runtime_apis::trusted_query::XcmTrustedQueryResult {
PolkadotXcm::is_trusted_teleporter(asset, location)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1346,10 +1346,10 @@ impl_runtime_apis! {
}

impl xcm_runtime_apis::trusted_query::TrustedQueryApi<Block> for Runtime {
fn is_trusted_reserve(asset: VersionedAsset, location: VersionedLocation) -> Result<bool, xcm_runtime_apis::trusted_query::Error> {
fn is_trusted_reserve(asset: VersionedAsset, location: VersionedLocation) -> xcm_runtime_apis::trusted_query::XcmTrustedQueryResult {
PolkadotXcm::is_trusted_reserve(asset, location)
}
fn is_trusted_teleporter(asset: VersionedAsset, location: VersionedLocation) -> Result<bool, xcm_runtime_apis::trusted_query::Error> {
fn is_trusted_teleporter(asset: VersionedAsset, location: VersionedLocation) -> xcm_runtime_apis::trusted_query::XcmTrustedQueryResult {
PolkadotXcm::is_trusted_teleporter(asset, location)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1173,10 +1173,10 @@ impl_runtime_apis! {
}

impl xcm_runtime_apis::trusted_query::TrustedQueryApi<Block> for Runtime {
fn is_trusted_reserve(asset: VersionedAsset, location: VersionedLocation) -> Result<bool, xcm_runtime_apis::trusted_query::Error> {
fn is_trusted_reserve(asset: VersionedAsset, location: VersionedLocation) -> xcm_runtime_apis::trusted_query::XcmTrustedQueryResult {
PolkadotXcm::is_trusted_reserve(asset, location)
}
fn is_trusted_teleporter(asset: VersionedAsset, location: VersionedLocation) -> Result<bool, xcm_runtime_apis::trusted_query::Error> {
fn is_trusted_teleporter(asset: VersionedAsset, location: VersionedLocation) -> xcm_runtime_apis::trusted_query::XcmTrustedQueryResult {
PolkadotXcm::is_trusted_teleporter(asset, location)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -885,10 +885,10 @@ impl_runtime_apis! {
}

impl xcm_runtime_apis::trusted_query::TrustedQueryApi<Block> for Runtime {
fn is_trusted_reserve(asset: VersionedAsset, location: VersionedLocation) -> Result<bool, xcm_runtime_apis::trusted_query::Error> {
fn is_trusted_reserve(asset: VersionedAsset, location: VersionedLocation) -> xcm_runtime_apis::trusted_query::XcmTrustedQueryResult {
PolkadotXcm::is_trusted_reserve(asset, location)
}
fn is_trusted_teleporter(asset: VersionedAsset, location: VersionedLocation) -> Result<bool, xcm_runtime_apis::trusted_query::Error> {
fn is_trusted_teleporter(asset: VersionedAsset, location: VersionedLocation) -> xcm_runtime_apis::trusted_query::XcmTrustedQueryResult {
PolkadotXcm::is_trusted_teleporter(asset, location)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1153,10 +1153,10 @@ impl_runtime_apis! {
}

impl xcm_runtime_apis::trusted_query::TrustedQueryApi<Block> for Runtime {
fn is_trusted_reserve(asset: VersionedAsset, location: VersionedLocation) -> Result<bool, xcm_runtime_apis::trusted_query::Error> {
fn is_trusted_reserve(asset: VersionedAsset, location: VersionedLocation) -> xcm_runtime_apis::trusted_query::XcmTrustedQueryResult {
PolkadotXcm::is_trusted_reserve(asset, location)
}
fn is_trusted_teleporter(asset: VersionedAsset, location: VersionedLocation) -> Result<bool, xcm_runtime_apis::trusted_query::Error> {
fn is_trusted_teleporter(asset: VersionedAsset, location: VersionedLocation) -> xcm_runtime_apis::trusted_query::XcmTrustedQueryResult {
PolkadotXcm::is_trusted_teleporter(asset, location)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1146,10 +1146,10 @@ impl_runtime_apis! {
}

impl xcm_runtime_apis::trusted_query::TrustedQueryApi<Block> for Runtime {
fn is_trusted_reserve(asset: VersionedAsset, location: VersionedLocation) -> Result<bool, xcm_runtime_apis::trusted_query::Error> {
fn is_trusted_reserve(asset: VersionedAsset, location: VersionedLocation) -> xcm_runtime_apis::trusted_query::XcmTrustedQueryResult {
PolkadotXcm::is_trusted_reserve(asset, location)
}
fn is_trusted_teleporter(asset: VersionedAsset, location: VersionedLocation) -> Result<bool, xcm_runtime_apis::trusted_query::Error> {
fn is_trusted_teleporter(asset: VersionedAsset, location: VersionedLocation) -> xcm_runtime_apis::trusted_query::XcmTrustedQueryResult {
PolkadotXcm::is_trusted_teleporter(asset, location)
}
}
Expand Down
4 changes: 2 additions & 2 deletions cumulus/parachains/runtimes/people/people-rococo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1064,10 +1064,10 @@ impl_runtime_apis! {
}

impl xcm_runtime_apis::trusted_query::TrustedQueryApi<Block> for Runtime {
fn is_trusted_reserve(asset: VersionedAsset, location: VersionedLocation) -> Result<bool, xcm_runtime_apis::trusted_query::Error> {
fn is_trusted_reserve(asset: VersionedAsset, location: VersionedLocation) -> xcm_runtime_apis::trusted_query::XcmTrustedQueryResult {
PolkadotXcm::is_trusted_reserve(asset, location)
}
fn is_trusted_teleporter(asset: VersionedAsset, location: VersionedLocation) -> Result<bool, xcm_runtime_apis::trusted_query::Error> {
fn is_trusted_teleporter(asset: VersionedAsset, location: VersionedLocation) -> xcm_runtime_apis::trusted_query::XcmTrustedQueryResult {
PolkadotXcm::is_trusted_teleporter(asset, location)
}
}
Expand Down
4 changes: 2 additions & 2 deletions cumulus/parachains/runtimes/people/people-westend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1062,10 +1062,10 @@ impl_runtime_apis! {
}

impl xcm_runtime_apis::trusted_query::TrustedQueryApi<Block> for Runtime {
fn is_trusted_reserve(asset: VersionedAsset, location: VersionedLocation) -> Result<bool, xcm_runtime_apis::trusted_query::Error> {
fn is_trusted_reserve(asset: VersionedAsset, location: VersionedLocation) -> xcm_runtime_apis::trusted_query::XcmTrustedQueryResult {
PolkadotXcm::is_trusted_reserve(asset, location)
}
fn is_trusted_teleporter(asset: VersionedAsset, location: VersionedLocation) -> Result<bool, xcm_runtime_apis::trusted_query::Error> {
fn is_trusted_teleporter(asset: VersionedAsset, location: VersionedLocation) -> xcm_runtime_apis::trusted_query::XcmTrustedQueryResult {
PolkadotXcm::is_trusted_teleporter(asset, location)
}
}
Expand Down
4 changes: 2 additions & 2 deletions cumulus/parachains/runtimes/testing/penpal/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1165,10 +1165,10 @@ impl_runtime_apis! {
}

impl xcm_runtime_apis::trusted_query::TrustedQueryApi<Block> for Runtime {
fn is_trusted_reserve(asset: VersionedAsset, location: VersionedLocation) -> Result<bool, xcm_runtime_apis::trusted_query::Error> {
fn is_trusted_reserve(asset: VersionedAsset, location: VersionedLocation) -> xcm_runtime_apis::trusted_query::XcmTrustedQueryResult {
PolkadotXcm::is_trusted_reserve(asset, location)
}
fn is_trusted_teleporter(asset: VersionedAsset, location: VersionedLocation) -> Result<bool, xcm_runtime_apis::trusted_query::Error> {
fn is_trusted_teleporter(asset: VersionedAsset, location: VersionedLocation) -> xcm_runtime_apis::trusted_query::XcmTrustedQueryResult {
PolkadotXcm::is_trusted_teleporter(asset, location)
}
}
Expand Down
7 changes: 5 additions & 2 deletions polkadot/xcm/xcm-runtime-apis/src/trusted_query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ use codec::{Decode, Encode};
use frame_support::pallet_prelude::TypeInfo;
use xcm::{VersionedAsset, VersionedLocation};

/// Result of [`TrustedQueryApi`] functions.
pub type XcmTrustedQueryResult = Result<bool, Error>;

sp_api::decl_runtime_apis! {
// API for querying trusted reserves and trusted teleporters.
pub trait TrustedQueryApi {
Expand All @@ -28,13 +31,13 @@ sp_api::decl_runtime_apis! {
/// # Arguments
/// * `asset`: `VersionedAsset`.
/// * `location`: `VersionedLocation`.
fn is_trusted_reserve(asset: VersionedAsset, location: VersionedLocation) -> Result<bool, Error>;
fn is_trusted_reserve(asset: VersionedAsset, location: VersionedLocation) -> XcmTrustedQueryResult;
/// Returns if the asset can be teleported to the location.
///
/// # Arguments
/// * `asset`: `VersionedAsset`.
/// * `location`: `VersionedLocation`.
fn is_trusted_teleporter(asset: VersionedAsset, location: VersionedLocation) -> Result<bool, Error>;
fn is_trusted_teleporter(asset: VersionedAsset, location: VersionedLocation) -> XcmTrustedQueryResult;
}
}

Expand Down
32 changes: 32 additions & 0 deletions prdoc/pr_6129.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Schema: Polkadot SDK PRDoc Schema (prdoc) v1.0.0
# See doc at https://raw.githubusercontent.com/paritytech/polkadot-sdk/master/prdoc/schema_user.json

title: "Improved TrustedQueryAPI signatures."

doc:
- audience: Runtime Dev
description: |
Changed returned type of API methods from `Result<bool, xcm_runtime_apis::trusted_query::Error>` to a typed one:
`type XcmTrustedQueryResult = Result<bool, xcm_runtime_apis::trusted_query::Error>`

crates:
- name: asset-hub-westend-runtime
bump: patch
- name: bridge-hub-rococo-runtime
bump: patch
- name: bridge-hub-westend-runtime
bump: patch
- name: collectives-westend-runtime
bump: patch
- name: contracts-rococo-runtime
bump: patch
- name: coretime-rococo-runtime
bump: patch
- name: coretime-westend-runtime
bump: patch
- name: people-rococo-runtime
bump: patch
- name: people-westend-runtime
bump: patch
- name: penpal-runtime
bump: patch

0 comments on commit 95483a8

Please sign in to comment.