@layerzerolabs/protocol-stellar-v2 0.2.8 → 0.2.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +443 -302
- package/.turbo/turbo-lint.log +118 -96
- package/.turbo/turbo-test.log +853 -731
- package/Cargo.lock +120 -37
- package/Cargo.toml +8 -5
- package/contracts/common-macros/src/contract_impl.rs +44 -0
- package/contracts/common-macros/src/lib.rs +86 -40
- package/contracts/common-macros/src/ownable.rs +24 -32
- package/contracts/common-macros/src/storage.rs +95 -120
- package/contracts/common-macros/src/tests/contract_impl.rs +289 -0
- package/contracts/common-macros/src/tests/mod.rs +9 -0
- package/contracts/common-macros/src/tests/ownable.rs +151 -0
- package/contracts/common-macros/src/tests/snapshots/common_macros__tests__contract_impl__snapshot_generated_contract_impl_code.snap +85 -0
- package/contracts/common-macros/src/tests/snapshots/common_macros__tests__ownable__snapshot_generated_ownable_code.snap +30 -0
- package/contracts/common-macros/src/tests/snapshots/common_macros__tests__ownable__snapshot_only_owner_preserves_function_signature.snap +9 -0
- package/contracts/common-macros/src/tests/snapshots/common_macros__tests__storage__snapshot_generated_storage_code.snap +1072 -0
- package/contracts/common-macros/src/tests/snapshots/common_macros__tests__ttl_configurable__snapshot_generated_ttl_configurable_code.snap +45 -0
- package/contracts/common-macros/src/tests/storage.rs +485 -0
- package/contracts/common-macros/src/tests/test_helpers.rs +93 -0
- package/contracts/common-macros/src/tests/ttl_configurable.rs +34 -0
- package/contracts/common-macros/src/ttl_configurable.rs +31 -14
- package/contracts/common-macros/src/utils.rs +27 -0
- package/contracts/endpoint-v2/ARCHITECTURE.md +4 -4
- package/contracts/endpoint-v2/src/endpoint_v2.rs +18 -15
- package/contracts/endpoint-v2/src/interfaces/message_lib.rs +2 -3
- package/contracts/endpoint-v2/src/interfaces/message_lib_manager.rs +5 -3
- package/contracts/endpoint-v2/src/interfaces/messaging_channel.rs +2 -2
- package/contracts/endpoint-v2/src/interfaces/messaging_composer.rs +2 -2
- package/contracts/endpoint-v2/src/interfaces/send_lib.rs +4 -4
- package/contracts/endpoint-v2/src/lib.rs +6 -5
- package/contracts/endpoint-v2/src/message_lib_manager.rs +14 -6
- package/contracts/endpoint-v2/src/messaging_channel.rs +6 -2
- package/contracts/endpoint-v2/src/messaging_composer.rs +6 -2
- package/contracts/endpoint-v2/src/storage.rs +10 -7
- package/contracts/endpoint-v2/src/tests/endpoint_v2/pay_messaging_fees.rs +16 -16
- package/contracts/endpoint-v2/src/tests/endpoint_v2/ttl_config.rs +46 -46
- package/contracts/endpoint-v2/src/tests/mock.rs +2 -2
- package/contracts/endpoint-v2/src/util.rs +8 -2
- package/contracts/message-libs/block-message-lib/Cargo.toml +1 -0
- package/contracts/message-libs/block-message-lib/src/lib.rs +5 -5
- package/contracts/message-libs/message-lib-common/src/errors.rs +8 -8
- package/contracts/message-libs/message-lib-common/src/interfaces/dvn.rs +0 -1
- package/contracts/message-libs/message-lib-common/src/interfaces/mod.rs +3 -3
- package/contracts/message-libs/message-lib-common/src/lib.rs +0 -2
- package/contracts/message-libs/message-lib-common/src/packet_codec_v1.rs +4 -6
- package/contracts/message-libs/message-lib-common/src/tests/packet_codec_v1.rs +2 -2
- package/contracts/message-libs/message-lib-common/src/tests/worker_options.rs +11 -11
- package/contracts/message-libs/message-lib-common/src/worker_options.rs +10 -16
- package/contracts/message-libs/simple-message-lib/src/errors.rs +0 -4
- package/contracts/message-libs/simple-message-lib/src/simple_message_lib.rs +49 -34
- package/contracts/message-libs/simple-message-lib/src/storage.rs +3 -7
- package/contracts/message-libs/simple-message-lib/src/test.rs +3 -3
- package/contracts/message-libs/treasury/src/storage.rs +1 -2
- package/contracts/message-libs/treasury/src/tests/setup.rs +3 -2
- package/contracts/message-libs/treasury/src/tests/treasury_tests.rs +0 -13
- package/contracts/message-libs/treasury/src/treasury.rs +18 -21
- package/contracts/message-libs/uln-302/Cargo.toml +1 -0
- package/contracts/message-libs/uln-302/src/interfaces/mod.rs +4 -4
- package/contracts/message-libs/uln-302/src/interfaces/{receive.rs → receive_uln.rs} +3 -3
- package/contracts/message-libs/uln-302/src/interfaces/{send.rs → send_uln.rs} +8 -80
- package/contracts/message-libs/uln-302/src/lib.rs +5 -4
- package/contracts/message-libs/uln-302/src/{receive.rs → receive_uln.rs} +20 -12
- package/contracts/message-libs/uln-302/src/{send.rs → send_uln.rs} +19 -13
- package/contracts/message-libs/uln-302/src/storage.rs +1 -2
- package/contracts/message-libs/uln-302/src/tests/config/uln_config.rs +3 -2
- package/contracts/message-libs/uln-302/src/tests/send_uln302/send.rs +30 -30
- package/contracts/message-libs/uln-302/src/tests/setup.rs +12 -11
- package/contracts/message-libs/uln-302/src/tests/uln302/set_config.rs +1 -1
- package/contracts/message-libs/uln-302/src/{config_validation.rs → types.rs} +79 -11
- package/contracts/message-libs/uln-302/src/uln302.rs +15 -10
- package/contracts/oapp-macros/Cargo.toml +2 -8
- package/contracts/oapp-macros/src/lib.rs +57 -311
- package/contracts/oapp-macros/src/oapp_core.rs +23 -32
- package/contracts/oapp-macros/src/oapp_full.rs +8 -2
- package/contracts/oapp-macros/src/oapp_options_type3.rs +21 -36
- package/contracts/oapp-macros/src/oapp_receiver.rs +38 -57
- package/contracts/oapp-macros/src/oapp_sender.rs +12 -14
- package/contracts/oapp-macros/src/util.rs +14 -10
- package/contracts/oapps/counter/Cargo.toml +2 -1
- package/contracts/oapps/counter/integration_tests/utils.rs +4 -4
- package/contracts/oapps/counter/src/codec.rs +8 -9
- package/contracts/oapps/counter/src/counter.rs +156 -147
- package/contracts/oapps/counter/src/storage.rs +1 -2
- package/contracts/oapps/counter/src/tests/test_codec.rs +5 -5
- package/contracts/oapps/counter/src/tests/test_counter.rs +11 -13
- package/contracts/oapps/oapp/Cargo.toml +1 -0
- package/contracts/oapps/oapp/src/errors.rs +1 -1
- package/contracts/oapps/oapp/src/lib.rs +3 -0
- package/contracts/oapps/oapp/src/macro_tests/mod.rs +1 -0
- package/contracts/oapps/oapp/src/macro_tests/test_macros.rs +312 -0
- package/contracts/oapps/oapp/src/oapp_core.rs +52 -53
- package/contracts/oapps/oapp/src/oapp_options_type3.rs +18 -28
- package/contracts/oapps/oapp/src/oapp_receiver.rs +82 -31
- package/contracts/oapps/oapp/src/oapp_sender.rs +55 -13
- package/contracts/oapps/oapp/src/tests/test_oapp_core.rs +16 -3
- package/contracts/oapps/oapp/src/tests/test_oapp_options_type3.rs +33 -8
- package/contracts/oapps/oapp/src/tests/test_oapp_receiver.rs +6 -9
- package/contracts/oapps/oapp/src/tests/test_oapp_sender.rs +28 -15
- package/contracts/oapps/oft/Cargo.toml +27 -0
- package/contracts/oapps/oft/integration-tests/mod.rs +3 -0
- package/contracts/oapps/oft/integration-tests/setup.rs +320 -0
- package/contracts/oapps/oft/integration-tests/test_with_sml.rs +155 -0
- package/contracts/oapps/oft/integration-tests/utils.rs +201 -0
- package/contracts/oapps/oft/src/codec/mod.rs +2 -0
- package/contracts/oapps/oft/src/codec/oft_compose_msg_codec.rs +55 -0
- package/contracts/oapps/oft/src/codec/oft_msg_codec.rs +62 -0
- package/contracts/oapps/oft/src/constants.rs +5 -0
- package/contracts/oapps/oft/src/errors.rs +8 -0
- package/contracts/oapps/oft/src/events.rs +19 -0
- package/contracts/oapps/oft/src/interfaces/mint_burn_token.rs +23 -0
- package/contracts/oapps/oft/src/interfaces/mod.rs +3 -0
- package/contracts/oapps/oft/src/lib.rs +22 -0
- package/contracts/oapps/oft/src/macro_tests/mod.rs +2 -0
- package/contracts/oapps/oft/src/macro_tests/test_all_default.rs +41 -0
- package/contracts/oapps/oft/src/macro_tests/test_override.rs +83 -0
- package/contracts/oapps/oft/src/oft.rs +320 -0
- package/contracts/oapps/oft/src/oft_types/lock_unlock.rs +50 -0
- package/contracts/oapps/oft/src/oft_types/mint_burn.rs +50 -0
- package/contracts/oapps/oft/src/oft_types/mod.rs +10 -0
- package/contracts/oapps/oft/src/storage.rs +11 -0
- package/contracts/oapps/oft/src/tests/mod.rs +13 -0
- package/contracts/oapps/oft/src/tests/test_decimals.rs +89 -0
- package/contracts/oapps/oft/src/tests/test_lz_receive.rs +282 -0
- package/contracts/oapps/oft/src/tests/test_oft_compose_msg_codec.rs +68 -0
- package/contracts/oapps/oft/src/tests/test_oft_msg_codec.rs +136 -0
- package/contracts/oapps/oft/src/tests/test_oft_version.rs +13 -0
- package/contracts/oapps/oft/src/tests/test_quote_oft.rs +159 -0
- package/contracts/oapps/oft/src/tests/test_quote_send.rs +195 -0
- package/contracts/oapps/oft/src/tests/test_resolve_address.rs +37 -0
- package/contracts/oapps/oft/src/tests/test_send.rs +915 -0
- package/contracts/oapps/oft/src/tests/test_token.rs +47 -0
- package/contracts/oapps/oft/src/tests/test_utils.rs +789 -0
- package/contracts/oapps/oft/src/types.rs +38 -0
- package/contracts/oapps/oft/src/utils.rs +67 -0
- package/contracts/oapps/oft-mint-burn/Cargo.toml +26 -0
- package/contracts/oapps/oft-mint-burn/src/lib.rs +3 -0
- package/contracts/oapps/oft-mint-burn/src/oft.rs +28 -0
- package/contracts/oapps/oft-mint-burn/src/tests/mod.rs +1 -0
- package/contracts/utils/src/buffer_reader.rs +8 -9
- package/contracts/utils/src/buffer_writer.rs +11 -5
- package/contracts/utils/src/errors.rs +5 -5
- package/contracts/utils/src/ownable.rs +14 -6
- package/contracts/utils/src/testing_utils.rs +11 -1
- package/contracts/utils/src/tests/buffer_reader.rs +491 -730
- package/contracts/utils/src/tests/buffer_writer.rs +336 -148
- package/contracts/utils/src/tests/bytes_ext.rs +125 -40
- package/contracts/utils/src/tests/mod.rs +3 -0
- package/contracts/utils/src/tests/ownable.rs +379 -27
- package/contracts/utils/src/tests/test_helper.rs +47 -0
- package/contracts/utils/src/tests/testing_utils.rs +555 -0
- package/contracts/utils/src/tests/ttl.rs +421 -0
- package/contracts/utils/src/ttl.rs +29 -89
- package/contracts/workers/dvn/Cargo.toml +31 -0
- package/contracts/workers/dvn/src/auth.rs +66 -0
- package/contracts/workers/dvn/src/dvn.rs +143 -0
- package/contracts/workers/dvn/src/errors.rs +21 -0
- package/contracts/workers/dvn/src/events.rs +19 -0
- package/contracts/workers/dvn/src/interfaces/dvn.rs +12 -0
- package/contracts/workers/dvn/src/interfaces/mod.rs +5 -0
- package/contracts/workers/dvn/src/interfaces/multisig.rs +15 -0
- package/contracts/workers/dvn/src/lib.rs +24 -0
- package/contracts/workers/dvn/src/multisig.rs +127 -0
- package/contracts/workers/dvn/src/storage.rs +35 -0
- package/contracts/workers/dvn/src/tests/auth.rs +237 -0
- package/contracts/workers/dvn/src/tests/dvn.rs +349 -0
- package/contracts/workers/dvn/src/tests/key_pair.rs +66 -0
- package/contracts/workers/dvn/src/tests/mod.rs +5 -0
- package/contracts/workers/dvn/src/tests/multisig/mod.rs +3 -0
- package/contracts/workers/dvn/src/tests/multisig/set_signer.rs +133 -0
- package/contracts/workers/dvn/src/tests/multisig/set_threshold.rs +108 -0
- package/contracts/workers/dvn/src/tests/multisig/verify_signatures.rs +109 -0
- package/contracts/workers/dvn/src/tests/setup.rs +109 -0
- package/contracts/workers/dvn/src/types.rs +26 -0
- package/contracts/workers/dvn-fee-lib/Cargo.toml +24 -0
- package/contracts/workers/dvn-fee-lib/src/dvn_fee_lib.rs +113 -0
- package/contracts/workers/dvn-fee-lib/src/errors.rs +8 -0
- package/contracts/workers/dvn-fee-lib/src/lib.rs +17 -0
- package/contracts/workers/dvn-fee-lib/src/tests/dvn_fee_lib.rs +282 -0
- package/contracts/workers/dvn-fee-lib/src/tests/mod.rs +1 -0
- package/contracts/workers/executor/Cargo.toml +10 -7
- package/contracts/workers/executor/src/errors.rs +8 -0
- package/contracts/workers/executor/src/events.rs +4 -7
- package/contracts/workers/executor/src/interfaces/executor.rs +72 -22
- package/contracts/workers/executor/src/interfaces/mod.rs +0 -2
- package/contracts/workers/executor/src/lib.rs +16 -7
- package/contracts/workers/executor/src/lz_executor.rs +308 -0
- package/contracts/workers/executor/src/storage.rs +24 -16
- package/contracts/workers/executor-fee-lib/Cargo.toml +22 -0
- package/contracts/workers/executor-fee-lib/src/errors.rs +15 -0
- package/contracts/workers/executor-fee-lib/src/executor_fee_lib.rs +215 -0
- package/contracts/workers/executor-fee-lib/src/executor_option.rs +203 -0
- package/contracts/workers/executor-fee-lib/src/lib.rs +7 -0
- package/contracts/workers/executor-helper/Cargo.toml +29 -0
- package/contracts/workers/executor-helper/src/executor_helper.rs +161 -0
- package/contracts/workers/executor-helper/src/lib.rs +11 -0
- package/contracts/workers/{worker-common → worker}/Cargo.toml +1 -4
- package/contracts/workers/worker/src/errors.rs +24 -0
- package/contracts/workers/worker/src/events.rs +62 -0
- package/contracts/workers/worker/src/interfaces/dvn_fee_lib.rs +75 -0
- package/contracts/workers/worker/src/interfaces/executor_fee_lib.rs +84 -0
- package/contracts/workers/{worker-common → worker}/src/interfaces/mod.rs +2 -2
- package/contracts/workers/worker/src/interfaces/price_feed.rs +85 -0
- package/contracts/workers/worker/src/lib.rs +14 -0
- package/contracts/workers/worker/src/storage.rs +63 -0
- package/contracts/workers/worker/src/worker.rs +459 -0
- package/package.json +3 -3
- package/sdk/dist/generated/bml.d.ts +88 -17
- package/sdk/dist/generated/bml.js +62 -16
- package/sdk/dist/generated/counter.d.ts +281 -102
- package/sdk/dist/generated/counter.js +93 -41
- package/sdk/dist/generated/endpoint.d.ts +128 -105
- package/sdk/dist/generated/endpoint.js +47 -45
- package/sdk/dist/generated/sml.d.ts +212 -69
- package/sdk/dist/generated/sml.js +103 -53
- package/sdk/dist/generated/uln302.d.ts +270 -173
- package/sdk/dist/generated/uln302.js +112 -64
- package/sdk/package.json +11 -11
- package/sdk/test/index.test.ts +147 -42
- package/sdk/test/suites/constants.ts +7 -3
- package/sdk/test/suites/deploy.ts +65 -42
- package/sdk/test/suites/localnet.ts +2 -2
- package/sdk/test/suites/scan.ts +28 -25
- package/sdk/test/utils.ts +199 -0
- package/sdk/tsconfig.json +93 -95
- package/tools/ts-bindings-gen/src/main.rs +2 -0
- package/contracts/common-macros/src/snapshots/common_macros__tests__tests__snapshot_generated_storage_code.snap +0 -310
- package/contracts/common-macros/src/tests.rs +0 -287
- package/contracts/oapp-macros/tests/test_macros.rs +0 -522
- package/contracts/workers/executor/src/executor.rs +0 -347
- package/contracts/workers/executor/src/interfaces/types.rs +0 -51
- package/contracts/workers/worker-common/src/constants.rs +0 -17
- package/contracts/workers/worker-common/src/errors.rs +0 -6
- package/contracts/workers/worker-common/src/events.rs +0 -34
- package/contracts/workers/worker-common/src/interfaces/executor_fee_lib.rs +0 -35
- package/contracts/workers/worker-common/src/interfaces/price_feed.rs +0 -40
- package/contracts/workers/worker-common/src/interfaces/worker.rs +0 -60
- package/contracts/workers/worker-common/src/lib.rs +0 -19
- package/contracts/workers/worker-common/src/storage.rs +0 -32
- package/contracts/workers/worker-common/src/worker_common.rs +0 -166
|
@@ -0,0 +1,1072 @@
|
|
|
1
|
+
---
|
|
2
|
+
source: contracts/common-macros/src/tests/storage.rs
|
|
3
|
+
assertion_line: 374
|
|
4
|
+
expression: formatted
|
|
5
|
+
---
|
|
6
|
+
#[soroban_sdk::contracttype]
|
|
7
|
+
pub enum StorageKeys {
|
|
8
|
+
Counter,
|
|
9
|
+
Message(Address),
|
|
10
|
+
Flag(String),
|
|
11
|
+
Data(u64, String),
|
|
12
|
+
Owner,
|
|
13
|
+
OptionalData(BytesN<32>),
|
|
14
|
+
TempData,
|
|
15
|
+
UserBalance(Address),
|
|
16
|
+
AnotherVariant(Address),
|
|
17
|
+
U32Value(u32),
|
|
18
|
+
I64Value(i64),
|
|
19
|
+
BoolValue(bool),
|
|
20
|
+
U8Value(u8),
|
|
21
|
+
UsizeValue(usize),
|
|
22
|
+
StringValue(String),
|
|
23
|
+
VecValue(Vec<u32>),
|
|
24
|
+
AddressValue(Address),
|
|
25
|
+
UnitVariant,
|
|
26
|
+
NamedVariant(u32, String, Address),
|
|
27
|
+
CachedValue(Address),
|
|
28
|
+
}
|
|
29
|
+
impl StorageKeys {
|
|
30
|
+
pub fn counter(env: &soroban_sdk::Env) -> u32 {
|
|
31
|
+
let key = StorageKeys::Counter;
|
|
32
|
+
let value = env.storage().instance().get::<_, u32>(&key);
|
|
33
|
+
value.unwrap_or(0)
|
|
34
|
+
}
|
|
35
|
+
pub fn set_counter(env: &soroban_sdk::Env, value: &u32) {
|
|
36
|
+
let key = StorageKeys::Counter;
|
|
37
|
+
env.storage().instance().set(&key, value);
|
|
38
|
+
}
|
|
39
|
+
pub fn remove_counter(env: &soroban_sdk::Env) {
|
|
40
|
+
let key = StorageKeys::Counter;
|
|
41
|
+
env.storage().instance().remove(&key);
|
|
42
|
+
}
|
|
43
|
+
pub fn set_or_remove_counter(env: &soroban_sdk::Env, value: &Option<u32>) {
|
|
44
|
+
match value.as_ref() {
|
|
45
|
+
Some(v) => Self::set_counter(env, v),
|
|
46
|
+
None => Self::remove_counter(env),
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
pub fn has_counter(env: &soroban_sdk::Env) -> bool {
|
|
50
|
+
let key = StorageKeys::Counter;
|
|
51
|
+
env.storage().instance().has(&key)
|
|
52
|
+
}
|
|
53
|
+
pub fn extend_counter_ttl(env: &soroban_sdk::Env, threshold: u32, extend_to: u32) {
|
|
54
|
+
let key = StorageKeys::Counter;
|
|
55
|
+
env.storage().instance().extend_ttl(threshold, extend_to);
|
|
56
|
+
}
|
|
57
|
+
pub fn message(env: &soroban_sdk::Env, sender: &Address) -> String {
|
|
58
|
+
let key = StorageKeys::Message(sender.clone());
|
|
59
|
+
let value = env.storage().persistent().get::<_, String>(&key);
|
|
60
|
+
if value.is_some() {
|
|
61
|
+
if let Some(utils::ttl::TtlConfig { threshold, extend_to }) = utils::ttl::TtlConfigStorage::persistent(
|
|
62
|
+
env,
|
|
63
|
+
) {
|
|
64
|
+
env.storage().persistent().extend_ttl(&key, threshold, extend_to);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
value.unwrap_or("hello".to_string())
|
|
68
|
+
}
|
|
69
|
+
pub fn set_message(env: &soroban_sdk::Env, sender: &Address, value: &String) {
|
|
70
|
+
let key = StorageKeys::Message(sender.clone());
|
|
71
|
+
env.storage().persistent().set(&key, value);
|
|
72
|
+
if let Some(utils::ttl::TtlConfig { threshold, extend_to }) = utils::ttl::TtlConfigStorage::persistent(
|
|
73
|
+
env,
|
|
74
|
+
) {
|
|
75
|
+
env.storage().persistent().extend_ttl(&key, threshold, extend_to);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
pub fn remove_message(env: &soroban_sdk::Env, sender: &Address) {
|
|
79
|
+
let key = StorageKeys::Message(sender.clone());
|
|
80
|
+
env.storage().persistent().remove(&key);
|
|
81
|
+
}
|
|
82
|
+
pub fn set_or_remove_message(
|
|
83
|
+
env: &soroban_sdk::Env,
|
|
84
|
+
sender: &Address,
|
|
85
|
+
value: &Option<String>,
|
|
86
|
+
) {
|
|
87
|
+
match value.as_ref() {
|
|
88
|
+
Some(v) => Self::set_message(env, sender, v),
|
|
89
|
+
None => Self::remove_message(env, sender),
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
pub fn has_message(env: &soroban_sdk::Env, sender: &Address) -> bool {
|
|
93
|
+
let key = StorageKeys::Message(sender.clone());
|
|
94
|
+
let exists = env.storage().persistent().has(&key);
|
|
95
|
+
if exists {
|
|
96
|
+
if let Some(utils::ttl::TtlConfig { threshold, extend_to }) = utils::ttl::TtlConfigStorage::persistent(
|
|
97
|
+
env,
|
|
98
|
+
) {
|
|
99
|
+
env.storage().persistent().extend_ttl(&key, threshold, extend_to);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
exists
|
|
103
|
+
}
|
|
104
|
+
pub fn extend_message_ttl(
|
|
105
|
+
env: &soroban_sdk::Env,
|
|
106
|
+
sender: &Address,
|
|
107
|
+
threshold: u32,
|
|
108
|
+
extend_to: u32,
|
|
109
|
+
) {
|
|
110
|
+
let key = StorageKeys::Message(sender.clone());
|
|
111
|
+
env.storage().persistent().extend_ttl(&key, threshold, extend_to);
|
|
112
|
+
}
|
|
113
|
+
pub fn flag(env: &soroban_sdk::Env, key: &String) -> Option<bool> {
|
|
114
|
+
let key = StorageKeys::Flag(key.clone());
|
|
115
|
+
let value = env.storage().temporary().get::<_, bool>(&key);
|
|
116
|
+
value
|
|
117
|
+
}
|
|
118
|
+
pub fn set_flag(env: &soroban_sdk::Env, key: &String, value: &bool) {
|
|
119
|
+
let key = StorageKeys::Flag(key.clone());
|
|
120
|
+
env.storage().temporary().set(&key, value);
|
|
121
|
+
}
|
|
122
|
+
pub fn remove_flag(env: &soroban_sdk::Env, key: &String) {
|
|
123
|
+
let key = StorageKeys::Flag(key.clone());
|
|
124
|
+
env.storage().temporary().remove(&key);
|
|
125
|
+
}
|
|
126
|
+
pub fn set_or_remove_flag(
|
|
127
|
+
env: &soroban_sdk::Env,
|
|
128
|
+
key: &String,
|
|
129
|
+
value: &Option<bool>,
|
|
130
|
+
) {
|
|
131
|
+
match value.as_ref() {
|
|
132
|
+
Some(v) => Self::set_flag(env, key, v),
|
|
133
|
+
None => Self::remove_flag(env, key),
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
pub fn has_flag(env: &soroban_sdk::Env, key: &String) -> bool {
|
|
137
|
+
let key = StorageKeys::Flag(key.clone());
|
|
138
|
+
env.storage().temporary().has(&key)
|
|
139
|
+
}
|
|
140
|
+
pub fn extend_flag_ttl(
|
|
141
|
+
env: &soroban_sdk::Env,
|
|
142
|
+
key: &String,
|
|
143
|
+
threshold: u32,
|
|
144
|
+
extend_to: u32,
|
|
145
|
+
) {
|
|
146
|
+
let key = StorageKeys::Flag(key.clone());
|
|
147
|
+
env.storage().temporary().extend_ttl(&key, threshold, extend_to);
|
|
148
|
+
}
|
|
149
|
+
pub fn data(env: &soroban_sdk::Env, id: u64, name: &String) -> Option<Vec<u8>> {
|
|
150
|
+
let key = StorageKeys::Data(id, name.clone());
|
|
151
|
+
let value = env.storage().persistent().get::<_, Vec<u8>>(&key);
|
|
152
|
+
if value.is_some() {
|
|
153
|
+
if let Some(utils::ttl::TtlConfig { threshold, extend_to }) = utils::ttl::TtlConfigStorage::persistent(
|
|
154
|
+
env,
|
|
155
|
+
) {
|
|
156
|
+
env.storage().persistent().extend_ttl(&key, threshold, extend_to);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
value
|
|
160
|
+
}
|
|
161
|
+
pub fn set_data(env: &soroban_sdk::Env, id: u64, name: &String, value: &Vec<u8>) {
|
|
162
|
+
let key = StorageKeys::Data(id, name.clone());
|
|
163
|
+
env.storage().persistent().set(&key, value);
|
|
164
|
+
if let Some(utils::ttl::TtlConfig { threshold, extend_to }) = utils::ttl::TtlConfigStorage::persistent(
|
|
165
|
+
env,
|
|
166
|
+
) {
|
|
167
|
+
env.storage().persistent().extend_ttl(&key, threshold, extend_to);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
pub fn remove_data(env: &soroban_sdk::Env, id: u64, name: &String) {
|
|
171
|
+
let key = StorageKeys::Data(id, name.clone());
|
|
172
|
+
env.storage().persistent().remove(&key);
|
|
173
|
+
}
|
|
174
|
+
pub fn set_or_remove_data(
|
|
175
|
+
env: &soroban_sdk::Env,
|
|
176
|
+
id: u64,
|
|
177
|
+
name: &String,
|
|
178
|
+
value: &Option<Vec<u8>>,
|
|
179
|
+
) {
|
|
180
|
+
match value.as_ref() {
|
|
181
|
+
Some(v) => Self::set_data(env, id, name, v),
|
|
182
|
+
None => Self::remove_data(env, id, name),
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
pub fn has_data(env: &soroban_sdk::Env, id: u64, name: &String) -> bool {
|
|
186
|
+
let key = StorageKeys::Data(id, name.clone());
|
|
187
|
+
let exists = env.storage().persistent().has(&key);
|
|
188
|
+
if exists {
|
|
189
|
+
if let Some(utils::ttl::TtlConfig { threshold, extend_to }) = utils::ttl::TtlConfigStorage::persistent(
|
|
190
|
+
env,
|
|
191
|
+
) {
|
|
192
|
+
env.storage().persistent().extend_ttl(&key, threshold, extend_to);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
exists
|
|
196
|
+
}
|
|
197
|
+
pub fn extend_data_ttl(
|
|
198
|
+
env: &soroban_sdk::Env,
|
|
199
|
+
id: u64,
|
|
200
|
+
name: &String,
|
|
201
|
+
threshold: u32,
|
|
202
|
+
extend_to: u32,
|
|
203
|
+
) {
|
|
204
|
+
let key = StorageKeys::Data(id, name.clone());
|
|
205
|
+
env.storage().persistent().extend_ttl(&key, threshold, extend_to);
|
|
206
|
+
}
|
|
207
|
+
pub fn owner(env: &soroban_sdk::Env) -> Option<Address> {
|
|
208
|
+
let key = StorageKeys::Owner;
|
|
209
|
+
let value = env.storage().persistent().get::<_, Address>(&key);
|
|
210
|
+
if value.is_some() {
|
|
211
|
+
if let Some(utils::ttl::TtlConfig { threshold, extend_to }) = utils::ttl::TtlConfigStorage::persistent(
|
|
212
|
+
env,
|
|
213
|
+
) {
|
|
214
|
+
env.storage().persistent().extend_ttl(&key, threshold, extend_to);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
value
|
|
218
|
+
}
|
|
219
|
+
pub fn set_owner(env: &soroban_sdk::Env, value: &Address) {
|
|
220
|
+
let key = StorageKeys::Owner;
|
|
221
|
+
env.storage().persistent().set(&key, value);
|
|
222
|
+
if let Some(utils::ttl::TtlConfig { threshold, extend_to }) = utils::ttl::TtlConfigStorage::persistent(
|
|
223
|
+
env,
|
|
224
|
+
) {
|
|
225
|
+
env.storage().persistent().extend_ttl(&key, threshold, extend_to);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
pub fn remove_owner(env: &soroban_sdk::Env) {
|
|
229
|
+
let key = StorageKeys::Owner;
|
|
230
|
+
env.storage().persistent().remove(&key);
|
|
231
|
+
}
|
|
232
|
+
pub fn set_or_remove_owner(env: &soroban_sdk::Env, value: &Option<Address>) {
|
|
233
|
+
match value.as_ref() {
|
|
234
|
+
Some(v) => Self::set_owner(env, v),
|
|
235
|
+
None => Self::remove_owner(env),
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
pub fn has_owner(env: &soroban_sdk::Env) -> bool {
|
|
239
|
+
let key = StorageKeys::Owner;
|
|
240
|
+
let exists = env.storage().persistent().has(&key);
|
|
241
|
+
if exists {
|
|
242
|
+
if let Some(utils::ttl::TtlConfig { threshold, extend_to }) = utils::ttl::TtlConfigStorage::persistent(
|
|
243
|
+
env,
|
|
244
|
+
) {
|
|
245
|
+
env.storage().persistent().extend_ttl(&key, threshold, extend_to);
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
exists
|
|
249
|
+
}
|
|
250
|
+
pub fn extend_owner_ttl(env: &soroban_sdk::Env, threshold: u32, extend_to: u32) {
|
|
251
|
+
let key = StorageKeys::Owner;
|
|
252
|
+
env.storage().persistent().extend_ttl(&key, threshold, extend_to);
|
|
253
|
+
}
|
|
254
|
+
pub fn custom_key_name(
|
|
255
|
+
env: &soroban_sdk::Env,
|
|
256
|
+
key: &BytesN<32>,
|
|
257
|
+
) -> Option<Option<Address>> {
|
|
258
|
+
let key = StorageKeys::OptionalData(key.clone());
|
|
259
|
+
let value = env.storage().persistent().get::<_, Option<Address>>(&key);
|
|
260
|
+
if value.is_some() {
|
|
261
|
+
if let Some(utils::ttl::TtlConfig { threshold, extend_to }) = utils::ttl::TtlConfigStorage::persistent(
|
|
262
|
+
env,
|
|
263
|
+
) {
|
|
264
|
+
env.storage().persistent().extend_ttl(&key, threshold, extend_to);
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
value
|
|
268
|
+
}
|
|
269
|
+
pub fn set_custom_key_name(
|
|
270
|
+
env: &soroban_sdk::Env,
|
|
271
|
+
key: &BytesN<32>,
|
|
272
|
+
value: &Option<Address>,
|
|
273
|
+
) {
|
|
274
|
+
let key = StorageKeys::OptionalData(key.clone());
|
|
275
|
+
env.storage().persistent().set(&key, value);
|
|
276
|
+
if let Some(utils::ttl::TtlConfig { threshold, extend_to }) = utils::ttl::TtlConfigStorage::persistent(
|
|
277
|
+
env,
|
|
278
|
+
) {
|
|
279
|
+
env.storage().persistent().extend_ttl(&key, threshold, extend_to);
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
pub fn remove_custom_key_name(env: &soroban_sdk::Env, key: &BytesN<32>) {
|
|
283
|
+
let key = StorageKeys::OptionalData(key.clone());
|
|
284
|
+
env.storage().persistent().remove(&key);
|
|
285
|
+
}
|
|
286
|
+
pub fn set_or_remove_custom_key_name(
|
|
287
|
+
env: &soroban_sdk::Env,
|
|
288
|
+
key: &BytesN<32>,
|
|
289
|
+
value: &Option<Option<Address>>,
|
|
290
|
+
) {
|
|
291
|
+
match value.as_ref() {
|
|
292
|
+
Some(v) => Self::set_custom_key_name(env, key, v),
|
|
293
|
+
None => Self::remove_custom_key_name(env, key),
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
pub fn has_custom_key_name(env: &soroban_sdk::Env, key: &BytesN<32>) -> bool {
|
|
297
|
+
let key = StorageKeys::OptionalData(key.clone());
|
|
298
|
+
let exists = env.storage().persistent().has(&key);
|
|
299
|
+
if exists {
|
|
300
|
+
if let Some(utils::ttl::TtlConfig { threshold, extend_to }) = utils::ttl::TtlConfigStorage::persistent(
|
|
301
|
+
env,
|
|
302
|
+
) {
|
|
303
|
+
env.storage().persistent().extend_ttl(&key, threshold, extend_to);
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
exists
|
|
307
|
+
}
|
|
308
|
+
pub fn extend_custom_key_name_ttl(
|
|
309
|
+
env: &soroban_sdk::Env,
|
|
310
|
+
key: &BytesN<32>,
|
|
311
|
+
threshold: u32,
|
|
312
|
+
extend_to: u32,
|
|
313
|
+
) {
|
|
314
|
+
let key = StorageKeys::OptionalData(key.clone());
|
|
315
|
+
env.storage().persistent().extend_ttl(&key, threshold, extend_to);
|
|
316
|
+
}
|
|
317
|
+
pub fn temp_data(env: &soroban_sdk::Env) -> Option<u64> {
|
|
318
|
+
let key = StorageKeys::TempData;
|
|
319
|
+
let value = env.storage().temporary().get::<_, u64>(&key);
|
|
320
|
+
value
|
|
321
|
+
}
|
|
322
|
+
pub fn set_temp_data(env: &soroban_sdk::Env, value: &u64) {
|
|
323
|
+
let key = StorageKeys::TempData;
|
|
324
|
+
env.storage().temporary().set(&key, value);
|
|
325
|
+
}
|
|
326
|
+
pub fn remove_temp_data(env: &soroban_sdk::Env) {
|
|
327
|
+
let key = StorageKeys::TempData;
|
|
328
|
+
env.storage().temporary().remove(&key);
|
|
329
|
+
}
|
|
330
|
+
pub fn set_or_remove_temp_data(env: &soroban_sdk::Env, value: &Option<u64>) {
|
|
331
|
+
match value.as_ref() {
|
|
332
|
+
Some(v) => Self::set_temp_data(env, v),
|
|
333
|
+
None => Self::remove_temp_data(env),
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
pub fn has_temp_data(env: &soroban_sdk::Env) -> bool {
|
|
337
|
+
let key = StorageKeys::TempData;
|
|
338
|
+
env.storage().temporary().has(&key)
|
|
339
|
+
}
|
|
340
|
+
pub fn extend_temp_data_ttl(env: &soroban_sdk::Env, threshold: u32, extend_to: u32) {
|
|
341
|
+
let key = StorageKeys::TempData;
|
|
342
|
+
env.storage().temporary().extend_ttl(&key, threshold, extend_to);
|
|
343
|
+
}
|
|
344
|
+
pub fn user_balance(env: &soroban_sdk::Env, user: &Address) -> Option<u32> {
|
|
345
|
+
let key = StorageKeys::UserBalance(user.clone());
|
|
346
|
+
let value = env.storage().persistent().get::<_, u32>(&key);
|
|
347
|
+
if value.is_some() {
|
|
348
|
+
if let Some(utils::ttl::TtlConfig { threshold, extend_to }) = utils::ttl::TtlConfigStorage::persistent(
|
|
349
|
+
env,
|
|
350
|
+
) {
|
|
351
|
+
env.storage().persistent().extend_ttl(&key, threshold, extend_to);
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
value
|
|
355
|
+
}
|
|
356
|
+
pub fn set_user_balance(env: &soroban_sdk::Env, user: &Address, value: &u32) {
|
|
357
|
+
let key = StorageKeys::UserBalance(user.clone());
|
|
358
|
+
env.storage().persistent().set(&key, value);
|
|
359
|
+
if let Some(utils::ttl::TtlConfig { threshold, extend_to }) = utils::ttl::TtlConfigStorage::persistent(
|
|
360
|
+
env,
|
|
361
|
+
) {
|
|
362
|
+
env.storage().persistent().extend_ttl(&key, threshold, extend_to);
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
pub fn remove_user_balance(env: &soroban_sdk::Env, user: &Address) {
|
|
366
|
+
let key = StorageKeys::UserBalance(user.clone());
|
|
367
|
+
env.storage().persistent().remove(&key);
|
|
368
|
+
}
|
|
369
|
+
pub fn set_or_remove_user_balance(
|
|
370
|
+
env: &soroban_sdk::Env,
|
|
371
|
+
user: &Address,
|
|
372
|
+
value: &Option<u32>,
|
|
373
|
+
) {
|
|
374
|
+
match value.as_ref() {
|
|
375
|
+
Some(v) => Self::set_user_balance(env, user, v),
|
|
376
|
+
None => Self::remove_user_balance(env, user),
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
pub fn has_user_balance(env: &soroban_sdk::Env, user: &Address) -> bool {
|
|
380
|
+
let key = StorageKeys::UserBalance(user.clone());
|
|
381
|
+
let exists = env.storage().persistent().has(&key);
|
|
382
|
+
if exists {
|
|
383
|
+
if let Some(utils::ttl::TtlConfig { threshold, extend_to }) = utils::ttl::TtlConfigStorage::persistent(
|
|
384
|
+
env,
|
|
385
|
+
) {
|
|
386
|
+
env.storage().persistent().extend_ttl(&key, threshold, extend_to);
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
exists
|
|
390
|
+
}
|
|
391
|
+
pub fn extend_user_balance_ttl(
|
|
392
|
+
env: &soroban_sdk::Env,
|
|
393
|
+
user: &Address,
|
|
394
|
+
threshold: u32,
|
|
395
|
+
extend_to: u32,
|
|
396
|
+
) {
|
|
397
|
+
let key = StorageKeys::UserBalance(user.clone());
|
|
398
|
+
env.storage().persistent().extend_ttl(&key, threshold, extend_to);
|
|
399
|
+
}
|
|
400
|
+
pub fn custom(env: &soroban_sdk::Env, key: &Address) -> Option<u32> {
|
|
401
|
+
let key = StorageKeys::AnotherVariant(key.clone());
|
|
402
|
+
let value = env.storage().persistent().get::<_, u32>(&key);
|
|
403
|
+
if value.is_some() {
|
|
404
|
+
if let Some(utils::ttl::TtlConfig { threshold, extend_to }) = utils::ttl::TtlConfigStorage::persistent(
|
|
405
|
+
env,
|
|
406
|
+
) {
|
|
407
|
+
env.storage().persistent().extend_ttl(&key, threshold, extend_to);
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
value
|
|
411
|
+
}
|
|
412
|
+
pub fn set_custom(env: &soroban_sdk::Env, key: &Address, value: &u32) {
|
|
413
|
+
let key = StorageKeys::AnotherVariant(key.clone());
|
|
414
|
+
env.storage().persistent().set(&key, value);
|
|
415
|
+
if let Some(utils::ttl::TtlConfig { threshold, extend_to }) = utils::ttl::TtlConfigStorage::persistent(
|
|
416
|
+
env,
|
|
417
|
+
) {
|
|
418
|
+
env.storage().persistent().extend_ttl(&key, threshold, extend_to);
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
pub fn remove_custom(env: &soroban_sdk::Env, key: &Address) {
|
|
422
|
+
let key = StorageKeys::AnotherVariant(key.clone());
|
|
423
|
+
env.storage().persistent().remove(&key);
|
|
424
|
+
}
|
|
425
|
+
pub fn set_or_remove_custom(
|
|
426
|
+
env: &soroban_sdk::Env,
|
|
427
|
+
key: &Address,
|
|
428
|
+
value: &Option<u32>,
|
|
429
|
+
) {
|
|
430
|
+
match value.as_ref() {
|
|
431
|
+
Some(v) => Self::set_custom(env, key, v),
|
|
432
|
+
None => Self::remove_custom(env, key),
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
pub fn has_custom(env: &soroban_sdk::Env, key: &Address) -> bool {
|
|
436
|
+
let key = StorageKeys::AnotherVariant(key.clone());
|
|
437
|
+
let exists = env.storage().persistent().has(&key);
|
|
438
|
+
if exists {
|
|
439
|
+
if let Some(utils::ttl::TtlConfig { threshold, extend_to }) = utils::ttl::TtlConfigStorage::persistent(
|
|
440
|
+
env,
|
|
441
|
+
) {
|
|
442
|
+
env.storage().persistent().extend_ttl(&key, threshold, extend_to);
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
exists
|
|
446
|
+
}
|
|
447
|
+
pub fn extend_custom_ttl(
|
|
448
|
+
env: &soroban_sdk::Env,
|
|
449
|
+
key: &Address,
|
|
450
|
+
threshold: u32,
|
|
451
|
+
extend_to: u32,
|
|
452
|
+
) {
|
|
453
|
+
let key = StorageKeys::AnotherVariant(key.clone());
|
|
454
|
+
env.storage().persistent().extend_ttl(&key, threshold, extend_to);
|
|
455
|
+
}
|
|
456
|
+
pub fn u32_value(env: &soroban_sdk::Env, key: u32) -> Option<u32> {
|
|
457
|
+
let key = StorageKeys::U32Value(key);
|
|
458
|
+
let value = env.storage().persistent().get::<_, u32>(&key);
|
|
459
|
+
if value.is_some() {
|
|
460
|
+
if let Some(utils::ttl::TtlConfig { threshold, extend_to }) = utils::ttl::TtlConfigStorage::persistent(
|
|
461
|
+
env,
|
|
462
|
+
) {
|
|
463
|
+
env.storage().persistent().extend_ttl(&key, threshold, extend_to);
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
value
|
|
467
|
+
}
|
|
468
|
+
pub fn set_u32_value(env: &soroban_sdk::Env, key: u32, value: &u32) {
|
|
469
|
+
let key = StorageKeys::U32Value(key);
|
|
470
|
+
env.storage().persistent().set(&key, value);
|
|
471
|
+
if let Some(utils::ttl::TtlConfig { threshold, extend_to }) = utils::ttl::TtlConfigStorage::persistent(
|
|
472
|
+
env,
|
|
473
|
+
) {
|
|
474
|
+
env.storage().persistent().extend_ttl(&key, threshold, extend_to);
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
pub fn remove_u32_value(env: &soroban_sdk::Env, key: u32) {
|
|
478
|
+
let key = StorageKeys::U32Value(key);
|
|
479
|
+
env.storage().persistent().remove(&key);
|
|
480
|
+
}
|
|
481
|
+
pub fn set_or_remove_u32_value(
|
|
482
|
+
env: &soroban_sdk::Env,
|
|
483
|
+
key: u32,
|
|
484
|
+
value: &Option<u32>,
|
|
485
|
+
) {
|
|
486
|
+
match value.as_ref() {
|
|
487
|
+
Some(v) => Self::set_u32_value(env, key, v),
|
|
488
|
+
None => Self::remove_u32_value(env, key),
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
pub fn has_u32_value(env: &soroban_sdk::Env, key: u32) -> bool {
|
|
492
|
+
let key = StorageKeys::U32Value(key);
|
|
493
|
+
let exists = env.storage().persistent().has(&key);
|
|
494
|
+
if exists {
|
|
495
|
+
if let Some(utils::ttl::TtlConfig { threshold, extend_to }) = utils::ttl::TtlConfigStorage::persistent(
|
|
496
|
+
env,
|
|
497
|
+
) {
|
|
498
|
+
env.storage().persistent().extend_ttl(&key, threshold, extend_to);
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
exists
|
|
502
|
+
}
|
|
503
|
+
pub fn extend_u32_value_ttl(
|
|
504
|
+
env: &soroban_sdk::Env,
|
|
505
|
+
key: u32,
|
|
506
|
+
threshold: u32,
|
|
507
|
+
extend_to: u32,
|
|
508
|
+
) {
|
|
509
|
+
let key = StorageKeys::U32Value(key);
|
|
510
|
+
env.storage().persistent().extend_ttl(&key, threshold, extend_to);
|
|
511
|
+
}
|
|
512
|
+
pub fn i64_value(env: &soroban_sdk::Env, key: i64) -> Option<i64> {
|
|
513
|
+
let key = StorageKeys::I64Value(key);
|
|
514
|
+
let value = env.storage().persistent().get::<_, i64>(&key);
|
|
515
|
+
if value.is_some() {
|
|
516
|
+
if let Some(utils::ttl::TtlConfig { threshold, extend_to }) = utils::ttl::TtlConfigStorage::persistent(
|
|
517
|
+
env,
|
|
518
|
+
) {
|
|
519
|
+
env.storage().persistent().extend_ttl(&key, threshold, extend_to);
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
value
|
|
523
|
+
}
|
|
524
|
+
pub fn set_i64_value(env: &soroban_sdk::Env, key: i64, value: &i64) {
|
|
525
|
+
let key = StorageKeys::I64Value(key);
|
|
526
|
+
env.storage().persistent().set(&key, value);
|
|
527
|
+
if let Some(utils::ttl::TtlConfig { threshold, extend_to }) = utils::ttl::TtlConfigStorage::persistent(
|
|
528
|
+
env,
|
|
529
|
+
) {
|
|
530
|
+
env.storage().persistent().extend_ttl(&key, threshold, extend_to);
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
pub fn remove_i64_value(env: &soroban_sdk::Env, key: i64) {
|
|
534
|
+
let key = StorageKeys::I64Value(key);
|
|
535
|
+
env.storage().persistent().remove(&key);
|
|
536
|
+
}
|
|
537
|
+
pub fn set_or_remove_i64_value(
|
|
538
|
+
env: &soroban_sdk::Env,
|
|
539
|
+
key: i64,
|
|
540
|
+
value: &Option<i64>,
|
|
541
|
+
) {
|
|
542
|
+
match value.as_ref() {
|
|
543
|
+
Some(v) => Self::set_i64_value(env, key, v),
|
|
544
|
+
None => Self::remove_i64_value(env, key),
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
pub fn has_i64_value(env: &soroban_sdk::Env, key: i64) -> bool {
|
|
548
|
+
let key = StorageKeys::I64Value(key);
|
|
549
|
+
let exists = env.storage().persistent().has(&key);
|
|
550
|
+
if exists {
|
|
551
|
+
if let Some(utils::ttl::TtlConfig { threshold, extend_to }) = utils::ttl::TtlConfigStorage::persistent(
|
|
552
|
+
env,
|
|
553
|
+
) {
|
|
554
|
+
env.storage().persistent().extend_ttl(&key, threshold, extend_to);
|
|
555
|
+
}
|
|
556
|
+
}
|
|
557
|
+
exists
|
|
558
|
+
}
|
|
559
|
+
pub fn extend_i64_value_ttl(
|
|
560
|
+
env: &soroban_sdk::Env,
|
|
561
|
+
key: i64,
|
|
562
|
+
threshold: u32,
|
|
563
|
+
extend_to: u32,
|
|
564
|
+
) {
|
|
565
|
+
let key = StorageKeys::I64Value(key);
|
|
566
|
+
env.storage().persistent().extend_ttl(&key, threshold, extend_to);
|
|
567
|
+
}
|
|
568
|
+
pub fn bool_value(env: &soroban_sdk::Env, key: bool) -> Option<bool> {
|
|
569
|
+
let key = StorageKeys::BoolValue(key);
|
|
570
|
+
let value = env.storage().persistent().get::<_, bool>(&key);
|
|
571
|
+
if value.is_some() {
|
|
572
|
+
if let Some(utils::ttl::TtlConfig { threshold, extend_to }) = utils::ttl::TtlConfigStorage::persistent(
|
|
573
|
+
env,
|
|
574
|
+
) {
|
|
575
|
+
env.storage().persistent().extend_ttl(&key, threshold, extend_to);
|
|
576
|
+
}
|
|
577
|
+
}
|
|
578
|
+
value
|
|
579
|
+
}
|
|
580
|
+
pub fn set_bool_value(env: &soroban_sdk::Env, key: bool, value: &bool) {
|
|
581
|
+
let key = StorageKeys::BoolValue(key);
|
|
582
|
+
env.storage().persistent().set(&key, value);
|
|
583
|
+
if let Some(utils::ttl::TtlConfig { threshold, extend_to }) = utils::ttl::TtlConfigStorage::persistent(
|
|
584
|
+
env,
|
|
585
|
+
) {
|
|
586
|
+
env.storage().persistent().extend_ttl(&key, threshold, extend_to);
|
|
587
|
+
}
|
|
588
|
+
}
|
|
589
|
+
pub fn remove_bool_value(env: &soroban_sdk::Env, key: bool) {
|
|
590
|
+
let key = StorageKeys::BoolValue(key);
|
|
591
|
+
env.storage().persistent().remove(&key);
|
|
592
|
+
}
|
|
593
|
+
pub fn set_or_remove_bool_value(
|
|
594
|
+
env: &soroban_sdk::Env,
|
|
595
|
+
key: bool,
|
|
596
|
+
value: &Option<bool>,
|
|
597
|
+
) {
|
|
598
|
+
match value.as_ref() {
|
|
599
|
+
Some(v) => Self::set_bool_value(env, key, v),
|
|
600
|
+
None => Self::remove_bool_value(env, key),
|
|
601
|
+
}
|
|
602
|
+
}
|
|
603
|
+
pub fn has_bool_value(env: &soroban_sdk::Env, key: bool) -> bool {
|
|
604
|
+
let key = StorageKeys::BoolValue(key);
|
|
605
|
+
let exists = env.storage().persistent().has(&key);
|
|
606
|
+
if exists {
|
|
607
|
+
if let Some(utils::ttl::TtlConfig { threshold, extend_to }) = utils::ttl::TtlConfigStorage::persistent(
|
|
608
|
+
env,
|
|
609
|
+
) {
|
|
610
|
+
env.storage().persistent().extend_ttl(&key, threshold, extend_to);
|
|
611
|
+
}
|
|
612
|
+
}
|
|
613
|
+
exists
|
|
614
|
+
}
|
|
615
|
+
pub fn extend_bool_value_ttl(
|
|
616
|
+
env: &soroban_sdk::Env,
|
|
617
|
+
key: bool,
|
|
618
|
+
threshold: u32,
|
|
619
|
+
extend_to: u32,
|
|
620
|
+
) {
|
|
621
|
+
let key = StorageKeys::BoolValue(key);
|
|
622
|
+
env.storage().persistent().extend_ttl(&key, threshold, extend_to);
|
|
623
|
+
}
|
|
624
|
+
pub fn u8_value(env: &soroban_sdk::Env, key: &u8) -> Option<u32> {
|
|
625
|
+
let key = StorageKeys::U8Value(key.clone());
|
|
626
|
+
let value = env.storage().persistent().get::<_, u32>(&key);
|
|
627
|
+
if value.is_some() {
|
|
628
|
+
if let Some(utils::ttl::TtlConfig { threshold, extend_to }) = utils::ttl::TtlConfigStorage::persistent(
|
|
629
|
+
env,
|
|
630
|
+
) {
|
|
631
|
+
env.storage().persistent().extend_ttl(&key, threshold, extend_to);
|
|
632
|
+
}
|
|
633
|
+
}
|
|
634
|
+
value
|
|
635
|
+
}
|
|
636
|
+
pub fn set_u8_value(env: &soroban_sdk::Env, key: &u8, value: &u32) {
|
|
637
|
+
let key = StorageKeys::U8Value(key.clone());
|
|
638
|
+
env.storage().persistent().set(&key, value);
|
|
639
|
+
if let Some(utils::ttl::TtlConfig { threshold, extend_to }) = utils::ttl::TtlConfigStorage::persistent(
|
|
640
|
+
env,
|
|
641
|
+
) {
|
|
642
|
+
env.storage().persistent().extend_ttl(&key, threshold, extend_to);
|
|
643
|
+
}
|
|
644
|
+
}
|
|
645
|
+
pub fn remove_u8_value(env: &soroban_sdk::Env, key: &u8) {
|
|
646
|
+
let key = StorageKeys::U8Value(key.clone());
|
|
647
|
+
env.storage().persistent().remove(&key);
|
|
648
|
+
}
|
|
649
|
+
pub fn set_or_remove_u8_value(
|
|
650
|
+
env: &soroban_sdk::Env,
|
|
651
|
+
key: &u8,
|
|
652
|
+
value: &Option<u32>,
|
|
653
|
+
) {
|
|
654
|
+
match value.as_ref() {
|
|
655
|
+
Some(v) => Self::set_u8_value(env, key, v),
|
|
656
|
+
None => Self::remove_u8_value(env, key),
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
pub fn has_u8_value(env: &soroban_sdk::Env, key: &u8) -> bool {
|
|
660
|
+
let key = StorageKeys::U8Value(key.clone());
|
|
661
|
+
let exists = env.storage().persistent().has(&key);
|
|
662
|
+
if exists {
|
|
663
|
+
if let Some(utils::ttl::TtlConfig { threshold, extend_to }) = utils::ttl::TtlConfigStorage::persistent(
|
|
664
|
+
env,
|
|
665
|
+
) {
|
|
666
|
+
env.storage().persistent().extend_ttl(&key, threshold, extend_to);
|
|
667
|
+
}
|
|
668
|
+
}
|
|
669
|
+
exists
|
|
670
|
+
}
|
|
671
|
+
pub fn extend_u8_value_ttl(
|
|
672
|
+
env: &soroban_sdk::Env,
|
|
673
|
+
key: &u8,
|
|
674
|
+
threshold: u32,
|
|
675
|
+
extend_to: u32,
|
|
676
|
+
) {
|
|
677
|
+
let key = StorageKeys::U8Value(key.clone());
|
|
678
|
+
env.storage().persistent().extend_ttl(&key, threshold, extend_to);
|
|
679
|
+
}
|
|
680
|
+
pub fn usize_value(env: &soroban_sdk::Env, key: &usize) -> Option<u32> {
|
|
681
|
+
let key = StorageKeys::UsizeValue(key.clone());
|
|
682
|
+
let value = env.storage().persistent().get::<_, u32>(&key);
|
|
683
|
+
if value.is_some() {
|
|
684
|
+
if let Some(utils::ttl::TtlConfig { threshold, extend_to }) = utils::ttl::TtlConfigStorage::persistent(
|
|
685
|
+
env,
|
|
686
|
+
) {
|
|
687
|
+
env.storage().persistent().extend_ttl(&key, threshold, extend_to);
|
|
688
|
+
}
|
|
689
|
+
}
|
|
690
|
+
value
|
|
691
|
+
}
|
|
692
|
+
pub fn set_usize_value(env: &soroban_sdk::Env, key: &usize, value: &u32) {
|
|
693
|
+
let key = StorageKeys::UsizeValue(key.clone());
|
|
694
|
+
env.storage().persistent().set(&key, value);
|
|
695
|
+
if let Some(utils::ttl::TtlConfig { threshold, extend_to }) = utils::ttl::TtlConfigStorage::persistent(
|
|
696
|
+
env,
|
|
697
|
+
) {
|
|
698
|
+
env.storage().persistent().extend_ttl(&key, threshold, extend_to);
|
|
699
|
+
}
|
|
700
|
+
}
|
|
701
|
+
pub fn remove_usize_value(env: &soroban_sdk::Env, key: &usize) {
|
|
702
|
+
let key = StorageKeys::UsizeValue(key.clone());
|
|
703
|
+
env.storage().persistent().remove(&key);
|
|
704
|
+
}
|
|
705
|
+
pub fn set_or_remove_usize_value(
|
|
706
|
+
env: &soroban_sdk::Env,
|
|
707
|
+
key: &usize,
|
|
708
|
+
value: &Option<u32>,
|
|
709
|
+
) {
|
|
710
|
+
match value.as_ref() {
|
|
711
|
+
Some(v) => Self::set_usize_value(env, key, v),
|
|
712
|
+
None => Self::remove_usize_value(env, key),
|
|
713
|
+
}
|
|
714
|
+
}
|
|
715
|
+
pub fn has_usize_value(env: &soroban_sdk::Env, key: &usize) -> bool {
|
|
716
|
+
let key = StorageKeys::UsizeValue(key.clone());
|
|
717
|
+
let exists = env.storage().persistent().has(&key);
|
|
718
|
+
if exists {
|
|
719
|
+
if let Some(utils::ttl::TtlConfig { threshold, extend_to }) = utils::ttl::TtlConfigStorage::persistent(
|
|
720
|
+
env,
|
|
721
|
+
) {
|
|
722
|
+
env.storage().persistent().extend_ttl(&key, threshold, extend_to);
|
|
723
|
+
}
|
|
724
|
+
}
|
|
725
|
+
exists
|
|
726
|
+
}
|
|
727
|
+
pub fn extend_usize_value_ttl(
|
|
728
|
+
env: &soroban_sdk::Env,
|
|
729
|
+
key: &usize,
|
|
730
|
+
threshold: u32,
|
|
731
|
+
extend_to: u32,
|
|
732
|
+
) {
|
|
733
|
+
let key = StorageKeys::UsizeValue(key.clone());
|
|
734
|
+
env.storage().persistent().extend_ttl(&key, threshold, extend_to);
|
|
735
|
+
}
|
|
736
|
+
pub fn string_value(env: &soroban_sdk::Env, key: &String) -> Option<String> {
|
|
737
|
+
let key = StorageKeys::StringValue(key.clone());
|
|
738
|
+
let value = env.storage().persistent().get::<_, String>(&key);
|
|
739
|
+
if value.is_some() {
|
|
740
|
+
if let Some(utils::ttl::TtlConfig { threshold, extend_to }) = utils::ttl::TtlConfigStorage::persistent(
|
|
741
|
+
env,
|
|
742
|
+
) {
|
|
743
|
+
env.storage().persistent().extend_ttl(&key, threshold, extend_to);
|
|
744
|
+
}
|
|
745
|
+
}
|
|
746
|
+
value
|
|
747
|
+
}
|
|
748
|
+
pub fn set_string_value(env: &soroban_sdk::Env, key: &String, value: &String) {
|
|
749
|
+
let key = StorageKeys::StringValue(key.clone());
|
|
750
|
+
env.storage().persistent().set(&key, value);
|
|
751
|
+
if let Some(utils::ttl::TtlConfig { threshold, extend_to }) = utils::ttl::TtlConfigStorage::persistent(
|
|
752
|
+
env,
|
|
753
|
+
) {
|
|
754
|
+
env.storage().persistent().extend_ttl(&key, threshold, extend_to);
|
|
755
|
+
}
|
|
756
|
+
}
|
|
757
|
+
pub fn remove_string_value(env: &soroban_sdk::Env, key: &String) {
|
|
758
|
+
let key = StorageKeys::StringValue(key.clone());
|
|
759
|
+
env.storage().persistent().remove(&key);
|
|
760
|
+
}
|
|
761
|
+
pub fn set_or_remove_string_value(
|
|
762
|
+
env: &soroban_sdk::Env,
|
|
763
|
+
key: &String,
|
|
764
|
+
value: &Option<String>,
|
|
765
|
+
) {
|
|
766
|
+
match value.as_ref() {
|
|
767
|
+
Some(v) => Self::set_string_value(env, key, v),
|
|
768
|
+
None => Self::remove_string_value(env, key),
|
|
769
|
+
}
|
|
770
|
+
}
|
|
771
|
+
pub fn has_string_value(env: &soroban_sdk::Env, key: &String) -> bool {
|
|
772
|
+
let key = StorageKeys::StringValue(key.clone());
|
|
773
|
+
let exists = env.storage().persistent().has(&key);
|
|
774
|
+
if exists {
|
|
775
|
+
if let Some(utils::ttl::TtlConfig { threshold, extend_to }) = utils::ttl::TtlConfigStorage::persistent(
|
|
776
|
+
env,
|
|
777
|
+
) {
|
|
778
|
+
env.storage().persistent().extend_ttl(&key, threshold, extend_to);
|
|
779
|
+
}
|
|
780
|
+
}
|
|
781
|
+
exists
|
|
782
|
+
}
|
|
783
|
+
pub fn extend_string_value_ttl(
|
|
784
|
+
env: &soroban_sdk::Env,
|
|
785
|
+
key: &String,
|
|
786
|
+
threshold: u32,
|
|
787
|
+
extend_to: u32,
|
|
788
|
+
) {
|
|
789
|
+
let key = StorageKeys::StringValue(key.clone());
|
|
790
|
+
env.storage().persistent().extend_ttl(&key, threshold, extend_to);
|
|
791
|
+
}
|
|
792
|
+
pub fn vec_value(env: &soroban_sdk::Env, key: &Vec<u32>) -> Option<Vec<u32>> {
|
|
793
|
+
let key = StorageKeys::VecValue(key.clone());
|
|
794
|
+
let value = env.storage().persistent().get::<_, Vec<u32>>(&key);
|
|
795
|
+
if value.is_some() {
|
|
796
|
+
if let Some(utils::ttl::TtlConfig { threshold, extend_to }) = utils::ttl::TtlConfigStorage::persistent(
|
|
797
|
+
env,
|
|
798
|
+
) {
|
|
799
|
+
env.storage().persistent().extend_ttl(&key, threshold, extend_to);
|
|
800
|
+
}
|
|
801
|
+
}
|
|
802
|
+
value
|
|
803
|
+
}
|
|
804
|
+
pub fn set_vec_value(env: &soroban_sdk::Env, key: &Vec<u32>, value: &Vec<u32>) {
|
|
805
|
+
let key = StorageKeys::VecValue(key.clone());
|
|
806
|
+
env.storage().persistent().set(&key, value);
|
|
807
|
+
if let Some(utils::ttl::TtlConfig { threshold, extend_to }) = utils::ttl::TtlConfigStorage::persistent(
|
|
808
|
+
env,
|
|
809
|
+
) {
|
|
810
|
+
env.storage().persistent().extend_ttl(&key, threshold, extend_to);
|
|
811
|
+
}
|
|
812
|
+
}
|
|
813
|
+
pub fn remove_vec_value(env: &soroban_sdk::Env, key: &Vec<u32>) {
|
|
814
|
+
let key = StorageKeys::VecValue(key.clone());
|
|
815
|
+
env.storage().persistent().remove(&key);
|
|
816
|
+
}
|
|
817
|
+
pub fn set_or_remove_vec_value(
|
|
818
|
+
env: &soroban_sdk::Env,
|
|
819
|
+
key: &Vec<u32>,
|
|
820
|
+
value: &Option<Vec<u32>>,
|
|
821
|
+
) {
|
|
822
|
+
match value.as_ref() {
|
|
823
|
+
Some(v) => Self::set_vec_value(env, key, v),
|
|
824
|
+
None => Self::remove_vec_value(env, key),
|
|
825
|
+
}
|
|
826
|
+
}
|
|
827
|
+
pub fn has_vec_value(env: &soroban_sdk::Env, key: &Vec<u32>) -> bool {
|
|
828
|
+
let key = StorageKeys::VecValue(key.clone());
|
|
829
|
+
let exists = env.storage().persistent().has(&key);
|
|
830
|
+
if exists {
|
|
831
|
+
if let Some(utils::ttl::TtlConfig { threshold, extend_to }) = utils::ttl::TtlConfigStorage::persistent(
|
|
832
|
+
env,
|
|
833
|
+
) {
|
|
834
|
+
env.storage().persistent().extend_ttl(&key, threshold, extend_to);
|
|
835
|
+
}
|
|
836
|
+
}
|
|
837
|
+
exists
|
|
838
|
+
}
|
|
839
|
+
pub fn extend_vec_value_ttl(
|
|
840
|
+
env: &soroban_sdk::Env,
|
|
841
|
+
key: &Vec<u32>,
|
|
842
|
+
threshold: u32,
|
|
843
|
+
extend_to: u32,
|
|
844
|
+
) {
|
|
845
|
+
let key = StorageKeys::VecValue(key.clone());
|
|
846
|
+
env.storage().persistent().extend_ttl(&key, threshold, extend_to);
|
|
847
|
+
}
|
|
848
|
+
pub fn address_value(env: &soroban_sdk::Env, key: &Address) -> Option<Address> {
|
|
849
|
+
let key = StorageKeys::AddressValue(key.clone());
|
|
850
|
+
let value = env.storage().persistent().get::<_, Address>(&key);
|
|
851
|
+
if value.is_some() {
|
|
852
|
+
if let Some(utils::ttl::TtlConfig { threshold, extend_to }) = utils::ttl::TtlConfigStorage::persistent(
|
|
853
|
+
env,
|
|
854
|
+
) {
|
|
855
|
+
env.storage().persistent().extend_ttl(&key, threshold, extend_to);
|
|
856
|
+
}
|
|
857
|
+
}
|
|
858
|
+
value
|
|
859
|
+
}
|
|
860
|
+
pub fn set_address_value(env: &soroban_sdk::Env, key: &Address, value: &Address) {
|
|
861
|
+
let key = StorageKeys::AddressValue(key.clone());
|
|
862
|
+
env.storage().persistent().set(&key, value);
|
|
863
|
+
if let Some(utils::ttl::TtlConfig { threshold, extend_to }) = utils::ttl::TtlConfigStorage::persistent(
|
|
864
|
+
env,
|
|
865
|
+
) {
|
|
866
|
+
env.storage().persistent().extend_ttl(&key, threshold, extend_to);
|
|
867
|
+
}
|
|
868
|
+
}
|
|
869
|
+
pub fn remove_address_value(env: &soroban_sdk::Env, key: &Address) {
|
|
870
|
+
let key = StorageKeys::AddressValue(key.clone());
|
|
871
|
+
env.storage().persistent().remove(&key);
|
|
872
|
+
}
|
|
873
|
+
pub fn set_or_remove_address_value(
|
|
874
|
+
env: &soroban_sdk::Env,
|
|
875
|
+
key: &Address,
|
|
876
|
+
value: &Option<Address>,
|
|
877
|
+
) {
|
|
878
|
+
match value.as_ref() {
|
|
879
|
+
Some(v) => Self::set_address_value(env, key, v),
|
|
880
|
+
None => Self::remove_address_value(env, key),
|
|
881
|
+
}
|
|
882
|
+
}
|
|
883
|
+
pub fn has_address_value(env: &soroban_sdk::Env, key: &Address) -> bool {
|
|
884
|
+
let key = StorageKeys::AddressValue(key.clone());
|
|
885
|
+
let exists = env.storage().persistent().has(&key);
|
|
886
|
+
if exists {
|
|
887
|
+
if let Some(utils::ttl::TtlConfig { threshold, extend_to }) = utils::ttl::TtlConfigStorage::persistent(
|
|
888
|
+
env,
|
|
889
|
+
) {
|
|
890
|
+
env.storage().persistent().extend_ttl(&key, threshold, extend_to);
|
|
891
|
+
}
|
|
892
|
+
}
|
|
893
|
+
exists
|
|
894
|
+
}
|
|
895
|
+
pub fn extend_address_value_ttl(
|
|
896
|
+
env: &soroban_sdk::Env,
|
|
897
|
+
key: &Address,
|
|
898
|
+
threshold: u32,
|
|
899
|
+
extend_to: u32,
|
|
900
|
+
) {
|
|
901
|
+
let key = StorageKeys::AddressValue(key.clone());
|
|
902
|
+
env.storage().persistent().extend_ttl(&key, threshold, extend_to);
|
|
903
|
+
}
|
|
904
|
+
pub fn unit_variant(env: &soroban_sdk::Env) -> Option<u32> {
|
|
905
|
+
let key = StorageKeys::UnitVariant;
|
|
906
|
+
let value = env.storage().persistent().get::<_, u32>(&key);
|
|
907
|
+
if value.is_some() {
|
|
908
|
+
if let Some(utils::ttl::TtlConfig { threshold, extend_to }) = utils::ttl::TtlConfigStorage::persistent(
|
|
909
|
+
env,
|
|
910
|
+
) {
|
|
911
|
+
env.storage().persistent().extend_ttl(&key, threshold, extend_to);
|
|
912
|
+
}
|
|
913
|
+
}
|
|
914
|
+
value
|
|
915
|
+
}
|
|
916
|
+
pub fn set_unit_variant(env: &soroban_sdk::Env, value: &u32) {
|
|
917
|
+
let key = StorageKeys::UnitVariant;
|
|
918
|
+
env.storage().persistent().set(&key, value);
|
|
919
|
+
if let Some(utils::ttl::TtlConfig { threshold, extend_to }) = utils::ttl::TtlConfigStorage::persistent(
|
|
920
|
+
env,
|
|
921
|
+
) {
|
|
922
|
+
env.storage().persistent().extend_ttl(&key, threshold, extend_to);
|
|
923
|
+
}
|
|
924
|
+
}
|
|
925
|
+
pub fn remove_unit_variant(env: &soroban_sdk::Env) {
|
|
926
|
+
let key = StorageKeys::UnitVariant;
|
|
927
|
+
env.storage().persistent().remove(&key);
|
|
928
|
+
}
|
|
929
|
+
pub fn set_or_remove_unit_variant(env: &soroban_sdk::Env, value: &Option<u32>) {
|
|
930
|
+
match value.as_ref() {
|
|
931
|
+
Some(v) => Self::set_unit_variant(env, v),
|
|
932
|
+
None => Self::remove_unit_variant(env),
|
|
933
|
+
}
|
|
934
|
+
}
|
|
935
|
+
pub fn has_unit_variant(env: &soroban_sdk::Env) -> bool {
|
|
936
|
+
let key = StorageKeys::UnitVariant;
|
|
937
|
+
let exists = env.storage().persistent().has(&key);
|
|
938
|
+
if exists {
|
|
939
|
+
if let Some(utils::ttl::TtlConfig { threshold, extend_to }) = utils::ttl::TtlConfigStorage::persistent(
|
|
940
|
+
env,
|
|
941
|
+
) {
|
|
942
|
+
env.storage().persistent().extend_ttl(&key, threshold, extend_to);
|
|
943
|
+
}
|
|
944
|
+
}
|
|
945
|
+
exists
|
|
946
|
+
}
|
|
947
|
+
pub fn extend_unit_variant_ttl(
|
|
948
|
+
env: &soroban_sdk::Env,
|
|
949
|
+
threshold: u32,
|
|
950
|
+
extend_to: u32,
|
|
951
|
+
) {
|
|
952
|
+
let key = StorageKeys::UnitVariant;
|
|
953
|
+
env.storage().persistent().extend_ttl(&key, threshold, extend_to);
|
|
954
|
+
}
|
|
955
|
+
pub fn named_variant(
|
|
956
|
+
env: &soroban_sdk::Env,
|
|
957
|
+
first: u32,
|
|
958
|
+
second: &String,
|
|
959
|
+
third: &Address,
|
|
960
|
+
) -> Option<u32> {
|
|
961
|
+
let key = StorageKeys::NamedVariant(first, second.clone(), third.clone());
|
|
962
|
+
let value = env.storage().persistent().get::<_, u32>(&key);
|
|
963
|
+
if value.is_some() {
|
|
964
|
+
if let Some(utils::ttl::TtlConfig { threshold, extend_to }) = utils::ttl::TtlConfigStorage::persistent(
|
|
965
|
+
env,
|
|
966
|
+
) {
|
|
967
|
+
env.storage().persistent().extend_ttl(&key, threshold, extend_to);
|
|
968
|
+
}
|
|
969
|
+
}
|
|
970
|
+
value
|
|
971
|
+
}
|
|
972
|
+
pub fn set_named_variant(
|
|
973
|
+
env: &soroban_sdk::Env,
|
|
974
|
+
first: u32,
|
|
975
|
+
second: &String,
|
|
976
|
+
third: &Address,
|
|
977
|
+
value: &u32,
|
|
978
|
+
) {
|
|
979
|
+
let key = StorageKeys::NamedVariant(first, second.clone(), third.clone());
|
|
980
|
+
env.storage().persistent().set(&key, value);
|
|
981
|
+
if let Some(utils::ttl::TtlConfig { threshold, extend_to }) = utils::ttl::TtlConfigStorage::persistent(
|
|
982
|
+
env,
|
|
983
|
+
) {
|
|
984
|
+
env.storage().persistent().extend_ttl(&key, threshold, extend_to);
|
|
985
|
+
}
|
|
986
|
+
}
|
|
987
|
+
pub fn remove_named_variant(
|
|
988
|
+
env: &soroban_sdk::Env,
|
|
989
|
+
first: u32,
|
|
990
|
+
second: &String,
|
|
991
|
+
third: &Address,
|
|
992
|
+
) {
|
|
993
|
+
let key = StorageKeys::NamedVariant(first, second.clone(), third.clone());
|
|
994
|
+
env.storage().persistent().remove(&key);
|
|
995
|
+
}
|
|
996
|
+
pub fn set_or_remove_named_variant(
|
|
997
|
+
env: &soroban_sdk::Env,
|
|
998
|
+
first: u32,
|
|
999
|
+
second: &String,
|
|
1000
|
+
third: &Address,
|
|
1001
|
+
value: &Option<u32>,
|
|
1002
|
+
) {
|
|
1003
|
+
match value.as_ref() {
|
|
1004
|
+
Some(v) => Self::set_named_variant(env, first, second, third, v),
|
|
1005
|
+
None => Self::remove_named_variant(env, first, second, third),
|
|
1006
|
+
}
|
|
1007
|
+
}
|
|
1008
|
+
pub fn has_named_variant(
|
|
1009
|
+
env: &soroban_sdk::Env,
|
|
1010
|
+
first: u32,
|
|
1011
|
+
second: &String,
|
|
1012
|
+
third: &Address,
|
|
1013
|
+
) -> bool {
|
|
1014
|
+
let key = StorageKeys::NamedVariant(first, second.clone(), third.clone());
|
|
1015
|
+
let exists = env.storage().persistent().has(&key);
|
|
1016
|
+
if exists {
|
|
1017
|
+
if let Some(utils::ttl::TtlConfig { threshold, extend_to }) = utils::ttl::TtlConfigStorage::persistent(
|
|
1018
|
+
env,
|
|
1019
|
+
) {
|
|
1020
|
+
env.storage().persistent().extend_ttl(&key, threshold, extend_to);
|
|
1021
|
+
}
|
|
1022
|
+
}
|
|
1023
|
+
exists
|
|
1024
|
+
}
|
|
1025
|
+
pub fn extend_named_variant_ttl(
|
|
1026
|
+
env: &soroban_sdk::Env,
|
|
1027
|
+
first: u32,
|
|
1028
|
+
second: &String,
|
|
1029
|
+
third: &Address,
|
|
1030
|
+
threshold: u32,
|
|
1031
|
+
extend_to: u32,
|
|
1032
|
+
) {
|
|
1033
|
+
let key = StorageKeys::NamedVariant(first, second.clone(), third.clone());
|
|
1034
|
+
env.storage().persistent().extend_ttl(&key, threshold, extend_to);
|
|
1035
|
+
}
|
|
1036
|
+
pub fn cached_value(env: &soroban_sdk::Env, key: &Address) -> Option<u64> {
|
|
1037
|
+
let key = StorageKeys::CachedValue(key.clone());
|
|
1038
|
+
let value = env.storage().persistent().get::<_, u64>(&key);
|
|
1039
|
+
value
|
|
1040
|
+
}
|
|
1041
|
+
pub fn set_cached_value(env: &soroban_sdk::Env, key: &Address, value: &u64) {
|
|
1042
|
+
let key = StorageKeys::CachedValue(key.clone());
|
|
1043
|
+
env.storage().persistent().set(&key, value);
|
|
1044
|
+
}
|
|
1045
|
+
pub fn remove_cached_value(env: &soroban_sdk::Env, key: &Address) {
|
|
1046
|
+
let key = StorageKeys::CachedValue(key.clone());
|
|
1047
|
+
env.storage().persistent().remove(&key);
|
|
1048
|
+
}
|
|
1049
|
+
pub fn set_or_remove_cached_value(
|
|
1050
|
+
env: &soroban_sdk::Env,
|
|
1051
|
+
key: &Address,
|
|
1052
|
+
value: &Option<u64>,
|
|
1053
|
+
) {
|
|
1054
|
+
match value.as_ref() {
|
|
1055
|
+
Some(v) => Self::set_cached_value(env, key, v),
|
|
1056
|
+
None => Self::remove_cached_value(env, key),
|
|
1057
|
+
}
|
|
1058
|
+
}
|
|
1059
|
+
pub fn has_cached_value(env: &soroban_sdk::Env, key: &Address) -> bool {
|
|
1060
|
+
let key = StorageKeys::CachedValue(key.clone());
|
|
1061
|
+
env.storage().persistent().has(&key)
|
|
1062
|
+
}
|
|
1063
|
+
pub fn extend_cached_value_ttl(
|
|
1064
|
+
env: &soroban_sdk::Env,
|
|
1065
|
+
key: &Address,
|
|
1066
|
+
threshold: u32,
|
|
1067
|
+
extend_to: u32,
|
|
1068
|
+
) {
|
|
1069
|
+
let key = StorageKeys::CachedValue(key.clone());
|
|
1070
|
+
env.storage().persistent().extend_ttl(&key, threshold, extend_to);
|
|
1071
|
+
}
|
|
1072
|
+
}
|