Skip to content

Commit

Permalink
chore: create "deploy-script-support" package (#2117)
Browse files Browse the repository at this point in the history
* chore: add deploy-script-support package, changes to lib-wallet
  • Loading branch information
katelynsills authored Jan 5, 2021
1 parent ab565cd commit b893a73
Show file tree
Hide file tree
Showing 41 changed files with 1,571 additions and 69 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@
"packages/agoric-cli",
"packages/deployment",
"packages/notifier",
"packages/xs-vat-worker"
"packages/xs-vat-worker",
"packages/deploy-script-support"
],
"devDependencies": {
"@typescript-eslint/parser": "^4.1.0",
Expand Down
3 changes: 2 additions & 1 deletion packages/agoric-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"main": "lib/main.js",
"bin": "bin/agoric",
"files": [
"lib"
"lib",
"exported.js"
],
"scripts": {
"build": "exit 0",
Expand Down
1 change: 1 addition & 0 deletions packages/bundle-source/exported.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import './src/types';
3 changes: 2 additions & 1 deletion packages/bundle-source/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@
},
"keywords": [],
"files": [
"src"
"src",
"exported"
],
"repository": {
"type": "git",
Expand Down
4 changes: 3 additions & 1 deletion packages/bundle-source/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import { encodeBase64 } from '@agoric/base64';

import { SourceMapConsumer } from 'source-map';

import './types';

const DEFAULT_MODULE_FORMAT = 'nestedEvaluate';
const DEFAULT_FILE_PREFIX = '/bundled-source';
const SUPPORTED_FORMATS = ['getExport', 'nestedEvaluate', 'endoZipBase64'];
Expand All @@ -33,7 +35,7 @@ export function tildotPlugin() {
},
};
}

