forked from Cylo-Traders/Agrocylo-PIP
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadmin.rs
More file actions
52 lines (42 loc) · 1.45 KB
/
Copy pathadmin.rs
File metadata and controls
52 lines (42 loc) · 1.45 KB
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
use crate::{events, storage};
use soroban_sdk::{Address, Env};
pub fn initialize(env: &Env, admin: &Address) {
if storage::has_admin(env) {
panic!("admin already initialized");
}
admin.require_auth();
storage::set_admin(env, admin);
storage::extend_instance_ttl(env);
events::admin_initialized(env, admin.clone());
}
pub fn require_admin(env: &Env) {
let admin = storage::get_admin(env);
admin.require_auth();
}
pub fn update_admin(env: &Env, new_admin: &Address) {
require_admin(env);
let old_admin = storage::get_admin(env);
storage::set_admin(env, new_admin);
storage::extend_instance_ttl(env);
events::admin_updated(env, old_admin, new_admin.clone());
}
pub fn get_admin(env: &Env) -> Address {
storage::get_admin(env)
}
pub fn approve_contract(env: &Env, contract: &Address) {
require_admin(env);
let admin = storage::get_admin(env);
storage::set_contract_approved(env, contract, true);
storage::extend_instance_ttl(env);
events::contract_approved(env, admin, contract.clone());
}
pub fn revoke_contract(env: &Env, contract: &Address) {
require_admin(env);
let admin = storage::get_admin(env);
storage::set_contract_approved(env, contract, false);
storage::extend_instance_ttl(env);
events::contract_revoked(env, admin, contract.clone());
}
pub fn is_contract_approved(env: &Env, contract: &Address) -> bool {
storage::is_contract_approved(env, contract)
}