Skip to content

Commit f47fd29

Browse files
committed
docs: more detail and more cross links
1 parent 159b0a4 commit f47fd29

File tree

3 files changed

+66
-31
lines changed

3 files changed

+66
-31
lines changed

main/guides/zoe/contract-upgrade.md

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
# Contract Upgrade
22

3-
The result of starting a contract includes the right to upgrade the contract instance. A call to [E(zoe).startInstance(...)](/reference/zoe-api/zoe.md#e-zoe-startinstance-installation-issuerkeywordrecord-terms-privateargs) returns a record of several objects that represent different levels of access.
4-
The `publicFacet` and `creatorFacet` are defined by the contract.
5-
The `adminFacet` is defined by Zoe and includes methods to upgrade the contract.
3+
The return value when starting a contract includes a capability that conveys the right to upgrade
4+
the contract instance. A call to
5+
[E(zoe).startInstance(...)](/reference/zoe-api/zoe.md#e-zoe-startinstance-installation-issuerkeywordrecord-terms-privateargs)
6+
returns a record of several objects that carry different powers. The `publicFacet` and
7+
`creatorFacet` are defined by the contract. The
8+
[`adminFacet`](/reference/zoe-api/zoe.html#adminFacet) is defined by Zoe and includes methods to
9+
upgrade the contract.
610

711
::: tip Upgrade Governance
812

@@ -60,16 +64,27 @@ There are a few requirements for the contract that differ from non-upgradable co
6064
6165
### Upgradable Declaration
6266
63-
The new code bundle declares that it supports upgrade by exporting a `prepare` function in place of `start`.
67+
The new code bundle declares that it supports upgrade by including a `meta` record in addition to
68+
`start`. (We used to indicate upgradability by using `prepare` instead of `start`, but that
69+
approach is deprecated.)`
6470
65-
<<< @/../snippets/zoe/src/02b-state-durable.js#export-prepare
71+
`meta` is a record with any or all of `upgradability`, `customTermsShape`, and `privateArgsShape`
72+
defined. The latter two are optional
73+
[Patterns](https://endojs.github.io/endo/modules/_endo_patterns.html) restricting respectively
74+
acceptable `terms`, and `privateArgs`. `upgradability` can be `none` (the contract is not
75+
upgradable), `canUpgrade` (this code can perform an upgrade), or `canBeUpgraded` (the contract
76+
stores kinds durably such that the next version can upgrade).
77+
78+
<<< @/../snippets/zoe/src/02b-state-durable.js#export-start
6679
6780
### Durability
6881
69-
The 3rd argument, `baggage`, of the `prepare` function is a `MapStore`
70-
that provides a way to preserve state and behavior of objects
71-
between incarnations in a way that preserves identity of objects
72-
as seen from other vats:
82+
<a id="baggage"></a>
83+
84+
The 3rd argument, `baggage`, of the `start` function is a `MapStore` that is saved by the kernel
85+
across restarts of the contract. It provides a way to preserve state and behavior of objects between
86+
incarnations in a way that also maintains the identity of objects as seen from other [vats](/glossary/#vat).
87+
7388
7489
```js
7590
let rooms;
@@ -83,7 +98,7 @@ if (!baggage.has('rooms')) {
8398
}
8499
```
85100
86-
The `provide` function supports a concise idiom for this find-or-create pattern:
101+
The `provide` function supports a concise idiom for this get-or-create pattern:
87102
88103
```js
89104
import { provide } from '@agoric/vat-data';
@@ -113,7 +128,8 @@ When the contract instance is restarted, its [vat](../js-programming/#vats-the-u
113128

114129
### Kinds
115130

116-
Use `zone.exoClass()` to define state and methods of kinds of durable objects such as `Room`:
131+
Use [`zone.exoClass()`](./contract-details.md#durable-objects) to define state and methods of kinds
132+
of durable objects such as `Room`:
117133

118134
<<< @/../snippets/zoe/src/02b-state-durable.js#exoclass
119135

@@ -141,8 +157,9 @@ const makeRoom = zone.exoClass('Room', RoomI, id => ({ id, value: 0 }), {
141157
});
142158
```
143159

144-
The interface guard also needs updating.
145-
<small>_See [@endo/patterns](https://endojs.github.io/endo/modules/_endo_patterns.html) for more on interface guards._</small>
160+
The interface guard also needs updating. <small>_[The Durable
161+
objects](./contract-details.md#guards-defensive-methods) section has more on interface
162+
guards._</small>
146163

147164
```js
148165
const RoomI = M.interface('Room', {
@@ -175,20 +192,6 @@ Define all exo classes/kits before any incoming method calls from other vats --
175192
176193
:::
177194
178-
### Baggage
179-
180-
baggage is a MapStore that provides a way to preserve the state and behavior of objects between [smart contract upgrades](/guides/zoe/contract-upgrade) in a way that preserves the identity of objects as seen from other [vats](#vat). In the provided contract, baggage is used to ensure that the state of various components is maintained even after the contract is upgraded.
181-
182-
```js
183-
export const start = async (zcf, privateArgs, baggage) => {
184-
// ...
185-
const { accountsStorageNode } = await provideAll(baggage, {
186-
accountsStorageNode: () => E(storageNode).makeChildNode('accounts')
187-
});
188-
// ...
189-
};
190-
```
191-
192195
### Exo
193196
194197
An Exo object is an exposed Remotable object with methods (aka a [`Far`](/guides/js-programming/far) object) which is

main/reference/zoe-api/zoe.md

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,24 +269,54 @@ It returns a **Promise** for a **StartInstanceResult** object. The object consis
269269
- **instance**: **Instance**
270270
- **creatorInvitation**: **Payment | undefined**
271271

272-
The **adminFacet** has one method:
272+
<a id="adminfacet"></a>
273+
274+
The **adminFacet** has four methods:
273275

274276
- **getVatShutdownPromise()**
275277
- Returns a promise that resolves to reason (the value passed to **fail(reason)**) or
276278
completion (the value passed to **exit(completion)**) when this newly started instance terminates.
277279

280+
- **restartContract(newPrivateArgs?)**
281+
- **newPrivateArgs**: **any** - Optional
282+
- returns VatUpgradeResults (a record with one field: incarnationNumber)
283+
284+
Restarts the contract without changing the contract bundle
285+
286+
- **upgradeContract(contractBundleId, newPrivateArgs)**
287+
- **contractBundleId**: **string**
288+
- **newPrivateArgs**: **any** - Optional
289+
290+
- returns VatUpgradeResults (a record with one field: incarnationNumber)
291+
292+
Upgrades the contract to use source code from a new bundle.
293+
294+
See [Contract Upgrade](/guides/zoe/contract-upgrade) for a description the
295+
process of upgrading contracts.
296+
297+
- **terminateContract(reason)**
298+
- **reason**: **Error**
299+
300+
terminates the contract. `reason` will be provided as the failure reason.
301+
302+
<a id="publicfacet"></a>
303+
278304
A **publicFacet** is an object available via Zoe to anyone knowing
279305
the instance they are associated with. The **publicFacet** is used for general queries
280306
and actions, such as getting a current price or creating public **[Invitations](./zoe-data-types#invitation)**. Since a
281307
facet is defined just as any other object,
282308
the contract developer can add methods to them just like they would any object.
283309

310+
<a id="creatorfacet"></a>
311+
284312
The **creatorFacet** is only available in this return value (i.e. only when starting
285313
a contract instance). The contract designer
286314
should use it to encapsulate things that the contract runner might not want to share,
287315
or might want to control the distribution of. The party who starts the contract
288316
should carefully consider the impact before sharing access to the **creatorFacet**.
289317

318+
<a id="creatorinvitation"></a>
319+
290320
**creatorInvitation** is an **Invitation** that the contract instance creator can use.
291321
It is usually used in contracts where the creator immediately sells
292322
something (auctions, swaps, etc.), so it's helpful for the creator to have

snippets/zoe/src/02b-state-durable.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@ const RoomMakerI = M.interface('RoomMaker', {
1717
});
1818
// #endregion interface-guard
1919

20-
// #region export-prepare
21-
export const prepare = (_zcf, _privateArgs, baggage) => {
22-
// #endregion export-prepare
20+
// #region export-start
21+
export const meta = { upgradability: 'canUpgrade' };
22+
23+
export const start = (_zcf, _privateArgs, baggage) => {
24+
// #endregion export-start
2325
// #region zone1
2426
const zone = makeDurableZone(baggage);
2527
const rooms = zone.mapStore('rooms');

0 commit comments

Comments
 (0)