]> Untitled Git - bdk/commitdiff
add method add_data as a shortcut to create an OP_RETURN output, fix the dust check...
authorRiccardo Casatta <riccardo@casatta.it>
Wed, 27 Oct 2021 14:34:33 +0000 (16:34 +0200)
committerRiccardo Casatta <riccardo@casatta.it>
Tue, 9 Nov 2021 14:36:39 +0000 (15:36 +0100)
src/wallet/mod.rs
src/wallet/tx_builder.rs

index 1f6353cd2c241dfb595f0a713e191113a494cbe1..b8d1196d94d794b469b0b98981a0d57e09fea689 100644 (file)
@@ -601,7 +601,7 @@ where
         let recipients = params.recipients.iter().map(|(r, v)| (r, *v));
 
         for (index, (script_pubkey, value)) in recipients.enumerate() {
-            if value.is_dust() {
+            if value.is_dust() && !script_pubkey.is_provably_unspendable() {
                 return Err(Error::OutputBelowDustLimit(index));
             }
 
index a0ed93cbe78664d4f7d3da5b854187fa3d836c05..0c7f7f857e8a40dfc07d125f6cf5899a8d4cb7f6 100644 (file)
@@ -560,6 +560,13 @@ impl<'a, B, D: BatchDatabase, Cs: CoinSelectionAlgorithm<D>> TxBuilder<'a, B, D,
         self
     }
 
+    /// Add data as an output, using OP_RETURN
+    pub fn add_data(&mut self, data: &[u8]) -> &mut Self {
+        let script = Script::new_op_return(data);
+        self.add_recipient(script, 0u64);
+        self
+    }
+
     /// Sets the address to *drain* excess coins to.
     ///
     /// Usually, when there are excess coins they are sent to a change address generated by the