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

feat: Convert all query calls to update calls #115

Merged
merged 1 commit into from
Jun 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
12 changes: 8 additions & 4 deletions src/commands/send.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,14 @@ pub async fn submit_unsigned_ingress(
args: Vec<u8>,
dry_run: bool,
) -> AnyhowResult {
let msg = crate::lib::signing::sign(&AuthInfo::NoAuth, canister_id, method_name, args)?;
let ingress = msg.message;
send(
&ingress,
let msg = crate::lib::signing::sign_ingress_with_request_status_query(
&AuthInfo::NoAuth,
canister_id,
method_name,
args,
)?;
submit_ingress_and_check_status(
&msg,
&SendOpts {
file_name: Default::default(),
yes: false,
Expand Down
39 changes: 9 additions & 30 deletions src/lib/signing.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use crate::lib::get_idl_string;
use crate::lib::{get_candid_type, get_local_candid};
use crate::lib::{AnyhowResult, AuthInfo};
use anyhow::{anyhow, Context};
use ic_agent::agent::QueryBuilder;
use ic_agent::agent::UpdateBuilder;
use ic_agent::RequestId;
use ic_types::principal::Principal;
Expand Down Expand Up @@ -105,42 +103,23 @@ pub fn sign(
method_name: &str,
args: Vec<u8>,
) -> AnyhowResult<SignedMessageWithRequestId> {
let spec = get_local_candid(canister_id)?;
let method_type = get_candid_type(spec, method_name);
let is_query = match &method_type {
Some((_, f)) => f.is_query(),
_ => false,
};

let ingress_expiry = Duration::from_secs(5 * 60);

let (content, request_id) = if is_query {
let bytes = QueryBuilder::new(&get_agent(auth)?, canister_id, method_name.to_string())
.with_arg(args)
.expire_after(ingress_expiry)
.sign()?
.signed_query;
(hex::encode(bytes), None)
} else {
let signed_update =
UpdateBuilder::new(&get_agent(auth)?, canister_id, method_name.to_string())
.with_arg(args)
.expire_after(ingress_expiry)
.sign()?;
let signed_update = UpdateBuilder::new(&get_agent(auth)?, canister_id, method_name.to_string())
.with_arg(args)
.expire_after(ingress_expiry)
.sign()?;

(
hex::encode(signed_update.signed_update),
Some(signed_update.request_id),
)
};
let content = hex::encode(signed_update.signed_update);
let request_id = signed_update.request_id;

Ok(SignedMessageWithRequestId {
message: Ingress {
call_type: if is_query { "query" } else { "update" }.to_string(),
request_id: request_id.map(|v| v.into()),
call_type: "update".to_string(),
request_id: Some(request_id.into()),
content,
},
request_id,
request_id: Some(request_id),
})
}

Expand Down
2 changes: 1 addition & 1 deletion tests/outputs/account-balance.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Sending message with

Call type: query
Call type: update
Sender: 2vxsx-fae
Canister id: ryjl3-tyaaa-aaaaa-aaaba-cai
Method name: account_balance_dfx
Expand Down
2 changes: 1 addition & 1 deletion tests/outputs/get-neuron-info.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Sending message with

Call type: query
Call type: update
Sender: 2vxsx-fae
Canister id: rrkah-fqaaa-aaaaa-aaaaq-cai
Method name: get_neuron_info
Expand Down
2 changes: 1 addition & 1 deletion tests/outputs/get-proposal-info.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Sending message with

Call type: query
Call type: update
Sender: 2vxsx-fae
Canister id: rrkah-fqaaa-aaaaa-aaaaq-cai
Method name: get_proposal_info
Expand Down
2 changes: 1 addition & 1 deletion tests/outputs/list-neurons-many.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Sending message with

Call type: query
Call type: update
Sender: fdsgv-62ihb-nbiqv-xgic5-iefsv-3cscz-tmbzv-63qd5-vh43v-dqfrt-pae
Canister id: rrkah-fqaaa-aaaaa-aaaaq-cai
Method name: list_neurons
Expand Down
2 changes: 1 addition & 1 deletion tests/outputs/list-neurons.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Sending message with

Call type: query
Call type: update
Sender: fdsgv-62ihb-nbiqv-xgic5-iefsv-3cscz-tmbzv-63qd5-vh43v-dqfrt-pae
Canister id: rrkah-fqaaa-aaaaa-aaaaq-cai
Method name: list_neurons
Expand Down
2 changes: 1 addition & 1 deletion tests/outputs/list-proposals.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Sending message with

Call type: query
Call type: update
Sender: 2vxsx-fae
Canister id: rrkah-fqaaa-aaaaa-aaaaq-cai
Method name: list_proposals
Expand Down