Skip to content

Commit

Permalink
Now it compiles with latest commit of mostro-core branch: message-ver…
Browse files Browse the repository at this point in the history
…sion-1
  • Loading branch information
arkanoider committed Nov 30, 2023
1 parent d189dbc commit 63e45f7
Show file tree
Hide file tree
Showing 12 changed files with 23 additions and 25 deletions.
2 changes: 1 addition & 1 deletion src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use crate::app::take_sell::take_sell_action;
use crate::lightning::LndConnector;

use anyhow::Result;
use mostro_core::message::{Action, Message, MessageKind};
use mostro_core::message::{Action, Message};
use nostr_sdk::prelude::*;
use sqlx::{Pool, Sqlite};
use std::sync::Arc;
Expand Down
2 changes: 1 addition & 1 deletion src/app/add_invoice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ pub async fn add_invoice_action(
// Only the buyer can add an invoice
if buyer_pubkey != event.pubkey {
// We create a Message
let message = Message::cant_do(Some(order.id), None);
let message = Message::cant_do(Some(order.id), None, None);
let message = message.as_json().unwrap();
send_dm(client, my_keys, &event.pubkey, message).await?;

Expand Down
2 changes: 1 addition & 1 deletion src/app/admin_add_solver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ pub async fn admin_add_solver_action(
add_user(&user, pool).await?;

// We create a Message for admin
let message = Message::new(None, None, Action::AdminAddSolver, None);
let message = Message::new_dispute(None, None, Action::AdminAddSolver, None);
let message = message.as_json()?;
// Send the message
send_dm(client, my_keys, &event.pubkey, message.clone()).await?;
Expand Down
2 changes: 1 addition & 1 deletion src/app/admin_cancel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ pub async fn admin_cancel_action(
// and update on local database the status and new event id
update_order_event(pool, client, my_keys, Status::CanceledByAdmin, &order, None).await?;
// We create a Message
let message = Message::new(Some(order.id), None, Action::AdminCancel, None);
let message = Message::new_dispute(Some(order.id), None, Action::AdminCancel, None);
let message = message.as_json()?;
// Message to admin
send_dm(client, my_keys, &event.pubkey, message.clone()).await?;
Expand Down
4 changes: 2 additions & 2 deletions src/app/admin_settle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub async fn admin_settle_action(
pool: &Pool<Sqlite>,
ln_client: &mut LndConnector,
) -> Result<()> {
let order_id = msg.order_id.unwrap();
let order_id = msg.get_inner_message_kind().id.unwrap();
let order = match Order::by_id(pool, order_id).await? {
Some(order) => order,
None => {
Expand All @@ -43,7 +43,7 @@ pub async fn admin_settle_action(
d.update(pool).await?;
}
// We create a Message
let message = Message::new(Some(order.id), None, Action::AdminSettle, None);
let message = Message::new_dispute(Some(order.id), None, Action::AdminSettle, None);
let message = message.as_json()?;
// Message to admin
send_dm(client, my_keys, &event.pubkey, message.clone()).await?;
Expand Down
4 changes: 2 additions & 2 deletions src/app/admin_take_dispute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub async fn admin_take_dispute_action(
client: &Client,
pool: &Pool<Sqlite>,
) -> Result<()> {
let content = if let Some(content) = msg.content {
let content = if let Some(content) = msg.get_inner_message_kind().content.to_owned() {
content
} else {
error!("No dispute id found!");
Expand Down Expand Up @@ -43,7 +43,7 @@ pub async fn admin_take_dispute_action(
take_dispute(pool, &Status::InProgress, dispute_id, &event.pubkey).await?;

// We create a Message for admin
let message = Message::new(None, None, Action::AdminAddSolver, None);
let message = Message::new_dispute(None, None, Action::AdminAddSolver, None);
let message = message.as_json()?;
// Send the message
send_dm(client, my_keys, &event.pubkey, message.clone()).await?;
Expand Down
8 changes: 4 additions & 4 deletions src/app/cancel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub async fn cancel_action(
pool: &Pool<Sqlite>,
ln_client: &mut LndConnector,
) -> Result<()> {
let order_id = msg.order_id.unwrap();
let order_id = msg.get_inner_message_kind().id.unwrap();
let mut order = match Order::by_id(pool, order_id).await? {
Some(order) => order,
None => {
Expand All @@ -41,7 +41,7 @@ pub async fn cancel_action(
// and update on local database the status and new event id
update_order_event(pool, client, my_keys, Status::Canceled, &order, None).await?;
// We create a Message for cancel
let message = Message::new(Some(order.id), None, Action::Cancel, None);
let message = Message::new_order(Some(order.id), None, Action::Cancel, None);
let message = message.as_json()?;
send_dm(client, my_keys, &event.pubkey, message).await?;
}
Expand Down Expand Up @@ -184,7 +184,7 @@ pub async fn cancel_add_invoice(
)
.await?;
// We create a Message for cancel
let message = Message::new(Some(order.id), None, Action::Cancel, None);
let message = Message::new_order(Some(order.id), None, Action::Cancel, None);
let message = message.as_json()?;
send_dm(client, my_keys, &event.pubkey, message.clone()).await?;
send_dm(client, my_keys, &seller_pubkey, message).await?;
Expand Down Expand Up @@ -239,7 +239,7 @@ pub async fn cancel_pay_hold_invoice(
// and update on local database the status and new event id
update_order_event(pool, client, my_keys, Status::Canceled, order, None).await?;
// We create a Message for cancel
let message = Message::new(Some(order.id), None, Action::Cancel, None);
let message = Message::new_order(Some(order.id), None, Action::Cancel, None);
let message = message.as_json()?;
send_dm(client, my_keys, &event.pubkey, message.clone()).await?;
send_dm(client, my_keys, &seller_pubkey, message).await?;
Expand Down
5 changes: 2 additions & 3 deletions src/app/dispute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,13 @@ pub async fn dispute_action(
add_dispute(&dispute, pool).await?;

// We create a Message for the initiator
let message = Message::new(Some(order.id), None, Action::DisputeInitiatedByYou, None);
let message = Message::new_dispute(Some(order.id), None, Action::DisputeInitiatedByYou, None);
let message = message.as_json()?;
let initiator_pubkey = XOnlyPublicKey::from_bech32(message_sender)?;
send_dm(client, my_keys, &initiator_pubkey, message).await?;

// We create a Message for the counterpart
let message = Message::new(
0,
let message = Message::new_dispute(
Some(order.id),
None,
Action::DisputeInitiatedByPeer,
Expand Down
2 changes: 1 addition & 1 deletion src/app/order.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::util::{get_market_quote, publish_order, send_dm};

use anyhow::Result;
use log::error;
use mostro_core::message::{Action, Message};
use mostro_core::message::Message;
use nostr_sdk::prelude::ToBech32;
use nostr_sdk::{Client, Event, Keys};
use sqlx::{Pool, Sqlite};
Expand Down
6 changes: 3 additions & 3 deletions src/app/rate_user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::util::{nostr_tags_to_tuple, send_dm, update_user_rating_event};

use anyhow::Result;
use log::error;
use mostro_core::message::{Action, Content, Message};
use mostro_core::message::{Content, Message};
use mostro_core::order::Order;
use mostro_core::rating::Rating;
use mostro_core::NOSTR_REPLACEABLE_EVENT_KIND;
Expand Down Expand Up @@ -50,7 +50,7 @@ pub async fn update_user_reputation_action(
pool: &Pool<Sqlite>,
rate_list: Arc<Mutex<Vec<Event>>>,
) -> Result<()> {
let order_id = msg.order_id.unwrap();
let order_id = msg.get_inner_message_kind().id.unwrap();
let order = match Order::by_id(pool, order_id).await? {
Some(order) => order,
None => {
Expand Down Expand Up @@ -112,7 +112,7 @@ pub async fn update_user_reputation_action(
// Check if content of Peer is the same of counterpart
let mut rating = 0_u8;

if let Content::RatingUser(v) = msg.content.unwrap() {
if let Content::RatingUser(v) = msg.get_inner_message_kind().content.to_owned().unwrap() {
rating = v;
}

Expand Down
9 changes: 4 additions & 5 deletions src/app/release.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub async fn release_action(
pool: &Pool<Sqlite>,
ln_client: &mut LndConnector,
) -> Result<()> {
let order_id = msg.get_inner_message_kind().order_id.unwrap();
let order_id = msg.get_inner_message_kind().id.unwrap();
let order = match Order::by_id(pool, order_id).await? {
Some(order) => order,
None => {
Expand All @@ -40,8 +40,7 @@ pub async fn release_action(

// We send a HoldInvoicePaymentSettled message to seller, the client should
// indicate *funds released* message to seller
let message = Message::new(
0,
let message = Message::new_order(
Some(order.id),
None,
Action::HoldInvoicePaymentSettled,
Expand All @@ -50,7 +49,7 @@ pub async fn release_action(
let message = message.as_json()?;
send_dm(client, my_keys, &seller_pubkey, message).await?;
// We send a message to buyer indicating seller released funds
let message = Message::new(Some(order.id), None, Action::Release, None);
let message = Message::new_order(Some(order.id), None, Action::Release, None);
let message = message.as_json()?;
let buyer_pubkey = XOnlyPublicKey::from_bech32(order.buyer_pubkey.as_ref().unwrap())?;
send_dm(client, my_keys, &buyer_pubkey, message).await?;
Expand Down Expand Up @@ -85,7 +84,7 @@ pub async fn release_action(
);
// Purchase completed message to buyer
let message =
Message::new(Some(order.id), None, Action::PurchaseCompleted, None);
Message::new_order(Some(order.id), None, Action::PurchaseCompleted, None);
let message = message.as_json().unwrap();
send_dm(&client, &my_keys, &buyer_pubkey, message)
.await
Expand Down
2 changes: 1 addition & 1 deletion src/app/take_sell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::util::{send_dm, set_market_order_sats_amount, show_hold_invoice};

use anyhow::Result;
use log::error;
use mostro_core::message::{Action, Content, Message};
use mostro_core::message::{Content, Message};
use mostro_core::order::{Order, Status};
use nostr_sdk::prelude::*;
use sqlx::{Pool, Sqlite};
Expand Down

0 comments on commit 63e45f7

Please sign in to comment.