@@ -49,100 +49,12 @@ impl<'a> CwIbcConnection<'a> {
49
49
info : MessageInfo ,
50
50
admin : Addr ,
51
51
) -> Result < Response , ContractError > {
52
- if admin. to_string ( ) . is_empty ( ) {
53
- return Err ( ContractError :: AdminAddressCannotBeNull { } ) ;
54
- }
55
-
56
- let owner = self
57
- . owner ( )
58
- . load ( store)
59
- . map_err ( |_| ContractError :: Unauthorized { } ) ?;
60
-
61
- if info. sender != owner {
62
- return Err ( ContractError :: Unauthorized { } ) ;
63
- }
64
52
self . admin ( ) . save ( store, & admin) ?;
65
53
Ok ( Response :: new ( )
66
54
. add_attribute ( "method" , "add_admin" )
67
55
. add_attribute ( "admin" , admin. to_string ( ) ) )
68
56
}
69
57
70
- /// This function updates the admin address of a contract if the caller is the owner and the new
71
- /// address is valid.
72
- ///
73
- /// Arguments:
74
- ///
75
- /// * `store`: A mutable reference to a trait object of type `dyn Storage`. This is used to interact
76
- /// with the contract's storage.
77
- /// * `info`: MessageInfo is a struct that contains information about the message being executed, such
78
- /// as the sender's address, the amount of tokens being sent, and the gas limit. It is used to ensure
79
- /// that only authorized parties can execute certain functions and to handle payment transactions.
80
- /// * `new_admin`: A string representing the new address of the admin that will replace the current
81
- /// admin.
82
- ///
83
- /// Returns:
84
- ///
85
- /// a `Result<Response, ContractError>`. If the function executes successfully, it returns a `Response`
86
- /// object with attributes "action" and "admin". If there is an error, it returns a `ContractError`
87
- /// object with a specific error message.
88
- pub fn update_admin (
89
- & self ,
90
- store : & mut dyn Storage ,
91
- info : MessageInfo ,
92
- new_admin : Addr ,
93
- ) -> Result < Response , ContractError > {
94
- if new_admin. to_string ( ) . is_empty ( ) {
95
- return Err ( ContractError :: AdminAddressCannotBeNull { } ) ;
96
- }
97
-
98
- if !new_admin. to_string ( ) . chars ( ) . all ( |x| x. is_alphanumeric ( ) ) {
99
- return Err ( ContractError :: InvalidAddress {
100
- address : new_admin. to_string ( ) ,
101
- } ) ;
102
- }
103
-
104
- self . ensure_admin ( store, info. sender ) ?;
105
-
106
- self . admin ( )
107
- . update ( store, |mut current_admin| -> Result < _ , ContractError > {
108
- if current_admin == new_admin {
109
- Err ( ContractError :: AdminAlreadyExist )
110
- } else {
111
- current_admin = new_admin. clone ( ) ;
112
- Ok ( current_admin)
113
- }
114
- } ) ?;
115
-
116
- Ok ( Response :: new ( )
117
- . add_attribute ( "action" , "update admin" )
118
- . add_attribute ( "admin" , new_admin. to_string ( ) ) )
119
- }
120
-
121
- /// The code defines a function to remove an admin and another function to validate an address.
122
- ///
123
- /// Arguments:
124
- ///
125
- /// * `store`: `store` is a mutable reference to a trait object of type `Storage`. It is used to
126
- /// interact with the contract's storage and modify its state.
127
- /// * `info`: `info` is a parameter of type `MessageInfo` which contains information about the message
128
- /// being executed, such as the sender's address, the amount of coins being sent, and the gas limit. It
129
- /// is used in the `remove_admin` function to ensure that the sender is the owner of the
130
- ///
131
- /// Returns:
132
- ///
133
- /// The `remove_admin` function returns a `Result<Response, ContractError>` and the `validate_address`
134
- /// function returns a `Result<String, ContractError>`.
135
- pub fn remove_admin (
136
- & self ,
137
- store : & mut dyn Storage ,
138
- info : MessageInfo ,
139
- ) -> Result < Response , ContractError > {
140
- self . ensure_owner ( store, & info) ?;
141
-
142
- self . admin ( ) . remove ( store) ;
143
- Ok ( Response :: new ( ) . add_attribute ( "method" , "remove_admin" ) )
144
- }
145
-
146
58
pub fn validate_address ( api : & dyn Api , address : & str ) -> Result < Addr , ContractError > {
147
59
if !address. chars ( ) . all ( |x| x. is_alphanumeric ( ) ) {
148
60
return Err ( ContractError :: InvalidAddress {
0 commit comments