forked from SiLioLabs/PayFlow
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupgrade.rs
More file actions
33 lines (26 loc) · 1.06 KB
/
Copy pathupgrade.rs
File metadata and controls
33 lines (26 loc) · 1.06 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
use soroban_sdk::{BytesN, Env};
use crate::{admin, errors::ContractError, events, DataKey};
pub fn propose_upgrade(env: &Env, new_wasm_hash: BytesN<32>) {
admin::require_admin(env);
env.storage().temporary().set(&DataKey::PendingUpgrade, &new_wasm_hash);
env.storage().temporary().extend_ttl(&DataKey::PendingUpgrade, 17280, 17280);
events::publish_upgrade_proposed(env, &new_wasm_hash);
}
pub fn commit_upgrade(env: &Env) {
admin::require_admin(env);
let pending_hash: BytesN<32> = env
.storage()
.temporary()
.get(&DataKey::PendingUpgrade)
.unwrap_or_else(|| env.panic_with_error(ContractError::NoPendingProposal));
env.storage().temporary().remove(&DataKey::PendingUpgrade);
#[cfg(not(test))]
env.deployer()
.update_current_contract_wasm(pending_hash.clone());
events::publish_upgraded(env, &pending_hash);
}
#[cfg(test)]
pub fn upgrade(env: &Env, new_wasm_hash: BytesN<32>) {
// Keep direct upgrade available for the test environment
events::publish_upgraded(env, &new_wasm_hash);
}