From 559cfc4373ffc77947adf5cac2af310ae43d4f4b Mon Sep 17 00:00:00 2001 From: LLFourn Date: Wed, 16 Mar 2022 10:11:31 +1100 Subject: [PATCH] Fix pre-segwit inputs with esplora --- src/blockchain/esplora/api.rs | 2 +- src/testutils/blockchain_tests.rs | 30 ++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/src/blockchain/esplora/api.rs b/src/blockchain/esplora/api.rs index 4e0e3f88b..640f7a0bb 100644 --- a/src/blockchain/esplora/api.rs +++ b/src/blockchain/esplora/api.rs @@ -17,7 +17,7 @@ pub struct Vin { // None if coinbase pub prevout: Option, pub scriptsig: Script, - #[serde(deserialize_with = "deserialize_witness")] + #[serde(deserialize_with = "deserialize_witness", default)] pub witness: Vec>, pub sequence: u32, pub is_coinbase: bool, diff --git a/src/testutils/blockchain_tests.rs b/src/testutils/blockchain_tests.rs index 6ac91e88f..cbbf90a1c 100644 --- a/src/testutils/blockchain_tests.rs +++ b/src/testutils/blockchain_tests.rs @@ -1124,6 +1124,36 @@ macro_rules! bdk_blockchain_tests { assert_eq!(tx_2.received, 10_000); assert_eq!(tx_2.sent, 0); } + + #[test] + fn test_send_receive_pkh() { + let descriptors = ("pkh(cVpPVruEDdmutPzisEsYvtST1usBR3ntr8pXSyt6D2YYqXRyPcFW)".to_string(), None); + let mut test_client = TestClient::default(); + let blockchain = get_blockchain(&test_client); + + let wallet = get_wallet_from_descriptors(&descriptors); + #[cfg(feature = "test-rpc")] + wallet.sync(&blockchain, SyncOptions::default()).unwrap(); + + let _ = test_client.receive(testutils! { + @tx ( (@external descriptors, 0) => 50_000 ) + }); + + wallet.sync(&blockchain, SyncOptions::default()).unwrap(); + + assert_eq!(wallet.get_balance().unwrap(), 50_000); + + let tx = { + let mut builder = wallet.build_tx(); + builder.add_recipient(test_client.get_node_address(None).script_pubkey(), 25_000); + let (mut psbt, _details) = builder.finish().unwrap(); + wallet.sign(&mut psbt, Default::default()).unwrap(); + psbt.extract_tx() + }; + blockchain.broadcast(&tx).unwrap(); + + wallet.sync(&blockchain, SyncOptions::default()).unwrap(); + } } };