Skip to content

Commit

Permalink
fix(types): board values
Browse files Browse the repository at this point in the history
  • Loading branch information
turadg committed May 8, 2024
1 parent 96c9ff5 commit dfb2453
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 13 deletions.
6 changes: 3 additions & 3 deletions packages/smart-wallet/src/marshal-contexts.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { DEFAULT_PREFIX } from '@agoric/vats/src/lib-board.js';
const { Fail, quote: q } = assert;

/**
* @import {PassableCap} from '@endo/marshal';
* @import {PassableCap, RemotableObject} from '@endo/marshal';
* @import {Key} from '@endo/patterns';
* @import {BoardId} from '@agoric/vats/src/lib-board.js';
*/
Expand Down Expand Up @@ -212,14 +212,14 @@ export const makeExportContext = () => {
purseEntries: walletObjects.purse.bySlot.entries,
/**
* @param {BoardId} id
* @param {PassableCap} val
* @param {RemotableObject} val
*/
initBoardId: (id, val) => {
initSlotVal(boardObjects, id, val);
},
/**
* @param {BoardId} id
* @param {PassableCap} val
* @param {RemotableObject} val
*/
ensureBoardId: (id, val) => {
if (boardObjects.byVal.has(val)) {
Expand Down
1 change: 0 additions & 1 deletion packages/smart-wallet/test/test-marshal-contexts.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ const makeOnChainWallet = board => {
getCurrentAmount: () => harden({ brand, value: 100 }),
});
// only for private brands
// context.initBrandId(boardId, brand);
context.initBoardId(boardId, brand);
// @ts-expect-error mock purse
context.initPurseId(name, purse); // TODO: strong id rather than name?
Expand Down
18 changes: 10 additions & 8 deletions packages/vats/src/lib-board.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ import {
prepareRecorder,
} from '@agoric/zoe/src/contractSupport/recorder.js';
import { E, Far } from '@endo/far';
import { makeMarshal } from '@endo/marshal';
import { isRemotable, makeMarshal } from '@endo/marshal';

import { crc6 } from './crc.js';

/**
* @import {PassableCap} from '@endo/marshal';
* @import {RemotableObject} from '@endo/pass-style';
* @import {Key} from '@endo/patterns');
*/

Expand Down Expand Up @@ -102,13 +102,13 @@ const initDurableBoardState = (
const immutable = { prefix, crcDigits };

const lastSequence = BigInt(initSequence);
/** @type {MapStore<BoardId, PassableCap>} */
/** @type {MapStore<BoardId, RemotableObject>} */
const idToVal = makeScalarBigMapStore('idToVal', {
durable: true,
keyShape: IdShape,
valueShape: ValShape,
});
/** @type {MapStore<PassableCap, BoardId>} */
/** @type {MapStore<RemotableObject, BoardId>} */
const valToId = makeScalarBigMapStore('valToId', {
durable: true,
keyShape: ValShape,
Expand All @@ -130,11 +130,14 @@ const initDurableBoardState = (
// transient marshallers that get GCed when the function completes.

/**
* @param {PassableCap} value
* @param {RemotableObject} value
* @param {BoardState} state
*/
const getId = (value, state) => {
const { idToVal, valToId, prefix, crcDigits } = state;
if (!isRemotable(value)) {
Fail`Board cannot create id for non-remotable`;
}

if (valToId.has(value)) {
return valToId.get(value);
Expand Down Expand Up @@ -267,8 +270,7 @@ export const prepareBoardKit = baggage => {
* `value` for its entire lifetime. For a well-known board, this is
* essentially forever.
*
* @param {PassableCap} value
* @throws if `value` is not a Key in the @agoric/store sense
* @param {RemotableObject} value
*/
getId(value) {
return getId(value, this.state);
Expand Down Expand Up @@ -305,7 +307,7 @@ export const prepareBoardKit = baggage => {
}
return E(firstValue).lookup(...rest);
},
/** @param {PassableCap} val */
/** @param {RemotableObject} val */
has(val) {
const { state } = this;
return state.valToId.has(val);
Expand Down
4 changes: 3 additions & 1 deletion packages/wallet/api/src/findOrMakeInvitation.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,9 @@ const makeInvitation = async (
board,
zoe,
) => {
const instance = E(board).getValue(instanceHandleBoardId);
const instance = /** @type {Promise<Instance>} */ (
E(board).getValue(instanceHandleBoardId)
);
const publicFacet = E(zoe).getPublicFacet(instance);
const { method, args = [] } = invitationMaker;

Expand Down

0 comments on commit dfb2453

Please sign in to comment.