Skip to content

Commit

Permalink
feat: change contact-info in /info endpoint fixes #303 (#305)
Browse files Browse the repository at this point in the history
  • Loading branch information
ngutech21 authored Jul 16, 2024
1 parent 8751686 commit 7221138
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 27 deletions.
15 changes: 12 additions & 3 deletions moksha-core/src/fixtures/nutshell_mint_info.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,18 @@
"description": "The short mint description",
"description_long": "A long mint description that can be a long piece of text.",
"contact": [
["email", "[email protected]"],
["twitter", "@me"],
["nostr", "npub..."]
{
"method": "email",
"info": "[email protected]"
},
{
"method": "twitter",
"info": "@me"
},
{
"method": "nostr",
"info": "npub..."
}
],
"motd": "Message to users",
"nuts": {
Expand Down
39 changes: 34 additions & 5 deletions moksha-core/src/primitives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,11 +220,40 @@ pub struct MintInfoResponse {
pub version: Option<String>,
pub description: Option<String>,
pub description_long: Option<String>,
pub contact: Option<Vec<Vec<String>>>,
pub contact: Option<Vec<ContactInfoResponse>>,
pub motd: Option<String>,
pub nuts: Nuts,
}

#[derive(Deserialize, Serialize, Debug, Clone, PartialEq, Eq, ToSchema)]
pub struct ContactInfoResponse {
pub method: String,
pub info: String,
}

impl ContactInfoResponse {
pub fn email(info: String) -> Self {
Self {
method: "email".to_string(),
info,
}
}

pub fn twitter(info: String) -> Self {
Self {
method: "twitter".to_string(),
info,
}
}

pub fn nostr(info: String) -> Self {
Self {
method: "twitter".to_string(),
info,
}
}
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct BtcOnchainMintQuote {
pub quote_id: Uuid,
Expand Down Expand Up @@ -536,7 +565,7 @@ mod tests {
use crate::{
dhke::public_key_from_hex,
fixture::read_fixture,
primitives::{KeyResponse, MintInfoResponse, Nuts, PostSwapResponse},
primitives::{ContactInfoResponse, KeyResponse, MintInfoResponse, Nuts, PostSwapResponse},
};

#[test]
Expand Down Expand Up @@ -570,9 +599,9 @@ mod tests {
description: Some("The short mint description".to_string()),
description_long: Some("A description that can be a long piece of text.".to_string()),
contact: Some(vec![
vec!["email".to_string(), "[email protected]".to_string()],
vec!["twitter".to_string(), "@me".to_string()],
vec!["nostr".to_string(), "npub...".to_string()],
ContactInfoResponse::email("[email protected]".to_string()),
ContactInfoResponse::twitter("@me".to_string()),
ContactInfoResponse::nostr("npub...".to_string()),
]),
nuts: Nuts::default(),
motd: Some("Message to display to users.".to_string()),
Expand Down
14 changes: 13 additions & 1 deletion moksha-mint/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::{env, net::SocketAddr, path::PathBuf, str::FromStr};

use clap::Parser;
use moksha_core::primitives::{
CurrencyUnit, Nut17, Nut18, PaymentMethod, PaymentMethodConfigBtcOnchain,
ContactInfoResponse, CurrencyUnit, Nut17, Nut18, PaymentMethod, PaymentMethodConfigBtcOnchain,
};
use serde::{Deserialize, Serialize};

Expand Down Expand Up @@ -302,6 +302,18 @@ pub struct MintInfoConfig {
// FIXME add missing fields for v1/info endpoint nut4/nut5 payment_methods, nut4 disabled flag
}

impl From<MintInfoConfig> for Vec<ContactInfoResponse> {
fn from(info: MintInfoConfig) -> Vec<ContactInfoResponse> {
[
info.contact_email.map(ContactInfoResponse::email),
info.contact_twitter.map(ContactInfoResponse::twitter),
info.contact_nostr.map(ContactInfoResponse::nostr),
]
.iter()
.filter_map(|contact| contact.to_owned())
.collect()
}
}
#[derive(Deserialize, Serialize, Debug, Clone, Default)]
pub struct BuildParams {
pub commit_hash: Option<String>,
Expand Down
19 changes: 1 addition & 18 deletions moksha-mint/src/routes/default.rs
Original file line number Diff line number Diff line change
Expand Up @@ -341,25 +341,8 @@ pub async fn get_melt_quote_bolt11(
)]
#[instrument(name = "get_info", skip(mint), err)]
pub async fn get_info(State(mint): State<Mint>) -> Result<Json<MintInfoResponse>, MokshaMintError> {
// TODO implement From-trait

let mint_info = mint.config.info.clone();
let contact = Some(
vec![
mint_info
.contact_email
.map(|email| vec!["email".to_owned(), email]),
mint_info
.contact_twitter
.map(|twitter| vec!["twitter".to_owned(), twitter]),
mint_info
.contact_nostr
.map(|nostr| vec!["nostr".to_owned(), nostr]),
]
.into_iter()
.flatten()
.collect::<Vec<Vec<String>>>(),
);
let contact = Some(mint_info.into());

let mint_info = MintInfoResponse {
nuts: get_nuts(&mint.config),
Expand Down

0 comments on commit 7221138

Please sign in to comment.