Skip to content

Commit e3c3ba4

Browse files
committed
chore: docs
1 parent db3e06f commit e3c3ba4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+206
-144
lines changed

crates/cache/src/lib.rs

+7-10
Original file line numberDiff line numberDiff line change
@@ -225,8 +225,7 @@ pub fn delete_cache(key: &str) -> Result<(), Error> {
225225
#[allow(deprecated)]
226226
pub fn read_cache<T>(key: &str) -> Result<Option<T>, Error>
227227
where
228-
T: 'static + DeserializeOwned,
229-
{
228+
T: 'static + DeserializeOwned, {
230229
let home = home_dir().ok_or(Error::Generic(
231230
"failed to get home directory. does your os support `std::env::home_dir()`?".to_string(),
232231
))?;
@@ -249,8 +248,8 @@ where
249248
.map_err(|e| Error::Generic(format!("failed to deserialize cache object: {:?}", e)))?;
250249

251250
// check if the cache has expired, if so, delete it and return None
252-
if cache.expiry
253-
< std::time::SystemTime::now()
251+
if cache.expiry <
252+
std::time::SystemTime::now()
254253
.duration_since(std::time::UNIX_EPOCH)
255254
.map_err(|e| Error::Generic(format!("failed to get current time: {:?}", e)))?
256255
.as_secs()
@@ -277,8 +276,7 @@ where
277276
#[allow(deprecated)]
278277
pub fn store_cache<T>(key: &str, value: T, expiry: Option<u64>) -> Result<(), Error>
279278
where
280-
T: Serialize,
281-
{
279+
T: Serialize, {
282280
let home = home_dir().ok_or(Error::Generic(
283281
"failed to get home directory. does your os support `std::env::home_dir()`?".to_string(),
284282
))?;
@@ -290,8 +288,8 @@ where
290288
std::time::SystemTime::now()
291289
.duration_since(std::time::UNIX_EPOCH)
292290
.map_err(|e| Error::Generic(format!("failed to get current time: {:?}", e)))?
293-
.as_secs()
294-
+ 60 * 60 * 24 * 90,
291+
.as_secs() +
292+
60 * 60 * 24 * 90,
295293
);
296294

297295
let cache = Cache { value, expiry };
@@ -316,8 +314,7 @@ pub async fn with_cache<T, F, Fut>(key: &str, func: F) -> eyre::Result<T>
316314
where
317315
T: 'static + Serialize + DeserializeOwned + Send + Sync,
318316
F: FnOnce() -> Fut + Send,
319-
Fut: std::future::Future<Output = Result<T, eyre::Report>> + Send,
320-
{
317+
Fut: std::future::Future<Output = Result<T, eyre::Report>> + Send, {
321318
// Try to read from cache
322319
match read_cache::<T>(key) {
323320
Ok(Some(cached_value)) => {

crates/cfg/src/core/graph.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ pub(crate) fn build_cfg(
6060
.first()
6161
.ok_or_eyre("failed to get first operation")?
6262
.last_instruction
63-
.opcode
64-
== JUMPDEST,
63+
.opcode ==
64+
JUMPDEST,
6565
)?;
6666
}
6767

crates/cli/src/args.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use tracing::{level_filters::LevelFilter, Level};
2020

2121
#[derive(Debug, Parser)]
2222
#[clap(name = "heimdall", author = "Jonathan Becker <[email protected]>", version)]
23-
pub struct Arguments {
23+
pub(crate) struct Arguments {
2424
#[clap(subcommand)]
2525
pub sub: Subcommands,
2626

@@ -34,7 +34,7 @@ pub struct Arguments {
3434
after_help = "For more information, read the wiki: https://jbecker.dev/r/heimdall-rs/wiki"
3535
)]
3636
#[allow(clippy::large_enum_variant)]
37-
pub enum Subcommands {
37+
pub(crate) enum Subcommands {
3838
#[clap(name = "disassemble", about = "Disassemble EVM bytecode to assembly")]
3939
Disassemble(DisassemblerArgs),
4040

@@ -66,7 +66,7 @@ pub enum Subcommands {
6666
/// The log configuration.
6767
#[derive(Debug, Args)]
6868
#[clap(next_help_heading = "LOGGING")]
69-
pub struct LogArgs {
69+
pub(crate) struct LogArgs {
7070
/// The format to use for logs written to stdout.
7171
#[clap(long = "log.stdout.format", value_name = "FORMAT", global = true, default_value_t = LogFormat::Terminal)]
7272
pub log_stdout_format: LogFormat,
@@ -115,7 +115,7 @@ impl LogArgs {
115115
}
116116

117117
/// Initializes tracing with the configured options from cli args.
118-
pub fn init_tracing(&self) -> eyre::Result<Option<FileWorkerGuard>> {
118+
pub(crate) fn init_tracing(&self) -> eyre::Result<Option<FileWorkerGuard>> {
119119
let mut tracer = HeimdallTracer::new();
120120

121121
let stdout = self.layer(self.log_stdout_format, self.log_stdout_filter.clone(), true);
@@ -132,7 +132,7 @@ impl LogArgs {
132132

133133
/// The color mode for the cli.
134134
#[derive(Debug, Copy, Clone, ValueEnum, Eq, PartialEq)]
135-
pub enum ColorMode {
135+
pub(crate) enum ColorMode {
136136
/// Colors on
137137
Always,
138138
/// Colors on
@@ -167,7 +167,7 @@ impl FromStr for ColorMode {
167167
/// The verbosity settings for the cli.
168168
#[derive(Debug, Copy, Clone, Args)]
169169
#[clap(next_help_heading = "DISPLAY")]
170-
pub struct Verbosity {
170+
pub(crate) struct Verbosity {
171171
/// Set the minimum log level.
172172
///
173173
/// -v Warnings & Errors
@@ -185,7 +185,7 @@ pub struct Verbosity {
185185
impl Verbosity {
186186
/// Get the corresponding [Directive] for the given verbosity, or none if the verbosity
187187
/// corresponds to silent.
188-
pub fn directive(&self) -> Directive {
188+
pub(crate) fn directive(&self) -> Directive {
189189
if self.quiet {
190190
LevelFilter::OFF.into()
191191
} else {

crates/cli/src/main.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! The Heimdall CLI is a command line interface for interacting with Heimdall modules.
2+
13
pub(crate) mod args;
24
pub(crate) mod output;
35

crates/cli/src/output.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use heimdall_common::ether::rpc;
1010
/// - if `target` is a contract_address, return `/output/{chain_id}/{target}/{filename}`
1111
/// - if `target` is a file or raw bytes, return `/output/local/{filename}`
1212
/// - if `output` is specified, return `/{output}/{filename}`
13-
pub async fn build_output_path(
13+
pub(crate) async fn build_output_path(
1414
output: &str,
1515
target: &str,
1616
rpc_url: &str,
@@ -38,7 +38,7 @@ pub async fn build_output_path(
3838
}
3939

4040
/// pass the input to the `less` command
41-
pub async fn print_with_less(input: &str) -> Result<()> {
41+
pub(crate) async fn print_with_less(input: &str) -> Result<()> {
4242
let mut child =
4343
std::process::Command::new("less").stdin(std::process::Stdio::piped()).spawn()?;
4444

crates/common/src/ether/bytecode.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! Functions for working with Ethereum bytecode.
2+
13
use crate::utils::strings::decode_hex;
24

35
use super::rpc::get_code;

crates/common/src/ether/calldata.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! Module for fetching calldata from a target.
2+
13
use super::rpc::get_transaction;
24
use crate::utils::strings::decode_hex;
35
use alloy::primitives::TxHash;

crates/common/src/ether/compiler.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
1+
//! Module for compiler detection.
2+
13
use std::fmt::Display;
24

35
use crate::{ether::bytecode::remove_pushbytes_from_bytecode, utils::iter::ByteSliceExt};
46
use tracing::{debug, trace, warn};
57

6-
#[derive(Debug, PartialEq, Clone)]
8+
/// Compiler enum to represent the compiler used to compile the contract.
9+
#[derive(Debug, PartialEq, Eq, Clone)]
710
pub enum Compiler {
11+
/// Indicates that the contract was compiled using the Solidity compiler.
812
Solc,
13+
/// Indicates that the contract was compiled using the Vyper compiler.
914
Vyper,
15+
/// Indicates that the contract is a minimal proxy.
1016
Proxy,
17+
/// Indicates that the compiler could not be detected.
1118
Unknown,
1219
}
1320

crates/common/src/ether/provider.rs

+13
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,19 @@ use std::{fmt::Debug, str::FromStr};
1818
/// supported by the [`Provider`].
1919
#[derive(Clone, Debug)]
2020
pub enum MultiTransportProvider {
21+
/// WebSocket transport
2122
Ws(RootProvider<PubSubFrontend, Ethereum>),
23+
/// IPC transport
2224
Ipc(RootProvider<PubSubFrontend, Ethereum>),
25+
/// HTTP transport
2326
Http(RootProvider<Http<Client>, Ethereum>),
2427
}
2528

2629
// We implement a convenience "constructor" method, to easily initialize the transport.
2730
// This will connect to [`Http`] if the rpc_url contains 'http', to [`Ws`] if it contains 'ws',
2831
// otherwise it'll default to [`Ipc`].
2932
impl MultiTransportProvider {
33+
/// Connect to a provider using the given rpc_url.
3034
pub async fn connect(rpc_url: &str) -> Result<Self> {
3135
if rpc_url.is_empty() {
3236
return Err(eyre::eyre!("No RPC URL provided"));
@@ -45,6 +49,7 @@ impl MultiTransportProvider {
4549
Ok(this)
4650
}
4751

52+
/// Get the chain id.
4853
pub async fn get_chainid(&self) -> Result<u64> {
4954
Ok(match self {
5055
Self::Ws(provider) => provider.get_chain_id().await?,
@@ -53,6 +58,7 @@ impl MultiTransportProvider {
5358
})
5459
}
5560

61+
/// Get the latest block number.
5662
pub async fn get_block_number(&self) -> Result<u64> {
5763
Ok(match self {
5864
Self::Ws(provider) => provider.get_block_number().await?,
@@ -61,6 +67,7 @@ impl MultiTransportProvider {
6167
})
6268
}
6369

70+
/// Get the bytecode at the given address.
6471
pub async fn get_code_at(&self, address: Address) -> Result<Vec<u8>> {
6572
Ok(match self {
6673
Self::Ws(provider) => provider.get_code_at(address).await?,
@@ -70,6 +77,7 @@ impl MultiTransportProvider {
7077
.to_vec())
7178
}
7279

80+
/// Get the transaction by hash.
7381
pub async fn get_transaction_by_hash(&self, tx_hash: TxHash) -> Result<Option<Transaction>> {
7482
Ok(match self {
7583
Self::Ws(provider) => provider.get_transaction_by_hash(tx_hash).await?,
@@ -78,6 +86,8 @@ impl MultiTransportProvider {
7886
})
7987
}
8088

89+
/// Replays the transaction at the given hash.
90+
/// The `trace_type` parameter is a list of the types of traces to return.
8191
pub async fn trace_replay_transaction(
8292
&self,
8393
tx_hash: &str,
@@ -92,6 +102,8 @@ impl MultiTransportProvider {
92102
})
93103
}
94104

105+
/// Replays the block at the given number.
106+
/// The `trace_type` parameter is a list of the types of traces to return.
95107
pub async fn trace_replay_block_transactions(
96108
&self,
97109
block_number: u64,
@@ -112,6 +124,7 @@ impl MultiTransportProvider {
112124
})
113125
}
114126

127+
/// Get the logs that match the given filter.
115128
pub async fn get_logs(&self, filter: &Filter) -> Result<Vec<Log>> {
116129
Ok(match self {
117130
Self::Ws(provider) => provider.get_logs(filter).await?,

crates/common/src/ether/rpc.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! RPC utilities for interacting with Ethereum nodes
2+
13
use crate::ether::provider::MultiTransportProvider;
24
use alloy::{
35
eips::BlockNumberOrTag,

crates/common/src/ether/signatures.rs

+26-4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
//! This module contains the logic for resolving signatures from
2+
//! 4-byte function selector or a 32-byte event selector.
3+
14
use std::path::PathBuf;
25

36
use alloy_dyn_abi::{DynSolType, DynSolValue};
@@ -19,16 +22,23 @@ use tracing::{debug, trace};
1922

2023
use super::types::DynSolValueExt;
2124

25+
/// A resolved function signature. May contain decoded inputs.
2226
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
2327
pub struct ResolvedFunction {
28+
/// The name of the function. For example, `transfer`.
2429
pub name: String,
30+
/// The function signature. For example, `transfer(address,uint256)`.
2531
pub signature: String,
32+
/// The inputs of the function. For example, `["address", "uint256"]`.
2633
pub inputs: Vec<String>,
34+
/// The decoded inputs of the function. For example, `[DynSolValue::Address("0x1234"),
35+
/// DynSolValue::Uint(123)]`.
2736
#[serde(skip)]
2837
pub decoded_inputs: Option<Vec<DynSolValue>>,
2938
}
3039

3140
impl ResolvedFunction {
41+
/// Returns the inputs of the function as a vector of [`DynSolType`]s.
3242
pub fn inputs(&self) -> Vec<DynSolType> {
3343
parse_function_parameters(&self.signature).expect("invalid signature")
3444
}
@@ -59,34 +69,45 @@ impl ResolvedFunction {
5969
}
6070
}
6171

62-
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
72+
/// A resolved error signature.
73+
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
6374
pub struct ResolvedError {
75+
/// The name of the error. For example, `revert`.
6476
pub name: String,
77+
/// The error signature. For example, `revert(string)`.
6578
pub signature: String,
79+
/// The inputs of the error. For example, `["string"]`.
6680
pub inputs: Vec<String>,
6781
}
6882

6983
impl ResolvedError {
84+
/// Returns the inputs of the error as a vector of [`DynSolType`]s.
7085
pub fn inputs(&self) -> Vec<DynSolType> {
7186
parse_function_parameters(&self.signature).expect("invalid signature")
7287
}
7388
}
74-
75-
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
89+
/// A resolved log signature.
90+
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
7691
pub struct ResolvedLog {
92+
/// The name of the log. For example, `Transfer`.
7793
pub name: String,
94+
/// The log signature. For example, `Transfer(address,address,uint256)`.
7895
pub signature: String,
96+
/// The inputs of the log. For example, `["address", "address", "uint256"]`.
7997
pub inputs: Vec<String>,
8098
}
8199

82100
impl ResolvedLog {
101+
/// Returns the inputs of the log as a vector of [`DynSolType`]s.
83102
pub fn inputs(&self) -> Vec<DynSolType> {
84103
parse_function_parameters(&self.signature).expect("invalid signature")
85104
}
86105
}
87-
106+
/// A trait for resolving a selector into a vector of [`ResolvedFunction`]s, [`ResolvedError`]s, or
88107
#[async_trait]
89108
pub trait ResolveSelector {
109+
/// Resolves a selector into a vector of [`ResolvedFunction`]s, [`ResolvedError`]s, or
110+
/// [`ResolvedLog`]s.
90111
async fn resolve(selector: &str) -> Result<Option<Vec<Self>>>
91112
where
92113
Self: Sized;
@@ -356,6 +377,7 @@ pub fn cache_signatures_from_abi(path: PathBuf) -> Result<()> {
356377
Ok(())
357378
}
358379

380+
/// Heuristic to score a function signature based on its spamminess.
359381
pub fn score_signature(signature: &str, num_words: Option<usize>) -> u32 {
360382
// the score starts at 1000
361383
let mut score = 1000;

0 commit comments

Comments
 (0)