Skip to content
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

fix Payment type #10828

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft

fix Payment type #10828

wants to merge 4 commits into from

Conversation

turadg
Copy link
Member

@turadg turadg commented Jan 9, 2025

refs: https://github.com/Agoric/agoric-private/issues/236

Description

The Payment type wasn't using the M extends Key parameter, causing an error in type checking when noUnusedLocals is enabled.

That was placed there in anticipation of using it to convey the type of keys in a set-like amount. This implements that.

It also adds a makePriceQuoteIssuer to reduce the boilerplate of casting the makeIssuerKit('quote', 'set') to carry the PriceDescription key.

Security Considerations

none

Scaling Considerations

none

Documentation Considerations

nothing new

Testing Considerations

existing tests

Upgrade Considerations

none

Copy link

cloudflare-workers-and-pages bot commented Jan 9, 2025

Deploying agoric-sdk with  Cloudflare Pages  Cloudflare Pages

Latest commit: bc25555
Status: ✅  Deploy successful!
Preview URL: https://4eb1f425.agoric-sdk.pages.dev
Branch Preview URL: https://236-type-fixes.agoric-sdk.pages.dev

View logs

@turadg turadg force-pushed the 236-type-fixes branch 2 times, most recently from c7d1762 to 38fd3af Compare January 9, 2025 21:40
@turadg turadg changed the title type fixes fix Payment type Jan 9, 2025
@turadg turadg marked this pull request as ready for review January 9, 2025 22:02
@turadg turadg requested a review from a team as a code owner January 9, 2025 22:02
* @param {ERef<Purse>} recoveryPurse
* @param {ERef<P>} srcPaymentP
* @template {AssetKind} K
* @template {Key} M
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please rename all these to something other than M.

@@ -322,7 +322,7 @@ harden(prepareIssuerKit);
* anything else is corrupted by that corrupted state. See
* https://github.com/Agoric/agoric-sdk/issues/3434
* @param {IssuerOptionsRecord} [options]
* @returns {IssuerKit<K, any>}
* @returns {IssuerKit<K>}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not also parameterize the type of makeIssuerKit with the thing you're currently calling M? Is this where the inference on the elementShape would go?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just a matter of prioritization. done now

getAllegedBrand: () => Brand<K>;
};
> = RemotableObject &
Tagged<
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand that the unfortunate name collision on Tagged comes from elsewhere, so we cannot easily fix it. But especially when juxtaposed with Remotable or other passable type names, it is terribly confusing. Please at least comment all such usage sites.

I see you're passing this through '@agoric/internal/src/tagged.js' anyway. Perhaps we could have the reexport a rename, and then avoid this unfortunate name collision everywhere else? This would be better than commenting each confusing usage site.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair. I've added an alternate export. I kept the rest of the source to make it easier to maintain with changes upstream

Comment on lines +123 to +129
* @type {IssuerKit<'set', { seat: number; show: string; start: string }>}
*/ (makeIssuerKit('Agoric Ballet Opera tickets', AssetKind.SET));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it make sense to also pass a corresponding elementShape to this call to makeIssuerKit?

As a test, maybe not worth bothering, so I ask hypothetically: would it have made sense, if code like this appears in production?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Several sites now use elementShape. I think the illustration is best when there's a TypedPattern shape available, like with InvitationElementShape which I was happy to find. This instance I think serves as a useful example of typing when you don't have an elementShape defined.

const { mint, issuer, brand } = makeIssuerKit('invitations', AssetKind.SET);
const { mint, issuer, brand } =
/** @type {IssuerKit<'set', InvitationDetails>} */ (
makeIssuerKit('invitations', AssetKind.SET)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Likewise

Comment on lines +331 to +333
* @returns {O['elementShape'] extends TypedPattern<infer T>
* ? IssuerKit<K, T>
* : IssuerKit<K>}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OMG cool!

@turadg turadg added the bypass:integration Prevent integration tests from running on PR label Jan 10, 2025
@turadg turadg requested a review from erights January 10, 2025 15:56
Copy link
Member

@erights erights left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@turadg turadg added the automerge:rebase Automatically rebase updates, then merge label Jan 10, 2025
@turadg turadg marked this pull request as draft January 10, 2025 17:40
@turadg turadg removed the automerge:rebase Automatically rebase updates, then merge label Jan 10, 2025
@turadg
Copy link
Member Author

turadg commented Jan 10, 2025

Stuck on this error:

src/proposals/econ-behaviors.js:3:1 - error TS9006: Declaration emit for this file requires using private name 'tag' from module '"/opt/agoric/agoric-sdk/packages/internal/src/tagged"'. An explicit type annotation may unblock declaration emit.

3 import { AmountMath } from '@agoric/ertp';

I'll come back to it when I have time

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bypass:integration Prevent integration tests from running on PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants