Learning Rust and Alloy-RS
use std::str::FromStr;
use alloy_primitives::{Address, U256};
pub fn checksum(address: &str) -> String {
match Address::from_str(address) {
Ok(addr) => addr.to_checksum(None),
Err(_) => {
tracing::error!("Invalid address: {}", address);
address.to_string()
}
}
}
use std::str::FromStr;
use alloy_primitives::{Address, U256};
pub fn checksum(address: &str) -> String {
Address::from_str(address)
.map(|addr| addr.to_checksum(None))
.unwrap_or_else(|_| {
tracing::error!("Invalid address: {}", address);
address.to_string()
})
}
------ checksum.rs
++++++ checksum.rs
@|-1,14 +1,13 ============================================================
|use std::str::FromStr;
|
|use alloy_primitives::{Address, U256};
|
|
|pub fn checksum(address: &str) -> String {
-| match Address::from_str(address) {
-| Ok(addr) => addr.to_checksum(None),
-| Err(_) => {
+| Address::from_str(address)
+| .map(|addr| addr.to_checksum(None))
+| .unwrap_or_else(|_| {
| tracing::error!("Invalid address: {}", address);
| address.to_string()
-| }
-| }
+| })
|}
pub fn hash_to_name(hash: &str) -> String {
if !hash.starts_with("0x0000") {
return hash[1..6].to_lowercase();
}
let len = hash.len();
let trimmed = hash.trim_start_matches("0x").trim_start_matches('0');
let trimmed = if trimmed.len() < 4 { &hash[len - 4..] } else { trimmed };
format!("x{}", &trimmed[..4].to_lowercase())
}
pub fn hash_to_name(hash: &str) -> String {
if !hash.starts_with("0x0000") {
return hash[1..6].to_lowercase();
}
let trimmed = hash.trim_start_matches("0x").trim_start_matches('0');
let slice = if trimmed.len() < 4 {
&hash[hash.len().saturating_sub(4)..]
} else {
&trimmed[..4]
};
format!("x{}", slice.to_lowercase())
}
This document contains a curated collection of software architecture principles, design philosophies, and engineering wisdom from various experts in the field.
May 29, 2025"The most profound economic changes come not from replacing existing players, but from transforming their roles and incentives within the ecosystem." — Vitalik Buterin
May 1, 2025[!WARNING] Rough Draft. This was all generated in claude chat: no IDE was harmed. see https://howardhinnant.github.io/date_algorithms.html#days_from_civil Days From Civil days_from_civil(Int y, unsigned m, unsigned d) noexcept { static_assert(std::numeric_limits<unsigned>::digits >= 18, "This algorithm has not been ported to a 16 bit unsigned integer");
Apr 17, 2025The design of these rules is to realize the following set of requirements:
Apr 1, 2025or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up