"Missing non_witness_utxo on foreign utxo <utxo>"
I'm getting this error. What does BDK use to determine whether or not it needs the non_witness_utxo? The UTXO itself is an OP_TRUE p2wsh dust fee anchor, and my wallet is using taproot addresses, so I don't see why it needs that info?
It's annoying for me to have to actually provide entire prev txs for every fee anchor I'm spending, so I'm tempted to just provide a fake tx in that field to avoid this error, but it might actually check if the txid matches the utxo I provided and that would be really annoying..
FWIW the reason we require it is because hardware wallets often require it for segwitv0. We could add an option to wave the requirement I guess.
[EDIT] We already have an option to wave the requirement see only_witness_utxo
See also https://github.com/rust-bitcoin/rust-bitcoin/issues/2175 which has a bit more discussion. This might stem from some bad documentation in rust-bitcoin.
Yeah I think since it's already the user that provides the fields, it should be up to the user to decide whether to set the non_witness_utxo field. If the user is just going to let bdk's hot wallet sign it, there is no need. If he is using a HW that requires it, then he should be adding the field.
But fwiw, I couldn't even find the code that was requiring it. There is this check in add_foreign_utxo about the prevout fields, but it doesn't get generated there, so it must be somewhere deeper in create_tx or so.
I still think it's not ideal that bdk enforces this. In an application where the field is not required, it can be pretty annoying to get his value.. Currently I have to do this workaround
psbt::Input {
witness_utxo: Some(self.output.clone()),
//TODO(stevenroose) BDK wants this here, but it shouldn't
non_witness_utxo: Some(Transaction {
version: 2,
lock_time: bitcoin::absolute::LockTime::ZERO,
input: vec![],
output: iter::repeat(TxOut::default()).take(self.point.vout)
.chain(Some(self.output.clone())).collect(),
}),
..Default::default()
}
@stevenroose did you see that there is only_witness_utxo option on the transaction builder. The docs for add_foreign_utxo actually mentions that this will happen unless you set it.
Sorry I had forgotten about this when I first replied.
@stevenroose can I close this issue? Does this TxBuilder function do what you need? https://docs.rs/bdk/latest/bdk/wallet/tx_builder/struct.TxBuilder.html#method.only_witness_utxo
Closing issue for now, will re-open if above suggestion didn't solve the problem.