Skip to content

Commit 37d885b

Browse files
committed
feat(docs): merge doc into main
1 parent fd1803c commit 37d885b

File tree

1,184 files changed

+295511
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,184 files changed

+295511
-0
lines changed

.github/workflows/mdbook.yml

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# Sample workflow for building and deploying a mdBook site to GitHub Pages
2+
#
3+
# To get started with mdBook see: https://rust-lang.github.io/mdBook/index.html
4+
#
5+
name: Deploy mdBook site to Pages
6+
7+
on:
8+
# Runs on pushes targeting the default branch
9+
push:
10+
branches: ["main"]
11+
12+
# Allows you to run this workflow manually from the Actions tab
13+
workflow_dispatch:
14+
15+
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
16+
permissions:
17+
contents: read
18+
pages: write
19+
id-token: write
20+
21+
# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
22+
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
23+
concurrency:
24+
group: "pages"
25+
cancel-in-progress: false
26+
27+
jobs:
28+
# Build job
29+
build:
30+
runs-on: ubuntu-latest
31+
env:
32+
MDBOOK_VERSION: 0.4.36
33+
steps:
34+
- uses: actions/checkout@v4
35+
- name: Install mdBook
36+
run: |
37+
curl --proto '=https' --tlsv1.2 https://sh.rustup.rs -sSf -y | sh
38+
rustup update
39+
cargo install --version ${MDBOOK_VERSION} mdbook
40+
cargo install mdbook-mermaid
41+
- name: Setup Pages
42+
id: pages
43+
uses: actions/configure-pages@v4
44+
- name: Build with mdBook
45+
run: |
46+
cd ./tutorial-book
47+
mdbook-mermaid install
48+
mdbook build
49+
- name: Upload artifact
50+
uses: actions/upload-pages-artifact@v3
51+
with:
52+
path: ./tutorial-book/book
53+
54+
# Deployment job
55+
deploy:
56+
environment:
57+
name: github-pages
58+
url: ${{ steps.deployment.outputs.page_url }}
59+
runs-on: ubuntu-latest
60+
needs: build
61+
steps:
62+
- name: Deploy to GitHub Pages
63+
id: deployment
64+
uses: actions/deploy-pages@v4

tutorial-book/.gitattributes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Auto detect text files and perform LF normalization
2+
* text=auto

tutorial-book/.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
book
2+
**/target/
3+
.DS_Store
4+
steps

tutorial-book/LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2024 Shawn Tabrizi
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

tutorial-book/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Building Bitcoin-like Blockchain in Substrate Book

tutorial-book/book.toml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[book]
2+
authors = ["@danielbui12"]
3+
language = "en"
4+
multilingual = false
5+
src = "src"
6+
title = "Substrate Bitcoin-like Blockchain"
7+
8+
[output.html]
9+
additional-css = ["custom/styles.css"]
10+
additional-js = ["custom/tabs.js"]
11+
git-repository-url = "https://github.com/openguild-labs/substrate-bitcoin"
12+
git-repository-icon = "fa-github"

