Skip to content

Commit 68b0766

Browse files
committed
mdBook generated from gitorial
1 parent 7d14411 commit 68b0766

File tree

562 files changed

+257444
-2799
lines changed

Some content is hidden

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

562 files changed

+257444
-2799
lines changed

src/0/source/.gitattributes

Lines changed: 0 additions & 2 deletions
This file was deleted.

src/0/source/README.md

Lines changed: 42 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,53 @@
1-
# Introduction to the Rust State Machine
1+
# Substrate Bitcoin-Like Blockchain Introduction
22

3-
Welcome to the Rust State Machine tutorial.
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.
44

5-
This is a guided tutorial intended to teach readers the basics of Rust, Blockchain, and eventually the inner workings of the [Polkadot SDK](https://github.com/paritytech/polkadot-sdk).
5+
## Prerequisites
66

7-
It has been my experience that the hardest part of building your first blockchain using the Polkadot SDK is navigating the advance Rust features used by [Substrate](https://github.com/paritytech/polkadot-sdk/tree/master/substrate), and understanding the underlying magic behind various macros which generate code for you.
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/).
88

9-
This tutorial tries to directly address this by having you build a completely vanilla Rust project which does all the same tricks as the Polkadot SDK, so you know first hand what is going on behind the scenes.
9+
## Useful Resources
1010

11-
This tutorial does not assume the reader has much previous knowledge about Rust, Blockchain, or the Polkadot SDK, however, this tutorial does not replace a basic introduction of any of those topics.
11+
Here are some essential resources that will assist you throughout this tutorial:
1212

13-
It is strongly recommended that before you begin this tutorial, that you at least have read the first 11 chapters of the [Rust Book](https://doc.rust-lang.org/book/).
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.
1418

15-
You need not be an expert in all that you read, but it will help to have exposure to all the various topics like: ownership, basic data types, structures, enums, crates, error handling, traits, generic types, and tests.
19+
By following these resources, you’ll gain a solid foundation in Substrate development, enabling you to make the most of this tutorial. 🚀
1620

17-
The tutorial is broken into sections which cover specific learning goals for the reader, and can act as good pause points if you need them.
1821

19-
All of the content of this tutorial is open source, free to access, and can be found [here](https://github.com/shawntabrizi/rust-state-machine).
22+
Overview of Bitcoin-like Blockchain in Substrate we will be building:
2023

21-
If you have suggestions which can improve the tutorial, comments, issues and pull requests are welcome.
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
2231
23-
Without further ado, enjoy and I hope you learn a ton!
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+
```

src/0/source/changes.diff

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +0,0 @@
1-
diff --git a/.gitattributes b/.gitattributes
2-
new file mode 100644
3-
index 00000000..dfe07704
4-
--- /dev/null
5-
+++ b/.gitattributes
6-
@@ -0,0 +1,2 @@
7-
+# Auto detect text files and perform LF normalization
8-
+* text=auto

src/1/README.md

Lines changed: 183 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,27 @@
1616

1717
<div class="tab">
1818
<button class="subtab tablinks file-source file-added active" onclick="switchSubTab(event, 'Cargo.toml')" data-id="Cargo.toml">Cargo.toml</button>
19-
<button class="subtab tablinks file-source file-added" onclick="switchSubTab(event, 'src/main.rs')" data-id="src/main.rs">src/main.rs</button>
19+
<button class="subtab tablinks file-source file-added" onclick="switchSubTab(event, 'LICENSE')" data-id="LICENSE">LICENSE</button>
20+
<button class="subtab tablinks file-source file-added" onclick="switchSubTab(event, 'multi-pow/Cargo.toml')" data-id="multi-pow/Cargo.toml">multi-pow/Cargo.toml</button>
21+
<button class="subtab tablinks file-source file-added" onclick="switchSubTab(event, 'multi-pow/src/lib.rs')" data-id="multi-pow/src/lib.rs">multi-pow/src/lib.rs</button>
22+
<button class="subtab tablinks file-source file-added" onclick="switchSubTab(event, 'node/Cargo.toml')" data-id="node/Cargo.toml">node/Cargo.toml</button>
23+
<button class="subtab tablinks file-source file-added" onclick="switchSubTab(event, 'node/build.rs')" data-id="node/build.rs">node/build.rs</button>
24+
<button class="subtab tablinks file-source file-added" onclick="switchSubTab(event, 'node/src/chain_spec.rs')" data-id="node/src/chain_spec.rs">node/src/chain_spec.rs</button>
25+
<button class="subtab tablinks file-source file-added" onclick="switchSubTab(event, 'node/src/cli.rs')" data-id="node/src/cli.rs">node/src/cli.rs</button>
26+
<button class="subtab tablinks file-source file-added" onclick="switchSubTab(event, 'node/src/command.rs')" data-id="node/src/command.rs">node/src/command.rs</button>
27+
<button class="subtab tablinks file-source file-added" onclick="switchSubTab(event, 'node/src/main.rs')" data-id="node/src/main.rs">node/src/main.rs</button>
28+
<button class="subtab tablinks file-source file-added" onclick="switchSubTab(event, 'node/src/rpc.rs')" data-id="node/src/rpc.rs">node/src/rpc.rs</button>
29+
<button class="subtab tablinks file-source file-added" onclick="switchSubTab(event, 'node/src/service.rs')" data-id="node/src/service.rs">node/src/service.rs</button>
30+
<button class="subtab tablinks file-source file-added" onclick="switchSubTab(event, 'runtime/Cargo.toml')" data-id="runtime/Cargo.toml">runtime/Cargo.toml</button>
31+
<button class="subtab tablinks file-source file-added" onclick="switchSubTab(event, 'runtime/build.rs')" data-id="runtime/build.rs">runtime/build.rs</button>
32+
<button class="subtab tablinks file-source file-added" onclick="switchSubTab(event, 'runtime/src/block_author.rs')" data-id="runtime/src/block_author.rs">runtime/src/block_author.rs</button>
33+
<button class="subtab tablinks file-source file-added" onclick="switchSubTab(event, 'runtime/src/difficulty.rs')" data-id="runtime/src/difficulty.rs">runtime/src/difficulty.rs</button>
34+
<button class="subtab tablinks file-source file-added" onclick="switchSubTab(event, 'runtime/src/issuance.rs')" data-id="runtime/src/issuance.rs">runtime/src/issuance.rs</button>
35+
<button class="subtab tablinks file-source file-added" onclick="switchSubTab(event, 'runtime/src/lib.rs')" data-id="runtime/src/lib.rs">runtime/src/lib.rs</button>
36+
<button class="subtab tablinks file-source file-added" onclick="switchSubTab(event, 'runtime/src/utxo.rs')" data-id="runtime/src/utxo.rs">runtime/src/utxo.rs</button>
37+
<button class="subtab tablinks file-source file-added" onclick="switchSubTab(event, 'rust-toolchain.toml')" data-id="rust-toolchain.toml">rust-toolchain.toml</button>
38+
<button class="subtab tablinks file-source file-added" onclick="switchSubTab(event, 'rustfmt.toml')" data-id="rustfmt.toml">rustfmt.toml</button>
39+
<button class="subtab tablinks file-source file-added" onclick="switchSubTab(event, 'spec.json')" data-id="spec.json">spec.json</button>
2040
</div>
2141
<div id="source/Cargo.toml" class="subtab tabcontent active" data-id="Cargo.toml">
2242

@@ -26,10 +46,170 @@
2646

2747
</div>
2848

29-
<div id="source/src/main.rs" class="subtab tabcontent" data-id="src/main.rs">
49+
<div id="source/LICENSE" class="subtab tabcontent" data-id="LICENSE">
50+
51+
```text
52+
{{#include ./source/LICENSE}}
53+
```
54+
55+
</div>
56+
57+
<div id="source/multi-pow/Cargo.toml" class="subtab tabcontent" data-id="multi-pow/Cargo.toml">
58+
59+
```toml
60+
{{#include ./source/multi-pow/Cargo.toml}}
61+
```
62+
63+
</div>
64+
65+
<div id="source/multi-pow/src/lib.rs" class="subtab tabcontent" data-id="multi-pow/src/lib.rs">
66+
67+
```rust
68+
{{#include ./source/multi-pow/src/lib.rs}}
69+
```
70+
71+
</div>
72+
73+
<div id="source/node/Cargo.toml" class="subtab tabcontent" data-id="node/Cargo.toml">
74+
75+
```toml
76+
{{#include ./source/node/Cargo.toml}}
77+
```
78+
79+
</div>
80+
81+
<div id="source/node/build.rs" class="subtab tabcontent" data-id="node/build.rs">
82+
83+
```rust
84+
{{#include ./source/node/build.rs}}
85+
```
86+
87+
</div>
88+
89+
<div id="source/node/src/chain_spec.rs" class="subtab tabcontent" data-id="node/src/chain_spec.rs">
90+
91+
```rust
92+
{{#include ./source/node/src/chain_spec.rs}}
93+
```
94+
95+
</div>
96+
97+
<div id="source/node/src/cli.rs" class="subtab tabcontent" data-id="node/src/cli.rs">
98+
99+
```rust
100+
{{#include ./source/node/src/cli.rs}}
101+
```
102+
103+
</div>
104+
105+
<div id="source/node/src/command.rs" class="subtab tabcontent" data-id="node/src/command.rs">
106+
107+
```rust
108+
{{#include ./source/node/src/command.rs}}
109+
```
110+
111+
</div>
112+
113+
<div id="source/node/src/main.rs" class="subtab tabcontent" data-id="node/src/main.rs">
114+
115+
```rust
116+
{{#include ./source/node/src/main.rs}}
117+
```
118+
119+
</div>
120+
121+
<div id="source/node/src/rpc.rs" class="subtab tabcontent" data-id="node/src/rpc.rs">
122+
123+
```rust
124+
{{#include ./source/node/src/rpc.rs}}
125+
```
126+
127+
</div>
128+
129+
<div id="source/node/src/service.rs" class="subtab tabcontent" data-id="node/src/service.rs">
30130

31131
```rust
32-
{{#include ./source/src/main.rs}}
132+
{{#include ./source/node/src/service.rs}}
133+
```
134+
135+
</div>
136+
137+
<div id="source/runtime/Cargo.toml" class="subtab tabcontent" data-id="runtime/Cargo.toml">
138+
139+
```toml
140+
{{#include ./source/runtime/Cargo.toml}}
141+
```
142+
143+
</div>
144+
145+
<div id="source/runtime/build.rs" class="subtab tabcontent" data-id="runtime/build.rs">
146+
147+
```rust
148+
{{#include ./source/runtime/build.rs}}
149+
```
150+
151+
</div>
152+
153+
<div id="source/runtime/src/block_author.rs" class="subtab tabcontent" data-id="runtime/src/block_author.rs">
154+
155+
```rust
156+
{{#include ./source/runtime/src/block_author.rs}}
157+
```
158+
159+
</div>
160+
161+
<div id="source/runtime/src/difficulty.rs" class="subtab tabcontent" data-id="runtime/src/difficulty.rs">
162+
163+
```rust
164+
{{#include ./source/runtime/src/difficulty.rs}}
165+
```
166+
167+
</div>
168+
169+
<div id="source/runtime/src/issuance.rs" class="subtab tabcontent" data-id="runtime/src/issuance.rs">
170+
171+
```rust
172+
{{#include ./source/runtime/src/issuance.rs}}
173+
```
174+
175+
</div>
176+
177+
<div id="source/runtime/src/lib.rs" class="subtab tabcontent" data-id="runtime/src/lib.rs">
178+
179+
```rust
180+
{{#include ./source/runtime/src/lib.rs}}
181+
```
182+
183+
</div>
184+
185+
<div id="source/runtime/src/utxo.rs" class="subtab tabcontent" data-id="runtime/src/utxo.rs">
186+
187+
```rust
188+
{{#include ./source/runtime/src/utxo.rs}}
189+
```
190+
191+
</div>
192+
193+
<div id="source/rust-toolchain.toml" class="subtab tabcontent" data-id="rust-toolchain.toml">
194+
195+
```toml
196+
{{#include ./source/rust-toolchain.toml}}
197+
```
198+
199+
</div>
200+
201+
<div id="source/rustfmt.toml" class="subtab tabcontent" data-id="rustfmt.toml">
202+
203+
```toml
204+
{{#include ./source/rustfmt.toml}}
205+
```
206+
207+
</div>
208+
209+
<div id="source/spec.json" class="subtab tabcontent" data-id="spec.json">
210+
211+
```json
212+
{{#include ./source/spec.json}}
33213
```
34214

35215
</div>

src/1/source/.editorconfig

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
root = true
2+
[*]
3+
indent_style=tab
4+
indent_size=tab
5+
tab_width=4
6+
end_of_line=lf
7+
charset=utf-8
8+
trim_trailing_whitespace=true
9+
max_line_length=100
10+
insert_final_newline=true
11+
12+
[*.yml]
13+
indent_style=space
14+
indent_size=2
15+
tab_width=8
16+
end_of_line=lf
17+
18+
[*.sh]
19+
indent_style=space
20+
indent_size=2
21+
tab_width=8
22+
end_of_line=lf
23+
24+
[*.js]
25+
indent_style=space
26+
indent_size=4
27+
28+
29+
[*.jsx]
30+
indent_style=space
31+
indent_size=4
32+
33+
[Dockerfile]
34+
indent_style=space
35+
indent_size=2

src/1/source/.gitattributes

Lines changed: 0 additions & 2 deletions
This file was deleted.

src/1/source/.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
1+
**/*.rs.bk
12
**/target/
2-
.DS_Store
3+
addresses.json
4+
5+
validators

0 commit comments

Comments
 (0)