referrerpolicy=no-referrer-when-downgrade

snowbridge_pallet_outbound_queue/
api.rs

1// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: 2023 Snowfork <hello@snowfork.com>
3//! Helpers for implementing runtime api
4
5use crate::{Config, MessageLeaves};
6use frame_support::storage::StorageStreamIter;
7use snowbridge_core::PricingParameters;
8use snowbridge_merkle_tree::{merkle_proof, MerkleProof};
9use snowbridge_outbound_queue_primitives::v1::{Command, Fee, GasMeter};
10use sp_core::Get;
11
12pub fn prove_message<T>(leaf_index: u64) -> Option<MerkleProof>
13where
14	T: Config,
15{
16	if !MessageLeaves::<T>::exists() {
17		return None
18	}
19	let proof =
20		merkle_proof::<<T as Config>::Hashing, _>(MessageLeaves::<T>::stream_iter(), leaf_index);
21	Some(proof)
22}
23
24pub fn calculate_fee<T>(
25	command: Command,
26	parameters: Option<PricingParameters<T::Balance>>,
27) -> Fee<T::Balance>
28where
29	T: Config,
30{
31	let gas_used_at_most = T::GasMeter::maximum_gas_used_at_most(&command);
32	let parameters = parameters.unwrap_or(T::PricingParameters::get());
33	crate::Pallet::<T>::calculate_fee(gas_used_at_most, parameters)
34}