diff --git a/Cargo.toml b/Cargo.toml index 63aafab0..203a4080 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,7 +14,7 @@ path = "src/main.rs" anyhow = "1.0.66" chrono = "0.4.23" easy-hasher = "2.2.1" -lightning-invoice = "0.22.0" +lightning-invoice = "0.25.0" log = "0.4.17" nostr-sdk = "0.24.0" serde = { version = "1.0.149" } @@ -37,7 +37,7 @@ uuid = { version = "1.3.0", features = [ "serde", ] } reqwest = { version = "0.11", features = ["json"] } -mostro-core = "0.3.3" +mostro-core = "0.3.6" tokio-cron-scheduler = "*" tracing = "0.1.37" tracing-subscriber = { version = "0.3.16", features = ["env-filter"] } diff --git a/migrations/20231005195154_users.sql b/migrations/20231005195154_users.sql new file mode 100644 index 00000000..74bd80b1 --- /dev/null +++ b/migrations/20231005195154_users.sql @@ -0,0 +1,8 @@ +CREATE TABLE IF NOT EXISTS users ( + id char(36) primary key not null, + pubkey char(64), + is_admin integer not null default 0, + is_solver integer not null default 0, + is_banned integer not null default 0, + created_at integer not null +); \ No newline at end of file diff --git a/src/app/add_invoice.rs b/src/app/add_invoice.rs index 8e3b42c5..dc953051 100644 --- a/src/app/add_invoice.rs +++ b/src/app/add_invoice.rs @@ -4,13 +4,13 @@ use crate::lightning::invoice::is_valid_invoice; use crate::util::{send_dm, show_hold_invoice}; use anyhow::Result; +use clap::ValueEnum; use log::error; use mostro_core::order::{Order, Status}; use mostro_core::{order::SmallOrder, Action, Content, Message}; use nostr_sdk::prelude::*; use sqlx::{Pool, Sqlite}; use sqlx_crud::Crud; -use std::str::FromStr; pub async fn add_invoice_action( msg: Message, @@ -67,7 +67,7 @@ pub async fn add_invoice_action( return Ok(()); } - let order_status = match Status::from_str(&order.status) { + let order_status = match Status::from_str(&order.status, true) { Ok(s) => s, Err(e) => { error!("AddInvoice: Order Id {order_id} wrong status: {e:?}"); diff --git a/src/app/take_buy.rs b/src/app/take_buy.rs index 906d4f05..f1b505cf 100644 --- a/src/app/take_buy.rs +++ b/src/app/take_buy.rs @@ -2,13 +2,13 @@ use crate::db::edit_master_seller_pubkey_order; use crate::util::{get_market_quote, send_dm, show_hold_invoice}; use anyhow::Result; +use clap::ValueEnum; use log::error; use mostro_core::order::{Order, Status}; use mostro_core::{Action, Content, Message}; use nostr_sdk::prelude::*; use sqlx::{Pool, Sqlite}; use sqlx_crud::Crud; -use std::str::FromStr; pub async fn take_buy_action( msg: Message, @@ -41,7 +41,7 @@ pub async fn take_buy_action( return Ok(()); } - let order_status = match Status::from_str(&order.status) { + let order_status = match Status::from_str(&order.status, true) { Ok(s) => s, Err(e) => { error!("TakeBuy: Order Id {order_id} wrong status: {e:?}"); diff --git a/src/app/take_sell.rs b/src/app/take_sell.rs index 6e6c2e7d..a1867c59 100644 --- a/src/app/take_sell.rs +++ b/src/app/take_sell.rs @@ -4,13 +4,13 @@ use crate::lightning::invoice::is_valid_invoice; use crate::util::{send_dm, set_market_order_sats_amount, show_hold_invoice}; use anyhow::Result; +use clap::ValueEnum; use log::error; use mostro_core::order::{Order, Status}; use mostro_core::{Action, Content, Message}; use nostr_sdk::prelude::*; use sqlx::{Pool, Sqlite}; use sqlx_crud::Crud; -use std::str::FromStr; pub async fn take_sell_action( msg: Message, @@ -84,7 +84,7 @@ pub async fn take_sell_action( pr = None; } - let order_status = match Status::from_str(&order.status) { + let order_status = match Status::from_str(&order.status, true) { Ok(s) => s, Err(e) => { error!("TakeSell: Order Id {order_id} wrong status: {e:?}"); diff --git a/src/error.rs b/src/error.rs index 5c68b627..6dc0b477 100644 --- a/src/error.rs +++ b/src/error.rs @@ -27,8 +27,8 @@ impl fmt::Display for MostroError { } } -impl From for MostroError { - fn from(_: lightning_invoice::ParseError) -> Self { +impl From for MostroError { + fn from(_: lightning_invoice::Bolt11ParseError) -> Self { MostroError::ParsingInvoiceError } } diff --git a/src/lightning/invoice.rs b/src/lightning/invoice.rs index 0166d49d..3ea75885 100644 --- a/src/lightning/invoice.rs +++ b/src/lightning/invoice.rs @@ -3,12 +3,12 @@ use crate::error::MostroError; use chrono::prelude::*; use chrono::Duration; -use lightning_invoice::{Invoice, SignedRawInvoice}; +use lightning_invoice::{Bolt11Invoice, SignedRawBolt11Invoice}; use std::str::FromStr; /// Decode a lightning invoice (bolt11) -pub fn decode_invoice(payment_request: &str) -> Result { - let invoice = Invoice::from_str(payment_request)?; +pub fn decode_invoice(payment_request: &str) -> Result { + let invoice = Bolt11Invoice::from_str(payment_request)?; Ok(invoice) } @@ -19,8 +19,8 @@ pub fn is_valid_invoice( payment_request: &str, amount: Option, fee: Option, -) -> Result { - let invoice = Invoice::from_str(payment_request)?; +) -> Result { + let invoice = decode_invoice(payment_request)?; let mostro_settings = Settings::get_mostro(); let ln_settings = Settings::get_ln(); @@ -44,7 +44,7 @@ pub fn is_valid_invoice( return Err(MostroError::InvoiceExpiredError); } - let parsed = payment_request.parse::()?; + let parsed = payment_request.parse::()?; let (parsed_invoice, _, _) = parsed.into_parts(); diff --git a/src/util.rs b/src/util.rs index 87e1f008..349c535c 100644 --- a/src/util.rs +++ b/src/util.rs @@ -8,13 +8,13 @@ use crate::nip33::{new_event, order_to_tags}; use crate::{db, flow}; use anyhow::{Context, Result}; +use clap::ValueEnum; use log::{error, info}; use mostro_core::order::{Kind as OrderKind, NewOrder, Order, SmallOrder, Status}; use mostro_core::{Action, Content, Message}; use nostr_sdk::prelude::*; use sqlx::SqlitePool; use sqlx::{Pool, Sqlite}; -use std::str::FromStr; use std::sync::Arc; use std::thread; use tokio::sync::mpsc::channel; @@ -95,7 +95,7 @@ pub async fn publish_order( // Now we have the order id, we can create a new event adding this id to the Order object let order = NewOrder::new( Some(order_id), - OrderKind::from_str(&order.kind).unwrap(), + OrderKind::from_str(&order.kind, true).unwrap(), Status::Pending, order.amount, order.fiat_code, @@ -203,7 +203,7 @@ pub async fn update_order_event( order: &Order, amount: Option, ) -> Result<()> { - let kind = OrderKind::from_str(&order.kind).unwrap(); + let kind = OrderKind::from_str(&order.kind, true).unwrap(); let amount = amount.unwrap_or(order.amount); let publish_order = NewOrder::new( Some(order.id),