Move TxIn to primitives
The `TxIn` has all public fields; move the `TxIn` to `primitives`.
This commit is contained in:
parent
ce0d517383
commit
4d37d7efc6
|
@ -32,7 +32,7 @@ use crate::{Amount, FeeRate, SignedAmount};
|
|||
|
||||
#[rustfmt::skip] // Keep public re-exports separate.
|
||||
#[doc(inline)]
|
||||
pub use primitives::transaction::{OutPoint, ParseOutPointError, Txid, Wtxid, Version};
|
||||
pub use primitives::transaction::{OutPoint, ParseOutPointError, Txid, Wtxid, Version, TxIn};
|
||||
|
||||
impl_hashencode!(Txid);
|
||||
impl_hashencode!(Wtxid);
|
||||
|
@ -89,46 +89,6 @@ crate::internal_macros::define_extension_trait! {
|
|||
const TX_IN_BASE_WEIGHT: Weight =
|
||||
Weight::from_vb_unwrap(OutPoint::SIZE as u64 + Sequence::SIZE as u64);
|
||||
|
||||
/// Bitcoin transaction input.
|
||||
///
|
||||
/// It contains the location of the previous transaction's output,
|
||||
/// that it spends and set of scripts that satisfy its spending
|
||||
/// conditions.
|
||||
///
|
||||
/// ### Bitcoin Core References
|
||||
///
|
||||
/// * [CTxIn definition](https://github.com/bitcoin/bitcoin/blob/345457b542b6a980ccfbc868af0970a6f91d1b82/src/primitives/transaction.h#L65)
|
||||
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Debug, Hash)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||
pub struct TxIn {
|
||||
/// The reference to the previous output that is being used as an input.
|
||||
pub previous_output: OutPoint,
|
||||
/// The script which pushes values on the stack which will cause
|
||||
/// the referenced output's script to be accepted.
|
||||
pub script_sig: ScriptBuf,
|
||||
/// The sequence number, which suggests to miners which of two
|
||||
/// conflicting transactions should be preferred, or 0xFFFFFFFF
|
||||
/// to ignore this feature. This is generally never used since
|
||||
/// the miner behavior cannot be enforced.
|
||||
pub sequence: Sequence,
|
||||
/// Witness data: an array of byte-arrays.
|
||||
/// Note that this field is *not* (de)serialized with the rest of the TxIn in
|
||||
/// Encodable/Decodable, as it is (de)serialized at the end of the full
|
||||
/// Transaction. It *is* (de)serialized with the rest of the TxIn in other
|
||||
/// (de)serialization routines.
|
||||
pub witness: Witness,
|
||||
}
|
||||
|
||||
impl TxIn {
|
||||
/// An empty transaction input with the previous output as for a coinbase transaction.
|
||||
pub const EMPTY_COINBASE: TxIn = TxIn {
|
||||
previous_output: OutPoint::COINBASE_PREVOUT,
|
||||
script_sig: ScriptBuf::new(),
|
||||
sequence: Sequence::MAX,
|
||||
witness: Witness::new(),
|
||||
};
|
||||
}
|
||||
|
||||
crate::internal_macros::define_extension_trait! {
|
||||
/// Extension functionality for the [`TxIn`] type.
|
||||
pub trait TxInExt impl for TxIn {
|
||||
|
@ -1310,18 +1270,6 @@ impl InputWeightPrediction {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "arbitrary")]
|
||||
impl<'a> Arbitrary<'a> for TxIn {
|
||||
fn arbitrary(u: &mut Unstructured<'a>) -> arbitrary::Result<Self> {
|
||||
Ok(TxIn {
|
||||
previous_output: OutPoint::arbitrary(u)?,
|
||||
script_sig: ScriptBuf::arbitrary(u)?,
|
||||
sequence: Sequence::arbitrary(u)?,
|
||||
witness: Witness::arbitrary(u)?,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "arbitrary")]
|
||||
impl<'a> Arbitrary<'a> for Transaction {
|
||||
fn arbitrary(u: &mut Unstructured<'a>) -> arbitrary::Result<Self> {
|
||||
|
|
|
@ -59,6 +59,7 @@ pub use self::{
|
|||
pub use self::{
|
||||
locktime::{absolute, relative},
|
||||
witness::Witness,
|
||||
transaction::TxIn,
|
||||
};
|
||||
|
||||
#[rustfmt::skip]
|
||||
|
|
|
@ -20,6 +20,55 @@ use internals::write_err;
|
|||
#[cfg(feature = "alloc")]
|
||||
use units::parse;
|
||||
|
||||
#[cfg(feature = "alloc")]
|
||||
use crate::script::ScriptBuf;
|
||||
#[cfg(feature = "alloc")]
|
||||
use crate::sequence::Sequence;
|
||||
#[cfg(feature = "alloc")]
|
||||
use crate::witness::Witness;
|
||||
|
||||
/// Bitcoin transaction input.
|
||||
///
|
||||
/// It contains the location of the previous transaction's output,
|
||||
/// that it spends and set of scripts that satisfy its spending
|
||||
/// conditions.
|
||||
///
|
||||
/// ### Bitcoin Core References
|
||||
///
|
||||
/// * [CTxIn definition](https://github.com/bitcoin/bitcoin/blob/345457b542b6a980ccfbc868af0970a6f91d1b82/src/primitives/transaction.h#L65)
|
||||
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Debug, Hash)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||
#[cfg(feature = "alloc")]
|
||||
pub struct TxIn {
|
||||
/// The reference to the previous output that is being used as an input.
|
||||
pub previous_output: OutPoint,
|
||||
/// The script which pushes values on the stack which will cause
|
||||
/// the referenced output's script to be accepted.
|
||||
pub script_sig: ScriptBuf,
|
||||
/// The sequence number, which suggests to miners which of two
|
||||
/// conflicting transactions should be preferred, or 0xFFFFFFFF
|
||||
/// to ignore this feature. This is generally never used since
|
||||
/// the miner behavior cannot be enforced.
|
||||
pub sequence: Sequence,
|
||||
/// Witness data: an array of byte-arrays.
|
||||
/// Note that this field is *not* (de)serialized with the rest of the TxIn in
|
||||
/// Encodable/Decodable, as it is (de)serialized at the end of the full
|
||||
/// Transaction. It *is* (de)serialized with the rest of the TxIn in other
|
||||
/// (de)serialization routines.
|
||||
pub witness: Witness,
|
||||
}
|
||||
|
||||
#[cfg(feature = "alloc")]
|
||||
impl TxIn {
|
||||
/// An empty transaction input with the previous output as for a coinbase transaction.
|
||||
pub const EMPTY_COINBASE: TxIn = TxIn {
|
||||
previous_output: OutPoint::COINBASE_PREVOUT,
|
||||
script_sig: ScriptBuf::new(),
|
||||
sequence: Sequence::MAX,
|
||||
witness: Witness::new(),
|
||||
};
|
||||
}
|
||||
|
||||
/// A reference to a transaction output.
|
||||
///
|
||||
/// ### Bitcoin Core References
|
||||
|
@ -199,6 +248,19 @@ impl fmt::Display for Version {
|
|||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fmt::Display::fmt(&self.0, f) }
|
||||
}
|
||||
|
||||
#[cfg(feature = "arbitrary")]
|
||||
#[cfg(feature = "alloc")]
|
||||
impl<'a> Arbitrary<'a> for TxIn {
|
||||
fn arbitrary(u: &mut Unstructured<'a>) -> arbitrary::Result<Self> {
|
||||
Ok(TxIn {
|
||||
previous_output: OutPoint::arbitrary(u)?,
|
||||
script_sig: ScriptBuf::arbitrary(u)?,
|
||||
sequence: Sequence::arbitrary(u)?,
|
||||
witness: Witness::arbitrary(u)?,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "arbitrary")]
|
||||
impl<'a> Arbitrary<'a> for OutPoint {
|
||||
fn arbitrary(u: &mut Unstructured<'a>) -> arbitrary::Result<Self> {
|
||||
|
|
Loading…
Reference in New Issue