Skip to content

Commit

Permalink
Merge branch 'feat--add-proxy-contract-node-logic' of github.com:cali…
Browse files Browse the repository at this point in the history
…mero-network/core into feat--add-proxy-contract-node-logic
  • Loading branch information
MatejVukosav committed Nov 8, 2024
2 parents bdfbf12 + 4e60de5 commit f3e221c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 18 deletions.
36 changes: 22 additions & 14 deletions crates/context/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ use calimero_store::types::{
};
use calimero_store::Store;
use camino::Utf8PathBuf;
use eyre::{bail, Result as EyreResult};
use eyre::{bail, OptionExt, Result as EyreResult};
use futures_util::{AsyncRead, TryFutureExt, TryStreamExt};
use rand::rngs::StdRng;
use rand::seq::IteratorRandom;
Expand Down Expand Up @@ -180,7 +180,7 @@ impl ContextManager {
(context_secret, identity_secret)
};

let handle = self.store.handle();
let mut handle = self.store.handle();

let context = {
let context_id = ContextId::from(*context_secret.public_key());
Expand All @@ -196,6 +196,19 @@ impl ContextManager {
bail!("Application is not installed on node.")
};

self.add_context(
&context,
identity_secret,
Some(ContextConfigParams {
protocol: self.client_config.new.protocol.as_str().into(),
network_id: self.client_config.new.network.as_str().into(),
contract_id: self.client_config.new.contract_id.as_str().into(),
proxy_contract: "".into(),
application_revision: 0,
members_revision: 0,
}),
)?;

let (tx, rx) = oneshot::channel();

let this = self.clone();
Expand Down Expand Up @@ -241,18 +254,11 @@ impl ContextManager {
.await?;

let proxy_contract = this.get_proxy_contract(context.id).await?;
drop(this.add_context(
&context,
identity_secret,
Some(ContextConfigParams {
protocol: this.client_config.new.protocol.as_str().into(),
network_id: this.client_config.new.network.as_str().into(),
contract_id: this.client_config.new.contract_id.as_str().into(),
proxy_contract: proxy_contract.into(),
application_revision: 0,
members_revision: 0,
}),
));

let key = ContextConfigKey::new(context.id);
let mut config = handle.get(&key)?.ok_or_eyre("expected config to exist")?;
config.proxy_contract = proxy_contract.into();
handle.put(&key, &config)?;

Ok((context.id, identity_secret.public_key()))
};
Expand Down Expand Up @@ -339,7 +345,9 @@ impl ContextManager {
}

let handle = self.store.handle();

let identity_key = ContextIdentityKey::new(context_id, invitee_id);

if handle.has(&identity_key)? {
return Ok(None);
}
Expand Down
8 changes: 4 additions & 4 deletions crates/node/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -455,17 +455,17 @@ impl Node {
)
.await
.map_err(|e| {
error!(%e, "Failed to create proposal {:?} with actions {:?} in context {:?} by identity {:?}", proposal_id, actions, context_id, executor_public_key);
error!(%e, "Failed to create proposal {:?}", proposal_id);
CallError::InternalError
})?;
}

for approval in &outcome.approvals {
for proposal_id in &outcome.approvals {
self.ctx_manager
.approve(context_id, executor_public_key, approval.clone())
.approve(context_id, executor_public_key, *proposal_id)
.await
.map_err(|e| {
error!(%e, "Failed to approve proposal {:?}", approval);
error!(%e, "Failed to approve proposal {:?}", proposal_id);
CallError::InternalError
})?;
}
Expand Down

0 comments on commit f3e221c

Please sign in to comment.