-
Notifications
You must be signed in to change notification settings - Fork 111
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add RPC for
chain-state
module (#760)
* Add RPC endpoint for chain state module, so it can be plugged into runtime * Move tests to integration tests * Fix native feature gating * Fixed check features
- Loading branch information
1 parent
461a749
commit 9bcd69c
Showing
8 changed files
with
67 additions
and
59 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 8 additions & 33 deletions
41
module-system/module-implementations/sov-chain-state/src/query.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,19 @@ | ||
use jsonrpsee::core::RpcResult; | ||
use sov_modules_api::macros::rpc_gen; | ||
use sov_rollup_interface::zk::ValidityCondition; | ||
use sov_state::WorkingSet; | ||
|
||
use super::ChainState; | ||
use crate::{StateTransitionId, TransitionHeight, TransitionInProgress}; | ||
|
||
/// Structure returned by the query methods. | ||
pub struct Response { | ||
/// Value returned by the queries | ||
pub value: u64, | ||
} | ||
use crate::{ChainState, TransitionHeight}; | ||
|
||
#[rpc_gen(client, server, namespace = "chainState")] | ||
impl<C: sov_modules_api::Context, Cond: ValidityCondition> ChainState<C, Cond> { | ||
/// Get the height of the current slot. | ||
/// Panics if the slot height is not set | ||
pub fn get_slot_height(&self, working_set: &mut WorkingSet<C::Storage>) -> TransitionHeight { | ||
self.slot_height | ||
.get(working_set) | ||
.expect("Slot height should be set at initialization") | ||
} | ||
|
||
/// Return the genesis hash of the module. | ||
pub fn get_genesis_hash(&self, working_set: &mut WorkingSet<C::Storage>) -> Option<[u8; 32]> { | ||
self.genesis_hash.get(working_set) | ||
} | ||
|
||
/// Returns the transition in progress of the module. | ||
pub fn get_in_progress_transition( | ||
&self, | ||
working_set: &mut WorkingSet<C::Storage>, | ||
) -> Option<TransitionInProgress<Cond>> { | ||
self.in_progress_transition.get(working_set) | ||
} | ||
|
||
/// Returns the completed transition associated with the provided `transition_num`. | ||
pub fn get_historical_transitions( | ||
#[rpc_method(name = "getSlotHeight")] | ||
pub fn get_slot_height_rpc( | ||
&self, | ||
transition_num: TransitionHeight, | ||
working_set: &mut WorkingSet<C::Storage>, | ||
) -> Option<StateTransitionId<Cond>> { | ||
self.historical_transitions | ||
.get(&transition_num, working_set) | ||
) -> RpcResult<TransitionHeight> { | ||
Ok(self.get_slot_height(working_set)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters