diff --git a/services/gatekeeper/server/src/gatekeeper-api.js b/services/gatekeeper/server/src/gatekeeper-api.js index 82998a6f..3a0d54e3 100644 --- a/services/gatekeeper/server/src/gatekeeper-api.js +++ b/services/gatekeeper/server/src/gatekeeper-api.js @@ -295,29 +295,30 @@ async function reportStatus() { console.log(`DID Database (${config.db}):`); console.log(` Total: ${status.dids.total}`); - console.log(` By type:`); - console.log(` Agents: ${status.dids.byType.agents}`); - console.log(` Assets: ${status.dids.byType.assets}`); - console.log(` Confirmed: ${status.dids.byType.confirmed}`); - console.log(` Unconfirmed: ${status.dids.byType.unconfirmed}`); - console.log(` Ephemeral: ${status.dids.byType.ephemeral}`); - console.log(` Invalid: ${status.dids.byType.invalid}`); - - console.log(` By registry:`); - const registries = Object.keys(status.dids.byRegistry).sort(); - for (let registry of registries) { - console.log(` ${registry}: ${status.dids.byRegistry[registry]}`); - } + if (status.dids.total > 0) { + console.log(` By type:`); + console.log(` Agents: ${status.dids.byType.agents}`); + console.log(` Assets: ${status.dids.byType.assets}`); + console.log(` Confirmed: ${status.dids.byType.confirmed}`); + console.log(` Unconfirmed: ${status.dids.byType.unconfirmed}`); + console.log(` Ephemeral: ${status.dids.byType.ephemeral}`); + console.log(` Invalid: ${status.dids.byType.invalid}`); + + console.log(` By registry:`); + const registries = Object.keys(status.dids.byRegistry).sort(); + for (let registry of registries) { + console.log(` ${registry}: ${status.dids.byRegistry[registry]}`); + } - console.log(` By version:`); - let count = 0; - for (let version of [1, 2, 3, 4, 5]) { - const num = status.dids.byVersion[version]; - console.log(` ${version}: ${num}`); - count += num; + console.log(` By version:`); + let count = 0; + for (let version of [1, 2, 3, 4, 5]) { + const num = status.dids.byVersion[version] || 0; + console.log(` ${version}: ${num}`); + count += num; + } + console.log(` 6+: ${status.dids.total - count}`); } - console.log(` 6+: ${status.dids.total - count}`); - console.log(`Memory Usage Report:`); console.log(` RSS: ${formatBytes(status.memoryUsage.rss)} (Resident Set Size - total memory allocated for the process)`); diff --git a/services/keymaster/server/src/keymaster-api.js b/services/keymaster/server/src/keymaster-api.js index 0d1d11be..539a61a4 100644 --- a/services/keymaster/server/src/keymaster-api.js +++ b/services/keymaster/server/src/keymaster-api.js @@ -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 () => { @@ -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; });