Merge bitcoindevkit/bdk#571: Fix pre-segwit inputs with esplora

52bc63e48f5d16cb03c8a58f7b0bd07cbb058dde Fix pre-segwit inputs with esplora (LLFourn)

Pull request description:

  Unexpectedly pre-segwit inputs have an empty JSON witness field in esplora.

  Fixes #570

  * [x] I've added tests to reproduce the issue which are now passing
  * [x] I'm linking the issue being fixed by this PR

ACKs for top commit:
  notmandatory:
    ACK 52bc63e48f5d16cb03c8a58f7b0bd07cbb058dde
  afilini:
    ACK 52bc63e48f5d16cb03c8a58f7b0bd07cbb058dde

Tree-SHA512: 1da82aeb2739111e1a516d94c79fe7d7c7879526a8cd780dcd63ff5ae9ccb1bed4eb20e5c575a45e37b6d1818d63ce6d3812e7b9ae34ebb02bc190a47b9750f8
This commit is contained in:
Steve Myers 2022-03-17 10:05:36 -05:00
commit 1e9a684b54
No known key found for this signature in database
GPG Key ID: 8105A46B22C2D051
2 changed files with 31 additions and 1 deletions

View File

@ -17,7 +17,7 @@ pub struct Vin {
// None if coinbase
pub prevout: Option<PrevOut>,
pub scriptsig: Script,
#[serde(deserialize_with = "deserialize_witness")]
#[serde(deserialize_with = "deserialize_witness", default)]
pub witness: Vec<Vec<u8>>,
pub sequence: u32,
pub is_coinbase: bool,

View File

@ -1165,6 +1165,36 @@ macro_rules! bdk_blockchain_tests {
assert!(utxo.outpoint != initial_tx.input[0].previous_output, "wallet displays spent txo in unspents");
}
}
#[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();
}
}
};