chore: Fix lint warnings for all targets (#240)

This commit is contained in:
Santiago Carmuega 2023-03-24 10:59:49 +01:00 committed by GitHub
parent 2f1270f8e8
commit 381a46f2cf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
15 changed files with 93 additions and 94 deletions

View file

@ -1,17 +1,16 @@
use blake2::Blake2bVar;
use bech32::{self, Error, ToBase32, Variant};
use blake2::digest::{Update, VariableOutput};
use bech32 :: {self, Variant, Error, ToBase32};
use blake2::Blake2bVar;
use hex::{self};
use std::error::Error as Err;
const DATA: &str = "asset";
pub struct AssetFingerprint {
hash_buf : [u8;20]
hash_buf: [u8; 20],
}
impl AssetFingerprint {
pub fn from_parts(policy_id: &str, asset_name: &str) -> Result<AssetFingerprint, Box<dyn Err>> {
let mut hasher = Blake2bVar::new(20).unwrap();
let c = format!("{policy_id}{asset_name}");
@ -20,12 +19,11 @@ impl AssetFingerprint {
let mut buf = [0u8; 20];
hasher.finalize_variable(&mut buf)?;
Ok(AssetFingerprint { hash_buf : buf })
Ok(AssetFingerprint { hash_buf: buf })
}
pub fn finger_print(&self) -> Result<String, Error> {
bech32::encode(DATA, self.hash_buf.to_base32(), Variant::Bech32)
pub fn finger_print(&self) -> Result<String, Error> {
bech32::encode(DATA, self.hash_buf.to_base32(), Variant::Bech32)
}
}
@ -35,17 +33,23 @@ mod tests {
#[test]
fn finger_print_test1() {
let af = AssetFingerprint::from_parts("7eae28af2208be856f7a119668ae52a49b73725e326dc16579dcc373", "").unwrap();
let af = AssetFingerprint::from_parts(
"7eae28af2208be856f7a119668ae52a49b73725e326dc16579dcc373",
"",
)
.unwrap();
let result = af.finger_print().unwrap();
assert_eq!(result, "asset1rjklcrnsdzqp65wjgrg55sy9723kw09mlgvlc3");
}
#[test]
fn finger_print_test2() {
let af = AssetFingerprint::from_parts("1e349c9bdea19fd6c147626a5260bc44b71635f398b67c59881df209", "504154415445").unwrap();
let af = AssetFingerprint::from_parts(
"1e349c9bdea19fd6c147626a5260bc44b71635f398b67c59881df209",
"504154415445",
)
.unwrap();
let result = af.finger_print().unwrap();
assert_eq!(result, "asset1hv4p5tv2a837mzqrst04d0dcptdjmluqvdx9k3");
}
}
}