Skip to content

Commit 47047b3

Browse files
committed
Move 'building chains' into cookbooks
1 parent 3a1ccb9 commit 47047b3

File tree

5 files changed

+59
-92
lines changed

5 files changed

+59
-92
lines changed

docs/cookbooks/index.rst

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
Cookbooks
2+
=========
3+
4+
The Cookbooks are collections of simple recipes that demonstrate good practices to accomplish
5+
common tasks. The examples are usually short answers to simple "How do I..." questions that go
6+
beyond simple API descriptions but also don't need a full guide to become clear.
7+
8+
.. _evm_cookbook:
9+
10+
EVM Cookbook
11+
~~~~~~~~~~~~
12+
13+
.. _evm_cookbook_recipe_using_the_chain_object:
14+
15+
Using the Chain object
16+
----------------------
17+
18+
A "single" blockchain is made by a series of different virtual machines
19+
for different spans of blocks. For example, the Ethereum mainnet had
20+
one virtual machine for blocks 0 till 1150000 (known as Frontier),
21+
and another VM for blocks 1150000 till 1920000 (known as Homestead).
22+
23+
The :class:`~eth.chains.chain.Chain` object manages the series of fork rules,
24+
after you define the VM ranges. For example, to set up a chain that would track
25+
the mainnet Ethereum network until block 1920000, you could create this chain
26+
class:
27+
28+
.. doctest::
29+
30+
>>> from eth import constants, Chain
31+
>>> from eth.vm.forks.frontier import FrontierVM
32+
>>> from eth.vm.forks.homestead import HomesteadVM
33+
>>> from eth.chains.mainnet import HOMESTEAD_MAINNET_BLOCK
34+
35+
>>> chain_class = Chain.configure(
36+
... __name__='Test Chain',
37+
... vm_configuration=(
38+
... (constants.GENESIS_BLOCK_NUMBER, FrontierVM),
39+
... (HOMESTEAD_MAINNET_BLOCK, HomesteadVM),
40+
... ),
41+
... )
42+
43+
Then to initialize, you can start it up with an in-memory database:
44+
45+
.. doctest::
46+
47+
>>> from eth.db.backends.memory import MemoryDB
48+
>>> from eth.chains.mainnet import MAINNET_GENESIS_HEADER
49+
50+
>>> # start a fresh in-memory db
51+
52+
>>> # initialize a fresh chain
53+
>>> chain = chain_class.from_genesis_header(MemoryDB(), MAINNET_GENESIS_HEADER)

docs/guides/eth/building_chains.rst

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

docs/guides/eth/index.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,5 @@ This section aims to provide hands-on guides to demonstrate how to use Py-EVM. I
1111
quickstart
1212
building_an_app_that_uses_pyevm
1313
architecture
14-
building_chains
1514
understanding_the_mining_process
1615
creating_opcodes

docs/guides/eth/understanding_the_mining_process.rst

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
Understanding the mining process
22
================================
33

4-
In the :doc:`Building Chains Guide <building_chains>` we already learned how to
5-
use the :class:`~eth.chains.base.MiningChain` class to create a single
4+
From the :ref:`EVM Cookbook<evm_cookbook>` we can already learn how to
5+
use the :class:`~eth.chains.base.Chain` class to create a single
66
blockchain as a combination of different virtual machines for different spans
77
of blocks.
88

@@ -38,7 +38,9 @@ block first because, after all, one primary use case for the Ethereum blockchain
3838
For the sake of simplicity though, we'll mine an empty block as a first example (meaning the block
3939
will not contain any transactions)
4040

41-
As a refresher, he's where we left of as part of the :doc:`Building Chains Guide </guides/eth/building_chains>`.
41+
As a refresher, he's how we create a chain as demonstrated in the
42+
:ref:`Using the chain object recipe<evm_cookbook_recipe_using_the_chain_object>` from the
43+
cookbook.
4244

4345
::
4446

docs/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Table of contents
1616
:maxdepth: 1
1717
:caption: Fundamentals
1818

19+
cookbooks/index
1920
guides/index
2021
api/index
2122

0 commit comments

Comments
 (0)