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

first idea of mostro message on request #278

Closed
wants to merge 3 commits into from
Closed
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
14 changes: 1 addition & 13 deletions Cargo.lock

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

59 changes: 59 additions & 0 deletions src/nip33.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::Settings;
use chrono::Duration;
use mostro_core::order::Order;
use mostro_core::NOSTR_REPLACEABLE_EVENT_KIND;
Expand Down Expand Up @@ -68,3 +69,61 @@ pub fn order_to_tags(order: &Order) -> Vec<(String, String)> {

tags
}

/// Transform mostro info fields to tags
///
/// # Arguments
///
///
pub fn info_to_tags(mostro_pubkey: &PublicKey) -> Vec<(String, String)> {
let mostro_settings = Settings::get_mostro();
let ln_settings = Settings::get_ln();

let tags = vec![
// max_order_amount
("mostro_pubkey".to_string(), mostro_pubkey.to_string()),
// max_order_amount
(
"max_order_amount".to_string(),
mostro_settings.max_order_amount.to_string(),
),
// min_order_amount
(
"min_order_amount".to_string(),
mostro_settings.min_payment_amount.to_string(),
),
// expiration_hours
(
"expiration_hours".to_string(),
mostro_settings.expiration_hours.to_string(),
),
// expiration_seconds
(
"expiration_seconds".to_string(),
mostro_settings.expiration_seconds.to_string(),
),
// fee
("fee".to_string(), mostro_settings.fee.to_string()),
// hold_invoice_expiration_window
(
"hold_invoice_expiration_window".to_string(),
ln_settings.hold_invoice_expiration_window.to_string(),
),
// hold_invoice_cltv_delta
(
"hold_invoice_cltv_delta".to_string(),
ln_settings.hold_invoice_cltv_delta.to_string(),
),
// invoice_expiration_window
(
"invoice_expiration_window".to_string(),
ln_settings.hold_invoice_cltv_delta.to_string(),
),
// Label to identify this is a Mostro's infos
("y".to_string(), "mostrop2p".to_string()),
// Table name
("z".to_string(), "info".to_string()),
];

tags
}
22 changes: 22 additions & 0 deletions src/scheduler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,32 @@ pub async fn start_scheduler(rate_list: Arc<Mutex<Vec<Event>>>) {
job_update_rate_events(rate_list).await;
job_cancel_orders().await;
job_retry_failed_payments().await;
job_info_event_send().await;

info!("Scheduler Started");
}

async fn job_info_event_send() {
let mostro_pubkey = match get_keys() {
Ok(keys) => keys,
Err(e) => return error!("{e}"),
};

tokio::spawn(async move {
loop {
info!("Sending info about mostro");

let tags = crate::nip33::info_to_tags(&mostro_pubkey.public_key());
let id = format!("Mostro npub {} info event", mostro_pubkey.public_key());

let info_ev = crate::nip33::new_event(&mostro_pubkey, "", id, tags).unwrap();
let _ = NOSTR_CLIENT.get().unwrap().send_event(info_ev).await;

tokio::time::sleep(tokio::time::Duration::from_secs(300)).await;
}
});
}

async fn job_retry_failed_payments() {
let ln_settings = Settings::get_ln();
let retries_number = ln_settings.payment_attempts as i64;
Expand Down
Loading