@@ -11,12 +11,19 @@ pub use bitcoin::{
1111
1212use serde:: Deserialize ;
1313
14+ /// It contains the value and scriptpubkey of a
15+ /// previous transaction output that a transaction
16+ /// input can reference.
1417#[ derive( Deserialize , Clone , Debug , PartialEq , Eq ) ]
1518pub struct PrevOut {
1619 pub value : u64 ,
1720 pub scriptpubkey : ScriptBuf ,
1821}
1922
23+ /// Represents the transaction input containing
24+ /// a Previous output (or none if coinbase) and includes
25+ /// the unlocking script, witness data, sequence number,
26+ /// and a flag indicating if it is a coinbase input.
2027#[ derive( Deserialize , Clone , Debug , PartialEq , Eq ) ]
2128pub struct Vin {
2229 pub txid : Txid ,
@@ -30,12 +37,15 @@ pub struct Vin {
3037 pub is_coinbase : bool ,
3138}
3239
40+ /// Represents the transaction output containing a value and
41+ /// a scriptpubkey.
3342#[ derive( Deserialize , Clone , Debug , PartialEq , Eq ) ]
3443pub struct Vout {
3544 pub value : u64 ,
3645 pub scriptpubkey : ScriptBuf ,
3746}
3847
48+ /// Represents Transaction Status.
3949#[ derive( Deserialize , Clone , Debug , PartialEq , Eq ) ]
4050pub struct TxStatus {
4151 pub confirmed : bool ,
@@ -44,13 +54,18 @@ pub struct TxStatus {
4454 pub block_time : Option < u64 > ,
4555}
4656
57+ /// It holds the block height, a Merkle path of
58+ /// transaction IDs, and the position of the
59+ /// transaction in the tree to verify its inclusion
60+ /// in a block.
4761#[ derive( Deserialize , Clone , Debug , PartialEq , Eq ) ]
4862pub struct MerkleProof {
4963 pub block_height : u32 ,
5064 pub merkle : Vec < Txid > ,
5165 pub pos : usize ,
5266}
5367
68+ /// Struct that contains the status of an output in a transaction.
5469#[ derive( Deserialize , Clone , Debug , PartialEq , Eq ) ]
5570pub struct OutputStatus {
5671 pub spent : bool ,
@@ -59,13 +74,19 @@ pub struct OutputStatus {
5974 pub status : Option < TxStatus > ,
6075}
6176
77+ /// This Struct represents the status of a block in the blockchain.
78+ /// `in_best_chain` - a boolean that shows whether the block is part of the main chain.
79+ /// `height` - Optional field that shows the height of the block if block is in main chain.
80+ /// `next_best` - Optional field that contains `BlockHash` of the next block that may represent
81+ /// the next block in the best chain.
6282#[ derive( Deserialize , Clone , Debug , PartialEq , Eq ) ]
6383pub struct BlockStatus {
6484 pub in_best_chain : bool ,
6585 pub height : Option < u32 > ,
6686 pub next_best : Option < BlockHash > ,
6787}
6888
89+ /// Structure represents a complete transaction
6990#[ derive( Deserialize , Clone , Debug , PartialEq , Eq ) ]
7091pub struct Tx {
7192 pub txid : Txid ,
@@ -81,12 +102,15 @@ pub struct Tx {
81102 pub fee : u64 ,
82103}
83104
105+ /// Returns timing information of a Block
106+ /// containg `timestamp` and `height` of block
84107#[ derive( Deserialize , Clone , Debug , PartialEq , Eq ) ]
85108pub struct BlockTime {
86109 pub timestamp : u64 ,
87110 pub height : u32 ,
88111}
89-
112+ /// Provides a Summary of a Bitcoin block which includes
113+ /// `BlockHash`, `BlockTime`, `previousblockhash`, `merkle_root`.
90114#[ derive( Debug , Clone , Deserialize , PartialEq , Eq ) ]
91115pub struct BlockSummary {
92116 pub id : BlockHash ,
@@ -124,6 +148,7 @@ pub struct AddressTxsSummary {
124148}
125149
126150impl Tx {
151+ /// Converts a transaction into a standard `Bitcoin transaction`.
127152 pub fn to_tx ( & self ) -> Transaction {
128153 Transaction {
129154 version : transaction:: Version :: non_standard ( self . version ) ,
@@ -154,6 +179,9 @@ impl Tx {
154179 }
155180 }
156181
182+ /// Checks Transaction status, returns a `BlockTime` struct contaning
183+ /// `height` and `timestamp` if transaction has been confirmed or
184+ /// `None` otherwise.
157185 pub fn confirmation_time ( & self ) -> Option < BlockTime > {
158186 match self . status {
159187 TxStatus {
@@ -166,6 +194,10 @@ impl Tx {
166194 }
167195 }
168196
197+ /// Takes Transaction as input
198+ /// iterates through all the inputs present in the transaction
199+ /// and checks for prevout field and creates a `TxOut` Struct for each input if it exists
200+ /// then returns all optional TxOut values as a vector.
169201 pub fn previous_outputs ( & self ) -> Vec < Option < TxOut > > {
170202 self . vin
171203 . iter ( )
@@ -178,11 +210,13 @@ impl Tx {
178210 } )
179211 . collect ( )
180212 }
181-
213+ /// Takes Transaction as input and returns
214+ /// the `Weight instance` of the weight present in Transaction.
182215 pub fn weight ( & self ) -> Weight {
183216 Weight :: from_wu ( self . weight )
184217 }
185-
218+ /// Takes Transaction as input and returns
219+ /// the `Amount instance` of the satoshis present in Transaction.
186220 pub fn fee ( & self ) -> Amount {
187221 Amount :: from_sat ( self . fee )
188222 }
0 commit comments