staging_xcm_executor/traits/
on_response.rs1use crate::{Junctions::Here, Xcm};
18use codec::{Decode, Encode};
19use core::{fmt::Debug, result};
20use frame_support::{pallet_prelude::Get, parameter_types};
21use sp_arithmetic::traits::Zero;
22use xcm::latest::{
23 Error as XcmError, InteriorLocation, Location, QueryId, Response, Result as XcmResult, Weight,
24 XcmContext,
25};
26
27pub trait OnResponse {
29 fn expecting_response(origin: &Location, query_id: u64, querier: Option<&Location>) -> bool;
32 fn on_response(
35 origin: &Location,
36 query_id: u64,
37 querier: Option<&Location>,
38 response: Response,
39 max_weight: Weight,
40 context: &XcmContext,
41 ) -> Weight;
42}
43impl OnResponse for () {
44 fn expecting_response(_origin: &Location, _query_id: u64, _querier: Option<&Location>) -> bool {
45 false
46 }
47 fn on_response(
48 _origin: &Location,
49 _query_id: u64,
50 _querier: Option<&Location>,
51 _response: Response,
52 _max_weight: Weight,
53 _context: &XcmContext,
54 ) -> Weight {
55 Weight::zero()
56 }
57}
58
59pub trait VersionChangeNotifier {
61 fn start(
70 location: &Location,
71 query_id: QueryId,
72 max_weight: Weight,
73 context: &XcmContext,
74 ) -> XcmResult;
75
76 fn stop(location: &Location, context: &XcmContext) -> XcmResult;
79
80 fn is_subscribed(location: &Location) -> bool;
82}
83
84impl VersionChangeNotifier for () {
85 fn start(_: &Location, _: QueryId, _: Weight, _: &XcmContext) -> XcmResult {
86 Err(XcmError::Unimplemented)
87 }
88 fn stop(_: &Location, _: &XcmContext) -> XcmResult {
89 Err(XcmError::Unimplemented)
90 }
91 fn is_subscribed(_: &Location) -> bool {
92 false
93 }
94}
95
96#[derive(Debug, PartialEq, Eq, Encode, Decode)]
98pub enum QueryResponseStatus<BlockNumber> {
99 Ready { response: Response, at: BlockNumber },
102 Pending { timeout: BlockNumber },
105 NotFound,
108 UnexpectedVersion,
110}
111
112pub trait QueryHandler {
114 type BlockNumber: Zero + Encode;
115 type Error;
116 type UniversalLocation: Get<InteriorLocation>;
117
118 fn new_query(
120 responder: impl Into<Location>,
121 timeout: Self::BlockNumber,
122 match_querier: impl Into<Location>,
123 ) -> QueryId;
124
125 fn report_outcome(
138 message: &mut Xcm<()>,
139 responder: impl Into<Location>,
140 timeout: Self::BlockNumber,
141 ) -> result::Result<QueryId, Self::Error>;
142
143 fn take_response(id: QueryId) -> QueryResponseStatus<Self::BlockNumber>;
145
146 #[cfg(feature = "runtime-benchmarks")]
148 fn expect_response(id: QueryId, response: Response);
149}
150
151parameter_types! {
152 pub UniversalLocation: InteriorLocation = Here;
153}
154
155impl QueryHandler for () {
156 type BlockNumber = u64;
157 type Error = ();
158 type UniversalLocation = UniversalLocation;
159
160 fn take_response(_query_id: QueryId) -> QueryResponseStatus<Self::BlockNumber> {
161 QueryResponseStatus::NotFound
162 }
163 fn new_query(
164 _responder: impl Into<Location>,
165 _timeout: Self::BlockNumber,
166 _match_querier: impl Into<Location>,
167 ) -> QueryId {
168 0u64
169 }
170
171 fn report_outcome(
172 _message: &mut Xcm<()>,
173 _responder: impl Into<Location>,
174 _timeout: Self::BlockNumber,
175 ) -> Result<QueryId, Self::Error> {
176 Err(())
177 }
178
179 #[cfg(feature = "runtime-benchmarks")]
180 fn expect_response(_id: QueryId, _response: crate::Response) {}
181}