@@ -22,6 +22,7 @@ use stacks_common::util::hash::Sha256Sum;
22
22
use crate :: burnchains:: Burnchain ;
23
23
use crate :: chainstate:: burn:: db:: sortdb:: SortitionDB ;
24
24
use crate :: chainstate:: coordinator:: OnChainRewardSetProvider ;
25
+ use crate :: chainstate:: nakamoto:: NakamotoChainState ;
25
26
use crate :: chainstate:: stacks:: boot:: {
26
27
PoxVersions , RewardSet , POX_1_NAME , POX_2_NAME , POX_3_NAME , POX_4_NAME ,
27
28
} ;
@@ -53,38 +54,6 @@ pub struct GetSignerResponse {
53
54
pub blocks_signed : u64 ,
54
55
}
55
56
56
- pub enum GetSignerErrors {
57
- NotAvailableYet ( crate :: chainstate:: coordinator:: Error ) ,
58
- Other ( String ) ,
59
- }
60
-
61
- impl GetSignerErrors {
62
- pub const NOT_AVAILABLE_ERR_TYPE : & ' static str = "not_available_try_again" ;
63
- pub const OTHER_ERR_TYPE : & ' static str = "other" ;
64
-
65
- pub fn error_type_string ( & self ) -> & ' static str {
66
- match self {
67
- Self :: NotAvailableYet ( _) => Self :: NOT_AVAILABLE_ERR_TYPE ,
68
- Self :: Other ( _) => Self :: OTHER_ERR_TYPE ,
69
- }
70
- }
71
- }
72
-
73
- impl From < & str > for GetSignerErrors {
74
- fn from ( value : & str ) -> Self {
75
- GetSignerErrors :: Other ( value. into ( ) )
76
- }
77
- }
78
-
79
- impl std:: fmt:: Display for GetSignerErrors {
80
- fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
81
- match self {
82
- GetSignerErrors :: NotAvailableYet ( e) => write ! ( f, "Could not read reward set. Prepare phase may not have started for this cycle yet. Err = {e:?}" ) ,
83
- GetSignerErrors :: Other ( msg) => write ! ( f, "{msg}" )
84
- }
85
- }
86
- }
87
-
88
57
/// Decode the HTTP request
89
58
impl HttpRequest for GetSignerRequestHandler {
90
59
fn verb ( & self ) -> & ' static str {
@@ -128,12 +97,12 @@ impl HttpRequest for GetSignerRequestHandler {
128
97
) ) ;
129
98
} ;
130
99
131
- let cycle_num = u64:: from_str_radix ( cycle_num_str. into ( ) , 10 )
132
- . map_err ( |e| Error :: DecodeError ( format ! ( "Failed to parse cycle number: {e}" ) ) ) ?;
133
-
134
100
let signer_pubkey = Secp256k1PublicKey :: from_hex ( signer_pubkey_str. into ( ) )
135
101
. map_err ( |e| Error :: DecodeError ( format ! ( "Failed to signer public key: {e}" ) ) ) ?;
136
102
103
+ let cycle_num = u64:: from_str_radix ( cycle_num_str. into ( ) , 10 )
104
+ . map_err ( |e| Error :: DecodeError ( format ! ( "Failed to parse cycle number: {e}" ) ) ) ?;
105
+
137
106
self . signer_pubkey = Some ( signer_pubkey) ;
138
107
self . reward_cycle = Some ( cycle_num) ;
139
108
@@ -152,16 +121,9 @@ impl RPCRequestHandler for GetSignerRequestHandler {
152
121
fn try_handle_request (
153
122
& mut self ,
154
123
preamble : HttpRequestPreamble ,
155
- contents : HttpRequestContents ,
124
+ _contents : HttpRequestContents ,
156
125
node : & mut StacksNodeState ,
157
126
) -> Result < ( HttpResponsePreamble , HttpResponseContents ) , NetError > {
158
- let tip = match node. load_stacks_chain_tip ( & preamble, & contents) {
159
- Ok ( tip) => tip,
160
- Err ( error_resp) => {
161
- return error_resp. try_into_contents ( ) . map_err ( NetError :: from) ;
162
- }
163
- } ;
164
-
165
127
let signer_pubkey = self
166
128
. signer_pubkey
167
129
. take ( )
@@ -172,13 +134,12 @@ impl RPCRequestHandler for GetSignerRequestHandler {
172
134
. take ( )
173
135
. ok_or ( NetError :: SendError ( "Missing `reward_cycle`" . into ( ) ) ) ?;
174
136
175
- let result = node. with_node_state ( |_network, _sortdb, _chainstate, _mempool, _rpc_args| {
176
- // TODO
177
- if true {
178
- Ok ( 0u64 )
179
- } else {
180
- Err ( "Something went wrong" )
181
- }
137
+ let result = node. with_node_state ( |_network, _sortdb, chainstate, _mempool, _rpc_args| {
138
+ NakamotoChainState :: get_signer_block_count (
139
+ & chainstate. index_conn ( ) ,
140
+ & signer_pubkey,
141
+ reward_cycle,
142
+ )
182
143
} ) ;
183
144
184
145
let response = match result {
@@ -238,31 +199,3 @@ impl StacksHttpResponse {
238
199
Ok ( response)
239
200
}
240
201
}
241
-
242
- #[ cfg( test) ]
243
- mod test {
244
- use super :: GetSignerErrors ;
245
-
246
- #[ test]
247
- // Test the formatting and error type strings of GetSignerErrors
248
- fn get_signer_errors ( ) {
249
- let not_available_err = GetSignerErrors :: NotAvailableYet (
250
- crate :: chainstate:: coordinator:: Error :: PoXNotProcessedYet ,
251
- ) ;
252
- let other_err = GetSignerErrors :: Other ( "foo" . into ( ) ) ;
253
-
254
- assert_eq ! (
255
- not_available_err. error_type_string( ) ,
256
- GetSignerErrors :: NOT_AVAILABLE_ERR_TYPE
257
- ) ;
258
- assert_eq ! (
259
- other_err. error_type_string( ) ,
260
- GetSignerErrors :: OTHER_ERR_TYPE
261
- ) ;
262
-
263
- assert ! ( not_available_err
264
- . to_string( )
265
- . starts_with( "Could not read reward set" ) ) ;
266
- assert_eq ! ( other_err. to_string( ) , "foo" . to_string( ) ) ;
267
- }
268
- }
0 commit comments