From 0a2d05496dd2de6e582f0df5729ffacd5ce80406 Mon Sep 17 00:00:00 2001 From: Michael FIG Date: Mon, 11 Jan 2021 13:23:37 -0600 Subject: [PATCH] feat: allow $NO_FAKE_CURRENCIES=1 to eliminate default purses --- .../cosmic-swingset/lib/ag-solo/fake-chain.js | 1 + .../lib/ag-solo/vats/bootstrap.js | 24 ++++++++++++++----- packages/cosmic-swingset/lib/chain-main.js | 5 +++- 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/packages/cosmic-swingset/lib/ag-solo/fake-chain.js b/packages/cosmic-swingset/lib/ag-solo/fake-chain.js index e842aca94f3..710b567f225 100644 --- a/packages/cosmic-swingset/lib/ag-solo/fake-chain.js +++ b/packages/cosmic-swingset/lib/ag-solo/fake-chain.js @@ -52,6 +52,7 @@ export async function connectToFakeChain(basedir, GCI, delay, inbound) { ROLE: 'sim-chain', giveMeAllTheAgoricPowers: true, hardcodedClientAddresses: [bootAddress], + noFakeCurrencies: process.env.NO_FAKE_CURRENCIES, }; const stateDBdir = path.join(basedir, `fake-chain-${GCI}-state`); function doOutboundBridge(dstID, _obj) { diff --git a/packages/cosmic-swingset/lib/ag-solo/vats/bootstrap.js b/packages/cosmic-swingset/lib/ag-solo/vats/bootstrap.js index 742c20fcc7a..e255a56efc4 100644 --- a/packages/cosmic-swingset/lib/ag-solo/vats/bootstrap.js +++ b/packages/cosmic-swingset/lib/ag-solo/vats/bootstrap.js @@ -38,7 +38,12 @@ export function buildRootObject(vatPowers, vatParameters) { } // Make services that are provided on the real or virtual chain side - async function makeChainBundler(vats, timerDevice, vatAdminSvc) { + async function makeChainBundler( + vats, + timerDevice, + vatAdminSvc, + noFakeCurrencies, + ) { // Create singleton instances. const [ sharingService, @@ -67,7 +72,7 @@ export function buildRootObject(vatPowers, vatParameters) { * @property {Array<[number, number]>} [fakeTradesGivenCentral] */ /** @type {Map} */ - const issuerNameToRecord = new Map( + const fakeIssuerNameToRecord = new Map( harden([ [ CENTRAL_ISSUER_NAME, @@ -133,13 +138,13 @@ export function buildRootObject(vatPowers, vatParameters) { ], ]), ); + const issuerNameToRecord = noFakeCurrencies + ? new Map() + : fakeIssuerNameToRecord; const issuerNames = [...issuerNameToRecord.keys()]; const centralIssuerIndex = issuerNames.findIndex( issuerName => issuerName === CENTRAL_ISSUER_NAME, ); - if (centralIssuerIndex < 0) { - throw Error(`Cannot find issuer ${CENTRAL_ISSUER_NAME}`); - } const issuers = await Promise.all( issuerNames.map(issuerName => E(vats.mints).makeMintAndIssuer( @@ -396,6 +401,7 @@ export function buildRootObject(vatPowers, vatParameters) { const { ROLE, giveMeAllTheAgoricPowers, + noFakeCurrencies, hardcodedClientAddresses, } = vatParameters.argv; @@ -424,7 +430,12 @@ export function buildRootObject(vatPowers, vatParameters) { // provisioning vat can ask the demo server for bundles, and can // register client pubkeys with comms await E(vats.provisioning).register( - await makeChainBundler(vats, devices.timer, vatAdminSvc), + await makeChainBundler( + vats, + devices.timer, + vatAdminSvc, + noFakeCurrencies, + ), vats.comms, vats.vattp, ); @@ -469,6 +480,7 @@ export function buildRootObject(vatPowers, vatParameters) { vats, devices.timer, vatAdminSvc, + noFakeCurrencies, ); // Allow manual provisioning requests via `agoric cosmos`. diff --git a/packages/cosmic-swingset/lib/chain-main.js b/packages/cosmic-swingset/lib/chain-main.js index 98163d3b856..ff84016e704 100644 --- a/packages/cosmic-swingset/lib/chain-main.js +++ b/packages/cosmic-swingset/lib/chain-main.js @@ -216,7 +216,10 @@ export default async function main(progname, args, { path, env, agcc }) { } const vatsdir = path.resolve(__dirname, '../lib/ag-solo/vats'); - const argv = { ROLE: 'chain' }; + const argv = { + ROLE: 'chain', + noFakeCurrencies: process.env.NO_FAKE_CURRENCIES, + }; const s = await launch( stateDBDir, mailboxStorage,