Move TxOut to primitives
The `TxOut` has all public fields; move the `TxOut` to `primitives`.
This commit is contained in:
parent
4d37d7efc6
commit
003dc9cf4d
|
@ -32,7 +32,7 @@ use crate::{Amount, FeeRate, SignedAmount};
|
||||||
|
|
||||||
#[rustfmt::skip] // Keep public re-exports separate.
|
#[rustfmt::skip] // Keep public re-exports separate.
|
||||||
#[doc(inline)]
|
#[doc(inline)]
|
||||||
pub use primitives::transaction::{OutPoint, ParseOutPointError, Txid, Wtxid, Version, TxIn};
|
pub use primitives::transaction::{OutPoint, ParseOutPointError, Txid, Wtxid, Version, TxIn, TxOut};
|
||||||
|
|
||||||
impl_hashencode!(Txid);
|
impl_hashencode!(Txid);
|
||||||
impl_hashencode!(Wtxid);
|
impl_hashencode!(Wtxid);
|
||||||
|
@ -151,32 +151,6 @@ crate::internal_macros::define_extension_trait! {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Bitcoin transaction output.
|
|
||||||
///
|
|
||||||
/// Defines new coins to be created as a result of the transaction,
|
|
||||||
/// along with spending conditions ("script", aka "output script"),
|
|
||||||
/// which an input spending it must satisfy.
|
|
||||||
///
|
|
||||||
/// An output that is not yet spent by an input is called Unspent Transaction Output ("UTXO").
|
|
||||||
///
|
|
||||||
/// ### Bitcoin Core References
|
|
||||||
///
|
|
||||||
/// * [CTxOut definition](https://github.com/bitcoin/bitcoin/blob/345457b542b6a980ccfbc868af0970a6f91d1b82/src/primitives/transaction.h#L148)
|
|
||||||
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Debug, Hash)]
|
|
||||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
|
||||||
pub struct TxOut {
|
|
||||||
/// The value of the output, in satoshis.
|
|
||||||
pub value: Amount,
|
|
||||||
/// The script which must be satisfied for the output to be spent.
|
|
||||||
pub script_pubkey: ScriptBuf,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl TxOut {
|
|
||||||
/// This is used as a "null txout" in consensus signing code.
|
|
||||||
pub const NULL: Self =
|
|
||||||
TxOut { value: Amount::from_sat(0xffffffffffffffff), script_pubkey: ScriptBuf::new() };
|
|
||||||
}
|
|
||||||
|
|
||||||
crate::internal_macros::define_extension_trait! {
|
crate::internal_macros::define_extension_trait! {
|
||||||
/// Extension functionality for the [`TxOut`] type.
|
/// Extension functionality for the [`TxOut`] type.
|
||||||
pub trait TxOutExt impl for TxOut {
|
pub trait TxOutExt impl for TxOut {
|
||||||
|
@ -231,13 +205,6 @@ crate::internal_macros::define_extension_trait! {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "arbitrary")]
|
|
||||||
impl<'a> Arbitrary<'a> for TxOut {
|
|
||||||
fn arbitrary(u: &mut Unstructured<'a>) -> arbitrary::Result<Self> {
|
|
||||||
Ok(TxOut { value: Amount::arbitrary(u)?, script_pubkey: ScriptBuf::arbitrary(u)? })
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns the total number of bytes that this script pubkey would contribute to a transaction.
|
/// Returns the total number of bytes that this script pubkey would contribute to a transaction.
|
||||||
fn size_from_script_pubkey(script_pubkey: &Script) -> usize {
|
fn size_from_script_pubkey(script_pubkey: &Script) -> usize {
|
||||||
let len = script_pubkey.len();
|
let len = script_pubkey.len();
|
||||||
|
|
|
@ -59,7 +59,7 @@ pub use self::{
|
||||||
pub use self::{
|
pub use self::{
|
||||||
locktime::{absolute, relative},
|
locktime::{absolute, relative},
|
||||||
witness::Witness,
|
witness::Witness,
|
||||||
transaction::TxIn,
|
transaction::{TxIn, TxOut},
|
||||||
};
|
};
|
||||||
|
|
||||||
#[rustfmt::skip]
|
#[rustfmt::skip]
|
||||||
|
|
|
@ -18,7 +18,7 @@ use hashes::sha256d;
|
||||||
#[cfg(feature = "alloc")]
|
#[cfg(feature = "alloc")]
|
||||||
use internals::write_err;
|
use internals::write_err;
|
||||||
#[cfg(feature = "alloc")]
|
#[cfg(feature = "alloc")]
|
||||||
use units::parse;
|
use units::{parse, Amount};
|
||||||
|
|
||||||
#[cfg(feature = "alloc")]
|
#[cfg(feature = "alloc")]
|
||||||
use crate::script::ScriptBuf;
|
use crate::script::ScriptBuf;
|
||||||
|
@ -69,6 +69,34 @@ impl TxIn {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Bitcoin transaction output.
|
||||||
|
///
|
||||||
|
/// Defines new coins to be created as a result of the transaction,
|
||||||
|
/// along with spending conditions ("script", aka "output script"),
|
||||||
|
/// which an input spending it must satisfy.
|
||||||
|
///
|
||||||
|
/// An output that is not yet spent by an input is called Unspent Transaction Output ("UTXO").
|
||||||
|
///
|
||||||
|
/// ### Bitcoin Core References
|
||||||
|
///
|
||||||
|
/// * [CTxOut definition](https://github.com/bitcoin/bitcoin/blob/345457b542b6a980ccfbc868af0970a6f91d1b82/src/primitives/transaction.h#L148)
|
||||||
|
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Debug, Hash)]
|
||||||
|
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||||
|
#[cfg(feature = "alloc")]
|
||||||
|
pub struct TxOut {
|
||||||
|
/// The value of the output, in satoshis.
|
||||||
|
pub value: Amount,
|
||||||
|
/// The script which must be satisfied for the output to be spent.
|
||||||
|
pub script_pubkey: ScriptBuf,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "alloc")]
|
||||||
|
impl TxOut {
|
||||||
|
/// This is used as a "null txout" in consensus signing code.
|
||||||
|
pub const NULL: Self =
|
||||||
|
TxOut { value: Amount::from_sat(0xffffffffffffffff), script_pubkey: ScriptBuf::new() };
|
||||||
|
}
|
||||||
|
|
||||||
/// A reference to a transaction output.
|
/// A reference to a transaction output.
|
||||||
///
|
///
|
||||||
/// ### Bitcoin Core References
|
/// ### Bitcoin Core References
|
||||||
|
@ -261,6 +289,14 @@ impl<'a> Arbitrary<'a> for TxIn {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "arbitrary")]
|
||||||
|
#[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: ScriptBuf::arbitrary(u)? })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(feature = "arbitrary")]
|
#[cfg(feature = "arbitrary")]
|
||||||
impl<'a> Arbitrary<'a> for OutPoint {
|
impl<'a> Arbitrary<'a> for OutPoint {
|
||||||
fn arbitrary(u: &mut Unstructured<'a>) -> arbitrary::Result<Self> {
|
fn arbitrary(u: &mut Unstructured<'a>) -> arbitrary::Result<Self> {
|
||||||
|
|
Loading…
Reference in New Issue