From d2459f6e0ee28e1d2fd2f00314a4ffc0e421b2b3 Mon Sep 17 00:00:00 2001 From: Hamish Peebles Date: Wed, 13 Dec 2023 22:35:35 +0000 Subject: [PATCH] Use msgpack for c2c call --- .../src/updates/c2c_accept_p2p_trade_offer.rs | 1 - .../src/updates/c2c_accept_p2p_trade_offer.rs | 27 ++++++++----------- 2 files changed, 11 insertions(+), 17 deletions(-) diff --git a/backend/canisters/user/api/src/updates/c2c_accept_p2p_trade_offer.rs b/backend/canisters/user/api/src/updates/c2c_accept_p2p_trade_offer.rs index 11093f532c..04bfa27fb3 100644 --- a/backend/canisters/user/api/src/updates/c2c_accept_p2p_trade_offer.rs +++ b/backend/canisters/user/api/src/updates/c2c_accept_p2p_trade_offer.rs @@ -20,6 +20,5 @@ pub struct Args { pub enum Response { Success(u64), // The transaction index TransferError(TransferError), - UserNotInGroupOrCommunity, InternalError(String), } diff --git a/backend/canisters/user/impl/src/updates/c2c_accept_p2p_trade_offer.rs b/backend/canisters/user/impl/src/updates/c2c_accept_p2p_trade_offer.rs index 83ad6b6866..a81b5a2245 100644 --- a/backend/canisters/user/impl/src/updates/c2c_accept_p2p_trade_offer.rs +++ b/backend/canisters/user/impl/src/updates/c2c_accept_p2p_trade_offer.rs @@ -1,16 +1,16 @@ -use crate::guards::caller_is_owner; +use crate::guards::caller_is_known_group_or_community_canister; use crate::model::p2p_trades::{P2PTradeOffer, P2PTradeOfferStatus}; use crate::{mutate_state, read_state, run_regular_jobs, RuntimeState}; +use canister_api_macros::update_msgpack; use canister_tracing_macros::trace; use escrow_canister::deposit_subaccount; -use ic_cdk_macros::update; use icrc_ledger_types::icrc1::account::Account; use icrc_ledger_types::icrc1::transfer::TransferArg; use types::{CanisterId, TimestampMillis, UserId}; use user_canister::c2c_accept_p2p_trade_offer::{Response::*, *}; use utils::time::NANOS_PER_MILLISECOND; -#[update(guard = "caller_is_owner")] +#[update_msgpack(guard = "caller_is_known_group_or_community_canister")] #[trace] async fn c2c_accept_p2p_trade_offer(args: Args) -> Response { run_regular_jobs(); @@ -72,19 +72,14 @@ struct PrepareResult { } fn prepare(args: &Args, state: &RuntimeState) -> Result { - let caller = state.env.caller(); - if state.data.group_chats.exists(&caller.into()) || state.data.communities.exists(&caller.into()) { - if let Some(offer) = state.data.p2p_trades.get(args.offer_id) { - if let Some(index) = offer.output_transaction_index { - return Err(Success(index)); - } + if let Some(offer) = state.data.p2p_trades.get(args.offer_id) { + if let Some(index) = offer.output_transaction_index { + return Err(Success(index)); } - Ok(PrepareResult { - my_user_id: state.env.canister_id().into(), - escrow_canister_id: state.data.escrow_canister_id, - now: state.env.now(), - }) - } else { - Err(UserNotInGroupOrCommunity) } + Ok(PrepareResult { + my_user_id: state.env.canister_id().into(), + escrow_canister_id: state.data.escrow_canister_id, + now: state.env.now(), + }) }