Use From trait for conversion
This commit is contained in:
		
							parent
							
								
									e738126bed
								
							
						
					
					
						commit
						87a8af9457
					
				
							
								
								
									
										32
									
								
								src/lib.rs
									
									
									
									
									
								
							
							
						
						
									
										32
									
								
								src/lib.rs
									
									
									
									
									
								
							| @ -82,19 +82,21 @@ pub enum Transaction { | |||||||
|     }, |     }, | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| fn to_transaction(x: &bdk::TransactionDetails) -> Transaction { | impl From<&bdk::TransactionDetails> for Transaction { | ||||||
|     let details = TransactionDetails { |     fn from(x: &bdk::TransactionDetails) -> Transaction { | ||||||
|         fees: x.fee, |         let details = TransactionDetails { | ||||||
|         id: x.txid.to_string(), |             fees: x.fee, | ||||||
|         received: x.received, |             id: x.txid.to_string(), | ||||||
|         sent: x.sent, |             received: x.received, | ||||||
|     }; |             sent: x.sent, | ||||||
|     match x.confirmation_time.clone() { |         }; | ||||||
|         Some(confirmation) => Transaction::Confirmed { |         match x.confirmation_time.clone() { | ||||||
|             details, |             Some(confirmation) => Transaction::Confirmed { | ||||||
|             confirmation, |                 details, | ||||||
|         }, |                 confirmation, | ||||||
|         None => Transaction::Unconfirmed { details }, |             }, | ||||||
|  |             None => Transaction::Unconfirmed { details }, | ||||||
|  |         } | ||||||
|     } |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| @ -133,7 +135,7 @@ trait OfflineWalletOperations<B>: WalletHolder<B> { | |||||||
| 
 | 
 | ||||||
|     fn get_transactions(&self) -> Result<Vec<Transaction>, Error> { |     fn get_transactions(&self) -> Result<Vec<Transaction>, Error> { | ||||||
|         let transactions = self.get_wallet().list_transactions(true)?; |         let transactions = self.get_wallet().list_transactions(true)?; | ||||||
|         Ok(transactions.iter().map(to_transaction).collect()) |         Ok(transactions.iter().map(Transaction::from).collect()) | ||||||
|     } |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| @ -275,7 +277,7 @@ impl OnlineWallet { | |||||||
|     ) -> Result<Transaction, Error> { |     ) -> Result<Transaction, Error> { | ||||||
|         let tx = psbt.internal.lock().unwrap().clone().extract_tx(); |         let tx = psbt.internal.lock().unwrap().clone().extract_tx(); | ||||||
|         self.get_wallet().broadcast(tx)?; |         self.get_wallet().broadcast(tx)?; | ||||||
|         Ok(to_transaction(&psbt.details)) |         Ok(Transaction::from(&psbt.details)) | ||||||
|     } |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user