From fad9e92c781eaf2f93ed63cdd7519d8a6d810e50 Mon Sep 17 00:00:00 2001 From: code0xff Date: Tue, 10 Sep 2024 16:41:15 +0900 Subject: [PATCH] refactor: Restruct pallet-cosmos-x-bank-types msgs --- frame/cosmos/x/bank/types/src/msgs/mod.rs | 18 +++++++ .../types/src/{msgs.rs => msgs/msg_send.rs} | 50 +++++++++---------- 2 files changed, 41 insertions(+), 27 deletions(-) create mode 100644 frame/cosmos/x/bank/types/src/msgs/mod.rs rename frame/cosmos/x/bank/types/src/{msgs.rs => msgs/msg_send.rs} (56%) diff --git a/frame/cosmos/x/bank/types/src/msgs/mod.rs b/frame/cosmos/x/bank/types/src/msgs/mod.rs new file mode 100644 index 0000000..30f5c11 --- /dev/null +++ b/frame/cosmos/x/bank/types/src/msgs/mod.rs @@ -0,0 +1,18 @@ +// This file is part of Horizon. + +// Copyright (C) 2023 Haderech Pte. Ltd. +// SPDX-License-Identifier: Apache-2.0 + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +pub mod msg_send; diff --git a/frame/cosmos/x/bank/types/src/msgs.rs b/frame/cosmos/x/bank/types/src/msgs/msg_send.rs similarity index 56% rename from frame/cosmos/x/bank/types/src/msgs.rs rename to frame/cosmos/x/bank/types/src/msgs/msg_send.rs index 1cb50af..d8a82bd 100644 --- a/frame/cosmos/x/bank/types/src/msgs.rs +++ b/frame/cosmos/x/bank/types/src/msgs/msg_send.rs @@ -21,36 +21,32 @@ use pallet_cosmos_types::{coin::Coin, tx_msgs::Msg}; use pallet_cosmos_x_auth_migrations::legacytx::stdsign::LegacyMsg; use serde::{Deserialize, Serialize}; -pub mod msg_send { - use super::*; - - #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] - pub struct MsgSend { - pub amount: Vec, - pub from_address: String, - pub to_address: String, - } +#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] +pub struct MsgSend { + pub amount: Vec, + pub from_address: String, + pub to_address: String, +} - impl TryFrom<&Any> for MsgSend { - type Error = (); - - fn try_from(any: &Any) -> Result { - let msg = bank::v1beta1::MsgSend::decode(&mut &*any.value).map_err(|_| ())?; - Ok(Self { - amount: msg.amount.iter().map(Into::into).collect(), - from_address: msg.from_address, - to_address: msg.to_address, - }) - } - } +impl TryFrom<&Any> for MsgSend { + type Error = (); - impl Msg for MsgSend { - fn get_signers(self) -> Vec { - vec![self.from_address.clone()] - } + fn try_from(any: &Any) -> Result { + let msg = bank::v1beta1::MsgSend::decode(&mut &*any.value).map_err(|_| ())?; + Ok(Self { + amount: msg.amount.iter().map(Into::into).collect(), + from_address: msg.from_address, + to_address: msg.to_address, + }) } +} - impl LegacyMsg for MsgSend { - const AMINO_NAME: &'static str = "cosmos-sdk/MsgSend"; +impl Msg for MsgSend { + fn get_signers(self) -> Vec { + vec![self.from_address.clone()] } } + +impl LegacyMsg for MsgSend { + const AMINO_NAME: &'static str = "cosmos-sdk/MsgSend"; +}