1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
use std::{
fmt::{Debug, Display},
path::PathBuf,
str::FromStr,
};
use crate::error::DeployError;
use serde::Serialize;
use strum::{IntoEnumIterator, ParseError};
pub trait Msg: Debug + Send + Sync + erased_serde::Serialize {}
impl<T> Msg for T where T: Debug + Serialize + Send + Sync {}
impl Serialize for dyn Msg {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
erased_serde::serialize(self, serializer)
}
}
pub trait Contract:
Send + Sync + Debug + Display + FromStr<Err = ParseError> + IntoEnumIterator + 'static
{
fn name(&self) -> String;
fn bin_name(&self) -> String {
self.name()
}
fn admin(&self) -> String;
fn execute(&self) -> anyhow::Result<Box<dyn Msg>> {
Err(DeployError::TraitNotImplemented.into())
}
fn query(&self) -> anyhow::Result<Box<dyn Msg>> {
Err(DeployError::TraitNotImplemented.into())
}
fn cw20_send(&self) -> anyhow::Result<Box<dyn Msg>> {
Err(DeployError::TraitNotImplemented.into())
}
fn instantiate_msg(&self) -> Option<Box<dyn Msg>>;
fn external_instantiate_msgs(&self) -> Vec<ExternalInstantiate<Box<dyn Msg>>> {
vec![]
}
fn migrate_msg(&self) -> Option<Box<dyn Msg>> {
None
}
fn set_config_msg(&self) -> Option<Box<dyn Msg>> {
None
}
fn set_up_msgs(&self) -> Vec<Box<dyn Msg>> {
vec![]
}
fn path(&self) -> PathBuf {
PathBuf::from(format!("contracts/{}", self.name()))
}
}
#[derive(Debug, Clone)]
pub struct ExternalInstantiate<T> {
pub msg: T,
pub code_id: u64,
pub name: String,
}
impl<T> From<ExternalInstantiate<T>> for ExternalInstantiate<Box<dyn Msg>>
where
T: Msg + Clone + 'static,
{
fn from(msg: ExternalInstantiate<T>) -> Self {
ExternalInstantiate {
msg: Box::new(msg.msg),
code_id: msg.code_id,
name: msg.name,
}
}
}