-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathsettings.rs
More file actions
100 lines (87 loc) · 2.64 KB
/
settings.rs
File metadata and controls
100 lines (87 loc) · 2.64 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
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
use crate::types::{Asset, Error, FeeConfig};
use soroban_sdk::{Address, Env};
const RETENTION_PERIOD_KEY: &str = "period";
const BASE_KEY: &str = "base_asset";
const DECIMALS_KEY: &str = "decimals";
const RESOLUTION_KEY: &str = "resolution";
const RETENTION_KEY: &str = "retention";
const CACHE_SIZE_KEY: &str = "cache_size";
pub const XRF_TOKEN_ADDRESS: &str = "CBLLEW7HD2RWATVSMLAGWM4G3WCHSHDJ25ALP4DI6LULV5TU35N2CIZA";
const DEFAULT_RETENTION_FEE: i128 = 100_000_000;
#[inline]
pub fn init(
e: &Env,
base: &Asset,
decimals: u32,
resolution: u32,
history_retention_period: u64,
cache_size: u32,
fee_config: &FeeConfig,
) {
//do not allow to initialize more than once
if e.storage().instance().has(&RETENTION_PERIOD_KEY) {
e.panic_with_error(Error::AlreadyInitialized);
}
let instance = e.storage().instance();
//initialized only once and cannot be changed in the future
instance.set(&BASE_KEY, base);
instance.set(&DECIMALS_KEY, &decimals);
set_resolution(e, resolution);
set_history_retention_period(e, history_retention_period);
set_cache_size(e, cache_size);
set_fee_config(e, fee_config);
}
#[inline]
pub fn get_base_asset(e: &Env) -> Asset {
e.storage().instance().get(&BASE_KEY).unwrap()
}
#[inline]
pub fn get_decimals(e: &Env) -> u32 {
e.storage().instance().get(&DECIMALS_KEY).unwrap()
}
#[inline]
pub fn get_resolution(e: &Env) -> u32 {
e.storage().instance().get(&RESOLUTION_KEY).unwrap()
}
#[inline]
pub fn set_resolution(e: &Env, resolution: u32) {
e.storage().instance().set(&RESOLUTION_KEY, &resolution)
}
#[inline]
pub fn get_history_retention_period(e: &Env) -> u64 {
e.storage()
.instance()
.get(&RETENTION_PERIOD_KEY)
.unwrap_or_default()
}
#[inline]
pub fn set_history_retention_period(e: &Env, retention_period: u64) {
e.storage()
.instance()
.set(&RETENTION_PERIOD_KEY, &retention_period);
}
#[inline]
pub fn get_cache_size(e: &Env) -> u32 {
e.storage().instance().get(&CACHE_SIZE_KEY).unwrap_or(2)
}
#[inline]
pub fn set_cache_size(e: &Env, cache_size: u32) {
e.storage().instance().set(&CACHE_SIZE_KEY, &cache_size);
}
#[inline]
pub fn set_fee_config(e: &Env, fee_config: &FeeConfig) {
e.storage().instance().set(&RETENTION_KEY, &fee_config);
}
#[inline]
pub fn get_fee_config(e: &Env) -> FeeConfig {
e.storage()
.instance()
.get(&RETENTION_KEY)
.unwrap_or_else(|| {
FeeConfig::Some((
// by default - XRF tokens with 1 XRF base cost
Address::from_str(e, XRF_TOKEN_ADDRESS),
DEFAULT_RETENTION_FEE,
))
})
}