]> Untitled Git - bdk/commitdiff
[repl] Add broadcast command
authorAlekos Filini <alekos.filini@gmail.com>
Tue, 21 Apr 2020 14:39:00 +0000 (16:39 +0200)
committerAlekos Filini <alekos.filini@gmail.com>
Tue, 21 Apr 2020 14:39:00 +0000 (16:39 +0200)
examples/repl.rs
src/wallet/mod.rs

index b67b6e385f7360afe6d75ea3a437595cd52ceab1..82c41f308703c566c9ac5448ac8d936f938d9129 100644 (file)
@@ -160,6 +160,18 @@ fn main() {
                         .takes_value(true)
                         .number_of_values(1)
                         .required(true),
+                ))
+        .subcommand(
+            SubCommand::with_name("broadcast")
+                .about("Extracts the finalized transaction from a PSBT and broadcasts it to the network")
+                .arg(
+                    Arg::with_name("psbt")
+                        .long("psbt")
+                        .value_name("BASE64_PSBT")
+                        .help("Sets the PSBT to broadcast")
+                        .takes_value(true)
+                        .number_of_values(1)
+                        .required(true),
                 ));
 
     let mut repl_app = app.clone().setting(AppSettings::NoBinaryName);
@@ -309,6 +321,12 @@ fn main() {
             if finalized {
                 println!("Extracted: {}", serialize_hex(&psbt.extract_tx()));
             }
+        } else if let Some(sub_matches) = matches.subcommand_matches("broadcast") {
+            let psbt = base64::decode(sub_matches.value_of("psbt").unwrap()).unwrap();
+            let psbt: PartiallySignedTransaction = deserialize(&psbt).unwrap();
+            let (txid, _) = wallet.broadcast(psbt).unwrap();
+
+            println!("TXID: {}", txid);
         }
     };
 
index daba328918742e8870608da53b73e8d03d6208af..57daa49157073365ce817484fc8c8590e9b15080 100644 (file)
@@ -1062,7 +1062,7 @@ where
         Ok(())
     }
 
-    pub fn broadcast(&mut self, psbt: PSBT) -> Result<Transaction, Error> {
+    pub fn broadcast(&self, psbt: PSBT) -> Result<(Txid, Transaction), Error> {
         let extracted = psbt.extract_tx();
         self.client
             .as_ref()
@@ -1070,6 +1070,6 @@ where
             .borrow_mut()
             .transaction_broadcast(&extracted)?;
 
-        Ok(extracted)
+        Ok((extracted.txid(), extracted))
     }
 }