referrerpolicy=no-referrer-when-downgrade

StatementApiServer

Trait StatementApiServer 

pub trait StatementApiServer:
    Sized
    + Send
    + Sync
    + 'static {
    // Required methods
    fn submit(
        &self,
        encoded: Bytes,
    ) -> Result<SubmitResult, ErrorObject<'static>>;
    fn subscribe_statement(
        &self,
        subscription_sink: PendingSubscriptionSink,
        ext: &Extensions,
        topic_filter: TopicFilter,
    );

    // Provided method
    fn into_rpc(self) -> RpcModule<Self> { ... }
}
Expand description

Re-export the API for backward compatibility. Server trait implementation for the StatementApi RPC API.

Required Methods§

fn submit(&self, encoded: Bytes) -> Result<SubmitResult, ErrorObject<'static>>

Submit a SCALE-encoded statement.

See Statement definition for more details.

Returns SubmitResult indicating success or failure reason.

§Examples
{ "jsonrpc": "2.0", "id": 2, "method": "statement_submit", "params": ["0x…scale-encoded…"] }

On success the result is { "status": "new" }. Other outcomes are known, knownExpired, rejected and invalid (each with a reason), and internalError.

fn subscribe_statement( &self, subscription_sink: PendingSubscriptionSink, ext: &Extensions, topic_filter: TopicFilter, )

Subscribe to new statements that match the provided filters.

§Parameters
  • topic_filter — Which topics to match. Use TopicFilter::Any to match all topics, TopicFilter::MatchAll(vec) to match statements that include all provided topics, or TopicFilter::MatchAny(vec) to match statements that include any of the provided topics.
§Returns

Returns a stream of StatementEvent values. When a subscription is initiated the endpoint will first return all matching statements already in the store in batches as StatementEvent::NewStatements.

NewStatements includes an Optional field remaining which indicates how many more statements are left to be sent in the initial batch of existing statements. The field guarantees to the client that it will receive at least this many more statements in the subscription stream, but it may receive more if new statements are added to the store that match the filter.

If there are no statements in the store matching the filter, an empty batch of statements is sent.

§Examples

Subscribe, matching statements that include all of the given topics (use "any" to match everything, or { "matchAny": [...] } for any-of):

{ "jsonrpc": "2.0", "id": 1, "method": "statement_subscribeStatement",
  "params": [{ "matchAll": ["0xdede…", "0xadad…"] }] }

Notifications arrive on statement_statement. The already-stored matches are delivered first in batches, each carrying remaining (how many more are guaranteed to follow). An empty initial batch is sent when nothing matches:

{ "jsonrpc": "2.0", "method": "statement_statement",
  "params": { "subscription": 4851578855668545,
    "result": { "event": "newStatements", "data": { "statements": [], "remaining": 0 } } } }

A non-empty batch from the initial set (each statement is hex-encoded SCALE):

{ "jsonrpc": "2.0", "method": "statement_statement",
  "params": { "subscription": 4851578855668545,
    "result": { "event": "newStatements",
      "data": { "statements": ["0x1000010000", "0x100001000000"], "remaining": 10 } } } }

Statements arriving live, after the initial set is drained, carry no remaining:

{ "jsonrpc": "2.0", "method": "statement_statement",
  "params": { "subscription": 4851578855668545,
    "result": { "event": "newStatements", "data": { "statements": ["0x1000010000"] } } } }

Provided Methods§

fn into_rpc(self) -> RpcModule<Self>

Collects all the methods and subscriptions defined in the trait and adds them into a single RpcModule.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§