Skip to content

Commit

Permalink
Clean up status list index calculation code.
Browse files Browse the repository at this point in the history
  • Loading branch information
dlongley committed Feb 18, 2024
1 parent 3d846a7 commit b14fef9
Showing 1 changed file with 5 additions and 28 deletions.
33 changes: 5 additions & 28 deletions lib/CredentialStatusWriter.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import assert from 'assert-plus';
import {Bitstring} from '@digitalbazaar/bitstring';
import {createRequire} from 'node:module';
import {getCredentialStatusInfo} from './helpers.js';
import {ListManager} from './ListManager.js';
const require = createRequire(import.meta.url);
const LRU = require('lru-cache');
Expand Down Expand Up @@ -191,21 +190,13 @@ export class CredentialStatusWriter {
// and the next unassigned SL index from the IAD add the appropriate
// information (based on list type) to a VC's credential status section.
const {
item: {statusLists},
} = this.listShard;
/*const {
blockIndex,
blockAssignmentDoc: {content: {blockSize}},
indexAssignmentDoc: {content: {nextLocalIndex: localIndex}},
blockAssignmentDoc: {content: {blockSize}}
} = listShard;
const statusListIndex = blockIndex * blockSize + localIndex;*/
const statusListIndex = _getStatusListIndex({listShard: this.listShard});
// FIXME: get from `_getStatusListIndex` or list shard above
const localIndex = _getLocalIndex({
listShard: this.listShard, statusListIndex
});

// get N-many statuses to be written from `item` and upsert each one
item: {statusLists}
} = this.listShard;
const statusListIndex = blockIndex * blockSize + localIndex;
// add a status entry for each status list from `item`
const result = {
localIndex,
statusEntries: statusLists.map(statusList =>
Expand Down Expand Up @@ -384,17 +375,3 @@ export class CredentialStatusWriter {
e => !duplicates.includes(e));
}
}

function _getStatusListIndex({listShard}) {
const {
blockIndex,
indexAssignmentDoc: {content: {nextLocalIndex}},
blockAssignmentDoc: {content: {blockSize}}
} = listShard;
return blockIndex * blockSize + nextLocalIndex;
}

function _getLocalIndex({listShard, statusListIndex}) {
const {blockAssignmentDoc: {content: {blockSize}}} = listShard;
return statusListIndex % blockSize;
}

0 comments on commit b14fef9

Please sign in to comment.