Skip to content

Commit

Permalink
Merge pull request #6 from MoonBite-GmbH/hotfix/add-features
Browse files Browse the repository at this point in the history
Multisig: Hotfix/add features
  • Loading branch information
ueco-jb authored Aug 27, 2024
2 parents 40c2138 + bec5ec8 commit 46c5ac4
Show file tree
Hide file tree
Showing 9 changed files with 1,306 additions and 413 deletions.
42 changes: 38 additions & 4 deletions contracts/deployer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ use soroban_sdk::{
String, Symbol, Val, Vec,
};

// Values used to extend the TTL of storage
pub const DAY_IN_LEDGERS: u32 = 17280;
pub const BUMP_AMOUNT: u32 = 7 * DAY_IN_LEDGERS;
pub const LIFETIME_THRESHOLD: u32 = BUMP_AMOUNT - DAY_IN_LEDGERS;

// Metadata that is added on to the WASM custom section
contractmeta!(
key = "Description",
Expand Down Expand Up @@ -73,26 +78,55 @@ pub enum DataKey {

pub fn set_initialized(env: &Env) {
env.storage().instance().set(&DataKey::IsInitialized, &());
env.storage()
.instance()
.extend_ttl(LIFETIME_THRESHOLD, BUMP_AMOUNT);
}

pub fn is_initialized(env: &Env) -> bool {
env.storage()
let is_initialized = env
.storage()
.instance()
.get::<_, ()>(&DataKey::IsInitialized)
.is_some()
.is_some();

env.storage()
.instance()
.has(&DataKey::IsInitialized)
.then(|| {
env.storage()
.instance()
.extend_ttl(LIFETIME_THRESHOLD, BUMP_AMOUNT)
});

is_initialized
}

pub fn set_wasm_hash(env: &Env, hash: &BytesN<32>) {
env.storage()
.instance()
.set(&DataKey::MultisigWasmHash, hash);
env.storage()
.instance()
.extend_ttl(LIFETIME_THRESHOLD, BUMP_AMOUNT);
}

pub fn get_wasm_hash(env: &Env) -> BytesN<32> {
env.storage()
let wasm_hash = env
.storage()
.instance()
.get(&DataKey::MultisigWasmHash)
.unwrap()
.unwrap();
env.storage()
.instance()
.has(&DataKey::MultisigWasmHash)
.then(|| {
env.storage()
.instance()
.extend_ttl(LIFETIME_THRESHOLD, BUMP_AMOUNT)
});

wasm_hash
}

#[cfg(test)]
Expand Down
4 changes: 3 additions & 1 deletion contracts/deployer/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ fn test_deploy_multisig_from_contract() {
}

#[test]
#[should_panic]
#[should_panic(
expected = "Multisig Deployer: Initialize: initializing the contract twice is not allowed"
)]
fn initialize_twice() {
let env = Env::default();
let deployer_client =
Expand Down
Loading

0 comments on commit 46c5ac4

Please sign in to comment.