@@ -11,12 +11,19 @@ pub use bitcoin::{
11
11
12
12
use serde:: Deserialize ;
13
13
14
+ /// It contains the value and scriptpubkey of a
15
+ /// previous transaction output that a transaction
16
+ /// input can reference.
14
17
#[ derive( Deserialize , Clone , Debug , PartialEq , Eq ) ]
15
18
pub struct PrevOut {
16
19
pub value : u64 ,
17
20
pub scriptpubkey : ScriptBuf ,
18
21
}
19
22
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.
20
27
#[ derive( Deserialize , Clone , Debug , PartialEq , Eq ) ]
21
28
pub struct Vin {
22
29
pub txid : Txid ,
@@ -30,12 +37,15 @@ pub struct Vin {
30
37
pub is_coinbase : bool ,
31
38
}
32
39
40
+ /// Represents the transaction output containing a value and
41
+ /// a scriptpubkey.
33
42
#[ derive( Deserialize , Clone , Debug , PartialEq , Eq ) ]
34
43
pub struct Vout {
35
44
pub value : u64 ,
36
45
pub scriptpubkey : ScriptBuf ,
37
46
}
38
47
48
+ /// Represents Transaction Status.
39
49
#[ derive( Deserialize , Clone , Debug , PartialEq , Eq ) ]
40
50
pub struct TxStatus {
41
51
pub confirmed : bool ,
@@ -44,13 +54,18 @@ pub struct TxStatus {
44
54
pub block_time : Option < u64 > ,
45
55
}
46
56
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.
47
61
#[ derive( Deserialize , Clone , Debug , PartialEq , Eq ) ]
48
62
pub struct MerkleProof {
49
63
pub block_height : u32 ,
50
64
pub merkle : Vec < Txid > ,
51
65
pub pos : usize ,
52
66
}
53
67
68
+ /// Struct that contains the status of an output in a transaction.
54
69
#[ derive( Deserialize , Clone , Debug , PartialEq , Eq ) ]
55
70
pub struct OutputStatus {
56
71
pub spent : bool ,
@@ -59,13 +74,19 @@ pub struct OutputStatus {
59
74
pub status : Option < TxStatus > ,
60
75
}
61
76
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.
62
82
#[ derive( Deserialize , Clone , Debug , PartialEq , Eq ) ]
63
83
pub struct BlockStatus {
64
84
pub in_best_chain : bool ,
65
85
pub height : Option < u32 > ,
66
86
pub next_best : Option < BlockHash > ,
67
87
}
68
88
89
+ /// Structure represents a complete transaction
69
90
#[ derive( Deserialize , Clone , Debug , PartialEq , Eq ) ]
70
91
pub struct Tx {
71
92
pub txid : Txid ,
@@ -81,12 +102,15 @@ pub struct Tx {
81
102
pub fee : u64 ,
82
103
}
83
104
105
+ /// Returns timing information of a Block
106
+ /// containg `timestamp` and `height` of block
84
107
#[ derive( Deserialize , Clone , Debug , PartialEq , Eq ) ]
85
108
pub struct BlockTime {
86
109
pub timestamp : u64 ,
87
110
pub height : u32 ,
88
111
}
89
-
112
+ /// Provides a Summary of a Bitcoin block which includes
113
+ /// `BlockHash`, `BlockTime`, `previousblockhash`, `merkle_root`.
90
114
#[ derive( Debug , Clone , Deserialize , PartialEq , Eq ) ]
91
115
pub struct BlockSummary {
92
116
pub id : BlockHash ,
@@ -124,6 +148,7 @@ pub struct AddressTxsSummary {
124
148
}
125
149
126
150
impl Tx {
151
+ /// Converts a transaction into a standard `Bitcoin transaction`.
127
152
pub fn to_tx ( & self ) -> Transaction {
128
153
Transaction {
129
154
version : transaction:: Version :: non_standard ( self . version ) ,
@@ -154,6 +179,9 @@ impl Tx {
154
179
}
155
180
}
156
181
182
+ /// Checks Transaction status, returns a `BlockTime` struct contaning
183
+ /// `height` and `timestamp` if transaction has been confirmed or
184
+ /// `None` otherwise.
157
185
pub fn confirmation_time ( & self ) -> Option < BlockTime > {
158
186
match self . status {
159
187
TxStatus {
@@ -166,6 +194,10 @@ impl Tx {
166
194
}
167
195
}
168
196
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.
169
201
pub fn previous_outputs ( & self ) -> Vec < Option < TxOut > > {
170
202
self . vin
171
203
. iter ( )
@@ -178,11 +210,13 @@ impl Tx {
178
210
} )
179
211
. collect ( )
180
212
}
181
-
213
+ /// Takes Transaction as input and returns
214
+ /// the `Weight instance` of the weight present in Transaction.
182
215
pub fn weight ( & self ) -> Weight {
183
216
Weight :: from_wu ( self . weight )
184
217
}
185
-
218
+ /// Takes Transaction as input and returns
219
+ /// the `Amount instance` of the satoshis present in Transaction.
186
220
pub fn fee ( & self ) -> Amount {
187
221
Amount :: from_sat ( self . fee )
188
222
}
0 commit comments