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

Commit

Permalink
refactor: Refactor pallet-cosmos-x-wasm-types
Browse files Browse the repository at this point in the history
  • Loading branch information
code0xff committed Sep 10, 2024
1 parent fc4f87f commit 176d010
Show file tree
Hide file tree
Showing 8 changed files with 299 additions and 217 deletions.
2 changes: 0 additions & 2 deletions frame/cosmos/x/auth/signing/src/sign_verifiable_tx/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ use cosmos_sdk_proto::cosmos::tx::v1beta1::Tx;

pub trait SigVerifiableTx {
fn get_signers(tx: &Tx) -> Result<Vec<String>, SigVerifiableTxError>;

fn fee_payer(tx: &Tx) -> Result<String, SigVerifiableTxError>;

fn sequence(tx: &Tx) -> Result<u64, SigVerifiableTxError>;
}
215 changes: 0 additions & 215 deletions frame/cosmos/x/wasm/types/src/tx.rs

This file was deleted.

22 changes: 22 additions & 0 deletions frame/cosmos/x/wasm/types/src/tx/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// 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_execute_contract;
pub mod msg_instantiate_contract2;
pub mod msg_migrate_contract;
pub mod msg_store_code;
pub mod msg_update_admin;
54 changes: 54 additions & 0 deletions frame/cosmos/x/wasm/types/src/tx/msg_execute_contract.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// 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.

use alloc::{string::String, vec, vec::Vec};
use cosmos_sdk_proto::{cosmwasm::wasm, prost::Message, Any};
use pallet_cosmos_types::{coin::Coin, tx_msgs::Msg};
use pallet_cosmos_x_auth_migrations::legacytx::stdsign::LegacyMsg;
use serde::{Deserialize, Serialize};

#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct MsgExecuteContract {
pub contract: String,
pub funds: Vec<Coin>,
pub msg: Vec<u8>,
pub sender: String,
}

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

fn try_from(any: &Any) -> Result<Self, Self::Error> {
let msg = wasm::v1::MsgExecuteContract::decode(&mut &*any.value).map_err(|_| ())?;
Ok(Self {
contract: msg.contract,
funds: msg.funds.iter().map(Into::into).collect(),
msg: msg.msg,
sender: msg.sender,
})
}
}

impl LegacyMsg for MsgExecuteContract {
const AMINO_NAME: &'static str = "wasm/MsgExecuteContract";
}

impl Msg for MsgExecuteContract {
fn get_signers(self) -> Vec<String> {
vec![self.sender.clone()]
}
}
62 changes: 62 additions & 0 deletions frame/cosmos/x/wasm/types/src/tx/msg_instantiate_contract2.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// 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.

use alloc::{string::String, vec, vec::Vec};
use cosmos_sdk_proto::{cosmwasm::wasm, prost::Message, Any};
use pallet_cosmos_types::{coin::Coin, tx_msgs::Msg};
use pallet_cosmos_x_auth_migrations::legacytx::stdsign::LegacyMsg;
use serde::{Deserialize, Serialize};

#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct MsgInstantiateContract2 {
pub admin: String,
pub code_id: u64,
pub fix_msg: bool,
pub funds: Vec<Coin>,
pub label: String,
pub msg: Vec<u8>,
pub salt: Vec<u8>,
pub sender: String,
}

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

fn try_from(any: &Any) -> Result<Self, Self::Error> {
let msg = wasm::v1::MsgInstantiateContract2::decode(&mut &*any.value).map_err(|_| ())?;
Ok(Self {
admin: msg.admin,
code_id: msg.code_id,
fix_msg: msg.fix_msg,
funds: msg.funds.iter().map(Into::into).collect(),
label: msg.label,
msg: msg.msg,
salt: msg.salt,
sender: msg.sender,
})
}
}

impl LegacyMsg for MsgInstantiateContract2 {
const AMINO_NAME: &'static str = "wasm/MsgInstantiateContract2";
}

impl Msg for MsgInstantiateContract2 {
fn get_signers(self) -> Vec<String> {
vec![self.sender.clone()]
}
}
Loading

0 comments on commit 176d010

Please sign in to comment.