Skip to content

Commit 6068530

Browse files
authored
Monorepo: Embed Code Examples in README Files
* Add embedme dev dependency to root package.json * Rebuild package-lock.json * Add examples:build script to package.json (Block) * Integrate first exemplary Block example * Replace typescript marker for markdown code embeds with ts (working alternative + embedme compatible) * Add missing examples for block * Add Util package examples, expand README with dedicated module sections and examples * Flesh out 4844 example
1 parent 3981bca commit 6068530

Some content is hidden

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

49 files changed

+825
-394
lines changed

package-lock.json

Lines changed: 68 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"@vitest/coverage-v8": "0.32.2",
2828
"@vitest/ui": "0.32.2",
2929
"c8": "7.12.0",
30+
"embedme": "1.22.1",
3031
"eslint": "8.45.0",
3132
"eslint-config-prettier": "8.8.0",
3233
"eslint-config-typestrict": "1.0.5",

packages/block/CHANGELOG.md

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,14 @@ The Shanghai hardfork is now the default HF in `@ethereumjs/common` and therefor
5858

5959
Also the Merge HF has been renamed to Paris (`Hardfork.Paris`) which is the correct HF name on the execution side, see [#2652](https://github.com/ethereumjs/ethereumjs-monorepo/pull/2652). To set the HF to Paris in Common you can do:
6060

61-
```typescript
61+
```ts
6262
import { Chain, Common, Hardfork } from '@ethereumjs/common'
6363
const common = new Common({ chain: Chain.Mainnet, hardfork: Hardfork.Paris })
6464
```
6565

6666
And third on hardforks 🙂: the upcoming Cancun hardfork is now fully supported and all EIPs are included (see PRs [#2659](https://github.com/ethereumjs/ethereumjs-monorepo/pull/2659) and [#2892](https://github.com/ethereumjs/ethereumjs-monorepo/pull/2892)). The Cancun HF can be activated with:
6767

68-
```typescript
68+
```ts
6969
import { Chain, Common, Hardfork } from '@ethereumjs/common'
7070
const common = new Common({ chain: Chain.Mainnet, hardfork: Hardfork.Cancun })
7171
```
@@ -78,7 +78,7 @@ Our APIs to (re-)set a a hardfork within a library had grown old over all change
7878

7979
We therefore removed the outdated `getHardforkByBlockNumber()` and `setHardforkByBlockNumber()` methods in `@ethereumjs/common` (artificially expanded with the option to also pass a `TD` or `timestamp`) with a more adequate `hardforkBy()` method flexibly taking in the adequate value type for a HF change, see PR [#2798](https://github.com/ethereumjs/ethereumjs-monorepo/pull/2798):
8080

81-
```typescript
81+
```ts
8282
common.setHardforkBy({ blockNumber: 5000000n }) // Setting a mainnet common to a Block from `Byzantium` (and so: to `Byzantium` HF)
8383
common.setHardforkBy({ timestamp: 1681340000n }) // Setting a mainnet common to a post-Shanghai timestamp
8484
common.setHardforkBy({ blockNumber, timestamp }) // Setting a common with to a not pre-known HF using both block number and timestamp
@@ -94,14 +94,14 @@ We have cleaned up and unified the validation methods in the `Block` library, se
9494

9595
The `Block.validateTransactions()` method, previously overloaded with different return types depending on the input, has been split up into:
9696

97-
```typescript
97+
```ts
9898
Block.transactionsAreValid(): boolean
9999
Block.getTransactionsValidationErrors(): string[]
100100
```
101101

102102
Other renamings:
103103

104-
```typescript
104+
```ts
105105
Block.validateTransactionsTrie(): Promise<boolean> // old
106106
Block.transactionsTrieIsValid(): Promise<boolean> // new
107107

@@ -124,7 +124,7 @@ The global initialization method for the KZG setup has been moved to a dedicated
124124

125125
The `initKZG()` method can be used as follows:
126126

127-
```typescript
127+
```ts
128128
// Make the kzg library available globally
129129
import * as kzg from 'c-kzg'
130130
import { initKZG } from '@ethereumjs/util'
@@ -141,7 +141,7 @@ For the Block library the most significant change is that there is now a new hea
141141

142142
Additionally there are the following three `dataGasUsed`/`excessDataGas` related new helper methods:
143143

144-
```typescript
144+
```ts
145145
BlockHeader.getDataGasPrice(): bigint
146146
BlockHeader.calcDataFee(numBlobs: number): bigint
147147
BlockHeader.calcNextExcessDataGas(): bigint
@@ -157,7 +157,7 @@ Two new handy constructors have been added to the `Block` class to bring the con
157157

158158
`Block.fromBeaconPayloadJson()` allows to initialize an Ethereum execution layer (EL) block with a payload received from the beacon chain (consensus layer (CL)) via an RPC call. 🤩 The new constructor can be used as follows:
159159

160-
```typescript
160+
```ts
161161
const block = await Block.fromBeaconPayloadJson(payload, { common })
162162
```
163163

@@ -173,14 +173,14 @@ Both builds have respective separate entrypoints in the distributed `package.jso
173173

174174
A CommonJS import of our libraries can then be done like this:
175175

176-
```typescript
176+
```ts
177177
const { Chain, Common } = require('@ethereumjs/common')
178178
const common = new Common({ chain: Chain.Mainnet })
179179
```
180180

181181
And this is how an ESM import looks like:
182182

183-
```typescript
183+
```ts
184184
import { Chain, Common } from '@ethereumjs/common'
185185
const common = new Common({ chain: Chain.Mainnet })
186186
```
@@ -199,7 +199,7 @@ We nevertheless think this is very much worth it and we tried to make transition
199199

200200
For this library you should check if you use one of the following constructors, methods, constants or types and do a search and update input and/or output values or general usages and add conversion methods if necessary:
201201

202-
```typescript
202+
```ts
203203
// header
204204
BlockHeader.fromHeaderData(headerData: HeaderData = {}, opts: BlockOptions = {})
205205
BlockHeader.fromRLPSerializedHeader(serializedHeaderData: Uint8Array, opts: BlockOptions = {})
@@ -267,7 +267,7 @@ This release fully supports all EIPs included in the [Shanghai](https://github.c
267267

268268
You can instantiate a Shanghai-enabled Common instance for your transactions with:
269269

270-
```typescript
270+
```ts
271271
import { Common, Chain, Hardfork } from '@ethereumjs/common'
272272

273273
const common = new Common({ chain: Chain.Mainnet, hardfork: Hardfork.Shanghai })
@@ -281,7 +281,7 @@ This release supports an experimental version of the blob transaction type intro
281281

282282
To create blocks which include blob transactions you have to active EIP-4844 in the associated `@ethereumjs/common` library:
283283

284-
```typescript
284+
```ts
285285
import { Common, Chain, Hardfork } from '@ethereumjs/common'
286286

287287
const common = new Common({ chain: Chain.Mainnet, hardfork: Hardfork.Shanghai, eips: [4844] })
@@ -304,7 +304,7 @@ This release comes with experimental [EIP-4895](https://eips.ethereum.org/EIPS/e
304304

305305
Withdrawals support can be activated by initializing a respective `Common` object, here is an example for a `Block` object initialization:
306306

307-
```typescript
307+
```ts
308308
import { Block } from '@ethereumjs/block'
309309
import { Common, Chain } from '@ethereumjs/common'
310310
import { Address } from '@ethereumjs/util'
@@ -351,7 +351,7 @@ For lots of custom chains (for e.g. devnets and testnets), you might come across
351351

352352
`Common` now has a new constructor `Common.fromGethGenesis()` - see PRs [#2300](https://github.com/ethereumjs/ethereumjs-monorepo/pull/2300) and [#2319](https://github.com/ethereumjs/ethereumjs-monorepo/pull/2319) - which can be used in following manner to instantiate for example a VM run or a tx with a `genesis.json` based Common:
353353

354-
```typescript
354+
```ts
355355
import { Common } from '@ethereumjs/common'
356356
// Load geth genesis json file into lets say `genesisJson` and optional `chain` and `genesisHash`
357357
const common = Common.fromGethGenesis(genesisJson, { chain: 'customChain', genesisHash })
@@ -410,7 +410,7 @@ This means that if this library is instantiated without providing an explicit `C
410410

411411
If you want to prevent these kind of implicit HF switches in the future it is likely a good practice to just always do your upper-level library instantiations with a `Common` instance setting an explicit HF, e.g.:
412412

413-
```typescript
413+
```ts
414414
import { Common, Chain, Hardfork } from '@ethereumjs/common'
415415

416416
const common = new Common({ chain: Chain.Mainnet, hardfork: Hardfork.London })
@@ -445,15 +445,15 @@ Since our [@ethereumjs/common](https://github.com/ethereumjs/ethereumjs-monorepo
445445

446446
So Common import and usage is changing from:
447447

448-
```typescript
448+
```ts
449449
import Common, { Chain, Hardfork } from '@ethereumjs/common'
450450

451451
const common = new Common({ chain: Chain.Mainnet, hardfork: Hardfork.Merge })
452452
```
453453

454454
to:
455455

456-
```typescript
456+
```ts
457457
import { Common, Chain, Hardfork } from '@ethereumjs/common'
458458

459459
const common = new Common({ chain: Chain.Mainnet, hardfork: Hardfork.Merge })
@@ -489,7 +489,7 @@ This means that a Block object instantiated without providing an explicit `Commo
489489

490490
If you want to prevent these kind of implicit HF switches in the future it is likely a good practice to just always do your upper-level library instantiations with a `Common` instance setting an explicit HF, e.g.:
491491

492-
```typescript
492+
```ts
493493
import Common, { Chain, Hardfork } from '@ethereumjs/common'
494494

495495
const common = new Common({ chain: Chain.Mainnet, hardfork: Hardfork.Merge })
@@ -618,7 +618,7 @@ Please note that for backwards-compatibility reasons the associated Common is st
618618

619619
An ArrowGlacier block can be instantiated with:
620620

621-
```typescript
621+
```ts
622622
import { Block } from '@ethereumjs/block'
623623
import Common, { Chain, Hardfork } from '@ethereumjs/common'
624624

@@ -674,7 +674,7 @@ Proof-of-Stake compatible execution blocks come with its own set of header field
674674

675675
You can instantiate a Merge/PoS block like this:
676676

677-
```typescript
677+
```ts
678678
import { Block } from '@ethereumjs/block'
679679
import Common, { Chain, Hardfork } from '@ethereumjs/common'
680680
const common = new Common({ chain: Chain.Mainnet, hardfork: Hardfork.Merge })
@@ -719,7 +719,7 @@ Source files from the `src` folder are now included in the distribution build, s
719719

720720
This `Block` release comes with full functional support for the `london` hardfork (all EIPs are finalized and integrated and `london` HF can be activated, there are no final block numbers for the HF integrated though yet). Please note that the default HF is still set to `istanbul`. You therefore need to explicitly set the `hardfork` parameter for instantiating a `Common` instance with a `london` HF activated:
721721

722-
```typescript
722+
```ts
723723
import { BN } from 'ethereumjs-util'
724724
import { Block } from '@ethereumjs/block'
725725
import Common from '@ethereumjs/common'
@@ -767,7 +767,7 @@ This release gets the `Block` library ready for the `berlin` HF by adding suppor
767767

768768
Please note that the default HF is still set to `istanbul`. You therefore need to explicitly set the `hardfork` parameter for instantiating a `Block` instance with a `berlin` HF activated:
769769

770-
```typescript
770+
```ts
771771
import { Block } from 'ethereumjs-block'
772772
import Common from '@ethereumjs/common'
773773
const common = new Common({ chain: 'mainnet', hardfork: 'berlin' })
@@ -797,7 +797,7 @@ This release introduces Clique/PoA support for the `Block` library, see the main
797797

798798
For sealing a block on instantiation there is a new `cliqueSigner` constructor option:
799799

800-
```typescript
800+
```ts
801801
const cliqueSigner = Buffer.from('PRIVATE_KEY_HEX_STRING', 'hex')
802802
const block = Block.fromHeaderData(headerData, { cliqueSigner })
803803
```
@@ -842,7 +842,7 @@ The import structure has slightly changed along:
842842

843843
**TypeScript**
844844

845-
```typescript
845+
```ts
846846
import { BlockHeader } from 'ethereumjs-block'
847847
import { Block } from 'ethereumjs-block'
848848
```
@@ -874,7 +874,7 @@ There are three new factory methods to create a new `BlockHeader`:
874874

875875
1. Pass in a Header-attribute named dictionary to `BlockHeader.fromHeaderData(headerData: HeaderData = {}, opts?: BlockOptions)`:
876876

877-
```typescript
877+
```ts
878878
const headerData = {
879879
number: 15,
880880
parentHash: '0x6bfee7294bf44572b7266358e627f3c35105e1c3851f3de09e6d646f955725a7',
@@ -887,7 +887,7 @@ const header = BlockHeader.fromHeaderData(headerData)
887887

888888
2. Create a `BlockHeader` from an RLP-serialized header `Buffer` with `BlockHeader.fromRLPSerializedHeader(serialized: Buffer, opts: BlockOptions)`.
889889

890-
```typescript
890+
```ts
891891
const serialized = Buffer.from(
892892
'f901f7a06bfee7294bf44572b7266358e627f3c35105e1c3851f3de09e6d646f955725a7a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347940000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421b9010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000830200000f837a120080845d20ab8080a00000000000000000000000000000000000000000000000000000000000000000880000000000000000',
893893
'hex'
@@ -897,7 +897,7 @@ const header = BlockHeader.fromRLPSerializedHeader(serialized)
897897

898898
3. Create a `BlockHeader` from an array of `Buffer` values, you can do a first short roundtrip test with:
899899

900-
```typescript
900+
```ts
901901
const valuesArray = header.raw()
902902
BlockHeader.fromValuesArray(valuesArray)
903903
```
@@ -1042,7 +1042,7 @@ The import structure has slightly changed along:
10421042

10431043
**TypeScript**
10441044

1045-
```typescript
1045+
```ts
10461046
import { BlockHeader } from 'ethereumjs-block'
10471047
import { Block } from 'ethereumjs-block'
10481048
```
@@ -1082,7 +1082,7 @@ There are three new factory methods to create a new `BlockHeader`:
10821082

10831083
1. Pass in a Header-attribute named dictionary to `BlockHeader.fromHeaderData(headerData: HeaderData = {}, opts?: BlockOptions)`:
10841084

1085-
```typescript
1085+
```ts
10861086
const headerData = {
10871087
number: 15,
10881088
parentHash: '0x6bfee7294bf44572b7266358e627f3c35105e1c3851f3de09e6d646f955725a7',
@@ -1095,7 +1095,7 @@ const header = BlockHeader.fromHeaderData(headerData)
10951095

10961096
2. Create a `BlockHeader` from an RLP-serialized header `Buffer` with `BlockHeader.fromRLPSerializedHeader(serialized: Buffer, opts: BlockOptions)`.
10971097

1098-
```typescript
1098+
```ts
10991099
const serialized = Buffer.from(
11001100
'f901f7a06bfee7294bf44572b7266358e627f3c35105e1c3851f3de09e6d646f955725a7a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347940000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421b9010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000830200000f837a120080845d20ab8080a00000000000000000000000000000000000000000000000000000000000000000880000000000000000',
11011101
'hex'
@@ -1105,7 +1105,7 @@ const header = BlockHeader.fromRLPSerializedHeader(serialized)
11051105

11061106
3. Create a `BlockHeader` from an array of `Buffer` values, you can do a first short roundtrip test with:
11071107

1108-
```typescript
1108+
```ts
11091109
const valuesArray = header.raw()
11101110
BlockHeader.fromValuesArray(valuesArray)
11111111
```

0 commit comments

Comments
 (0)