-
Notifications
You must be signed in to change notification settings - Fork 127
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(inspect): implement
DecodedTransactionTrace
- Loading branch information
1 parent
8b65118
commit cc7c9fd
Showing
8 changed files
with
401 additions
and
223 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
use std::collections::{HashMap, HashSet}; | ||
|
||
use ethers::types::Address; | ||
use futures::future::try_join_all; | ||
|
||
use crate::{error::Error, inspect::InspectArgs}; | ||
use heimdall_common::{resources::transpose::get_label, utils::hex::ToLowerHex}; | ||
|
||
#[derive(Debug, Clone)] | ||
pub struct Contracts { | ||
pub contracts: HashMap<Address, String>, | ||
transpose_api_key: Option<String>, | ||
} | ||
|
||
impl Contracts { | ||
pub fn new(args: &InspectArgs) -> Self { | ||
Self { contracts: HashMap::new(), transpose_api_key: args.transpose_api_key.clone() } | ||
} | ||
|
||
pub async fn add(&mut self, address: Address) -> Result<(), Error> { | ||
// if alias already exists, don't overwrite | ||
if self.contracts.contains_key(&address) { | ||
return Ok(()); | ||
} | ||
|
||
if let Some(transpose_api_key) = &self.transpose_api_key { | ||
self.contracts.insert( | ||
address, | ||
get_label(&address.to_lower_hex(), transpose_api_key) | ||
.await | ||
.unwrap_or(address.to_lower_hex()), | ||
); | ||
} else { | ||
self.contracts.insert(address, address.to_lower_hex()); | ||
} | ||
|
||
Ok(()) | ||
} | ||
|
||
pub async fn extend(&mut self, addresses: HashSet<Address>) -> Result<(), Error> { | ||
// for each address, get the label | ||
if let Some(transpose_api_key) = &self.transpose_api_key { | ||
let handles: Vec<_> = addresses | ||
.clone() | ||
.into_iter() | ||
.map(move |address| { | ||
let transpose_api_key = transpose_api_key.clone(); | ||
tokio::spawn(async move { | ||
get_label(&address.to_lower_hex(), &transpose_api_key).await | ||
}) | ||
}) | ||
.collect(); | ||
|
||
let labels = | ||
try_join_all(handles).await.map_err(|e| Error::TransposeError(e.to_string()))?; | ||
|
||
self.contracts.extend( | ||
addresses | ||
.into_iter() | ||
.zip(labels.into_iter()) | ||
.map(|(address, label)| (address, label.unwrap_or(address.to_lower_hex()))), | ||
); | ||
// replace None | ||
} else { | ||
self.contracts | ||
.extend(addresses.into_iter().map(|address| (address, address.to_lower_hex()))); | ||
} | ||
|
||
Ok(()) | ||
} | ||
|
||
pub fn get(&self, address: Address) -> Option<&String> { | ||
self.contracts.get(&address) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
pub(crate) mod contracts; | ||
pub mod tracing; |
Oops, something went wrong.