-
Notifications
You must be signed in to change notification settings - Fork 214
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into markm-delegate-is-passable
- Loading branch information
Showing
46 changed files
with
675 additions
and
173 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,8 @@ | |
"doctor": "yarn synthetic-chain doctor" | ||
}, | ||
"dependencies": { | ||
"@agoric/synthetic-chain": "^0.0.10" | ||
"@agoric/synthetic-chain": "^0.0.10", | ||
"@types/better-sqlite3": "^7.6.9" | ||
}, | ||
"packageManager": "[email protected]", | ||
"license": "Apache-2.0" | ||
|
8 changes: 8 additions & 0 deletions
8
a3p-integration/proposals/a:upgrade-next/priceFeed-follower-auction.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import test from 'ava'; | ||
import { getDetailsMatchingVats } from './vatDetails.js'; | ||
|
||
test('new auction vat', async t => { | ||
const details = await getDetailsMatchingVats('auctioneer'); | ||
// This query matches both the auction and its governor, so 2*2 | ||
t.is(Object.keys(details).length, 4); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
import dbOpenAmbient from 'better-sqlite3'; | ||
|
||
const HOME = process.env.HOME; | ||
|
||
/** @type {<T>(val: T | undefined) => T} */ | ||
export const NonNullish = val => { | ||
if (!val) throw Error('required'); | ||
return val; | ||
}; | ||
|
||
/** | ||
* @file look up vat incarnation from kernel DB | ||
* @see {getIncarnation} | ||
*/ | ||
|
||
const swingstorePath = `${HOME}/.agoric/data/agoric/swingstore.sqlite`; | ||
|
||
/** | ||
* SQL short-hand | ||
* | ||
* @param {import('better-sqlite3').Database} db | ||
*/ | ||
export const dbTool = db => { | ||
const prepare = (strings, ...params) => { | ||
const dml = strings.join('?'); | ||
return { stmt: db.prepare(dml), params }; | ||
}; | ||
const sql = (strings, ...args) => { | ||
const { stmt, params } = prepare(strings, ...args); | ||
return stmt.all(...params); | ||
}; | ||
sql.get = (strings, ...args) => { | ||
const { stmt, params } = prepare(strings, ...args); | ||
return stmt.get(...params); | ||
}; | ||
return sql; | ||
}; | ||
|
||
/** | ||
* @param {import('better-sqlite3').Database} db | ||
*/ | ||
const makeSwingstore = db => { | ||
const sql = dbTool(db); | ||
|
||
/** @param {string} key */ | ||
const kvGet = key => sql.get`select * from kvStore where key = ${key}`.value; | ||
/** @param {string} key */ | ||
const kvGetJSON = key => JSON.parse(kvGet(key)); | ||
|
||
/** @param {string} vatID */ | ||
const lookupVat = vatID => { | ||
return Object.freeze({ | ||
source: () => kvGetJSON(`${vatID}.source`), | ||
options: () => kvGetJSON(`${vatID}.options`), | ||
currentSpan: () => | ||
sql.get`select * from transcriptSpans where isCurrent = 1 and vatID = ${vatID}`, | ||
}); | ||
}; | ||
|
||
return Object.freeze({ | ||
/** @param {string} vatName */ | ||
findVat: vatName => { | ||
/** @type {string[]} */ | ||
const dynamicIDs = kvGetJSON('vat.dynamicIDs'); | ||
const targetVat = dynamicIDs.find(vatID => | ||
lookupVat(vatID).options().name.includes(vatName), | ||
); | ||
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, | ||
}); | ||
}; | ||
|
||
/** @param {string} vatName */ | ||
export const getDetailsMatchingVats = async vatName => { | ||
const kStore = makeSwingstore( | ||
dbOpenAmbient(swingstorePath, { readonly: true }), | ||
); | ||
|
||
const vatIDs = kStore.findVats(vatName); | ||
const infos = []; | ||
for (const vatID of vatIDs) { | ||
const vatInfo = kStore.lookupVat(vatID); | ||
const source = vatInfo.source(); | ||
// @ts-expect-error cast | ||
const { incarnation } = vatInfo.currentSpan(); | ||
infos.push({ vatName, vatID, incarnation, ...source }); | ||
} | ||
|
||
return infos; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.