@ethereumjs/blockchain
Version:
A module to store and interact with blocks
46 lines • 1.46 kB
JavaScript
import { bigIntToBytes, concatBytes, utf8ToBytes } from '@ethereumjs/util';
// Geth compatible DB keys
const HEADS_KEY = 'heads';
/**
* Current canonical head for light sync
*/
const HEAD_HEADER_KEY = 'LastHeader';
/**
* Current canonical head for full sync
*/
const HEAD_BLOCK_KEY = 'LastBlock';
/**
* headerPrefix + number + hash -> header
*/
const HEADER_PREFIX = utf8ToBytes('h');
/**
* headerPrefix + number + hash + tdSuffix -> td
*/
const TD_SUFFIX = utf8ToBytes('t');
/**
* headerPrefix + number + numSuffix -> hash
*/
const NUM_SUFFIX = utf8ToBytes('n');
/**
* blockHashPrefix + hash -> number
*/
const BLOCK_HASH_PREFIX = utf8ToBytes('H');
/**
* bodyPrefix + number + hash -> block body
*/
const BODY_PREFIX = utf8ToBytes('b');
// Utility functions
/**
* Convert bigint to big endian Uint8Array
*/
const bytesBE8 = (n) => bigIntToBytes(BigInt.asUintN(64, n));
const tdKey = (n, hash) => concatBytes(HEADER_PREFIX, bytesBE8(n), hash, TD_SUFFIX);
const headerKey = (n, hash) => concatBytes(HEADER_PREFIX, bytesBE8(n), hash);
const bodyKey = (n, hash) => concatBytes(BODY_PREFIX, bytesBE8(n), hash);
const numberToHashKey = (n) => concatBytes(HEADER_PREFIX, bytesBE8(n), NUM_SUFFIX);
const hashToNumberKey = (hash) => concatBytes(BLOCK_HASH_PREFIX, hash);
/**
* @hidden
*/
export { bodyKey, bytesBE8, hashToNumberKey, HEAD_BLOCK_KEY, HEAD_HEADER_KEY, headerKey, HEADS_KEY, numberToHashKey, tdKey, };
//# sourceMappingURL=constants.js.map