-
Notifications
You must be signed in to change notification settings - Fork 206
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(wallet/api): marshal contexts for wallet, board #5883
Conversation
good progress:
|
So you'd like me to do something like b516b66 to integrate this? Can we make a checklist of things to do, like purses, payments, issuers, brands, etc |
['applyFunction', purse.actions, [1, 'thing']], | ||
]); | ||
|
||
const ctx = makeExportContext(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm confused about this test case, because ctx
I thought would be inside lib-wallet
, while the logging presence would be used outside lib-wallet
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point; I guess I'll think this over some more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd like to come back to this in a later PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good.
I don't know how to assess this:
there's a risk that chainStorage data from the AMM could try to refer to a purse using a slots such as purse:123; such a reference must fail.
Can a test be added for that?
* @template T | ||
* @typedef {`${string & keyof T}:${Digits}`} WalletSlot<T> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bravo on the string template type. non-blocking suggestion to help document how this works,
* @template T | |
* @typedef {`${string & keyof T}:${Digits}`} WalletSlot<T> | |
* @template {Record<string, IdTable<*,*>} T | |
* @typedef {`${keyof T}:${Digits}`} WalletSlot<T> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I integrated most of that suggestion. Constraining T
that way helps not only documentation but also got rid of one or two @ts-expect-error
s.
But getting rid of string &
doesn't seem to fly.
* @returns {WalletSlot<T>} | ||
*/ | ||
const makeWalletSlot = (_tables, kind, id) => { | ||
const digits = /** @type {Digits} */ (`${id}`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
consider asserting id >= 1
for the digits
*/ | ||
|
||
/** | ||
* @template T |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for documentation purposes,
* @template T | |
* @template {Record<string, IdTable<*,*>} T |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks; I'll give that a try.
Earlier I explored similar things without luck and punted.
*/ | ||
const findKey = (record, predicate) => { | ||
const key = Object.keys(record).find(predicate); | ||
// @ts-expect-error clearly keys(r).find() is keyof T |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
well, keyof T | undefined
. the jsdoc is right but this comment is loose
/** | ||
* @template T | ||
* @param {T} _tables | ||
* @param {string & keyof T} kind |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the above would also simplify this,
* @param {string & keyof T} kind | |
* @param {keyof T} kind |
* @template T | ||
* @param {T} record | ||
* @param {(value: string, index: number, obj: string[]) => boolean} predicate | ||
* @returns {string & keyof T | undefined} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto on above suggestions about typing the template
}; | ||
|
||
/** | ||
* Since KindSlots always include a colon and BoardIds never do, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👏
t.deepEqual(cap2, { | ||
body: JSON.stringify({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
when these don't match, it'll be a string diff. consider comparing the object with JSON.parse(cap2)
.
If not comparing objects then it should be t.is
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test is supposed to be at the CapData level, where body
is a string. Writing the expected body
using JSON.stringify()
makes it easier to read. I suppose I could add a comment...
Meanwhile, your comment prompts me to think about this a bit more carefully... In the API, slots
are compared by identity, so t.deepEqual()
is only correct because we happen to be using primitives (strings). In nearby designs, the slots are { kind: 'purse', id: 123}
objects where it's really easy to have things that pass t.deepEqual()
but not t.is()
.
}); | ||
}); | ||
|
||
// { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dead code
It's in there:
p.s. "AMM cannot forge references to purses" would be a better phrasing. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approving now. (No automerge label so you'll be able to try the TS tweak before it merges.)
- perhaps one bug fix around `purse:1` vs `1`?
refs: #4398
obsoletes #5874
Description
When serializing wallet state for chainStorage, there's a tension between
makeMarshal
is parameterized by the type of slots. Here we use a disjoint union ofkind:seq
ids for closely held objects; for examplepurse:123
@samsiegart note that unlike #5874 , this PR doesn't include any changes to
lib-wallet.js
; I hope you can layer those changes on top of this as a form of review.This PR includes
makeLoggingPresence
, which is some advanced work on smart wallet middleware. While the design is still in progress, test coverage of this version is good enough that I'd like to land it.Security Considerations
As @warner noted, there's a risk that chainStorage data from the AMM could try to refer to a purse using a slots such as
purse:123
; such a reference must fail.Documentation Considerations
not much; these are internal APIs.
Testing Considerations
Test coverage is 100%.