Skip to content

Commit

Permalink
Reorgnize InboundMessage to abi module
Browse files Browse the repository at this point in the history
  • Loading branch information
yrong committed Nov 14, 2024
1 parent fb3b30c commit 83b6ff8
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 77 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
5 changes: 4 additions & 1 deletion bridges/snowbridge/pallets/outbound-queue-v2/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 4 additions & 1 deletion bridges/snowbridge/pallets/outbound-queue-v2/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion bridges/snowbridge/pallets/outbound-queue-v2/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
157 changes: 85 additions & 72 deletions bridges/snowbridge/primitives/core/src/outbound/v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<CommandWrapper, ConstU32<MAX_COMMANDS>>,
#[derive(Encode, Decode, TypeInfo, PartialEq, Clone, RuntimeDebug)]
pub struct InboundMessage {
/// Origin
pub origin: H256,
/// Nonce
pub nonce: u64,
/// Commands
pub commands: BoundedVec<CommandWrapper, ConstU32<MAX_COMMANDS>>,
}
}

pub const MAX_COMMANDS: u32 = 8;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ use parachains_common::{
use snowbridge_core::{
outbound::{
v1::{Command, Fee},
v2::InboundMessage,
v2::abi::InboundMessage,
DryRunError,
},
AgentId, PricingParameters,
Expand Down

0 comments on commit 83b6ff8

Please sign in to comment.