Skip to content

Commit 6b2af4c

Browse files
committed
docs: add missing documentation
1 parent e802597 commit 6b2af4c

File tree

2 files changed

+44
-4
lines changed

2 files changed

+44
-4
lines changed

src/api.rs

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,19 @@ pub use bitcoin::{
1111

1212
use 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)]
1518
pub 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)]
2128
pub 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)]
3443
pub struct Vout {
3544
pub value: u64,
3645
pub scriptpubkey: ScriptBuf,
3746
}
3847

48+
/// Represents Transaction Status.
3949
#[derive(Deserialize, Clone, Debug, PartialEq, Eq)]
4050
pub 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)]
4862
pub 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)]
5570
pub 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)]
6383
pub 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)]
7091
pub 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)]
85108
pub 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)]
91115
pub struct BlockSummary {
92116
pub id: BlockHash,
@@ -124,6 +148,7 @@ pub struct AddressTxsSummary {
124148
}
125149

126150
impl 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
}

src/async.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ use crate::{
3434
BASE_BACKOFF_MILLIS, RETRYABLE_ERROR_CODES,
3535
};
3636

37+
/// Struct that an HTTP client configured with an
38+
/// Esplora server URL, max retries, and a type
39+
/// marker for asynchronous sleep behavior.
3740
#[derive(Debug, Clone)]
3841
pub struct AsyncClient<S = DefaultSleeper> {
3942
/// The URL of the Esplora Server.
@@ -81,7 +84,7 @@ impl<S: Sleeper> AsyncClient<S> {
8184
marker: PhantomData,
8285
})
8386
}
84-
87+
/// A constructor for creating a new instance of `AsyncClient`.
8588
pub fn from_client(url: String, client: Client) -> Self {
8689
AsyncClient {
8790
url,
@@ -482,6 +485,9 @@ fn is_status_retryable(status: reqwest::StatusCode) -> bool {
482485
RETRYABLE_ERROR_CODES.contains(&status.as_u16())
483486
}
484487

488+
/// The Sleeper trait defines an asynchronous
489+
/// sleep mechanism with an associated future
490+
/// type that completes after a given duration.
485491
pub trait Sleeper: 'static {
486492
type Sleep: std::future::Future<Output = ()>;
487493
fn sleep(dur: std::time::Duration) -> Self::Sleep;

0 commit comments

Comments
 (0)