Skip to content
This repository was archived by the owner on Apr 6, 2020. It is now read-only.

Commit 3dd0ffb

Browse files
authored
Merge pull request #98 from ethereumjs/tsdocs-docs
Typedoc generated docs
2 parents b155694 + 82d057a commit 3dd0ffb

File tree

9 files changed

+682
-213
lines changed

9 files changed

+682
-213
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
.idea/
2+
13
# Created by https://www.gitignore.io/api/osx,node
24

35
### OSX ###

README.md

Lines changed: 1 addition & 195 deletions
Original file line numberDiff line numberDiff line change
@@ -11,200 +11,6 @@ A module to store and interact with blocks.
1111

1212
`npm install ethereumjs-blockchain`
1313

14-
# EXAMPLE
15-
16-
The following is an example to iterate through an existing Geth DB (needs `level` to be
17-
installed separately):
18-
19-
```javascript
20-
const level = require('level')
21-
const Blockchain = require('ethereumjs-blockchain')
22-
const utils = require('ethereumjs-util')
23-
24-
const gethDbPath = './chaindata' // Add your own path here
25-
const db = level(gethDbPath)
26-
27-
new Blockchain({ db: db }).iterator(
28-
'i',
29-
(block, reorg, cb) => {
30-
const blockNumber = utils.bufferToInt(block.header.number)
31-
const blockHash = block.hash().toString('hex')
32-
console.log(`BLOCK ${blockNumber}: ${blockHash}`)
33-
cb()
34-
},
35-
err => console.log(err || 'Done.'),
36-
)
37-
```
38-
39-
**WARNING**: Since `ethereumjs-blockchain` is also doing write operations
40-
on the DB for safety reasons only run this on a copy of your database, otherwise this might lead
41-
to a compromised DB state.
42-
4314
# API
4415

