@lodestar/beacon-node
Version:
A Typescript implementation of the beacon chain
31 lines • 1.7 kB
JavaScript
import { encodeKey } from "@lodestar/db";
import { intToBytes } from "@lodestar/utils";
import { Bucket, getBucketNameByValue } from "../buckets.js";
export const rootIndexBucketId = getBucketNameByValue(Bucket.index_blockArchiveRootIndex);
export const parentRootIndexBucketId = getBucketNameByValue(Bucket.index_blockArchiveParentRootIndex);
export async function getRootIndex(db, blockRoot) {
return db.get(getRootIndexKey(blockRoot), { bucketId: rootIndexBucketId });
}
export async function getParentRootIndex(db, parentRoot) {
return db.get(getParentRootIndexKey(parentRoot), { bucketId: parentRootIndexBucketId });
}
export async function storeRootIndex(db, slot, blockRoot) {
return db.put(getRootIndexKey(blockRoot), intToBytes(slot, 8, "be"), { bucketId: rootIndexBucketId });
}
export async function storeParentRootIndex(db, slot, parentRoot) {
return db.put(getParentRootIndexKey(parentRoot), intToBytes(slot, 8, "be"), { bucketId: parentRootIndexBucketId });
}
export async function deleteRootIndex(db, signedBeaconBlockType, block) {
const beaconBlockType = signedBeaconBlockType.fields.message;
return db.delete(getRootIndexKey(beaconBlockType.hashTreeRoot(block.message)), { bucketId: rootIndexBucketId });
}
export async function deleteParentRootIndex(db, block) {
return db.delete(getParentRootIndexKey(block.message.parentRoot), { bucketId: parentRootIndexBucketId });
}
export function getParentRootIndexKey(parentRoot) {
return encodeKey(Bucket.index_blockArchiveParentRootIndex, parentRoot);
}
export function getRootIndexKey(root) {
return encodeKey(Bucket.index_blockArchiveRootIndex, root);
}
//# sourceMappingURL=blockArchiveIndex.js.map