referrerpolicy=no-referrer-when-downgrade

snowbridge_outbound_queue_primitives/v2/
exporter.rs

1// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: 2023 Snowfork <hello@snowfork.com>
3use core::marker::PhantomData;
4use snowbridge_core::operating_mode::ExportPausedQuery;
5use sp_std::vec::Vec;
6use xcm::{
7	prelude::{Location, SendError, SendResult, SendXcm, Xcm, XcmHash},
8	VersionedLocation, VersionedXcm,
9};
10use xcm_builder::InspectMessageQueues;
11
12pub struct PausableExporter<PausedQuery, InnerExporter>(PhantomData<(PausedQuery, InnerExporter)>);
13
14impl<PausedQuery: ExportPausedQuery, InnerExporter: SendXcm> SendXcm
15	for PausableExporter<PausedQuery, InnerExporter>
16{
17	type Ticket = InnerExporter::Ticket;
18
19	fn validate(
20		destination: &mut Option<Location>,
21		message: &mut Option<Xcm<()>>,
22	) -> SendResult<Self::Ticket> {
23		match PausedQuery::is_paused() {
24			true => Err(SendError::NotApplicable),
25			false => InnerExporter::validate(destination, message),
26		}
27	}
28
29	fn deliver(ticket: Self::Ticket) -> Result<XcmHash, SendError> {
30		match PausedQuery::is_paused() {
31			true => Err(SendError::NotApplicable),
32			false => InnerExporter::deliver(ticket),
33		}
34	}
35}
36
37impl<Halted: ExportPausedQuery, InnerExporter: SendXcm> InspectMessageQueues
38	for PausableExporter<Halted, InnerExporter>
39{
40	fn clear_messages() {}
41
42	/// This router needs to implement `InspectMessageQueues` but doesn't have to
43	/// return any messages, since it just reuses the inner router.
44	fn get_messages() -> Vec<(VersionedLocation, Vec<VersionedXcm<()>>)> {
45		Vec::new()
46	}
47}