@@ -6,14 +6,14 @@ use roles_logic_sv2::{
6
6
DeclareMiningJobError , DeclareMiningJobSuccess , IdentifyTransactionsSuccess ,
7
7
ProvideMissingTransactions , ProvideMissingTransactionsSuccess , SubmitSolutionJd ,
8
8
} ,
9
- parsers:: JobDeclaration , utils :: Mutex ,
9
+ parsers:: JobDeclaration ,
10
10
} ;
11
- use std:: { convert:: TryInto , io:: Cursor , sync :: Arc } ;
12
- use stratum_common:: bitcoin:: { Transaction , Txid } ;
11
+ use std:: { convert:: TryInto , io:: Cursor } ;
12
+ use stratum_common:: bitcoin:: Transaction ;
13
13
pub type SendTo = SendTo_ < JobDeclaration < ' static > , ( ) > ;
14
14
use super :: { signed_token, TransactionState } ;
15
- use crate :: mempool:: { self , error :: JdsMempoolError , JDsMempool } ;
16
- use roles_logic_sv2:: { errors:: Error , parsers :: PoolMessages as AllMessages } ;
15
+ use crate :: mempool;
16
+ use roles_logic_sv2:: errors:: Error ;
17
17
use stratum_common:: bitcoin:: consensus:: Decodable ;
18
18
use tracing:: info;
19
19
@@ -78,7 +78,6 @@ impl ParseClientJobDeclarationMessages for JobDeclaratorDownstream {
78
78
. unwrap ( )
79
79
. unwrap ( ) ;
80
80
let mut transactions_with_state = vec ! [ TransactionState :: Missing ; short_hash_list. len( ) ] ;
81
- let mut txs_to_retrieve: Vec < ( String , usize ) > = vec ! [ ] ;
82
81
let mut missing_txs: Vec < u16 > = Vec :: new ( ) ;
83
82
84
83
for ( i, sid) in short_hash_list. iter ( ) . enumerate ( ) {
@@ -99,10 +98,10 @@ impl ParseClientJobDeclarationMessages for JobDeclaratorDownstream {
99
98
} ,
100
99
}
101
100
}
102
- self . declared_mining_job = Some ( (
103
- message. clone ( ) . into_static ( ) ,
101
+ self . declared_mining_job = ( Some (
102
+ message. clone ( ) . into_static ( ) ) ,
104
103
transactions_with_state
105
- ) ) ;
104
+ ) ;
106
105
107
106
//let self_mutex = Arc::new(Mutex::new(self));
108
107
//add_tx_data_to_job(self_mutex);
@@ -153,59 +152,51 @@ impl ParseClientJobDeclarationMessages for JobDeclaratorDownstream {
153
152
& mut self ,
154
153
message : ProvideMissingTransactionsSuccess ,
155
154
) -> Result < SendTo , Error > {
156
- match & mut self . declared_mining_job {
157
- Some ( ( _, ref mut transactions_with_state) ) => {
158
- for ( i, tx) in message. transaction_list . inner_as_ref ( ) . iter ( ) . enumerate ( ) {
159
- for tx_with_state in transactions_with_state. clone ( ) {
160
- match tx_with_state {
161
- TransactionState :: Present ( _) => continue ,
162
- TransactionState :: ToBeRetrievedFromMempool ( _) => continue ,
163
- TransactionState :: Missing => {
164
- let mut cursor = Cursor :: new ( tx) ;
165
- // TODO remove this unwrap
166
- let transaction = Transaction :: consensus_decode_from_finite_reader ( & mut cursor) . unwrap ( ) ;
167
- transactions_with_state[ i] = TransactionState :: Present ( transaction. clone ( ) ) ;
168
- mempool:: JDsMempool :: add_tx_data_to_mempool (
169
- self . mempool . clone ( ) ,
170
- transaction. txid ( ) ,
171
- Some ( transaction) ,
172
- ) ;
173
- break ;
174
- }
175
-
176
- }
177
- }
178
- }
179
- // if there still a missing transaction return an error
180
- for tx_with_state in transactions_with_state {
155
+ let ( _, ref mut transactions_with_state) = & mut self . declared_mining_job ;
156
+ for ( i, tx) in message. transaction_list . inner_as_ref ( ) . iter ( ) . enumerate ( ) {
157
+ for tx_with_state in transactions_with_state. clone ( ) {
181
158
match tx_with_state {
182
159
TransactionState :: Present ( _) => continue ,
183
160
TransactionState :: ToBeRetrievedFromMempool ( _) => continue ,
184
161
TransactionState :: Missing => {
185
- return Err ( Error :: JDSMissingTransactions ) ;
186
-
162
+ let mut cursor = Cursor :: new ( tx) ;
163
+ // TODO remove this unwrap
164
+ let transaction = Transaction :: consensus_decode_from_finite_reader ( & mut cursor) . unwrap ( ) ;
165
+ transactions_with_state[ i] = TransactionState :: Present ( transaction. clone ( ) ) ;
166
+ mempool:: JDsMempool :: add_tx_data_to_mempool (
167
+ self . mempool . clone ( ) ,
168
+ transaction. txid ( ) ,
169
+ Some ( transaction) ,
170
+ ) ;
171
+ break ;
187
172
}
173
+
188
174
}
189
175
}
190
- // TODO check it
191
- let tx_hash_list_hash = self . tx_hash_list_hash . clone ( ) . unwrap ( ) . into_static ( ) ;
192
- let message_success = DeclareMiningJobSuccess {
193
- request_id : message. request_id ,
194
- new_mining_job_token : signed_token (
195
- tx_hash_list_hash,
196
- & self . public_key . clone ( ) ,
197
- & self . private_key . clone ( ) ,
198
- ) ,
199
- } ;
200
- let message_enum_success = JobDeclaration :: DeclareMiningJobSuccess ( message_success) ;
201
- Ok ( SendTo :: Respond ( message_enum_success) )
202
176
}
203
- None => Err ( Error :: LogicErrorMessage ( Box :: new (
204
- AllMessages :: JobDeclaration ( JobDeclaration :: ProvideMissingTransactionsSuccess (
205
- message. clone ( ) . into_static ( ) ,
206
- ) ) ,
207
- ) ) ) ,
208
- }
177
+ // if there still a missing transaction return an error
178
+ for tx_with_state in transactions_with_state {
179
+ match tx_with_state {
180
+ TransactionState :: Present ( _) => continue ,
181
+ TransactionState :: ToBeRetrievedFromMempool ( _) => continue ,
182
+ TransactionState :: Missing => {
183
+ return Err ( Error :: JDSMissingTransactions )
184
+
185
+ }
186
+ }
187
+ }
188
+ // TODO check it
189
+ let tx_hash_list_hash = self . tx_hash_list_hash . clone ( ) . unwrap ( ) . into_static ( ) ;
190
+ let message_success = DeclareMiningJobSuccess {
191
+ request_id : message. request_id ,
192
+ new_mining_job_token : signed_token (
193
+ tx_hash_list_hash,
194
+ & self . public_key . clone ( ) ,
195
+ & self . private_key . clone ( ) ,
196
+ ) ,
197
+ } ;
198
+ let message_enum_success = JobDeclaration :: DeclareMiningJobSuccess ( message_success) ;
199
+ Ok ( SendTo :: Respond ( message_enum_success) )
209
200
}
210
201
211
202
fn handle_submit_solution ( & mut self , message : SubmitSolutionJd < ' _ > ) -> Result < SendTo , Error > {
@@ -215,56 +206,3 @@ impl ParseClientJobDeclarationMessages for JobDeclaratorDownstream {
215
206
}
216
207
}
217
208
218
- //fn add_tx_data_to_job(jdd: Arc<Mutex<&mut JobDeclaratorDownstream>>) {
219
- // tokio::task::spawn(async move {
220
- // let mut tx_list: Vec<Txid> = Vec::new();
221
- // let mut new_transactions: Vec<Transaction> = Vec::new();
222
- // let mempool = jdd.safe_lock(|a| a.mempool.clone()).unwrap();
223
- // jdd.safe_lock(|a| for tx in a.declared_mining_job.clone().unwrap().1 {
224
- // match tx {
225
- // TransactionState::Present(_) => continue,
226
- // TransactionState::Missing => continue,
227
- // TransactionState::ToBeRetrievedFromMempool(m) => tx_list.push(m),
228
- // }
229
- // });
230
- // for txid in tx_list {
231
- // let new_tx_data: Result<Transaction, JdsMempoolError> = mempool
232
- // .safe_lock(|x| x.get_client())
233
- // .map_err(|e| JdsMempoolError::PoisonLock(e.to_string()))?
234
- // .ok_or(JdsMempoolError::NoClient)?
235
- // .get_raw_transaction(&txid.to_string(), None)
236
- // .await
237
- // .map_err(JdsMempoolError::Rpc);
238
- // if let Ok(transaction) = new_tx_data {
239
- // new_transactions.push(transaction);
240
- // //this unwrap is safe
241
- // } else {
242
- // // TODO propagate error
243
- // todo!()
244
- // };
245
- // };
246
- //
247
- // //for tx in tx_list.iter().enumerate() {
248
- // // match tx.1 {
249
- // // &TransactionState::Missing | &TransactionState::Present(_) => continue,
250
- // // &TransactionState::ToBeRetrievedFromMempool(txid) => {
251
- // // let new_tx_data: Result<Transaction, JdsMempoolError> = mempool
252
- // // .safe_lock(|x| x.get_client())
253
- // // .map_err(|e| JdsMempoolError::PoisonLock(e.to_string()))?
254
- // // .ok_or(JdsMempoolError::NoClient)?
255
- // // .get_raw_transaction(&txid.to_string(), None)
256
- // // .await
257
- // // .map_err(JdsMempoolError::Rpc);
258
- // // if let Ok(transaction) = new_tx_data {
259
- // // new_transactions_mutex.safe_lock(|a| a.push(transaction));
260
- // // //this unwrap is safe
261
- // // } else {
262
- // // // TODO propagate error
263
- // // todo!()
264
- // // };
265
- // // }
266
- // // };
267
- // //}
268
- // Ok::<(), JdsMempoolError>(())
269
- // });
270
- //}
0 commit comments