sc_rpc_spec_v2/transaction/api.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//! API trait for transactions.
20
21use crate::transaction::{error::ErrorBroadcast, event::TransactionEvent};
22use jsonrpsee::{core::RpcResult, proc_macros::rpc};
23use sp_core::Bytes;
24
25#[rpc(client, server)]
26pub trait TransactionApi<Hash: Clone> {
27 /// Submit an extrinsic to watch.
28 ///
29 /// See [`TransactionEvent`](crate::transaction::event::TransactionEvent) for details on
30 /// transaction life cycle.
31 ///
32 /// # Unstable
33 ///
34 /// This method is unstable and subject to change in the future.
35 #[subscription(
36 name = "transactionWatch_v1_submitAndWatch" => "transactionWatch_v1_watchEvent",
37 unsubscribe = "transactionWatch_v1_unwatch",
38 item = TransactionEvent<Hash>,
39 )]
40 fn submit_and_watch(&self, bytes: Bytes);
41}
42
43#[rpc(client, server)]
44pub trait TransactionBroadcastApi {
45 /// Broadcast an extrinsic to the chain.
46 ///
47 /// # Unstable
48 ///
49 /// This method is unstable and subject to change in the future.
50
51 #[method(name = "transaction_v1_broadcast", with_extensions)]
52 async fn broadcast(&self, bytes: Bytes) -> RpcResult<Option<String>>;
53
54 /// Broadcast an extrinsic to the chain.
55 ///
56 /// # Unstable
57 ///
58 /// This method is unstable and subject to change in the future.
59 #[method(name = "transaction_v1_stop", with_extensions)]
60 async fn stop_broadcast(&self, operation_id: String) -> Result<(), ErrorBroadcast>;
61}