-
Notifications
You must be signed in to change notification settings - Fork 215
/
Copy pathupgrade-mintHolder-proposal.js
74 lines (61 loc) · 1.85 KB
/
upgrade-mintHolder-proposal.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import { makeTracer } from '@agoric/internal';
import { E } from '@endo/far';
const trace = makeTracer('upgrade mintHolder', true);
export const upgradeMintHolder = async (
{
consume: {
contractKits: contractKitsP,
instancePrivateArgs: instancePrivateArgsP,
},
},
options,
) => {
const { contractRef, labelList } = options.options;
assert(contractRef.bundleID, 'mintHolder bundleID not found');
assert(labelList, 'mintHolder bank asset label list not found');
trace(`Start mintHolder contract upgrade`);
trace(`Assets: `, labelList);
const [contractKits, instancePrivateArgs] = await Promise.all([
contractKitsP,
instancePrivateArgsP,
]);
for (const assetLabel of labelList) {
const mintHolderKit = Array.from(contractKits.values()).find(
kit => kit.label && kit.label === assetLabel,
);
if (!mintHolderKit) {
console.error(
`ERROR: failed to upgrade ${assetLabel} mintHolder, contractKit not found`,
);
continue;
}
trace(`${assetLabel} mintHolderKit: `, mintHolderKit);
const { publicFacet, adminFacet, instance } = mintHolderKit;
/*
* Ensure that publicFacet holds an issuer by verifying that has
* the makeEmptyPurse method.
*/
await E(publicFacet).makeEmptyPurse();
const privateArgs = instancePrivateArgs.get(instance);
const upgradeResult = await E(adminFacet).upgradeContract(
contractRef.bundleID,
privateArgs,
);
trace(`${assetLabel} upgrade result: `, upgradeResult);
}
trace(`Finished mintHolder contract upgrade`);
};
export const getManifestForUpgradingMintHolder = (
_powers,
{ contractRef, labelList },
) => ({
manifest: {
[upgradeMintHolder.name]: {
consume: {
contractKits: true,
instancePrivateArgs: true,
},
},
},
options: { contractRef, labelList },
});