Skip to content

Commit f8a7011

Browse files
author
ChallengeDev210
committed
Merge rust-bitcoin/rust-bitcoin#1018: Add more documentation to some core types
1875c91 Extend docstring for more types (Dawid Ciężarkiewicz) 325ea8f Add "Relevant BIPs` to `Address` (Dawid Ciężarkiewicz) 7c2ca3d Add `BlockHeader` Bitcoin Core reference link (Dawid Ciężarkiewicz) f4922f6 Update `BlockHeader::version` documentation (Dawid Ciężarkiewicz) Pull request description: This is meant to make it more educational, and handy even for experienced developers. A first step to make https://docs.rs/bitcoin (or `cargo doc --open`) a go-to place for convenient Bitcoin documentation. ACKs for top commit: tcharding: tACK 1875c91 apoelstra: ACK 1875c91 sanket1729: utACK 1875c91. Thanks for doing this. Tree-SHA512: 8457e120f9979bfd95e55e8b18faf6131610aa2241f8e5fc4630fe61dc7e16ddfc35fb6eff46339804016db7b176465943cc0c02d84dcf478ed55da9f5e06fc5
2 parents 77ee454 + e67c160 commit f8a7011

File tree

4 files changed

+87
-9
lines changed

4 files changed

+87
-9
lines changed

src/blockdata/block.rs

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,26 @@ use crate::blockdata::constants::{max_target, WITNESS_SCALE_FACTOR};
3737
use crate::blockdata::script;
3838
use crate::VarInt;
3939

40-
/// A block header, which contains all the block's information except
41-
/// the actual transactions
40+
/// Bitcoin block header.
41+
///
42+
/// Contains all the block's information except the actual transactions, but
43+
/// including a root of a [merkle tree] commiting to all transactions in the block.
44+
///
45+
/// [merkle tree]: https://en.wikipedia.org/wiki/Merkle_tree
46+
///
47+
/// ### Bitcoin Core References
48+
///
49+
/// * [CBlockHeader definition](https://github.com/bitcoin/bitcoin/blob/345457b542b6a980ccfbc868af0970a6f91d1b82/src/primitives/block.h#L20)
4250
#[derive(Copy, PartialEq, Eq, Clone, Debug)]
4351
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
4452
#[cfg_attr(feature = "serde", serde(crate = "actual_serde"))]
4553
pub struct BlockHeader {
46-
/// The protocol version. Should always be 1.
54+
/// Originally protocol version, but repurposed for soft-fork signaling.
55+
///
56+
/// ### Relevant BIPs
57+
///
58+
/// * [BIP9 - Version bits with timeout and delay](https://github.com/bitcoin/bips/blob/master/bip-0009.mediawiki) (current usage)
59+
/// * [BIP34 - Block v2, Height in Coinbase](https://github.com/bitcoin/bips/blob/master/bip-0034.mediawiki)
4760
pub version: i32,
4861
/// Reference to the previous block in the chain.
4962
pub prev_blockhash: BlockHash,
@@ -156,8 +169,17 @@ impl BlockHeader {
156169
}
157170
}
158171

159-
/// A Bitcoin block, which is a collection of transactions with an attached
160-
/// proof of work.
172+
/// Bitcoin block.
173+
///
174+
/// A collection of transactions with an attached proof of work.
175+
///
176+
/// See [Bitcoin Wiki: Block][wiki-block] for more information.
177+
///
178+
/// [wiki-block]: https://en.bitcoin.it/wiki/Block
179+
///
180+
/// ### Bitcoin Core References
181+
///
182+
/// * [CBlock definition](https://github.com/bitcoin/bitcoin/blob/345457b542b6a980ccfbc868af0970a6f91d1b82/src/primitives/block.h#L62)
161183
#[derive(PartialEq, Eq, Clone, Debug)]
162184
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
163185
#[cfg_attr(feature = "serde", serde(crate = "actual_serde"))]

src/blockdata/script.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,20 @@ use crate::util::taproot::{LeafVersion, TapBranchHash, TapLeafHash};
4747
use secp256k1::{Secp256k1, Verification, XOnlyPublicKey};
4848
use crate::schnorr::{TapTweak, TweakedPublicKey, UntweakedPublicKey};
4949

50-
/// A Bitcoin script.
50+
/// Bitcoin script.
51+
///
52+
/// A list of instructions in a simple, [Forth]-like, stack-based programming language
53+
/// that Bitcoin uses.
54+
///
55+
/// [Forth]: https://en.wikipedia.org/wiki/Forth_(programming_language)
56+
///
57+
/// See [Bitcoin Wiki: Script][wiki-script] for more information.
58+
///
59+
/// [wiki-script]: https://en.bitcoin.it/wiki/Script
60+
///
61+
/// ### Bitcoin Core References
62+
///
63+
/// * [CScript definition](https://github.com/bitcoin/bitcoin/blob/d492dc1cdaabdc52b0766bf4cba4bd73178325d0/src/script/script.h#L410)
5164
#[derive(Clone, Default, PartialOrd, Ord, PartialEq, Eq, Hash)]
5265
pub struct Script(Box<[u8]>);
5366

