Skip to content

Commit

Permalink
Fix: changed to trade keys the receiver of the messages of take-sell
Browse files Browse the repository at this point in the history
  • Loading branch information
arkanoider committed Dec 15, 2024
1 parent ca38530 commit 3a63750
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
11 changes: 6 additions & 5 deletions src/app/take_sell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ pub async fn take_sell_action(
return Ok(());
}

let buyer_pubkey = event.sender;
// Get trade pubkey of the buyer
let buyer_trade_pubkey = event.rumor.pubkey;

let seller_pubkey = match &order.seller_pubkey {
Some(seller) => PublicKey::from_str(seller.as_str())?,
Expand Down Expand Up @@ -100,7 +101,7 @@ pub async fn take_sell_action(
Some(order.id),
Action::NotAllowedByStatus,
None,
&buyer_pubkey,
&buyer_trade_pubkey,
None,
)
.await;
Expand All @@ -125,7 +126,7 @@ pub async fn take_sell_action(
}

// Add buyer pubkey to order
order.buyer_pubkey = Some(buyer_pubkey.to_string());
order.buyer_pubkey = Some(buyer_trade_pubkey.to_string());
order.trade_index_buyer = msg.get_inner_message_kind().trade_index;
// Timestamp take order time
order.taken_at = Timestamp::now().as_u64() as i64;
Expand All @@ -140,7 +141,7 @@ pub async fn take_sell_action(
}

if pr.is_none() {
match set_waiting_invoice_status(&mut order, buyer_pubkey, request_id).await {
match set_waiting_invoice_status(&mut order, buyer_trade_pubkey, request_id).await {
Ok(_) => {
// Update order status
if let Ok(order_updated) =
Expand All @@ -159,7 +160,7 @@ pub async fn take_sell_action(
show_hold_invoice(
my_keys,
pr,
&buyer_pubkey,
&buyer_trade_pubkey,
&seller_pubkey,
order,
request_id,
Expand Down
14 changes: 9 additions & 5 deletions src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,12 +162,12 @@ pub async fn publish_order(
keys: &Keys,
new_order: &SmallOrder,
initiator_pubkey: &str,
ack_pubkey: PublicKey,
trade_pubkey: PublicKey,
request_id: Option<u64>,
trade_index: Option<i64>,
) -> Result<()> {
// Prepare a new default order
let new_order_db = prepare_new_order(new_order, initiator_pubkey, trade_index).await?;
let new_order_db = prepare_new_order(new_order, initiator_pubkey, trade_index, trade_pubkey).await?;

// CRUD order creation
let mut order = new_order_db.clone().create(pool).await?;
Expand All @@ -194,7 +194,7 @@ pub async fn publish_order(
Some(order_id),
Action::NewOrder,
Some(Payload::Order(order)),
&ack_pubkey,
&trade_pubkey,
trade_index,
)
.await;
Expand All @@ -212,6 +212,7 @@ async fn prepare_new_order(
new_order: &SmallOrder,
initiator_pubkey: &str,
trade_index: Option<i64>,
trade_pubkey: PublicKey,
) -> Result<Order> {
let mut fee = 0;
if new_order.amount > 0 {
Expand Down Expand Up @@ -243,10 +244,10 @@ async fn prepare_new_order(

if new_order.kind == Some(OrderKind::Buy) {
new_order_db.kind = OrderKind::Buy.to_string();
new_order_db.buyer_pubkey = Some(initiator_pubkey.to_string());
new_order_db.buyer_pubkey = Some(trade_pubkey.to_string());
new_order_db.trade_index_buyer = trade_index;
} else {
new_order_db.seller_pubkey = Some(initiator_pubkey.to_string());
new_order_db.seller_pubkey = Some(trade_pubkey.to_string());
new_order_db.trade_index_seller = trade_index;
}

Expand All @@ -261,6 +262,9 @@ pub async fn send_dm(
sender_keys: Keys,
payload: String,
) -> Result<()> {

info!("sender key {} - receiver key {}", sender_keys.public_key().to_hex(), receiver_pubkey.to_hex());

let event = gift_wrap(&sender_keys, *receiver_pubkey, payload.clone(), None)?;
info!(
"Sending DM, Event ID: {} with payload: {:#?}",
Expand Down

0 comments on commit 3a63750

Please sign in to comment.