endo icon indicating copy to clipboard operation
endo copied to clipboard

feat(marshal): display slot values if supplied

Open michaelfig opened this issue 3 years ago • 3 comments

Allow an optional slots argument to decodeToJustin that allows printing of slotToVal(slot, "iface").

michaelfig avatar Jun 10 '22 15:06 michaelfig

Could you provide a link to where you (plan to) use it? Otherwise, I'm having trouble imagining the motivation.

It's in the agoric follow command for consuming off-chain subscriptions (@agoric/casting): https://github.com/Agoric/agoric-sdk/blob/02c97e9f25cda307825a9a8e9dae8b8995b86d73/packages/agoric-cli/src/follow.js#L44

Each such subscription usually consists of marshalled data, for which the slots are meaningful data that can indicate the path of how to obtain a live reference to an on-chain object given a marshalling context. (The slots essentially indicate clist entries, and are only informational unless you hold a live unserialization ocap.)

Here is an illustrative (partly aspirational) example based on what I'm trying to achieve with this PR.

Before

$ agoric follow :wallet.agoric1xyzzy.purses --ojustin
[{
  id: 99n,
  currentBalance: {
    value: 123n,
    brand: slot(0, 'Alleged: public brand')
  },
  actions: slot(1, 'Alleged: private purse actions')
}]
^C

see how the slot rendering doesn't contain enough information to understand how to reconstitute the ocaps just given this output (even if you know which Agoric instance it came from)?

After

$ agoric follow :wallet.agoric1xyzzy.purses --ojustin
[{
  id: 99n,
  currentBalance: {
    value: 123n,
    brand: slotToVal('board01929', 'Alleged: public brand')
  },
  actions: slotToVal('wallet/agoric1xyzzy/o+11', 'Alleged: private purse actions')
}]
^C

With that information (and knowing which Agoric instance it came from), a consumer with access to the marshal context that understands board0... identifiers can reconstitute the public brand. A consumer with access to the marshal context that understands wallet/agoric1xyzzy/... identifiers can reconstitute the private purse actions.

michaelfig avatar Jun 12 '22 17:06 michaelfig

I updated your PR comment so that the Justin text is syntax highlighted as JS. Looks much more readable to me. But if you don't like, feel free to revert these edits.

erights avatar Jun 13 '22 19:06 erights

you could extend those to test round tripping for these too.

I tested round tripping. Please take another look before I merge.

michaelfig avatar Jun 14 '22 05:06 michaelfig