feat: add transactions method on wallet
This commit is contained in:
		
							parent
							
								
									bbc6e1a43c
								
							
						
					
					
						commit
						a1a45996fc
					
				| @ -19,6 +19,15 @@ class LiveWalletTest { | |||||||
|         println("Balance: $balance") |         println("Balance: $balance") | ||||||
| 
 | 
 | ||||||
|         assert(wallet.getBalance().total > 0uL) |         assert(wallet.getBalance().total > 0uL) | ||||||
|  | 
 | ||||||
|  |         println("Transactions count: ${wallet.transactions().count()}") | ||||||
|  |         val transactions = wallet.transactions().take(3) | ||||||
|  |         for (tx in transactions) { | ||||||
|  |             val sentAndReceived = wallet.sentAndReceived(tx) | ||||||
|  |             println("Transaction: ${tx.txid()}") | ||||||
|  |             println("Sent ${sentAndReceived.sent}") | ||||||
|  |             println("Received ${sentAndReceived.received}") | ||||||
|  |         } | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     @Test |     @Test | ||||||
|  | |||||||
| @ -109,6 +109,8 @@ interface Wallet { | |||||||
|   boolean sign(PartiallySignedTransaction psbt); |   boolean sign(PartiallySignedTransaction psbt); | ||||||
| 
 | 
 | ||||||
|   SentAndReceivedValues sent_and_received([ByRef] Transaction tx); |   SentAndReceivedValues sent_and_received([ByRef] Transaction tx); | ||||||
|  | 
 | ||||||
|  |   sequence<Transaction> transactions(); | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| interface Update {}; | interface Update {}; | ||||||
|  | |||||||
| @ -99,6 +99,13 @@ impl Wallet { | |||||||
|         let (sent, received): (u64, u64) = self.get_wallet().sent_and_received(&tx.clone().into()); |         let (sent, received): (u64, u64) = self.get_wallet().sent_and_received(&tx.clone().into()); | ||||||
|         SentAndReceivedValues { sent, received } |         SentAndReceivedValues { sent, received } | ||||||
|     } |     } | ||||||
|  | 
 | ||||||
|  |     pub fn transactions(&self) -> Vec<Arc<Transaction>> { | ||||||
|  |         self.get_wallet() | ||||||
|  |             .transactions() | ||||||
|  |             .map(|tx| Arc::new(tx.tx_node.tx.clone().into())) | ||||||
|  |             .collect() | ||||||
|  |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| pub struct SentAndReceivedValues { | pub struct SentAndReceivedValues { | ||||||
|  | |||||||
| @ -15,6 +15,15 @@ class LiveWalletTest { | |||||||
|         println("Balance: ${wallet.getBalance().total}") |         println("Balance: ${wallet.getBalance().total}") | ||||||
| 
 | 
 | ||||||
|         assert(wallet.getBalance().total > 0uL) |         assert(wallet.getBalance().total > 0uL) | ||||||
|  | 
 | ||||||
|  |         println("Transactions count: ${wallet.transactions().count()}") | ||||||
|  |         val transactions = wallet.transactions().take(3) | ||||||
|  |         for (tx in transactions) { | ||||||
|  |             val sentAndReceived = wallet.sentAndReceived(tx) | ||||||
|  |             println("Transaction: ${tx.txid()}") | ||||||
|  |             println("Sent ${sentAndReceived.sent}") | ||||||
|  |             println("Received ${sentAndReceived.received}") | ||||||
|  |         } | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     @Test |     @Test | ||||||
|  | |||||||
| @ -5,7 +5,7 @@ class TestLiveWallet(unittest.TestCase): | |||||||
| 
 | 
 | ||||||
|     def test_synced_balance(self): |     def test_synced_balance(self): | ||||||
|         descriptor: bdk.Descriptor = bdk.Descriptor( |         descriptor: bdk.Descriptor = bdk.Descriptor( | ||||||
|             "wpkh([c258d2e4/84h/1h/0h]tpubDDYkZojQFQjht8Tm4jsS3iuEmKjTiEGjG6KnuFNKKJb5A6ZUCUZKdvLdSDWofKi4ToRCwb9poe1XdqfUnP4jaJjCB2Zwv11ZLgSbnZSNecE/0/*)", |             "wpkh(tprv8ZgxMBicQKsPf2qfrEygW6fdYseJDDrVnDv26PH5BHdvSuG6ecCbHqLVof9yZcMoM31z9ur3tTYbSnr1WBqbGX97CbXcmp5H6qeMpyvx35B/84h/1h/0h/0/*)", | ||||||
|             bdk.Network.TESTNET |             bdk.Network.TESTNET | ||||||
|         ) |         ) | ||||||
|         wallet: bdk.Wallet = bdk.Wallet.new_no_persist( |         wallet: bdk.Wallet = bdk.Wallet.new_no_persist( | ||||||
| @ -23,6 +23,15 @@ class TestLiveWallet(unittest.TestCase): | |||||||
| 
 | 
 | ||||||
|         self.assertGreater(wallet.get_balance().total, 0) |         self.assertGreater(wallet.get_balance().total, 0) | ||||||
| 
 | 
 | ||||||
|  |         print(f"Transactions count: {len(wallet.transactions())}") | ||||||
|  |         transactions = wallet.transactions()[:3] | ||||||
|  |         for tx in transactions: | ||||||
|  |             sent_and_received = wallet.sent_and_received(tx) | ||||||
|  |             print(f"Transaction: {tx.txid()}") | ||||||
|  |             print(f"Sent {sent_and_received.sent}") | ||||||
|  |             print(f"Received {sent_and_received.received}") | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|     def test_broadcast_transaction(self): |     def test_broadcast_transaction(self): | ||||||
|         descriptor: bdk.Descriptor = bdk.Descriptor( |         descriptor: bdk.Descriptor = bdk.Descriptor( | ||||||
|             "wpkh(tprv8ZgxMBicQKsPf2qfrEygW6fdYseJDDrVnDv26PH5BHdvSuG6ecCbHqLVof9yZcMoM31z9ur3tTYbSnr1WBqbGX97CbXcmp5H6qeMpyvx35B/84h/1h/0h/0/*)", |             "wpkh(tprv8ZgxMBicQKsPf2qfrEygW6fdYseJDDrVnDv26PH5BHdvSuG6ecCbHqLVof9yZcMoM31z9ur3tTYbSnr1WBqbGX97CbXcmp5H6qeMpyvx35B/84h/1h/0h/0/*)", | ||||||
|  | |||||||
| @ -21,6 +21,15 @@ final class LiveWalletTests: XCTestCase { | |||||||
|         try wallet.applyUpdate(update: update) |         try wallet.applyUpdate(update: update) | ||||||
| 
 | 
 | ||||||
|         XCTAssertGreaterThan(wallet.getBalance().total, UInt64(0)) |         XCTAssertGreaterThan(wallet.getBalance().total, UInt64(0)) | ||||||
|  | 
 | ||||||
|  |         print("Transactions count: \(wallet.transactions().count)") | ||||||
|  |         let transactions = wallet.transactions().prefix(3) | ||||||
|  |         for tx in transactions { | ||||||
|  |             let sentAndReceived = wallet.sentAndReceived(tx: tx) | ||||||
|  |             print("Transaction: \(tx.txid())") | ||||||
|  |             print("Sent \(sentAndReceived.sent)") | ||||||
|  |             print("Received \(sentAndReceived.received)") | ||||||
|  |         } | ||||||
|     } |     } | ||||||
|      |      | ||||||
|     func testBroadcastTransaction() throws { |     func testBroadcastTransaction() throws { | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user