Skip to content
15 changes: 15 additions & 0 deletions src/app/admin_cancel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,13 @@ pub async fn admin_cancel_action(
// we check if there is a dispute
let dispute = find_dispute_by_order_id(pool, order.id).await;

// Get the creator of the dispute
let dispute_initiator = match (order.seller_dispute, order.buyer_dispute) {
(true, false) => "seller",
(false, true) => "buyer",
(_, _) => return Err(MostroInternalErr(ServiceError::DisputeEventError)),
};

if let Ok(mut d) = dispute {
let dispute_id = d.id;
// we update the dispute
Expand All @@ -85,6 +92,11 @@ pub async fn admin_cancel_action(
TagKind::Custom(Cow::Borrowed("s")),
vec![DisputeStatus::SellerRefunded.to_string()],
),
// Who is the dispute creator
Tag::custom(
TagKind::Custom(std::borrow::Cow::Borrowed("initiator")),
vec![dispute_initiator.to_string()],
),
Tag::custom(
TagKind::Custom(Cow::Borrowed("y")),
vec!["mostro".to_string()],
Expand All @@ -98,6 +110,9 @@ pub async fn admin_cancel_action(
let event = new_event(my_keys, "", dispute_id.to_string(), tags)
.map_err(|e| MostroInternalErr(ServiceError::NostrError(e.to_string())))?;

// Publish dispute event with update
info!("Dispute event to be published: {event:#?}");

match get_nostr_client() {
Ok(client) => {
if let Err(e) = client.send_event(&event).await {
Expand Down
15 changes: 15 additions & 0 deletions src/app/admin_settle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,13 @@ pub async fn admin_settle_action(
// we check if there is a dispute
let dispute = find_dispute_by_order_id(pool, order.id).await;

// Get the creator of the dispute
let dispute_initiator = match (order.seller_dispute, order.buyer_dispute) {
(true, false) => "seller",
(false, true) => "buyer",
(_, _) => return Err(MostroInternalErr(ServiceError::DisputeEventError)),
};

if let Ok(mut d) = dispute {
let dispute_id = d.id;
// we update the dispute
Expand All @@ -91,6 +98,11 @@ pub async fn admin_settle_action(
TagKind::Custom(std::borrow::Cow::Borrowed("s")),
vec![DisputeStatus::Settled.to_string()],
),
// Who is the dispute creator
Tag::custom(
TagKind::Custom(std::borrow::Cow::Borrowed("initiator")),
vec![dispute_initiator.to_string()],
),
Tag::custom(
TagKind::Custom(std::borrow::Cow::Borrowed("y")),
vec!["mostro".to_string()],
Expand All @@ -105,6 +117,9 @@ pub async fn admin_settle_action(
let event = new_event(my_keys, "", dispute_id.to_string(), tags)
.map_err(|e| MostroInternalErr(ServiceError::NostrError(e.to_string())))?;

// Print event dispute with update
tracing::info!("Dispute event to be published: {event:#?}");

match get_nostr_client() {
Ok(client) => {
if let Err(e) = client.send_event(&event).await {
Expand Down
11 changes: 11 additions & 0 deletions src/app/admin_take_dispute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,12 +211,23 @@ pub async fn admin_take_dispute_action(
.await
.map_err(|e| MostroInternalErr(ServiceError::NostrError(e.to_string())))?;

// Get the creator of the dispute
let dispute_initiator = match order.buyer_dispute {
true => "buyer",
false => "seller",
};

// We create a tag to show status of the dispute
let tags: Tags = Tags::from_list(vec![
Tag::custom(
TagKind::Custom(std::borrow::Cow::Borrowed("s")),
vec![Status::InProgress.to_string()],
),
// Who is the dispute creator
Tag::custom(
TagKind::Custom(std::borrow::Cow::Borrowed("initiator")),
vec![dispute_initiator.to_string()],
),
Tag::custom(
TagKind::Custom(std::borrow::Cow::Borrowed("y")),
vec!["mostro".to_string()],
Expand Down
23 changes: 19 additions & 4 deletions src/app/dispute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,31 @@ use uuid::Uuid;

/// Publishes a dispute event to the Nostr network.
///
/// Creates and publishes a NIP-33 replaceable event containing dispute details
/// including status and application metadata.
async fn publish_dispute_event(dispute: &Dispute, my_keys: &Keys) -> Result<(), MostroError> {
/// Creates and publishes a NIP-33 replaceable event containing dispute details,
/// including status, initiator (`buyer` or `seller`), and application metadata.
async fn publish_dispute_event(
dispute: &Dispute,
my_keys: &Keys,
is_buyer_dispute: bool,
) -> Result<(), MostroError> {
// Create initiator string
let initiator = match is_buyer_dispute {
true => "buyer",
false => "seller",
};

// Create tags for the dispute event
let tags = Tags::from_list(vec![
// Status tag - indicates the current state of the dispute
Tag::custom(
TagKind::Custom(Cow::Borrowed("s")),
vec![dispute.status.to_string()],
),
// Who is the dispute creator
Tag::custom(
TagKind::Custom(Cow::Borrowed("initiator")),
vec![initiator.to_string()],
),
// Application identifier tag
Tag::custom(
TagKind::Custom(Cow::Borrowed("y")),
Expand Down Expand Up @@ -218,7 +233,7 @@ pub async fn dispute_action(
.await?;

// Publish dispute event to network
publish_dispute_event(&dispute, my_keys)
publish_dispute_event(&dispute, my_keys, is_buyer_dispute)
.await
.map_err(|_| MostroInternalErr(ServiceError::DisputeEventError))?;

Expand Down