Skip to content
This repository was archived by the owner on Oct 27, 2023. It is now read-only.

Commit cee4953

Browse files
committed
feat: cookbook
Cookbook on how to sign segwit and taproot transactions Additionally: - Convert `build.sh` to a GitHub Action - Automated CI in GitHub Actions that test all the code in the cookbook - Automated scheduled CI in GitHub Actions that check all markdown files for broken links - Dependabot to update (weekly) - GitHub Actions - Test dependencies - `justfile` to easy run the build and test with `just`
1 parent 151a309 commit cee4953

21 files changed

+1005
-96
lines changed

.github/dependabot.yml

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Set update schedule for GitHub Actions
2+
version: 2
3+
updates:
4+
- package-ecosystem: "github-actions"
5+
directory: "/"
6+
schedule:
7+
# Check for updates to GitHub Actions every week
8+
interval: "weekly"
9+
- package-ecosystem: "cargo"
10+
directory: "/cookbook/tests" # point this towards a Cargo.toml directory
11+
schedule:
12+
# Check for updates to Rust dependencies every week
13+
interval: "weekly"

.github/workflows/check-links.yml

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: Markdown Links Check
2+
# runs every monday at 9 am
3+
on:
4+
schedule:
5+
- cron: "0 9 * * 1"
6+
workflow_dispatch: null
7+
8+
jobs:
9+
check-links:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v4
13+
- uses: gaurav-nelson/github-action-markdown-link-check@v1
14+
# checks all markdown files from /cookbook including all subfolders
15+
with:
16+
use-quiet-mode: 'yes'
17+
use-verbose-mode: 'yes'
18+
folder-path: 'cookbook/'
19+
- uses: actions/checkout@v4
20+
- uses: gaurav-nelson/github-action-markdown-link-check@v1
21+
# checks all markdown files from root but ignores subfolders
22+
with:
23+
use-quiet-mode: 'yes'
24+
use-verbose-mode: 'yes'
25+
max-depth: 0

.github/workflows/gh-pages.yml

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# This needs the following setting:
2+
# Setttings > Actions > General > Workflow permissions
3+
# change to "Read and write permissions"
4+
name: github pages
5+
6+
on:
7+
push:
8+
branches:
9+
- master
10+
workflow_dispatch: null
11+
12+
jobs:
13+
deploy:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v4
17+
with:
18+
submodules: true # could be useful in the future
19+
fetch-depth: 0 # we just need the latest commit
20+
21+
- name: Setup mdBook
22+
uses: peaceiris/actions-mdbook@v1
23+
with:
24+
mdbook-version: 'latest'
25+
26+
- name: Build mdbook
27+
working-directory: ./cookbook
28+
run: mdbook build --dest-dir "../site/static/book"
29+
30+
- name: Setup Hugo
31+
uses: peaceiris/actions-hugo@v2
32+
with:
33+
hugo-version: "latest"
34+
35+
- name: Build Hugo
36+
working-directory: ./site
37+
run: hugo --minify
38+
39+
- name: Deploy
40+
uses: peaceiris/actions-gh-pages@v3
41+
if: github.ref == 'refs/heads/master'
42+
with:
43+
github_token: ${{ secrets.GITHUB_TOKEN }}
44+
publish_dir: ./site/public

.github/workflows/test.yml

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: Tests
2+
on:
3+
push:
4+
branches: [ master, '[0-9]+.[0-9]+.[0-9]+', '[0-9]+.[0-9]+.[0-9]+-[A-Za-z0-9]+' ]
5+
pull_request:
6+
branches: [ master, '[0-9]+.[0-9]+.[0-9]+', '[0-9]+.[0-9]+.[0-9]+-[A-Za-z0-9]+' ]
7+
# runs every monday at 9 am
8+
schedule:
9+
- cron: "0 9 * * 1"
10+
workflow_dispatch: null
11+
12+
jobs:
13+
code-samples:
14+
name: Test code samples
15+
runs-on: ubuntu-latest
16+
steps:
17+
- uses: actions/checkout@v4
18+
- name: Install toolchain
19+
uses: actions-rs/toolchain@v1
20+
with:
21+
profile: minimal
22+
toolchain: stable
23+
- name: Generate harness
24+
working-directory: ./cookbook/tests
25+
run: ./generate.sh
26+
- name: Test code samples
27+
working-directory: ./cookbook/tests
28+
run: cargo test

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,7 @@ site/.hugo_build.lock
66

77
# mdbook build
88
cookbook/book
9+
cookbook/tests/Cargo.lock
10+
cookbook/tests/target
11+
cookbook/tests/src
912
site/static/book

README.md

