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

Seller can rate buyer after release funds #426

Merged
merged 1 commit into from
Jan 16, 2025
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
51 changes: 30 additions & 21 deletions src/app/release.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use crate::db::{self};
use crate::lightning::LndConnector;
use crate::lnurl::resolv_ln_address;
use crate::util::{
get_keys, get_nostr_client, rate_counterpart, send_cant_do_msg, send_new_order_msg,
settle_seller_hold_invoice, update_order_event,
get_keys, get_nostr_client, send_cant_do_msg, send_new_order_msg, settle_seller_hold_invoice,
update_order_event,
};
use anyhow::{Error, Result};
use fedimint_tonic_lnd::lnrpc::payment::PaymentStatus;
Expand Down Expand Up @@ -179,6 +179,17 @@ pub async fn release_action(
)
.await;

// Send DM to seller to rate counterpart
send_new_order_msg(
request_id,
Some(order.id),
Action::Rate,
None,
&event.rumor.pubkey,
None,
)
.await;

// Finally we try to pay buyer's invoice
let _ = do_payment(order, request_id).await;

Expand Down Expand Up @@ -262,13 +273,9 @@ pub async fn do_payment(mut order: Order, request_id: Option<u64>) -> Result<()>

let my_keys = get_keys()?;

let (seller_pubkey, buyer_pubkey) = match (&order.seller_pubkey, &order.buyer_pubkey) {
(Some(seller), Some(buyer)) => (
PublicKey::from_str(seller.as_str())?,
PublicKey::from_str(buyer.as_str())?,
),
(None, _) => return Err(Error::msg("Missing seller pubkey")),
(_, None) => return Err(Error::msg("Missing buyer pubkey")),
let buyer_pubkey = match &order.buyer_pubkey {
Some(buyer) => PublicKey::from_str(buyer.as_str())?,
None => return Err(Error::msg("Missing buyer pubkey")),
};

let payment = {
Expand All @@ -284,14 +291,9 @@ pub async fn do_payment(mut order: Order, request_id: Option<u64>) -> Result<()>
order.id, msg.payment.payment_hash
);

let _ = payment_success(
&mut order,
&buyer_pubkey,
&seller_pubkey,
&my_keys,
request_id,
)
.await;
let _ =
payment_success(&mut order, &buyer_pubkey, &my_keys, request_id)
.await;
}
PaymentStatus::Failed => {
info!(
Expand Down Expand Up @@ -322,7 +324,6 @@ pub async fn do_payment(mut order: Order, request_id: Option<u64>) -> Result<()>
async fn payment_success(
order: &mut Order,
buyer_pubkey: &PublicKey,
seller_pubkey: &PublicKey,
my_keys: &Keys,
request_id: Option<u64>,
) -> Result<()> {
Expand All @@ -339,9 +340,17 @@ async fn payment_success(

if let Ok(order_updated) = update_order_event(my_keys, Status::Success, order).await {
let pool = db::connect().await?;
if let Ok(order_success) = order_updated.update(&pool).await {
// Adding here rate process
rate_counterpart(buyer_pubkey, seller_pubkey, &order_success, request_id).await?;
if let Ok(order) = order_updated.update(&pool).await {
// Send dm to buyer to rate counterpart
send_new_order_msg(
request_id,
Some(order.id),
Action::Rate,
None,
buyer_pubkey,
None,
)
.await;
}
}
Ok(())
Expand Down
32 changes: 0 additions & 32 deletions src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -606,38 +606,6 @@ pub async fn set_waiting_invoice_status(
Ok(order.amount)
}

/// Send message to buyer and seller to vote for counterpart
pub async fn rate_counterpart(
buyer_pubkey: &PublicKey,
seller_pubkey: &PublicKey,
order: &Order,
request_id: Option<u64>,
) -> Result<()> {
// Send dm to counterparts
// to buyer
send_new_order_msg(
request_id,
Some(order.id),
Action::Rate,
None,
buyer_pubkey,
None,
)
.await;
// to seller
send_new_order_msg(
request_id,
Some(order.id),
Action::Rate,
None,
seller_pubkey,
None,
)
.await;

Ok(())
}

/// Settle a seller hold invoice
#[allow(clippy::too_many_arguments)]
pub async fn settle_seller_hold_invoice(
Expand Down
Loading