forked from ipfs/js-ipfs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
eth.js
53 lines (43 loc) · 1.29 KB
/
eth.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
'use strict'
const createNode = require('./create-node.js')
const asyncEach = require('async/each')
const path = require('path')
const multihashing = require('multihashing-async')
const Block = require('ipfs-block')
const CID = require('cids')
const fs = require('fs')
createNode((err, ipfs) => {
if (err) {
throw err
}
console.log('\nStart of the example:')
const ethBlocks = [
path.join(__dirname, '/eth-blocks/block_302516'),
path.join(__dirname, '/eth-blocks/block_302517')
]
asyncEach(ethBlocks, (ethBlockPath, cb) => {
const data = fs.readFileSync(ethBlockPath)
multihashing(data, 'keccak-256', (err, multihash) => {
if (err) {
cb(err)
}
const cid = new CID(1, 'eth-block', multihash)
// console.log(cid.toBaseEncodedString())
ipfs.block.put(new Block(data, cid), cb)
})
}, (err) => {
if (err) {
throw err
}
const block302516 = 'z43AaGEywSDX5PUJcrn5GfZmb6FjisJyR7uahhWPk456f7k7LDA'
const block302517 = 'z43AaGF42R2DXsU65bNnHRCypLPr9sg6D7CUws5raiqATVaB1jj'
function errOrLog (err, result) {
if (err) {
throw err
}
console.log(result.value.toString('hex'))
}
ipfs.dag.get(block302516 + '/number', errOrLog)
ipfs.dag.get(block302517 + '/parent/number', errOrLog)
})
})