1
1
use std:: num:: NonZeroU32 ;
2
2
3
3
use cosmwasm_std:: {
4
- entry_point , from_json , Addr , CosmosMsg , Deps , DepsMut , Env , Event , MessageInfo , Order ,
5
- Response , StdError ,
4
+ from_json , to_json_binary , Addr , Binary , CosmosMsg , Deps , DepsMut , Env , Event , MessageInfo ,
5
+ Order , Response , StdError ,
6
6
} ;
7
7
use depolama:: { self , StorageExt } ;
8
8
use frissitheto:: { InitStateVersionError , UpgradeError , UpgradeMsg } ;
9
9
use ucs03_zkgmable:: Zkgmable ;
10
10
11
11
use crate :: {
12
- msg:: { ExecuteMsg , InitMsg , MigrateMsg } ,
12
+ msg:: { ExecuteMsg , InitMsg , MigrateMsg , QueryMsg } ,
13
13
state:: { Admins , Zkgm } ,
14
14
types:: { Admin , LocalAdmin , RemoteAdmin } ,
15
15
} ;
@@ -21,27 +21,35 @@ pub mod types;
21
21
#[ cfg( test) ]
22
22
mod tests;
23
23
24
- fn ensure_remote_admin ( deps : Deps , info : & MessageInfo , admin : & RemoteAdmin ) -> Result < ( ) , Error > {
24
+ pub fn ensure_remote_admin (
25
+ deps : Deps ,
26
+ info : & MessageInfo ,
27
+ admin : & RemoteAdmin ,
28
+ ) -> Result < ( ) , ContractError > {
25
29
// for remote admins, first ensure that info.sender is zkgm
26
30
if info. sender
27
31
!= deps
28
32
. storage
29
33
. maybe_read_item :: < Zkgm > ( ) ?
30
- . ok_or ( Error :: ZkgmNotConfigured ) ?
34
+ . ok_or ( ContractError :: ZkgmNotConfigured ) ?
31
35
{
32
- return Err ( Error :: OnlyZkgm {
36
+ return Err ( ContractError :: OnlyZkgm {
33
37
sender : info. sender . clone ( ) ,
34
38
} ) ;
35
39
}
36
40
37
41
deps. storage
38
42
. maybe_read :: < Admins > ( & Admin :: Remote ( admin. clone ( ) ) ) ?
39
- . ok_or_else ( || Error :: OnlyAdmin {
43
+ . ok_or_else ( || ContractError :: OnlyAdmin {
40
44
sender : Admin :: Remote ( admin. clone ( ) ) ,
41
45
} )
42
46
}
43
47
44
- fn ensure_local_admin_or_self ( deps : Deps , env : & Env , info : & MessageInfo ) -> Result < String , Error > {
48
+ pub fn ensure_local_admin_or_self (
49
+ deps : Deps ,
50
+ env : & Env ,
51
+ info : & MessageInfo ,
52
+ ) -> Result < String , ContractError > {
45
53
// allow reentrant calls into this contract
46
54
if info. sender != env. contract . address {
47
55
let local_admin = Admin :: Local ( LocalAdmin {
@@ -50,7 +58,7 @@ fn ensure_local_admin_or_self(deps: Deps, env: &Env, info: &MessageInfo) -> Resu
50
58
51
59
deps. storage
52
60
. maybe_read :: < Admins > ( & local_admin) ?
53
- . ok_or_else ( || Error :: OnlyAdmin {
61
+ . ok_or_else ( || ContractError :: OnlyAdmin {
54
62
sender : Admin :: Local ( LocalAdmin {
55
63
address : info. sender . to_string ( ) ,
56
64
} ) ,
@@ -62,7 +70,7 @@ fn ensure_local_admin_or_self(deps: Deps, env: &Env, info: &MessageInfo) -> Resu
62
70
}
63
71
}
64
72
65
- fn init ( deps : DepsMut , msg : InitMsg ) -> Response {
73
+ pub fn init ( deps : DepsMut , msg : InitMsg ) -> Response {
66
74
match msg {
67
75
InitMsg :: Zkgm {
68
76
zkgm,
@@ -93,25 +101,25 @@ fn init(deps: DepsMut, msg: InitMsg) -> Response {
93
101
Response :: default ( )
94
102
}
95
103
96
- #[ entry_point]
104
+ #[ cfg_attr ( not ( feature = "library" ) , cosmwasm_std :: entry_point) ]
97
105
pub fn instantiate (
98
106
mut deps : DepsMut ,
99
107
_: Env ,
100
108
_: MessageInfo ,
101
109
msg : InitMsg ,
102
- ) -> Result < Response , Error > {
110
+ ) -> Result < Response , ContractError > {
103
111
frissitheto:: init_state_version ( & mut deps, const { NonZeroU32 :: new ( 1 ) . unwrap ( ) } ) ?;
104
112
105
113
Ok ( init ( deps, msg) )
106
114
}
107
115
108
- #[ entry_point]
116
+ #[ cfg_attr ( not ( feature = "library" ) , cosmwasm_std :: entry_point) ]
109
117
pub fn execute (
110
118
deps : DepsMut ,
111
119
env : Env ,
112
120
info : MessageInfo ,
113
121
msg : ExecuteMsg ,
114
- ) -> Result < Response , Error > {
122
+ ) -> Result < Response , ContractError > {
115
123
match msg {
116
124
ExecuteMsg :: SetZkgm ( zkgm) => {
117
125
let actor = ensure_local_admin_or_self ( deps. as_ref ( ) , & env, & info) ?;
@@ -155,7 +163,7 @@ pub fn execute(
155
163
. collect :: < Result < Vec < _ > , _ > > ( ) ?
156
164
. is_empty ( )
157
165
{
158
- Err ( Error :: OneAdminRequired )
166
+ Err ( ContractError :: OneAdminRequired )
159
167
} else {
160
168
Ok ( Response :: new ( ) . add_events ( maybe_event) )
161
169
}
@@ -184,16 +192,29 @@ pub fn execute(
184
192
] ) )
185
193
. add_messages ( from_json :: < Vec < CosmosMsg > > ( & on_zkgm. message ) ?) )
186
194
}
187
- ExecuteMsg :: Zkgmable ( Zkgmable :: OnIntentZkgm ( _) ) => Err ( Error :: IntentsNotSupported ) ,
195
+ ExecuteMsg :: Zkgmable ( Zkgmable :: OnIntentZkgm ( _) ) => Err ( ContractError :: IntentsNotSupported ) ,
188
196
}
189
197
}
190
198
191
- #[ entry_point]
199
+ #[ cfg_attr( not( feature = "library" ) , cosmwasm_std:: entry_point) ]
200
+ pub fn query ( deps : Deps , _: Env , msg : QueryMsg ) -> Result < Binary , ContractError > {
201
+ match msg {
202
+ QueryMsg :: Admins { } => Ok ( to_json_binary (
203
+ & deps
204
+ . storage
205
+ . iter :: < Admins > ( Order :: Ascending )
206
+ . map ( |r| r. map ( |( admin, _) | admin) )
207
+ . collect :: < Result < Vec < _ > , _ > > ( ) ?,
208
+ ) ?) ,
209
+ }
210
+ }
211
+
212
+ #[ cfg_attr( not( feature = "library" ) , cosmwasm_std:: entry_point) ]
192
213
pub fn migrate (
193
214
deps : DepsMut ,
194
215
_: Env ,
195
216
msg : UpgradeMsg < InitMsg , MigrateMsg > ,
196
- ) -> Result < Response , Error > {
217
+ ) -> Result < Response , ContractError > {
197
218
msg. run (
198
219
deps,
199
220
|deps, init_msg| {
@@ -205,7 +226,7 @@ pub fn migrate(
205
226
}
206
227
207
228
#[ derive( Debug , PartialEq , thiserror:: Error ) ]
208
- pub enum Error {
229
+ pub enum ContractError {
209
230
#[ error( transparent) ]
210
231
Std ( #[ from] StdError ) ,
211
232
@@ -215,7 +236,7 @@ pub enum Error {
215
236
#[ error( "init state version error: {0}" ) ]
216
237
InitStateVersion ( #[ from] InitStateVersionError ) ,
217
238
218
- #[ error( "sender {sender} is a configured admin" ) ]
239
+ #[ error( "sender {sender} is not a configured admin" ) ]
219
240
OnlyAdmin { sender : Admin } ,
220
241
221
242
#[ error( "sender {sender} is not zkgm" ) ]
0 commit comments