Skip to content

Commit e0aeee2

Browse files
authored
Merge pull request #283 from AdExNetwork/update-eth_checksum
Move `eth_checksum` to primitives
2 parents 0c216c9 + e303503 commit e0aeee2

File tree

7 files changed

+34
-6
lines changed

7 files changed

+34
-6
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

adview-manager/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ pub fn apply_selection(campaigns: &[MarketChannel], options: &AdViewManagerOptio
154154
}
155155

156156
fn is_video(ad_unit: &AdUnit) -> bool {
157-
ad_unit.media_mime.split('/').nth(0) == Some("video")
157+
ad_unit.media_mime.split('/').next() == Some("video")
158158
}
159159

160160
fn calculate_target_score(a: &[TargetingTag], b: &[TargetingTag]) -> TargetingScore {

primitives/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ time = "0.1.42"
2525
hex = "0.3.2"
2626
merkletree = "0.10.0"
2727
tiny-keccak = "1.5"
28-
eth_checksum = "0.1.1"
28+
rust-crypto = "0.2"
2929
# Numbers - BigNum, Numbers, Traits and Derives
3030
num-bigint = { version = "0.2", features = ["serde"] }
3131
num = "0.2.0"

primitives/src/big_num.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use std::convert::TryFrom;
2-
use std::error::Error;
32
use std::iter::Sum;
43
use std::ops::{Add, AddAssign, Div, Mul, Sub};
54
use std::str::FromStr;
@@ -195,7 +194,7 @@ impl TryFrom<&str> for BigNum {
195194

196195
fn try_from(num: &str) -> Result<Self, Self::Error> {
197196
let big_uint = BigUint::from_str(&num)
198-
.map_err(|err| super::DomainError::InvalidArgument(err.description().to_string()))?;
197+
.map_err(|err| super::DomainError::InvalidArgument(err.to_string()))?;
199198

200199
Ok(Self(big_uint))
201200
}

primitives/src/eth_checksum.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
use crypto::{digest::Digest, sha3::Sha3};
2+
3+
pub fn checksum(address: &str) -> String {
4+
let address = address.trim_start_matches("0x").to_lowercase();
5+
6+
let address_hash = {
7+
let mut hasher = Sha3::keccak256();
8+
hasher.input(address.as_bytes());
9+
hasher.result_str()
10+
};
11+
12+
address
13+
.char_indices()
14+
.fold(String::from("0x"), |mut acc, (index, address_char)| {
15+
// this cannot fail since it's Keccak256 hashed
16+
let n = u16::from_str_radix(&address_hash[index..index + 1], 16).unwrap();
17+
18+
if n > 7 {
19+
// make char uppercase if ith character is 9..f
20+
acc.push_str(&address_char.to_uppercase().to_string())
21+
} else {
22+
// already lowercased
23+
acc.push(address_char)
24+
}
25+
26+
acc
27+
})
28+
}

primitives/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ pub mod util {
2424
pub mod logging;
2525
}
2626
pub mod analytics;
27+
mod eth_checksum;
2728
pub mod validator;
2829

2930
pub use self::ad_unit::AdUnit;

sentry/src/middleware/auth.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ fn get_request_ip(req: &Request<Body>) -> Option<String> {
8383
.get("true-client-ip")
8484
.or_else(|| req.headers().get("x-forwarded-for"))
8585
.and_then(|hv| hv.to_str().map(ToString::to_string).ok())
86-
.map(|token| token.split(',').nth(0).map(ToString::to_string))
86+
.map(|token| token.split(',').next().map(ToString::to_string))
8787
.flatten()
8888
}
8989

0 commit comments

Comments
 (0)