Skip to content

Commit

Permalink
add the ability to find details for multiple vats (#174)
Browse files Browse the repository at this point in the history
* test: add the ability to find details for multiple vats
  • Loading branch information
Chris-Hibbert committed Sep 9, 2024
1 parent 45c6389 commit d37362f
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
29 changes: 29 additions & 0 deletions packages/synthetic-chain/src/lib/vat-status.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,14 @@ const makeSwingstore = db => {
if (!targetVat) throw Error(`vat not found: ${vatName}`);
return targetVat;
},
/** @param {string} string a substring to search for within the vat name. */
findVats: string => {
/** @type {string[]} */
const dynamicIDs = kvGetJSON('vat.dynamicIDs');
return dynamicIDs.filter(vatID =>
lookupVat(vatID).options().name.includes(string),
);
},
lookupVat,
});
};
Expand Down Expand Up @@ -94,3 +102,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;
};
1 change: 1 addition & 0 deletions packages/synthetic-chain/test/snapshots/test-exports.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 {},
Expand Down
Binary file modified packages/synthetic-chain/test/snapshots/test-exports.ts.snap
Binary file not shown.

0 comments on commit d37362f

Please sign in to comment.