Skip to content

Commit

Permalink
Upgrade dependencies (#125)
Browse files Browse the repository at this point in the history
* upgrade mostro core
* upgrade lightning invoice
* refactoring
* add new users table
  • Loading branch information
grunch authored Oct 6, 2023
1 parent 871b347 commit 18e3155
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 19 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand All @@ -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"] }
Expand Down
8 changes: 8 additions & 0 deletions migrations/20231005195154_users.sql
Original file line number Diff line number Diff line change
@@ -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
);
4 changes: 2 additions & 2 deletions src/app/add_invoice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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:?}");
Expand Down
4 changes: 2 additions & 2 deletions src/app/take_buy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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:?}");
Expand Down
4 changes: 2 additions & 2 deletions src/app/take_sell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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:?}");
Expand Down
4 changes: 2 additions & 2 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ impl fmt::Display for MostroError {
}
}

impl From<lightning_invoice::ParseError> for MostroError {
fn from(_: lightning_invoice::ParseError) -> Self {
impl From<lightning_invoice::Bolt11ParseError> for MostroError {
fn from(_: lightning_invoice::Bolt11ParseError) -> Self {
MostroError::ParsingInvoiceError
}
}
Expand Down
12 changes: 6 additions & 6 deletions src/lightning/invoice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Invoice, MostroError> {
let invoice = Invoice::from_str(payment_request)?;
pub fn decode_invoice(payment_request: &str) -> Result<Bolt11Invoice, MostroError> {
let invoice = Bolt11Invoice::from_str(payment_request)?;

Ok(invoice)
}
Expand All @@ -19,8 +19,8 @@ pub fn is_valid_invoice(
payment_request: &str,
amount: Option<u64>,
fee: Option<u64>,
) -> Result<Invoice, MostroError> {
let invoice = Invoice::from_str(payment_request)?;
) -> Result<Bolt11Invoice, MostroError> {
let invoice = decode_invoice(payment_request)?;
let mostro_settings = Settings::get_mostro();
let ln_settings = Settings::get_ln();

Expand All @@ -44,7 +44,7 @@ pub fn is_valid_invoice(
return Err(MostroError::InvoiceExpiredError);
}

let parsed = payment_request.parse::<SignedRawInvoice>()?;
let parsed = payment_request.parse::<SignedRawBolt11Invoice>()?;

let (parsed_invoice, _, _) = parsed.into_parts();

Expand Down
6 changes: 3 additions & 3 deletions src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -203,7 +203,7 @@ pub async fn update_order_event(
order: &Order,
amount: Option<i64>,
) -> 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),
Expand Down

0 comments on commit 18e3155

Please sign in to comment.