Skip to content

Commit

Permalink
Fix pre-segwit inputs with esplora
Browse files Browse the repository at this point in the history
  • Loading branch information
LLFourn authored and notmandatory committed Mar 17, 2022
1 parent 52bcd10 commit 559cfc4
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/blockchain/esplora/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
30 changes: 30 additions & 0 deletions src/testutils/blockchain_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
};

Expand Down

0 comments on commit 559cfc4

Please sign in to comment.