mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-20 22:11:01 +00:00
Use TypedLaneId instead of LaneId (#1738)
* TypedLaneId -> LaneId * fix benchmarks compilation
This commit is contained in:
committed by
Bastian Köcher
parent
41daa32acb
commit
03425b33ae
@@ -67,16 +67,30 @@ impl OperatingMode for MessagesOperatingMode {
|
||||
}
|
||||
}
|
||||
|
||||
/// Lane identifier.
|
||||
pub type LaneId = [u8; 4];
|
||||
|
||||
/// Lane id which implements `TypeId`.
|
||||
// TODO (https://github.com/paritytech/parity-bridges-common/issues/1694):
|
||||
// `LaneId` shall be replaced with this across all codebase (codec-compatible)
|
||||
#[derive(Decode, Encode, RuntimeDebug)]
|
||||
pub struct TypedLaneId(pub [u8; 4]);
|
||||
#[derive(
|
||||
Clone,
|
||||
Copy,
|
||||
Decode,
|
||||
Default,
|
||||
Encode,
|
||||
Eq,
|
||||
Ord,
|
||||
PartialOrd,
|
||||
PartialEq,
|
||||
RuntimeDebug,
|
||||
TypeInfo,
|
||||
MaxEncodedLen,
|
||||
)]
|
||||
pub struct LaneId(pub [u8; 4]);
|
||||
|
||||
impl TypeId for TypedLaneId {
|
||||
impl AsRef<[u8]> for LaneId {
|
||||
fn as_ref(&self) -> &[u8] {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl TypeId for LaneId {
|
||||
const TYPE_ID: [u8; 4] = *b"blan";
|
||||
}
|
||||
|
||||
|
||||
@@ -56,7 +56,7 @@ pub fn outbound_lane_data_key(pallet_prefix: &str, lane: &LaneId) -> StorageKey
|
||||
bp_runtime::storage_map_final_key::<Blake2_128Concat>(
|
||||
pallet_prefix,
|
||||
OUTBOUND_LANES_MAP_NAME,
|
||||
lane,
|
||||
&lane.encode(),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -65,7 +65,7 @@ pub fn inbound_lane_data_key(pallet_prefix: &str, lane: &LaneId) -> StorageKey {
|
||||
bp_runtime::storage_map_final_key::<Blake2_128Concat>(
|
||||
pallet_prefix,
|
||||
INBOUND_LANES_MAP_NAME,
|
||||
lane,
|
||||
&lane.encode(),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -91,7 +91,7 @@ mod tests {
|
||||
fn storage_message_key_computed_properly() {
|
||||
// If this test fails, then something has been changed in module storage that is breaking
|
||||
// all previously crafted messages proofs.
|
||||
let storage_key = message_key("BridgeMessages", b"test", 42).0;
|
||||
let storage_key = message_key("BridgeMessages", &LaneId(*b"test"), 42).0;
|
||||
assert_eq!(
|
||||
storage_key,
|
||||
hex!("dd16c784ebd3390a9bc0357c7511ed018a395e6242c6813b196ca31ed0547ea79446af0e09063bd4a7874aef8a997cec746573742a00000000000000").to_vec(),
|
||||
@@ -104,7 +104,7 @@ mod tests {
|
||||
fn outbound_lane_data_key_computed_properly() {
|
||||
// If this test fails, then something has been changed in module storage that is breaking
|
||||
// all previously crafted outbound lane state proofs.
|
||||
let storage_key = outbound_lane_data_key("BridgeMessages", b"test").0;
|
||||
let storage_key = outbound_lane_data_key("BridgeMessages", &LaneId(*b"test")).0;
|
||||
assert_eq!(
|
||||
storage_key,
|
||||
hex!("dd16c784ebd3390a9bc0357c7511ed0196c246acb9b55077390e3ca723a0ca1f44a8995dd50b6657a037a7839304535b74657374").to_vec(),
|
||||
@@ -117,7 +117,7 @@ mod tests {
|
||||
fn inbound_lane_data_key_computed_properly() {
|
||||
// If this test fails, then something has been changed in module storage that is breaking
|
||||
// all previously crafted inbound lane state proofs.
|
||||
let storage_key = inbound_lane_data_key("BridgeMessages", b"test").0;
|
||||
let storage_key = inbound_lane_data_key("BridgeMessages", &LaneId(*b"test")).0;
|
||||
assert_eq!(
|
||||
storage_key,
|
||||
hex!("dd16c784ebd3390a9bc0357c7511ed01e5f83cf83f2127eb47afdc35d6e43fab44a8995dd50b6657a037a7839304535b74657374").to_vec(),
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
#![warn(missing_docs)]
|
||||
#![cfg_attr(not(feature = "std"), no_std)]
|
||||
|
||||
use bp_messages::{LaneId, TypedLaneId};
|
||||
use bp_messages::LaneId;
|
||||
use sp_runtime::{
|
||||
codec::{Decode, Encode},
|
||||
traits::AccountIdConversion,
|
||||
@@ -45,7 +45,7 @@ where
|
||||
{
|
||||
/// Return account that pay rewards for serving given lane.
|
||||
pub fn lane_rewards_account(lane_id: LaneId) -> Relayer {
|
||||
TypedLaneId(lane_id).into_sub_account_truncating(b"bridge-lane")
|
||||
lane_id.into_sub_account_truncating(b"bridge-lane")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,17 +72,17 @@ mod tests {
|
||||
#[test]
|
||||
fn lanes_are_using_different_accounts() {
|
||||
assert_eq!(
|
||||
PayLaneRewardFromAccount::<(), bp_rialto::AccountId>::lane_rewards_account([
|
||||
PayLaneRewardFromAccount::<(), bp_rialto::AccountId>::lane_rewards_account(LaneId([
|
||||
0, 0, 0, 0
|
||||
]),
|
||||
])),
|
||||
hex_literal::hex!("626c616e000000006272696467652d6c616e6500000000000000000000000000")
|
||||
.into(),
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
PayLaneRewardFromAccount::<(), bp_rialto::AccountId>::lane_rewards_account([
|
||||
PayLaneRewardFromAccount::<(), bp_rialto::AccountId>::lane_rewards_account(LaneId([
|
||||
0, 0, 0, 1
|
||||
]),
|
||||
])),
|
||||
hex_literal::hex!("626c616e000000016272696467652d6c616e6500000000000000000000000000")
|
||||
.into(),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user