Skip to content

Commit e119387

Browse files
committed
fixup! docs: publishing to vstorage
1 parent 3312def commit e119387

File tree

2 files changed

+31
-11
lines changed

2 files changed

+31
-11
lines changed

main/guides/governance/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ Adding parameter governance to a contract consists mainly of using `handleParamG
4646
We pass it `zcf` so that it can `getTerms()` for initial parameter values, and we
4747
pass `paramTypes` to specify governed parameters and their types. `initialPoserInvitation`
4848
is necessary to set up replacing the electorate. `storageNode` and `marshaller` are used
49-
to publish values of the parameters to vstorage.
49+
to [publish values of the parameters to vstorage](../zoe/pub-to-storage).
5050

5151
```js
5252
import { handleParamGovernance } from '@agoric/governance/src/contractHelper.js';

main/guides/zoe/pub-to-storage.md

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,32 @@ Contracts can use [notifiers and subscriptions](../js-programming/notifiers)
44
to publish to clients. To publish data visible to [vstorage queries](../getting-started/contract-rpc#querying-vstorage), contracts should connect
55
a subscriber to a `chainStorage` node.
66

7-
Let's look at the Inter Protocol [assetReserve.js](https://github.com/Agoric/agoric-sdk/blob/agoric-upgrade-13/packages/inter-protocol/src/reserve/assetReserve.js) contract. It publishes to [published.reserve.metrics](https://github.com/Agoric/agoric-sdk/blob/agoric-upgrade-13/packages/inter-protocol/test/reserve/snapshots/test-reserve.js.md) data of the form
7+
## Deployment Capabilities for Publishing to chainStorage
8+
9+
In [Adding Parameter Governance to a Contract](../governance/#adding-parameter-governance-to-a-contract), the contract
10+
gets 2 properties for publishing to chainStorage in its `privateArgs`: `storageNode` and `marshaller`.
11+
12+
In [dapp-agoric-basics](https://github.com/Agoric/dapp-agoric-basics), the `startSwapContract` uses 2 [permitted deployment capabilities](../coreeval/permissions), `chainStorage` and `board` and uses them to make the `privateArgs`:
13+
14+
```js
15+
const marshaller = await E(board).getPublishingMarshaller();
16+
const storageNode = await E(chainStorage).makeChildNode(contractName);
17+
```
18+
19+
A `Marshaller` is parameterized by functions for mapping unforgeable object identities to plain data slot references and back. Using the [board](../integration/name-services#the-board-publishing-under-arbitrary-names) name service gives consistent slot references across contracts.
20+
As discussed in [Marshalling Amounts and Instances](../getting-started/contract-rpc#marshalling-amounts-and-instances), this lets
21+
off-chain clients use the same `@endo/marshal` API.
22+
23+
The `chainStorage` node corresponds to the `published` key in the
24+
[vstorage hierarchy](/reference/vstorage-ref).
25+
Using `E(chainStorage).makeChildNode(contractName)` gives the contract
26+
access to write to the `published.swaparoo` key and all keys under it.
27+
28+
The `swaparoo` contract delegates the rest of publishing governance parameters to the `@agoric/governance` package.
29+
30+
## Publishing structured data to chainStorage
31+
32+
Let's look at the Inter Protocol [assetReserve.js](https://github.com/Agoric/agoric-sdk/blob/agoric-upgrade-13/packages/inter-protocol/src/reserve/assetReserve.js) contract to get more of the details. It publishes to [published.reserve.metrics](https://github.com/Agoric/agoric-sdk/blob/agoric-upgrade-13/packages/inter-protocol/test/reserve/snapshots/test-reserve.js.md) data of the form
833

934
```js
1035
/**
@@ -109,19 +134,18 @@ const metricsNode = await E(storageNode).makeChildNode('metrics');
109134

110135
The `marshaller` is used to serialize data structures such as `MetricsNotification` above.
111136

112-
## Deployment Capabilities for Publishing to chainStorage
137+
### Deployment Capabilities for the reserve
113138

114-
To start a contract such as `assetReserve` above, the [setupReserve](https://github.com/Agoric/agoric-sdk/blob/agoric-upgrade-13/packages/inter-protocol/src/proposals/econ-behaviors.js#L76) function needs to supply
115-
the two `privateArgs`: `marshaller` and `storageNode`:
139+
To start `assetReserve`, the [setupReserve](https://github.com/Agoric/agoric-sdk/blob/agoric-upgrade-13/packages/inter-protocol/src/proposals/econ-behaviors.js#L76) function again supplies
140+
the two relevant `privateArgs`, `marshaller` and `storageNode`:
116141

117142
```js
118143
const STORAGE_PATH = 'reserve';
119144
const storageNode = await E(storageNode).makeChildNode(STORAGE_PATH);
120145
const marshaller = await E(board).getReadonlyMarshaller();
121146
```
122147

123-
As usual for a [permissioned deployment script function](../coreeval/proposal), `setupReserve` function is passed `BootstrapPowers`
124-
including `chainStorage` and `board`:
148+
The `setupReserve` function gets `chainStorage` and `board` deployment capabilities passed in:
125149

126150
```js
127151
export const setupReserve = async ({
@@ -133,7 +157,3 @@ export const setupReserve = async ({
133157
...
134158
}) => { ... };
135159
```
136-
137-
A `Marshaller` is parameterized by functions for mapping unforgeable object identities to plain data slot references and back. Using the [board](../integration/name-services#the-board-publishing-under-arbitrary-names) name service gives consistent slot references across contracts.
138-
As discussed in [Marshalling Amounts and Instances](../getting-started/contract-rpc#marshalling-amounts-and-instances), this lets
139-
off-chain clients use the same `@endo/marshal` API.

0 commit comments

Comments
 (0)