@@ -19,7 +19,7 @@ use std::net::SocketAddr;
19
19
use blockstack_lib:: burnchains:: Txid ;
20
20
use blockstack_lib:: chainstate:: nakamoto:: NakamotoBlock ;
21
21
use blockstack_lib:: chainstate:: stacks:: boot:: {
22
- NakamotoSignerEntry , SIGNERS_VOTING_FUNCTION_NAME , SIGNERS_VOTING_NAME ,
22
+ NakamotoSignerEntry , SIGNERS_NAME , SIGNERS_VOTING_FUNCTION_NAME , SIGNERS_VOTING_NAME ,
23
23
} ;
24
24
use blockstack_lib:: chainstate:: stacks:: db:: StacksBlockHeaderTypes ;
25
25
use blockstack_lib:: chainstate:: stacks:: {
@@ -162,6 +162,20 @@ impl StacksClient {
162
162
Ok ( sortition_info)
163
163
}
164
164
165
+ /// Get the last set reward cycle stored within the stackerdb contract
166
+ pub fn get_last_set_cycle ( & self ) -> Result < u128 , ClientError > {
167
+ let signer_stackerdb_contract_id = boot_code_id ( SIGNERS_NAME , self . mainnet ) ;
168
+ let function_name_str = "get-last-set-cycle" ;
169
+ let function_name = ClarityName :: from ( function_name_str) ;
170
+ let value = self . read_only_contract_call (
171
+ & signer_stackerdb_contract_id. issuer . clone ( ) . into ( ) ,
172
+ & signer_stackerdb_contract_id. name ,
173
+ & function_name,
174
+ & [ ] ,
175
+ ) ?;
176
+ Ok ( value. expect_result_ok ( ) ?. expect_u128 ( ) ?)
177
+ }
178
+
165
179
/// Retrieve the signer slots stored within the stackerdb contract
166
180
pub fn get_stackerdb_signer_slots (
167
181
& self ,
@@ -962,11 +976,11 @@ mod tests {
962
976
use super :: * ;
963
977
use crate :: client:: tests:: {
964
978
build_account_nonce_response, build_get_approved_aggregate_key_response,
965
- build_get_last_round_response, build_get_medium_estimated_fee_ustx_response ,
966
- build_get_peer_info_response , build_get_pox_data_response , build_get_round_info_response ,
967
- build_get_tenure_tip_response , build_get_vote_for_aggregate_key_response ,
968
- build_get_weight_threshold_response , build_read_only_response , write_response ,
969
- MockServerClient ,
979
+ build_get_last_round_response, build_get_last_set_cycle_response ,
980
+ build_get_medium_estimated_fee_ustx_response , build_get_peer_info_response ,
981
+ build_get_pox_data_response , build_get_round_info_response , build_get_tenure_tip_response ,
982
+ build_get_vote_for_aggregate_key_response , build_get_weight_threshold_response ,
983
+ build_read_only_response , write_response , MockServerClient ,
970
984
} ;
971
985
972
986
#[ test]
@@ -1623,4 +1637,14 @@ mod tests {
1623
1637
write_response ( mock. server , response. as_bytes ( ) ) ;
1624
1638
assert_eq ! ( h. join( ) . unwrap( ) . unwrap( ) , header) ;
1625
1639
}
1640
+
1641
+ #[ test]
1642
+ fn get_last_set_cycle_should_succeed ( ) {
1643
+ let mock = MockServerClient :: new ( ) ;
1644
+ let reward_cycle = thread_rng ( ) . next_u64 ( ) ;
1645
+ let response = build_get_last_set_cycle_response ( reward_cycle) ;
1646
+ let h = spawn ( move || mock. client . get_last_set_cycle ( ) ) ;
1647
+ write_response ( mock. server , response. as_bytes ( ) ) ;
1648
+ assert_eq ! ( h. join( ) . unwrap( ) . unwrap( ) , reward_cycle as u128 ) ;
1649
+ }
1626
1650
}
0 commit comments