1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
pub mod error;
use jsonrpc_core::Result as RpcResult;
use jsonrpc_derive::rpc;
use jsonrpc_pubsub::{typed::Subscriber, SubscriptionId};
use sp_rpc::{number::NumberOrHex, list::ListOrValue};
use self::error::{FutureResult, Result};
pub use self::gen_client::Client as ChainClient;
#[rpc]
pub trait ChainApi<Number, Hash, Header, SignedBlock> {
type Metadata;
#[rpc(name = "chain_getHeader")]
fn header(&self, hash: Option<Hash>) -> FutureResult<Option<Header>>;
#[rpc(name = "chain_getBlock")]
fn block(&self, hash: Option<Hash>) -> FutureResult<Option<SignedBlock>>;
#[rpc(name = "chain_getBlockHash", alias("chain_getHead"))]
fn block_hash(
&self,
hash: Option<ListOrValue<NumberOrHex>>,
) -> Result<ListOrValue<Option<Hash>>>;
#[rpc(name = "chain_getFinalizedHead", alias("chain_getFinalisedHead"))]
fn finalized_head(&self) -> Result<Hash>;
#[pubsub(subscription = "chain_allHead", subscribe, name = "chain_subscribeAllHeads")]
fn subscribe_all_heads(&self, metadata: Self::Metadata, subscriber: Subscriber<Header>);
#[pubsub(subscription = "chain_allHead", unsubscribe, name = "chain_unsubscribeAllHeads")]
fn unsubscribe_all_heads(
&self,
metadata: Option<Self::Metadata>,
id: SubscriptionId,
) -> RpcResult<bool>;
#[pubsub(
subscription = "chain_newHead",
subscribe,
name = "chain_subscribeNewHeads",
alias("subscribe_newHead", "chain_subscribeNewHead")
)]
fn subscribe_new_heads(&self, metadata: Self::Metadata, subscriber: Subscriber<Header>);
#[pubsub(
subscription = "chain_newHead",
unsubscribe,
name = "chain_unsubscribeNewHeads",
alias("unsubscribe_newHead", "chain_unsubscribeNewHead")
)]
fn unsubscribe_new_heads(
&self,
metadata: Option<Self::Metadata>,
id: SubscriptionId,
) -> RpcResult<bool>;
#[pubsub(
subscription = "chain_finalizedHead",
subscribe,
name = "chain_subscribeFinalizedHeads",
alias("chain_subscribeFinalisedHeads")
)]
fn subscribe_finalized_heads(&self, metadata: Self::Metadata, subscriber: Subscriber<Header>);
#[pubsub(
subscription = "chain_finalizedHead",
unsubscribe,
name = "chain_unsubscribeFinalizedHeads",
alias("chain_unsubscribeFinalisedHeads")
)]
fn unsubscribe_finalized_heads(
&self,
metadata: Option<Self::Metadata>,
id: SubscriptionId,
) -> RpcResult<bool>;
}