Files
pezkuwi-sdk/pezbridges/pezsnowbridge/test-utils/src/mock_converter.rs
T
pezkuwichain 3ddf58cef9 fix: EnsureOrigin try_successful_origin and snowbridge rename
- Fix pezpallet-welati EnsureOrigin implementations (3 fixes)
  - Remove incorrect #[cfg(not(feature = "runtime-benchmarks"))] blocks
  - Affects EnsureSerok, EnsureParlementer, EnsureDiwan

- Fix asset-hub-zagros governance origins macros (2 fixes)
  - Remove non-benchmark try_successful_origin from decl_unit_ensures!
  - Remove non-benchmark try_successful_origin from decl_ensure!

- Rename snowbridge -> pezsnowbridge for consistency

- Update WORKFLOW_PLAN.md with build status and package names
  - Correct package names: pezkuwi-teyrchain-bin, pezstaging-node-cli
  - Mark completed builds: pezkuwi, pezkuwi-teyrchain-bin,
    pezstaging-node-cli, teyrchain-template-node
2025-12-25 01:26:18 +03:00

43 lines
1.5 KiB
Rust

// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: 2023 Snowfork <hello@snowfork.com>
use codec::Encode;
use pezframe_support::pezsp_runtime::traits::MaybeConvert;
use pezsnowbridge_core::TokenIdOf;
use pezsp_core::H256;
use std::{cell::RefCell, collections::HashMap};
use xcm::{
latest::InteriorLocation,
prelude::{Location, Reanchorable},
};
use xcm_executor::traits::ConvertLocation;
thread_local! {
pub static IDENTIFIER_TO_LOCATION: RefCell<HashMap<H256, Location>> = RefCell::new(HashMap::new());
pub static LOCATION_TO_IDENTIFIER: RefCell<HashMap<Vec<u8>, H256>> = RefCell::new(HashMap::new());
}
pub fn add_location_override(location: Location, ethereum: Location, bh_context: InteriorLocation) {
let (token_id, reanchored_location) = reanchor_to_ethereum(location, ethereum, bh_context);
IDENTIFIER_TO_LOCATION.with(|b| b.borrow_mut().insert(token_id, reanchored_location.clone()));
LOCATION_TO_IDENTIFIER.with(|b| b.borrow_mut().insert(reanchored_location.encode(), token_id));
}
pub fn reanchor_to_ethereum(
location: Location,
ethereum: Location,
bh_context: InteriorLocation,
) -> (H256, Location) {
let mut reanchored_lol = location.clone();
let _ = reanchored_lol.reanchor(&ethereum, &bh_context);
let token_id = TokenIdOf::convert_location(&reanchored_lol).unwrap();
(token_id, reanchored_lol)
}
pub struct LocationIdConvert;
impl MaybeConvert<H256, Location> for LocationIdConvert {
fn maybe_convert(id: H256) -> Option<Location> {
IDENTIFIER_TO_LOCATION.with(|b| b.borrow().get(&id).and_then(|l| Option::from(l.clone())))
}
}