-
Notifications
You must be signed in to change notification settings - Fork 212
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
convert fast-usdc contract to .ts #10480
Open
turadg
wants to merge
6
commits into
master
Choose a base branch
from
ta/fu-ts
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+132
−154
Open
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
653ec1f
build: support for .ts in JS bundles
turadg f5aa600
feat(types): generic makeDurablePublishKit
turadg f531c7f
feat(types): generic zone.mapStore
turadg 384916e
refactor: fast-usdc.contract to .ts
turadg d46b152
refactor: Convert transaction-feed.js to TypeScript
turadg 2899c22
refactor: convert operator-kit to .ts
turadg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,13 @@ | ||
import { makeTracer } from '@agoric/internal'; | ||
import { prepareDurablePublishKit } from '@agoric/notifier'; | ||
import type { Zone } from '@agoric/zone'; | ||
import { M } from '@endo/patterns'; | ||
import { CctpTxEvidenceShape } from '../type-guards.js'; | ||
import type { CctpTxEvidence } from '../types.js'; | ||
import { defineInertInvitation } from '../utils/zoe.js'; | ||
import type { OperatorKit } from './operator-kit.js'; | ||
import { prepareOperatorKit } from './operator-kit.js'; | ||
|
||
/** | ||
* @import {Zone} from '@agoric/zone'; | ||
* @import {OperatorKit} from './operator-kit.js'; | ||
* @import {CctpTxEvidence} from '../types.js'; | ||
*/ | ||
|
||
const trace = makeTracer('TxFeed', true); | ||
|
||
/** Name in the invitation purse (keyed also by this contract instance) */ | ||
|
@@ -21,7 +18,6 @@ const TransactionFeedKitI = harden({ | |
submitEvidence: M.call(CctpTxEvidenceShape, M.any()).returns(), | ||
}), | ||
creator: M.interface('Transaction Feed Creator', { | ||
// TODO narrow the return shape to OperatorKit | ||
initOperator: M.call(M.string()).returns(M.record()), | ||
makeOperatorInvitation: M.call(M.string()).returns(M.promise()), | ||
removeOperator: M.call(M.string()).returns(), | ||
|
@@ -31,18 +27,18 @@ const TransactionFeedKitI = harden({ | |
}), | ||
}); | ||
|
||
/** | ||
* @param {Zone} zone | ||
* @param {ZCF} zcf | ||
*/ | ||
export const prepareTransactionFeedKit = (zone, zcf) => { | ||
const kinds = zone.mapStore('Kinds'); | ||
interface State { | ||
operators: MapStore<string, OperatorKit>; | ||
pending: MapStore<string, MapStore<string, CctpTxEvidence>>; | ||
} | ||
|
||
export const prepareTransactionFeedKit = (zone: Zone, zcf: ZCF) => { | ||
const kinds = zone.mapStore<string, unknown>('Kinds'); | ||
const makeDurablePublishKit = prepareDurablePublishKit( | ||
kinds, | ||
'Transaction Feed', | ||
); | ||
/** @type {PublishKit<CctpTxEvidence>} */ | ||
const { publisher, subscriber } = makeDurablePublishKit(); | ||
const { publisher, subscriber } = makeDurablePublishKit<CctpTxEvidence>(); | ||
|
||
const makeInertInvitation = defineInertInvitation(zcf, 'submitting evidence'); | ||
|
||
|
@@ -53,15 +49,16 @@ export const prepareTransactionFeedKit = (zone, zcf) => { | |
return zone.exoClassKit( | ||
'Fast USDC Feed', | ||
TransactionFeedKitI, | ||
() => { | ||
/** @type {MapStore<string, OperatorKit>} */ | ||
const operators = zone.mapStore('operators', { | ||
durable: true, | ||
}); | ||
/** @type {MapStore<string, MapStore<string, CctpTxEvidence>>} */ | ||
const pending = zone.mapStore('pending', { | ||
(): State => { | ||
const operators = zone.mapStore<string, OperatorKit>('operators', { | ||
durable: true, | ||
}); | ||
const pending = zone.mapStore<string, MapStore<string, CctpTxEvidence>>( | ||
'pending', | ||
{ | ||
durable: true, | ||
}, | ||
); | ||
return { operators, pending }; | ||
}, | ||
{ | ||
|
@@ -71,24 +68,21 @@ export const prepareTransactionFeedKit = (zone, zcf) => { | |
* oracle network, with the able to submit data to submit evidence of | ||
* CCTP transactions. | ||
* | ||
* @param {string} operatorId unique per contract instance | ||
* @returns {Promise<Invitation<OperatorKit>>} | ||
* @param operatorId unique per contract instance | ||
*/ | ||
makeOperatorInvitation(operatorId) { | ||
makeOperatorInvitation( | ||
operatorId: string, | ||
): Promise<Invitation<OperatorKit>> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why type the return? It seems the same value is inferred There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just moved from what was there. I'll leave since it doesn't hurt to be explicit |
||
const { creator } = this.facets; | ||
trace('makeOperatorInvitation', operatorId); | ||
|
||
return zcf.makeInvitation( | ||
/** @type {OfferHandler<OperatorKit>} */ | ||
seat => { | ||
seat.exit(); | ||
return creator.initOperator(operatorId); | ||
}, | ||
INVITATION_MAKERS_DESC, | ||
); | ||
return zcf.makeInvitation(seat => { | ||
seat.exit(); | ||
return creator.initOperator(operatorId); | ||
}, INVITATION_MAKERS_DESC); | ||
}, | ||
/** @param {string} operatorId */ | ||
initOperator(operatorId) { | ||
|
||
initOperator(operatorId: string) { | ||
const { operators, pending } = this.state; | ||
trace('initOperator', operatorId); | ||
|
||
|
@@ -105,8 +99,7 @@ export const prepareTransactionFeedKit = (zone, zcf) => { | |
return operatorKit; | ||
}, | ||
|
||
/** @param {string} operatorId */ | ||
async removeOperator(operatorId) { | ||
async removeOperator(operatorId: string) { | ||
const { operators } = this.state; | ||
trace('removeOperator', operatorId); | ||
const operatorKit = operators.get(operatorId); | ||
|
@@ -117,11 +110,10 @@ export const prepareTransactionFeedKit = (zone, zcf) => { | |
operatorPowers: { | ||
/** | ||
* Add evidence from an operator. | ||
* | ||
* @param {CctpTxEvidence} evidence | ||
* @param {OperatorKit} operatorKit | ||
* @param evidence | ||
* @param operatorKit | ||
*/ | ||
submitEvidence(evidence, operatorKit) { | ||
submitEvidence(evidence: CctpTxEvidence, operatorKit: OperatorKit) { | ||
const { pending } = this.state; | ||
trace( | ||
'submitEvidence', | ||
|
@@ -177,4 +169,6 @@ export const prepareTransactionFeedKit = (zone, zcf) => { | |
}; | ||
harden(prepareTransactionFeedKit); | ||
|
||
/** @typedef {ReturnType<ReturnType<typeof prepareTransactionFeedKit>>} TransactionFeedKit */ | ||
export type TransactionFeedKit = ReturnType< | ||
ReturnType<typeof prepareTransactionFeedKit> | ||
>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Why is this unknown?
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 just didn't know what to type it and this worked