diff --git a/src/wallet.rs b/src/wallet.rs index 626fc604e1..d3a182e6f3 100644 --- a/src/wallet.rs +++ b/src/wallet.rs @@ -1,8 +1,10 @@ use { super::*, + base64::{self, Engine}, bitcoin::secp256k1::{All, Secp256k1}, bitcoin::{ bip32::{ChildNumber, DerivationPath, ExtendedPrivKey, Fingerprint}, + psbt::Psbt, Network, }, bitcoincore_rpc::bitcoincore_rpc_json::{Descriptor, ImportDescriptors, Timestamp}, @@ -62,7 +64,6 @@ impl Wallet { ); if let Some((username, password)) = options.credentials() { - use base64::Engine; let credentials = base64::engine::general_purpose::STANDARD.encode(format!("{username}:{password}")); headers.insert( diff --git a/src/wallet/inscribe.rs b/src/wallet/inscribe.rs index 08344f7cb0..27f107e2c5 100644 --- a/src/wallet/inscribe.rs +++ b/src/wallet/inscribe.rs @@ -30,9 +30,11 @@ pub struct InscriptionInfo { #[derive(Serialize, Deserialize)] pub struct Output { pub commit: Txid, + pub commit_psbt: Option, pub inscriptions: Vec, pub parent: Option, pub reveal: Txid, + pub reveal_psbt: Option, pub total_fees: u64, } diff --git a/src/wallet/inscribe/batch.rs b/src/wallet/inscribe/batch.rs index 76b82b0337..1c27df1669 100644 --- a/src/wallet/inscribe/batch.rs +++ b/src/wallet/inscribe/batch.rs @@ -57,9 +57,24 @@ impl Batch { )?; if self.dry_run { + let commit_psbt = wallet + .bitcoin_client() + .wallet_process_psbt( + &base64::engine::general_purpose::STANDARD + .encode(Psbt::from_unsigned_tx(Self::remove_witnesses(commit_tx.clone()))?.serialize()), + Some(false), + None, + None, + )? + .psbt; + + let reveal_psbt = Psbt::from_unsigned_tx(Self::remove_witnesses(reveal_tx.clone()))?; + return Ok(Some(Box::new(self.output( commit_tx.txid(), + Some(commit_psbt), reveal_tx.txid(), + Some(base64::engine::general_purpose::STANDARD.encode(reveal_psbt.serialize())), total_fees, self.inscriptions.clone(), )))); @@ -118,16 +133,28 @@ impl Batch { Ok(Some(Box::new(self.output( commit, + None, reveal, + None, total_fees, self.inscriptions.clone(), )))) } + fn remove_witnesses(mut transaction: Transaction) -> Transaction { + for txin in transaction.input.iter_mut() { + txin.witness = Witness::new(); + } + + transaction + } + fn output( &self, commit: Txid, + commit_psbt: Option, reveal: Txid, + reveal_psbt: Option, total_fees: u64, inscriptions: Vec, ) -> Output { @@ -174,7 +201,9 @@ impl Batch { Output { commit, + commit_psbt, reveal, + reveal_psbt, total_fees, parent: self.parent_info.clone().map(|info| info.id), inscriptions: inscriptions_output, @@ -266,9 +295,9 @@ impl Batch { reinscription = true; if self.reinscribe { continue; - } else { - bail!("sat at {} already inscribed", satpoint); } + + bail!("sat at {} already inscribed", satpoint); } if inscribed_satpoint.outpoint == satpoint.outpoint { diff --git a/tests/wallet/inscribe.rs b/tests/wallet/inscribe.rs index 51bb78222b..cd2fe38f43 100644 --- a/tests/wallet/inscribe.rs +++ b/tests/wallet/inscribe.rs @@ -416,20 +416,27 @@ fn inscribe_with_dry_run_flag() { bitcoin_rpc_server.mine_blocks(1); - CommandBuilder::new("wallet inscribe --dry-run --file degenerate.png --fee-rate 1") - .write("degenerate.png", [1; 520]) - .bitcoin_rpc_server(&bitcoin_rpc_server) - .ord_rpc_server(&ord_rpc_server) - .run_and_deserialize_output::(); + let inscribe = + CommandBuilder::new("wallet inscribe --dry-run --file degenerate.png --fee-rate 1") + .write("degenerate.png", [1; 520]) + .bitcoin_rpc_server(&bitcoin_rpc_server) + .ord_rpc_server(&ord_rpc_server) + .run_and_deserialize_output::(); + + assert!(inscribe.commit_psbt.is_some()); + assert!(inscribe.reveal_psbt.is_some()); assert!(bitcoin_rpc_server.mempool().is_empty()); - CommandBuilder::new("wallet inscribe --file degenerate.png --fee-rate 1") + let inscribe = CommandBuilder::new("wallet inscribe --file degenerate.png --fee-rate 1") .write("degenerate.png", [1; 520]) .bitcoin_rpc_server(&bitcoin_rpc_server) .ord_rpc_server(&ord_rpc_server) .run_and_deserialize_output::(); + assert!(inscribe.commit_psbt.is_none()); + assert!(inscribe.reveal_psbt.is_none()); + assert_eq!(bitcoin_rpc_server.mempool().len(), 2); }