-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
enha: simplify extraction of contract name and function signature (#1544
- Loading branch information
1 parent
db9fd53
commit 336b8af
Showing
10 changed files
with
74 additions
and
143 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,16 +1,29 @@ | ||
//! Auto-generated code. | ||
use crate::eth::primitives::Address; | ||
use crate::infra::metrics; | ||
|
||
include!(concat!(env!("OUT_DIR"), "/contracts.rs")); | ||
include!(concat!(env!("OUT_DIR"), "/signatures.rs")); | ||
|
||
pub type SoliditySignature = &'static str; | ||
|
||
pub type ContractName = &'static str; | ||
|
||
/// Returns the contract name for a given address. | ||
pub fn get_contract_name(address: &Address) -> ContractName { | ||
/// Returns the contract name to be used in observability tasks. | ||
pub fn contract_name_for_o11y(address: &Option<Address>) -> ContractName { | ||
let Some(address) = address else { return metrics::LABEL_MISSING }; | ||
match CONTRACTS.get(address.as_bytes()) { | ||
Some(contract_name) => contract_name, | ||
None => "unknown", | ||
None => metrics::LABEL_UNKNOWN, | ||
} | ||
} | ||
|
||
/// Returns the function name to be used in observability tasks. | ||
pub fn function_sig_for_o11y(bytes: impl AsRef<[u8]>) -> SoliditySignature { | ||
let Some(id) = bytes.as_ref().get(..4) else { return metrics::LABEL_MISSING }; | ||
match SIGNATURES_4_BYTES.get(id) { | ||
Some(signature) => signature, | ||
None => metrics::LABEL_UNKNOWN, | ||
} | ||
} |
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
This file was deleted.
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
Oops, something went wrong.