45-
- [`Blockchain`](#blockchain)
46-
- [`new Blockchain(opts)`](#new-blockchainblockdb-detailsdb)
47-
- [`BlockChain` methods](#blockchain-methods)
48-
- [`blockchain.putGenesis(genesis, [cb])`](#blockchainputgenesisgenesis-cb)
49-
- [`blockchain.getHead(name, [cb])`](#blockchaingetheadname-cb)
50-
- [`blockchain.getLatestHeader([cb])`](#blockchaingetlatestheadercb)
51-
- [`blockchain.getLatestBlock([cb])`](#blockchaingetlatestblockcb)
52-
- [`blockchain.putBlocks(blocks, [cb])`](#blockchainputblocksblocks-cb)
53-
- [`blockchain.putBlock(block, [cb])`](#blockchainputblockblock-cb)
54-
- [`blockchain.getBlock(hash, [cb])`](#blockchaingetblockhash-cb)
55-
- [`blockchain.getBlocks(blockId, maxBlocks, skip, reverse, [cb])`](#blockchaingetblocksblockid-maxblocks-skip-reverse-cb)
56-
- [`blockchain.putHeaders(headers, [cb])`](#blockchainputheadersheaders-cb)
57-
- [`blockchain.putHeader(header, [cb])`](#blockchainputheaderheader-cb)
58-
- [`blockchain.selectNeededHashes(hashes, [cb])`](#blockchainselectneededhasheshashes-cb)
59-
- [`blockchain.delBlock(blockHash, [cb])`](#blockchaindelblockblockhash-cb)
60-
- [`blockchain.iterator(name, onBlock, [cb])`](#blockchainiteratorname-onblock-cb)
61-
62-
## `Blockchain`
63-
64-
Implements functions for retrieving, manipulating and storing Ethereum's blockchain
65-
66-
### `new Blockchain(opts)`
67-
68-
Creates new Blockchain object
69-
70-
- `opts.chain` **([String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) \| [Number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number))** The chain for the block [default: 'mainnet']
71-
- `opts.hardfork` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** Hardfork for the block [default: null, block number-based behavior]
72-
- `opts.common` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** Alternatively pass a Common instance (ethereumjs-common) instead of setting chain/hardfork directly
73-
- `opts.db` - Database to store blocks and metadata. Should be a [levelup](https://github.com/rvagg/node-levelup) instance.
74-
- `opts.validate` - this the flag to validate blocks (e.g. Proof-of-Work), latest HF rules supported: `Constantinople`.
75-
76-
[DEPRECATION NOTE]
77-
The old separated DB constructor parameters `opts.blockDB` and `opts.detailsDB` from before the Geth DB-compatible `v3.0.0` release are deprecated and continued usage is discouraged. When provided `opts.blockDB` will be used
78-
as `opts.db` and `opts.detailsDB` is ignored. On the storage level the DB formats are not compatible and it is not
79-
possible to load an old-format DB state into a post-`v3.0.0` `Blockchain` object.
80-
81-
### `BlockChain` methods
82-
83-
#### `blockchain.putGenesis(genesis, cb)`
84-
85-
Puts the genesis block in the database.
86-
87-
- `genesis` - the genesis block to be added
88-
- `cb` - the callback. It is given two parameters `err` and the saved `block`
89-
90-
---
91-
92-
#### `blockchain.getHead(name, cb)`
93-
94-
Returns the specified iterator head.
95-
96-
- `name` - Optional name of the state root head (default: 'vm')
97-
- `cb` - the callback. It is given two parameters `err` and the returned `block`
98-
99-
---
100-
101-
#### `blockchain.getLatestHeader(cb)`
102-
103-
Returns the latest header in the canonical chain.
104-
105-
- `cb` - the callback. It is given two parameters `err` and the returned `header`
106-
107-
---
108-
109-
#### `blockchain.getLatestBlock(cb)`
110-
111-
Returns the latest full block in the canonical chain.
112-
113-
- `cb` - the callback. It is given two parameters `err` and the returned `block`
114-
115-
---
116-
117-
#### `blockchain.putBlocks(blocks, cb)`
118-
119-
Adds many blocks to the blockchain.
120-
121-
- `blocks` - the blocks to be added to the blockchain
122-
- `cb` - the callback. It is given two parameters `err` and the last of the saved `blocks`
123-
124-
---
125-
126-
#### `blockchain.putBlock(block, cb)`
127-
128-
Adds a block to the blockchain.
129-
130-
- `block` - the block to be added to the blockchain
131-
- `cb` - the callback. It is given two parameters `err` and the saved `block`
132-
133-
---
134-
135-
#### `blockchain.getBlock(blockTag, cb)`
136-
137-
Gets a block by its blockTag.
138-
139-
- `blockTag` - the block's hash or number
140-
- `cb` - the callback. It is given two parameters `err` and the found `block` (an instance of https://github.com/ethereumjs/ethereumjs-block) if any.
141-
142-
---
143-
144-
#### `blockchain.getBlocks(blockId, maxBlocks, skip, reverse, cb)`
145-
146-
Looks up many blocks relative to blockId.
147-
148-
- `blockId` - the block's hash or number
149-
- `maxBlocks` - max number of blocks to return
150-
- `skip` - number of blocks to skip
151-
- `reverse` - fetch blocks in reverse
152-
- `cb` - the callback. It is given two parameters `err` and the found `blocks` if any.
153-
154-
---
155-
156-
#### `blockchain.putHeaders(headers, cb)`
157-
158-
Adds many headers to the blockchain.
159-
160-
- `headers` - the headers to be added to the blockchain
161-
- `cb` - the callback. It is given two parameters `err` and the last of the saved `headers`
162-
163-
---
164-
165-
#### `blockchain.putHeader(header, cb)`
166-
167-
Adds a header to the blockchain.
168-
169-
- `header` - the header to be added to the blockchain
170-
- `cb` - the callback. It is given two parameters `err` and the saved `header`
171-
172-
---
173-
174-
#### `blockchain.getDetails(hash, cb)`
175-
176-
[DEPRECATED] Returns an empty object
177-
178-
---
179-
180-
#### `blockchain.selectNeededHashes(hashes, cb)`
181-
182-
Given an ordered array, returns to the callback an array of hashes that are not in the blockchain yet.
183-
184-
- `hashes` - Ordered array of hashes
185-
- `cb` - the callback. It is given two parameters `err` and hashes found.
186-
187-
---
188-
189-
#### `blockchain.delBlock(blockHash, cb)`
190-
191-
Deletes a block from the blockchain. All child blocks in the chain are deleted and any encountered heads are set to the parent block
192-
193-
- `blockHash` - the hash of the block to be deleted
194-
- `cb` - A callback.
195-
196-
---
197-
198-
#### `blockchain.iterator(name, onBlock, cb)`
199-
200-
Iterates through blocks starting at the specified verified state root head and calls the onBlock function on each block
201-
202-
- `name` - name of the state root head
203-
- `onBlock` - function called on each block with params (block, reorg, cb)
204-
- `cb` - A callback function
205-
206-
# TESTS
207-
208-
Tests can be found in the `test` directory and run with `npm run test`.
209-
210-
These can also be valuable as examples/inspiration on how to run the library and invoke different parts of the API.
16+
[./docs/](./docs/README.md)

docs/README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# ethereumjs-blockchain
2+
3+
## Index
4+
5+
### Classes
6+
7+
- [Blockchain](classes/blockchain.md)
8+
9+
---

0 commit comments

Comments
 (0)