Skip to content

Commit

Permalink
Use msgpack for c2c call
Browse files Browse the repository at this point in the history
  • Loading branch information
hpeebles committed Dec 13, 2023
1 parent defd4af commit d2459f6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,5 @@ pub struct Args {
pub enum Response {
Success(u64), // The transaction index
TransferError(TransferError),
UserNotInGroupOrCommunity,
InternalError(String),
}
Original file line number Diff line number Diff line change
@@ -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();
Expand Down Expand Up @@ -72,19 +72,14 @@ struct PrepareResult {
}

fn prepare(args: &Args, state: &RuntimeState) -> Result<PrepareResult, Response> {
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(),
})
}

0 comments on commit d2459f6

Please sign in to comment.