@@ -10,8 +10,10 @@ pub type Funds = Decimal;
1010pub type Rewards = Decimal ;
1111pub type VoteCount = HashMap < Identifier , HashSet < Hash > > ;
1212
13+ use chain_impl_mockchain:: certificate:: ExternalProposalId ;
1314use jormungandr_lib:: crypto:: { account:: Identifier , hash:: Hash } ;
1415use std:: collections:: { HashMap , HashSet } ;
16+ use std:: str:: FromStr ;
1517use thiserror:: Error ;
1618use vit_servicing_station_lib:: db:: models:: proposals:: FullProposalInfo ;
1719
@@ -36,9 +38,16 @@ impl Threshold {
3638 let proposals = proposals
3739 . into_iter ( )
3840 . map ( |p| {
39- <[ u8 ; 32 ] >:: try_from ( p. proposal . chain_proposal_id )
40- . map_err ( Error :: InvalidHash )
41- . map ( |hash| ( p. proposal . challenge_id , Hash :: from ( hash) ) )
41+ // the chain_proposal_id comes as hex-encoded string digest of a blake2b256 key
42+ // the first step is to decode the &str
43+ let chain_proposal_str = std:: str:: from_utf8 ( & p. proposal . chain_proposal_id )
44+ . map_err ( |_| Error :: InvalidHash ( p. proposal . chain_proposal_id . clone ( ) ) ) ?;
45+ // second step is to convert &str into a digest so that it can be converted into
46+ // [u8;32]
47+ let chain_proposal_id = ExternalProposalId :: from_str ( chain_proposal_str)
48+ . map_err ( |_| Error :: InvalidHash ( p. proposal . chain_proposal_id . clone ( ) ) ) ?;
49+ let bytes: [ u8 ; 32 ] = chain_proposal_id. into ( ) ;
50+ Ok ( ( p. proposal . challenge_id , Hash :: from ( bytes) ) )
4251 } )
4352 . collect :: < Result < Vec < _ > , Error > > ( ) ?;
4453 Ok ( Self {
0 commit comments