/** @type {BundleSource} */
export default async function bundleSource(
startFilename,
moduleFormat = DEFAULT_MODULE_FORMAT,
Expand Down
6 changes: 6 additions & 0 deletions packages/bundle-source/src/types.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/**
* @callback BundleSource
* @param {string} startFilename - the filepath to start the bundling from
* @param {string=} moduleFormat
* @param {Object=} powers
*/
1 change: 1 addition & 0 deletions packages/cosmic-swingset/exported.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import './lib/ag-solo/vats/types';
10 changes: 2 additions & 8 deletions packages/cosmic-swingset/lib/ag-solo/vats/lib-board.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { assert, details, q } from '@agoric/assert';
import makeStore from '@agoric/store';
import { models as crcmodels } from 'polycrc';

import './types';

const CRC_NUM_DIGITS = 2;
const ID_REGEXP = new RegExp(`^[0-9]{${CRC_NUM_DIGITS + 1},}$`);

Expand All @@ -26,14 +28,6 @@ const calcCrc = num => {
return crcStr;
};

/**
* @typedef {Object} Board
* @property {(id: string) => any} getValue
* @property {(value: any) => string} getId
* @property {(value: any) => boolean} has
* @property {() => string[]} ids
*/

/**
* Create a board to post things on.
*
Expand Down
7 changes: 7 additions & 0 deletions packages/cosmic-swingset/lib/ag-solo/vats/types.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/**
* @typedef {Object} Board
* @property {(id: string) => any} getValue
* @property {(value: any) => string} getId
* @property {(value: any) => boolean} has
* @property {() => string[]} ids
*/
1 change: 1 addition & 0 deletions packages/dapp-svelte-wallet/api/exported.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import './src/types';
162 changes: 105 additions & 57 deletions packages/dapp-svelte-wallet/api/src/lib-wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ export function makeWallet({
*/
let zoeInvitePurse;

const ZOE_INVITE_BRAND_PETNAME = 'zoe invite';

function getSortedValues(map) {
const entries = [...map.entries()];
// Sort for determinism.
Expand Down Expand Up @@ -567,16 +569,6 @@ export function makeWallet({
return `instance ${q(petname)} successfully added to wallet`;
};

const addInstallation = (petname, installationHandle) => {
// We currently just add the petname mapped to the installationHandle
// value, but we could have a list of known installations for
// possible display in the wallet.
petname = installationMapping.suggestPetname(petname, installationHandle);
// We don't wait for the update before returning.
updateAllState();
return `installation ${q(petname)} successfully added to wallet`;
};

const makeEmptyPurse = async (brandPetname, petnameForPurse) => {
const brand = brandMapping.petnameToVal.get(brandPetname);
const { issuer } = brandTable.getByBrand(brand);
Expand Down Expand Up @@ -987,14 +979,6 @@ export function makeWallet({
return ret;
}

/** @returns {[Petname, Issuer][]} */
function getIssuers() {
return brandMapping.petnameToVal.entries().map(([petname, brand]) => {
const { issuer } = brandTable.getByBrand(brand);
return [petname, issuer];
});
}

/** @type {Store<Payment, PaymentRecord>} */
const payments = makeStore('payment');
const {
Expand Down Expand Up @@ -1243,54 +1227,103 @@ export function makeWallet({
// suggestion can be rejected and the suggested petname can be
// changed
return acceptPetname(
addInstallation,
// eslint-disable-next-line no-use-before-define
installationManager.add,
suggestedPetname,
installationHandleBoardId,
dappOrigin,
);
}

async function renameIssuer(petname, issuer) {
assert(
brandTable.hasByIssuer(issuer),
`issuer has not been previously added`,
);
const brandRecord = brandTable.getByIssuer(issuer);
brandMapping.renamePetname(petname, brandRecord.brand);
await updateAllState();
return `issuer ${q(petname)} successfully renamed in wallet`;
function getBrand(petname) {
const brand = brandMapping.petnameToVal.get(petname);
return brand;
}

async function renameInstance(petname, instance) {
instanceMapping.renamePetname(petname, instance);
await updateAllState();
return `instance ${q(petname)} successfully renamed in wallet`;
function getSelfContact() {
return selfContact;
}

async function renameInstallation(petname, installation) {
installationMapping.renamePetname(petname, installation);
await updateAllState();
return `installation ${q(petname)} successfully renamed in wallet`;
const makeManager = petnameMapping => {
const manager = {
rename: async (petname, thing) => {
petnameMapping.renamePetname(petname, thing);
await updateAllState();
},
get: petnameMapping.petnameToVal.get,
getAll: petnameMapping.petnameToVal.entries,
add: async (petname, thing) => {
petnameMapping.suggestPetname(petname, thing);
await updateAllState();
},
};
return harden(manager);
};

/** @type {InstallationManager} */
const installationManager = makeManager(installationMapping);

/** @type {InstanceManager} */
const instanceManager = makeManager(instanceMapping);

/** @type {IssuerManager} */
const issuerManager = {
rename: async (petname, issuer) => {
assert(
brandTable.hasByIssuer(issuer),
`issuer has not been previously added`,
);
const brandRecord = brandTable.getByIssuer(issuer);
brandMapping.renamePetname(petname, brandRecord.brand);
await updateAllState();
},
get: petname => {
const brand = brandMapping.petnameToVal.get(petname);
return brandTable.getByBrand(brand).issuer;
},
getAll: () => {
return brandMapping.petnameToVal.entries().map(([petname, brand]) => {
const { issuer } = brandTable.getByBrand(brand);
return [petname, issuer];
});
},
add: async (petname, issuerP) => {
const { brand, issuer } = await brandTable.initIssuer(issuerP);
if (!issuerToBoardId.has(issuer)) {
const issuerBoardId = await E(board).getId(issuer);
issuerToBoardId.init(issuer, issuerBoardId);
}
brandMapping.suggestPetname(petname, brand);
await updateAllIssuersState();
},
};
harden(issuerManager);

function getInstallationManager() {
return installationManager;
}

function getIssuer(petname) {
const brand = brandMapping.petnameToVal.get(petname);
return brandTable.getByBrand(brand).issuer;
function getInstanceManager() {
return instanceManager;
}

function getSelfContact() {
return selfContact;
function getIssuerManager() {
return issuerManager;
}

function getInstance(petname) {
return instanceMapping.petnameToVal.get(petname);
const offerResultStore = makeWeakStore('invitationHandle');

async function saveOfferResult(invitationHandle, offerResult) {
offerResultStore.init(invitationHandle, offerResult);
}

function getInstallation(petname) {
return installationMapping.petnameToVal.get(petname);
async function getOfferResult(invitationHandle) {
return offerResultStore.get(invitationHandle);
}

const wallet = harden({
saveOfferResult,
getOfferResult,
waitForDappApproval,
getDappsNotifier() {
return dappsNotifier;
Expand All @@ -1304,20 +1337,36 @@ export function makeWallet({
getOffersNotifier() {
return offersNotifier;
},
addIssuer,
/** @deprecated use issuerManager.add instead */
addIssuer: issuerManager.add,
getBrand,
publishIssuer,
addInstance,
addInstallation,
renameIssuer,
renameInstance,
renameInstallation,
/** @deprecated use instanceManager.add instead */
addInstance: instanceManager.add,
/** @deprecated use installationManager.add instead */
addInstallation: installationManager.add,
getInstallationManager,
getInstanceManager,
getIssuerManager,
/** @deprecated use issuerManager.rename instead */
renameIssuer: issuerManager.rename,
/** @deprecated use instanceManager.rename instead */
renameInstance: instanceManager.rename,
/** @deprecated use installationManager.rename instead */
renameInstallation: installationManager.rename,
getSelfContact,
getInstance,
getInstallation,
/** @deprecated use instanceManager.get instead */
getInstance: instanceManager.get,
/** @deprecated use installationManager.get instead */
getInstallation: installationManager.get,
/** @deprecated use installationManager.getAll instead */
getInstallations: installationManager.getAll,
makeEmptyPurse,
deposit,
getIssuer,
getIssuers,
/** @deprecated use issuerManager.get instead */
getIssuer: issuerManager.get,
/** @deprecated use issuerManager.getAll instead */
getIssuers: issuerManager.getAll,
getPurses,
getPurse,
getPurseIssuer,
Expand Down Expand Up @@ -1351,11 +1400,10 @@ export function makeWallet({

const initialize = async () => {
// Make Zoe invite purse
const ZOE_INVITE_BRAND_PETNAME = 'zoe invite';
const ZOE_INVITE_PURSE_PETNAME = 'Default Zoe invite purse';
const inviteIssuerP = E(zoe).getInvitationIssuer();
const addZoeIssuer = issuerP =>
wallet.addIssuer(ZOE_INVITE_BRAND_PETNAME, issuerP);
issuerManager.add(ZOE_INVITE_BRAND_PETNAME, issuerP);
const makeInvitePurse = () =>
wallet.makeEmptyPurse(ZOE_INVITE_BRAND_PETNAME, ZOE_INVITE_PURSE_PETNAME);
const addInviteDepositFacet = () =>
Expand Down
21 changes: 21 additions & 0 deletions packages/dapp-svelte-wallet/api/src/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,24 @@
* @property {any} requestContext
* @property {string} id
*/

/**
* @template T
* @typedef {Object} PetnameManager
* @property {(petname: Petname, object: T) => Promise<void>} rename
* @property {(petname: Petname) => T} get
* @property { () => Array<[Petname, T]>} getAll
* @property {(petname: Petname, object: T) => Promise<void>} add
*/

/**
* @typedef {PetnameManager<Installation>} InstallationManager
*/

/**
* @typedef {PetnameManager<Instance>} InstanceManager
*/

/**
* @typedef {PetnameManager<Issuer>} IssuerManager
*/
Loading

0 comments on commit b893a73

Please sign in to comment.