tutorial-book/custom/styles.css

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
:root {
2+
--content-max-width: 100% !important;
3+
}
4+
5+
/* -- Section -- */
6+
7+
.content-section {
8+
max-width: 800px;
9+
margin: auto;
10+
padding: 0px 5px 50px 5px;
11+
}
12+
13+
/* -- Nav -- */
14+
15+
.nav-chapters {
16+
/* Make nav buttons not full height on wide screen. */
17+
top: auto;
18+
margin: 10px;
19+
font-size: 2.5em;
20+
text-align: center;
21+
text-decoration: none;
22+
width: 90px;
23+
border-radius: 5px;
24+
}
25+
26+
/* -- Two Col Layout -- */
27+
28+
.content-col {
29+
width: 100%;
30+
padding-bottom: 50px;
31+
}
32+
33+
@media screen and (min-width: 1081px) {
34+
35+
/* -- Override Content Padding - Move to Col -- */
36+
.content {
37+
padding: 0px;
38+
}
39+
40+
.content-col {
41+
width: calc(50% - 10px);
42+
height: calc(100vh - 102px);
43+
float: left;
44+
overflow: scroll;
45+
padding: 0px 5px 50px 5px;
46+
}
47+
}
48+
49+
/* -- Tabs -- */
50+
51+
/* Style the tab */
52+
.tab {
53+
overflow: hidden;
54+
border: 1px solid color-mix(in srgb, var(--sidebar-bg), #888 15%);
55+
background-color: var(--sidebar-bg);
56+
color: var(--sidebar-fg);
57+
}
58+
59+
/* Style the buttons that are used to open the tab content */
60+
.tab button {
61+
background-color: inherit;
62+
float: left;
63+
border: none;
64+
outline: none;
65+
cursor: pointer;
66+
padding: 14px 16px;
67+
transition: 0.3s;
68+
color: var(--sidebar-fg);
69+
}
70+
71+
/* Change background color of buttons on hover */
72+
.tab button:hover {
73+
background-color: color-mix(in srgb, var(--sidebar-bg), #888 30%);
74+
}
75+
76+
/* Create an active/current tablink class */
77+
.tab button.active {
78+
background-color: color-mix(in srgb, var(--sidebar-bg), #888 50%);
79+
}
80+
81+
/* Style the tab content */
82+
.tabcontent {
83+
display: none;
84+
border: 1px solid color-mix(in srgb, var(--sidebar-bg), #888 15%);
85+
border-top: none;
86+
}
87+
88+
.tabcontent pre {
89+
margin: 0px;
90+
}
91+
92+
.tabcontent.active {
93+
display: block !important;
94+
}
95+
96+
.file-modified {
97+
color: darkorange !important;
98+
}
99+
100+
.file-solution.file-modified {
101+
color: light-dark(darkblue, skyblue) !important;
102+
}
103+
104+
.file-added {
105+
color: light-dark(darkgreen, limegreen) !important;
106+
}

tutorial-book/custom/tabs.js

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
function switchMainTab(evt, tabName) {
2+
// Declare all variables
3+
var i, tabcontent, tablinks;
4+
5+
// Get all elements with class="tabcontent" and hide them
6+
tabcontent = document.getElementsByClassName("maintab tabcontent");
7+
for (i = 0; i < tabcontent.length; i++) {
8+
tabcontent[i].className = tabcontent[i].className.replace(" active", "");
9+
}
10+
11+
// Get all elements with class="tablinks" and remove the class "active"
12+
tablinks = document.getElementsByClassName("maintab tablinks");
13+
for (i = 0; i < tablinks.length; i++) {
14+
tablinks[i].className = tablinks[i].className.replace(" active", "");
15+
}
16+
17+
// Show the current tab, and add an "active" class to the button that opened the tab
18+
document.getElementById(tabName).className += " active";
19+
evt.currentTarget.className += " active";
20+
}
21+
22+
function switchSubTab(evt, filePath) {
23+
// Declare all variables
24+
var i, tabcontent, tablinks;
25+
26+
// Get all elements with class="tabcontent" and hide them
27+
tabcontent = document.getElementsByClassName("subtab tabcontent");
28+
for (i = 0; i < tabcontent.length; i++) {
29+
tabcontent[i].className = tabcontent[i].className.replace(" active", "");
30+
}
31+
32+
// Get all elements with class="tablinks" and remove the class "active"
33+
tablinks = document.getElementsByClassName("subtab tablinks");
34+
for (i = 0; i < tablinks.length; i++) {
35+
tablinks[i].className = tablinks[i].className.replace(" active", "");
36+
}
37+
38+
// Get all elements with class matching the tabname class and show them
39+
tabcontent = document.querySelectorAll(`[data-id="${filePath}"]`);
40+
for (i = 0; i < tabcontent.length; i++) {
41+
tabcontent[i].className += " active";
42+
}
43+
}
44+
45+
function switchDiff(evt, filePath) {
46+
// Declare all variables
47+
var i, tabcontent, tablinks;
48+
49+
// Get all elements with class="tabcontent" and hide them
50+
tabcontent = document.getElementsByClassName("difftab tabcontent");
51+
for (i = 0; i < tabcontent.length; i++) {
52+
tabcontent[i].className = tabcontent[i].className.replace(" active", "");
53+
}
54+
55+
// Get all elements with class="tablinks" and remove the class "active"
56+
tablinks = document.getElementsByClassName("difftab tablinks");
57+
for (i = 0; i < tablinks.length; i++) {
58+
tablinks[i].className = tablinks[i].className.replace(" active", "");
59+
}
60+
61+
// Get all elements with class matching the tabname class and show them
62+
tabcontent = document.querySelectorAll(`[data-id="${filePath}"]`);
63+
for (i = 0; i < tabcontent.length; i++) {
64+
tabcontent[i].className += " active";
65+
}
66+
}

tutorial-book/src/0/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
<div class="content-section">
3+
4+
{{#include ./source/README.md}}
5+
6+
</div>
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Substrate Bitcoin-Like Blockchain Introduction
2+
3+
This repository is derived from [Academy-PoW](https://github.com/Polkadot-Blockchain-Academy/Academy-PoW), originally designed as a learning resource. While implementing a Bitcoin-like blockchain, I faced several challenges that required updates and fixes to ensure smooth execution. Additionally, I transitioned the account model from an **Account-based** system to a **UTXO-based** approach. This implementation builds upon the foundational work from **[Building a UTXO Chain from Scratch | Substrate Seminar](https://www.youtube.com/watch?v=XuJmxMMHvDw)**. Inspired by this resource, I aimed to further enhance the project, incorporating my own insights and improvements.
4+
5+
## Prerequisites
6+
7+
Before starting this interactive tutorial, you should have a basic understanding of **Substrate** and **FRAME development**. If you're new to these concepts, it's highly recommended to complete the introductory Substrate tutorials available in the official documentation. For example [Substrate Interactive Tutorial - Polkadot Study](https://polkadot.study/tutorials/interactive-substrate-tutorials-rusty-crewmates/).
8+
9+
## Useful Resources
10+
11+
Here are some essential resources that will assist you throughout this tutorial:
12+
13+
- [Set Up Substrate Development Environment](https://docs.substrate.io/install/) – Choose your environment and complete the installation of required packages and Rust.
14+
- [Polkadot SDK Documentation](https://paritytech.github.io/polkadot-sdk/master/polkadot_sdk_docs/polkadot_sdk/index.html) – In-depth reference for the Polkadot SDK.
15+
- [Simulating a Substrate Network](https://docs.substrate.io/tutorials/build-a-blockchain/simulate-network/) – Learn how to simulate a network in Substrate.
16+
- [Unspent Transaction Output (UTXO)](https://github.com/danielbui12/substrate-bitcoin-like-blockchain/blob/main/docs/utxo/utxo.md) – Understanding UTXO account model.
17+
- [Proof of Work code breakdown](https://github.com/danielbui12/substrate-bitcoin-like-blockchain/blob/main/docs/pow/code-breakdown.md) – Learn how the Proof of Work code is implemented.
18+
19+
By following these resources, you’ll gain a solid foundation in Substrate development, enabling you to make the most of this tutorial. 🚀
20+
21+
22+
Overview of Bitcoin-like Blockchain in Substrate we will be building:
23+
24+
```mermaid
25+
graph TD;
26+
subgraph UTXO_Runtime
27+
Timestamp -->|Time trait| Difficulty
28+
Block_Author -->|BlockAuthor| UTXO
29+
Bitcoin_Halving --> |Issuance| UTXO
30+
FRAME_System
31+
32+
subgraph Difficulty
33+
Sha3_Difficulty
34+
Keccak_Difficulty
35+
Md5_Difficulty
36+
end
37+
end
38+
39+
subgraph UTXO_Node
40+
subgraph Multi_PoW_Consensus
41+
Sha3_Algorithm
42+
Keccak_Algorithm
43+
Md5_Algorithm
44+
end
45+
46+
Tx_Pool
47+
end
48+
49+
Difficulty --> Difficulty_API{{Difficulty API}}
50+
Difficulty_API --> Multi_PoW_Consensus
51+
UTXO --> Tx_Pool_API{{Tx Pool API}}
52+
Tx_Pool_API --> Tx_Pool
53+
```

0 commit comments

Comments
 (0)