snowbridge_inbound_queue_primitives/
lib.rs
1#![cfg_attr(not(feature = "std"), no_std)]
5pub mod v1;
6pub mod v2;
7use codec::Encode;
8use sp_core::blake2_256;
9use sp_std::marker::PhantomData;
10use xcm::prelude::{AccountKey20, Ethereum, GlobalConsensus, Location};
11use xcm_executor::traits::ConvertLocation;
12
13pub use snowbridge_verification_primitives::*;
14
15pub struct EthereumLocationsConverterFor<AccountId>(PhantomData<AccountId>);
17impl<AccountId> ConvertLocation<AccountId> for EthereumLocationsConverterFor<AccountId>
18where
19 AccountId: From<[u8; 32]> + Clone,
20{
21 fn convert_location(location: &Location) -> Option<AccountId> {
22 match location.unpack() {
23 (2, [GlobalConsensus(Ethereum { chain_id })]) =>
24 Some(Self::from_chain_id(chain_id).into()),
25 (2, [GlobalConsensus(Ethereum { chain_id }), AccountKey20 { network: _, key }]) =>
26 Some(Self::from_chain_id_with_key(chain_id, *key).into()),
27 _ => None,
28 }
29 }
30}
31
32impl<AccountId> EthereumLocationsConverterFor<AccountId> {
33 pub fn from_chain_id(chain_id: &u64) -> [u8; 32] {
34 (b"ethereum-chain", chain_id).using_encoded(blake2_256)
35 }
36 pub fn from_chain_id_with_key(chain_id: &u64, key: [u8; 20]) -> [u8; 32] {
37 (b"ethereum-chain", chain_id, key).using_encoded(blake2_256)
38 }
39}
40
41pub type CallIndex = [u8; 2];