Skip to content

Commit fcf2e9d

Browse files
authored
feat: adding tos to mint (#604)
* feat: adding tos(terms of service) to mint and update cdk-sqlite migration
1 parent 5a7362c commit fcf2e9d

File tree

3 files changed

+83
-57
lines changed

3 files changed

+83
-57
lines changed

crates/cashu/src/nuts/nut06.rs

+71-52
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ impl<'de> Deserialize<'de> for MintVersion {
5959
}
6060
}
6161

62-
/// Mint Info [NIP-06]
62+
/// Mint Info [NUT-06]
6363
#[derive(Default, Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
6464
#[cfg_attr(feature = "swagger", derive(utoipa::ToSchema))]
6565
pub struct MintInfo {
@@ -95,6 +95,9 @@ pub struct MintInfo {
9595
/// server unix timestamp
9696
#[serde(skip_serializing_if = "Option::is_none")]
9797
pub time: Option<u64>,
98+
/// terms of url service of the mint
99+
#[serde(skip_serializing_if = "Option::is_none")]
100+
pub tos_url: Option<String>,
98101
}
99102

100103
impl MintInfo {
@@ -197,6 +200,17 @@ impl MintInfo {
197200
..self
198201
}
199202
}
203+
204+
/// Set tos_url
205+
pub fn tos_url<S>(self, tos_url: S) -> Self
206+
where
207+
S: Into<String>,
208+
{
209+
Self {
210+
tos_url: Some(tos_url.into()),
211+
..self
212+
}
213+
}
200214
}
201215

