1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
use sc_transaction_pool_api::{
    ImportNotificationStream, PoolStatus, ReadyTransactions, TransactionFor, TransactionSource,
    TransactionStatusStreamFor, TxHash,
};
use sp_runtime::OpaqueExtrinsic;
use std::collections::HashMap;
use std::pin::Pin;
use std::sync::Arc;
use subcoin_runtime::interface::OpaqueBlock;

#[derive(Clone, Debug)]
pub struct PoolTransaction {
    data: Arc<OpaqueExtrinsic>,
    hash: sp_core::H256,
}

impl From<OpaqueExtrinsic> for PoolTransaction {
    fn from(e: OpaqueExtrinsic) -> Self {
        Self {
            data: Arc::from(e),
            hash: sp_core::H256::zero(),
        }
    }
}

impl sc_transaction_pool_api::InPoolTransaction for PoolTransaction {
    type Transaction = Arc<OpaqueExtrinsic>;
    type Hash = sp_core::H256;

    fn data(&self) -> &Self::Transaction {
        &self.data
    }

    fn hash(&self) -> &Self::Hash {
        &self.hash
    }

    fn priority(&self) -> &u64 {
        unimplemented!()
    }

    fn longevity(&self) -> &u64 {
        unimplemented!()
    }

    fn requires(&self) -> &[Vec<u8>] {
        unimplemented!()
    }

    fn provides(&self) -> &[Vec<u8>] {
        unimplemented!()
    }

    fn is_propagable(&self) -> bool {
        unimplemented!()
    }
}

#[derive(Clone, Debug)]
pub struct Transactions(Vec<Arc<PoolTransaction>>);
pub struct TransactionsIterator(std::vec::IntoIter<Arc<PoolTransaction>>);

/// Creates a dummy transaction pool.
pub fn new_dummy_pool() -> Transactions {
    Transactions(Vec::new())
}

impl Iterator for TransactionsIterator {
    type Item = Arc<PoolTransaction>;

    fn next(&mut self) -> Option<Self::Item> {
        self.0.next()
    }
}

impl ReadyTransactions for TransactionsIterator {
    fn report_invalid(&mut self, _tx: &Self::Item) {}
}

#[async_trait::async_trait]
impl sc_transaction_pool_api::TransactionPool for Transactions {
    type Block = OpaqueBlock;
    type Hash = sp_core::H256;
    type InPoolTransaction = PoolTransaction;
    type Error = sc_transaction_pool_api::error::Error;

    /// Returns a future that imports a bunch of unverified transactions to the pool.
    async fn submit_at(
        &self,
        _at: Self::Hash,
        _source: TransactionSource,
        _xts: Vec<TransactionFor<Self>>,
    ) -> Result<Vec<Result<sp_core::H256, Self::Error>>, Self::Error> {
        unimplemented!()
    }

    /// Returns a future that imports one unverified transaction to the pool.
    async fn submit_one(
        &self,
        _at: Self::Hash,
        _source: TransactionSource,
        _xt: TransactionFor<Self>,
    ) -> Result<TxHash<Self>, Self::Error> {
        unimplemented!()
    }

    async fn submit_and_watch(
        &self,
        _at: Self::Hash,
        _source: TransactionSource,
        _xt: TransactionFor<Self>,
    ) -> Result<Pin<Box<TransactionStatusStreamFor<Self>>>, Self::Error> {
        unimplemented!()
    }

    async fn ready_at(
        &self,
        _at: Self::Hash,
    ) -> Box<dyn ReadyTransactions<Item = Arc<Self::InPoolTransaction>> + Send> {
        Box::new(TransactionsIterator(self.0.clone().into_iter()))
    }

    fn ready(&self) -> Box<dyn ReadyTransactions<Item = Arc<Self::InPoolTransaction>> + Send> {
        Box::new(std::iter::empty::<Arc<Self::InPoolTransaction>>())
    }

    fn remove_invalid(&self, _hashes: &[TxHash<Self>]) -> Vec<Arc<Self::InPoolTransaction>> {
        Default::default()
    }

    fn futures(&self) -> Vec<Self::InPoolTransaction> {
        unimplemented!()
    }

    fn status(&self) -> PoolStatus {
        unimplemented!()
    }

    fn import_notification_stream(&self) -> ImportNotificationStream<TxHash<Self>> {
        unimplemented!()
    }

    fn on_broadcasted(&self, _propagations: HashMap<TxHash<Self>, Vec<String>>) {
        unimplemented!()
    }

    fn hash_of(&self, _xt: &TransactionFor<Self>) -> TxHash<Self> {
        unimplemented!()
    }

    fn ready_transaction(&self, _hash: &TxHash<Self>) -> Option<Arc<Self::InPoolTransaction>> {
        unimplemented!()
    }

    async fn ready_at_with_timeout(
        &self,
        _at: Self::Hash,
        _timeout: std::time::Duration,
    ) -> Box<dyn ReadyTransactions<Item = Arc<Self::InPoolTransaction>> + Send> {
        unimplemented!()
    }
}