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

fix: update app id in contract #957

Merged
merged 4 commits into from
Nov 9, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
42 changes: 40 additions & 2 deletions crates/context/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ use calimero_store::types::{
use calimero_store::Store;
use camino::Utf8PathBuf;
use eyre::{bail, OptionExt, Result as EyreResult};
use futures_util::{AsyncRead, TryFutureExt, TryStreamExt};
use futures_util::{AsyncRead, TryStreamExt};
use rand::rngs::StdRng;
use rand::seq::IteratorRandom;
use rand::SeedableRng;
Expand Down Expand Up @@ -834,10 +834,11 @@ impl ContextManager {
Ok(contexts)
}

pub fn update_application_id(
pub async fn update_application_id(
&self,
context_id: ContextId,
application_id: ApplicationId,
signer_id: PublicKey,
) -> EyreResult<()> {
// todo! use context config
MatejVukosav marked this conversation as resolved.
Show resolved Hide resolved

Expand All @@ -849,6 +850,43 @@ impl ContextManager {
bail!("Context not found")
};

let this = self.clone();
petarjuki7 marked this conversation as resolved.
Show resolved Hide resolved

let Some(application) = this.get_application(&application_id)? else {
bail!("Application with id {:?} not found", application_id)
};

let Some(ContextIdentityValue {
private_key: Some(requester_secret),
}) = handle.get(&ContextIdentityKey::new(context_id, signer_id))?
else {
bail!(
"Identity {:?} not found in context {:?}",
petarjuki7 marked this conversation as resolved.
Show resolved Hide resolved
signer_id,
context_id
)
};

let _ = this
.config_client
.mutate::<ContextConfigEnv>(
this.client_config.new.protocol.as_str().into(),
this.client_config.new.network.as_str().into(),
this.client_config.new.contract_id.as_str().into(),
MatejVukosav marked this conversation as resolved.
Show resolved Hide resolved
)
.update_application(
context_id.rt().expect("bla"),
petarjuki7 marked this conversation as resolved.
Show resolved Hide resolved
ApplicationConfig::new(
application.id.rt().expect("infallible conversion"),
application.blob.rt().expect("infallible conversion"),
application.size,
ApplicationSourceConfig(application.source.to_string().into()),
ApplicationMetadataConfig(Repr::new(application.metadata.into())),
),
)
.send(requester_secret)
.await?;

value.application = ApplicationMetaKey::new(application_id);

handle.put(&key, &value)?;
Expand Down
4 changes: 3 additions & 1 deletion crates/meroctl/src/cli/context/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,9 @@ async fn update_context_application(
&format!("admin-api/dev/contexts/{context_id}/application"),
)?;

let request = UpdateContextApplicationRequest::new(application_id);
//How to make conversion from libp2p to public key
let public_key = keypair.public();
let request = UpdateContextApplicationRequest::new(application_id, public_key);
petarjuki7 marked this conversation as resolved.
Show resolved Hide resolved

let response: UpdateContextApplicationResponse =
do_request(client, url, Some(request), keypair, RequestType::Post).await?;
Expand Down
8 changes: 6 additions & 2 deletions crates/server-primitives/src/admin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -395,11 +395,15 @@ impl JoinContextResponse {
#[serde(rename_all = "camelCase")]
pub struct UpdateContextApplicationRequest {
pub application_id: ApplicationId,
pub executor_public_key: PublicKey,
}

impl UpdateContextApplicationRequest {
pub const fn new(application_id: ApplicationId) -> Self {
Self { application_id }
pub const fn new(application_id: ApplicationId, executor_public_key: PublicKey) -> Self {
Self {
application_id,
executor_public_key,
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,12 @@ pub async fn handler(

let result = state
.ctx_manager
.update_application_id(context_id_result, req.application_id)
.update_application_id(
context_id_result,
req.application_id,
req.executor_public_key,
)
.await
.map_err(parse_api_error);

match result {
Expand Down
Loading