Skip to content

Commit d993692

Browse files
committed
Merge rust-bitcoin#4931: Add initial primitives 1.0.0 design document
485118f Add encoding section to primitives 1.0.0 doc (Tobin C. Harding) ca1ada7 doc: Document primitives v1.0.0 (Tobin C. Harding) Pull request description: Please see patch 1 for motivation and purpose. (Note, I started this because everytime I got to work on `primitives` `hashes` stuff I have to check out the API text files branch and grep for stuff to work out what I'm doing. This file documents it so its there on master.) ACKs for top commit: apoelstra: ACK 485118f; successfully ran local tests; great! Tree-SHA512: 0072e1e49e35645d872ae0825501a07fc9bccdbaca6bf5a5a56eb137b7bb80848bc7d2447a292a86aa722675f9e03109671476f470d757a4bc88ef7dc954d70d
2 parents eb80f6c + 485118f commit d993692

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

docs/primitives.md

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# primitives 1.0.0
2+
3+
Design considerations and TODOs for the `bitcoin-primitives 1.0.0` release.
4+
5+
## TODOs
6+
7+
### consensus encoding
8+
9+
GitHub discussion: https://github.com/rust-bitcoin/rust-bitcoin/discussions/4856
10+
11+
Pull encoding done in: https://github.com/rust-bitcoin/rust-bitcoin/pull/4912
12+
13+
<!-- TODO: Add a consenus-encoding.md file? -->
14+
15+
### Remove `hashes` from the public API.
16+
17+
Required due to [C-STABLE](https://rust-lang.github.io/api-guidelines/necessities.html#c-stable).
18+
19+
Currently `hashes` shows up in the public API in all of our hash wrapper types. This can be seen by
20+
grepping the API text files introduced in
21+
[#4792](https://github.com/rust-bitcoin/rust-bitcoin/issues/4792)
22+
23+
The wrapper types are:
24+
25+
```bash
26+
$ grep hashes api/primitives/all-features.txt | grep impl | awk '{print $NF}'
27+
28+
bitcoin_primitives::block::BlockHash
29+
bitcoin_primitives::block::WitnessCommitment
30+
bitcoin_primitives::merkle_tree::TxMerkleNode
31+
bitcoin_primitives::merkle_tree::WitnessMerkleNode
32+
bitcoin_primitives::script::ScriptHash
33+
bitcoin_primitives::script::WScriptHash
34+
bitcoin_primitives::transaction::Ntxid
35+
bitcoin_primitives::transaction::Txid
36+
bitcoin_primitives::transaction::Wtxid
37+
```
38+
39+
Using `Txid` as an example, `hashes` appears in the following places:
40+
41+
```bash
42+
$ grep hashes api/primitives/all-features.txt | grep Txid
43+
44+
impl bitcoin_hashes::Hash for bitcoin_primitives::transaction::Txid
45+
pub const fn bitcoin_primitives::transaction::Txid::as_byte_array(&self) -> &<bitcoin_hashes::sha256d::Hash as bitcoin_hashes::Hash>::Bytes
46+
pub const fn bitcoin_primitives::transaction::Txid::from_byte_array(bytes: <bitcoin_hashes::sha256d::Hash as bitcoin_hashes::Hash>::Bytes) -> Self
47+
pub const fn bitcoin_primitives::transaction::Txid::to_byte_array(self) -> <bitcoin_hashes::sha256d::Hash as bitcoin_hashes::Hash>::Bytes
48+
pub type bitcoin_primitives::transaction::Txid::Bytes = <bitcoin_hashes::sha256d::Hash as bitcoin_hashes::Hash>::Bytes
49+
```
50+
51+
All these come from the `hash_newtype` macro.
52+
53+
Usage of `hash_newtype` in `bitcoin` (i.e. other usage outside of `primitives`):
54+
55+
- `bip158::{FilterHash, FilterHeader}`
56+
- `bip32::XKeyIdentifier`
57+
- `crypto::key::{PubkeyHash, WPubkeyHash}`
58+
- `crypto::sighash::{LegacySighash, SegwitV0Sighash}`
59+
- `taproot::{TapLeafHash, TapNodeHash, TapTweakHash}`

0 commit comments

Comments
 (0)