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

Commit 4fcdec6

Browse files
committed
Import consts and util fns instead of re-defining
1 parent 0f7e549 commit 4fcdec6

File tree

1 file changed

+10
-17
lines changed

1 file changed

+10
-17
lines changed

src/index.js

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,16 @@ const Buffer = require('safe-buffer').Buffer
1313
const BN = ethUtil.BN
1414
const rlp = ethUtil.rlp
1515
const DBManager = require('./dbManager')
16-
17-
// geth compatible db keys
18-
const headHeaderKey = 'LastHeader' // current canonical head for light sync
19-
const headBlockKey = 'LastBlock' // current canonical head for full sync
20-
const headerPrefix = Buffer.from('h') // headerPrefix + number + hash -> header
21-
const tdSuffix = Buffer.from('t') // headerPrefix + number + hash + tdSuffix -> td
22-
const numSuffix = Buffer.from('n') // headerPrefix + number + numSuffix -> hash
23-
const blockHashPrefix = Buffer.from('H') // blockHashPrefix + hash -> number
24-
const bodyPrefix = Buffer.from('b') // bodyPrefix + number + hash -> block body
25-
26-
// utility functions
27-
const bufBE8 = n => n.toArrayLike(Buffer, 'be', 8) // convert BN to big endian Buffer
28-
const tdKey = (n, hash) => Buffer.concat([headerPrefix, bufBE8(n), hash, tdSuffix])
29-
const headerKey = (n, hash) => Buffer.concat([headerPrefix, bufBE8(n), hash])
30-
const bodyKey = (n, hash) => Buffer.concat([bodyPrefix, bufBE8(n), hash])
31-
const numberToHashKey = n => Buffer.concat([headerPrefix, bufBE8(n), numSuffix])
32-
const hashToNumberKey = hash => Buffer.concat([blockHashPrefix, hash])
16+
const {
17+
tdKey,
18+
headerKey,
19+
bodyKey,
20+
headHeaderKey,
21+
headBlockKey,
22+
hashToNumberKey,
23+
numberToHashKey,
24+
bufBE8
25+
} = require('./util')
3326

3427
module.exports = class Blockchain {
3528
constructor (opts) {

0 commit comments

Comments
 (0)