subcoin_service/
transaction_pool.rs

1use sc_transaction_pool_api::{
2    ImportNotificationStream, PoolStatus, ReadyTransactions, TransactionFor, TransactionSource,
3    TransactionStatusStreamFor, TxHash, TxInvalidityReportMap,
4};
5use sp_runtime::OpaqueExtrinsic;
6use std::collections::HashMap;
7use std::pin::Pin;
8use std::sync::Arc;
9use subcoin_runtime::interface::OpaqueBlock;
10
11#[derive(Clone, Debug)]
12pub struct PoolTransaction {
13    data: Arc<OpaqueExtrinsic>,
14    hash: sp_core::H256,
15}
16
17impl From<OpaqueExtrinsic> for PoolTransaction {
18    fn from(e: OpaqueExtrinsic) -> Self {
19        Self {
20            data: Arc::from(e),
21            hash: sp_core::H256::zero(),
22        }
23    }
24}
25
26impl sc_transaction_pool_api::InPoolTransaction for PoolTransaction {
27    type Transaction = Arc<OpaqueExtrinsic>;
28    type Hash = sp_core::H256;
29
30    fn data(&self) -> &Self::Transaction {
31        &self.data
32    }
33
34    fn hash(&self) -> &Self::Hash {
35        &self.hash
36    }
37
38    fn priority(&self) -> &u64 {
39        unimplemented!()
40    }
41
42    fn longevity(&self) -> &u64 {
43        unimplemented!()
44    }
45
46    fn requires(&self) -> &[Vec<u8>] {
47        unimplemented!()
48    }
49
50    fn provides(&self) -> &[Vec<u8>] {
51        unimplemented!()
52    }
53
54    fn is_propagable(&self) -> bool {
55        unimplemented!()
56    }
57}
58
59#[derive(Clone, Debug)]
60pub struct Transactions(Vec<Arc<PoolTransaction>>);
61pub struct TransactionsIterator(std::vec::IntoIter<Arc<PoolTransaction>>);
62
63/// Creates a dummy transaction pool.
64pub fn new_dummy_pool() -> Transactions {
65    Transactions(Vec::new())
66}
67
68impl Iterator for TransactionsIterator {
69    type Item = Arc<PoolTransaction>;
70
71    fn next(&mut self) -> Option<Self::Item> {
72        self.0.next()
73    }
74}
75
76impl ReadyTransactions for TransactionsIterator {
77    fn report_invalid(&mut self, _tx: &Self::Item) {}
78}
79
80#[async_trait::async_trait]
81impl sc_transaction_pool_api::TransactionPool for Transactions {
82    type Block = OpaqueBlock;
83    type Hash = sp_core::H256;
84    type InPoolTransaction = PoolTransaction;
85    type Error = sc_transaction_pool_api::error::Error;
86
87    /// Returns a future that imports a bunch of unverified transactions to the pool.
88    async fn submit_at(
89        &self,
90        _at: Self::Hash,
91        _source: TransactionSource,
92        _xts: Vec<TransactionFor<Self>>,
93    ) -> Result<Vec<Result<sp_core::H256, Self::Error>>, Self::Error> {
94        unimplemented!()
95    }
96
97    /// Returns a future that imports one unverified transaction to the pool.
98    async fn submit_one(
99        &self,
100        _at: Self::Hash,
101        _source: TransactionSource,
102        _xt: TransactionFor<Self>,
103    ) -> Result<TxHash<Self>, Self::Error> {
104        unimplemented!()
105    }
106
107    async fn submit_and_watch(
108        &self,
109        _at: Self::Hash,
110        _source: TransactionSource,
111        _xt: TransactionFor<Self>,
112    ) -> Result<Pin<Box<TransactionStatusStreamFor<Self>>>, Self::Error> {
113        unimplemented!()
114    }
115
116    async fn ready_at(
117        &self,
118        _at: Self::Hash,
119    ) -> Box<dyn ReadyTransactions<Item = Arc<Self::InPoolTransaction>> + Send> {
120        Box::new(TransactionsIterator(self.0.clone().into_iter()))
121    }
122
123    fn ready(&self) -> Box<dyn ReadyTransactions<Item = Arc<Self::InPoolTransaction>> + Send> {
124        Box::new(std::iter::empty::<Arc<Self::InPoolTransaction>>())
125    }
126
127    async fn report_invalid(
128        &self,
129        _at: Option<Self::Hash>,
130        _invalid_tx_errors: TxInvalidityReportMap<TxHash<Self>>,
131    ) -> Vec<Arc<Self::InPoolTransaction>> {
132        unimplemented!()
133    }
134
135    fn futures(&self) -> Vec<Self::InPoolTransaction> {
136        unimplemented!()
137    }
138
139    fn status(&self) -> PoolStatus {
140        unimplemented!()
141    }
142
143    fn import_notification_stream(&self) -> ImportNotificationStream<TxHash<Self>> {
144        unimplemented!()
145    }
146
147    fn on_broadcasted(&self, _propagations: HashMap<TxHash<Self>, Vec<String>>) {
148        unimplemented!()
149    }
150
151    fn hash_of(&self, _xt: &TransactionFor<Self>) -> TxHash<Self> {
152        unimplemented!()
153    }
154
155    fn ready_transaction(&self, _hash: &TxHash<Self>) -> Option<Arc<Self::InPoolTransaction>> {
156        unimplemented!()
157    }
158
159    async fn ready_at_with_timeout(
160        &self,
161        _at: Self::Hash,
162        _timeout: std::time::Duration,
163    ) -> Box<dyn ReadyTransactions<Item = Arc<Self::InPoolTransaction>> + Send> {
164        unimplemented!()
165    }
166}