@@ -10,8 +10,10 @@ pub type Funds = Decimal;
10
10
pub type Rewards = Decimal ;
11
11
pub type VoteCount = HashMap < Identifier , HashSet < Hash > > ;
12
12
13
+ use chain_impl_mockchain:: certificate:: ExternalProposalId ;
13
14
use jormungandr_lib:: crypto:: { account:: Identifier , hash:: Hash } ;
14
15
use std:: collections:: { HashMap , HashSet } ;
16
+ use std:: str:: FromStr ;
15
17
use thiserror:: Error ;
16
18
use vit_servicing_station_lib:: db:: models:: proposals:: FullProposalInfo ;
17
19
@@ -36,9 +38,16 @@ impl Threshold {
36
38
let proposals = proposals
37
39
. into_iter ( )
38
40
. 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) ) )
42
51
} )
43
52
. collect :: < Result < Vec < _ > , Error > > ( ) ?;
44
53
Ok ( Self {
0 commit comments