@@ -10,9 +10,11 @@ use crate::error::{Result, SpvError};
1010use crate :: network:: NetworkManager ;
1111use crate :: storage:: StorageManager ;
1212use crate :: types:: AddressBalance ;
13+ use dashcore:: sml:: llmq_type:: LLMQType ;
1314use dashcore:: sml:: masternode_list:: MasternodeList ;
1415use dashcore:: sml:: masternode_list_engine:: MasternodeListEngine ;
1516use dashcore:: sml:: quorum_entry:: qualified_quorum_entry:: QualifiedQuorumEntry ;
17+ use dashcore:: QuorumHash ;
1618use key_wallet_manager:: wallet_interface:: WalletInterface ;
1719
1820use super :: DashSpvClient ;
@@ -73,45 +75,32 @@ impl<
7375 pub fn get_quorum_at_height (
7476 & self ,
7577 height : u32 ,
76- quorum_type : u8 ,
77- quorum_hash : & [ u8 ; 32 ] ,
78- ) -> Option < & QualifiedQuorumEntry > {
79- use dashcore:: sml:: llmq_type:: LLMQType ;
80- use dashcore:: QuorumHash ;
81- use dashcore_hashes:: Hash ;
82-
83- let llmq_type: LLMQType = LLMQType :: from ( quorum_type) ;
84- if llmq_type == LLMQType :: LlmqtypeUnknown {
85- tracing:: warn!( "Invalid quorum type {} requested at height {}" , quorum_type, height) ;
86- return None ;
87- } ;
88-
89- let qhash = QuorumHash :: from_byte_array ( * quorum_hash) ;
90-
78+ quorum_type : LLMQType ,
79+ quorum_hash : QuorumHash ,
80+ ) -> Result < QualifiedQuorumEntry > {
9181 // First check if we have the masternode list at this height
9282 match self . get_masternode_list_at_height ( height) {
9383 Some ( ml) => {
9484 // We have the masternode list, now look for the quorum
95- match ml. quorums . get ( & llmq_type ) {
96- Some ( quorums) => match quorums. get ( & qhash ) {
85+ match ml. quorums . get ( & quorum_type ) {
86+ Some ( quorums) => match quorums. get ( & quorum_hash ) {
9787 Some ( quorum) => {
9888 tracing:: debug!(
9989 "Found quorum type {} at height {} with hash {}" ,
10090 quorum_type,
10191 height,
10292 hex:: encode( quorum_hash)
10393 ) ;
104- Some ( quorum)
94+ Ok ( quorum. clone ( ) )
10595 }
10696 None => {
107- tracing:: warn!(
108- "Quorum not found: type {} at height {} with hash {} (masternode list exists with {} quorums of this type)" ,
109- quorum_type,
110- height,
111- hex:: encode( quorum_hash) ,
112- quorums. len( )
113- ) ;
114- None
97+ let message = format ! ( "Quorum not found: type {} at height {} with hash {} (masternode list exists with {} quorums of this type)" ,
98+ quorum_type,
99+ height,
100+ hex:: encode( quorum_hash) ,
101+ quorums. len( ) ) ;
102+ tracing:: warn!( message) ;
103+ Err ( SpvError :: QuorumLookupError ( message) )
115104 }
116105 } ,
117106 None => {
@@ -120,7 +109,10 @@ impl<
120109 quorum_type,
121110 height
122111 ) ;
123- None
112+ Err ( SpvError :: QuorumLookupError ( format ! (
113+ "No quorums of type {} found at height {}" ,
114+ quorum_type, height
115+ ) ) )
124116 }
125117 }
126118 }
@@ -129,7 +121,10 @@ impl<
129121 "No masternode list found at height {} - cannot retrieve quorum" ,
130122 height
131123 ) ;
132- None
124+ Err ( SpvError :: QuorumLookupError ( format ! (
125+ "No masternode list found at height {}" ,
126+ height
127+ ) ) )
133128 }
134129 }
135130 }
0 commit comments