@@ -36,6 +36,7 @@ pub struct Vout {
36
36
pub scriptpubkey : ScriptBuf ,
37
37
}
38
38
39
+ ///Represents Transaction Status.
39
40
#[ derive( Deserialize , Clone , Debug , PartialEq , Eq ) ]
40
41
pub struct TxStatus {
41
42
pub confirmed : bool ,
@@ -51,6 +52,7 @@ pub struct MerkleProof {
51
52
pub pos : usize ,
52
53
}
53
54
55
+ /// Struct that contains the status of an output in a transaction.
54
56
#[ derive( Deserialize , Clone , Debug , PartialEq , Eq ) ]
55
57
pub struct OutputStatus {
56
58
pub spent : bool ,
@@ -59,13 +61,19 @@ pub struct OutputStatus {
59
61
pub status : Option < TxStatus > ,
60
62
}
61
63
64
+ ///A Struct represents the status of a block in the blockchain.
65
+ /// `in_best_chain` - a boolean that shows whether the block is part of the main chain.
66
+ /// `height` - Optional field that shows the height of the block if block is in main chain.
67
+ /// `next_best` - Optional field that contains `BlockHash` of the next block that may represent
68
+ /// the next block in the best chain.
62
69
#[ derive( Deserialize , Clone , Debug , PartialEq , Eq ) ]
63
70
pub struct BlockStatus {
64
71
pub in_best_chain : bool ,
65
72
pub height : Option < u32 > ,
66
73
pub next_best : Option < BlockHash > ,
67
74
}
68
75
76
+ ///Structure represents a complete transaction
69
77
#[ derive( Deserialize , Clone , Debug , PartialEq , Eq ) ]
70
78
pub struct Tx {
71
79
pub txid : Txid ,
@@ -81,12 +89,15 @@ pub struct Tx {
81
89
pub fee : u64 ,
82
90
}
83
91
92
+ ///Returns timing information of a Block
93
+ /// containg `timestamp` and `height` of block
84
94
#[ derive( Deserialize , Clone , Debug , PartialEq , Eq ) ]
85
95
pub struct BlockTime {
86
96
pub timestamp : u64 ,
87
97
pub height : u32 ,
88
98
}
89
-
99
+ ///Provides a Summary of a Bitcoin block which includes
100
+ /// `BlockHash`, `BlockTime`, `previousblockhash`, `merkle_root`.
90
101
#[ derive( Debug , Clone , Deserialize , PartialEq , Eq ) ]
91
102
pub struct BlockSummary {
92
103
pub id : BlockHash ,
@@ -124,6 +135,7 @@ pub struct AddressTxsSummary {
124
135
}
125
136
126
137
impl Tx {
138
+ ///Converts a transaction into a standard `Bitcoin transaction`.
127
139
pub fn to_tx ( & self ) -> Transaction {
128
140
Transaction {
129
141
version : transaction:: Version :: non_standard ( self . version ) ,
@@ -154,6 +166,9 @@ impl Tx {
154
166
}
155
167
}
156
168
169
+ ///Checks Transaction status, returns a `BlockTime` struct contaning
170
+ /// `height` and `timestamp` if transaction has been confirmed or
171
+ /// `None` otherwise.
157
172
pub fn confirmation_time ( & self ) -> Option < BlockTime > {
158
173
match self . status {
159
174
TxStatus {
@@ -166,6 +181,10 @@ impl Tx {
166
181
}
167
182
}
168
183
184
+ ///Takes Transaction as input
185
+ /// iterates through all the inputs present in the transaction
186
+ /// and checks for prevout field and creates a `TxOut` Struct for each input if it exists
187
+ /// then returns all optional TxOut values as a vector.
169
188
pub fn previous_outputs ( & self ) -> Vec < Option < TxOut > > {
170
189
self . vin
171
190
. iter ( )
@@ -178,11 +197,13 @@ impl Tx {
178
197
} )
179
198
. collect ( )
180
199
}
181
-
200
+ ///Takes Transaction as input and returns
201
+ /// the `Weight instance` of the weight present in Transaction.
182
202
pub fn weight ( & self ) -> Weight {
183
203
Weight :: from_wu ( self . weight )
184
204
}
185
-
205
+ ///Takes Transaction as input and returns
206
+ /// the `Amount instance` of the satoshis present in Transaction.
186
207
pub fn fee ( & self ) -> Amount {
187
208
Amount :: from_sat ( self . fee )
188
209
}
0 commit comments