diff --git a/src/subcommand/wallet/inscribe/batch.rs b/src/subcommand/wallet/inscribe/batch.rs index 7dc70420fb..24cdbc219e 100644 --- a/src/subcommand/wallet/inscribe/batch.rs +++ b/src/subcommand/wallet/inscribe/batch.rs @@ -282,7 +282,12 @@ impl Batch { let commit_tx_address = Address::p2tr_tweaked(taproot_spend_info.output_key(), chain.network()); - let total_postage = self.postage * u64::try_from(self.inscriptions.len()).unwrap(); + let total_postage = match self.mode { + Mode::SameSat => self.postage, + Mode::SharedOutput | Mode::SeparateOutputs => { + self.postage * u64::try_from(self.inscriptions.len()).unwrap() + } + }; let mut reveal_inputs = vec![OutPoint::null()]; let mut reveal_outputs = self @@ -291,8 +296,8 @@ impl Batch { .map(|destination| TxOut { script_pubkey: destination.script_pubkey(), value: match self.mode { - Mode::SeparateOutputs | Mode::SameSat => self.postage.to_sat(), - Mode::SharedOutput => total_postage.to_sat(), + Mode::SeparateOutputs => self.postage.to_sat(), + Mode::SharedOutput | Mode::SameSat => total_postage.to_sat(), }, }) .collect::>(); diff --git a/tests/wallet/inscribe.rs b/tests/wallet/inscribe.rs index d5ed2f7c44..13529e5549 100644 --- a/tests/wallet/inscribe.rs +++ b/tests/wallet/inscribe.rs @@ -1686,3 +1686,56 @@ fn batch_inscribe_with_sat_arg_fails_if_wrong_mode() { .expected_stderr("error: `sat` can only be set in `same-sat` mode\n") .run_and_extract_stdout(); } + +#[test] +fn batch_inscribe_with_fee_rate() { + let rpc_server = test_bitcoincore_rpc::spawn(); + create_wallet(&rpc_server); + rpc_server.mine_blocks(2); + + let set_fee_rate = 1.0; + + let output = CommandBuilder::new(format!("--index-sats wallet inscribe --fee-rate {set_fee_rate} --batch batch.yaml")) + .write("inscription.txt", "Hello World") + .write("tulip.png", [0; 555]) + .write("meow.wav", [0; 2048]) + .write( + "batch.yaml", + "mode: same-sat\nsat: 5000111111\ninscriptions:\n- file: inscription.txt\n- file: tulip.png\n- file: meow.wav\n" + ) + .rpc_server(&rpc_server) + .run_and_deserialize_output::(); + + let commit_tx = &rpc_server.mempool()[0]; + let mut fee = 0; + for input in &commit_tx.input { + fee += rpc_server + .get_utxo_amount(&input.previous_output) + .unwrap() + .to_sat(); + } + for output in &commit_tx.output { + fee -= output.value; + } + let fee_rate = fee as f64 / commit_tx.vsize() as f64; + pretty_assert_eq!(fee_rate, set_fee_rate); + + let reveal_tx = &rpc_server.mempool()[1]; + let mut fee = 0; + for input in &reveal_tx.input { + fee += &commit_tx.output[input.previous_output.vout as usize].value; + } + for output in &reveal_tx.output { + fee -= output.value; + } + let fee_rate = fee as f64 / reveal_tx.vsize() as f64; + pretty_assert_eq!(fee_rate, set_fee_rate); + + assert_eq!( + ord::FeeRate::try_from(set_fee_rate) + .unwrap() + .fee(commit_tx.vsize() + reveal_tx.vsize()) + .to_sat(), + output.total_fees + ); +}