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

Refactored replaceable event kind #114

Merged
merged 1 commit into from
Sep 19, 2023
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
5 changes: 2 additions & 3 deletions src/app/rate_user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::util::{send_dm, update_user_rating_event};
use anyhow::Result;
use log::{error, info};
use mostro_core::order::Order;
use mostro_core::{Action, Content, Message, Rating};
use mostro_core::{Action, Content, Message, Rating,NOSTR_REPLACEABLE_EVENT_KIND};
use nostr_sdk::prelude::*;
use sqlx::{Pool, Sqlite};
use sqlx_crud::Crud;
Expand Down Expand Up @@ -90,7 +90,6 @@ pub async fn get_nip_33_event(
let mut notifications = client.notifications();

let mut ev = None;

while let Ok(notification) = notifications.recv().await {
if let RelayPoolNotification::Message(_, msg) = notification {
match msg {
Expand Down Expand Up @@ -130,7 +129,7 @@ pub async fn get_counterpart_reputation(

let filter = Filter::new()
.author(my_keys.public_key().to_string())
.kind(Kind::Custom(30000))
.kind(Kind::Custom(NOSTR_REPLACEABLE_EVENT_KIND))
.identifier(user.to_string());
println!("Filter : {:?}", filter);
let event_nip33 = send_relays_requests(client, filter).await;
Expand Down
11 changes: 4 additions & 7 deletions src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::{db, flow};
use anyhow::{Context, Result};
use log::{error, info};
use mostro_core::order::{NewOrder, Order, SmallOrder};
use mostro_core::{Action, Content, Kind as OrderKind, Message, Status};
use mostro_core::{Action, Content, Kind as OrderKind, Message, Status, NOSTR_REPLACEABLE_EVENT_KIND};
use nostr_sdk::prelude::*;
use sqlx::SqlitePool;
use sqlx::{Pool, Sqlite};
Expand Down Expand Up @@ -108,7 +108,6 @@ pub async fn publish_order(
let order_string = order.as_json().unwrap();
info!("serialized order: {order_string}");
// This tag (nip33) allows us to change this event in particular in the future
let event_kind = 30000;
let d_tag = Tag::Generic(TagKind::Custom("d".to_string()), vec![order_id.to_string()]);
// This tag helps client to subscribe to sell/buy order type notifications
let k_tag = Tag::Generic(
Expand All @@ -121,7 +120,7 @@ pub async fn publish_order(
vec![order.fiat_code.clone()],
);
let event = EventBuilder::new(
Kind::Custom(event_kind as u64),
Kind::Custom(NOSTR_REPLACEABLE_EVENT_KIND),
&order_string,
&[d_tag, k_tag, f_tag],
)
Expand Down Expand Up @@ -195,9 +194,8 @@ pub async fn update_user_rating_event(
) -> Result<()> {
// let reputation = reput
// nip33 kind and d tag
let event_kind = 30000;
let d_tag = Tag::Generic(TagKind::Custom("d".to_string()), vec![user.to_string()]);
let event = EventBuilder::new(Kind::Custom(event_kind), reputation, &[d_tag]).to_event(keys)?;
let event = EventBuilder::new(Kind::Custom(NOSTR_REPLACEABLE_EVENT_KIND), reputation, &[d_tag]).to_event(keys)?;
info!("Sending replaceable event: {event:#?}");
// We update the order vote status
if buyer_sent_rate {
Expand Down Expand Up @@ -239,10 +237,9 @@ pub async fn update_order_event(
);
let order_string = publish_order.as_json()?;
// nip33 kind and d tag
let event_kind = 30000;
let d_tag = Tag::Generic(TagKind::Custom("d".to_string()), vec![order.id.to_string()]);
let event =
EventBuilder::new(Kind::Custom(event_kind), &order_string, &[d_tag]).to_event(keys)?;
EventBuilder::new(Kind::Custom(NOSTR_REPLACEABLE_EVENT_KIND), &order_string, &[d_tag]).to_event(keys)?;
let event_id = event.id.to_string();
let status_str = status.to_string();
info!("Sending replaceable event: {event:#?}");
Expand Down
Loading