Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add the ability to find details for multiple vats #174

Merged
merged 3 commits into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -62,6 +62,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 @@ -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;
};
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.
Loading