check for proofs when creating token

This commit is contained in:
thesimplekid
2023-08-28 11:24:27 +01:00
parent f1d98a5d16
commit 4a7ea24be0
4 changed files with 25 additions and 7 deletions

View File

@@ -126,7 +126,7 @@ impl Wallet {
let proofs = self.mint(amount, hash).await?;
let token = Token::new(self.client.mint_url.clone(), proofs, None);
Ok(token)
Ok(token?)
}
/// Blocking Mint Token
@@ -135,7 +135,7 @@ impl Wallet {
let proofs = self.mint(amount, hash)?;
let token = Token::new(self.client.client.mint_url.clone(), proofs, None);
Ok(token)
Ok(token?)
}
/// Mint Proofs
@@ -515,12 +515,12 @@ impl Wallet {
#[cfg(not(feature = "blocking"))]
pub fn proofs_to_token(&self, proofs: Proofs, memo: Option<String>) -> Result<String, Error> {
Ok(Token::new(self.client.mint_url.clone(), proofs, memo).convert_to_string()?)
Ok(Token::new(self.client.mint_url.clone(), proofs, memo)?.convert_to_string()?)
}
#[cfg(feature = "blocking")]
pub fn proofs_to_token(&self, proofs: Proofs, memo: Option<String>) -> Result<String, Error> {
Ok(Token::new(self.client.client.mint_url.clone(), proofs, memo).convert_to_string()?)
Ok(Token::new(self.client.client.mint_url.clone(), proofs, memo)?.convert_to_string()?)
}
}

View File

@@ -92,6 +92,9 @@ pub mod wallet {
Base64Error(base64::DecodeError),
/// Unsupported Token
UnsupportedToken,
/// Token Requires proofs
ProofsRequired,
/// Custom Error message
CustomError(String),
}
@@ -107,6 +110,7 @@ pub mod wallet {
Error::UnsupportedToken => write!(f, "Unsuppported Token"),
Error::EllipticError(err) => write!(f, "{}", err),
Error::SerdeJsonError(err) => write!(f, "{}", err),
Error::ProofsRequired => write!(f, "Token must have at least one proof",),
}
}
}

View File

@@ -109,11 +109,19 @@ pub mod wallet {
}
impl Token {
pub fn new(mint_url: Url, proofs: Proofs, memo: Option<String>) -> Self {
Self {
pub fn new(
mint_url: Url,
proofs: Proofs,
memo: Option<String>,
) -> Result<Self, wallet::Error> {
if proofs.is_empty() {
return Err(wallet::Error::ProofsRequired);
}
Ok(Self {
token: vec![MintProofs::new(mint_url, proofs)],
memo,
}
})
}
pub fn token_info(&self) -> (u64, String) {

View File

@@ -0,0 +1,6 @@
precommit:
cargo check --no-default-features --features mint
cargo check --no-default-features --features wallet
cargo check --no-default-features --features blocking
typos
cargo test