Skip to content

Commit 15609b4

Browse files
authored
Merge pull request #231 from AdExNetwork/fee-addr-and-testfix
feeAddr + casing fixes
2 parents 72f5be4 + b86be55 commit 15609b4

File tree

6 files changed

+12
-8
lines changed

6 files changed

+12
-8
lines changed

adapter/src/dummy.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ impl Adapter for DummyAdapter {
4343
let signature = format!(
4444
"Dummy adapter signature for {} by {}",
4545
state_root,
46-
self.whoami()
46+
self.whoami().to_hex_checksummed_string()
4747
);
4848
Ok(signature)
4949
}
@@ -57,7 +57,7 @@ impl Adapter for DummyAdapter {
5757
// select the `identity` and compare it to the signer
5858
// for empty string this will return array with 1 element - an empty string `[""]`
5959
let is_same = match signature.rsplit(' ').take(1).next() {
60-
Some(from) => from == signer.to_string(),
60+
Some(from) => from == signer.to_hex_checksummed_string(),
6161
None => false,
6262
};
6363

adapter/src/ethereum.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,7 @@ mod test {
547547
.expect("failed to create id"),
548548
url: "http://localhost:8005".to_string(),
549549
fee: 100.into(),
550+
fee_addr: None,
550551
};
551552

552553
let follower_validator_desc = ValidatorDesc {
@@ -555,6 +556,7 @@ mod test {
555556
.expect("failed to create id"),
556557
url: "http://localhost:8006".to_string(),
557558
fee: 100.into(),
559+
fee_addr: None,
558560
};
559561

560562
let mut valid_channel = Channel {

primitives/src/util/tests/prep_db.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,14 @@ lazy_static! {
4545
id: ValidatorId::try_from("ce07CbB7e054514D590a0262C93070D838bFBA2e").expect("Failed to parse DUMMY_VALIDATOR_LEADER id "),
4646
url: "http://localhost:8005".to_string(),
4747
fee: 100.into(),
48+
fee_addr: None,
4849
};
4950

5051
pub static ref DUMMY_VALIDATOR_FOLLOWER: ValidatorDesc = ValidatorDesc {
5152
id: ValidatorId::try_from("c91763d7f14ac5c5ddfbcd012e0d2a61ab9bded3").expect("Failed to parse DUMMY_VALIDATOR_FOLLOWER id "),
5253
url: "http://localhost:8006".to_string(),
5354
fee: 100.into(),
55+
fee_addr: None,
5456
};
5557

5658
pub static ref DUMMY_CHANNEL: Channel = {

primitives/src/validator.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ impl ValidatorId {
2828
}
2929

3030
pub fn to_hex_checksummed_string(&self) -> String {
31-
eth_checksum::checksum(&format!("0x{}", hex::encode(self.0)))
31+
eth_checksum::checksum(&format!("0x{}", self.to_hex_non_prefix_string()))
3232
}
3333
}
3434

@@ -79,14 +79,15 @@ impl TryFrom<&String> for ValidatorId {
7979

8080
impl fmt::Display for ValidatorId {
8181
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
82-
write!(f, "{}", format!("0x{}", hex::encode(self.0)))
82+
write!(f, "{}", format!("0x{}", self.to_hex_non_prefix_string()))
8383
}
8484
}
8585

8686
#[derive(Serialize, Deserialize, Debug, Clone)]
8787
#[serde(rename_all = "camelCase")]
8888
pub struct ValidatorDesc {
8989
pub id: ValidatorId,
90+
pub fee_addr: Option<ValidatorId>,
9091
pub url: String,
9192
pub fee: BigNum,
9293
}

validator_worker/src/core/fees.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,8 @@ fn distribute_fee<'a>(
7676
};
7777

7878
if fee_rounded > 0.into() {
79-
let entry = balances
80-
.entry(validator.id.to_string())
81-
.or_insert_with(|| 0.into());
79+
let addr = validator.fee_addr.as_ref().unwrap_or(&validator.id);
80+
let entry = balances.entry(addr.to_string()).or_insert_with(|| 0.into());
8281

8382
*entry += &fee_rounded;
8483
}

validator_worker/src/sentry_interface.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ impl<T: Adapter + 'static> SentryApi<T> {
9696
let url = format!(
9797
"{}/validator-messages/{}/{}?limit=1",
9898
self.validator_url,
99-
from.to_string(),
99+
from.to_hex_checksummed_string(),
100100
message_type
101101
);
102102
let result = self

0 commit comments

Comments
 (0)