-
Notifications
You must be signed in to change notification settings - Fork 181
/
helpers.rs
154 lines (143 loc) · 3.74 KB
/
helpers.rs
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
use std::marker::PhantomData;
use crate::traits::{Cw721Calls, Cw721CustomMsg, Cw721State};
use crate::{
DefaultOptionalCollectionExtension, DefaultOptionalCollectionExtensionMsg,
DefaultOptionalNftExtension, DefaultOptionalNftExtensionMsg,
};
use cosmwasm_schema::cw_serde;
use cosmwasm_std::{Addr, Empty};
/// Returns "empty" if the string is empty, otherwise the string itself
pub fn value_or_empty(value: &str) -> String {
if value.is_empty() {
"empty".to_string()
} else {
value.to_string()
}
}
#[deprecated(
since = "0.19.0",
note = "Please use `DefaultCw721Helper`, `EmptyCw721Helper`, or `Cw721Helper` instead"
)]
pub type Cw721Contract = DefaultCw721Helper;
/// Opionated version of generic `Cw721Helper` with default extensions.
#[cw_serde]
pub struct DefaultCw721Helper(
pub Addr,
pub PhantomData<DefaultOptionalNftExtension>,
pub PhantomData<DefaultOptionalNftExtensionMsg>,
pub PhantomData<DefaultOptionalCollectionExtension>,
pub PhantomData<DefaultOptionalCollectionExtensionMsg>,
pub PhantomData<Empty>,
pub PhantomData<Empty>,
);
impl DefaultCw721Helper {
pub fn new(addr: Addr) -> Self {
DefaultCw721Helper(
addr,
PhantomData,
PhantomData,
PhantomData,
PhantomData,
PhantomData,
PhantomData,
)
}
}
impl
Cw721Calls<
DefaultOptionalNftExtension,
DefaultOptionalNftExtensionMsg,
DefaultOptionalCollectionExtension,
DefaultOptionalCollectionExtensionMsg,
Empty,
Empty,
> for DefaultCw721Helper
{
fn addr(&self) -> Addr {
self.0.clone()
}
}
/// Opionated version of generic `Cw721Helper` with empty extensions.
#[cw_serde]
pub struct EmptyCw721Helper(
pub Addr,
pub PhantomData<Empty>,
pub PhantomData<Empty>,
pub PhantomData<Empty>,
pub PhantomData<Empty>,
pub PhantomData<Empty>,
pub PhantomData<Empty>,
);
impl EmptyCw721Helper {
pub fn new(addr: Addr) -> Self {
EmptyCw721Helper(
addr,
PhantomData,
PhantomData,
PhantomData,
PhantomData,
PhantomData,
PhantomData,
)
}
}
impl Cw721Calls<Empty, Empty, Empty, Empty, Empty, Empty> for EmptyCw721Helper {
fn addr(&self) -> Addr {
self.0.clone()
}
}
/// `Cw721Helper` with generic extionsions. See `DefaultCw721Helper` and `EmptyCw721Helper` for
/// specific use cases.
#[cw_serde]
pub struct Cw721Helper<
TNftExtension,
TNftExtensionMsg,
TCollectionExtension,
TCollectionExtensionMsg,
TExtensionMsg,
TExtensionQueryMsg,
>(
pub Addr,
pub PhantomData<TNftExtension>,
pub PhantomData<TNftExtensionMsg>,
pub PhantomData<TCollectionExtension>,
pub PhantomData<TCollectionExtensionMsg>,
pub PhantomData<TExtensionMsg>,
pub PhantomData<TExtensionQueryMsg>,
);
impl<
TNftExtension,
TNftExtensionMsg,
TCollectionExtension,
TCollectionExtensionMsg,
TExtensionMsg,
TExtensionQueryMsg,
>
Cw721Calls<
TNftExtension,
TNftExtensionMsg,
TCollectionExtension,
TCollectionExtensionMsg,
TExtensionMsg,
TExtensionQueryMsg,
>
for Cw721Helper<
TNftExtension,
TNftExtensionMsg,
TCollectionExtension,
TCollectionExtensionMsg,
TExtensionMsg,
TExtensionQueryMsg,
>
where
TNftExtensionMsg: Cw721CustomMsg,
TNftExtension: Cw721State,
TCollectionExtension: Cw721State,
TCollectionExtensionMsg: Cw721CustomMsg,
TExtensionMsg: Cw721CustomMsg,
TExtensionQueryMsg: Cw721CustomMsg,
{
fn addr(&self) -> Addr {
self.0.clone()
}
}