Skip to main content

sc_rpc_api/statement/
mod.rs

1// This file is part of Substrate.
2
3// Copyright (C) Parity Technologies (UK) Ltd.
4// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
5
6// This program is free software: you can redistribute it and/or modify
7// it under the terms of the GNU General Public License as published by
8// the Free Software Foundation, either version 3 of the License, or
9// (at your option) any later version.
10
11// This program is distributed in the hope that it will be useful,
12// but WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14// GNU General Public License for more details.
15
16// You should have received a copy of the GNU General Public License
17// along with this program. If not, see <https://www.gnu.org/licenses/>.
18
19//! Substrate Statement Store RPC API.
20
21use jsonrpsee::{core::RpcResult, proc_macros::rpc};
22use sp_core::Bytes;
23use sp_statement_store::{StatementEvent, SubmitResult, TopicFilter};
24
25pub mod error;
26
27/// Substrate statement RPC API
28#[rpc(client, server)]
29pub trait StatementApi {
30	/// Subscribe to new statements that match the provided filters.
31	///
32	/// # Parameters
33	///
34	/// - `topic_filter` — Which topics to match. Use `TopicFilter::Any` to match all topics,
35	///   `TopicFilter::MatchAll(vec)` to match statements that include all provided topics, or
36	///   `TopicFilter::MatchAny(vec)` to match statements that include any of the provided topics.
37	///
38	/// # Returns
39	///
40	/// Returns a stream of `StatementEvent` values.
41	/// When a subscription is initiated the endpoint will first return all matching statements
42	/// already in the store in batches as `StatementEvent::NewStatements`.
43	///
44	/// NewStatements includes an Optional field `remaining` which indicates how many more
45	/// statements are left to be sent in the initial batch of existing statements. The field
46	/// guarantees to the client that it will receive at least this many more statements in the
47	/// subscription stream, but it may receive more if new statements are added to the store that
48	/// match the filter.
49	///
50	///  If there are no statements in the store matching the filter, an empty batch of statements
51	/// is sent.
52	#[subscription(
53		name = "statement_subscribeStatement" => "statement_statement",
54		unsubscribe = "statement_unsubscribeStatement",
55		item = StatementEvent,
56		with_extensions,
57	)]
58	fn subscribe_statement(&self, topic_filter: TopicFilter);
59
60	/// Submit a SCALE-encoded statement.
61	///
62	/// See `Statement` definition for more details.
63	///
64	/// Returns `SubmitResult` indicating success or failure reason.
65	#[method(name = "statement_submit")]
66	fn submit(&self, encoded: Bytes) -> RpcResult<SubmitResult>;
67}