Skip to content

Commit

Permalink
Bumps mostro core version
Browse files Browse the repository at this point in the history
Code refactoring and small improvements
  • Loading branch information
grunch committed Dec 26, 2024
1 parent 51caba5 commit ea06bbb
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 24 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ uuid = { version = "1.8.0", features = [
"serde",
] }
reqwest = { version = "0.12.1", features = ["json"] }
mostro-core = { version = "0.6.19", features = ["sqlx"] }
mostro-core = { version = "0.6.20", features = ["sqlx"] }
tracing = "0.1.40"
tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }
config = "0.14.0"
Expand Down
30 changes: 15 additions & 15 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,31 +70,31 @@ async fn check_trade_index(pool: &Pool<Sqlite>, event: &UnwrappedGift, msg: &Mes
let message_kind = msg.get_inner_message_kind();
if let Action::NewOrder | Action::TakeBuy | Action::TakeSell = message_kind.action {
match is_user_present(pool, event.sender.to_string()).await {
Ok(mut user) => {
Ok(user) => {
if let (true, index) = message_kind.has_trade_index() {
let (_, sig): (Message, nostr_sdk::secp256k1::schnorr::Signature) =
serde_json::from_str(&event.rumor.content).unwrap();
if index > user.last_trade_index
&& msg
.get_inner_message_kind()
.verify_signature(event.rumor.pubkey, sig)
{
user.last_trade_index = index;
if let Err(e) = update_user_trade_index(
pool,
event.sender.to_string(),
user.last_trade_index,
if index <= user.last_trade_index {
tracing::info!("Invalid trade index");
send_cant_do_msg(
None,
message_kind.id,
Some(CantDoReason::InvalidTradeIndex),
&event.rumor.pubkey,
)
.await
.await;
} else if message_kind.verify_signature(event.rumor.pubkey, sig) {
if let Err(e) =
update_user_trade_index(pool, event.sender.to_string(), index).await
{
tracing::error!("Error updating user trade index: {}", e);
}
} else {
tracing::info!("Invalid signature or trade index");
tracing::info!("Invalid signature");
send_cant_do_msg(
None,
msg.get_inner_message_kind().id,
Some(CantDoReason::InvalidTradeIndex),
message_kind.id,
Some(CantDoReason::InvalidSignature),
&event.rumor.pubkey,
)
.await;
Expand Down
5 changes: 3 additions & 2 deletions src/app/admin_take_dispute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,12 @@ pub async fn admin_take_dispute_action(
};

let mut new_order = order.as_new_order();
// Only in this case we use the trade pubkey fields to store the master pubkey
new_order
.master_buyer_pubkey
.buyer_trade_pubkey
.clone_from(&order.master_buyer_pubkey);
new_order
.master_seller_pubkey
.seller_trade_pubkey
.clone_from(&order.master_seller_pubkey);

// Update dispute fields
Expand Down
4 changes: 2 additions & 2 deletions src/app/rate_user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,15 @@ pub async fn update_user_reputation_action(
if message_sender == buyer {
counterpart = order
.master_seller_pubkey
.ok_or_else(|| Error::msg("Missing master seller pubkey"))?;
.ok_or_else(|| Error::msg("Missing seller identity pubkey"))?;
buyer_rating = true;
counterpart_trade_pubkey = order
.buyer_pubkey
.ok_or_else(|| Error::msg("Missing buyer pubkey"))?;
} else if message_sender == seller {
counterpart = order
.master_buyer_pubkey
.ok_or_else(|| Error::msg("Missing master buyer pubkey"))?;
.ok_or_else(|| Error::msg("Missing buyer identity pubkey"))?;
seller_rating = true;
counterpart_trade_pubkey = order
.seller_pubkey
Expand Down
4 changes: 2 additions & 2 deletions src/flow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ pub async fn hold_invoice_paid(hash: &str, request_id: Option<u64>) -> Result<()
order_data.amount = new_amount;
status = Status::WaitingBuyerInvoice;
order_data.status = Some(status);
order_data.master_buyer_pubkey = None;
order_data.master_seller_pubkey = None;
order_data.buyer_trade_pubkey = None;
order_data.seller_trade_pubkey = None;
// We ask to buyer for a new invoice
send_new_order_msg(
request_id,
Expand Down

0 comments on commit ea06bbb

Please sign in to comment.