+10
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,13 @@ Website for the rust-bitcoin ecosystem. The site is built using [hugo](https://g
77
[nightfall](https://themes.gohugo.io/themes/hugo-theme-nightfall/) theme.
88

99
Includes a cookbook built with [mdbook](https://rust-lang.github.io/mdBook/).
10+
11+
## License
12+
13+
This website is licensed under [CC0 1.0 Universal (CC0 1.0) Public Domain Dedication][cc].
14+
15+
[![CC BY-SA 4.0][cc-image]][cc]
16+
17+
[cc]: https://creativecommons.org/publicdomain/zero/1.0/
18+
[cc-image]: https://licensebuttons.net/l/by-sa/4.0/88x31.png
19+
[cc-shield]: https://img.shields.io/badge/License-CC0%201.0-lightgrey.svg

build.sh

-77
This file was deleted.

cookbook/README.md

+54-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,58 @@
1-
# Rust Bitcoin CookBook
1+
# Rust Bitcoin Cookbook
22

3-
Welcome to the Rust-Bitcoin documentation! This documentation is designed to provide readers with a
4-
comprehensive understanding of Rust-Bitcoin and its key features.
3+
[![CC0 1.0][cc-shield]][cc]
54

5+
Welcome to the `rust-bitcoin` cookbook!
6+
This cookbook is designed to provide readers with a
7+
comprehensive understanding of `rust-bitcoin` and its key features.
8+
Don't forget to check [`rust-bitcoin`'s documentation](https://docs.rs/bitcoin)
69

7-
## Build
10+
## How to contribute
811

9-
The book can be built with `mdbook`: https://rust-lang.github.io/mdBook/
12+
For the cookbook we use [`mdbook`](https://rust-lang.github.io/mdBook).
13+
Please check how to install it on your system.
14+
15+
To build the cookbook locally, run:
16+
17+
```bash
18+
mdbook build
19+
```
20+
21+
If you want to preview the cookbook locally, run:
22+
23+
```bash
24+
mdbook serve
25+
```
26+
27+
### Testing the code snippets
28+
29+
Since [`mdbook` does not support external crates](https://github.com/rust-lang/mdBook/issues/706),
30+
we use [a solution provided by `doc-comment`](https://github.com/rust-lang/mdBook/issues/706#issuecomment-1139423009)
31+
to test the code snippets in the cookbook.
32+
First, go to the `tests/` directory:
33+
34+
```bash
35+
cd tests
36+
```
37+
38+
Then, run the `generate.sh` to automatically generate all tests files:
39+
40+
```bash
41+
./generate.sh
42+
```
43+
44+
Finally run the tests:
45+
46+
```bash
47+
cargo test
48+
```
49+
50+
## License
51+
52+
This website is licensed under [CC0 1.0 Universal (CC0 1.0) Public Domain Dedication][cc].
53+
54+
[![CC BY-SA 4.0][cc-image]][cc]
55+
56+
[cc]: https://creativecommons.org/publicdomain/zero/1.0/
57+
[cc-image]: https://licensebuttons.net/l/by-sa/4.0/88x31.png
58+
[cc-shield]: https://img.shields.io/badge/License-CC0%201.0-lightgrey.svg

cookbook/book.toml

+12-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
11
[book]
2-
authors = ["Harshil Jani"]
2+
authors = [
3+
"Harshil Jani <[email protected]>",
4+
"Tobin C. Harding<[email protected]>",
5+
"Einherjar <[email protected]>",
6+
]
37
language = "en"
48
multilingual = false
59
src = "src"
610
title = "Rust Bitcoin Cookbook"
11+
description = "A cookbook for Rust Bitcoin development"
12+
13+
[rust]
14+
edition = "2021"
15+
16+
[output.html.playground]
17+
runnable = false # playground is not runnable by default

cookbook/src/SUMMARY.md

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Summary
22

3-
[Table of Contents](./table_of_contents.md)
4-
[About](./about.md)
5-
- [Chapter 1](./chapter_1.md)
3+
[Introduction](./intro.md)
4+
5+
- [Constructing and Signing Transactions](tx.md)
6+
- [SegWit V0](tx_segwit-v0.md)
7+
- [Taproot](tx_taproot.md)

cookbook/src/about.md

-8
This file was deleted.

cookbook/src/chapter_1.md

-1
This file was deleted.

cookbook/src/intro.md

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Rust Bitcoin
2+
3+
[![CC0 1.0][cc-shield]][cc]
4+
5+
[`rust-bitcoin`](https://github.com/rust-bitcoin/rust-bitcoin) is a library for working with Bitcoin in Rust.
6+
It contains Bitcoin network protocol and associated primitives.
7+
You can find more by reading the [documentation](https://docs.rs/bitcoin).
8+
9+
To add `rust-bitcoin` to your project, run:
10+
11+
```bash
12+
cargo add bitcoin
13+
```
14+
15+
Additionally, you can add flags to enable features.
16+
Here's an example:
17+
18+
```bash
19+
cargo add bitcoin --features=rand-std
20+
```
21+
22+
This cookbook provides straightforward examples that showcase effective approaches
23+
for accomplishing typical Bitcoin-related programming tasks,
24+
and utilizing the Rust ecosystem's crates.
25+
26+
The book covers various topics, including receiving data over P2P,
27+
parsing blocks and transactions,
28+
and constructing and signing transactions.
29+
30+
## Table of Contents
31+
32+
This book contains:
33+
34+
1. [Constructing and Signing Transactions](tx.md)
35+
1. [SegWit V0](tx_segwit-v0.md)
36+
1. [Taproot](tx_taproot.md)
37+
38+
## License
39+
40+
This website is licensed under [CC0 1.0 Universal (CC0 1.0) Public Domain Dedication][cc].
41+
42+
[![CC BY-SA 4.0][cc-image]][cc]
43+
44+
[cc]: https://creativecommons.org/publicdomain/zero/1.0/
45+
[cc-image]: https://licensebuttons.net/l/by-sa/4.0/88x31.png
46+
[cc-shield]: https://img.shields.io/badge/License-CC0%201.0-lightgrey.svg

cookbook/src/table_of_contents.md

-1
This file was deleted.

cookbook/src/tx.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Constructing and Signing Transactions
2+
3+
We provide the following examples:
4+
5+
- [Constructing and Signing Transactions - SegWit V0](tx_segwit-v0.md)
6+
- [Constructing and Signing Transactions - Taproot](tx_taproot.md)

0 commit comments

Comments
 (0)