Make capitalization of SegWit uniform in rustdocs
This commit is contained in:
parent
8d508e0deb
commit
3520e832ac
|
@ -11,7 +11,7 @@ fn main() {
|
|||
// This example derives root xprv from a 32-byte seed,
|
||||
// derives the child xprv with path m/84h/0h/0h,
|
||||
// prints out corresponding xpub,
|
||||
// calculates and prints out the first receiving segwit address.
|
||||
// calculates and prints out the first receiving SegWit address.
|
||||
// Run this example with cargo and seed(hex-encoded) argument:
|
||||
// cargo run --example bip32 7934c09359b234e076b9fa5a1abfd38e3dc2a9939745b7cc3c22a48d831d14bd
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@ use hex_lit::hex;
|
|||
|
||||
//run with: cargo run --example sighash
|
||||
|
||||
/// Computes segwit sighash for a transaction input that spends a p2wpkh output with "witness_v0_keyhash" scriptPubKey.type
|
||||
/// Computes SegWit sighash for a transaction input that spends a p2wpkh output with "witness_v0_keyhash" scriptPubKey.type
|
||||
///
|
||||
/// # Parameters
|
||||
///
|
||||
|
@ -98,7 +98,7 @@ fn compute_sighash_legacy(raw_tx: &[u8], inp_idx: usize, script_pubkey_bytes_opt
|
|||
}
|
||||
}
|
||||
|
||||
/// Computes sighash for a segwit multisig transaction input that spends a p2wsh output with "witness_v0_scripthash" scriptPubKey.type
|
||||
/// Computes sighash for a SegWit multisig transaction input that spends a p2wsh output with "witness_v0_scripthash" scriptPubKey.type
|
||||
///
|
||||
/// # Parameters
|
||||
///
|
||||
|
|
|
@ -78,7 +78,7 @@ impl std::error::Error for UnknownAddressTypeError {
|
|||
pub enum ParseError {
|
||||
/// Base58 legacy decoding error.
|
||||
Base58(Base58Error),
|
||||
/// Bech32 segwit decoding error.
|
||||
/// Bech32 SegWit decoding error.
|
||||
Bech32(Bech32Error),
|
||||
/// Address's network differs from required one.
|
||||
NetworkValidation(NetworkValidationError),
|
||||
|
@ -165,7 +165,7 @@ impl std::error::Error for NetworkValidationError {}
|
|||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
#[non_exhaustive]
|
||||
pub enum Bech32Error {
|
||||
/// Parse segwit Bech32 error.
|
||||
/// Parse SegWit Bech32 error.
|
||||
ParseBech32(ParseBech32Error),
|
||||
/// A witness version conversion/parsing error.
|
||||
WitnessVersion(witness_version::TryFromError),
|
||||
|
|
|
@ -254,7 +254,7 @@ pub enum AddressData {
|
|||
/// The script hash used to encumber outputs to this address.
|
||||
script_hash: ScriptHash,
|
||||
},
|
||||
/// Data encoded by a Segwit address.
|
||||
/// Data encoded by a SegWit address.
|
||||
Segwit {
|
||||
/// The witness program used to encumber outputs to this address.
|
||||
witness_program: WitnessProgram,
|
||||
|
@ -421,7 +421,7 @@ impl Address {
|
|||
|
||||
/// Constructs a new pay-to-witness-public-key-hash (P2WPKH) [`Address`] from a public key.
|
||||
///
|
||||
/// This is the native segwit address type for an output redeemable with a single signature.
|
||||
/// This is the native SegWit address type for an output redeemable with a single signature.
|
||||
pub fn p2wpkh(pk: CompressedPublicKey, hrp: impl Into<KnownHrp>) -> Self {
|
||||
let program = WitnessProgram::p2wpkh(pk);
|
||||
Address::from_witness_program(program, hrp)
|
||||
|
@ -430,7 +430,7 @@ impl Address {
|
|||
/// Constructs a new pay-to-script-hash (P2SH) [`Address`] that embeds a
|
||||
/// pay-to-witness-public-key-hash (P2WPKH).
|
||||
///
|
||||
/// This is a segwit address type that looks familiar (as p2sh) to legacy clients.
|
||||
/// This is a SegWit address type that looks familiar (as p2sh) to legacy clients.
|
||||
pub fn p2shwpkh(pk: CompressedPublicKey, network: impl Into<NetworkKind>) -> Address {
|
||||
let builder = script::Builder::new().push_int_unchecked(0).push_slice(pk.wpubkey_hash());
|
||||
let script_hash = builder.as_script().script_hash().expect("script is less than 520 bytes");
|
||||
|
@ -455,7 +455,7 @@ impl Address {
|
|||
/// Constructs a new pay-to-script-hash (P2SH) [`Address`] that embeds a
|
||||
/// pay-to-witness-script-hash (P2WSH).
|
||||
///
|
||||
/// This is a segwit address type that looks familiar (as p2sh) to legacy clients.
|
||||
/// This is a SegWit address type that looks familiar (as p2sh) to legacy clients.
|
||||
pub fn p2shwsh(
|
||||
witness_script: &Script,
|
||||
network: impl Into<NetworkKind>,
|
||||
|
@ -546,7 +546,7 @@ impl Address {
|
|||
}
|
||||
}
|
||||
|
||||
/// Gets the witness program for this address if this is a segwit address.
|
||||
/// Gets the witness program for this address if this is a SegWit address.
|
||||
pub fn witness_program(&self) -> Option<WitnessProgram> {
|
||||
use AddressInner::*;
|
||||
|
||||
|
@ -642,7 +642,7 @@ impl Address {
|
|||
/// Returns true if the given pubkey is directly related to the address payload.
|
||||
///
|
||||
/// This is determined by directly comparing the address payload with either the
|
||||
/// hash of the given public key or the segwit redeem hash generated from the
|
||||
/// hash of the given public key or the SegWit redeem hash generated from the
|
||||
/// given key. For Taproot addresses, the supplied key is assumed to be tweaked
|
||||
pub fn is_related_to_pubkey(&self, pubkey: PublicKey) -> bool {
|
||||
let pubkey_hash = pubkey.pubkey_hash();
|
||||
|
@ -684,7 +684,7 @@ impl Address {
|
|||
///
|
||||
/// - For p2sh, the payload is the script hash.
|
||||
/// - For p2pkh, the payload is the pubkey hash.
|
||||
/// - For segwit addresses, the payload is the witness program.
|
||||
/// - For SegWit addresses, the payload is the witness program.
|
||||
fn payload_as_bytes(&self) -> &[u8] {
|
||||
use AddressInner::*;
|
||||
match self.0 {
|
||||
|
@ -868,18 +868,18 @@ impl<V: NetworkValidation> fmt::Debug for Address<V> {
|
|||
|
||||
/// Address can be parsed only with `NetworkUnchecked`.
|
||||
///
|
||||
/// Only segwit bech32 addresses prefixed with `bc`, `bcrt` or `tb` and legacy base58 addresses
|
||||
/// Only SegWit bech32 addresses prefixed with `bc`, `bcrt` or `tb` and legacy base58 addresses
|
||||
/// prefixed with `1`, `2, `3`, `m` or `n` are supported.
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// - [`ParseError::Bech32`] if the segwit address begins with a `bc`, `bcrt` or `tb` and is not a
|
||||
/// - [`ParseError::Bech32`] if the SegWit address begins with a `bc`, `bcrt` or `tb` and is not a
|
||||
/// valid bech32 address.
|
||||
///
|
||||
/// - [`ParseError::Base58`] if the legacy address begins with a `1`, `2`, `3`, `m` or `n` and is
|
||||
/// not a valid base58 address.
|
||||
///
|
||||
/// - [`UnknownHrpError`] if the address does not begin with one of the above segwit or
|
||||
/// - [`UnknownHrpError`] if the address does not begin with one of the above SegWit or
|
||||
/// legacy prifixes.
|
||||
impl FromStr for Address<NetworkUnchecked> {
|
||||
type Err = ParseError;
|
||||
|
@ -899,7 +899,7 @@ impl FromStr for Address<NetworkUnchecked> {
|
|||
}
|
||||
}
|
||||
|
||||
/// Convert a byte array of a pubkey hash into a segwit redeem hash
|
||||
/// Convert a byte array of a pubkey hash into a SegWit redeem hash
|
||||
fn segwit_redeem_hash(pubkey_hash: PubkeyHash) -> hash160::Hash {
|
||||
let mut sha_engine = hash160::Hash::engine();
|
||||
sha_engine.input(&[0, 20]);
|
||||
|
@ -1099,9 +1099,9 @@ mod tests {
|
|||
Some(AddressType::P2tr),
|
||||
),
|
||||
// Related to future extensions, addresses are valid but have no type
|
||||
// segwit v1 and len != 32
|
||||
// SegWit v1 and len != 32
|
||||
("bc1pw508d6qejxtdg4y5r3zarvary0c5xw7kw508d6qejxtdg4y5r3zarvary0c5xw7kt5nd6y", None),
|
||||
// segwit v2
|
||||
// SegWit v2
|
||||
("bc1zw508d6qejxtdg4y5r3zarvaryvaxxpcs", None),
|
||||
];
|
||||
for (address, expected_type) in &addresses {
|
||||
|
|
|
@ -190,7 +190,7 @@ pub(super) fn new_witness_program_unchecked<T: AsRef<PushBytes>>(
|
|||
) -> ScriptBuf {
|
||||
let program = program.as_ref();
|
||||
debug_assert!(program.len() >= 2 && program.len() <= 40);
|
||||
// In segwit v0, the program must be 20 or 32 bytes long.
|
||||
// In SegWit v0, the program must be 20 or 32 bytes long.
|
||||
debug_assert!(version != WitnessVersion::V0 || program.len() == 20 || program.len() == 32);
|
||||
Builder::new().push_opcode(version.into()).push_slice(program).into_script()
|
||||
}
|
||||
|
|
|
@ -172,7 +172,7 @@ crate::internal_macros::define_extension_trait! {
|
|||
instructions.next().is_none()
|
||||
}
|
||||
|
||||
/// Checks whether a script pubkey is a Segregated Witness (segwit) program.
|
||||
/// Checks whether a script pubkey is a Segregated Witness (SegWit) program.
|
||||
#[inline]
|
||||
fn is_witness_program(&self) -> bool { self.witness_version().is_some() }
|
||||
|
||||
|
|
|
@ -672,7 +672,7 @@ fn script_ord() {
|
|||
fn test_bitcoinconsensus() {
|
||||
use crate::consensus_validation::ScriptExt as _;
|
||||
|
||||
// a random segwit transaction from the blockchain using native segwit
|
||||
// a random SegWit transaction from the blockchain using native SegWit
|
||||
let spent_bytes = hex!("0020701a8d401c84fb13e6baf169d59684e17abd9fa216c8cc5b9fc63d622ff8c58d");
|
||||
let spent = Script::from_bytes(&spent_bytes);
|
||||
let spending = hex!("010000000001011f97548fbbe7a0db7588a66e18d803d0089315aa7d4cc28360b6ec50ef36718a0100000000ffffffff02df1776000000000017a9146c002a686959067f4866b8fb493ad7970290ab728757d29f0000000000220020701a8d401c84fb13e6baf169d59684e17abd9fa216c8cc5b9fc63d622ff8c58d04004730440220565d170eed95ff95027a69b313758450ba84a01224e1f7f130dda46e94d13f8602207bdd20e307f062594022f12ed5017bbf4a055a06aea91c10110a0e3bb23117fc014730440220647d2dc5b15f60bc37dc42618a370b2a1490293f9e5c8464f53ec4fe1dfe067302203598773895b4b16d37485cbe21b337f4e4b650739880098c592553add7dd4355016952210375e00eb72e29da82b89367947f29ef34afb75e8654f6ea368e0acdfd92976b7c2103a1b26313f430c4b15bb1fdce663207659d8cac749a0e53d70eff01874496feff2103c96d495bfdd5ba4145e3e046fee45e84a8a48ad05bd8dbb395c011a32cf9f88053ae00000000");
|
||||
|
|
|
@ -31,7 +31,7 @@ pub const MAX_SIZE: usize = 40;
|
|||
/// number, therefore we carry the version number around along with the program bytes.
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||
pub struct WitnessProgram {
|
||||
/// The segwit version associated with this witness program.
|
||||
/// The SegWit version associated with this witness program.
|
||||
version: WitnessVersion,
|
||||
/// The witness program (between 2 and 40 bytes).
|
||||
program: ArrayVec<u8, MAX_SIZE>,
|
||||
|
@ -47,7 +47,7 @@ impl WitnessProgram {
|
|||
return Err(InvalidLength(program_len));
|
||||
}
|
||||
|
||||
// Specific segwit v0 check. These addresses can never spend funds sent to them.
|
||||
// Specific SegWit v0 check. These addresses can never spend funds sent to them.
|
||||
if version == WitnessVersion::V0 && (program_len != 20 && program_len != 32) {
|
||||
return Err(InvalidSegwitV0Length(program_len));
|
||||
}
|
||||
|
|
|
@ -115,8 +115,8 @@ crate::internal_macros::define_extension_trait! {
|
|||
Weight::from_non_witness_data_size(self.base_size().to_u64())
|
||||
}
|
||||
|
||||
/// The weight of the TxIn when it's included in a segwit transaction (i.e., a transaction
|
||||
/// having at least one segwit input).
|
||||
/// The weight of the TxIn when it's included in a SegWit transaction (i.e., a transaction
|
||||
/// having at least one SegWit input).
|
||||
///
|
||||
/// This always takes into account the witness, even when empty, in which
|
||||
/// case 1WU for the witness length varint (`00`) is included.
|
||||
|
@ -125,7 +125,7 @@ crate::internal_macros::define_extension_trait! {
|
|||
/// might increase more than `TxIn::segwit_weight`. This happens when:
|
||||
/// - the new input added causes the input length `VarInt` to increase its encoding length
|
||||
/// - the new input is the first segwit input added - this will add an additional 2WU to the
|
||||
/// transaction weight to take into account the segwit marker
|
||||
/// transaction weight to take into account the SegWit marker
|
||||
fn segwit_weight(&self) -> Weight {
|
||||
Weight::from_non_witness_data_size(self.base_size().to_u64())
|
||||
+ Weight::from_witness_data_size(self.witness.size().to_u64())
|
||||
|
@ -220,7 +220,7 @@ pub trait TransactionExt: sealed::Sealed {
|
|||
#[deprecated(since = "0.31.0", note = "use `compute_txid()` instead")]
|
||||
fn txid(&self) -> Txid;
|
||||
|
||||
/// Computes the segwit version of the transaction id.
|
||||
/// Computes the SegWit version of the transaction id.
|
||||
#[deprecated(since = "0.31.0", note = "use `compute_wtxid()` instead")]
|
||||
fn wtxid(&self) -> Wtxid;
|
||||
|
||||
|
@ -234,13 +234,13 @@ pub trait TransactionExt: sealed::Sealed {
|
|||
/// multiplied by three plus the with-witness consensus-serialized size.
|
||||
///
|
||||
/// For transactions with no inputs, this function will return a value 2 less than the actual
|
||||
/// weight of the serialized transaction. The reason is that zero-input transactions, post-segwit,
|
||||
/// weight of the serialized transaction. The reason is that zero-input transactions, post-SegWit,
|
||||
/// cannot be unambiguously serialized; we make a choice that adds two extra bytes. For more
|
||||
/// details see [BIP 141](https://github.com/bitcoin/bips/blob/master/bip-0141.mediawiki)
|
||||
/// which uses a "input count" of `0x00` as a `marker` for a Segwit-encoded transaction.
|
||||
/// which uses a "input count" of `0x00` as a `marker` for a SegWit-encoded transaction.
|
||||
///
|
||||
/// If you need to use 0-input transactions, we strongly recommend you do so using the PSBT
|
||||
/// API. The unsigned transaction encoded within PSBT is always a non-segwit transaction
|
||||
/// API. The unsigned transaction encoded within PSBT is always a non-SegWit transaction
|
||||
/// and can therefore avoid this ambiguity.
|
||||
fn weight(&self) -> Weight;
|
||||
|
||||
|
@ -320,7 +320,7 @@ pub trait TransactionExt: sealed::Sealed {
|
|||
/// The `spent` parameter is a closure/function that looks up the output being spent by each input
|
||||
/// It takes in an [`OutPoint`] and returns a [`TxOut`]. If you can't provide this, a placeholder of
|
||||
/// `|_| None` can be used. Without access to the previous [`TxOut`], any sigops in a redeemScript (P2SH)
|
||||
/// as well as any segwit sigops will not be counted for that input.
|
||||
/// as well as any SegWit sigops will not be counted for that input.
|
||||
fn total_sigop_cost<S>(&self, spent: S) -> usize
|
||||
where
|
||||
S: FnMut(&OutPoint) -> Option<TxOut>;
|
||||
|
@ -452,12 +452,12 @@ trait TransactionExtPriv {
|
|||
/// `count_p2sh_sigops` and `count_witness_sigops` respectively).
|
||||
fn count_p2pk_p2pkh_sigops(&self) -> usize;
|
||||
|
||||
/// Does not include wrapped segwit (see `count_witness_sigops`).
|
||||
/// Does not include wrapped SegWit (see `count_witness_sigops`).
|
||||
fn count_p2sh_sigops<S>(&self, spent: &mut S) -> usize
|
||||
where
|
||||
S: FnMut(&OutPoint) -> Option<TxOut>;
|
||||
|
||||
/// Includes wrapped segwit (returns 0 for Taproot spends).
|
||||
/// Includes wrapped SegWit (returns 0 for Taproot spends).
|
||||
fn count_witness_sigops<S>(&self, spent: &mut S) -> usize
|
||||
where
|
||||
S: FnMut(&OutPoint) -> Option<TxOut>;
|
||||
|
@ -471,7 +471,7 @@ impl TransactionExtPriv for Transaction {
|
|||
fn count_p2pk_p2pkh_sigops(&self) -> usize {
|
||||
let mut count: usize = 0;
|
||||
for input in &self.input {
|
||||
// 0 for p2wpkh, p2wsh, and p2sh (including wrapped segwit).
|
||||
// 0 for p2wpkh, p2wsh, and p2sh (including wrapped SegWit).
|
||||
count = count.saturating_add(input.script_sig.count_sigops_legacy());
|
||||
}
|
||||
for output in &self.output {
|
||||
|
@ -480,7 +480,7 @@ impl TransactionExtPriv for Transaction {
|
|||
count
|
||||
}
|
||||
|
||||
/// Does not include wrapped segwit (see `count_witness_sigops`).
|
||||
/// Does not include wrapped SegWit (see `count_witness_sigops`).
|
||||
fn count_p2sh_sigops<S>(&self, spent: &mut S) -> usize
|
||||
where
|
||||
S: FnMut(&OutPoint) -> Option<TxOut>,
|
||||
|
@ -505,7 +505,7 @@ impl TransactionExtPriv for Transaction {
|
|||
count
|
||||
}
|
||||
|
||||
/// Includes wrapped segwit (returns 0 for Taproot spends).
|
||||
/// Includes wrapped SegWit (returns 0 for Taproot spends).
|
||||
fn count_witness_sigops<S>(&self, spent: &mut S) -> usize
|
||||
where
|
||||
S: FnMut(&OutPoint) -> Option<TxOut>,
|
||||
|
@ -712,7 +712,7 @@ impl Encodable for Transaction {
|
|||
len += self.input.consensus_encode(w)?;
|
||||
len += self.output.consensus_encode(w)?;
|
||||
} else {
|
||||
// BIP-141 (segwit) transaction serialization also includes marker, flag, and witness data.
|
||||
// BIP-141 (SegWit) transaction serialization also includes marker, flag, and witness data.
|
||||
len += SEGWIT_MARKER.consensus_encode(w)?;
|
||||
len += SEGWIT_FLAG.consensus_encode(w)?;
|
||||
len += self.input.consensus_encode(w)?;
|
||||
|
@ -732,7 +732,7 @@ impl Decodable for Transaction {
|
|||
) -> Result<Self, encode::Error> {
|
||||
let version = Version::consensus_decode_from_finite_reader(r)?;
|
||||
let input = Vec::<TxIn>::consensus_decode_from_finite_reader(r)?;
|
||||
// segwit
|
||||
// SegWit
|
||||
if input.is_empty() {
|
||||
let segwit_flag = u8::consensus_decode_from_finite_reader(r)?;
|
||||
match segwit_flag {
|
||||
|
@ -759,7 +759,7 @@ impl Decodable for Transaction {
|
|||
// We don't support anything else
|
||||
x => Err(encode::ParseError::UnsupportedSegwitFlag(x).into()),
|
||||
}
|
||||
// non-segwit
|
||||
// non-SegWit
|
||||
} else {
|
||||
Ok(Transaction {
|
||||
version,
|
||||
|
@ -1416,7 +1416,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn txid() {
|
||||
// segwit tx from Liquid integration tests, txid/hash from Core decoderawtransaction
|
||||
// SegWit tx from Liquid integration tests, txid/hash from Core decoderawtransaction
|
||||
let tx_bytes = hex!(
|
||||
"01000000000102ff34f95a672bb6a4f6ff4a7e90fa8c7b3be7e70ffc39bc99be3bda67942e836c00000000\
|
||||
23220020cde476664d3fa347b8d54ef3aee33dcb686a65ced2b5207cbf4ec5eda6b9b46e4f414d4c934ad8\
|
||||
|
@ -1460,7 +1460,7 @@ mod tests {
|
|||
assert_eq!(format!("{:.10x}", tx.compute_txid()), "9652aa62b0");
|
||||
assert_eq!(tx.weight(), Weight::from_wu(2718));
|
||||
|
||||
// non-segwit tx from my mempool
|
||||
// non-SegWit tx from my mempool
|
||||
let tx_bytes = hex!(
|
||||
"01000000010c7196428403d8b0c88fcb3ee8d64f56f55c8973c9ab7dd106bb4f3527f5888d000000006a47\
|
||||
30440220503a696f55f2c00eee2ac5e65b17767cd88ed04866b5637d3c1d5d996a70656d02202c9aff698f\
|
||||
|
@ -1551,7 +1551,7 @@ mod tests {
|
|||
use crate::consensus_validation::{TransactionExt as _, TxVerifyError};
|
||||
use crate::witness::Witness;
|
||||
|
||||
// a random recent segwit transaction from blockchain using both old and segwit inputs
|
||||
// a random recent SegWit transaction from blockchain using both old and SegWit inputs
|
||||
let mut spending: Transaction = deserialize(hex!("020000000001031cfbc8f54fbfa4a33a30068841371f80dbfe166211242213188428f437445c91000000006a47304402206fbcec8d2d2e740d824d3d36cc345b37d9f65d665a99f5bd5c9e8d42270a03a8022013959632492332200c2908459547bf8dbf97c65ab1a28dec377d6f1d41d3d63e012103d7279dfb90ce17fe139ba60a7c41ddf605b25e1c07a4ddcb9dfef4e7d6710f48feffffff476222484f5e35b3f0e43f65fc76e21d8be7818dd6a989c160b1e5039b7835fc00000000171600140914414d3c94af70ac7e25407b0689e0baa10c77feffffffa83d954a62568bbc99cc644c62eb7383d7c2a2563041a0aeb891a6a4055895570000000017160014795d04cc2d4f31480d9a3710993fbd80d04301dffeffffff06fef72f000000000017a91476fd7035cd26f1a32a5ab979e056713aac25796887a5000f00000000001976a914b8332d502a529571c6af4be66399cd33379071c588ac3fda0500000000001976a914fc1d692f8de10ae33295f090bea5fe49527d975c88ac522e1b00000000001976a914808406b54d1044c429ac54c0e189b0d8061667e088ac6eb68501000000001976a914dfab6085f3a8fb3e6710206a5a959313c5618f4d88acbba20000000000001976a914eb3026552d7e3f3073457d0bee5d4757de48160d88ac0002483045022100bee24b63212939d33d513e767bc79300051f7a0d433c3fcf1e0e3bf03b9eb1d70220588dc45a9ce3a939103b4459ce47500b64e23ab118dfc03c9caa7d6bfc32b9c601210354fd80328da0f9ae6eef2b3a81f74f9a6f66761fadf96f1d1d22b1fd6845876402483045022100e29c7e3a5efc10da6269e5fc20b6a1cb8beb92130cc52c67e46ef40aaa5cac5f0220644dd1b049727d991aece98a105563416e10a5ac4221abac7d16931842d5c322012103960b87412d6e169f30e12106bdf70122aabb9eb61f455518322a18b920a4dfa887d30700")
|
||||
.as_slice()).unwrap();
|
||||
let spent1: Transaction = deserialize(hex!("020000000001040aacd2c49f5f3c0968cfa8caf9d5761436d95385252e3abb4de8f5dcf8a582f20000000017160014bcadb2baea98af0d9a902e53a7e9adff43b191e9feffffff96cd3c93cac3db114aafe753122bd7d1afa5aa4155ae04b3256344ecca69d72001000000171600141d9984579ceb5c67ebfbfb47124f056662fe7adbfeffffffc878dd74d3a44072eae6178bb94b9253177db1a5aaa6d068eb0e4db7631762e20000000017160014df2a48cdc53dae1aba7aa71cb1f9de089d75aac3feffffffe49f99275bc8363f5f593f4eec371c51f62c34ff11cc6d8d778787d340d6896c0100000017160014229b3b297a0587e03375ab4174ef56eeb0968735feffffff03360d0f00000000001976a9149f44b06f6ee92ddbc4686f71afe528c09727a5c788ac24281b00000000001976a9140277b4f68ff20307a2a9f9b4487a38b501eb955888ac227c0000000000001976a9148020cd422f55eef8747a9d418f5441030f7c9c7788ac0247304402204aa3bd9682f9a8e101505f6358aacd1749ecf53a62b8370b97d59243b3d6984f02200384ad449870b0e6e89c92505880411285ecd41cf11e7439b973f13bad97e53901210205b392ffcb83124b1c7ce6dd594688198ef600d34500a7f3552d67947bbe392802473044022033dfd8d190a4ae36b9f60999b217c775b96eb10dee3a1ff50fb6a75325719106022005872e4e36d194e49ced2ebcf8bb9d843d842e7b7e0eb042f4028396088d292f012103c9d7cbf369410b090480de2aa15c6c73d91b9ffa7d88b90724614b70be41e98e0247304402207d952de9e59e4684efed069797e3e2d993e9f98ec8a9ccd599de43005fe3f713022076d190cc93d9513fc061b1ba565afac574e02027c9efbfa1d7b71ab8dbb21e0501210313ad44bc030cc6cb111798c2bf3d2139418d751c1e79ec4e837ce360cc03b97a024730440220029e75edb5e9413eb98d684d62a077b17fa5b7cc19349c1e8cc6c4733b7b7452022048d4b9cae594f03741029ff841e35996ef233701c1ea9aa55c301362ea2e2f68012103590657108a72feb8dc1dec022cf6a230bb23dc7aaa52f4032384853b9f8388baf9d20700")
|
||||
|
@ -1693,15 +1693,15 @@ mod tests {
|
|||
fn txin_txout_weight() {
|
||||
// [(is_segwit, tx_hex, expected_weight)]
|
||||
let txs = [
|
||||
// one segwit input (P2WPKH)
|
||||
// one SegWit input (P2WPKH)
|
||||
(true, "020000000001018a763b78d3e17acea0625bf9e52b0dc1beb2241b2502185348ba8ff4a253176e0100000000ffffffff0280d725000000000017a914c07ed639bd46bf7087f2ae1dfde63b815a5f8b488767fda20300000000160014869ec8520fa2801c8a01bfdd2e82b19833cd0daf02473044022016243edad96b18c78b545325aaff80131689f681079fb107a67018cb7fb7830e02205520dae761d89728f73f1a7182157f6b5aecf653525855adb7ccb998c8e6143b012103b9489bde92afbcfa85129a82ffa512897105d1a27ad9806bded27e0532fc84e700000000", Weight::from_wu(565)),
|
||||
// one segwit input (P2WSH)
|
||||
// one SegWit input (P2WSH)
|
||||
(true, "01000000000101a3ccad197118a2d4975fadc47b90eacfdeaf8268adfdf10ed3b4c3b7e1ad14530300000000ffffffff0200cc5501000000001976a91428ec6f21f4727bff84bb844e9697366feeb69f4d88aca2a5100d00000000220020701a8d401c84fb13e6baf169d59684e17abd9fa216c8cc5b9fc63d622ff8c58d04004730440220548f11130353b3a8f943d2f14260345fc7c20bde91704c9f1cbb5456355078cd0220383ed4ed39b079b618bcb279bbc1f2ca18cb028c4641cb522c9c5868c52a0dc20147304402203c332ecccb3181ca82c0600520ee51fee80d3b4a6ab110945e59475ec71e44ac0220679a11f3ca9993b04ccebda3c834876f353b065bb08f50076b25f5bb93c72ae1016952210375e00eb72e29da82b89367947f29ef34afb75e8654f6ea368e0acdfd92976b7c2103a1b26313f430c4b15bb1fdce663207659d8cac749a0e53d70eff01874496feff2103c96d495bfdd5ba4145e3e046fee45e84a8a48ad05bd8dbb395c011a32cf9f88053ae00000000", Weight::from_wu(766)),
|
||||
// one segwit input (P2WPKH) and two legacy inputs (P2PKH)
|
||||
// one SegWit input (P2WPKH) and two legacy inputs (P2PKH)
|
||||
(true, "010000000001036b6b6ac7e34e97c53c1cc74c99c7948af2e6aac75d8778004ae458d813456764000000006a473044022001deec7d9075109306320b3754188f81a8236d0d232b44bc69f8309115638b8f02204e17a5194a519cf994d0afeea1268740bdc10616b031a521113681cc415e815c012103488d3272a9fad78ee887f0684cb8ebcfc06d0945e1401d002e590c7338b163feffffffffc75bd7aa6424aee972789ec28ba181254ee6d8311b058d165bd045154d7660b0000000006b483045022100c8641bcbee3e4c47a00417875015d8c5d5ea918fb7e96f18c6ffe51bc555b401022074e2c46f5b1109cd79e39a9aa203eadd1d75356415e51d80928a5fb5feb0efee0121033504b4c6dfc3a5daaf7c425aead4c2dbbe4e7387ce8e6be2648805939ecf7054ffffffff494df3b205cd9430a26f8e8c0dc0bb80496fbc555a524d6ea307724bc7e60eee0100000000ffffffff026d861500000000001976a9145c54ed1360072ebaf56e87693b88482d2c6a101588ace407000000000000160014761e31e2629c6e11936f2f9888179d60a5d4c1f900000247304402201fa38a67a63e58b67b6cfffd02f59121ca1c8a1b22e1efe2573ae7e4b4f06c2b022002b9b431b58f6e36b3334fb14eaecee7d2f06967a77ef50d8d5f90dda1057f0c01210257dc6ce3b1100903306f518ee8fa113d778e403f118c080b50ce079fba40e09a00000000", Weight::from_wu(1755)),
|
||||
// three legacy inputs (P2PKH)
|
||||
(false, "0100000003e4d7be4314204a239d8e00691128dca7927e19a7339c7948bde56f669d27d797010000006b483045022100b988a858e2982e2daaf0755b37ad46775d6132057934877a5badc91dee2f66ff022020b967c1a2f0916007662ec609987e951baafa6d4fda23faaad70715611d6a2501210254a2dccd8c8832d4677dc6f0e562eaaa5d11feb9f1de2c50a33832e7c6190796ffffffff9e22eb1b3f24c260187d716a8a6c2a7efb5af14a30a4792a6eeac3643172379c000000006a47304402207df07f0cd30dca2cf7bed7686fa78d8a37fe9c2254dfdca2befed54e06b779790220684417b8ff9f0f6b480546a9e90ecee86a625b3ea1e4ca29b080da6bd6c5f67e01210254a2dccd8c8832d4677dc6f0e562eaaa5d11feb9f1de2c50a33832e7c6190796ffffffff1123df3bfb503b59769731da103d4371bc029f57979ebce68067768b958091a1000000006a47304402207a016023c2b0c4db9a7d4f9232fcec2193c2f119a69125ad5bcedcba56dd525e02206a734b3a321286c896759ac98ebfd9d808df47f1ce1fbfbe949891cc3134294701210254a2dccd8c8832d4677dc6f0e562eaaa5d11feb9f1de2c50a33832e7c6190796ffffffff0200c2eb0b000000001976a914e5eb3e05efad136b1405f5c2f9adb14e15a35bb488ac88cfff1b000000001976a9144846db516db3130b7a3c92253599edec6bc9630b88ac00000000", Weight::from_wu(2080)),
|
||||
// one segwit input (P2TR)
|
||||
// one SegWit input (P2TR)
|
||||
(true, "01000000000101b5cee87f1a60915c38bb0bc26aaf2b67be2b890bbc54bb4be1e40272e0d2fe0b0000000000ffffffff025529000000000000225120106daad8a5cb2e6fc74783714273bad554a148ca2d054e7a19250e9935366f3033760000000000002200205e6d83c44f57484fd2ef2a62b6d36cdcd6b3e06b661e33fd65588a28ad0dbe060141df9d1bfce71f90d68bf9e9461910b3716466bfe035c7dbabaa7791383af6c7ef405a3a1f481488a91d33cd90b098d13cb904323a3e215523aceaa04e1bb35cdb0100000000", Weight::from_wu(617)),
|
||||
// one legacy input (P2PKH)
|
||||
(false, "0100000001c336895d9fa674f8b1e294fd006b1ac8266939161600e04788c515089991b50a030000006a47304402204213769e823984b31dcb7104f2c99279e74249eacd4246dabcf2575f85b365aa02200c3ee89c84344ae326b637101a92448664a8d39a009c8ad5d147c752cbe112970121028b1b44b4903c9103c07d5a23e3c7cf7aeb0ba45ddbd2cfdce469ab197381f195fdffffff040000000000000000536a4c5058325bb7b7251cf9e36cac35d691bd37431eeea426d42cbdecca4db20794f9a4030e6cb5211fabf887642bcad98c9994430facb712da8ae5e12c9ae5ff314127d33665000bb26c0067000bb0bf00322a50c300000000000017a9145ca04fdc0a6d2f4e3f67cfeb97e438bb6287725f8750c30000000000001976a91423086a767de0143523e818d4273ddfe6d9e4bbcc88acc8465003000000001976a914c95cbacc416f757c65c942f9b6b8a20038b9b12988ac00000000", Weight::from_wu(1396)),
|
||||
|
@ -1724,7 +1724,7 @@ mod tests {
|
|||
+ tx.input.iter().fold(Weight::ZERO, |sum, i| sum + txin_weight(i))
|
||||
+ tx.output.iter().fold(Weight::ZERO, |sum, o| sum + o.weight());
|
||||
|
||||
// The empty tx uses segwit serialization but a legacy tx does not.
|
||||
// The empty tx uses SegWit serialization but a legacy tx does not.
|
||||
if !tx.uses_segwit_serialization() {
|
||||
calculated_weight -= Weight::from_wu(2);
|
||||
}
|
||||
|
|
|
@ -165,7 +165,7 @@ pub enum ParseError {
|
|||
NonMinimalVarInt,
|
||||
/// Parsing error.
|
||||
ParseFailed(&'static str),
|
||||
/// Unsupported Segwit flag.
|
||||
/// Unsupported SegWit flag.
|
||||
UnsupportedSegwitFlag(u8),
|
||||
}
|
||||
|
||||
|
|
|
@ -1093,7 +1093,7 @@ impl From<hex::HexToArrayError> for ParseCompressedPublicKeyError {
|
|||
fn from(e: hex::HexToArrayError) -> Self { Self::Hex(e) }
|
||||
}
|
||||
|
||||
/// Segwit public keys must always be compressed.
|
||||
/// SegWit public keys must always be compressed.
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
#[non_exhaustive]
|
||||
pub struct UncompressedPublicKeyError;
|
||||
|
|
|
@ -51,7 +51,7 @@ hash_newtype! {
|
|||
#[hash_newtype(forward)]
|
||||
pub struct LegacySighash(sha256d::Hash);
|
||||
|
||||
/// Hash of a transaction according to the segwit version 0 signature algorithm.
|
||||
/// Hash of a transaction according to the SegWit version 0 signature algorithm.
|
||||
#[hash_newtype(forward)]
|
||||
pub struct SegwitV0Sighash(sha256d::Hash);
|
||||
}
|
||||
|
@ -92,7 +92,7 @@ hashes::impl_serde_for_newtype!(TapSighash);
|
|||
|
||||
impl_message_from_hash!(TapSighash);
|
||||
|
||||
/// Efficiently calculates signature hash message for legacy, segwit and Taproot inputs.
|
||||
/// Efficiently calculates signature hash message for legacy, SegWit and Taproot inputs.
|
||||
#[derive(Debug)]
|
||||
pub struct SighashCache<T: Borrow<Transaction>> {
|
||||
/// Access to transaction required for transaction introspection. Moreover, type
|
||||
|
@ -100,17 +100,17 @@ pub struct SighashCache<T: Borrow<Transaction>> {
|
|||
/// the latter in particular is necessary for [`SighashCache::witness_mut`].
|
||||
tx: T,
|
||||
|
||||
/// Common cache for Taproot and segwit inputs, `None` for legacy inputs.
|
||||
/// Common cache for Taproot and SegWit inputs, `None` for legacy inputs.
|
||||
common_cache: Option<CommonCache>,
|
||||
|
||||
/// Cache for segwit v0 inputs (the result of another round of sha256 on `common_cache`).
|
||||
/// Cache for SegWit v0 inputs (the result of another round of sha256 on `common_cache`).
|
||||
segwit_cache: Option<SegwitCache>,
|
||||
|
||||
/// Cache for Taproot v1 inputs.
|
||||
taproot_cache: Option<TaprootCache>,
|
||||
}
|
||||
|
||||
/// Common values cached between segwit and Taproot inputs.
|
||||
/// Common values cached between SegWit and Taproot inputs.
|
||||
#[derive(Debug)]
|
||||
struct CommonCache {
|
||||
prevouts: sha256::Hash,
|
||||
|
@ -121,7 +121,7 @@ struct CommonCache {
|
|||
outputs: sha256::Hash,
|
||||
}
|
||||
|
||||
/// Values cached for segwit inputs, equivalent to [`CommonCache`] plus another round of `sha256`.
|
||||
/// Values cached for SegWit inputs, equivalent to [`CommonCache`] plus another round of `sha256`.
|
||||
#[derive(Debug)]
|
||||
struct SegwitCache {
|
||||
prevouts: sha256d::Hash,
|
||||
|
@ -859,8 +859,8 @@ impl<R: Borrow<Transaction>> SighashCache<R> {
|
|||
|
||||
/// Computes the BIP143 sighash to spend a p2wpkh transaction for any flag type.
|
||||
///
|
||||
/// `script_pubkey` is the `scriptPubkey` (native segwit) of the spend transaction
|
||||
/// ([`TxOut::script_pubkey`]) or the `redeemScript` (wrapped segwit).
|
||||
/// `script_pubkey` is the `scriptPubkey` (native SegWit) of the spend transaction
|
||||
/// ([`TxOut::script_pubkey`]) or the `redeemScript` (wrapped SegWit).
|
||||
pub fn p2wpkh_signature_hash(
|
||||
&mut self,
|
||||
input_index: usize,
|
||||
|
@ -1150,9 +1150,9 @@ impl<R: BorrowMut<Transaction>> SighashCache<R> {
|
|||
/// *sighasher.witness_mut(input_index).unwrap() = Witness::p2wpkh(&signature, &pk);
|
||||
/// ```
|
||||
///
|
||||
/// For full signing code see the [`segwit v0`] and [`taproot`] signing examples.
|
||||
/// For full signing code see the [`SegWit v0`] and [`taproot`] signing examples.
|
||||
///
|
||||
/// [`segwit v0`]: <https://github.com/rust-bitcoin/rust-bitcoin/blob/master/bitcoin/examples/sign-tx-segwit-v0.rs>
|
||||
/// [`SegWit v0`]: <https://github.com/rust-bitcoin/rust-bitcoin/blob/master/bitcoin/examples/sign-tx-segwit-v0.rs>
|
||||
/// [`taproot`]: <https://github.com/rust-bitcoin/rust-bitcoin/blob/master/bitcoin/examples/sign-tx-taproot.rs>
|
||||
pub fn witness_mut(&mut self, input_index: usize) -> Option<&mut Witness> {
|
||||
self.tx.borrow_mut().input.get_mut(input_index).map(|i| &mut i.witness)
|
||||
|
|
|
@ -18,7 +18,7 @@ use super::constants::{MAX_BLOCK_SIGOPS_COST, WITNESS_SCALE_FACTOR};
|
|||
/// Maximum weight of a transaction for it to be relayed by most nodes on the network
|
||||
pub const MAX_STANDARD_TX_WEIGHT: u32 = 400_000;
|
||||
|
||||
/// Minimum non-witness size for a standard transaction (1 segwit input + 1 P2WPKH output = 82 bytes)
|
||||
/// Minimum non-witness size for a standard transaction (1 SegWit input + 1 P2WPKH output = 82 bytes)
|
||||
pub const MIN_STANDARD_TX_NONWITNESS_SIZE: u32 = 82;
|
||||
|
||||
/// Maximum number of sigops in a standard tx.
|
||||
|
|
|
@ -69,11 +69,11 @@ const PSBT_IN_PROPRIETARY: u64 = 0xFC;
|
|||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||
pub struct Input {
|
||||
/// The non-witness transaction this input spends from. Should only be
|
||||
/// `Option::Some` for inputs which spend non-segwit outputs or
|
||||
/// if it is unknown whether an input spends a segwit output.
|
||||
/// `Option::Some` for inputs which spend non-SegWit outputs or
|
||||
/// if it is unknown whether an input spends a SegWit output.
|
||||
pub non_witness_utxo: Option<Transaction>,
|
||||
/// The transaction output this input spends from. Should only be
|
||||
/// `Option::Some` for inputs which spend segwit outputs,
|
||||
/// `Option::Some` for inputs which spend SegWit outputs,
|
||||
/// including P2SH embedded ones.
|
||||
pub witness_utxo: Option<TxOut>,
|
||||
/// A map from public keys to their corresponding signature as would be
|
||||
|
|
|
@ -669,7 +669,7 @@ impl Psbt {
|
|||
let utxo = self.spend_utxo(input_index)?;
|
||||
let spk = utxo.script_pubkey.clone();
|
||||
|
||||
// Anything that is not segwit and is not p2sh is `Bare`.
|
||||
// Anything that is not SegWit and is not p2sh is `Bare`.
|
||||
if !(spk.is_witness_program() || spk.is_p2sh()) {
|
||||
return Ok(OutputType::Bare);
|
||||
}
|
||||
|
@ -897,11 +897,11 @@ pub enum OutputType {
|
|||
Wpkh,
|
||||
/// A pay-to-witness-script-hash output (P2WSH).
|
||||
Wsh,
|
||||
/// A nested segwit output, pay-to-witness-pubkey-hash nested in a pay-to-script-hash.
|
||||
/// A nested SegWit output, pay-to-witness-pubkey-hash nested in a pay-to-script-hash.
|
||||
ShWpkh,
|
||||
/// A nested segwit output, pay-to-witness-script-hash nested in a pay-to-script-hash.
|
||||
/// A nested SegWit output, pay-to-witness-script-hash nested in a pay-to-script-hash.
|
||||
ShWsh,
|
||||
/// A pay-to-script-hash output excluding wrapped segwit (P2SH).
|
||||
/// A pay-to-script-hash output excluding wrapped SegWit (P2SH).
|
||||
Sh,
|
||||
/// A Taproot output (P2TR).
|
||||
Tr,
|
||||
|
@ -954,7 +954,7 @@ pub enum SignError {
|
|||
NotEcdsa,
|
||||
/// The `scriptPubkey` is not a P2WPKH script.
|
||||
NotWpkh,
|
||||
/// Sighash computation error (segwit v0 input).
|
||||
/// Sighash computation error (SegWit v0 input).
|
||||
SegwitV0Sighash(transaction::InputsIndexError),
|
||||
/// Sighash computation error (p2wpkh input).
|
||||
P2wpkhSighash(sighash::P2wpkhError),
|
||||
|
|
|
@ -16,7 +16,7 @@ fn do_test(data: &[u8]) {
|
|||
}
|
||||
let no_witness_len = bitcoin::consensus::encode::serialize(&tx).len();
|
||||
// For 0-input transactions, `no_witness_len` will be incorrect because
|
||||
// we serialize as segwit even after "stripping the witnesses". We need
|
||||
// we serialize as SegWit even after "stripping the witnesses". We need
|
||||
// to drop two bytes (i.e. eight weight). Similarly, calculated_weight is
|
||||
// incorrect and needs 2 wu removing for the marker/flag bytes.
|
||||
if tx.input.is_empty() {
|
||||
|
|
|
@ -48,7 +48,7 @@ use crate::witness::Witness;
|
|||
/// ### Serialization notes
|
||||
///
|
||||
/// If any inputs have nonempty witnesses, the entire transaction is serialized
|
||||
/// in the post-BIP141 Segwit format which includes a list of witnesses. If all
|
||||
/// in the post-BIP141 SegWit format which includes a list of witnesses. If all
|
||||
/// inputs have empty witnesses, the transaction is serialized in the pre-BIP141
|
||||
/// format.
|
||||
///
|
||||
|
@ -58,22 +58,22 @@ use crate::witness::Witness;
|
|||
/// uses BIP141. (Ordinarily there is no conflict, since in PSBT transactions
|
||||
/// are always unsigned and therefore their inputs have empty witnesses.)
|
||||
///
|
||||
/// The specific ambiguity is that Segwit uses the flag bytes `0001` where an old
|
||||
/// The specific ambiguity is that SegWit uses the flag bytes `0001` where an old
|
||||
/// serializer would read the number of transaction inputs. The old serializer
|
||||
/// would interpret this as "no inputs, one output", which means the transaction
|
||||
/// is invalid, and simply reject it. Segwit further specifies that this encoding
|
||||
/// is invalid, and simply reject it. SegWit further specifies that this encoding
|
||||
/// should *only* be used when some input has a nonempty witness; that is,
|
||||
/// witness-less transactions should be encoded in the traditional format.
|
||||
///
|
||||
/// However, in protocols where transactions may legitimately have 0 inputs, e.g.
|
||||
/// when parties are cooperatively funding a transaction, the "00 means Segwit"
|
||||
/// heuristic does not work. Since Segwit requires such a transaction be encoded
|
||||
/// when parties are cooperatively funding a transaction, the "00 means SegWit"
|
||||
/// heuristic does not work. Since SegWit requires such a transaction be encoded
|
||||
/// in the original transaction format (since it has no inputs and therefore
|
||||
/// no input witnesses), a traditionally encoded transaction may have the `0001`
|
||||
/// Segwit flag in it, which confuses most Segwit parsers including the one in
|
||||
/// SegWit flag in it, which confuses most SegWit parsers including the one in
|
||||
/// Bitcoin Core.
|
||||
///
|
||||
/// We therefore deviate from the spec by always using the Segwit witness encoding
|
||||
/// We therefore deviate from the spec by always using the SegWit witness encoding
|
||||
/// for 0-input transactions, which results in unambiguously parseable transactions.
|
||||
///
|
||||
/// ### A note on ordering
|
||||
|
@ -150,8 +150,8 @@ impl Transaction {
|
|||
|
||||
/// Computes the [`Txid`].
|
||||
///
|
||||
/// Hashes the transaction **excluding** the segwit data (i.e. the marker, flag bytes, and the
|
||||
/// witness fields themselves). For non-segwit transactions which do not have any segwit data,
|
||||
/// Hashes the transaction **excluding** the SegWit data (i.e. the marker, flag bytes, and the
|
||||
/// witness fields themselves). For non-SegWit transactions which do not have any SegWit data,
|
||||
/// this will be equal to [`Transaction::compute_wtxid()`].
|
||||
#[doc(alias = "txid")]
|
||||
pub fn compute_txid(&self) -> Txid {
|
||||
|
@ -159,10 +159,10 @@ impl Transaction {
|
|||
Txid::from_byte_array(hash.to_byte_array())
|
||||
}
|
||||
|
||||
/// Computes the segwit version of the transaction id.
|
||||
/// Computes the SegWit version of the transaction id.
|
||||
///
|
||||
/// Hashes the transaction **including** all segwit data (i.e. the marker, flag bytes, and the
|
||||
/// witness fields themselves). For non-segwit transactions which do not have any segwit data,
|
||||
/// Hashes the transaction **including** all SegWit data (i.e. the marker, flag bytes, and the
|
||||
/// witness fields themselves). For non-SegWit transactions which do not have any SegWit data,
|
||||
/// this will be equal to [`Transaction::compute_txid()`].
|
||||
#[doc(alias = "wtxid")]
|
||||
pub fn compute_wtxid(&self) -> Wtxid {
|
||||
|
@ -235,7 +235,7 @@ fn hash_transaction(tx: &Transaction, uses_segwit_serialization: bool) -> sha256
|
|||
enc.input(&tx.version.0.to_le_bytes()); // Same as `encode::emit_i32`.
|
||||
|
||||
if uses_segwit_serialization {
|
||||
// BIP-141 (segwit) transaction serialization also includes marker and flag.
|
||||
// BIP-141 (SegWit) transaction serialization also includes marker and flag.
|
||||
enc.input(&[SEGWIT_MARKER]);
|
||||
enc.input(&[SEGWIT_FLAG]);
|
||||
}
|
||||
|
@ -268,7 +268,7 @@ fn hash_transaction(tx: &Transaction, uses_segwit_serialization: bool) -> sha256
|
|||
}
|
||||
|
||||
if uses_segwit_serialization {
|
||||
// BIP-141 (segwit) transaction serialization also includes the witness data.
|
||||
// BIP-141 (SegWit) transaction serialization also includes the witness data.
|
||||
for input in &tx.input {
|
||||
// Same as `Encodable for Witness`.
|
||||
enc.input(compact_size::encode(input.witness.len()).as_slice());
|
||||
|
|
|
@ -13,7 +13,7 @@ use internals::compact_size;
|
|||
|
||||
use crate::prelude::Vec;
|
||||
|
||||
/// The Witness is the data used to unlock bitcoin since the [segwit upgrade].
|
||||
/// The Witness is the data used to unlock bitcoin since the [SegWit upgrade].
|
||||
///
|
||||
/// Can be logically seen as an array of bytestrings, i.e. `Vec<Vec<u8>>`, and it is serialized on the wire
|
||||
/// in that format. You can convert between this type and `Vec<Vec<u8>>` by using [`Witness::from_slice`]
|
||||
|
@ -22,7 +22,7 @@ use crate::prelude::Vec;
|
|||
/// For serialization and deserialization performance it is stored internally as a single `Vec`,
|
||||
/// saving some allocations.
|
||||
///
|
||||
/// [segwit upgrade]: <https://github.com/bitcoin/bips/blob/master/bip-0143.mediawiki>
|
||||
/// [SegWit upgrade]: <https://github.com/bitcoin/bips/blob/master/bip-0143.mediawiki>
|
||||
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||
pub struct Witness {
|
||||
/// Contains the witness `Vec<Vec<u8>>` serialization.
|
||||
|
|
Loading…
Reference in New Issue