Skip to content

Commit

Permalink
Implement solidity codecs on xcm::latest (#1614)
Browse files Browse the repository at this point in the history
* feat: ✨ implement solidity codecs on xcm::latest

* refactor: 🔥 delete commented code

* fix: 🐛 manage missing cases for network_id_from_bytes
  • Loading branch information
manuelmauro authored Feb 20, 2025
1 parent 06b861f commit 4dddde8
Showing 1 changed file with 7 additions and 19 deletions.
26 changes: 7 additions & 19 deletions precompiles/src/solidity/codec/xcm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ use alloc::{string::String, vec::Vec};
use frame_support::{ensure, traits::ConstU32};
use sp_core::H256;
use sp_weights::Weight;
use xcm::lts::{Junction, Junctions, Location, NetworkId};
use xcm::{
latest::{Junction, Junctions, Location, NetworkId},
v5::{ROCOCO_GENESIS_HASH, WESTEND_GENESIS_HASH},
};

use crate::solidity::{
codec::{bytes::*, Codec, Reader, Writer},
Expand Down Expand Up @@ -76,21 +79,6 @@ pub(crate) fn network_id_to_bytes(network_id: Option<NetworkId>) -> Vec<u8> {
encoded.append(&mut block_hash.into());
encoded
}
Some(NetworkId::Westend) => {
encoded.push(5u8);
encoded.push(4u8);
encoded
}
Some(NetworkId::Rococo) => {
encoded.push(6u8);
encoded.push(5u8);
encoded
}
Some(NetworkId::Wococo) => {
encoded.push(7u8);
encoded.push(6u8);
encoded
}
Some(NetworkId::Ethereum { chain_id }) => {
encoded.push(8u8);
encoded.push(7u8);
Expand Down Expand Up @@ -152,9 +140,9 @@ pub(crate) fn network_id_from_bytes(encoded_bytes: Vec<u8>) -> MayRevert<Option<
block_hash,
}))
}
5 => Ok(Some(NetworkId::Westend)),
6 => Ok(Some(NetworkId::Rococo)),
7 => Ok(Some(NetworkId::Wococo)),
5 => Ok(Some(NetworkId::ByGenesis(WESTEND_GENESIS_HASH))),
6 => Ok(Some(NetworkId::ByGenesis(ROCOCO_GENESIS_HASH))),
7 => Err(RevertReason::custom("Wococo Network is no longer supported").into()),
8 => {
let mut chain_id: [u8; 8] = Default::default();
chain_id.copy_from_slice(encoded_network_id.read_raw_bytes(8)?);
Expand Down

0 comments on commit 4dddde8

Please sign in to comment.