Skip to content
This repository has been archived by the owner on Nov 20, 2024. It is now read-only.

Commit

Permalink
refactor: Restruct pallet-cosmos-x-bank-types msgs
Browse files Browse the repository at this point in the history
  • Loading branch information
code0xff committed Sep 10, 2024
1 parent 5d13288 commit fad9e92
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 27 deletions.
18 changes: 18 additions & 0 deletions frame/cosmos/x/bank/types/src/msgs/mod.rs
Original file line number Diff line number Diff line change
@@ -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;
Original file line number Diff line number Diff line change
Expand Up @@ -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<Coin>,
pub from_address: String,
pub to_address: String,
}
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct MsgSend {
pub amount: Vec<Coin>,
pub from_address: String,
pub to_address: String,
}

impl TryFrom<&Any> for MsgSend {
type Error = ();

fn try_from(any: &Any) -> Result<Self, Self::Error> {
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<String> {
vec![self.from_address.clone()]
}
fn try_from(any: &Any) -> Result<Self, Self::Error> {
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<String> {
vec![self.from_address.clone()]
}
}

impl LegacyMsg for MsgSend {
const AMINO_NAME: &'static str = "cosmos-sdk/MsgSend";
}

0 comments on commit fad9e92

Please sign in to comment.