Skip to content

Commit

Permalink
gateway: Move GatewayMessage to gateway pallet
Browse files Browse the repository at this point in the history
  • Loading branch information
cdamian committed Jul 31, 2024
1 parent 1c5c77a commit 8379adb
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 26 deletions.
1 change: 1 addition & 0 deletions libs/traits/src/liquidity_pools.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ pub trait MessageQueue {
fn submit(msg: Self::Message) -> DispatchResult;
}

/// The trait required for processing queued messages.
pub trait MessageProcessor {
/// The message type.
type Message;
Expand Down
6 changes: 6 additions & 0 deletions libs/types/src/domain_address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ pub enum DomainAddress {
EVM(EVMChainId, [u8; 20]),
}

impl Default for DomainAddress {
fn default() -> Self {
DomainAddress::Centrifuge([0; 32])
}
}

impl DomainAddress {
pub fn evm(chain_id: EVMChainId, address: [u8; 20]) -> Self {
Self::EVM(chain_id, address)
Expand Down
17 changes: 0 additions & 17 deletions libs/types/src/gateway.rs

This file was deleted.

1 change: 0 additions & 1 deletion libs/types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ pub mod domain_address;
pub mod epoch;
pub mod fee_keys;
pub mod fixed_point;
pub mod gateway;
pub mod ids;
pub mod investments;
pub mod locations;
Expand Down
8 changes: 4 additions & 4 deletions pallets/liquidity-pools-gateway/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,10 @@ use cfg_traits::{
},
TryConvert,
};
use cfg_types::{
domain_address::{Domain, DomainAddress},
gateway::GatewayMessage,
};
use cfg_types::domain_address::{Domain, DomainAddress};
use frame_support::{dispatch::DispatchResult, pallet_prelude::*, PalletError};
use frame_system::pallet_prelude::OriginFor;
use message::GatewayMessage;
use orml_traits::GetByKey;
pub use pallet::*;
use parity_scale_codec::{EncodeLike, FullCodec};
Expand All @@ -51,6 +49,8 @@ use crate::weights::WeightInfo;
mod origin;
pub use origin::*;

pub mod message;

pub mod weights;

#[cfg(test)]
Expand Down
25 changes: 25 additions & 0 deletions pallets/liquidity-pools-gateway/src/message.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
use cfg_types::domain_address::{Domain, DomainAddress};
use frame_support::pallet_prelude::{Decode, Encode, MaxEncodedLen, TypeInfo};

/// Message type used by the LP gateway.
#[derive(Debug, Encode, Decode, Clone, Eq, MaxEncodedLen, PartialEq, TypeInfo)]
pub enum GatewayMessage<AccountId, Message> {
Inbound {
domain_address: DomainAddress,
message: Message,
},
Outbound {
sender: AccountId,
destination: Domain,
message: Message,
},
}

impl<AccountId, Message: Default> Default for GatewayMessage<AccountId, Message> {
fn default() -> Self {
GatewayMessage::Inbound {
domain_address: Default::default(),
message: Default::default(),
}
}
}
4 changes: 2 additions & 2 deletions pallets/liquidity-pools-gateway/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ use cfg_mocks::{
RouterMock,
};
use cfg_traits::liquidity_pools::test_util::Message;
use cfg_types::{domain_address::DomainAddress, gateway::GatewayMessage};
use cfg_types::domain_address::DomainAddress;
use frame_support::{derive_impl, weights::constants::RocksDbWeight};
use runtime_common::origin::EnsureAccountOrRoot;
use sp_core::{crypto::AccountId32, H256};
use sp_runtime::traits::IdentityLookup;

use crate::{pallet as pallet_liquidity_pools_gateway, EnsureLocal};
use crate::{pallet as pallet_liquidity_pools_gateway, EnsureLocal, GatewayMessage};

pub const LENGTH_SOURCE_CHAIN: usize = 10;
pub const SOURCE_CHAIN: [u8; LENGTH_SOURCE_CHAIN] = *b"ethereum-2";
Expand Down
20 changes: 18 additions & 2 deletions pallets/liquidity-pools-gateway/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ use cfg_mocks::*;
use cfg_traits::liquidity_pools::{
test_util::Message, LPEncoding, MessageProcessor, OutboundMessageHandler,
};
use cfg_types::{domain_address::*, gateway::GatewayMessage};
use cfg_types::domain_address::*;
use frame_support::{
assert_noop, assert_ok, dispatch::PostDispatchInfo, pallet_prelude::Pays, weights::Weight,
};
use parity_scale_codec::MaxEncodedLen;
use sp_core::{bounded::BoundedVec, crypto::AccountId32, ByteArray, H160};
use sp_runtime::{DispatchError, DispatchError::BadOrigin, DispatchErrorWithPostInfo};

Expand All @@ -14,6 +15,7 @@ use super::{
origin::*,
pallet::*,
};
use crate::GatewayMessage;

mod utils {
use super::*;
Expand Down Expand Up @@ -1083,7 +1085,21 @@ mod message_processor_impl {
Err(err)
});

assert_noop!(LiquidityPoolsGateway::process(gateway_message), err);
let expected_error = DispatchErrorWithPostInfo {
post_info: PostDispatchInfo {
actual_weight: Some(Weight::from_parts(
0,
Message::max_encoded_len() as u64,
)),
pays_fee: Pays::Yes,
},
error: err,
};

assert_noop!(
LiquidityPoolsGateway::process(gateway_message),
expected_error
);
});
}
}
Expand Down

0 comments on commit 8379adb

Please sign in to comment.