src/blockdata/transaction.rs

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ const UINT256_ONE: [u8; 32] = [
5353
];
5454

5555
/// A reference to a transaction output.
56+
///
57+
/// ### Bitcoin Core References
58+
///
59+
/// * [COutPoint definition](https://github.com/bitcoin/bitcoin/blob/345457b542b6a980ccfbc868af0970a6f91d1b82/src/primitives/transaction.h#L26)
5660
#[derive(Copy, Clone, Debug, Eq, Hash, PartialEq, PartialOrd, Ord)]
5761
pub struct OutPoint {
5862
/// The referenced transaction's txid.
@@ -188,7 +192,15 @@ impl ::core::str::FromStr for OutPoint {
188192
}
189193
}
190194

191-
/// A transaction input, which defines old coins to be consumed
195+
/// Bitcoin transaction input.
196+
///
197+
/// It contains the location of the previous transaction's output,
198+
/// that it spends and set of scripts that satisfy its spending
199+
/// conditions.
200+
///
201+
/// ### Bitcoin Core References
202+
///
203+
/// * [CTxIn definition](https://github.com/bitcoin/bitcoin/blob/345457b542b6a980ccfbc868af0970a6f91d1b82/src/primitives/transaction.h#L65)
192204
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Debug, Hash)]
193205
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
194206
#[cfg_attr(feature = "serde", serde(crate = "actual_serde"))]
@@ -222,7 +234,17 @@ impl Default for TxIn {
222234
}
223235
}
224236

225-
/// A transaction output, which defines new coins to be created from old ones.
237+
/// Bitcoin transaction output.
238+
///
239+
/// Defines new coins to be created as a result of the transaction,
240+
/// along with spending conditions ("script", aka "output script"),
241+
/// which an input spending it must satisfy.
242+
///
243+
/// An output that is not yet spent by an input is called Unspent Transaction Output ("UTXO").
244+
///
245+
/// ### Bitcoin Core References
246+
///
247+
/// * [CTxOut definition](https://github.com/bitcoin/bitcoin/blob/345457b542b6a980ccfbc868af0970a6f91d1b82/src/primitives/transaction.h#L148)
226248
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Debug, Hash)]
227249
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
228250
#[cfg_attr(feature = "serde", serde(crate = "actual_serde"))]
@@ -240,7 +262,19 @@ impl Default for TxOut {
240262
}
241263
}
242264

243-
/// A Bitcoin transaction, which describes an authenticated movement of coins.
265+
/// Bitcoin transaction.
266+
///
267+
/// An authenticated movement of coins.
268+
///
269+
/// See [Bitcoin Wiki: Transaction][wiki-transaction] for more information.
270+
///
271+
/// [wiki-transaction]: https://en.bitcoin.it/wiki/Transaction
272+
///
273+
/// ### Bitcoin Core References
274+
///
275+
/// * [CTtransaction definition](https://github.com/bitcoin/bitcoin/blob/345457b542b6a980ccfbc868af0970a6f91d1b82/src/primitives/transaction.h#L279)
276+
///
277+
/// ### Serialization notes
244278
///
245279
/// If any inputs have nonempty witnesses, the entire transaction is serialized
246280
/// in the post-BIP141 Segwit format which includes a list of witnesses. If all

src/util/address.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,15 @@ impl<'a> fmt::Display for AddressEncoding<'a> {
547547
}
548548

549549
/// A Bitcoin address.
550+
///
551+
/// ### Relevant BIPs
552+
///
553+
/// * [BIP13 - Address Format for pay-to-script-hash](https://github.com/bitcoin/bips/blob/master/bip-0013.mediawiki)
554+
/// * [BIP16 - Pay to Script Hash](https://github.com/bitcoin/bips/blob/master/bip-0016.mediawiki)
555+
/// * [BIP141 - Segregated Witness (Consensus layer)](https://github.com/bitcoin/bips/blob/master/bip-0141.mediawiki)
556+
/// * [BIP142 - Address Format for Segregated Witness](https://github.com/bitcoin/bips/blob/master/bip-0142.mediawiki)
557+
/// * [BIP341 - Taproot: SegWit version 1 spending rules](https://github.com/bitcoin/bips/blob/master/bip-0341.mediawiki)
558+
/// * [BIP350 - Bech32m format for v1+ witness addresses](https://github.com/bitcoin/bips/blob/master/bip-0350.mediawiki)
550559
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
551560
pub struct Address {
552561
/// The type of the address.

0 commit comments

Comments
 (0)