mirror of
https://github.com/aljazceru/cdk.git
synced 2025-12-20 22:24:54 +01:00
feat: adding tos to mint (#604)
* feat: adding tos(terms of service) to mint and update cdk-sqlite migration
This commit is contained in:
@@ -59,7 +59,7 @@ impl<'de> Deserialize<'de> for MintVersion {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Mint Info [NIP-06]
|
/// Mint Info [NUT-06]
|
||||||
#[derive(Default, Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
#[derive(Default, Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
||||||
#[cfg_attr(feature = "swagger", derive(utoipa::ToSchema))]
|
#[cfg_attr(feature = "swagger", derive(utoipa::ToSchema))]
|
||||||
pub struct MintInfo {
|
pub struct MintInfo {
|
||||||
@@ -95,6 +95,9 @@ pub struct MintInfo {
|
|||||||
/// server unix timestamp
|
/// server unix timestamp
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub time: Option<u64>,
|
pub time: Option<u64>,
|
||||||
|
/// terms of url service of the mint
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
pub tos_url: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl MintInfo {
|
impl MintInfo {
|
||||||
@@ -197,6 +200,17 @@ impl MintInfo {
|
|||||||
..self
|
..self
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Set tos_url
|
||||||
|
pub fn tos_url<S>(self, tos_url: S) -> Self
|
||||||
|
where
|
||||||
|
S: Into<String>,
|
||||||
|
{
|
||||||
|
Self {
|
||||||
|
tos_url: Some(tos_url.into()),
|
||||||
|
..self
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Supported nuts and settings
|
/// Supported nuts and settings
|
||||||
@@ -432,7 +446,8 @@ mod tests {
|
|||||||
"9": {"supported": true},
|
"9": {"supported": true},
|
||||||
"10": {"supported": true},
|
"10": {"supported": true},
|
||||||
"11": {"supported": true}
|
"11": {"supported": true}
|
||||||
}
|
},
|
||||||
|
"tos_url": "https://cashu.mint/tos"
|
||||||
}"#;
|
}"#;
|
||||||
|
|
||||||
let _mint_info: MintInfo = serde_json::from_str(mint_info_str).unwrap();
|
let _mint_info: MintInfo = serde_json::from_str(mint_info_str).unwrap();
|
||||||
@@ -455,7 +470,8 @@ mod tests {
|
|||||||
|
|
||||||
println!("{}", mint_info);
|
println!("{}", mint_info);
|
||||||
*/
|
*/
|
||||||
let mint_info_str = r#"{
|
let mint_info_str = r#"
|
||||||
|
{
|
||||||
"name": "Bob's Cashu mint",
|
"name": "Bob's Cashu mint",
|
||||||
"pubkey": "0283bf290884eed3a7ca2663fc0260de2e2064d6b355ea13f98dec004b7a7ead99",
|
"pubkey": "0283bf290884eed3a7ca2663fc0260de2e2064d6b355ea13f98dec004b7a7ead99",
|
||||||
"version": "Nutshell/0.15.0",
|
"version": "Nutshell/0.15.0",
|
||||||
@@ -502,10 +518,12 @@ mod tests {
|
|||||||
"9": {"supported": true},
|
"9": {"supported": true},
|
||||||
"10": {"supported": true},
|
"10": {"supported": true},
|
||||||
"12": {"supported": true}
|
"12": {"supported": true}
|
||||||
}
|
},
|
||||||
|
"tos_url": "https://cashu.mint/tos"
|
||||||
}"#;
|
}"#;
|
||||||
let info: MintInfo = serde_json::from_str(mint_info_str).unwrap();
|
let info: MintInfo = serde_json::from_str(mint_info_str).unwrap();
|
||||||
let mint_info_str = r#"{
|
let mint_info_str = r#"
|
||||||
|
{
|
||||||
"name": "Bob's Cashu mint",
|
"name": "Bob's Cashu mint",
|
||||||
"pubkey": "0283bf290884eed3a7ca2663fc0260de2e2064d6b355ea13f98dec004b7a7ead99",
|
"pubkey": "0283bf290884eed3a7ca2663fc0260de2e2064d6b355ea13f98dec004b7a7ead99",
|
||||||
"version": "Nutshell/0.15.0",
|
"version": "Nutshell/0.15.0",
|
||||||
@@ -546,7 +564,8 @@ mod tests {
|
|||||||
"9": {"supported": true},
|
"9": {"supported": true},
|
||||||
"10": {"supported": true},
|
"10": {"supported": true},
|
||||||
"12": {"supported": true}
|
"12": {"supported": true}
|
||||||
}
|
},
|
||||||
|
"tos_url": "https://cashu.mint/tos"
|
||||||
}"#;
|
}"#;
|
||||||
let mint_info: MintInfo = serde_json::from_str(mint_info_str).unwrap();
|
let mint_info: MintInfo = serde_json::from_str(mint_info_str).unwrap();
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
ALTER TABLE mint ADD tos_url TEXT;
|
||||||
@@ -87,6 +87,7 @@ impl WalletDatabase for WalletSqliteDatabase {
|
|||||||
urls,
|
urls,
|
||||||
motd,
|
motd,
|
||||||
time,
|
time,
|
||||||
|
tos_url,
|
||||||
) = match mint_info {
|
) = match mint_info {
|
||||||
Some(mint_info) => {
|
Some(mint_info) => {
|
||||||
let MintInfo {
|
let MintInfo {
|
||||||
@@ -101,6 +102,7 @@ impl WalletDatabase for WalletSqliteDatabase {
|
|||||||
urls,
|
urls,
|
||||||
motd,
|
motd,
|
||||||
time,
|
time,
|
||||||
|
tos_url,
|
||||||
} = mint_info;
|
} = mint_info;
|
||||||
|
|
||||||
(
|
(
|
||||||
@@ -115,18 +117,19 @@ impl WalletDatabase for WalletSqliteDatabase {
|
|||||||
urls.map(|c| serde_json::to_string(&c).ok()),
|
urls.map(|c| serde_json::to_string(&c).ok()),
|
||||||
motd,
|
motd,
|
||||||
time,
|
time,
|
||||||
|
tos_url,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
None => (
|
None => (
|
||||||
None, None, None, None, None, None, None, None, None, None, None,
|
None, None, None, None, None, None, None, None, None, None, None, None,
|
||||||
),
|
),
|
||||||
};
|
};
|
||||||
|
|
||||||
sqlx::query(
|
sqlx::query(
|
||||||
r#"
|
r#"
|
||||||
INSERT INTO mint
|
INSERT INTO mint
|
||||||
(mint_url, name, pubkey, version, description, description_long, contact, nuts, icon_url, urls, motd, mint_time)
|
(mint_url, name, pubkey, version, description, description_long, contact, nuts, icon_url, urls, motd, mint_time, tos_url)
|
||||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||||
ON CONFLICT(mint_url) DO UPDATE SET
|
ON CONFLICT(mint_url) DO UPDATE SET
|
||||||
name = excluded.name,
|
name = excluded.name,
|
||||||
pubkey = excluded.pubkey,
|
pubkey = excluded.pubkey,
|
||||||
@@ -138,7 +141,8 @@ ON CONFLICT(mint_url) DO UPDATE SET
|
|||||||
icon_url = excluded.icon_url,
|
icon_url = excluded.icon_url,
|
||||||
urls = excluded.urls,
|
urls = excluded.urls,
|
||||||
motd = excluded.motd,
|
motd = excluded.motd,
|
||||||
mint_time = excluded.mint_time
|
mint_time = excluded.mint_time,
|
||||||
|
tos_url = excluded.tos_url
|
||||||
;
|
;
|
||||||
"#,
|
"#,
|
||||||
)
|
)
|
||||||
@@ -154,6 +158,7 @@ ON CONFLICT(mint_url) DO UPDATE SET
|
|||||||
.bind(urls)
|
.bind(urls)
|
||||||
.bind(motd)
|
.bind(motd)
|
||||||
.bind(time.map(|v| v as i64))
|
.bind(time.map(|v| v as i64))
|
||||||
|
.bind(tos_url)
|
||||||
.execute(&self.pool)
|
.execute(&self.pool)
|
||||||
.await
|
.await
|
||||||
.map_err(Error::from)?;
|
.map_err(Error::from)?;
|
||||||
@@ -833,7 +838,7 @@ fn sqlite_row_to_mint_info(row: &SqliteRow) -> Result<MintInfo, Error> {
|
|||||||
let motd: Option<String> = row.try_get("motd").map_err(Error::from)?;
|
let motd: Option<String> = row.try_get("motd").map_err(Error::from)?;
|
||||||
let row_urls: Option<String> = row.try_get("urls").map_err(Error::from)?;
|
let row_urls: Option<String> = row.try_get("urls").map_err(Error::from)?;
|
||||||
let time: Option<i64> = row.try_get("mint_time").map_err(Error::from)?;
|
let time: Option<i64> = row.try_get("mint_time").map_err(Error::from)?;
|
||||||
|
let tos_url: Option<String> = row.try_get("tos_url").map_err(Error::from)?;
|
||||||
Ok(MintInfo {
|
Ok(MintInfo {
|
||||||
name,
|
name,
|
||||||
pubkey: row_pubkey.and_then(|p| PublicKey::from_slice(&p).ok()),
|
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> {
|
|||||||
urls: row_urls.and_then(|c| serde_json::from_str(&c).ok()),
|
urls: row_urls.and_then(|c| serde_json::from_str(&c).ok()),
|
||||||
motd,
|
motd,
|
||||||
time: time.map(|t| t as u64),
|
time: time.map(|t| t as u64),
|
||||||
|
tos_url,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user