Skip to content

Commit 140bc51

Browse files
committed
fix: get_state_root_hash param
1 parent 6ff38bf commit 140bc51

File tree

2 files changed

+6
-11
lines changed

2 files changed

+6
-11
lines changed

adapter/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use ethabi::token::{LenientTokenizer, StrictTokenizer, Tokenizer};
1111
use hex::FromHex;
1212
use primitives::channel::ChannelError;
1313
use primitives::BigNum;
14-
use primitives::Channel;
14+
use primitives::{Channel, ValidatorId};
1515
use sha2::{Digest, Sha256};
1616
use std::convert::TryFrom;
1717
use tiny_keccak::Keccak;
@@ -46,9 +46,9 @@ pub fn get_signable_state_root(
4646
Ok(res)
4747
}
4848

49-
pub fn get_balance_leaf(acc: &[u8; 20], amnt: &BigNum) -> Result<[u8; 32], Box<dyn Error>> {
49+
pub fn get_balance_leaf(acc: &ValidatorId, amnt: &BigNum) -> Result<[u8; 32], Box<dyn Error>> {
5050
let params = [
51-
(ParamType::Address, &hex::encode(acc)[..]),
51+
(ParamType::Address, &acc.to_string()[..]),
5252
(ParamType::Uint(256), &amnt.to_str_radix(10)[..]),
5353
];
5454
let encoded = encode_params(&params, true)?;

validator_worker/src/lib.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
use std::error::Error;
55

66
use adapter::{get_balance_leaf, get_signable_state_root};
7-
use hex::FromHex;
87
use primitives::adapter::Adapter;
98
use primitives::merkle_tree::MerkleTree;
10-
use primitives::BalancesMap;
9+
use primitives::{BalancesMap, ValidatorId};
10+
use std::convert::TryFrom;
1111

1212
pub use self::sentry_interface::{all_channels, SentryApi};
1313

@@ -31,12 +31,7 @@ pub(crate) fn get_state_root_hash<A: Adapter + 'static>(
3131
// Note: MerkleTree takes care of deduplicating and sorting
3232
let elems: Vec<[u8; 32]> = balances
3333
.iter()
34-
.map(|(acc, amount)| {
35-
get_balance_leaf(
36-
&<[u8; 20]>::from_hex(&acc[2..]).expect("failed to unwrap ex"),
37-
amount,
38-
)
39-
})
34+
.map(|(acc, amount)| get_balance_leaf(&ValidatorId::try_from(acc.as_str())?, amount))
4035
.collect::<Result<_, _>>()?;
4136

4237
let tree = MerkleTree::new(&elems);

0 commit comments

Comments
 (0)