cosmrs/cosmwasm/
msg_migrate_contract.rs

1use crate::{proto, tx::Msg, AccountId, ErrorReport, Result};
2use std::convert::TryFrom;
3
4/// MsgMigrateContract runs a code upgrade/ downgrade for a smart contract
5#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Ord)]
6pub struct MsgMigrateContract {
7    /// Sender is the that actor that signed the messages
8    pub sender: AccountId,
9
10    /// Contract is the address of the smart contract
11    pub contract: AccountId,
12
13    /// CodeID references the new WASM code
14    pub code_id: u64,
15
16    /// Msg json encoded message to be passed to the contract on migration
17    pub msg: Vec<u8>,
18}
19
20impl Msg for MsgMigrateContract {
21    type Proto = proto::cosmwasm::wasm::v1::MsgMigrateContract;
22}
23
24impl TryFrom<proto::cosmwasm::wasm::v1::MsgMigrateContract> for MsgMigrateContract {
25    type Error = ErrorReport;
26
27    fn try_from(
28        proto: proto::cosmwasm::wasm::v1::MsgMigrateContract,
29    ) -> Result<MsgMigrateContract> {
30        Ok(MsgMigrateContract {
31            sender: proto.sender.parse()?,
32            contract: proto.contract.parse()?,
33            code_id: proto.code_id,
34            msg: proto.msg,
35        })
36    }
37}
38
39impl From<MsgMigrateContract> for proto::cosmwasm::wasm::v1::MsgMigrateContract {
40    fn from(msg: MsgMigrateContract) -> proto::cosmwasm::wasm::v1::MsgMigrateContract {
41        proto::cosmwasm::wasm::v1::MsgMigrateContract {
42            sender: msg.sender.to_string(),
43            contract: msg.contract.to_string(),
44            code_id: msg.code_id,
45            msg: msg.msg,
46        }
47    }
48}
49
50/// MsgMigrateContractResponse returns contract migration result data.
51#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Ord)]
52pub struct MsgMigrateContractResponse {
53    /// Data contains same raw bytes returned as data from the wasm contract.
54    /// (May be empty)
55    pub data: Vec<u8>,
56}
57
58impl Msg for MsgMigrateContractResponse {
59    type Proto = proto::cosmwasm::wasm::v1::MsgMigrateContractResponse;
60}
61
62impl TryFrom<proto::cosmwasm::wasm::v1::MsgMigrateContractResponse> for MsgMigrateContractResponse {
63    type Error = ErrorReport;
64
65    fn try_from(
66        proto: proto::cosmwasm::wasm::v1::MsgMigrateContractResponse,
67    ) -> Result<MsgMigrateContractResponse> {
68        Ok(MsgMigrateContractResponse { data: proto.data })
69    }
70}
71
72impl From<MsgMigrateContractResponse> for proto::cosmwasm::wasm::v1::MsgMigrateContractResponse {
73    fn from(
74        msg: MsgMigrateContractResponse,
75    ) -> proto::cosmwasm::wasm::v1::MsgMigrateContractResponse {
76        proto::cosmwasm::wasm::v1::MsgMigrateContractResponse { data: msg.data }
77    }
78}