@lodestar/beacon-node
Version:
A Typescript implementation of the beacon chain
30 lines • 950 B
JavaScript
import { ssz } from "@lodestar/types";
/**
* Implementation of CPStateDatastore using db.
*/
export class DbCPStateDatastore {
constructor(db) {
this.db = db;
}
async write(cpKey, stateBytes) {
const serializedCheckpoint = checkpointToDatastoreKey(cpKey);
await this.db.checkpointState.putBinary(serializedCheckpoint, stateBytes);
return serializedCheckpoint;
}
async remove(serializedCheckpoint) {
await this.db.checkpointState.delete(serializedCheckpoint);
}
async read(serializedCheckpoint) {
return this.db.checkpointState.getBinary(serializedCheckpoint);
}
async readKeys() {
return this.db.checkpointState.keys();
}
}
export function datastoreKeyToCheckpoint(key) {
return ssz.phase0.Checkpoint.deserialize(key);
}
export function checkpointToDatastoreKey(cp) {
return ssz.phase0.Checkpoint.serialize(cp);
}
//# sourceMappingURL=db.js.map