Skip to content
This repository has been archived by the owner on Oct 20, 2024. It is now read-only.

Commit

Permalink
refactor: use cashu-sdk post v1
Browse files Browse the repository at this point in the history
  • Loading branch information
thesimplekid committed Jan 18, 2024
1 parent 28f51af commit 1f5dcfa
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 344 deletions.
3 changes: 2 additions & 1 deletion config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
url = "https://example.com/"
listen_host = "127.0.0.1"
listen_port = 8085
secret_key = "supersecretprivatekey"
mnemonic = "supersecretprivatekey"
max_order = 32

[mint_info]
name = "test mint"
description = "A mint for testing"
description_long = "A longer mint for testing"
motd = "Hello world"

[contact]
Expand Down
20 changes: 7 additions & 13 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,12 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/

use std::collections::HashSet;
use std::path::PathBuf;
use std::str::FromStr;

use cashu_sdk::nuts::MintInfo;
use cashu_sdk::Amount;
use config::{Config, ConfigError, File};
use nostr::key::XOnlyPublicKey;
use serde::{Deserialize, Serialize};
use tracing::{debug, warn};

Expand All @@ -42,9 +40,11 @@ pub struct Info {
pub url: String,
#[serde(default = "path_default")]
pub db_path: PathBuf,
#[serde(default = "last_pay_path")]
pub last_pay_path: String,
pub listen_host: String,
pub listen_port: u16,
pub secret_key: String,
pub mnemonic: String,
#[serde(default = "derivation_path_default")]
pub derivation_path: String,
#[serde(default = "max_order_default")]
Expand All @@ -65,6 +65,10 @@ fn max_order_default() -> u8 {
32
}

fn last_pay_path() -> String {
"./last_path".to_string()
}

#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
pub enum LnBackend {
#[default]
Expand All @@ -83,21 +87,11 @@ pub struct Ln {
pub reserve_fee_min: Amount,
}

#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct NodeManager {
pub enable_node_manager: bool,
pub authorized_users: HashSet<XOnlyPublicKey>,
pub jwt_secret: String,
pub listen_host: String,
pub listen_port: u16,
}

#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct Settings {
pub info: Info,
pub mint_info: MintInfo,
pub ln: Ln,
pub node_manager: Option<NodeManager>,
}

impl Settings {
Expand Down
10 changes: 0 additions & 10 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ use serde::{Deserialize, Serialize};

#[derive(Debug)]
pub enum Error {
InvoiceNotPaid,
InvoiceExpired,
DecodeInvoice,
StatusCode(StatusCode),
_Ln(ln_rs::Error),
Expand All @@ -19,8 +17,6 @@ impl std::error::Error for Error {}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::InvoiceNotPaid => write!(f, "Lightning invoice not paid yet."),
Self::InvoiceExpired => write!(f, "Lightning invoice expired."),
Self::DecodeInvoice => write!(f, "Failed to decode LN Invoice"),
Self::StatusCode(code) => write!(f, "{}", code),
Self::_Ln(code) => write!(f, "{}", code),
Expand Down Expand Up @@ -68,13 +64,7 @@ impl ErrorResponse {
impl IntoResponse for Error {
fn into_response(self) -> Response {
match self {
Error::InvoiceNotPaid => (
StatusCode::OK,
ErrorResponse::new(0, &self.to_string()).as_json(),
)
.into_response(),
Error::DecodeInvoice => (StatusCode::BAD_REQUEST, self.to_string()).into_response(),
Error::InvoiceExpired => (StatusCode::BAD_REQUEST, self.to_string()).into_response(),
Error::StatusCode(code) => (code, "").into_response(),
Error::_Ln(code) => {
(StatusCode::INTERNAL_SERVER_ERROR, code.to_string()).into_response()
Expand Down
Loading

0 comments on commit 1f5dcfa

Please sign in to comment.