import { Repository } from "@lodestar/db";
import { ssz } from "@lodestar/types";
import { getSignedBlockTypeFromBytes } from "../../util/multifork.js";
import { Bucket, getBucketNameByValue } from "../buckets.js";
/**
 * Blocks by root
 *
 * Used to store unfinalized blocks
 */
export class BlockRepository extends Repository {
    constructor(config, db) {
        const bucket = Bucket.allForks_block;
        const type = ssz.phase0.SignedBeaconBlock; // Pick some type but won't be used
        super(config, db, bucket, type, getBucketNameByValue(bucket));
    }
    /**
     * Id is hashTreeRoot of unsigned BeaconBlock
     */
    getId(value) {
        return this.config.getForkTypes(value.message.slot).BeaconBlock.hashTreeRoot(value.message);
    }
    encodeValue(value) {
        return this.config.getForkTypes(value.message.slot).SignedBeaconBlock.serialize(value);
    }
    decodeValue(data) {
        return getSignedBlockTypeFromBytes(this.config, data).deserialize(data);
    }
}
//# sourceMappingURL=block.js.map