-
Notifications
You must be signed in to change notification settings - Fork 222
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(orchestrate): membrane friendly wrapper for agoricNames
* Perform remote calls to agoricNames in membrane-friendly way. This is an * interim approach until #9541, * #9322, or * #9519
- Loading branch information
1 parent
944adea
commit 6631048
Showing
4 changed files
with
100 additions
and
15 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import { VowShape } from '@agoric/vow'; | ||
import { E, Far } from '@endo/far'; | ||
import { M } from '@endo/patterns'; | ||
import { BrandShape } from '@agoric/ertp'; | ||
|
||
const { Fail } = assert; | ||
|
||
/** | ||
* @import {NameHub} from '@agoric/vats'; | ||
* @import {AssetInfo} from '@agoric/vats/src/vat-bank'; | ||
* @import {Remote} from '@agoric/internal'; | ||
* @import {Vow, VowTools} from '@agoric/vow'; | ||
* @import {Zone} from '@agoric/zone'; | ||
*/ | ||
|
||
/** | ||
* Perform remote calls to agoricNames in membrane-friendly way. This is an | ||
* interim approach until https://github.com/Agoric/agoric-sdk/issues/9541, | ||
* https://github.com/Agoric/agoric-sdk/pull/9322, or | ||
* https://github.com/Agoric/agoric-sdk/pull/9519 | ||
* | ||
* XXX consider exposing `has`, `entries`, `keys`, `values` from `NameHub` | ||
* | ||
* @param {Zone} zone | ||
* @param {{ agoricNames: Remote<NameHub>; vowTools: VowTools }} powers | ||
*/ | ||
export const makeAgNamesTools = ( | ||
zone, | ||
{ agoricNames, vowTools: { watch } }, | ||
) => { | ||
const agNamesTools = zone.exo( | ||
'AgoricNamesTools', | ||
M.interface('AgoricNamesToolsI', { | ||
lookup: M.call().rest(M.arrayOf(M.string())).returns(VowShape), | ||
findBrandInVBank: M.call(BrandShape).returns(VowShape), | ||
}), | ||
{ | ||
/** @param {...string} args */ | ||
lookup(...args) { | ||
return watch(E(agoricNames).lookup(...args)); | ||
}, | ||
/** | ||
* @param {Brand<'nat'>} brand | ||
* @returns {Vow<AssetInfo>} | ||
*/ | ||
findBrandInVBank(brand) { | ||
// XXX consider caching and refetching 1x if brand is not found, | ||
// if this is planned to be local / long-lived | ||
const vbankAssetNameHubP = E(agoricNames).lookup('vbankAsset'); | ||
return watch( | ||
E(vbankAssetNameHubP).values(), | ||
Far('BrandsWatcher', { | ||
/** @param {AssetInfo[]} assets */ | ||
onFulfilled(assets) { | ||
const it = assets.find(a => a.brand === brand); | ||
it || Fail`brand ${brand} not in agoricNames.vbankAsset`; | ||
return it; | ||
}, | ||
}), | ||
); | ||
}, | ||
}, | ||
); | ||
return agNamesTools; | ||
}; | ||
/** @typedef {ReturnType<typeof makeAgNamesTools>} AgNamesTools */ |
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
25 changes: 25 additions & 0 deletions
25
packages/orchestration/test/exos/agoric-names-tools.test.ts
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,25 @@ | ||
import { test } from '@agoric/zoe/tools/prepare-test-env-ava.js'; | ||
|
||
import { V } from '@agoric/vow/vat.js'; | ||
import { makeHeapZone } from '@agoric/zone'; | ||
import { makeAgNamesTools } from '../../src/exos/agoric-names-tools.js'; | ||
import { commonSetup } from '../supports.js'; | ||
|
||
test('agoric names tools', async t => { | ||
const { | ||
bootstrap: { agoricNames, vowTools }, | ||
brands: { ist }, | ||
} = await commonSetup(t); | ||
|
||
const zone = makeHeapZone(); | ||
const agNamesTools = makeAgNamesTools(zone, { | ||
agoricNames, | ||
vowTools, | ||
}); | ||
|
||
const chainEntry = await V.when(agNamesTools.lookup('chain', 'celestia')); | ||
t.like(chainEntry, { chainId: 'celestia' }); | ||
|
||
const istDenom = await V.when(agNamesTools.findBrandInVBank(ist.brand)); | ||
t.like(istDenom, { denom: 'uist' }); | ||
}); |