Skip to content

Commit

Permalink
Merge 3ed8d04 into 2fbf178
Browse files Browse the repository at this point in the history
  • Loading branch information
nflaig authored Apr 29, 2023
2 parents 2fbf178 + 3ed8d04 commit 2d4bd20
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ export class AttestationByTargetRepository {
private readonly bucketId: string;
private readonly dbReqOpts: DbReqOpts;

private readonly minKey: Uint8Array;
private readonly maxKey: Uint8Array;

constructor(opts: DatabaseApiOptions) {
this.db = opts.controller;
this.type = new ContainerType({
Expand All @@ -36,14 +39,16 @@ export class AttestationByTargetRepository {
}); // casing doesn't matter
this.bucketId = getBucketNameByValue(this.bucket);
this.dbReqOpts = {bucketId: this.bucketId};
this.minKey = encodeKey(this.bucket, Buffer.alloc(0));
this.maxKey = encodeKey(this.bucket + 1, Buffer.alloc(0));
}

async getAll(pubkey: BLSPubkey, limit?: number): Promise<SlashingProtectionAttestation[]> {
const attestations = await this.db.values({
...this.dbReqOpts,
limit,
gte: this.encodeKey(pubkey, 0),
lt: this.encodeKey(pubkey, Number.MAX_SAFE_INTEGER),
bucketId: this.bucketId,
});
return attestations.map((attestation) => this.type.deserialize(attestation));
}
Expand All @@ -64,7 +69,7 @@ export class AttestationByTargetRepository {
}

async listPubkeys(): Promise<BLSPubkey[]> {
const keys = await this.db.keys(this.dbReqOpts);
const keys = await this.db.keys({gte: this.minKey, lt: this.maxKey, bucketId: this.bucketId});
return uniqueVectorArr(keys.map((key) => this.decodeKey(key).pubkey));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ export class BlockBySlotRepository {
private readonly bucketId: string;
private readonly dbReqOpts: DbReqOpts;

private readonly minKey: Uint8Array;
private readonly maxKey: Uint8Array;

constructor(opts: DatabaseApiOptions) {
this.db = opts.controller;
this.type = new ContainerType({
Expand All @@ -35,14 +38,16 @@ export class BlockBySlotRepository {
}); // casing doesn't matter
this.bucketId = getBucketNameByValue(this.bucket);
this.dbReqOpts = {bucketId: this.bucketId};
this.minKey = encodeKey(this.bucket, Buffer.alloc(0));
this.maxKey = encodeKey(this.bucket + 1, Buffer.alloc(0));
}

async getAll(pubkey: BLSPubkey, limit?: number): Promise<SlashingProtectionBlock[]> {
const blocks = await this.db.values({
...this.dbReqOpts,
limit,
gte: this.encodeKey(pubkey, 0),
lt: this.encodeKey(pubkey, Number.MAX_SAFE_INTEGER),
bucketId: this.bucketId,
});
return blocks.map((block) => this.type.deserialize(block));
}
Expand All @@ -68,7 +73,7 @@ export class BlockBySlotRepository {
}

async listPubkeys(): Promise<BLSPubkey[]> {
const keys = await this.db.keys(this.dbReqOpts);
const keys = await this.db.keys({gte: this.minKey, lt: this.maxKey, bucketId: this.bucketId});
return uniqueVectorArr(keys.map((key) => this.decodeKey(key).pubkey));
}

Expand Down

0 comments on commit 2d4bd20

Please sign in to comment.