@@ -21,14 +21,21 @@ use iota_types::{
2121 governance:: StakedIota ,
2222 id:: ID ,
2323 iota_serde:: BigInt ,
24- iota_system_state:: { PoolTokenExchangeRate , iota_system_state_summary:: IotaSystemStateSummary } ,
24+ iota_system_state:: {
25+ PoolTokenExchangeRate ,
26+ iota_system_state_summary:: {
27+ IotaSystemStateSummary , IotaSystemStateSummaryV1 , IotaSystemStateSummaryV2 ,
28+ } ,
29+ } ,
2530 timelock:: timelocked_staked_iota:: TimelockedStakedIota ,
2631} ;
2732use jsonrpsee:: { RpcModule , core:: RpcResult } ;
2833use serde:: { Serialize , de:: DeserializeOwned } ;
2934use tokio:: sync:: Mutex ;
3035
31- use crate :: { errors:: IndexerError , indexer_reader:: IndexerReader } ;
36+ use crate :: {
37+ errors:: IndexerError , indexer_reader:: IndexerReader , types:: IotaSystemStateSummaryView ,
38+ } ;
3239
3340/// Maximum amount of staked objects for querying.
3441const MAX_QUERY_STAKED_OBJECTS : usize = 1000 ;
@@ -63,9 +70,8 @@ impl GovernanceReadApi {
6370 }
6471
6572 async fn get_validators_apy ( & self ) -> Result < ValidatorApys , IndexerError > {
66- let system_state_summary: IotaSystemStateSummary =
67- self . get_latest_iota_system_state ( ) . await ?;
68- let epoch = system_state_summary. epoch ;
73+ let system_state_summary = self . get_latest_iota_system_state ( ) . await ?;
74+ let epoch = system_state_summary. epoch ( ) ;
6975
7076 let exchange_rate_table = self . exchange_rates ( & system_state_summary) . await ?;
7177
@@ -170,7 +176,7 @@ impl GovernanceReadApi {
170176 } ) ;
171177
172178 let system_state_summary = self . get_latest_iota_system_state ( ) . await ?;
173- let epoch = system_state_summary. epoch ;
179+ let epoch = system_state_summary. epoch ( ) ;
174180
175181 let ( candidate_rates, pending_rates) = tokio:: try_join!(
176182 self . candidate_validators_exchange_rate( & system_state_summary) ,
@@ -236,7 +242,7 @@ impl GovernanceReadApi {
236242 } ) ;
237243
238244 let system_state_summary = self . get_latest_iota_system_state ( ) . await ?;
239- let epoch = system_state_summary. epoch ;
245+ let epoch = system_state_summary. epoch ( ) ;
240246
241247 let rates = self
242248 . exchange_rates ( & system_state_summary)
@@ -359,7 +365,7 @@ impl GovernanceReadApi {
359365 & self ,
360366 system_state_summary : & IotaSystemStateSummary ,
361367 ) -> Result < Vec < ValidatorExchangeRates > , IndexerError > {
362- let epoch = system_state_summary. epoch ;
368+ let epoch = system_state_summary. epoch ( ) ;
363369
364370 let mut cache = self . exchange_rates_cache . lock ( ) . await ;
365371
@@ -399,7 +405,7 @@ impl GovernanceReadApi {
399405 system_state_summary : & IotaSystemStateSummary ,
400406 ) -> Result < Vec < ValidatorExchangeRates > , IndexerError > {
401407 let tables = system_state_summary
402- . active_validators
408+ . active_validators ( )
403409 . iter ( )
404410 . map ( |validator| {
405411 (
@@ -422,8 +428,8 @@ impl GovernanceReadApi {
422428 ) -> Result < Vec < ValidatorExchangeRates > , IndexerError > {
423429 let tables = self
424430 . validator_summary_from_system_state (
425- system_state_summary. inactive_pools_id ,
426- system_state_summary. inactive_pools_size ,
431+ system_state_summary. inactive_pools_id ( ) ,
432+ system_state_summary. inactive_pools_size ( ) ,
427433 |df| bcs:: from_bytes :: < ID > ( & df. bcs_name ) . map_err ( Into :: into) ,
428434 )
429435 . await ?;
@@ -470,8 +476,8 @@ impl GovernanceReadApi {
470476 ) -> Result < Vec < ValidatorExchangeRates > , IndexerError > {
471477 let tables = self
472478 . validator_summary_from_system_state (
473- system_state_summary. validator_candidates_id ,
474- system_state_summary. validator_candidates_size ,
479+ system_state_summary. validator_candidates_id ( ) ,
480+ system_state_summary. validator_candidates_size ( ) ,
475481 |df| bcs:: from_bytes :: < IotaAddress > ( & df. bcs_name ) . map_err ( Into :: into) ,
476482 )
477483 . await ?;
@@ -502,9 +508,9 @@ impl GovernanceReadApi {
502508 /// let system_state_summary = self.get_latest_iota_system_state().await?;
503509 /// let _ = self.validator_summary_from_system_state(
504510 /// // ID of the object that maps from a staking pool ID to the inactive validator that has that pool as its staking pool
505- /// system_state_summary.inactive_pools_id,
511+ /// system_state_summary.inactive_pools_id() ,
506512 /// // Number of inactive staking pools
507- /// system_state_summary.inactive_pools_size,
513+ /// system_state_summary.inactive_pools_size() ,
508514 /// // Extract the `ID` of the `Inactive` validator from the `DynamicFieldInfo` in the `system_state_summary.inactive_pools_id` table
509515 /// |df| bcs::from_bytes::<ID>(&df.bcs_name).map_err(Into::into),
510516 /// ).await?;
@@ -517,9 +523,9 @@ impl GovernanceReadApi {
517523 /// let system_state_summary = self.get_latest_iota_system_state().await?;
518524 /// let _ = self.validator_summary_from_system_state(
519525 /// // ID of the object that stores preactive validators, mapping their addresses to their Validator structs
520- /// system_state_summary.validator_candidates_id,
526+ /// system_state_summary.validator_candidates_id() ,
521527 /// // Number of preactive validators
522- /// system_state_summary.validator_candidates_size,
528+ /// system_state_summary.validator_candidates_size() ,
523529 /// // Extract the `IotaAddress` of the `Candidate` validator from the `DynamicFieldInfo` in the `system_state_summary.validator_candidates_id` table
524530 /// |df| bcs::from_bytes::<IotaAddress>(&df.bcs_name).map_err(Into::into),
525531 /// ).await?;
@@ -683,10 +689,20 @@ impl GovernanceReadApiServer for GovernanceReadApi {
683689 Ok ( epoch. committee ( ) . map_err ( IndexerError :: from) ?. into ( ) )
684690 }
685691
686- async fn get_latest_iota_system_state ( & self ) -> RpcResult < IotaSystemStateSummary > {
687- self . get_latest_iota_system_state ( )
688- . await
689- . map_err ( Into :: into)
692+ async fn get_latest_iota_system_state ( & self ) -> RpcResult < IotaSystemStateSummaryV2 > {
693+ Ok ( self
694+ . get_latest_iota_system_state ( )
695+ . await ?
696+ . try_into ( )
697+ . map_err ( IndexerError :: from) ?)
698+ }
699+
700+ async fn get_latest_iota_system_state_v1 ( & self ) -> RpcResult < IotaSystemStateSummaryV1 > {
701+ Ok ( self
702+ . get_latest_iota_system_state ( )
703+ . await ?
704+ . try_into ( )
705+ . map_err ( IndexerError :: from) ?)
690706 }
691707
692708 async fn get_reference_gas_price ( & self ) -> RpcResult < BigInt < u64 > > {
0 commit comments