-
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
Make Recovery sets optional #9013
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
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 |
---|---|---|
|
@@ -72,6 +72,7 @@ const amountShapeFromElementShape = (brand, assetKind, elementShape) => { | |
* @param {K} assetKind | ||
* @param {DisplayInfo<K>} displayInfo | ||
* @param {Pattern} elementShape | ||
* @param {RecoverySetsOption} recoverySetsState | ||
* @param {ShutdownWithFailure} [optShutdownWithFailure] | ||
* @returns {PaymentLedger<K>} | ||
*/ | ||
|
@@ -81,6 +82,7 @@ export const preparePaymentLedger = ( | |
assetKind, | ||
displayInfo, | ||
elementShape, | ||
recoverySetsState, | ||
optShutdownWithFailure = undefined, | ||
) => { | ||
/** @type {Brand<K>} */ | ||
|
@@ -141,11 +143,11 @@ export const preparePaymentLedger = ( | |
}); | ||
|
||
/** | ||
* A withdrawn live payment is associated with the recovery set of the purse | ||
* it was withdrawn from. Let's call these "recoverable" payments. All | ||
* recoverable payments are live, but not all live payments are recoverable. | ||
* We do the bookkeeping for payment recovery with this weakmap from | ||
* recoverable payments to the recovery set they are in. A bunch of | ||
* A (non-empty) withdrawn live payment is associated with the recovery set of | ||
* the purse it was withdrawn from. Let's call these "recoverable" payments. | ||
* All recoverable payments are live, but not all live payments are | ||
* recoverable. We do the bookkeeping for payment recovery with this weakmap | ||
* from recoverable payments to the recovery set they are in. A bunch of | ||
* interesting invariants here: | ||
* | ||
* - Every payment that is a key in the outer `paymentRecoverySets` weakMap is | ||
|
@@ -157,6 +159,9 @@ export const preparePaymentLedger = ( | |
* - A purse's recovery set only contains payments withdrawn from that purse and | ||
* not yet consumed. | ||
* | ||
* If `recoverySetsState === 'noRecoverySets'`, then nothing should ever be | ||
* added to this WeakStore. | ||
* | ||
* @type {WeakMapStore<Payment, SetStore<Payment>>} | ||
*/ | ||
const paymentRecoverySets = issuerZone.weakMapStore('paymentRecoverySets'); | ||
|
@@ -170,7 +175,11 @@ export const preparePaymentLedger = ( | |
* @param {SetStore<Payment>} [optRecoverySet] | ||
*/ | ||
const initPayment = (payment, amount, optRecoverySet = undefined) => { | ||
if (optRecoverySet !== undefined) { | ||
if (recoverySetsState === 'noRecoverySets') { | ||
optRecoverySet === undefined || | ||
Fail`when recoverSetsState === 'noRecoverySets', optRecoverySet must be empty`; | ||
} | ||
if (optRecoverySet !== undefined && !AmountMath.isEmpty(amount)) { | ||
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. Good to see the isEmpty check arrive too! |
||
optRecoverySet.add(payment); | ||
paymentRecoverySets.init(payment, optRecoverySet); | ||
} | ||
|
@@ -263,10 +272,10 @@ export const preparePaymentLedger = ( | |
* | ||
* @param {import('./amountStore.js').AmountStore} balanceStore | ||
* @param {Amount} amount - the amount to be withdrawn | ||
* @param {SetStore<Payment>} recoverySet | ||
* @param {SetStore<Payment>} [recoverySet] | ||
* @returns {Payment} | ||
*/ | ||
const withdrawInternal = (balanceStore, amount, recoverySet) => { | ||
const withdrawInternal = (balanceStore, amount, recoverySet = undefined) => { | ||
amount = coerce(amount); | ||
const payment = makePayment(); | ||
// COMMIT POINT Move the withdrawn assets from this purse into | ||
|
@@ -294,6 +303,8 @@ export const preparePaymentLedger = ( | |
depositInternal, | ||
withdrawInternal, | ||
}), | ||
recoverySetsState, | ||
paymentRecoverySets, | ||
); | ||
|
||
/** @type {Issuer<K>} */ | ||
|
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
Oops, something went wrong.
Oops, something went wrong.
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.
Thx for expanding this out.