-
Notifications
You must be signed in to change notification settings - Fork 208
/
upgrade-walletFactory-proposal.js
128 lines (117 loc) · 4.08 KB
/
upgrade-walletFactory-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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
// @ts-check
import { E } from '@endo/far';
import { makeMarshal } from '@endo/marshal';
import { allValues } from '@agoric/internal';
console.warn('upgrade-walletFactory-proposal.js module evaluating');
const { Fail } = assert;
// vstorage paths under published.*
const WALLET_STORAGE_PATH_SEGMENT = 'wallet';
const BOARD_AUX = 'boardAux';
const marshalData = makeMarshal(_val => Fail`data only`);
/**
* @param { BootstrapPowers } powers
*
* @param {object} config
* @param {{ walletFactoryRef: VatSourceRef & { bundleID: string } }} config.options
*/
export const upgradeWalletFactory = async (
{
consume: {
contractKits,
governedContractKits,
chainStorage,
walletBridgeManager: walletBridgeManagerP,
},
instance: {
consume: { walletFactory: wfInstanceP, provisionPool: ppInstanceP },
},
},
config,
) => {
console.log('upgradeWalletFactory: config', config);
const { walletFactoryRef } = config.options;
// console.log('upgradeWalletFactory: awaiting instances etc.');
const { wfInstance, ppInstance, walletBridgeManager, storageNode } =
await allValues({
wfInstance: wfInstanceP,
ppInstance: ppInstanceP,
walletBridgeManager: walletBridgeManagerP,
// @ts-expect-error chainStorage is only falsy in testing
storageNode: E(chainStorage).makeChildNode(WALLET_STORAGE_PATH_SEGMENT),
});
// console.log('upgradeWalletFactory: awaiting contract kits');
const { wfKit, ppKit } = await allValues({
wfKit: E(contractKits).get(wfInstance),
ppKit: E(governedContractKits).get(ppInstance),
});
// console.log('upgradeWalletFactory: awaiting walletReviver');
const walletReviver = await E(ppKit.creatorFacet).getWalletReviver();
const newPrivateArgs = harden({
storageNode,
walletBridgeManager,
walletReviver,
});
console.log(
'upgradeWalletFactory: upgrading with newPrivateArgs',
newPrivateArgs,
);
await E(wfKit.adminFacet).upgradeContract(
walletFactoryRef.bundleID,
newPrivateArgs,
);
console.log('upgradeWalletFactory: done');
};
harden(upgradeWalletFactory);
/**
* @param { BootstrapPowers } powers
*/
export const publishAgoricBrandsDisplayInfo = async ({
consume: { agoricNames, board, chainStorage },
}) => {
// chainStorage type includes undefined, which doesn't apply here.
// @ts-expect-error UNTIL https://github.com/Agoric/agoric-sdk/issues/8247
const boardAux = E(chainStorage).makeChildNode(BOARD_AUX);
const publishBrandInfo = async brand => {
const [id, displayInfo, allegedName] = await Promise.all([
E(board).getId(brand),
E(brand).getDisplayInfo(),
E(brand).getAllegedName(),
]);
const node = E(boardAux).makeChildNode(id);
const aux = marshalData.toCapData(harden({ allegedName, displayInfo }));
await E(node).setValue(JSON.stringify(aux));
};
/** @type {ERef<import('@agoric/vats').NameHub>} */
const brandHub = E(agoricNames).lookup('brand');
const brands = await E(brandHub).values();
// tolerate failure; in particular, for the timer brand
await Promise.allSettled(brands.map(publishBrandInfo));
};
harden(publishAgoricBrandsDisplayInfo);
/** @type { import("@agoric/vats/src/core/lib-boot").BootstrapManifest } */
const manifest = {
[upgradeWalletFactory.name]: {
// include rationale for closely-held, high authority capabilities
consume: {
contractKits: `to upgrade walletFactory using its adminFacet`,
governedContractKits:
'to get walletReviver from provisionPool.creatorFacet',
chainStorage: 'to allow walletFactory to (continue) write to vstorage',
walletBridgeManager: 'to handle bridged cosmos SpendAction messages',
},
// widely-shared, low authority instance handles need no rationale
instance: {
consume: { walletFactory: true, provisionPool: true },
},
},
[publishAgoricBrandsDisplayInfo.name]: {
consume: { agoricNames: true, board: true, chainStorage: true },
},
};
harden(manifest);
export const getManifestForUpgrade = (_powers, { walletFactoryRef }) => {
return harden({
manifest,
options: { walletFactoryRef },
});
};