Skip to content

Commit

Permalink
Fixed keypair
Browse files Browse the repository at this point in the history
  • Loading branch information
petarjuki7 committed Nov 8, 2024
1 parent 7fdd038 commit c70862d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 19 deletions.
20 changes: 7 additions & 13 deletions crates/context/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -850,32 +850,26 @@ impl ContextManager {
bail!("Context not found")
};

let this = self.clone();

let Some(application) = this.get_application(&application_id)? else {
let Some(application) = self.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 {:?}",
signer_id,
context_id
)
bail!("'{}' is not a member of '{}'", signer_id, context_id)
};

let _ = this
let _ = self
.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(),
self.client_config.new.protocol.as_str().into(),
self.client_config.new.network.as_str().into(),
self.client_config.new.contract_id.as_str().into(),
)
.update_application(
context_id.rt().expect("bla"),
context_id.rt().expect("infallible conversion"),
ApplicationConfig::new(
application.id.rt().expect("infallible conversion"),
application.blob.rt().expect("infallible conversion"),
Expand Down
15 changes: 9 additions & 6 deletions crates/meroctl/src/cli/context/create.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use calimero_primitives::application::ApplicationId;
use calimero_primitives::context::ContextId;
use calimero_primitives::hash::Hash;
use calimero_primitives::identity::PublicKey;
use calimero_server_primitives::admin::{
CreateContextRequest, CreateContextResponse, GetApplicationResponse,
InstallApplicationResponse, InstallDevApplicationRequest, UpdateContextApplicationRequest,
Expand Down Expand Up @@ -118,7 +119,7 @@ impl CreateCommand {
)
.await?;

let context_id = create_context(
let (context_id, member_public_key) = create_context(
environment,
&client,
multiaddr,
Expand All @@ -137,6 +138,7 @@ impl CreateCommand {
path,
metadata,
&config.identity,
member_public_key,
)
.await?;
}
Expand All @@ -155,7 +157,7 @@ async fn create_context(
application_id: ApplicationId,
params: Option<String>,
keypair: &Keypair,
) -> EyreResult<ContextId> {
) -> EyreResult<(ContextId, PublicKey)> {
if !app_installed(base_multiaddr, &application_id, client, keypair).await? {
bail!("Application is not installed on node.")
}
Expand All @@ -172,7 +174,7 @@ async fn create_context(

environment.output.write(&response);

Ok(response.data.context_id)
Ok((response.data.context_id, response.data.member_public_key))
}

async fn watch_app_and_update_context(
Expand All @@ -183,6 +185,7 @@ async fn watch_app_and_update_context(
path: Utf8PathBuf,
metadata: Option<Vec<u8>>,
keypair: &Keypair,
member_public_key: PublicKey,
) -> EyreResult<()> {
let (tx, mut rx) = mpsc::channel(1);

Expand Down Expand Up @@ -240,6 +243,7 @@ async fn watch_app_and_update_context(
context_id,
application_id,
keypair,
member_public_key,
)
.await?;
}
Expand All @@ -254,15 +258,14 @@ async fn update_context_application(
context_id: ContextId,
application_id: ApplicationId,
keypair: &Keypair,
member_public_key: PublicKey,
) -> EyreResult<()> {
let url = multiaddr_to_url(
base_multiaddr,
&format!("admin-api/dev/contexts/{context_id}/application"),
)?;

//How to make conversion from libp2p to public key
let public_key = keypair.public();
let request = UpdateContextApplicationRequest::new(application_id, public_key);
let request = UpdateContextApplicationRequest::new(application_id, member_public_key);

let response: UpdateContextApplicationResponse =
do_request(client, url, Some(request), keypair, RequestType::Post).await?;
Expand Down

0 comments on commit c70862d

Please sign in to comment.