202216
/// Supported nuts and settings
@@ -405,12 +419,12 @@ mod tests {
405419
#[test]
406420
fn test_des_mint_into() {
407421
let mint_info_str = r#"{
408-
"name": "Cashu mint",
409-
"pubkey": "0296d0aa13b6a31cf0cd974249f28c7b7176d7274712c95a41c7d8066d3f29d679",
410-
"version": "Nutshell/0.15.3",
411-
"contact": [
412-
["", ""],
413-
["", ""]
422+
"name": "Cashu mint",
423+
"pubkey": "0296d0aa13b6a31cf0cd974249f28c7b7176d7274712c95a41c7d8066d3f29d679",
424+
"version": "Nutshell/0.15.3",
425+
"contact": [
426+
["", ""],
427+
["", ""]
414428
],
415429
"nuts": {
416430
"4": {
@@ -432,7 +446,8 @@ mod tests {
432446
"9": {"supported": true},
433447
"10": {"supported": true},
434448
"11": {"supported": true}
435-
}
449+
},
450+
"tos_url": "https://cashu.mint/tos"
436451
}"#;
437452

438453
let _mint_info: MintInfo = serde_json::from_str(mint_info_str).unwrap();
@@ -455,7 +470,8 @@ mod tests {
455470
456471
println!("{}", mint_info);
457472
*/
458-
let mint_info_str = r#"{
473+
let mint_info_str = r#"
474+
{
459475
"name": "Bob's Cashu mint",
460476
"pubkey": "0283bf290884eed3a7ca2663fc0260de2e2064d6b355ea13f98dec004b7a7ead99",
461477
"version": "Nutshell/0.15.0",
@@ -502,51 +518,54 @@ mod tests {
502518
"9": {"supported": true},
503519
"10": {"supported": true},
504520
"12": {"supported": true}
505-
}
521+
},
522+
"tos_url": "https://cashu.mint/tos"
506523
}"#;
507524
let info: MintInfo = serde_json::from_str(mint_info_str).unwrap();
508-
let mint_info_str = r#"{
509-
"name": "Bob's Cashu mint",
510-
"pubkey": "0283bf290884eed3a7ca2663fc0260de2e2064d6b355ea13f98dec004b7a7ead99",
511-
"version": "Nutshell/0.15.0",
512-
"description": "The short mint description",
513-
"description_long": "A description that can be a long piece of text.",
514-
"contact": [
515-
["nostr", "xxxxx"],
516-
["email", "contact@me.com"]
517-
],
518-
"motd": "Message to display to users.",
519-
"icon_url": "https://this-is-a-mint-icon-url.com/icon.png",
520-
"nuts": {
521-
"4": {
522-
"methods": [
523-
{
524-
"method": "bolt11",
525-
"unit": "sat",
526-
"min_amount": 0,
527-
"max_amount": 10000,
528-
"description": true
529-
}
530-
],
531-
"disabled": false
532-
},
533-
"5": {
534-
"methods": [
535-
{
536-
"method": "bolt11",
537-
"unit": "sat",
538-
"min_amount": 0,
539-
"max_amount": 10000
540-
}
541-
],
542-
"disabled": false
543-
},
544-
"7": {"supported": true},
545-
"8": {"supported": true},
546-
"9": {"supported": true},
547-
"10": {"supported": true},
548-
"12": {"supported": true}
549-
}
525+
let mint_info_str = r#"
526+
{
527+
"name": "Bob's Cashu mint",
528+
"pubkey": "0283bf290884eed3a7ca2663fc0260de2e2064d6b355ea13f98dec004b7a7ead99",
529+
"version": "Nutshell/0.15.0",
530+
"description": "The short mint description",
531+
"description_long": "A description that can be a long piece of text.",
532+
"contact": [
533+
["nostr", "xxxxx"],
534+
["email", "contact@me.com"]
535+
],
536+
"motd": "Message to display to users.",
537+
"icon_url": "https://this-is-a-mint-icon-url.com/icon.png",
538+
"nuts": {
539+
"4": {
540+
"methods": [
541+
{
542+
"method": "bolt11",
543+
"unit": "sat",
544+
"min_amount": 0,
545+
"max_amount": 10000,
546+
"description": true
547+
}
548+
],
549+
"disabled": false
550+
},
551+
"5": {
552+
"methods": [
553+
{
554+
"method": "bolt11",
555+
"unit": "sat",
556+
"min_amount": 0,
557+
"max_amount": 10000
558+
}
559+
],
560+
"disabled": false
561+
},
562+
"7": {"supported": true},
563+
"8": {"supported": true},
564+
"9": {"supported": true},
565+
"10": {"supported": true},
566+
"12": {"supported": true}
567+
},
568+
"tos_url": "https://cashu.mint/tos"
550569
}"#;
551570
let mint_info: MintInfo = serde_json::from_str(mint_info_str).unwrap();
552571

Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ALTER TABLE mint ADD tos_url TEXT;

crates/cdk-sqlite/src/wallet/mod.rs

+11-5
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ impl WalletDatabase for WalletSqliteDatabase {
8787
urls,
8888
motd,
8989
time,
90+
tos_url,
9091
) = match mint_info {
9192
Some(mint_info) => {
9293
let MintInfo {
@@ -101,6 +102,7 @@ impl WalletDatabase for WalletSqliteDatabase {
101102
urls,
102103
motd,
103104
time,
105+
tos_url,
104106
} = mint_info;
105107

106108
(
@@ -115,18 +117,19 @@ impl WalletDatabase for WalletSqliteDatabase {
115117
urls.map(|c| serde_json::to_string(&c).ok()),
116118
motd,
117119
time,
120+
tos_url,
118121
)
119122
}
120123
None => (
121-
None, None, None, None, None, None, None, None, None, None, None,
124+
None, None, None, None, None, None, None, None, None, None, None, None,
122125
),
123126
};
124127

125128
sqlx::query(
126129
r#"
127130
INSERT INTO mint
128-
(mint_url, name, pubkey, version, description, description_long, contact, nuts, icon_url, urls, motd, mint_time)
129-
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
131+
(mint_url, name, pubkey, version, description, description_long, contact, nuts, icon_url, urls, motd, mint_time, tos_url)
132+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
130133
ON CONFLICT(mint_url) DO UPDATE SET
131134
name = excluded.name,
132135
pubkey = excluded.pubkey,
@@ -138,7 +141,8 @@ ON CONFLICT(mint_url) DO UPDATE SET
138141
icon_url = excluded.icon_url,
139142
urls = excluded.urls,
140143
motd = excluded.motd,
141-
mint_time = excluded.mint_time
144+
mint_time = excluded.mint_time,
145+
tos_url = excluded.tos_url
142146
;
143147
"#,
144148
)
@@ -154,6 +158,7 @@ ON CONFLICT(mint_url) DO UPDATE SET
154158
.bind(urls)
155159
.bind(motd)
156160
.bind(time.map(|v| v as i64))
161+
.bind(tos_url)
157162
.execute(&self.pool)
158163
.await
159164
.map_err(Error::from)?;
@@ -833,7 +838,7 @@ fn sqlite_row_to_mint_info(row: &SqliteRow) -> Result<MintInfo, Error> {
833838
let motd: Option<String> = row.try_get("motd").map_err(Error::from)?;
834839
let row_urls: Option<String> = row.try_get("urls").map_err(Error::from)?;
835840
let time: Option<i64> = row.try_get("mint_time").map_err(Error::from)?;
836-
841+
let tos_url: Option<String> = row.try_get("tos_url").map_err(Error::from)?;
837842
Ok(MintInfo {
838843
name,
839844
pubkey: row_pubkey.and_then(|p| PublicKey::from_slice(&p).ok()),
@@ -848,6 +853,7 @@ fn sqlite_row_to_mint_info(row: &SqliteRow) -> Result<MintInfo, Error> {
848853
urls: row_urls.and_then(|c| serde_json::from_str(&c).ok()),
849854
motd,
850855
time: time.map(|t| t as u64),
856+
tos_url,
851857
})
852858
}
853859

0 commit comments

Comments
 (0)