Skip to content

Commit

Permalink
Merge pull request #3 from sbip-sg/update-for-create2
Browse files Browse the repository at this point in the history
Update for create2
  • Loading branch information
cassc authored Jul 9, 2024
2 parents ee6664f + 8530aa0 commit f344436
Show file tree
Hide file tree
Showing 7 changed files with 237 additions and 228 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ thread_local = "1.1.8"
tokio = { version = "1.38.0", features = ["full"] }
strum_macros = "0.26.4"
hashbrown = "*"
redis = "0.25.4"
redis = { version= "0.25.4", optional = true}

[dev-dependencies]
criterion = {version="0.3.6", features=["html_reports"] }

[features]
default = []
redis=["dep:redis"]
11 changes: 4 additions & 7 deletions src/cache/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use eyre::Result;

#[cfg(not(feature = "redis"))]
pub mod filesystem_cache;

#[cfg(feature = "redis")]
pub mod redis_cache;

pub trait ProviderCache: Clone + Default {
Expand All @@ -13,11 +16,5 @@ pub trait ProviderCache: Clone + Default {
response: &str,
) -> Result<()>;

fn get(
&self,
chain: &str,
block: u64,
api: &str,
request_hash: &str,
) -> Result<String>;
fn get(&self, chain: &str, block: u64, api: &str, request_hash: &str) -> Result<String>;
}
13 changes: 11 additions & 2 deletions src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,15 @@ pub fn bigint_to_ruint_u256(b: &BigInt) -> Result<U256> {
if sign == num_bigint::Sign::Minus {
return Err(eyre::eyre!("BigInt is negative"));
}
let bytes = &bytes[..32];
Ok(U256::from_be_slice(bytes.into()))

let mut padded_bytes = [0u8; 32];
let bytes_len = bytes.len();
if bytes_len > 32 {
return Err(eyre::eyre!("BigInt is too large"));
}

// Copy bytes into the end of the padded array
padded_bytes[(32 - bytes_len)..].copy_from_slice(&bytes);

Ok(U256::from_be_slice(&padded_bytes))
}
Loading

0 comments on commit f344436

Please sign in to comment.