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

Refactor canister API macros to support more serialization formats #6038

Merged
merged 4 commits into from
Jul 16, 2024
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
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use crate::{mutate_state, RuntimeState};
use canister_api_macros::update_msgpack;
use canister_api_macros::update;
use canister_tracing_macros::trace;
use group_prize_bot::handle_direct_message::*;
use types::{BotMessage, MessageContentInitial, TextContent};

#[update_msgpack]
#[update(msgpack = true)]
#[trace]
fn handle_direct_message(_args: Args) -> Response {
mutate_state(handle_message)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use crate::model::pending_actions::PendingAction;
use crate::model::reward_codes::ClaimRewardCodeResult;
use crate::{mutate_state, RewardCodes, RuntimeState};
use canister_api_macros::update_msgpack;
use canister_api_macros::update;
use canister_tracing_macros::trace;
use icp_dispenser_bot::handle_direct_message::*;
use types::{BotMessage, MessageContent, MessageContentInitial, TextContent, UserId};

#[update_msgpack]
#[update(msgpack = true)]
#[trace]
fn handle_direct_message(args: Args) -> Response {
mutate_state(|state| handle_message(args, state))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use crate::guards::caller_is_local_user_index;
use crate::model::pending_actions_queue::Action;
use crate::{mutate_state, RuntimeState};
use canister_api_macros::update_msgpack;
use canister_api_macros::update;
use canister_tracing_macros::trace;
use satoshi_dice_canister::c2c_add_user::{Response::*, *};
use types::{BlobReference, CanisterId, ImageContent, MessageContentInitial, TextContent, ThumbnailData, UserId};

#[update_msgpack(guard = "caller_is_local_user_index")]
#[update(guard = "caller_is_local_user_index", msgpack = true)]
#[trace]
fn c2c_add_user(args: Args) -> Response {
mutate_state(|state| c2c_add_user_impl(args.user_id, state))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::model::pending_actions_queue::{Action, TransferCkbtc};
use crate::model::user_map::DiceRoll;
use crate::{mutate_state, RuntimeState, MAX_SATS_PER_ROLL};
use canister_api_macros::update_msgpack;
use canister_api_macros::update;
use canister_tracing_macros::trace;
use rand::RngCore;
use satoshi_dice_canister::handle_direct_message::*;
Expand All @@ -10,7 +10,7 @@ use utils::time::MINUTE_IN_MS;

const MAX_TOTAL_WINNINGS: u64 = 50_000;

#[update_msgpack]
#[update(msgpack = true)]
#[trace]
fn handle_direct_message(args: Args) -> Response {
mutate_state(|state| handle_message(args, state))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use crate::{mutate_state, RuntimeState};
use candid::Principal;
use canister_api_macros::update_msgpack;
use canister_api_macros::update;
use canister_tracing_macros::trace;
use sns1_airdrop::handle_direct_message::*;
use std::collections::hash_map::Entry::{Occupied, Vacant};
use types::{BotMessage, MessageContent, MessageContentInitial, TextContent, UserId};

#[update_msgpack]
#[update(msgpack = true)]
#[trace]
fn handle_direct_message(args: Args) -> Response {
mutate_state(|state| handle_message(args, state))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use crate::guards::caller_is_local_user_index;
use crate::read_state;
use crate::RuntimeState;
use canister_api_macros::query_msgpack;
use canister_api_macros::query;
use community_canister::c2c_can_issue_access_token_for_channel::*;
use group_chat_core::{GroupChatCore, GroupMemberInternal};
use types::{AccessTokenType, VideoCallType};

#[query_msgpack(guard = "caller_is_local_user_index")]
#[query(guard = "caller_is_local_user_index", msgpack = true)]
fn c2c_can_issue_access_token_for_channel(args: Args) -> Response {
read_state(|state| c2c_can_issue_access_token_for_channel_impl(args, state))
}
Expand Down
7 changes: 3 additions & 4 deletions backend/canisters/community/impl/src/queries/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,17 @@ use crate::guards::caller_is_local_user_index;
use crate::queries::check_replica_up_to_date;
use crate::{read_state, RuntimeState};
use candid::Principal;
use canister_api_macros::query_msgpack;
use canister_api_macros::query;
use community_canister::c2c_events::Args as C2CArgs;
use community_canister::events::{Response::*, *};
use group_chat_core::EventsResult;
use ic_cdk::query;

#[query]
#[query(candid = true)]
fn events(args: Args) -> Response {
read_state(|state| events_impl(args, None, state))
}

#[query_msgpack(guard = "caller_is_local_user_index")]
#[query(guard = "caller_is_local_user_index", msgpack = true)]
fn c2c_events(args: C2CArgs) -> Response {
read_state(|state| events_impl(args.args, Some(args.caller), state))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,17 @@ use crate::guards::caller_is_local_user_index;
use crate::queries::check_replica_up_to_date;
use crate::{read_state, RuntimeState};
use candid::Principal;
use canister_api_macros::query_msgpack;
use canister_api_macros::query;
use community_canister::c2c_events_by_index::Args as C2CArgs;
use community_canister::events_by_index::{Response::*, *};
use group_chat_core::EventsResult;
use ic_cdk::query;

#[query]
#[query(candid = true)]
fn events_by_index(args: Args) -> Response {
read_state(|state| events_by_index_impl(args, None, state))
}

#[query_msgpack(guard = "caller_is_local_user_index")]
#[query(guard = "caller_is_local_user_index", msgpack = true)]
fn c2c_events_by_index(args: C2CArgs) -> Response {
read_state(|state| events_by_index_impl(args.args, Some(args.caller), state))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,17 @@ use crate::guards::caller_is_local_user_index;
use crate::queries::check_replica_up_to_date;
use crate::{read_state, RuntimeState};
use candid::Principal;
use canister_api_macros::query_msgpack;
use canister_api_macros::query;
use community_canister::c2c_events_window::Args as C2CArgs;
use community_canister::events_window::{Response::*, *};
use group_chat_core::EventsResult;
use ic_cdk::query;

#[query]
#[query(candid = true)]
fn events_window(args: Args) -> Response {
read_state(|state| events_window_impl(args, None, state))
}

#[query_msgpack(guard = "caller_is_local_user_index")]
#[query(guard = "caller_is_local_user_index", msgpack = true)]
fn c2c_events_window(args: C2CArgs) -> Response {
read_state(|state| events_window_impl(args.args, Some(args.caller), state))
}
Expand Down
7 changes: 3 additions & 4 deletions backend/canisters/community/impl/src/queries/summary.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
use crate::read_state;
use crate::RuntimeState;
use candid::Principal;
use canister_api_macros::query_msgpack;
use canister_api_macros::query;
use community_canister::c2c_summary::{Args as C2CArgs, Response as C2CResponse};
use community_canister::summary::{Response::*, *};
use ic_cdk::query;

#[query]
#[query(candid = true)]
fn summary(args: Args) -> Response {
read_state(|state| summary_impl(args.invite_code, None, state))
}

#[query_msgpack]
#[query(msgpack = true)]
fn c2c_summary(args: C2CArgs) -> C2CResponse {
read_state(|state| summary_impl(args.invite_code, args.on_behalf_of, state))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,20 @@ use crate::model::members::CommunityMemberInternal;
use crate::RuntimeState;
use crate::{read_state, Data};
use candid::Principal;
use canister_api_macros::query_msgpack;
use canister_api_macros::query;
use community_canister::c2c_summary_updates::{Args as C2CArgs, Response as C2CResponse};
use community_canister::summary_updates::{Response::*, *};
use ic_cdk::query;
use types::{
AccessGate, CommunityCanisterCommunitySummaryUpdates, CommunityMembershipUpdates, CommunityPermissions, EventIndex,
FrozenGroupInfo, OptionUpdate, TimestampMillis,
};

#[query]
#[query(candid = true)]
fn summary_updates(args: Args) -> Response {
read_state(|state| summary_updates_impl(args.updates_since, args.invite_code, None, state))
}

#[query_msgpack]
#[query(msgpack = true)]
fn c2c_summary_updates(args: C2CArgs) -> C2CResponse {
read_state(|state| summary_updates_impl(args.updates_since, args.invite_code, args.on_behalf_of, state))
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use crate::activity_notifications::handle_activity_notification;
use crate::{mutate_state, run_regular_jobs, RuntimeState};
use canister_api_macros::update_candid_and_msgpack;
use canister_api_macros::update;
use canister_tracing_macros::trace;
use chat_events::Reader;
use community_canister::add_reaction::{Response::*, *};
use group_chat_core::{AddRemoveReactionResult, GroupChatCore};
use types::{Achievement, ChannelReactionAddedNotification, EventIndex, EventWrapper, Message, Notification, UserId};

#[update_candid_and_msgpack]
#[update(candid = true, msgpack = true)]
#[trace]
fn add_reaction(args: Args) -> Response {
run_regular_jobs();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use crate::{read_state, run_regular_jobs, RuntimeState};
use canister_api_macros::update_msgpack;
use canister_api_macros::update;
use canister_tracing_macros::trace;
use community_canister::c2c_delete_community::{Response::*, *};
use group_index_canister::c2c_delete_community;
use tracing::error;
use types::{CanisterId, CommunityId, UserId};

#[update_msgpack]
#[update(msgpack = true)]
#[trace]
async fn c2c_delete_community(_args: Args) -> Response {
run_regular_jobs();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ use crate::activity_notifications::handle_activity_notification;
use crate::guards::caller_is_group_index_or_local_group_index;
use crate::model::events::CommunityEventInternal;
use crate::{mutate_state, run_regular_jobs, RuntimeState};
use canister_api_macros::update_msgpack;
use canister_api_macros::update;
use canister_tracing_macros::trace;
use community_canister::c2c_freeze_community::{Response::*, *};
use types::{EventWrapper, FrozenGroupInfo, GroupFrozen, Timestamped};

#[update_msgpack(guard = "caller_is_group_index_or_local_group_index")]
#[update(guard = "caller_is_group_index_or_local_group_index", msgpack = true)]
#[trace]
fn c2c_freeze_community(args: Args) -> Response {
run_regular_jobs();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ use crate::guards::caller_is_user_index_or_local_user_index;
use crate::model::events::CommunityEventInternal;
use crate::model::invited_users::UserInvitation;
use crate::{mutate_state, run_regular_jobs, RuntimeState};
use canister_api_macros::update_msgpack;
use canister_api_macros::update;
use canister_tracing_macros::trace;
use community_canister::c2c_invite_users::{Response::*, *};
use types::UsersInvited;

const MAX_INVITES: usize = 100;

#[update_msgpack(guard = "caller_is_user_index_or_local_user_index")]
#[update(guard = "caller_is_user_index_or_local_user_index", msgpack = true)]
#[trace]
fn c2c_invite_users(args: Args) -> Response {
run_regular_jobs();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ use crate::activity_notifications::handle_activity_notification;
use crate::guards::caller_is_local_user_index;
use crate::updates::c2c_invite_users::invite_users_to_community_impl;
use crate::{mutate_state, run_regular_jobs, RuntimeState};
use canister_api_macros::update_msgpack;
use canister_api_macros::update;
use canister_tracing_macros::trace;
use community_canister::c2c_invite_users_to_channel::{Response::*, *};
use group_chat_core::InvitedUsersResult;

#[update_msgpack(guard = "caller_is_local_user_index")]
#[update(guard = "caller_is_local_user_index", msgpack = true)]
#[trace]
fn c2c_invite_users_to_channel(args: Args) -> Response {
run_regular_jobs();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::run_regular_jobs;
use crate::updates::c2c_join_community::join_community;
use crate::{activity_notifications::handle_activity_notification, mutate_state, read_state, RuntimeState};
use candid::Principal;
use canister_api_macros::update_msgpack;
use canister_api_macros::update;
use canister_tracing_macros::trace;
use chat_events::ChatEventInternal;
use community_canister::c2c_join_channel::{Response::*, *};
Expand All @@ -16,7 +16,7 @@ use gated_groups::{
use group_chat_core::AddResult;
use types::{AccessGate, ChannelId, MemberJoined, TimestampMillis, UniquePersonProof, VerifiedCredentialGateArgs};

#[update_msgpack(guard = "caller_is_user_index_or_local_user_index")]
#[update(guard = "caller_is_user_index_or_local_user_index", msgpack = true)]
#[trace]
async fn c2c_join_channel(args: Args) -> Response {
run_regular_jobs();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ use crate::model::events::CommunityEventInternal;
use crate::model::members::AddResult;
use crate::updates::c2c_join_channel::join_channel_synchronously;
use crate::{mutate_state, read_state, run_regular_jobs, RuntimeState};
use canister_api_macros::update_msgpack;
use canister_api_macros::update;
use canister_tracing_macros::trace;
use community_canister::c2c_join_community::{Response::*, *};
use gated_groups::{check_if_passes_gate, CheckGateArgs, CheckIfPassesGateResult, CheckVerifiedCredentialGateArgs};
use types::{AccessGate, ChannelId, MemberJoined, UsersUnblocked};

#[update_msgpack(guard = "caller_is_user_index_or_local_user_index")]
#[update(guard = "caller_is_user_index_or_local_user_index", msgpack = true)]
#[trace]
async fn c2c_join_community(args: Args) -> Response {
run_regular_jobs();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ use crate::{
activity_notifications::handle_activity_notification, model::events::CommunityEventInternal, mutate_state,
run_regular_jobs, RuntimeState,
};
use canister_api_macros::update_msgpack;
use canister_api_macros::update;
use canister_tracing_macros::trace;
use community_canister::c2c_leave_community::{Response::*, *};
use types::MemberLeft;

// Called via the user's user canister
#[update_msgpack]
#[update(msgpack = true)]
#[trace]
fn c2c_leave_community(_args: Args) -> Response {
run_regular_jobs();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use crate::guards::caller_is_escrow_canister;
use crate::{mutate_state, run_regular_jobs, RuntimeState};
use canister_api_macros::update_msgpack;
use canister_api_macros::update;
use canister_tracing_macros::trace;
use escrow_canister::{SwapStatus, SwapStatusChange as Args};
use types::{Chat, EventIndex, P2PSwapCancelled, P2PSwapExpired, P2PSwapLocation, P2PSwapStatus};

#[update_msgpack(guard = "caller_is_escrow_canister")]
#[update(guard = "caller_is_escrow_canister", msgpack = true)]
#[trace]
fn c2c_notify_p2p_swap_status_change(args: Args) {
run_regular_jobs();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use crate::guards::caller_is_user_index;
use crate::{mutate_state, run_regular_jobs, RuntimeState};
use canister_api_macros::update_msgpack;
use canister_api_macros::update;
use canister_tracing_macros::trace;
use community_canister::c2c_set_user_suspended::{Response::*, *};
use types::Timestamped;

#[update_msgpack(guard = "caller_is_user_index")]
#[update(guard = "caller_is_user_index", msgpack = true)]
#[trace]
fn c2c_set_user_suspended(args: Args) -> Response {
run_regular_jobs();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
use crate::activity_notifications::handle_activity_notification;
use crate::{mutate_state, run_regular_jobs, RuntimeState};
use canister_api_macros::update_msgpack;
use canister_api_macros::update;
use canister_tracing_macros::trace;
use chat_events::{Reader, TipMessageArgs};
use community_canister::c2c_tip_message::{Response::*, *};
use group_chat_core::TipMessageResult;
use ledger_utils::format_crypto_amount_with_symbol;
use types::{ChannelMessageTipped, EventIndex, Notification};

#[update_msgpack]
#[update(msgpack = true)]
#[trace]
fn c2c_tip_message(args: Args) -> Response {
run_regular_jobs();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ use crate::activity_notifications::handle_activity_notification;
use crate::guards::caller_is_group_index_or_local_group_index;
use crate::model::events::CommunityEventInternal;
use crate::{mutate_state, run_regular_jobs, RuntimeState};
use canister_api_macros::update_msgpack;
use canister_api_macros::update;
use canister_tracing_macros::trace;
use community_canister::c2c_unfreeze_community::{Response::*, *};
use types::{EventWrapper, GroupUnfrozen, Timestamped};

#[update_msgpack(guard = "caller_is_group_index_or_local_group_index")]
#[update(guard = "caller_is_group_index_or_local_group_index", msgpack = true)]
#[trace]
async fn c2c_unfreeze_community(args: Args) -> Response {
run_regular_jobs();
Expand Down
Loading
Loading