Skip to content

Commit

Permalink
fix: clippy issues
Browse files Browse the repository at this point in the history
  • Loading branch information
remiroyc committed Sep 20, 2023
1 parent cad1ec7 commit 3ab5191
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 27 deletions.
10 changes: 5 additions & 5 deletions crates/ark-metadata/src/cairo_string_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,28 @@ use starknet::core::{types::FieldElement, utils::parse_cairo_short_string};
pub fn parse_cairo_long_string(field_elements: Vec<FieldElement>) -> Result<String> {
match field_elements.len() {
0 => {
return Err(anyhow!("No value found"));
Err(anyhow!("No value found"))
}
// If the long_string contains only one FieldElement, try to parse it using the short string parser.
1 => match field_elements.first() {
Some(first_string_field_element) => {
match parse_cairo_short_string(first_string_field_element) {
Ok(value) => {
return Ok(value);
Ok(value)
}
Err(_) => {
return Err(anyhow!("Error parsing short string"));
Err(anyhow!("Error parsing short string"))
}
}
}
None => return Err(anyhow!("No value found")),
None => Err(anyhow!("No value found")),
},
// If the long_string has more than one FieldElement, parse each FieldElement sequentially
// and concatenate their results.
_ => {
let mut result = String::new();
for i in 1..field_elements.len() {
let field_element = field_elements[i as usize].clone();
let field_element = field_elements[i];
match parse_cairo_short_string(&field_element) {
Ok(value) => {
result.push_str(&value);
Expand Down
4 changes: 2 additions & 2 deletions crates/ark-metadata/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ async fn main() -> Result<()> {
dotenv().ok();

let storage = DefaultStorage::new();
let file_manager = LocalFileManager::default();
let file_manager = LocalFileManager;

let starknet_client =
StarknetClientHttp::new("https://starknode.thearkproject.dev/mainnet").unwrap();
let mut metadata_manager = MetadataManager::new(&storage, &starknet_client, &file_manager);

let contract_address = FieldElement::from_hex_be(
&"0x0727a63f78ee3f1bd18f78009067411ab369c31dece1ae22e16f567906409905",
"0x0727a63f78ee3f1bd18f78009067411ab369c31dece1ae22e16f567906409905",
)
.unwrap();
let token_id_low = FieldElement::from_dec_str("1").unwrap();
Expand Down
6 changes: 3 additions & 3 deletions crates/ark-metadata/src/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use anyhow::Result;
use ark_storage::types::TokenMetadata;
use base64::{engine::general_purpose, Engine as _};
use reqwest::Client;
use urlencoding;


#[derive(Debug, PartialEq)]
pub enum MetadataType<'a> {
Expand All @@ -16,8 +16,8 @@ pub enum MetadataType<'a> {
pub async fn get_token_metadata(client: &Client, uri: &str) -> Result<TokenMetadata> {
let metadata_type = get_metadata_type(uri);
let metadata = match metadata_type {
MetadataType::Ipfs(uri) => get_ipfs_metadata(uri, &client).await?,
MetadataType::Http(uri) => get_http_metadata(uri, &client).await?,
MetadataType::Ipfs(uri) => get_ipfs_metadata(uri, client).await?,
MetadataType::Http(uri) => get_http_metadata(uri, client).await?,
MetadataType::OnChain(uri) => get_onchain_metadata(uri)?,
};
Ok(metadata)
Expand Down
34 changes: 17 additions & 17 deletions crates/ark-metadata/src/metadata_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ impl<'a, T: StorageManager, C: StarknetClient, F: FileManager> MetadataManager<'
url.as_str(),
image_ext,
cache_image.unwrap_or(false),
contract_address.clone(),
contract_address,
TokenId {
low: token_id_low,
high: token_id_high,
Expand Down Expand Up @@ -147,11 +147,11 @@ impl<'a, T: StorageManager, C: StarknetClient, F: FileManager> MetadataManager<'
let response = self.request_client.head(url).send().await?;
let (content_type, content_length) = extract_metadata_from_headers(response.headers())?;

return Ok(MetadataImage {
Ok(MetadataImage {
file_type: content_type,
content_length,
is_cache_updated: false,
});
})
} else {
debug!("Fetching image... {}", url);
let response = reqwest::get(url).await?;
Expand All @@ -163,7 +163,7 @@ impl<'a, T: StorageManager, C: StarknetClient, F: FileManager> MetadataManager<'
.save(&FileInfo {
name: format!("{}.{}", token_id.format().token_id, file_ext),
content: bytes.to_vec(),
dir_path: Some(String::from(format!("{:#064x}", contract_address))),
dir_path: Some(format!("{:#064x}", contract_address)),
})
.await?;

Expand All @@ -187,9 +187,9 @@ impl<'a, T: StorageManager, C: StarknetClient, F: FileManager> MetadataManager<'
let token_uri_cairo0 = self
.fetch_token_uri(
selector!("tokenURI"),
token_id_low.clone(),
token_id_high.clone(),
contract_address.clone(),
token_id_low,
token_id_high,
contract_address,
)
.await?;

Expand All @@ -207,10 +207,10 @@ impl<'a, T: StorageManager, C: StarknetClient, F: FileManager> MetadataManager<'
.await?;

if self.is_valid_uri(&token_uri_cairo1) {
return Ok(token_uri_cairo1);
Ok(token_uri_cairo1)
} else {
error!("Token URI not found");
return Err(anyhow!("Token URI not found"));
Err(anyhow!("Token URI not found"))
}
}

Expand Down Expand Up @@ -312,7 +312,7 @@ mod tests {
.times(1)
.returning(|_, _, _, _| {
Ok(vec![
FieldElement::from_dec_str(&"4").unwrap(),
FieldElement::from_dec_str("4").unwrap(),
FieldElement::from_hex_be("0x68").unwrap(),
FieldElement::from_hex_be("0x74").unwrap(),
FieldElement::from_hex_be("0x74").unwrap(),
Expand All @@ -339,9 +339,9 @@ mod tests {
// EXECUTION: Call the function under test
let result = metadata_manager
.refresh_token_metadata(
contract_address.clone(),
token_id.low.clone(),
token_id.high.clone(),
contract_address,
token_id.low,
token_id.high,
Some(false),
Some(false),
)
Expand All @@ -363,7 +363,7 @@ mod tests {
.times(1)
.returning(|_, _, _, _| {
Ok(vec![
FieldElement::from_dec_str(&"4").unwrap(),
FieldElement::from_dec_str("4").unwrap(),
FieldElement::from_hex_be("0x68").unwrap(),
FieldElement::from_hex_be("0x74").unwrap(),
FieldElement::from_hex_be("0x74").unwrap(),
Expand Down Expand Up @@ -402,14 +402,14 @@ mod tests {
.expect_call_contract()
.times(1)
.with(
eq(contract_address.clone()),
eq(selector_name.clone()),
eq(contract_address),
eq(selector_name),
eq(vec![FieldElement::ZERO, FieldElement::ZERO]),
eq(BlockId::Tag(BlockTag::Latest)),
)
.returning(|_, _, _, _| {
Ok(vec![
FieldElement::from_dec_str(&"4").unwrap(),
FieldElement::from_dec_str("4").unwrap(),
FieldElement::from_hex_be("0x68").unwrap(),
FieldElement::from_hex_be("0x74").unwrap(),
FieldElement::from_hex_be("0x74").unwrap(),
Expand Down

0 comments on commit 3ab5191

Please sign in to comment.