-
Notifications
You must be signed in to change notification settings - Fork 791
Conversation
This should work now / it works when testing locally on mds1/drai |
Actually, I should probably add an actual error for rate limits so we can catch it in Foundry for retries |
This fails when the file doesn't exist, going back in draft |
then should be good to merge |
let query = self.create_query("contract", "getabi", HashMap::from([("address", address)])); | ||
let resp: Response<String> = self.get_json(&query).await?; | ||
if resp.result.starts_with("Max rate limit reached") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we have to dupe the check here cus it deserializes message
as a string.. really annoying but no way around it really
if etherscan would give me access i would make their api better
ethers-etherscan/src/lib.rs
Outdated
expiry: SystemTime::now() | ||
.checked_add(self.ttl) | ||
.expect("cache ttl overflowed") | ||
.duration_since(UNIX_EPOCH) | ||
.expect("system time is before unix epoch") | ||
.as_secs(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a simpler way to do this?
let reader = std::io::BufReader::new(std::fs::File::open(path)?); | ||
if let Ok(inner) = serde_json::from_reader::<_, CacheEnvelope<T>>(reader) { | ||
// If this does not return None then we have passed the expiry | ||
if SystemTime::now().checked_sub(Duration::from_secs(inner.expiry)).is_some() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above
Oh wait, I re-requested review before I cached the "not verified" objects |
if let Some(ref cache) = self.cache { | ||
// If this is None, then we have a cache miss | ||
if let Some(src) = cache.get_source(address) { | ||
// If this is None, then the contract is not verified | ||
return match src { | ||
Some(src) => Ok(src), | ||
None => Err(EtherscanError::ContractCodeNotVerified(address)), | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is really ugly, but the alternative was to cache Result<T, EtherscanError>
. Not sure. Any suggestions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can prob do something like if let Some(Some(src)) = cache.get_source(address)
but nbd. feel free to do in follow up
} | ||
} | ||
|
||
fn get<T: DeserializeOwned>(&self, prefix: &str, address: Address) -> Option<T> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Switched this to an option since we don't really care about the errors:
- If we can't deserialize it, it's malformed and we need to rewrite it
- If we can't open the file, the directory doesn't exist (we probably care here, should we add tracing?)
if let Some(ref cache) = self.cache { | ||
// If this is None, then we have a cache miss | ||
if let Some(src) = cache.get_source(address) { | ||
// If this is None, then the contract is not verified | ||
return match src { | ||
Some(src) => Ok(src), | ||
None => Err(EtherscanError::ContractCodeNotVerified(address)), | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can prob do something like if let Some(Some(src)) = cache.get_source(address)
but nbd. feel free to do in follow up
Merging - let's hope it works well :) |
* feat: etherscan identifier * chore: bump ethers for the caching PR gakonst/ethers-rs#1108 * feat: add cache ttl to etherscan identifier * chore: clippy * chore: re-add ethers patch section * build: bump ethers * test: fix tests * fix: trace macros * bump color eyre and lock tracing-subscriber (#1220) * bump color eyre * lock tracing-subscriber 0.3.9 * feat: pull etherscan api key and eth rpc from env * refactor: readability in `trace.addresses` * refactor: add `AddressIdentity` type * refactor: add a rate limited etherscan stream * test: don't set `ETH_RPC_URL` as its not used * refactor: smol nit Co-authored-by: Georgios Konstantopoulos <[email protected]> Co-authored-by: Matthias Seitz <[email protected]>
* feat: etherscan identifier * chore: bump ethers for the caching PR gakonst/ethers-rs#1108 * feat: add cache ttl to etherscan identifier * chore: clippy * chore: re-add ethers patch section * build: bump ethers * test: fix tests * fix: trace macros * bump color eyre and lock tracing-subscriber (#1220) * bump color eyre * lock tracing-subscriber 0.3.9 * feat: pull etherscan api key and eth rpc from env * refactor: readability in `trace.addresses` * refactor: add `AddressIdentity` type * refactor: add a rate limited etherscan stream * test: don't set `ETH_RPC_URL` as its not used * refactor: smol nit Co-authored-by: Georgios Konstantopoulos <[email protected]> Co-authored-by: Matthias Seitz <[email protected]>
* feat: etherscan identifier * chore: bump ethers for the caching PR gakonst/ethers-rs#1108 * feat: add cache ttl to etherscan identifier * chore: clippy * chore: re-add ethers patch section * build: bump ethers * test: fix tests * fix: trace macros * bump color eyre and lock tracing-subscriber (#1220) * bump color eyre * lock tracing-subscriber 0.3.9 * feat: pull etherscan api key and eth rpc from env * refactor: readability in `trace.addresses` * refactor: add `AddressIdentity` type * refactor: add a rate limited etherscan stream * test: don't set `ETH_RPC_URL` as its not used * refactor: smol nit Co-authored-by: Georgios Konstantopoulos <[email protected]> Co-authored-by: Matthias Seitz <[email protected]>
Supersedes #935