Skip to content

Commit

Permalink
chore(libs): bump deps (#965)
Browse files Browse the repository at this point in the history
* libs-sourcify,libs-solidity-metadata: bump blocksocut-display-bytes to v1.1.0

* libs-solidity-metadata: bump minicbor to v0.24

* libs-solidity-metadata: move blockscout-display-bytes to dev-dependencies.

Use added in updated blockscout-display-bytes `decode_hex` method
instead of DisplayBytes struct.

* libs-sourcify: replace DisplayBytes on new blockscout-display-bytes functions

* libs-solidity-metadata: bump to v1.1.0
  • Loading branch information
rimrakhimov authored Jul 1, 2024
1 parent e1983b1 commit c4261d0
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 57 deletions.
8 changes: 5 additions & 3 deletions libs/solidity-metadata/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "solidity-metadata"
version = "1.0.0"
version = "1.1.0"
description = "Parsing solidity metadata stored in bytecode"
license = "MIT"
repository = "https://github.com/blockscout/blockscout-rs"
Expand All @@ -11,7 +11,9 @@ categories = ["parsing"]
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
minicbor = { version = "0.18", features = ["std"] }
minicbor = { version = "0.24", features = ["std"] }
semver = "1.0"
thiserror = "1.0"
blockscout-display-bytes = "1.0"

[dev-dependencies]
blockscout-display-bytes = "1.1.0"
22 changes: 11 additions & 11 deletions libs/solidity-metadata/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ impl<'b> Decode<'b, DecodeContext> for MetadataHash {
#[cfg(test)]
mod metadata_hash_deserialization_tests {
use super::*;
use blockscout_display_bytes::Bytes as DisplayBytes;
use blockscout_display_bytes::decode_hex;
use std::str::FromStr;

fn is_valid_custom_error(
Expand Down Expand Up @@ -142,7 +142,7 @@ mod metadata_hash_deserialization_tests {
// { "bzzr0": b"d4fba422541feba2d648f6657d9354ec14ea9f5919b520abe0feb60981d7b17c" }
let hex =
"a165627a7a72305820d4fba422541feba2d648f6657d9354ec14ea9f5919b520abe0feb60981d7b17c";
let encoded = DisplayBytes::from_str(hex).unwrap().0;
let encoded = decode_hex(hex).unwrap();
let expected = MetadataHash { solc: None };
let expected_size = encoded.len();

Expand All @@ -160,7 +160,7 @@ mod metadata_hash_deserialization_tests {
// given
// { "ipfs": b"1220BCC988B1311237F2C00CCD0BFBD8B01D24DC18F720603B0DE93FE6327DF53625", "solc": b'00080e' }
let hex = "a2646970667358221220bcc988b1311237f2c00ccd0bfbd8b01d24dc18f720603b0de93fe6327df5362564736f6c634300080e";
let encoded = DisplayBytes::from_str(hex).unwrap().0;
let encoded = decode_hex(hex).unwrap();
let expected = MetadataHash {
solc: Some(Version::new(0, 8, 14)),
};
Expand All @@ -180,7 +180,7 @@ mod metadata_hash_deserialization_tests {
// given
// {"ipfs": b'1220BA5AF27FE13BC83E671BD6981216D35DF49AB3AC923741B8948B277F93FBF732', "solc": "0.8.15-ci.2022.5.23+commit.21591531"}
let hex = "a2646970667358221220ba5af27fe13bc83e671bd6981216d35df49ab3ac923741b8948b277f93fbf73264736f6c637823302e382e31352d63692e323032322e352e32332b636f6d6d69742e3231353931353331";
let encoded = DisplayBytes::from_str(hex).unwrap().0;
let encoded = decode_hex(hex).unwrap();
let expected = MetadataHash {
solc: Some(
Version::from_str("0.8.15-ci.2022.5.23+commit.21591531")
Expand All @@ -207,11 +207,11 @@ mod metadata_hash_deserialization_tests {
let second =
"a165627a7a72305820d4fba422541feba2d648f6657d9354ec14ea9f5919b520abe0feb60981d7b17c";
let hex = format!("{first}{second}");
let encoded = DisplayBytes::from_str(&hex).unwrap().0;
let encoded = decode_hex(&hex).unwrap();
let expected = MetadataHash {
solc: Some(Version::new(0, 8, 14)),
};
let expected_size = DisplayBytes::from_str(first).unwrap().0.len();
let expected_size = decode_hex(first).unwrap().len();

// when
let (decoded, decoded_size) = MetadataHash::from_cbor(encoded.as_ref())
Expand All @@ -226,7 +226,7 @@ mod metadata_hash_deserialization_tests {
fn deserialization_of_non_cbor_hex_should_fail() {
// given
let hex = "1234567890";
let encoded = DisplayBytes::from_str(hex).unwrap().0;
let encoded = decode_hex(hex).unwrap();

// when
let decoded = MetadataHash::from_cbor(encoded.as_ref());
Expand All @@ -244,7 +244,7 @@ mod metadata_hash_deserialization_tests {
// given
// "solc"
let hex = "64736f6c63";
let encoded = DisplayBytes::from_str(hex).unwrap().0;
let encoded = decode_hex(hex).unwrap();

// when
let decoded = MetadataHash::from_cbor(encoded.as_ref());
Expand All @@ -262,7 +262,7 @@ mod metadata_hash_deserialization_tests {
// given
// { "solc": b'000400', "ipfs": b"1220BCC988B1311237F2C00CCD0BFBD8B01D24DC18F720603B0DE93FE6327DF53625", "solc": b'00080e' }
let hex = "a364736f6c6343000400646970667358221220bcc988b1311237f2c00ccd0bfbd8b01d24dc18f720603b0de93fe6327df5362564736f6c634300080e";
let encoded = DisplayBytes::from_str(hex).unwrap().0;
let encoded = decode_hex(hex).unwrap();

// when
let decoded = MetadataHash::from_cbor(encoded.as_ref());
Expand All @@ -281,7 +281,7 @@ mod metadata_hash_deserialization_tests {
// 3 elements expected in the map but got only 2:
// { "ipfs": b"1220BCC988B1311237F2C00CCD0BFBD8B01D24DC18F720603B0DE93FE6327DF53625", "solc": b'00080e' }
let hex = "a3646970667358221220bcc988b1311237f2c00ccd0bfbd8b01d24dc18f720603b0de93fe6327df5362564736f6c634300080e";
let encoded = DisplayBytes::from_str(hex).unwrap().0;
let encoded = decode_hex(hex).unwrap();

// when
let decoded = MetadataHash::from_cbor(encoded.as_ref());
Expand All @@ -299,7 +299,7 @@ mod metadata_hash_deserialization_tests {
// given
// { "ipfs": b"1220BCC988B1311237F2C00CCD0BFBD8B01D24DC18F720603B0DE93FE6327DF53625", "solc": 123 } \
let hex= "a2646970667358221220bcc988b1311237f2c00ccd0bfbd8b01d24dc18f720603b0de93fe6327df5362564736f6c63187B";
let encoded = DisplayBytes::from_str(hex).unwrap().0;
let encoded = decode_hex(hex).unwrap();

// when
let decoded = MetadataHash::from_cbor(encoded.as_ref());
Expand Down
2 changes: 1 addition & 1 deletion libs/sourcify/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ edition = "2021"
[dependencies]
anyhow = "1.0.71"
bytes = "1.4.0"
blockscout-display-bytes = "1.0.0"
blockscout-display-bytes = "1.1.0"
reqwest = { version = "0.11.18", features = ["json"] }
reqwest-middleware = "0.2.2"
reqwest-retry = "0.3.0"
Expand Down
19 changes: 12 additions & 7 deletions libs/sourcify/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::{
},
Error, SourcifyError, VerifyFromEtherscanError,
};
use blockscout_display_bytes::Bytes as DisplayBytes;
use blockscout_display_bytes::ToHex;
use bytes::Bytes;
use reqwest::{Response, StatusCode};
use reqwest_middleware::{ClientWithMiddleware, Middleware};
Expand Down Expand Up @@ -126,9 +126,14 @@ impl Client {
chain_id: &str,
contract_address: Bytes,
) -> Result<GetSourceFilesResponse, Error<EmptyCustomError>> {
let contract_address = DisplayBytes::from(contract_address);
let url =
self.generate_url(format!("files/any/{}/{}", chain_id, contract_address).as_str());
let url = self.generate_url(
format!(
"files/any/{}/{}",
chain_id,
ToHex::to_hex(&contract_address)
)
.as_str(),
);

let response = self
.reqwest_client
Expand All @@ -148,7 +153,6 @@ impl Client {
chain_id: &str,
contract_address: Bytes,
) -> Result<VerifyFromEtherscanResponse, Error<VerifyFromEtherscanError>> {
let contract_address = DisplayBytes::from(contract_address);
let url = self.generate_url("verify/etherscan");

#[derive(Serialize)]
Expand All @@ -160,7 +164,7 @@ impl Client {

let request = Request {
chain_id,
address: contract_address.to_string(),
address: ToHex::to_hex(&contract_address),
};

let response = self
Expand Down Expand Up @@ -251,6 +255,7 @@ impl Client {
#[cfg(test)]
mod tests {
use super::*;
use blockscout_display_bytes::decode_hex;
use governor::{
clock::DefaultClock,
middleware::NoOpMiddleware,
Expand All @@ -263,7 +268,7 @@ mod tests {
use std::num::NonZeroU32;

fn parse_contract_address(contract_address: &str) -> Bytes {
DisplayBytes::from_str(contract_address).unwrap().0
decode_hex(contract_address).unwrap().into()
}

static RATE_LIMITER_MIDDLEWARE: OnceCell<
Expand Down
67 changes: 32 additions & 35 deletions libs/sourcify/src/types.rs

Large diffs are not rendered by default.

0 comments on commit c4261d0

Please sign in to comment.