What changed, and why it matters
This commit is a simple renaming of a field in the code from `value` to `amount` across many files. It does not change what the code does, how transactions are validated, or how bitcoins are counted. It is a cleanup change to match a proposed naming standard before the library reaches version 1.0.
No security action needed. Treat as a normal API-breaking refactor. Downstream users should update references from `txout.value` to `txout.amount` when upgrading.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch renames the public field TxOut::value to TxOut::amount in primitives/src/transaction.rs and updates all in-tree references, including examples, tests, consensus validation, sighash computation, PSBT handling, and serde helpers. The serialized transaction format is unchanged because the field still encodes the same Amount type in the same little-endian byte order. No logic, arithmetic, or security behavior is modified.
Changed components
primitives/src/transaction.rs (TxOut struct field name)bitcoin/src/blockdata/transaction.rsbitcoin/src/consensus_validation.rsbitcoin/src/crypto/sighash.rsbitcoin/src/psbt/mod.rsbitcoin examples and testsInspect captured patch +146 / −143
diff --git a/bitcoin/examples/ecdsa-psbt-simple.rs b/bitcoin/examples/ecdsa-psbt-simple.rs
index a7a6eee1..8c6139d8 100644
--- a/bitcoin/examples/ecdsa-psbt-simple.rs
+++ b/bitcoin/examples/ecdsa-psbt-simple.rs
@@ -109,7 +109,7 @@ fn dummy_unspent_transaction_outputs() -> Vec<(OutPoint, TxOut)> {
vout: 0,
};
- let utxo_1 = TxOut { value: DUMMY_UTXO_AMOUNT_INPUT_1, script_pubkey: script_pubkey_1 };
+ let utxo_1 = TxOut { amount: DUMMY_UTXO_AMOUNT_INPUT_1, script_pubkey: script_pubkey_1 };
let script_pubkey_2 = "bc1qy7swwpejlw7a2rp774pa8rymh8tw3xvd2x2xkd"
.parse::<Address<_>>()
@@ -123,7 +123,7 @@ fn dummy_unspent_transaction_outputs() -> Vec<(OutPoint, TxOut)> {
vout: 1,
};
- let utxo_2 = TxOut { value: DUMMY_UTXO_AMOUNT_INPUT_2, script_pubkey: script_pubkey_2 };
+ let utxo_2 = TxOut { amount: DUMMY_UTXO_AMOUNT_INPUT_2, script_pubkey: script_pubkey_2 };
vec![(out_point_1, utxo_1), (out_point_2, utxo_2)]
}
@@ -165,11 +165,11 @@ fn main() {
.collect();
// The spend output is locked to a key controlled by the receiver.
- let spend = TxOut { value: SPEND_AMOUNT, script_pubkey: address.script_pubkey() };
+ let spend = TxOut { amount: SPEND_AMOUNT, script_pubkey: address.script_pubkey() };
// The change output is locked to a key controlled by us.
let change = TxOut {
- value: CHANGE_AMOUNT,
+ amount: CHANGE_AMOUNT,
script_pubkey: ScriptPubKeyBuf::new_p2wpkh(pk_change.wpubkey_hash()), // Change comes back to us.
};
diff --git a/bitcoin/examples/ecdsa-psbt.rs b/bitcoin/examples/ecdsa-psbt.rs
index c2402514..d67d194c 100644
--- a/bitcoin/examples/ecdsa-psbt.rs
+++ b/bitcoin/examples/ecdsa-psbt.rs
@@ -51,7 +51,7 @@ const EXTENDED_MASTER_PRIVATE_KEY: &str = "tprv8ZgxMBicQKsPeSHZFZWT8zxie2dXWcwem
const INPUT_UTXO_TXID: &str = "295f06639cde6039bf0c3dbf4827f0e3f2b2c2b476408e2f9af731a8d7a9c7fb";
const INPUT_UTXO_VOUT: u32 = 0;
const INPUT_UTXO_SCRIPT_PUBKEY: &str = "00149891eeb8891b3e80a2a1ade180f143add23bf5de";
-const INPUT_UTXO_VALUE: &str = "50 BTC";
+const INPUT_UTXO_AMOUNT: &str = "50 BTC";
// Get this from the descriptor,
// "wpkh([97f17dca/0'/0'/0']02749483607dafb30c66bd93ece4474be65745ce538c2d70e8e246f17e7a4e0c0c)#m9n56cx0".
const INPUT_UTXO_DERIVATION_PATH: &str = "0h/0h/0h";
@@ -191,8 +191,8 @@ impl WatchOnly {
witness: Witness::default(),
}],
outputs: vec![
- TxOut { value: to_amount, script_pubkey: to_address.script_pubkey() },
- TxOut { value: change_amount, script_pubkey: change_address.script_pubkey() },
+ TxOut { amount: to_amount, script_pubkey: to_address.script_pubkey() },
+ TxOut { amount: change_amount, script_pubkey: change_address.script_pubkey() },
],
};
@@ -276,9 +276,9 @@ fn input_derivation_path() -> Result<DerivationPath> {
fn previous_output() -> TxOut {
let script_pubkey = ScriptPubKeyBuf::from_hex_no_length_prefix(INPUT_UTXO_SCRIPT_PUBKEY)
.expect("failed to parse input utxo scriptPubkey");
- let amount = INPUT_UTXO_VALUE.parse::<Amount>().expect("failed to parse input utxo value");
+ let amount = INPUT_UTXO_AMOUNT.parse::<Amount>().expect("failed to parse input utxo amount");
- TxOut { value: amount, script_pubkey }
+ TxOut { amount, script_pubkey }
}
struct Error(Box<dyn std::error::Error>);
diff --git a/bitcoin/examples/sighash.rs b/bitcoin/examples/sighash.rs
index e25f267c..cfa3f990 100644
--- a/bitcoin/examples/sighash.rs
+++ b/bitcoin/examples/sighash.rs
@@ -19,7 +19,7 @@ use hex_lit::hex;
///
/// * `raw_tx` - the spending tx hex
/// * `inp_idx` - the spending tx input index
-/// * `amount` - the ref tx output value in sats
+/// * `amount` - the ref tx output amount.
fn compute_sighash_p2wpkh(raw_tx: &[u8], inp_idx: usize, amount: Amount) {
let tx: Transaction = consensus::deserialize(raw_tx).unwrap();
let inp = &tx.inputs[inp_idx];
@@ -103,7 +103,7 @@ fn compute_sighash_legacy(raw_tx: &[u8], inp_idx: usize, script_pubkey_bytes_opt
///
/// * `raw_tx` - the spending tx hex
/// * `inp_idx` - the spending tx input index
-/// * `amount` - the ref tx output value in sats
+/// * `amount` - the ref tx output amount.
fn compute_sighash_p2wsh(raw_tx: &[u8], inp_idx: usize, amount: Amount) {
let tx: Transaction = consensus::deserialize(raw_tx).unwrap();
let inp = &tx.inputs[inp_idx];
@@ -145,12 +145,12 @@ fn sighash_p2wpkh() {
//vin:0
let inp_idx = 0;
- //output value from the referenced vout:0 from the referenced tx:
+ //output amount from the referenced vout:0 from the referenced tx:
//bitcoin-cli getrawtransaction 752d675b9cc0bd14e0bd23969effee0005ad6d7e550dcc832f0216c7ffd4e15c 3
- let ref_out_value = Amount::from_sat_u32(200000000);
+ let ref_out_amount = Amount::from_sat_u32(200000000);
println!("\nsighash_p2wpkh:");
- compute_sighash_p2wpkh(&raw_tx, inp_idx, ref_out_value);
+ compute_sighash_p2wpkh(&raw_tx, inp_idx, ref_out_amount);
}
fn sighash_p2sh_multisig_2x2() {
@@ -174,13 +174,13 @@ fn sighash_p2wsh_multisig_2x2() {
//bitcoin-cli decodescript 52210289da5da9d3700156db2d01e6362491733f6c886971791deda74b4e9d707190b2210323c437f30384498be79df2990ce5a8de00844e768c0ccce914335b6c26adea7352ae
//its ASM is 2 0289da5da9d3700156db2d01e6362491733f6c886971791deda74b4e9d707190b2 0323c437f30384498be79df2990ce5a8de00844e768c0ccce914335b6c26adea73 2 OP_CHECKMULTISIG
let raw_tx = hex!("010000000001011b9eb4122976fad8f809ee4cea8ac8d1c5b6b8e0d0f9f93327a5d78c9a3945280000000000ffffffff02ba3e0d00000000002200201c3b09401aaa7c9709d118a75d301bdb2180fb68b2e9b3ade8ad4ff7281780cfa586010000000000220020a41d0d894799879ca1bd88c1c3f1c2fd4b1592821cc3c5bfd5be5238b904b09f040047304402201c7563e876d67b5702aea5726cd202bf92d0b1dc52c4acd03435d6073e630bac022032b64b70d7fba0cb8be30b882ea06c5f8ec7288d113459dd5d3e294214e2c96201483045022100f532f7e3b8fd01a0edc86de4870db4e04858964d0a609df81deb99d9581e6c2e02206d9e9b6ab661176be8194faded62f518cdc6ee74dba919e0f35d77cff81f38e5014752210289da5da9d3700156db2d01e6362491733f6c886971791deda74b4e9d707190b2210323c437f30384498be79df2990ce5a8de00844e768c0ccce914335b6c26adea7352ae00000000");
- //For the witness transaction sighash computation, we need its referenced output's value from the original transaction:
+ //For the witness transaction sighash computation, we need its referenced output's amount from the original transaction:
//bitcoin-cli getrawtransaction 2845399a8cd7a52733f9f9d0e0b8b6c5d1c88aea4cee09f8d8fa762912b49e1b 3
- //we need vout 0 value in sats:
- let ref_out_value = Amount::from_sat_u32(968240);
+ //we need vout 0 amount:
+ let ref_out_amount = Amount::from_sat_u32(968240);
println!("\nsighash_p2wsh_multisig_2x2:");
- compute_sighash_p2wsh(&raw_tx, 0, ref_out_value);
+ compute_sighash_p2wsh(&raw_tx, 0, ref_out_amount);
}
fn sighash_p2ms_multisig_2x3() {
diff --git a/bitcoin/examples/sign-tx-segwit-v0.rs b/bitcoin/examples/sign-tx-segwit-v0.rs
index 2c347f97..778d8c38 100644
--- a/bitcoin/examples/sign-tx-segwit-v0.rs
+++ b/bitcoin/examples/sign-tx-segwit-v0.rs
@@ -39,11 +39,11 @@ fn main() {
};
// The spend output is locked to a key controlled by the receiver.
- let spend = TxOut { value: SPEND_AMOUNT, script_pubkey: address.script_pubkey() };
+ let spend = TxOut { amount: SPEND_AMOUNT, script_pubkey: address.script_pubkey() };
// The change output is locked to a key controlled by us.
let change = TxOut {
- value: CHANGE_AMOUNT,
+ amount: CHANGE_AMOUNT,
script_pubkey: ScriptPubKeyBuf::new_p2wpkh(wpkh), // Change comes back to us.
};
@@ -112,7 +112,7 @@ fn receivers_address() -> Address {
///
/// An utxo is described by the `OutPoint` (txid and index within the transaction that it was
/// created). Using the out point one can get the transaction by `txid` and using the `vout` get the
-/// transaction value and script pubkey (`TxOut`) of the utxo.
+/// transaction amount and script pubkey (`TxOut`) of the utxo.
///
/// This output is locked to keys that we control, in a real application this would be a valid
/// output taken from a transaction that appears in the chain.
@@ -124,7 +124,7 @@ fn dummy_unspent_transaction_output(wpkh: WPubkeyHash) -> (OutPoint, TxOut) {
vout: 0,
};
- let utxo = TxOut { value: DUMMY_UTXO_AMOUNT, script_pubkey };
+ let utxo = TxOut { amount: DUMMY_UTXO_AMOUNT, script_pubkey };
(out_point, utxo)
}
diff --git a/bitcoin/examples/sign-tx-taproot.rs b/bitcoin/examples/sign-tx-taproot.rs
index 71d7026c..00b1bb35 100644
--- a/bitcoin/examples/sign-tx-taproot.rs
+++ b/bitcoin/examples/sign-tx-taproot.rs
@@ -39,11 +39,11 @@ fn main() {
};
// The spend output is locked to a key controlled by the receiver.
- let spend = TxOut { value: SPEND_AMOUNT, script_pubkey: address.script_pubkey() };
+ let spend = TxOut { amount: SPEND_AMOUNT, script_pubkey: address.script_pubkey() };
// The change output is locked to a key controlled by us.
let change = TxOut {
- value: CHANGE_AMOUNT,
+ amount: CHANGE_AMOUNT,
script_pubkey: ScriptPubKeyBuf::new_p2tr(&secp, internal_key, None), // Change comes back to us.
};
@@ -107,7 +107,7 @@ fn receivers_address() -> Address {
///
/// An utxo is described by the `OutPoint` (txid and index within the transaction that it was
/// created). Using the out point one can get the transaction by `txid` and using the `vout` get the
-/// transaction value and script pubkey (`TxOut`) of the utxo.
+/// transaction amount and script pubkey (`TxOut`) of the utxo.
///
/// This output is locked to keys that we control, in a real application this would be a valid
/// output taken from a transaction that appears in the chain.
@@ -123,7 +123,7 @@ fn dummy_unspent_transaction_output<C: Verification, K: Into<UntweakedPublicKey>
vout: 0,
};
- let utxo = TxOut { value: DUMMY_UTXO_AMOUNT, script_pubkey };
+ let utxo = TxOut { amount: DUMMY_UTXO_AMOUNT, script_pubkey };
(out_point, utxo)
}
diff --git a/bitcoin/examples/taproot-psbt-simple.rs b/bitcoin/examples/taproot-psbt-simple.rs
index 0ba490e1..64567851 100644
--- a/bitcoin/examples/taproot-psbt-simple.rs
+++ b/bitcoin/examples/taproot-psbt-simple.rs
@@ -119,7 +119,7 @@ fn dummy_unspent_transaction_outputs() -> Vec<(OutPoint, TxOut)> {
vout: 0,
};
- let utxo_1 = TxOut { value: DUMMY_UTXO_AMOUNT_INPUT_1, script_pubkey: script_pubkey_1 };
+ let utxo_1 = TxOut { amount: DUMMY_UTXO_AMOUNT_INPUT_1, script_pubkey: script_pubkey_1 };
let script_pubkey_2 = "bc1pfd0jmmdnp278vppcw68tkkmquxtq50xchy7f6wdmjtjm7fgsr8dszdcqce"
.parse::<Address<_>>()
@@ -133,7 +133,7 @@ fn dummy_unspent_transaction_outputs() -> Vec<(OutPoint, TxOut)> {
vout: 1,
};
- let utxo_2 = TxOut { value: DUMMY_UTXO_AMOUNT_INPUT_2, script_pubkey: script_pubkey_2 };
+ let utxo_2 = TxOut { amount: DUMMY_UTXO_AMOUNT_INPUT_2, script_pubkey: script_pubkey_2 };
vec![(out_point_1, utxo_1), (out_point_2, utxo_2)]
}
@@ -185,11 +185,11 @@ fn main() {
.collect();
// The spend output is locked to a key controlled by the receiver.
- let spend = TxOut { value: SPEND_AMOUNT, script_pubkey: address.script_pubkey() };
+ let spend = TxOut { amount: SPEND_AMOUNT, script_pubkey: address.script_pubkey() };
// The change output is locked to a key controlled by us.
let change = TxOut {
- value: CHANGE_AMOUNT,
+ amount: CHANGE_AMOUNT,
script_pubkey: ScriptPubKeyBuf::new_p2tr(&secp, pk_change, None), // Change comes back to us.
};
diff --git a/bitcoin/examples/taproot-psbt.rs b/bitcoin/examples/taproot-psbt.rs
index c95bf16d..1f1f6781 100644
--- a/bitcoin/examples/taproot-psbt.rs
+++ b/bitcoin/examples/taproot-psbt.rs
@@ -118,8 +118,8 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
// Set these fields with valid data for the UTXO from step 5 above
UTXO_1,
vec![
- TxOut { value: amount_to_send, script_pubkey: to_address.script_pubkey() },
- TxOut { value: change_amount, script_pubkey: change_address.script_pubkey() },
+ TxOut { amount: amount_to_send, script_pubkey: to_address.script_pubkey() },
+ TxOut { amount: change_amount, script_pubkey: change_address.script_pubkey() },
],
)?);
println!(
@@ -257,7 +257,7 @@ fn generate_bip86_key_spend_tx(
let script_pubkey =
ScriptPubKeyBuf::from_hex_no_length_prefix(input_utxo.script_pubkey)
.expect("failed to parse input utxo scriptPubkey");
- Some(TxOut { value: from_amount, script_pubkey })
+ Some(TxOut { amount: from_amount, script_pubkey })
},
tap_key_origins: origins,
..Default::default()
@@ -272,7 +272,7 @@ fn generate_bip86_key_spend_tx(
let mut input_txouts = Vec::<TxOut>::new();
for input in [&input_utxo].iter() {
input_txouts.push(TxOut {
- value: input.amount,
+ amount: input.amount,
script_pubkey: ScriptPubKeyBuf::from_hex_no_length_prefix(input.script_pubkey)?,
});
}
@@ -330,7 +330,7 @@ fn generate_bip86_key_spend_tx(
let tx = psbt.extract_tx_unchecked_fee_rate();
tx.verify(|_| {
Some(TxOut {
- value: from_amount,
+ amount: from_amount,
script_pubkey: ScriptPubKeyBuf::from_hex_no_length_prefix(input_utxo.script_pubkey)
.unwrap(),
})
@@ -414,7 +414,7 @@ impl BenefactorWallet {
taproot_spend_info.internal_key(),
taproot_spend_info.merkle_root(),
);
- let value = (input_utxo.amount - ABSOLUTE_FEES)
+ let amount = (input_utxo.amount - ABSOLUTE_FEES)
.expect("ABSOLUTE_FEES must be set below input amount");
// Spend a normal BIP-0086-like output as an input in our inheritance funding transaction
@@ -422,7 +422,7 @@ impl BenefactorWallet {
&self.secp,
self.master_xpriv,
input_utxo,
- vec![TxOut { script_pubkey: script_pubkey.clone(), value }],
+ vec![TxOut { script_pubkey: script_pubkey.clone(), amount }],
)?;
// CREATOR + UPDATER
@@ -455,7 +455,7 @@ impl BenefactorWallet {
);
let input = Input {
- witness_utxo: { Some(TxOut { value, script_pubkey }) },
+ witness_utxo: { Some(TxOut { amount, script_pubkey }) },
tap_key_origins: origins,
tap_merkle_root: taproot_spend_info.merkle_root(),
sighash_type: Some(ty),
@@ -478,8 +478,8 @@ impl BenefactorWallet {
if let Some(ref spend_info) = self.current_spend_info.clone() {
let mut psbt = self.next_psbt.clone().expect("should have next_psbt");
let input = &mut psbt.inputs[0];
- let input_value = input.witness_utxo.as_ref().unwrap().value;
- let output_value = (input_value - ABSOLUTE_FEES).into_result()?;
+ let input_amount = input.witness_utxo.as_ref().unwrap().amount;
+ let output_amount = (input_amount - ABSOLUTE_FEES).into_result()?;
// We use some other derivation path in this example for our inheritance protocol. The important thing is to ensure
// that we use an unhardened path so we can make use of xpubs.
@@ -516,7 +516,7 @@ impl BenefactorWallet {
);
psbt.unsigned_tx.outputs =
- vec![TxOut { script_pubkey: output_script_pubkey.clone(), value: output_value }];
+ vec![TxOut { script_pubkey: output_script_pubkey.clone(), amount: output_amount }];
psbt.outputs = vec![Output::default()];
psbt.unsigned_tx.lock_time = absolute::LockTime::ZERO;
@@ -527,7 +527,7 @@ impl BenefactorWallet {
let hash = SighashCache::new(&psbt.unsigned_tx).taproot_key_spend_signature_hash(
0,
&sighash::Prevouts::All(&[TxOut {
- value: input_value,
+ amount: input_amount,
script_pubkey: prevout_script_pubkey,
}]),
sighash_type,
@@ -572,7 +572,7 @@ impl BenefactorWallet {
// EXTRACTOR
let tx = psbt.extract_tx_unchecked_fee_rate();
tx.verify(|_| {
- Some(TxOut { value: input_value, script_pubkey: output_script_pubkey.clone() })
+ Some(TxOut { amount: input_amount, script_pubkey: output_script_pubkey.clone() })
})
.expect("failed to verify transaction");
@@ -605,9 +605,9 @@ impl BenefactorWallet {
let input = Input {
witness_utxo: {
let script_pubkey = output_script_pubkey;
- let amount = output_value;
+ let amount = output_amount;
- Some(TxOut { value: amount, script_pubkey })
+ Some(TxOut { amount, script_pubkey })
},
tap_key_origins: origins,
tap_merkle_root: taproot_spend_info.merkle_root(),
@@ -648,13 +648,13 @@ impl BeneficiaryWallet {
lock_time: absolute::LockTime,
to_address: Address,
) -> Result<Transaction, Box<dyn std::error::Error>> {
- let input_value = psbt.inputs[0].witness_utxo.as_ref().unwrap().value;
+ let input_amount = psbt.inputs[0].witness_utxo.as_ref().unwrap().amount;
let input_script_pubkey =
psbt.inputs[0].witness_utxo.as_ref().unwrap().script_pubkey.clone();
psbt.unsigned_tx.lock_time = lock_time;
psbt.unsigned_tx.outputs = vec![TxOut {
script_pubkey: to_address.script_pubkey(),
- value: (input_value - ABSOLUTE_FEES)
+ amount: (input_amount - ABSOLUTE_FEES)
.expect("ABSOLUTE_FEES must be set below input amount"),
}];
psbt.outputs = vec![Output::default()];
@@ -671,7 +671,7 @@ impl BeneficiaryWallet {
let hash = SighashCache::new(&unsigned_tx).taproot_script_spend_signature_hash(
0,
&sighash::Prevouts::All(&[TxOut {
- value: input_value,
+ amount: input_amount,
script_pubkey: input_script_pubkey.clone(),
}]),
*lh,
@@ -715,7 +715,7 @@ impl BeneficiaryWallet {
// EXTRACTOR
let tx = psbt.extract_tx_unchecked_fee_rate();
tx.verify(|_| {
- Some(TxOut { value: input_value, script_pubkey: input_script_pubkey.clone() })
+ Some(TxOut { amount: input_amount, script_pubkey: input_script_pubkey.clone() })
})
.expect("failed to verify transaction");
diff --git a/bitcoin/src/bip152.rs b/bitcoin/src/bip152.rs
index f8b10aa3..026d7e18 100644
--- a/bitcoin/src/bip152.rs
+++ b/bitcoin/src/bip152.rs
@@ -475,7 +475,7 @@ mod test {
sequence: Sequence(1),
witness: Witness::new(),
}],
- outputs: vec![TxOut { value: Amount::ONE_SAT, script_pubkey: ScriptPubKeyBuf::new() }],
+ outputs: vec![TxOut { amount: Amount::ONE_SAT, script_pubkey: ScriptPubKeyBuf::new() }],
}
}
diff --git a/bitcoin/src/blockdata/block.rs b/bitcoin/src/blockdata/block.rs
index a6f3e5f9..f085d684 100644
--- a/bitcoin/src/blockdata/block.rs
+++ b/bitcoin/src/blockdata/block.rs
@@ -811,7 +811,7 @@ mod tests {
sequence: Sequence::ENABLE_LOCKTIME_AND_RBF,
witness: Witness::new(),
}],
- outputs: vec![TxOut { value: Amount::ONE_BTC, script_pubkey: ScriptPubKeyBuf::new() }],
+ outputs: vec![TxOut { amount: Amount::ONE_BTC, script_pubkey: ScriptPubKeyBuf::new() }],
};
let transactions = vec![non_coinbase_tx];
@@ -887,7 +887,7 @@ mod tests {
sequence: Sequence::ENABLE_LOCKTIME_AND_RBF,
witness: Witness::new(),
}],
- outputs: vec![TxOut { value: Amount::ONE_BTC, script_pubkey: ScriptPubKeyBuf::new() }],
+ outputs: vec![TxOut { amount: Amount::ONE_BTC, script_pubkey: ScriptPubKeyBuf::new() }],
};
let invalid_coinbase_result = Block::new_checked(header, vec![non_coinbase_tx]);
diff --git a/bitcoin/src/blockdata/constants.rs b/bitcoin/src/blockdata/constants.rs
index cd5cc668..8e3f1c35 100644
--- a/bitcoin/src/blockdata/constants.rs
+++ b/bitcoin/src/blockdata/constants.rs
@@ -112,7 +112,7 @@ fn bitcoin_genesis_tx(params: &Params) -> Transaction {
witness: Witness::default(),
});
- ret.outputs.push(TxOut { value: Amount::FIFTY_BTC, script_pubkey: out_script });
+ ret.outputs.push(TxOut { amount: Amount::FIFTY_BTC, script_pubkey: out_script });
// end
ret
@@ -287,7 +287,7 @@ mod test {
assert_eq!(gen.outputs.len(), 1);
assert_eq!(serialize(&gen.outputs[0].script_pubkey),
hex!("434104678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5fac"));
- assert_eq!(gen.outputs[0].value, "50 BTC".parse::<Amount>().unwrap());
+ assert_eq!(gen.outputs[0].amount, "50 BTC".parse::<Amount>().unwrap());
assert_eq!(gen.lock_time, absolute::LockTime::ZERO);
assert_eq!(
diff --git a/bitcoin/src/blockdata/transaction.rs b/bitcoin/src/blockdata/transaction.rs
index 318d9fa7..59bc7084 100644
--- a/bitcoin/src/blockdata/transaction.rs
+++ b/bitcoin/src/blockdata/transaction.rs
@@ -186,10 +186,10 @@ internal_macros::define_extension_trait! {
///
/// [`minimal_non_dust_custom`]: TxOut::minimal_non_dust_custom
fn minimal_non_dust(script_pubkey: ScriptPubKeyBuf) -> TxOut {
- TxOut { value: script_pubkey.minimal_non_dust(), script_pubkey }
+ TxOut { amount: script_pubkey.minimal_non_dust(), script_pubkey }
}
- /// Constructs a new `TxOut` with given script and the smallest possible `value` that is **not** dust
+ /// Constructs a new `TxOut` with given script and the smallest possible `amount` that is **not** dust
/// per current Core policy.
///
/// Dust depends on the -dustrelayfee value of the Bitcoin Core node you are broadcasting to.
@@ -201,7 +201,7 @@ internal_macros::define_extension_trait! {
///
/// [`minimal_non_dust`]: TxOut::minimal_non_dust
fn minimal_non_dust_custom(script_pubkey: ScriptPubKeyBuf, dust_relay_fee: FeeRate) -> Option<TxOut> {
- Some(TxOut { value: script_pubkey.minimal_non_dust_custom(dust_relay_fee)?, script_pubkey })
+ Some(TxOut { amount: script_pubkey.minimal_non_dust_custom(dust_relay_fee)?, script_pubkey })
}
}
}
@@ -642,7 +642,7 @@ impl Decodable for Version {
}
}
-crate::internal_macros::impl_consensus_encoding!(TxOut, value, script_pubkey);
+internal_macros::impl_consensus_encoding!(TxOut, amount, script_pubkey);
impl Encodable for OutPoint {
fn consensus_encode<W: Write + ?Sized>(&self, w: &mut W) -> Result<usize, io::Error> {
diff --git a/bitcoin/src/consensus_validation.rs b/bitcoin/src/consensus_validation.rs
index 9d1c0beb..d4128b10 100644
--- a/bitcoin/src/consensus_validation.rs
+++ b/bitcoin/src/consensus_validation.rs
@@ -106,7 +106,7 @@ where
verify_script_with_flags(
&output.script_pubkey,
idx,
- output.value,
+ output.amount,
serialized_tx.as_slice(),
flags,
)?;
diff --git a/bitcoin/src/crypto/sighash.rs b/bitcoin/src/crypto/sighash.rs
index bad17a7c..442528ed 100644
--- a/bitcoin/src/crypto/sighash.rs
+++ b/bitcoin/src/crypto/sighash.rs
@@ -688,7 +688,7 @@ impl<R: Borrow<Transaction>> SighashCache<R> {
let txin = &self.tx.borrow().tx_in(input_index).map_err(SigningDataError::sighash)?;
let previous_output = prevouts.get(input_index).map_err(SigningDataError::sighash)?;
txin.previous_output.consensus_encode(writer)?;
- previous_output.value.consensus_encode(writer)?;
+ previous_output.amount.consensus_encode(writer)?;
previous_output.script_pubkey.consensus_encode(writer)?;
txin.sequence.consensus_encode(writer)?;
} else {
@@ -821,7 +821,7 @@ impl<R: Borrow<Transaction>> SighashCache<R> {
writer: &mut W,
input_index: usize,
script_code: &WitnessScript,
- value: Amount,
+ amount: Amount,
sighash_type: EcdsaSighashType,
) -> Result<(), SigningDataError<transaction::InputsIndexError>> {
let zero_hash = [0; 32];
@@ -849,7 +849,7 @@ impl<R: Borrow<Transaction>> SighashCache<R> {
let txin = &self.tx.borrow().tx_in(input_index).map_err(SigningDataError::sighash)?;
txin.previous_output.consensus_encode(writer)?;
script_code.consensus_encode(writer)?;
- value.consensus_encode(writer)?;
+ amount.consensus_encode(writer)?;
txin.sequence.consensus_encode(writer)?;
}
@@ -879,7 +879,7 @@ impl<R: Borrow<Transaction>> SighashCache<R> {
&mut self,
input_index: usize,
script_pubkey: &crate::script::Script<T>,
- value: Amount,
+ amount: Amount,
sighash_type: EcdsaSighashType,
) -> Result<SegwitV0Sighash, P2wpkhError> {
let script_code = script_pubkey.p2wpkh_script_code().ok_or(P2wpkhError::NotP2wpkhScript)?;
@@ -889,7 +889,7 @@ impl<R: Borrow<Transaction>> SighashCache<R> {
&mut enc,
input_index,
&script_code,
- value,
+ amount,
sighash_type,
)
.map_err(SigningDataError::unwrap_sighash)?;
@@ -904,7 +904,7 @@ impl<R: Borrow<Transaction>> SighashCache<R> {
&mut self,
input_index: usize,
witness_script: &WitnessScript,
- value: Amount,
+ amount: Amount,
sighash_type: EcdsaSighashType,
) -> Result<SegwitV0Sighash, transaction::InputsIndexError> {
let mut enc = SegwitV0Sighash::engine();
@@ -912,7 +912,7 @@ impl<R: Borrow<Transaction>> SighashCache<R> {
&mut enc,
input_index,
witness_script,
- value,
+ amount,
sighash_type,
)
.map_err(SigningDataError::unwrap_sighash)?;
@@ -1127,7 +1127,7 @@ impl<R: Borrow<Transaction>> SighashCache<R> {
let mut enc_amounts = sha256::Hash::engine();
let mut enc_script_pubkeys = sha256::Hash::engine();
for prevout in prevouts {
- prevout.borrow().value.consensus_encode(&mut enc_amounts).unwrap();
+ prevout.borrow().amount.consensus_encode(&mut enc_amounts).unwrap();
prevout.borrow().script_pubkey.consensus_encode(&mut enc_script_pubkeys).unwrap();
}
TaprootCache {
@@ -1548,7 +1548,7 @@ mod tests {
extern crate serde_json;
- const DUMMY_TXOUT: TxOut = TxOut { value: Amount::MIN, script_pubkey: ScriptPubKeyBuf::new() };
+ const DUMMY_TXOUT: TxOut = TxOut { amount: Amount::MIN, script_pubkey: ScriptPubKeyBuf::new() };
#[test]
fn sighash_single_bug() {
@@ -1895,7 +1895,7 @@ mod tests {
script_pubkey: ScriptPubKeyBuf,
#[serde(rename = "amountSats")]
#[serde(with = "crate::amount::serde::as_sat")]
- value: Amount,
+ amount: Amount,
}
#[derive(serde::Deserialize)]
@@ -1981,7 +1981,7 @@ mod tests {
.given
.utxos_spent
.into_iter()
- .map(|txo| TxOut { value: txo.value, script_pubkey: txo.script_pubkey })
+ .map(|txo| TxOut { amount: txo.amount, script_pubkey: txo.script_pubkey })
.collect::<Vec<_>>();
// Test intermediary
@@ -2097,15 +2097,16 @@ mod tests {
),
).unwrap();
+
let spk = ScriptPubKeyBuf::from_hex_no_length_prefix(
"00141d0f172a0ecb48aee1be1f2687d2963ae33f71a1",
)
.unwrap();
- let value = Amount::from_sat_u32(600_000_000);
+ let amount = Amount::from_sat_u32(600_000_000);
let mut cache = SighashCache::new(&tx);
assert_eq!(
- cache.p2wpkh_signature_hash(1, &spk, value, EcdsaSighashType::All).unwrap(),
+ cache.p2wpkh_signature_hash(1, &spk, amount, EcdsaSighashType::All).unwrap(),
"c37af31116d1b27caf68aae9e3ac82f1477929014d5b917657d0eb49478cb670"
.parse::<SegwitV0Sighash>()
.unwrap(),
@@ -2144,11 +2145,11 @@ mod tests {
"001479091972186c449eb1ded22b78e40d009bdf0089",
)
.unwrap();
- let value = Amount::from_sat_u32(1_000_000_000);
+ let amount = Amount::from_sat_u32(1_000_000_000);
let mut cache = SighashCache::new(&tx);
assert_eq!(
- cache.p2wpkh_signature_hash(0, &spk, value, EcdsaSighashType::All).unwrap(),
+ cache.p2wpkh_signature_hash(0, &spk, amount, EcdsaSighashType::All).unwrap(),
"64f3b0f4dd2bb3aa1ce8566d220cc74dda9df97d8490cc81d89d735c92e59fb6"
.parse::<SegwitV0Sighash>()
.unwrap(),
@@ -2194,16 +2195,16 @@ mod tests {
)
.unwrap();
- let value = Amount::from_sat_u32(987_654_321);
- (tx, witness_script, value)
+ let amount = Amount::from_sat_u32(987_654_321);
+ (tx, witness_script, amount)
}
#[test]
fn bip143_p2wsh_nested_in_p2sh_sighash_type_all() {
- let (tx, witness_script, value) = bip143_p2wsh_nested_in_p2sh_data();
+ let (tx, witness_script, amount) = bip143_p2wsh_nested_in_p2sh_data();
let mut cache = SighashCache::new(&tx);
assert_eq!(
- cache.p2wsh_signature_hash(0, &witness_script, value, EcdsaSighashType::All).unwrap(),
+ cache.p2wsh_signature_hash(0, &witness_script, amount, EcdsaSighashType::All).unwrap(),
"185c0be5263dce5b4bb50a047973c1b6272bfbd0103a89444597dc40b248ee7c"
.parse::<SegwitV0Sighash>()
.unwrap(),
@@ -2240,11 +2241,11 @@ mod tests {
fn $test_name() {
use EcdsaSighashType::*;
- let (tx, witness_script, value) = bip143_p2wsh_nested_in_p2sh_data();
+ let (tx, witness_script, amount) = bip143_p2wsh_nested_in_p2sh_data();
let mut cache = SighashCache::new(&tx);
assert_eq!(
cache
- .p2wsh_signature_hash(0, &witness_script, value, $sighash_type)
+ .p2wsh_signature_hash(0, &witness_script, amount, $sighash_type)
.unwrap(),
$sighash
.parse::<SegwitV0Sighash>()
diff --git a/bitcoin/src/psbt/mod.rs b/bitcoin/src/psbt/mod.rs
index 6dc89a99..9c20091f 100644
--- a/bitcoin/src/psbt/mod.rs
+++ b/bitcoin/src/psbt/mod.rs
@@ -192,7 +192,7 @@ impl Psbt {
let fee = match self.fee() {
Ok(fee) => fee,
Err(Error::MissingUtxo) =>
- return Err(ExtractTxError::MissingInputValue { tx: self.internal_extract_tx() }),
+ return Err(ExtractTxError::MissingInputAmount { tx: self.internal_extract_tx() }),
Err(Error::NegativeFee) => return Err(ExtractTxError::SendingTooMuch { psbt: self }),
Err(Error::FeeOverflow) =>
return Err(ExtractTxError::AbsurdFeeRate {
@@ -530,20 +530,20 @@ impl Psbt {
Ok((Message::from(sighash), hash_ty))
}
Wpkh => {
- let sighash = cache.p2wpkh_signature_hash(input_index, spk, utxo.value, hash_ty)?;
+ let sighash = cache.p2wpkh_signature_hash(input_index, spk, utxo.amount, hash_ty)?;
Ok((Message::from(sighash), hash_ty))
}
ShWpkh => {
let redeem_script = input.redeem_script.as_ref().expect("checked above");
let sighash =
- cache.p2wpkh_signature_hash(input_index, redeem_script, utxo.value, hash_ty)?;
+ cache.p2wpkh_signature_hash(input_index, redeem_script, utxo.amount, hash_ty)?;
Ok((Message::from(sighash), hash_ty))
}
Wsh | ShWsh => {
let witness_script =
input.witness_script.as_ref().ok_or(SignError::MissingWitnessScript)?;
let sighash = cache
- .p2wsh_signature_hash(input_index, witness_script, utxo.value, hash_ty)
+ .p2wsh_signature_hash(input_index, witness_script, utxo.amount, hash_ty)
.map_err(SignError::SegwitV0Sighash)?;
Ok((Message::from(sighash), hash_ty))
}
@@ -717,11 +717,11 @@ impl Psbt {
pub fn fee(&self) -> Result<Amount, Error> {
let mut inputs = Amount::ZERO;
for utxo in self.iter_funding_utxos() {
- inputs = inputs.checked_add(utxo?.value).ok_or(Error::FeeOverflow)?;
+ inputs = inputs.checked_add(utxo?.amount).ok_or(Error::FeeOverflow)?;
}
let mut outputs = Amount::ZERO;
for out in &self.unsigned_tx.outputs {
- outputs = outputs.checked_add(out.value).ok_or(Error::FeeOverflow)?;
+ outputs = outputs.checked_add(out.amount).ok_or(Error::FeeOverflow)?;
}
inputs.checked_sub(outputs).ok_or(Error::NegativeFee)
}
@@ -1151,12 +1151,12 @@ pub enum ExtractTxError {
/// The extracted [`Transaction`] (use this to ignore the error)
tx: Transaction,
},
- /// One or more of the inputs lacks value information (witness_utxo or non_witness_utxo)
- MissingInputValue {
+ /// One or more of the inputs lacks amount information (witness_utxo or non_witness_utxo)
+ MissingInputAmount {
/// The extracted [`Transaction`] (use this to ignore the error)
tx: Transaction,
},
- /// Input value is less than Output Value, and the [`Transaction`] would be invalid.
+ /// Input amount is less than output amount, and the [`Transaction`] would be invalid.
SendingTooMuch {
/// The original [`Psbt`] is returned untouched.
psbt: Psbt,
@@ -1177,13 +1177,13 @@ impl fmt::Display for ExtractTxError {
"an absurdly high fee rate of {} sat/kwu",
fee_rate.to_sat_per_kwu_floor()
),
- MissingInputValue { .. } => write!(
+ MissingInputAmount { .. } => write!(
f,
- "one of the inputs lacked value information (witness_utxo or non_witness_utxo)"
+ "one of the inputs lacked amount information (witness_utxo or non_witness_utxo)"
),
SendingTooMuch { .. } => write!(
f,
- "transaction would be invalid due to output value being greater than input value."
+ "transaction would be invalid due to output amount being greater than input amount."
),
}
}
@@ -1195,7 +1195,7 @@ impl std::error::Error for ExtractTxError {
use ExtractTxError::*;
match *self {
- AbsurdFeeRate { .. } | MissingInputValue { .. } | SendingTooMuch { .. } => None,
+ AbsurdFeeRate { .. } | MissingInputAmount { .. } | SendingTooMuch { .. } => None,
}
}
}
@@ -1360,7 +1360,7 @@ mod tests {
}
#[track_caller]
- fn psbt_with_values(input: u64, output: u64) -> Psbt {
+ fn psbt_with_amounts(input: u64, output: u64) -> Psbt {
Psbt {
unsigned_tx: Transaction {
version: transaction::Version::TWO,
@@ -1377,7 +1377,7 @@ mod tests {
witness: Witness::default(),
}],
outputs: vec![TxOut {
- value: Amount::from_sat(output).unwrap(),
+ amount: Amount::from_sat(output).unwrap(),
script_pubkey: ScriptPubKeyBuf::from_hex_no_length_prefix(
"a9143545e6e33b832c47050f24d3eeb93c9c03948bc787",
)
@@ -1391,7 +1391,7 @@ mod tests {
inputs: vec![Input {
witness_utxo: Some(TxOut {
- value: Amount::from_sat(input).unwrap(),
+ amount: Amount::from_sat(input).unwrap(),
script_pubkey: ScriptPubKeyBuf::from_hex_no_length_prefix(
"a914339725ba21efd62ac753a9bcd067d6c7a6a39d0587",
)
@@ -1433,7 +1433,7 @@ mod tests {
#[test]
fn psbt_high_fee_checks() {
- let psbt = psbt_with_values(Amount::MAX.to_sat(), 1000);
+ let psbt = psbt_with_amounts(Amount::MAX.to_sat(), 1000);
// We cannot create an expected fee rate to test against because `FeeRate::from_sat_per_mvb` is private.
// Large fee rate errors if we pass in 1 sat/vb so just use this to get the error fee rate returned.
@@ -1468,12 +1468,12 @@ mod tests {
// No one is using an ~50 BTC fee so if we can handle this
// then the `FeeRate` restrictions are fine for PSBT usage.
- let psbt = psbt_with_values(Amount::from_btc_u16(50).to_sat(), 1000); // fee = 50 BTC - 1000 sats
+ let psbt = psbt_with_amounts(Amount::from_btc_u16(50).to_sat(), 1000); // fee = 50 BTC - 1000 sats
assert!(psbt.extract_tx_with_fee_rate_limit(FeeRate::MAX).is_ok());
// Testing that extract_tx will error at 25k sat/vbyte (6250000 sat/kwu)
assert_eq!(
- psbt_with_values(2076001, 1000).extract_tx().map_err(|e| match e {
+ psbt_with_amounts(2076001, 1000).extract_tx().map_err(|e| match e {
ExtractTxError::AbsurdFeeRate { fee_rate, .. } => fee_rate,
_ => panic!(""),
}),
@@ -1482,7 +1482,7 @@ mod tests {
// Lowering the input satoshis by 1 lowers the sat/kwu by 3
// Putting it exactly at 25k sat/vbyte
- assert!(psbt_with_values(2076000, 1000).extract_tx().is_ok());
+ assert!(psbt_with_amounts(2076000, 1000).extract_tx().is_ok());
}
#[test]
@@ -1554,14 +1554,14 @@ mod tests {
}],
outputs: vec![
TxOut {
- value: Amount::from_sat_u32(99_999_699),
+ amount: Amount::from_sat_u32(99_999_699),
script_pubkey: ScriptPubKeyBuf::from_hex_no_length_prefix(
"76a914d0c59903c5bac2868760e90fd521a4665aa7652088ac",
)
.unwrap(),
},
TxOut {
- value: Amount::from_sat_u32(100_000_000),
+ amount: Amount::from_sat_u32(100_000_000),
script_pubkey: ScriptPubKeyBuf::from_hex_no_length_prefix(
"a9143545e6e33b832c47050f24d3eeb93c9c03948bc787",
)
@@ -1629,7 +1629,7 @@ mod tests {
)]),
}],
outputs: vec![TxOut {
- value: Amount::from_sat(190_303_501_938).unwrap(),
+ amount: Amount::from_sat(190_303_501_938).unwrap(),
script_pubkey: ScriptPubKeyBuf::from_hex_no_length_prefix(
"a914339725ba21efd62ac753a9bcd067d6c7a6a39d0587",
)
@@ -1681,7 +1681,7 @@ mod tests {
Input {
non_witness_utxo: Some(tx),
witness_utxo: Some(TxOut {
- value: Amount::from_sat(190_303_501_938).unwrap(),
+ amount: Amount::from_sat(190_303_501_938).unwrap(),
script_pubkey: ScriptPubKeyBuf::from_hex_no_length_prefix("a914339725ba21efd62ac753a9bcd067d6c7a6a39d0587").unwrap(),
}),
sighash_type: Some("SIGHASH_SINGLE|SIGHASH_ANYONECANPAY".parse::<PsbtSighashType>().unwrap()),
@@ -1806,11 +1806,11 @@ mod tests {
],
outputs: vec![
TxOut {
- value: Amount::from_sat_u32(99_999_699),
+ amount: Amount::from_sat_u32(99_999_699),
script_pubkey: ScriptPubKeyBuf::from_hex_no_length_prefix("76a914d0c59903c5bac2868760e90fd521a4665aa7652088ac").unwrap(),
},
TxOut {
- value: Amount::from_sat_u32(100_000_000),
+ amount: Amount::from_sat_u32(100_000_000),
script_pubkey: ScriptPubKeyBuf::from_hex_no_length_prefix("a9143545e6e33b832c47050f24d3eeb93c9c03948bc787").unwrap(),
},
],
@@ -1853,11 +1853,11 @@ mod tests {
],
outputs: vec![
TxOut {
- value: Amount::from_sat_u32(200_000_000),
+ amount: Amount::from_sat_u32(200_000_000),
script_pubkey: ScriptPubKeyBuf::from_hex_no_length_prefix("76a91485cff1097fd9e008bb34af709c62197b38978a4888ac").unwrap(),
},
TxOut {
- value: Amount::from_sat(190_303_501_938).unwrap(),
+ amount: Amount::from_sat(190_303_501_938).unwrap(),
script_pubkey: ScriptPubKeyBuf::from_hex_no_length_prefix("a914339725ba21efd62ac753a9bcd067d6c7a6a39d0587").unwrap(),
},
],
@@ -2167,11 +2167,12 @@ mod tests {
],
outputs: vec![
TxOut {
- value: Amount::from_sat_u32(99_999_699),
+ amount: Amount::from_sat_u32(99_999_699),
script_pubkey: ScriptPubKeyBuf::from_hex_no_length_prefix("76a914d0c59903c5bac2868760e90fd521a4665aa7652088ac").unwrap(),
},
TxOut {
- value: Amount::from_sat_u32(100_000_000),
+
+ amount: Amount::from_sat_u32(100_000_000),
script_pubkey: ScriptPubKeyBuf::from_hex_no_length_prefix("a9143545e6e33b832c47050f24d3eeb93c9c03948bc787").unwrap(),
},
],
@@ -2214,11 +2215,11 @@ mod tests {
],
outputs: vec![
TxOut {
- value: Amount::from_sat_u32(200_000_000),
+ amount: Amount::from_sat_u32(200_000_000),
script_pubkey: ScriptPubKeyBuf::from_hex_no_length_prefix("76a91485cff1097fd9e008bb34af709c62197b38978a4888ac").unwrap(),
},
TxOut {
- value: Amount::from_sat(190_303_501_938).unwrap(),
+ amount: Amount::from_sat(190_303_501_938).unwrap(),
script_pubkey: ScriptPubKeyBuf::from_hex_no_length_prefix("a914339725ba21efd62ac753a9bcd067d6c7a6a39d0587").unwrap(),
},
],
@@ -2465,11 +2466,11 @@ mod tests {
],
outputs: vec![
TxOut {
- value: output_0_val,
+ amount: output_0_val,
script_pubkey: ScriptPubKeyBuf::new()
},
TxOut {
- value: output_1_val,
+ amount: output_1_val,
script_pubkey: ScriptPubKeyBuf::new()
},
],
@@ -2504,11 +2505,11 @@ mod tests {
],
outputs: vec![
TxOut {
- value: prev_output_val,
+ amount: prev_output_val,
script_pubkey: ScriptPubKeyBuf::new()
},
TxOut {
- value: Amount::from_sat(190_303_501_938).unwrap(),
+ amount: Amount::from_sat(190_303_501_938).unwrap(),
script_pubkey: ScriptPubKeyBuf::new()
},
],
@@ -2538,7 +2539,7 @@ mod tests {
}
// negative fee
let mut t3 = t.clone();
- t3.unsigned_tx.outputs[0].value = prev_output_val;
+ t3.unsigned_tx.outputs[0].amount = prev_output_val;
match t3.fee().unwrap_err() {
Error::NegativeFee => {}
e => panic!("unexpected error: {:?}", e),
@@ -2555,13 +2556,13 @@ mod tests {
version: transaction::Version::TWO,
lock_time: locktime::absolute::LockTime::ZERO,
inputs: vec![TxIn::EMPTY_COINBASE],
- outputs: vec![TxOut { value: Amount::ZERO, script_pubkey: ScriptPubKeyBuf::new() }],
+ outputs: vec![TxOut { amount: Amount::ZERO, script_pubkey: ScriptPubKeyBuf::new() }],
};
let mut psbt = Psbt::from_unsigned_tx(tx).unwrap();
psbt.inputs[0].tap_internal_key = Some(internal_key);
psbt.inputs[0].witness_utxo = Some(transaction::TxOut {
- value: Amount::from_sat_u32(10),
+ amount: Amount::from_sat_u32(10),
script_pubkey: ScriptPubKeyBuf::new_p2tr(&secp, internal_key, None),
});
@@ -2588,13 +2589,13 @@ mod tests {
version: transaction::Version::TWO,
lock_time: locktime::absolute::LockTime::ZERO,
inputs: vec![TxIn::EMPTY_COINBASE],
- outputs: vec![TxOut { value: Amount::ZERO, script_pubkey: ScriptPubKeyBuf::new() }],
+ outputs: vec![TxOut { amount: Amount::ZERO, script_pubkey: ScriptPubKeyBuf::new() }],
};
let mut psbt = Psbt::from_unsigned_tx(tx).unwrap();
psbt.inputs[0].tap_internal_key = Some(internal_key);
psbt.inputs[0].witness_utxo = Some(transaction::TxOut {
- value: Amount::from_sat_u32(10),
+ amount: Amount::from_sat_u32(10),
script_pubkey: ScriptPubKeyBuf::new_p2tr(&secp, internal_key, None),
});
@@ -2618,7 +2619,8 @@ mod tests {
version: transaction::Version::TWO,
lock_time: absolute::LockTime::ZERO,
inputs: vec![TxIn::EMPTY_COINBASE, TxIn::EMPTY_COINBASE],
- outputs: vec![TxOut { value: Amount::ZERO, script_pubkey: ScriptPubKeyBuf::new() }],
+
+ outputs: vec![TxOut { amount: Amount::ZERO, script_pubkey: ScriptPubKeyBuf::new() }],
};
let mut psbt = Psbt::from_unsigned_tx(unsigned_tx).unwrap();
@@ -2631,7 +2633,7 @@ mod tests {
// First input we can spend. See comment above on key_map for why we use defaults here.
let txout_wpkh = TxOut {
- value: Amount::from_sat_u32(10),
+ amount: Amount::from_sat_u32(10),
script_pubkey: ScriptPubKeyBuf::new_p2wpkh(pk.wpubkey_hash().unwrap()),
};
psbt.inputs[0].witness_utxo = Some(txout_wpkh);
@@ -2643,7 +2645,7 @@ mod tests {
// Second input is unspendable by us e.g., from another wallet that supports future upgrades.
let unknown_prog = WitnessProgram::new(WitnessVersion::V4, &[0xaa; 34]).unwrap();
let txout_unknown_future = TxOut {
- value: Amount::from_sat_u32(10),
+ amount: Amount::from_sat_u32(10),
script_pubkey: ScriptPubKeyBuf::new_witness_program(&unknown_prog),
};
psbt.inputs[1].witness_utxo = Some(txout_unknown_future);
diff --git a/bitcoin/tests/bip_174.rs b/bitcoin/tests/bip_174.rs
index 69168ee7..7b1bab9a 100644
--- a/bitcoin/tests/bip_174.rs
+++ b/bitcoin/tests/bip_174.rs
@@ -182,13 +182,13 @@ fn create_transaction() -> Transaction {
],
outputs: vec![
TxOut {
- value: Amount::from_str_in(output_0.amount, Denomination::Bitcoin)
+ amount: Amount::from_str_in(output_0.amount, Denomination::Bitcoin)
.expect("failed to parse amount"),
script_pubkey: ScriptPubKeyBuf::from_hex_no_length_prefix(output_0.script_pubkey)
.expect("failed to parse script"),
},
TxOut {
- value: Amount::from_str_in(output_1.amount, Denomination::Bitcoin)
+ amount: Amount::from_str_in(output_1.amount, Denomination::Bitcoin)
.expect("failed to parse amount"),
script_pubkey: ScriptPubKeyBuf::from_hex_no_length_prefix(output_1.script_pubkey)
.expect("failed to parse script"),
diff --git a/bitcoin/tests/psbt-sign-taproot.rs b/bitcoin/tests/psbt-sign-taproot.rs
index 87d485b4..4d4356ac 100644
--- a/bitcoin/tests/psbt-sign-taproot.rs
+++ b/bitcoin/tests/psbt-sign-taproot.rs
@@ -200,9 +200,9 @@ fn create_psbt_for_taproot_key_path_spend(
to_address: Address,
tree: TaprootSpendInfo,
) -> Psbt {
- let send_value = 6400;
+ let send_amount = 6400;
let out_puts = vec![TxOut {
- value: Amount::from_sat(send_value).unwrap(),
+ amount: Amount::from_sat(send_amount).unwrap(),
script_pubkey: to_address.script_pubkey(),
}];
let prev_tx_id = "06980ca116f74c7845a897461dd0e1d15b114130176de5004957da516b4dee3a";
@@ -236,11 +236,11 @@ fn create_psbt_for_taproot_key_path_spend(
),
);
- let utxo_value = 6588;
+ let utxo_amount = 6588;
let mut input = Input {
witness_utxo: {
let script_pubkey = from_address.script_pubkey();
- Some(TxOut { value: Amount::from_sat(utxo_value).unwrap(), script_pubkey })
+ Some(TxOut { amount: Amount::from_sat(utxo_amount).unwrap(), script_pubkey })
},
tap_key_origins: origins,
..Default::default()
@@ -276,12 +276,12 @@ fn create_psbt_for_taproot_script_path_spend<K: Into<XOnlyPublicKey>>(
use_script: TapScriptBuf,
) -> Psbt {
let x_only_pubkey_of_signing_key = x_only_pubkey_of_signing_key.into();
- let utxo_value = 6280;
- let send_value = 6000;
+ let utxo_amount = 6280;
+ let send_amount = 6000;
let mfp = "73c5da0a";
let out_puts = vec![TxOut {
- value: Amount::from_sat(send_value).unwrap(),
+ amount: Amount::from_sat(send_amount).unwrap(),
script_pubkey: to_address.script_pubkey(),
}];
let prev_tx_id = "9d7c6770fca57285babab60c51834cfcfd10ad302119cae842d7216b4ac9a376";
@@ -320,7 +320,7 @@ fn create_psbt_for_taproot_script_path_spend<K: Into<XOnlyPublicKey>>(
let mut input = Input {
witness_utxo: {
let script_pubkey = from_address.script_pubkey();
- Some(TxOut { value: Amount::from_sat(utxo_value).unwrap(), script_pubkey })
+ Some(TxOut { amount: Amount::from_sat(utxo_amount).unwrap(), script_pubkey })
},
tap_key_origins: origins,
tap_scripts,
diff --git a/bitcoin/tests/serde.rs b/bitcoin/tests/serde.rs
index 0d4eeaa8..e39ec511 100644
--- a/bitcoin/tests/serde.rs
+++ b/bitcoin/tests/serde.rs
@@ -215,7 +215,7 @@ fn serde_regression_psbt() {
.unwrap()]),
}],
outputs: vec![TxOut {
- value: Amount::from_sat(190_303_501_938).unwrap(),
+ amount: Amount::from_sat(190_303_501_938).unwrap(),
script_pubkey: ScriptPubKeyBuf::from_hex_no_length_prefix(
"a914339725ba21efd62ac753a9bcd067d6c7a6a39d0587",
)
@@ -265,7 +265,7 @@ fn serde_regression_psbt() {
inputs: vec![Input {
non_witness_utxo: Some(tx),
witness_utxo: Some(TxOut {
- value: Amount::from_sat(190_303_501_938).unwrap(),
+ amount: Amount::from_sat(190_303_501_938).unwrap(),
script_pubkey: ScriptPubKeyBuf::from_hex_no_length_prefix("a914339725ba21efd62ac753a9bcd067d6c7a6a39d0587").unwrap(),
}),
sighash_type: Some(PsbtSighashType::from("SIGHASH_SINGLE|SIGHASH_ANYONECANPAY".parse::<EcdsaSighashType>().unwrap())),
diff --git a/primitives/src/transaction.rs b/primitives/src/transaction.rs
index 354ff75c..6ad06e53 100644
--- a/primitives/src/transaction.rs
+++ b/primitives/src/transaction.rs
@@ -267,7 +267,7 @@ fn hash_transaction(tx: &Transaction, uses_segwit_serialization: bool) -> sha256
enc.input(compact_size::encode(output_len).as_slice());
for output in &tx.outputs {
// Encode each output same as we do in `Encodable for TxOut`.
- enc.input(&output.value.to_sat().to_le_bytes());
+ enc.input(&output.amount.to_sat().to_le_bytes());
let script_pubkey_bytes = output.script_pubkey.as_bytes();
enc.input(compact_size::encode(script_pubkey_bytes.len()).as_slice());
@@ -347,8 +347,8 @@ impl TxIn {
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Debug, Hash)]
#[cfg(feature = "alloc")]
pub struct TxOut {
- /// The value of the output, in satoshis.
- pub value: Amount,
+ /// The value of the output.
+ pub amount: Amount,
/// The script which must be satisfied for the output to be spent.
pub script_pubkey: ScriptPubKeyBuf,
}
@@ -616,7 +616,7 @@ impl<'a> Arbitrary<'a> for TxIn {
#[cfg(feature = "alloc")]
impl<'a> Arbitrary<'a> for TxOut {
fn arbitrary(u: &mut Unstructured<'a>) -> arbitrary::Result<Self> {
- Ok(TxOut { value: Amount::arbitrary(u)?, script_pubkey: ScriptPubKeyBuf::arbitrary(u)? })
+ Ok(TxOut { amount: Amount::arbitrary(u)?, script_pubkey: ScriptPubKeyBuf::arbitrary(u)? })
}
}
@@ -690,7 +690,7 @@ mod tests {
};
let txout = TxOut {
- value: Amount::from_sat(123_456_789).unwrap(),
+ amount: Amount::from_sat(123_456_789).unwrap(),
script_pubkey: ScriptPubKeyBuf::new(),
};
@@ -704,9 +704,9 @@ mod tests {
// Test changing the transaction
let mut tx = tx_orig.clone();
tx.inputs[0].previous_output.txid = Txid::from_byte_array([0xFF; 32]);
- tx.outputs[0].value = Amount::from_sat(987_654_321).unwrap();
+ tx.outputs[0].amount = Amount::from_sat(987_654_321).unwrap();
assert_eq!(tx.inputs[0].previous_output.txid.to_byte_array(), [0xFF; 32]);
- assert_eq!(tx.outputs[0].value.to_sat(), 987_654_321);
+ assert_eq!(tx.outputs[0].amount.to_sat(), 987_654_321);
// Test uses_segwit_serialization
assert!(!tx.uses_segwit_serialization());
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.