Allow creating transactions with dust outputs

Add TxBuilder::allow_dust() that skips checking the dust limit
This commit is contained in:
Liam
2022-07-29 15:30:43 -04:00
parent 061f15af00
commit bfd7b2f65d
3 changed files with 41 additions and 5 deletions

View File

@@ -790,7 +790,10 @@ where
let recipients = params.recipients.iter().map(|(r, v)| (r, *v));
for (index, (script_pubkey, value)) in recipients.enumerate() {
if value.is_dust(script_pubkey) && !script_pubkey.is_provably_unspendable() {
if !params.allow_dust
&& value.is_dust(script_pubkey)
&& !script_pubkey.is_provably_unspendable()
{
return Err(Error::OutputBelowDustLimit(index));
}
@@ -5408,6 +5411,30 @@ pub(crate) mod test {
builder.finish().unwrap();
}
#[test]
fn test_allow_dust_limit() {
let (wallet, _, _) = get_funded_wallet(get_test_single_sig_cltv());
let addr = wallet.get_address(New).unwrap();
let mut builder = wallet.build_tx();
builder.add_recipient(addr.script_pubkey(), 0);
assert!(matches!(
builder.finish().unwrap_err(),
Error::OutputBelowDustLimit(0)
));
let mut builder = wallet.build_tx();
builder
.allow_dust(true)
.add_recipient(addr.script_pubkey(), 0);
assert!(builder.finish().is_ok());
}
#[test]
fn test_fee_rate_sign_no_grinding_high_r() {
// Our goal is to obtain a transaction with a signature with high-R (71 bytes