diff --git a/zebra-chain/src/lib.rs b/zebra-chain/src/lib.rs index e84d0f5b6..c945b00e1 100644 --- a/zebra-chain/src/lib.rs +++ b/zebra-chain/src/lib.rs @@ -5,5 +5,6 @@ extern crate failure; pub mod block; +pub mod serialization; +pub mod transaction; pub mod types; -pub mod serialization; \ No newline at end of file diff --git a/zebra-chain/src/transaction.rs b/zebra-chain/src/transaction.rs new file mode 100644 index 000000000..d7be862f1 --- /dev/null +++ b/zebra-chain/src/transaction.rs @@ -0,0 +1,70 @@ +//! Transaction types. + +/// OutPoint +/// +/// A particular transaction output reference. +#[derive(Copy, Clone, Debug, Eq, PartialEq)] +pub struct OutPoint { + /// The hash of the referenced transaction. + pub hash: [u8; 32], + + /// The index of the specific output in the transaction. The first output is 0, etc. + pub index: u32, +} + +/// Transaction Input +// `Copy` cannot be implemented for `Vec` +#[derive(Clone, Debug, Eq, PartialEq)] +pub struct TransactionInput { + /// The previous output transaction reference. + pub previous_output: OutPoint, + + /// Computational Script for confirming transaction authorization. + // XXX pzec uses their own `Bytes` type that wraps a `Vec` + // with some extra methods. + pub signature_script: Vec, + + /// Transaction version as defined by the sender. Intended for + /// "replacement" of transactions when information is updated + /// before inclusion into a block. + pub sequence: u32, +} + +/// Transaction Output +// `Copy` cannot be implemented for `Vec` +#[derive(Clone, Debug, Eq, PartialEq)] +pub struct TransactionOutput { + /// Transaction value. + // At https://en.bitcoin.it/wiki/Protocol_documentation#tx, this is an i64. + pub value: u64, + + /// Usually contains the public key as a Bitcoin script setting up + /// conditions to claim this output. + pub pk_script: Vec, +} + +/// Transaction Input +#[derive(Clone, Debug, Eq, PartialEq)] +pub struct Transaction { + /// Transaction data format version (note, this is signed). + pub version: i32, + + /// A list of 1 or more transaction inputs or sources for coins. + pub tx_in: Vec, + + /// A list of 1 or more transaction outputs or destinations for coins. + pub tx_out: Vec, + + /// The block number or timestamp at which this transaction is unlocked: + /// + /// |Value |Description | + /// |------------|----------------------------------------------------| + /// |0 |Not locked (default) | + /// |< 500000000 |Block number at which this transaction is unlocked | + /// |>= 500000000|UNIX timestamp at which this transaction is unlocked| + /// + /// If all `TransactionInput`s have final (0xffffffff) sequence + /// numbers, then lock_time is irrelevant. Otherwise, the + /// transaction may not be added to a block until after `lock_time`. + pub lock_time: u32, +} diff --git a/zebra-chain/src/types.rs b/zebra-chain/src/types.rs index 3820e1c01..a9a7e8203 100644 --- a/zebra-chain/src/types.rs +++ b/zebra-chain/src/types.rs @@ -47,75 +47,6 @@ pub enum InventoryType { #[derive(Copy, Clone, Debug, Eq, PartialEq)] pub struct InventoryVector(pub InventoryType, pub [u8; 32]); -/// OutPoint -/// -/// A particular transaction output reference. -#[derive(Copy, Clone, Debug, Eq, PartialEq)] -pub struct OutPoint { - /// The hash of the referenced transaction. - pub hash: [u8; 32], - - /// The index of the specific output in the transaction. The first output is 0, etc. - pub index: u32, -} - -/// Transaction Input -// `Copy` cannot be implemented for `Vec` -#[derive(Clone, Debug, Eq, PartialEq)] -pub struct TransactionInput { - /// The previous output transaction reference. - pub previous_output: OutPoint, - - /// Computational Script for confirming transaction authorization. - // XXX pzec uses their own `Bytes` type that wraps a `Vec` - // with some extra methods. - pub signature_script: Vec, - - /// Transaction version as defined by the sender. Intended for - /// "replacement" of transactions when information is updated - /// before inclusion into a block. - pub sequence: u32, -} - -/// Transaction Output -// `Copy` cannot be implemented for `Vec` -#[derive(Clone, Debug, Eq, PartialEq)] -pub struct TransactionOutput { - /// Transaction value. - // At https://en.bitcoin.it/wiki/Protocol_documentation#tx, this is an i64. - pub value: u64, - - /// Usually contains the public key as a Bitcoin script setting up - /// conditions to claim this output. - pub pk_script: Vec, -} - -/// Transaction Input -#[derive(Clone, Debug, Eq, PartialEq)] -pub struct Transaction { - /// Transaction data format version (note, this is signed). - pub version: i32, - - /// A list of 1 or more transaction inputs or sources for coins. - pub tx_in: Vec, - - /// A list of 1 or more transaction outputs or destinations for coins. - pub tx_out: Vec, - - /// The block number or timestamp at which this transaction is unlocked: - /// - /// |Value |Description | - /// |------------|----------------------------------------------------| - /// |0 |Not locked (default) | - /// |< 500000000 |Block number at which this transaction is unlocked | - /// |>= 500000000|UNIX timestamp at which this transaction is unlocked| - /// - /// If all `TransactionInput`s have final (0xffffffff) sequence - /// numbers, then lock_time is irrelevant. Otherwise, the - /// transaction may not be added to a block until after `lock_time`. - pub lock_time: u32, -} - #[cfg(test)] mod tests { use super::*; diff --git a/zebra-network/src/message.rs b/zebra-network/src/message.rs index ee092fe4b..f39f0d0bf 100644 --- a/zebra-network/src/message.rs +++ b/zebra-network/src/message.rs @@ -9,7 +9,8 @@ use zebra_chain::{ serialization::{ ReadZcashExt, SerializationError, WriteZcashExt, ZcashDeserialize, ZcashSerialize, }, - types::{BlockHeight, Sha256dChecksum, Transaction}, + transaction::Transaction, + types::{BlockHeight, Sha256dChecksum}, }; use crate::meta_addr::MetaAddr;