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

Commit

Permalink
improve: mint info version
Browse files Browse the repository at this point in the history
  • Loading branch information
thesimplekid committed Jul 18, 2023
1 parent 741db2b commit 1b506d1
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 23 deletions.
18 changes: 1 addition & 17 deletions Cargo.lock

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

1 change: 0 additions & 1 deletion mint/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ use tracing::{debug, warn};
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct MintInfo {
pub name: Option<String>,
pub pubkey: Option<String>,
pub version: Option<String>,
pub description: Option<String>,
pub description_long: Option<String>,
Expand Down
48 changes: 43 additions & 5 deletions mint/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use cashu_crab::nuts::nut05::{CheckFeesRequest, CheckFeesResponse};
use cashu_crab::nuts::nut06::{SplitRequest, SplitResponse};
use cashu_crab::nuts::nut07::{CheckSpendableRequest, CheckSpendableResponse};
use cashu_crab::nuts::nut08::{MeltRequest, MeltResponse};
use cashu_crab::nuts::nut09::MintVersion;
use cashu_crab::nuts::*;
use cashu_crab::{mint::Mint, Sha256};
use clap::Parser;
Expand All @@ -32,6 +33,8 @@ use tracing::{debug, warn};
use types::KeysetInfo;
use utils::unix_time;

pub const CARGO_PKG_VERSION: Option<&'static str> = option_env!("CARGO_PKG_VERSION");

use crate::cli::CLIArgs;
use crate::config::LnBackend;
use crate::database::Db;
Expand Down Expand Up @@ -244,8 +247,6 @@ struct MintInfo {
#[serde(default, skip_serializing_if = "Option::is_none")]
name: Option<String>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pubkey: Option<String>,
#[serde(default, skip_serializing_if = "Option::is_none")]
version: Option<String>,
#[serde(default, skip_serializing_if = "Option::is_none")]
description: Option<String>,
Expand All @@ -263,7 +264,6 @@ impl From<config::MintInfo> for MintInfo {
fn from(info: config::MintInfo) -> Self {
Self {
name: info.name,
pubkey: info.pubkey,
version: info.version,
description: info.description,
description_long: info.description_long,
Expand Down Expand Up @@ -484,6 +484,44 @@ async fn post_check(
})?))
}

async fn get_info(State(state): State<MintState>) -> Result<Json<MintInfo>, Error> {
Ok(Json(state.mint_info))
async fn get_info(State(state): State<MintState>) -> Result<Json<nut09::MintInfo>, Error> {
// TODO:
let nuts = vec![
"NUT-07".to_string(),
"NUT-08".to_string(),
"NUT-09".to_string(),
];

let mint_version = MintVersion {
name: "cashu-rs-mint".to_string(),
version: CARGO_PKG_VERSION
.map(std::borrow::ToOwned::to_owned)
.unwrap_or("".to_string()),
};

let contact: Vec<Vec<String>> = state
.mint_info
.contact
.iter()
.map(|inner_map| {
inner_map
.iter()
.flat_map(|(k, v)| vec![k.clone(), v.clone()])
.collect()
})
.collect();

let mint_info = nut09::MintInfo {
name: state.mint_info.name,
// TODO:
pubkey: None,
version: Some(mint_version),
description: state.mint_info.description,
description_long: state.mint_info.description_long,
contact,
nuts,
motd: state.mint_info.motd,
};

Ok(Json(mint_info))
}

0 comments on commit 1b506d1

Please sign in to comment.