Skip to content

Commit b4e2a76

Browse files
Use alloy address validation instead of creating a method
1 parent c3017eb commit b4e2a76

File tree

1 file changed

+3
-10
lines changed
  • aggregation_mode/batcher/src/server

1 file changed

+3
-10
lines changed

aggregation_mode/batcher/src/server/http.rs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,6 @@ impl BatcherServer {
3535
Self { db, config }
3636
}
3737

38-
fn is_valid_eth_address(addr: &str) -> bool {
39-
let addr = addr.strip_prefix("0x").unwrap_or(addr);
40-
if addr.len() != 40 {
41-
return false;
42-
}
43-
addr.chars().all(|c| c.is_ascii_hexdigit())
44-
}
45-
4638
pub async fn start(&self) {
4739
// Note: BatcherServer is thread safe so we can just clone it (no need to add mutexes)
4840
let port = self.config.port;
@@ -71,7 +63,8 @@ impl BatcherServer {
7163
.json(AppResponse::new_unsucessfull("Missing address", 400));
7264
};
7365

74-
if !Self::is_valid_eth_address(address_raw) {
66+
// Check that the address is a valid ethereum address
67+
if !alloy::primitives::Address::from_str(address_raw.trim()).is_ok() {
7568
return HttpResponse::BadRequest()
7669
.json(AppResponse::new_unsucessfull("Invalid address", 400));
7770
}
@@ -225,7 +218,7 @@ impl BatcherServer {
225218

226219
let state = state.get_ref();
227220

228-
if !Self::is_valid_eth_address(&params.address.clone()) {
221+
if !alloy::primitives::Address::from_str(&params.address.clone().trim()).is_ok() {
229222
return HttpResponse::BadRequest()
230223
.json(AppResponse::new_unsucessfull("Invalid address", 400));
231224
}

0 commit comments

Comments
 (0)