From 83b6ff851625be9c5a520bdf602607c28e4de668 Mon Sep 17 00:00:00 2001 From: ron Date: Fri, 15 Nov 2024 01:08:43 +0800 Subject: [PATCH] Reorgnize InboundMessage to abi module --- .../outbound-queue-v2/runtime-api/src/lib.rs | 2 +- .../pallets/outbound-queue-v2/src/api.rs | 5 +- .../pallets/outbound-queue-v2/src/lib.rs | 5 +- .../pallets/outbound-queue-v2/src/test.rs | 2 +- .../primitives/core/src/outbound/v2.rs | 157 ++++++++++-------- .../bridge-hubs/bridge-hub-westend/src/lib.rs | 2 +- 6 files changed, 96 insertions(+), 77 deletions(-) diff --git a/bridges/snowbridge/pallets/outbound-queue-v2/runtime-api/src/lib.rs b/bridges/snowbridge/pallets/outbound-queue-v2/runtime-api/src/lib.rs index 08d10ddd9269..f2c88658c23f 100644 --- a/bridges/snowbridge/pallets/outbound-queue-v2/runtime-api/src/lib.rs +++ b/bridges/snowbridge/pallets/outbound-queue-v2/runtime-api/src/lib.rs @@ -3,7 +3,7 @@ #![cfg_attr(not(feature = "std"), no_std)] use frame_support::traits::tokens::Balance as BalanceT; -use snowbridge_core::outbound::{v2::InboundMessage, DryRunError}; +use snowbridge_core::outbound::{v2::abi::InboundMessage, DryRunError}; use snowbridge_merkle_tree::MerkleProof; use xcm::prelude::Xcm; diff --git a/bridges/snowbridge/pallets/outbound-queue-v2/src/api.rs b/bridges/snowbridge/pallets/outbound-queue-v2/src/api.rs index 15c224931081..336979b47a36 100644 --- a/bridges/snowbridge/pallets/outbound-queue-v2/src/api.rs +++ b/bridges/snowbridge/pallets/outbound-queue-v2/src/api.rs @@ -6,7 +6,10 @@ use crate::{Config, MessageLeaves}; use frame_support::storage::StorageStreamIter; use snowbridge_core::{ outbound::{ - v2::{CommandWrapper, GasMeter, InboundMessage, Message}, + v2::{ + abi::{CommandWrapper, InboundMessage}, + GasMeter, Message, + }, DryRunError, }, AgentIdOf, diff --git a/bridges/snowbridge/pallets/outbound-queue-v2/src/lib.rs b/bridges/snowbridge/pallets/outbound-queue-v2/src/lib.rs index 9722e0876b9f..85745101e2f5 100644 --- a/bridges/snowbridge/pallets/outbound-queue-v2/src/lib.rs +++ b/bridges/snowbridge/pallets/outbound-queue-v2/src/lib.rs @@ -73,7 +73,10 @@ use frame_support::{ pub use pallet::*; use snowbridge_core::{ inbound::{Message as DeliveryMessage, VerificationError, Verifier}, - outbound::v2::{CommandWrapper, GasMeter, InboundMessage, InboundMessageWrapper, Message}, + outbound::v2::{ + abi::{CommandWrapper, InboundMessage, InboundMessageWrapper}, + GasMeter, Message, + }, BasicOperatingMode, RewardLedger, TokenId, }; use snowbridge_merkle_tree::merkle_root; diff --git a/bridges/snowbridge/pallets/outbound-queue-v2/src/test.rs b/bridges/snowbridge/pallets/outbound-queue-v2/src/test.rs index b4d70e37a9e4..0c1c2868cb90 100644 --- a/bridges/snowbridge/pallets/outbound-queue-v2/src/test.rs +++ b/bridges/snowbridge/pallets/outbound-queue-v2/src/test.rs @@ -13,7 +13,7 @@ use frame_support::{ use codec::Encode; use snowbridge_core::{ outbound::{ - v2::{primary_governance_origin, Command, InboundMessageWrapper, SendMessage}, + v2::{abi::InboundMessageWrapper, primary_governance_origin, Command, SendMessage}, SendError, }, ChannelId, ParaId, diff --git a/bridges/snowbridge/primitives/core/src/outbound/v2.rs b/bridges/snowbridge/primitives/core/src/outbound/v2.rs index 94015e506285..59be8767c2f4 100644 --- a/bridges/snowbridge/primitives/core/src/outbound/v2.rs +++ b/bridges/snowbridge/primitives/core/src/outbound/v2.rs @@ -3,7 +3,6 @@ //! # Outbound V2 primitives use crate::outbound::{OperatingMode, SendError}; -use alloy_sol_types::sol; use codec::{Decode, Encode}; use frame_support::{pallet_prelude::ConstU32, BoundedVec}; use hex_literal::hex; @@ -12,89 +11,103 @@ use sp_arithmetic::traits::{BaseArithmetic, Unsigned}; use sp_core::{RuntimeDebug, H160, H256}; use sp_std::{vec, vec::Vec}; +use crate::outbound::v2::abi::{ + CreateAgentParams, MintForeignTokenParams, RegisterForeignTokenParams, SetOperatingModeParams, + UnlockNativeTokenParams, UpgradeParams, +}; use alloy_primitives::{Address, FixedBytes}; use alloy_sol_types::SolValue; -sol! { - struct InboundMessageWrapper { - // origin - bytes32 origin; - // Message nonce - uint64 nonce; - // Commands - CommandWrapper[] commands; - } +pub mod abi { + use super::MAX_COMMANDS; + use alloy_sol_types::sol; + use codec::{Decode, Encode}; + use frame_support::BoundedVec; + use scale_info::TypeInfo; + use sp_core::{ConstU32, RuntimeDebug, H256}; + use sp_std::vec::Vec; - #[derive(Encode, Decode, RuntimeDebug, PartialEq,TypeInfo)] - struct CommandWrapper { - uint8 kind; - uint64 gas; - bytes payload; - } + sol! { + struct InboundMessageWrapper { + // origin + bytes32 origin; + // Message nonce + uint64 nonce; + // Commands + CommandWrapper[] commands; + } - // Payload for Upgrade - struct UpgradeParams { - // The address of the implementation contract - address implAddress; - // Codehash of the new implementation contract. - bytes32 implCodeHash; - // Parameters used to upgrade storage of the gateway - bytes initParams; - } + #[derive(Encode, Decode, RuntimeDebug, PartialEq,TypeInfo)] + struct CommandWrapper { + uint8 kind; + uint64 gas; + bytes payload; + } - // Payload for CreateAgent - struct CreateAgentParams { - /// @dev The agent ID of the consensus system - bytes32 agentID; - } + // Payload for Upgrade + struct UpgradeParams { + // The address of the implementation contract + address implAddress; + // Codehash of the new implementation contract. + bytes32 implCodeHash; + // Parameters used to upgrade storage of the gateway + bytes initParams; + } - // Payload for SetOperatingMode instruction - struct SetOperatingModeParams { - /// The new operating mode - uint8 mode; - } + // Payload for CreateAgent + struct CreateAgentParams { + /// @dev The agent ID of the consensus system + bytes32 agentID; + } - // Payload for NativeTokenUnlock instruction - struct UnlockNativeTokenParams { - // Token address - address token; - // Recipient address - address recipient; - // Amount to unlock - uint128 amount; - } + // Payload for SetOperatingMode instruction + struct SetOperatingModeParams { + /// The new operating mode + uint8 mode; + } - // Payload for RegisterForeignToken - struct RegisterForeignTokenParams { - /// @dev The token ID (hash of stable location id of token) - bytes32 foreignTokenID; - /// @dev The name of the token - bytes name; - /// @dev The symbol of the token - bytes symbol; - /// @dev The decimal of the token - uint8 decimals; - } + // Payload for NativeTokenUnlock instruction + struct UnlockNativeTokenParams { + // Token address + address token; + // Recipient address + address recipient; + // Amount to unlock + uint128 amount; + } + + // Payload for RegisterForeignToken + struct RegisterForeignTokenParams { + /// @dev The token ID (hash of stable location id of token) + bytes32 foreignTokenID; + /// @dev The name of the token + bytes name; + /// @dev The symbol of the token + bytes symbol; + /// @dev The decimal of the token + uint8 decimals; + } - // Payload for MintForeignTokenParams instruction - struct MintForeignTokenParams { - // Foreign token ID - bytes32 foreignTokenID; - // Recipient address - address recipient; - // Amount to mint - uint128 amount; + // Payload for MintForeignTokenParams instruction + struct MintForeignTokenParams { + // Foreign token ID + bytes32 foreignTokenID; + // Recipient address + address recipient; + // Amount to mint + uint128 amount; + } } -} -#[derive(Encode, Decode, TypeInfo, PartialEq, Clone, RuntimeDebug)] -pub struct InboundMessage { - /// Origin - pub origin: H256, - /// Nonce - pub nonce: u64, - /// Commands - pub commands: BoundedVec>, + #[derive(Encode, Decode, TypeInfo, PartialEq, Clone, RuntimeDebug)] + pub struct InboundMessage { + /// Origin + pub origin: H256, + /// Nonce + pub nonce: u64, + /// Commands + pub commands: BoundedVec>, + } } pub const MAX_COMMANDS: u32 = 8; diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/lib.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/lib.rs index 70a94e8dd630..0ac65c20a86c 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/lib.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/lib.rs @@ -101,7 +101,7 @@ use parachains_common::{ use snowbridge_core::{ outbound::{ v1::{Command, Fee}, - v2::InboundMessage, + v2::abi::InboundMessage, DryRunError, }, AgentId, PricingParameters,