Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
mraszyk committed Nov 28, 2024
1 parent 724abf6 commit 75f52b8
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 6 deletions.
12 changes: 10 additions & 2 deletions src/dfx/src/commands/canister/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -352,12 +352,20 @@ To figure out the id of your wallet, run 'dfx identity get-wallet (--network ic)
let pocketic = env.get_pocketic();
if let Some(pocketic) = pocketic {
let res = pocketic
.query_call(canister_id, *sender, method_name, arg_value)
.query_call_with_effective_principal(
canister_id,
RawEffectivePrincipal::CanisterId(
effective_canister_id.as_slice().to_vec(),
),
*sender,
method_name,
arg_value,
)
.await
.map_err(|err| anyhow!("Failed to perform query call: {}", err))?;
match res {
WasmResult::Reply(data) => data,
WasmResult::Reject(err) => bail!("Query call rejected: {}", err),
WasmResult::Reject(err) => bail!("Canister rejected: {}", err),
}
} else {
bail!("Impersonating sender is only supported for a local PocketIC instance.")
Expand Down
26 changes: 22 additions & 4 deletions src/dfx/src/lib/operations/canister/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,28 @@ where
.await
.context("Query call (without wallet) failed.")?
}
CallSender::Impersonate(_) => {
unreachable!(
"Impersonating sender in management canister query calls is not supported."
)
CallSender::Impersonate(sender) => {
let pocketic = env.get_pocketic();
if let Some(pocketic) = pocketic {
let res = pocketic
.query_call_with_effective_principal(
Principal::management_canister(),
RawEffectivePrincipal::CanisterId(destination_canister.as_slice().to_vec()),
*sender,
method,
encode_args((arg,)).unwrap(),
)
.await
.map_err(|err| anyhow!("Failed to perform query call: {}", err))?;
match res {
WasmResult::Reply(data) => {
decode_args(&data).context("Failed to decode query call response.")?
}
WasmResult::Reject(err) => bail!("Canister rejected: {}", err),
}
} else {
bail!("Impersonating sender is only supported for a local PocketIC instance.")
}
}
CallSender::Wallet(wallet_id) => {
let wallet = build_wallet_canister(*wallet_id, agent).await?;
Expand Down

0 comments on commit 75f52b8

Please sign in to comment.