referrerpolicy=no-referrer-when-downgrade

sp_statement_store/
event.rs

1// This file is part of Substrate.
2
3// Copyright (C) Parity Technologies (UK) Ltd.
4// SPDX-License-Identifier: Apache-2.0
5
6// Licensed under the Apache License, Version 2.0 (the "License");
7// you may not use this file except in compliance with the License.
8// You may obtain a copy of the License at
9//
10// 	http://www.apache.org/licenses/LICENSE-2.0
11//
12// Unless required by applicable law or agreed to in writing, software
13// distributed under the License is distributed on an "AS IS" BASIS,
14// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15// See the License for the specific language governing permissions and
16// limitations under the License.
17
18use alloc::{string::String, vec::Vec};
19use sp_core::Bytes;
20
21/// Subscription notification event.
22#[derive(Debug, Clone, PartialEq, Eq)]
23#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
24#[cfg_attr(feature = "serde", serde(tag = "event", rename_all = "camelCase"))]
25pub enum SubscribeEvent {
26	/// Statements admitted before the filter was attached.
27	ReplayStatements {
28		/// Filter that produced this replay batch.
29		#[cfg_attr(feature = "serde", serde(rename = "filterId"))]
30		filter_id: String,
31		/// SCALE-encoded statements included in this replay batch.
32		statements: Vec<Bytes>,
33	},
34	/// Replay completion marker.
35	ReplayDone {
36		/// Filter whose replay completed.
37		#[cfg_attr(feature = "serde", serde(rename = "filterId"))]
38		filter_id: String,
39	},
40	/// Statements admitted after matching filters were attached.
41	NewStatements {
42		/// Statement entries included in this notification.
43		statements: Vec<NewStatementEntry>,
44	},
45	/// Terminal notification.
46	Stop,
47}
48
49/// Statement item included in a `newStatements` notification.
50#[derive(Debug, Clone, PartialEq, Eq)]
51#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
52pub struct NewStatementEntry {
53	/// SCALE-encoded statement bytes.
54	pub statement: Bytes,
55	/// Filters that matched this statement.
56	#[cfg_attr(feature = "serde", serde(rename = "filterIds"))]
57	pub filter_ids: Vec<String>,
58}
59
60/// Response returned by `statement_unstable_add_filter`.
61#[derive(Debug, Clone, PartialEq, Eq)]
62#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
63#[cfg_attr(feature = "serde", serde(untagged))]
64pub enum AddFilterResponse {
65	/// Filter was added and the string contains its filter id.
66	Ok(String),
67	/// Filter could not be added because the subscription reached its limit.
68	LimitReached(LimitReachedResult),
69}
70
71/// Response payload for a limit-reached add-filter result.
72#[derive(Debug, Clone, PartialEq, Eq)]
73#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
74pub struct LimitReachedResult {
75	/// Machine-readable result tag.
76	pub result: LimitReachedTag,
77}
78
79/// Result tag returned when the filter limit is reached.
80#[derive(Debug, Clone, Copy, PartialEq, Eq)]
81#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
82#[cfg_attr(feature = "serde", serde(rename_all = "camelCase"))]
83pub enum LimitReachedTag {
84	/// The subscription cannot accept another filter.
85	LimitReached,
86}
87
88impl AddFilterResponse {
89	/// Returns the limit-reached response.
90	pub fn limit_reached() -> Self {
91		AddFilterResponse::LimitReached(LimitReachedResult {
92			result: LimitReachedTag::LimitReached,
93		})
94	}
95}