diff --git a/packages/synthetic-chain/src/lib/vat-status.js b/packages/synthetic-chain/src/lib/vat-status.js index 345a856b..dc15e950 100644 --- a/packages/synthetic-chain/src/lib/vat-status.js +++ b/packages/synthetic-chain/src/lib/vat-status.js @@ -62,6 +62,14 @@ const makeSwingstore = db => { if (!targetVat) throw Error(`vat not found: ${vatName}`); return targetVat; }, + /** @param {string} vatName */ + findVats: vatName => { + /** @type {string[]} */ + const dynamicIDs = kvGetJSON('vat.dynamicIDs'); + return dynamicIDs.filter(vatID => + lookupVat(vatID).options().name.includes(vatName), + ); + }, lookupVat, }); }; @@ -92,3 +100,24 @@ export const getIncarnation = async vatName => { return details.incarnation; }; + +/** @param {string} vatName */ +export const getDetailsMatchingVats = async vatName => { + const fullPath = swingstorePath.replace(/^~/, NonNullish(HOME)); + + const db = dbOpenAmbient(fullPath, { readonly: true }); + const kStore = makeSwingstore(db); + + const vatIDs = kStore.findVats(vatName); + const infos = []; + for (const vatID of vatIDs) { + const vatInfo = kStore.lookupVat(vatID); + const name = vatInfo.options().name; + const source = vatInfo.source(); + // @ts-expect-error cast + const { incarnation } = vatInfo.currentSpan(); + infos.push({ vatName: name, vatID, incarnation, ...source }); + } + + return infos; +}; diff --git a/packages/synthetic-chain/test/snapshots/test-exports.ts.md b/packages/synthetic-chain/test/snapshots/test-exports.ts.md index 05e608ff..44e233da 100644 --- a/packages/synthetic-chain/test/snapshots/test-exports.ts.md +++ b/packages/synthetic-chain/test/snapshots/test-exports.ts.md @@ -60,6 +60,7 @@ Generated by [AVA](https://avajs.dev). generateOracleMap: Function generateOracleMap {}, getAuctionCollateral: AsyncFunction {}, getContractInfo: AsyncFunction {}, + getDetailsMatchingVats: AsyncFunction {}, getISTBalance: AsyncFunction {}, getIncarnation: AsyncFunction {}, getInstanceBoardId: AsyncFunction {}, diff --git a/packages/synthetic-chain/test/snapshots/test-exports.ts.snap b/packages/synthetic-chain/test/snapshots/test-exports.ts.snap index dc736f99..17997e70 100644 Binary files a/packages/synthetic-chain/test/snapshots/test-exports.ts.snap and b/packages/synthetic-chain/test/snapshots/test-exports.ts.snap differ