|
| 1 | +// This is generated by writeCoreEval; please edit! |
| 2 | +/* eslint-disable */ |
| 3 | + |
| 4 | +const manifestBundleRef = {bundleID:"b1-376c98ef85078bacb39dcac6128613f802d6dd44174424a97d4fa2dda7f1529ffdbaf93dd2c11997d478deae9cea402ec35022e20c8a867c9e10f992e53cff0a"}; |
| 5 | +const getManifestCall = harden([ |
| 6 | + "getManifestForPortfolioControl", |
| 7 | + { |
| 8 | + installKeys: { |
| 9 | + postalService: { |
| 10 | + bundleID: "b1-9486f1a9b190fd5aebaeb371674567e03813d7e63f16f1c94e8ea4722eeb8d696dac171b7ed144edc2520eb49ede449205f5866835249f75ca940547665e9073", |
| 11 | + }, |
| 12 | + }, |
| 13 | + options: { |
| 14 | + ymaxControlAddress: "agoric15u29seyj3c9rdwg7gwkc97uttrk6j9fl4jkuyh", |
| 15 | + }, |
| 16 | + }, |
| 17 | +]); |
| 18 | +const customManifest = { |
| 19 | + delegatePortfolioContract: { |
| 20 | + consume: { |
| 21 | + agoricNames: true, |
| 22 | + agoricNamesAdmin: true, |
| 23 | + board: true, |
| 24 | + chainStorage: true, |
| 25 | + chainTimerService: true, |
| 26 | + cosmosInterchainService: true, |
| 27 | + getDepositFacet: true, |
| 28 | + localchain: true, |
| 29 | + startUpgradable: true, |
| 30 | + ymax0Kit: true, |
| 31 | + zoe: true, |
| 32 | + }, |
| 33 | + instance: { |
| 34 | + consume: { |
| 35 | + postalService: true, |
| 36 | + }, |
| 37 | + }, |
| 38 | + }, |
| 39 | + deployPostalService: { |
| 40 | + consume: { |
| 41 | + namesByAddress: true, |
| 42 | + startUpgradable: true, |
| 43 | + }, |
| 44 | + installation: { |
| 45 | + consume: { |
| 46 | + postalService: true, |
| 47 | + }, |
| 48 | + }, |
| 49 | + instance: { |
| 50 | + produce: { |
| 51 | + postalService: true, |
| 52 | + }, |
| 53 | + }, |
| 54 | + }, |
| 55 | +}; |
| 56 | + |
| 57 | +// Make a behavior function and "export" it by way of script completion value. |
| 58 | +// It is constructed by an anonymous invocation to ensure the absence of a global binding |
| 59 | +// for makeCoreProposalBehavior, which may not be necessary but preserves behavior pre-dating |
| 60 | +// https://github.com/Agoric/agoric-sdk/pull/8712 . |
| 61 | +const behavior = (({ |
| 62 | + manifestBundleRef, |
| 63 | + getManifestCall: [manifestGetterName, ...manifestGetterArgs], |
| 64 | + customManifest, |
| 65 | + E, |
| 66 | + log = console.info, |
| 67 | + customRestoreRef, |
| 68 | +}) => { |
| 69 | + const { entries, fromEntries } = Object; |
| 70 | + |
| 71 | + /** |
| 72 | + * Given an object whose properties may be promise-valued, return a promise |
| 73 | + * for an analogous object in which each such value has been replaced with its |
| 74 | + * fulfillment. |
| 75 | + * This is a non-recursive form of endo `deeplyFulfilled`. |
| 76 | + * |
| 77 | + * @template T |
| 78 | + * @param {{[K in keyof T]: (T[K] | Promise<T[K]>)}} obj |
| 79 | + * @returns {Promise<T>} |
| 80 | + */ |
| 81 | + const shallowlyFulfilled = async obj => { |
| 82 | + if (!obj) { |
| 83 | + return obj; |
| 84 | + } |
| 85 | + const awaitedEntries = await Promise.all( |
| 86 | + entries(obj).map(async ([key, valueP]) => { |
| 87 | + const value = await valueP; |
| 88 | + return [key, value]; |
| 89 | + }), |
| 90 | + ); |
| 91 | + return fromEntries(awaitedEntries); |
| 92 | + }; |
| 93 | + |
| 94 | + const makeRestoreRef = (vatAdminSvc, zoe) => { |
| 95 | + /** @type {(ref: import\('./externalTypes.js').ManifestBundleRef) => Promise<Installation<unknown>>} */ |
| 96 | + const defaultRestoreRef = async bundleRef => { |
| 97 | + // extract-proposal.js creates these records, and bundleName is |
| 98 | + // the optional name under which the bundle was installed into |
| 99 | + // config.bundles |
| 100 | + const bundleIdP = |
| 101 | + 'bundleName' in bundleRef |
| 102 | + ? E(vatAdminSvc).getBundleIDByName(bundleRef.bundleName) |
| 103 | + : bundleRef.bundleID; |
| 104 | + const bundleID = await bundleIdP; |
| 105 | + const label = bundleID.slice(0, 8); |
| 106 | + return E(zoe).installBundleID(bundleID, label); |
| 107 | + }; |
| 108 | + return defaultRestoreRef; |
| 109 | + }; |
| 110 | + |
| 111 | + /** @param {ChainBootstrapSpace & BootstrapPowers & { evaluateBundleCap: any }} powers */ |
| 112 | + const coreProposalBehavior = async powers => { |
| 113 | + // NOTE: `powers` is expected to match or be a superset of the above `permits` export, |
| 114 | + // which should therefore be kept in sync with this deconstruction code. |
| 115 | + // HOWEVER, do note that this function is invoked with at least the *union* of powers |
| 116 | + // required by individual moduleBehaviors declared by the manifest getter, which is |
| 117 | + // necessary so it can use `runModuleBehaviors` to provide the appropriate subset to |
| 118 | + // each one (see ./writeCoreEvalParts.js). |
| 119 | + // Handle `powers` with the requisite care. |
| 120 | + const { |
| 121 | + consume: { vatAdminSvc, zoe, agoricNamesAdmin }, |
| 122 | + evaluateBundleCap, |
| 123 | + installation: { produce: produceInstallations }, |
| 124 | + modules: { |
| 125 | + utils: { runModuleBehaviors }, |
| 126 | + }, |
| 127 | + } = powers; |
| 128 | + |
| 129 | + // Get the on-chain installation containing the manifest and behaviors. |
| 130 | + log('evaluateBundleCap', { |
| 131 | + manifestBundleRef, |
| 132 | + manifestGetterName, |
| 133 | + vatAdminSvc, |
| 134 | + }); |
| 135 | + let bcapP; |
| 136 | + if ('bundleName' in manifestBundleRef) { |
| 137 | + bcapP = E(vatAdminSvc).getNamedBundleCap(manifestBundleRef.bundleName); |
| 138 | + } else if ('bundleID' in manifestBundleRef) { |
| 139 | + bcapP = E(vatAdminSvc).getBundleCap(manifestBundleRef.bundleID); |
| 140 | + } else { |
| 141 | + const keys = Reflect.ownKeys(manifestBundleRef).map(key => |
| 142 | + typeof key === 'string' ? JSON.stringify(key) : String(key), |
| 143 | + ); |
| 144 | + const keysStr = `[${keys.join(', ')}]`; |
| 145 | + throw Error( |
| 146 | + `bundleRef must have own bundleName or bundleID, missing in ${keysStr}`, |
| 147 | + ); |
| 148 | + } |
| 149 | + const bundleCap = await bcapP; |
| 150 | + |
| 151 | + const proposalNS = await evaluateBundleCap(bundleCap); |
| 152 | + |
| 153 | + // Get the manifest and its metadata. |
| 154 | + log('execute', { |
| 155 | + manifestGetterName, |
| 156 | + bundleExports: Object.keys(proposalNS), |
| 157 | + }); |
| 158 | + const restoreRef = customRestoreRef || makeRestoreRef(vatAdminSvc, zoe); |
| 159 | + const { |
| 160 | + manifest, |
| 161 | + options: rawOptions, |
| 162 | + installations: rawInstallations, |
| 163 | + } = await proposalNS[manifestGetterName]( |
| 164 | + harden({ restoreRef }), |
| 165 | + ...manifestGetterArgs, |
| 166 | + ); |
| 167 | + |
| 168 | + // Await promises in the returned options and installations records. |
| 169 | + const [options, installations] = await Promise.all( |
| 170 | + [rawOptions, rawInstallations].map(shallowlyFulfilled), |
| 171 | + ); |
| 172 | + |
| 173 | + // Publish the installations for our dependencies. |
| 174 | + const installationEntries = entries(installations || {}); |
| 175 | + if (installationEntries.length > 0) { |
| 176 | + const installAdmin = E(agoricNamesAdmin).lookupAdmin('installation'); |
| 177 | + await Promise.all( |
| 178 | + installationEntries.map(([key, value]) => { |
| 179 | + produceInstallations[key].reset(); |
| 180 | + produceInstallations[key].resolve(value); |
| 181 | + return E(installAdmin).update(key, value); |
| 182 | + }), |
| 183 | + ); |
| 184 | + } |
| 185 | + |
| 186 | + // Evaluate the manifest. |
| 187 | + return runModuleBehaviors({ |
| 188 | + // Remember that `powers` may be arbitrarily broad. |
| 189 | + allPowers: powers, |
| 190 | + behaviors: proposalNS, |
| 191 | + manifest: customManifest || manifest, |
| 192 | + makeConfig: (name, _permit) => { |
| 193 | + log('coreProposal:', name); |
| 194 | + return { options }; |
| 195 | + }, |
| 196 | + }); |
| 197 | + }; |
| 198 | + |
| 199 | + return coreProposalBehavior; |
| 200 | +})({ manifestBundleRef, getManifestCall, customManifest, E }); |
| 201 | +behavior; |
| 202 | + |
| 203 | +// HACK! b1-078729b9683de5f81afe8b14bd163f0165b8dd803f587413df8dff76b557d56e5d0d67f8f654bc920b5bb3a734d7d7644791692efbbc08c08984e37c6e0e6c88 |
0 commit comments