openmina_node_common/service/rpc/
transition_frontier.rs1#[cfg(target_family = "wasm")]
2use gloo_utils::format::JsValueSerdeExt;
3use node::rpc::*;
4#[cfg(target_family = "wasm")]
5use wasm_bindgen::prelude::*;
6
7use super::RpcSender;
8
9#[derive(Clone)]
10#[cfg_attr(target_family = "wasm", wasm_bindgen)]
11pub struct TransitionFrontier {
12 #[allow(unused)]
13 sender: RpcSender,
14}
15
16#[derive(Clone)]
17#[cfg_attr(target_family = "wasm", wasm_bindgen)]
18pub struct TransitionFrontierBestChain {
19 #[allow(unused)]
20 sender: RpcSender,
21}
22
23impl TransitionFrontier {
24 pub fn new(sender: RpcSender) -> Self {
25 Self { sender }
26 }
27}
28
29#[cfg_attr(target_family = "wasm", wasm_bindgen)]
30impl TransitionFrontier {
31 pub fn best_chain(&self) -> TransitionFrontierBestChain {
32 TransitionFrontierBestChain {
33 sender: self.sender.clone(),
34 }
35 }
36}
37
38impl TransitionFrontierBestChain {
39 async fn _user_commands(&self) -> Option<RpcTransitionFrontierUserCommandsResponse> {
40 self.sender
41 .oneshot_request(RpcRequest::TransitionFrontierUserCommandsGet)
42 .await
43 }
44}
45
46#[cfg(not(target_family = "wasm"))]
47impl TransitionFrontierBestChain {
48 pub async fn user_commands(&self) -> Option<RpcTransitionFrontierUserCommandsResponse> {
49 self._user_commands().await
50 }
51}
52
53#[cfg(target_family = "wasm")]
54#[cfg_attr(target_family = "wasm", wasm_bindgen)]
55impl TransitionFrontierBestChain {
56 pub async fn user_commands(&self) -> JsValue {
57 JsValue::from_serde(&self._user_commands().await).unwrap_or_default()
58 }
59}