File tree Expand file tree Collapse file tree 4 files changed +81
-1
lines changed Expand file tree Collapse file tree 4 files changed +81
-1
lines changed Original file line number Diff line number Diff line change
1
+ #[ cfg( target_family = "wasm" ) ]
2
+ use gloo_utils:: format:: JsValueSerdeExt ;
3
+ use node:: rpc:: * ;
4
+ #[ cfg( target_family = "wasm" ) ]
5
+ use wasm_bindgen:: prelude:: * ;
6
+
7
+ use super :: RpcSender ;
8
+
9
+ #[ derive( Clone ) ]
10
+ #[ cfg_attr( target_family = "wasm" , wasm_bindgen) ]
11
+ pub struct Ledger {
12
+ #[ allow( unused) ]
13
+ sender : RpcSender ,
14
+ }
15
+
16
+ #[ derive( Clone ) ]
17
+ #[ cfg_attr( target_family = "wasm" , wasm_bindgen) ]
18
+ pub struct LedgerSelected {
19
+ #[ allow( unused) ]
20
+ sender : RpcSender ,
21
+ }
22
+
23
+ #[ derive( Clone ) ]
24
+ #[ cfg_attr( target_family = "wasm" , wasm_bindgen) ]
25
+ pub struct LedgerAccounts {
26
+ #[ allow( unused) ]
27
+ sender : RpcSender ,
28
+ }
29
+
30
+ impl Ledger {
31
+ pub fn new ( sender : RpcSender ) -> Self {
32
+ Self { sender }
33
+ }
34
+
35
+ pub fn latest ( & self ) -> LedgerSelected {
36
+ LedgerSelected {
37
+ sender : self . sender . clone ( ) ,
38
+ }
39
+ }
40
+ }
41
+
42
+ impl LedgerSelected {
43
+ pub fn accounts ( & self ) -> LedgerAccounts {
44
+ LedgerAccounts {
45
+ sender : self . sender . clone ( ) ,
46
+ }
47
+ }
48
+ }
49
+
50
+ impl LedgerAccounts {
51
+ async fn _all ( & self ) -> Option < RpcLedgerSlimAccountsResponse > {
52
+ self . sender
53
+ . oneshot_request ( RpcRequest :: LedgerAccountsGet ( AccountQuery :: All ) )
54
+ . await
55
+ }
56
+ }
57
+
58
+ #[ cfg( not( target_family = "wasm" ) ) ]
59
+ impl LedgerAccounts {
60
+ pub async fn all ( & self ) -> Option < RpcLedgerSlimAccountsResponse > {
61
+ self . _all ( ) . await
62
+ }
63
+ }
64
+
65
+ #[ cfg( target_family = "wasm" ) ]
66
+ #[ cfg_attr( target_family = "wasm" , wasm_bindgen) ]
67
+ impl LedgerAccounts {
68
+ pub async fn all ( & self ) -> JsValue {
69
+ JsValue :: from_serde ( & self . _all ( ) . await ) . unwrap_or_default ( )
70
+ }
71
+ }
Original file line number Diff line number Diff line change 1
1
mod sender;
2
2
pub use sender:: RpcSender ;
3
3
4
+ pub mod ledger;
4
5
pub mod state;
5
6
pub mod stats;
6
7
pub mod transaction_pool;
Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ use node::core::channels::{mpsc, oneshot};
8
8
use node:: p2p:: connection:: outgoing:: P2pConnectionOutgoingInitOpts ;
9
9
use node:: rpc:: * ;
10
10
11
+ use super :: ledger:: Ledger ;
11
12
use super :: state:: State ;
12
13
use super :: stats:: Stats ;
13
14
use super :: transaction_pool:: TransactionPool ;
@@ -86,6 +87,10 @@ impl RpcSender {
86
87
pub fn transition_frontier ( & self ) -> TransitionFrontier {
87
88
TransitionFrontier :: new ( self . clone ( ) )
88
89
}
90
+
91
+ pub fn ledger ( & self ) -> Ledger {
92
+ Ledger :: new ( self . clone ( ) )
93
+ }
89
94
}
90
95
91
96
#[ cfg( target_family = "wasm" ) ]
Original file line number Diff line number Diff line change @@ -468,7 +468,10 @@ pub async fn run(port: u16, rpc_sender: RpcSender) {
468
468
469
469
async move {
470
470
rpc_sender_clone
471
- . oneshot_request ( RpcRequest :: LedgerAccountsGet ( AccountQuery :: All ) )
471
+ . ledger ( )
472
+ . latest ( )
473
+ . accounts ( )
474
+ . all ( )
472
475
. await
473
476
. map_or_else (
474
477
dropped_channel_response,
You can’t perform that action at this time.
0 commit comments