Skip to content

Commit

Permalink
keymaster waits for gatekeeper to sync
Browse files Browse the repository at this point in the history
  • Loading branch information
macterra committed Dec 20, 2024
1 parent d987fbc commit 851254f
Showing 1 changed file with 27 additions and 13 deletions.
40 changes: 27 additions & 13 deletions services/keymaster/server/src/keymaster-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -681,6 +681,31 @@ process.on('unhandledRejection', (reason, promise) => {
//console.error('Unhandled rejection caught');
});

async function waitForCurrentId() {
let isReady = false;
const currentId = await keymaster.getCurrentId();

if (!currentId) {
return;
}

while (!isReady) {
try {
console.log(`Resolving current ID: ${currentId}`);
const doc = await keymaster.resolveDID(currentId);
console.log(JSON.stringify(doc, null, 4));
isReady = true;
}
catch {
console.log(`Waiting for gatekeeper to sync...`);
}

if (!isReady) {
await new Promise(resolve => setTimeout(resolve, 10000));
}
}
}

const port = config.keymasterPort;

app.listen(port, async () => {
Expand All @@ -707,17 +732,6 @@ app.listen(port, async () => {
await keymaster.start({ gatekeeper, wallet, cipher });
console.log(`keymaster server running on port ${port}`);

try {
const currentId = await keymaster.getCurrentId();

if (currentId) {
console.log(`current ID: ${currentId}`);
const doc = await keymaster.resolveId();
console.log(JSON.stringify(doc, null, 4));
}
serverReady = true;
}
catch (error) {
console.log(error);
}
await waitForCurrentId();
serverReady = true;
});

0 comments on commit 851254f

Please sign in to comment.