Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: nuke proxy when erasing context config #990

Merged
merged 1 commit into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions contracts/context-config/src/sys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use calimero_context_config::repr::Repr;
use calimero_context_config::types::{Application, ContextId, ContextIdentity, SignerId};
use calimero_context_config::{SystemRequest, Timestamp};
use near_sdk::store::{IterableMap, IterableSet};
use near_sdk::{env, near};
use near_sdk::{env, near, Gas, NearToken, Promise};

use crate::{parse_input, Config, ContextConfigs, ContextConfigsExt};

Expand Down Expand Up @@ -36,9 +36,17 @@ impl ContextConfigs {
for (_, context) in self.contexts.drain() {
let _ignored = context.application.into_inner();
context.members.into_inner().clear();
let _ignored = context.proxy.into_inner();
let proxy = context.proxy.into_inner();

let _is_sent_on_drop = Promise::new(proxy).function_call(
"nuke".to_owned(),
vec![],
NearToken::default(),
Gas::from_tgas(1),
);
}

self.next_proxy_id = 0;
self.proxy_code.set(None);

env::log_str(&format!(
Expand Down
1 change: 0 additions & 1 deletion contracts/proxy-lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ impl ProxyContract {
&self,
proposal_id: Repr<ProposalId>,
) -> Option<Vec<Repr<SignerId>>> {
let approvals_for_proposal = self.approvals.get(&proposal_id);
let approvals = self.approvals.get(&proposal_id)?;
Some(approvals.iter().flat_map(|a| a.rt()).collect())
}
Expand Down
21 changes: 21 additions & 0 deletions contracts/proxy-lib/src/mutate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ impl ProxyContract {
}
}
}

#[near]
impl ProxyContract {
#[private]
Expand Down Expand Up @@ -226,6 +227,26 @@ impl ProxyContract {
)
}

fn erase(&mut self) {
// if this is going to be exposed, it should be a proposal
self.proposals.clear();
self.approvals.clear();
self.num_proposals_pk.clear();
self.context_storage.clear();
}

pub fn nuke(&mut self) -> Promise {
require!(
env::predecessor_account_id() == self.context_config_account_id,
"Only the context config contract can nuke the proxy"
);

self.erase();

Promise::new(env::current_account_id())
.delete_account(self.context_config_account_id.clone())
}

#[private]
pub fn update_contract_callback(
&mut self,
Expand Down