Skip to content

Commit

Permalink
Merge branch 'master' into icp_query_mutate_integration
Browse files Browse the repository at this point in the history
  • Loading branch information
frdomovic authored Nov 27, 2024
2 parents 1133242 + 31d56aa commit bd33db2
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 9 deletions.
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
27 changes: 21 additions & 6 deletions crates/context/config/src/client/protocol/near.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ use std::{time, vec};

pub use near_crypto::SecretKey;
use near_crypto::{InMemorySigner, PublicKey, Signer};
use near_jsonrpc_client::errors::{
JsonRpcError, JsonRpcServerError, JsonRpcServerResponseStatusError,
};
use near_jsonrpc_client::methods::query::{RpcQueryRequest, RpcQueryResponse};
use near_jsonrpc_client::methods::send_tx::RpcSendTransactionRequest;
use near_jsonrpc_client::methods::tx::RpcTransactionStatusRequest;
Expand Down Expand Up @@ -298,12 +301,24 @@ impl Network {
match response {
Ok(response) => break response,
Err(err) => {
let Some(RpcTransactionError::TimeoutError) = err.handler_error() else {
return Err(NearError::Custom {
operation: ErrorOperation::Mutate,
reason: err.to_string(),
});
};
#[expect(
clippy::wildcard_enum_match_arm,
reason = "quite terse, these variants"
)]
match err {
JsonRpcError::ServerError(
JsonRpcServerError::ResponseStatusError(
JsonRpcServerResponseStatusError::TimeoutError,
)
| JsonRpcServerError::HandlerError(RpcTransactionError::TimeoutError),
) => {}
_ => {
return Err(NearError::Custom {
operation: ErrorOperation::Mutate,
reason: err.to_string(),
});
}
}

if sent_at.elapsed().as_secs() > 60 {
return Err(NearError::TransactionTimeout);
Expand Down

0 comments on commit bd33db2

Please sign in to comment.