-
Notifications
You must be signed in to change notification settings - Fork 254
feat(zoe): zoe part of minimal want patterns using M.containerHas(el,n)
#10952
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
base: markm-want-patterns-only-ertp
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,7 @@ import { makeScalarMapStore } from '@agoric/vat-data'; | |
|
|
||
| import { assertRightsConserved } from './rightsConservation.js'; | ||
| import { addToAllocation, subtractFromAllocation } from './allocationMath.js'; | ||
| import { mustBeKey } from '../contractSupport/zoeHelpers.js'; | ||
|
|
||
| /** | ||
| * @import {MapStore} from '@agoric/swingset-liveslots'; | ||
|
|
@@ -47,11 +48,15 @@ export const makeAllocationMap = transfers => { | |
| allocations.set(seat, [newIncr, decr]); | ||
| }; | ||
|
|
||
| for (const [fromSeat, toSeat, fromAmounts, toAmounts] of transfers) { | ||
| for (const [fromSeat, toSeat, fromAmountBounds, toAmounts] of transfers) { | ||
| if (fromSeat) { | ||
| if (!fromAmounts) { | ||
| if (!fromAmountBounds) { | ||
| throw Fail`Transfer from ${fromSeat} must say how much`; | ||
| } | ||
| const fromAmounts = mustBeKey( | ||
| fromAmountBounds, | ||
| 'TODO: atomicRearange does not yet support AmountBounds', | ||
| ); | ||
| decrementAllocation(fromSeat, fromAmounts); | ||
| if (toSeat) { | ||
| // Conserved transfer between seats | ||
|
|
@@ -74,8 +79,8 @@ export const makeAllocationMap = transfers => { | |
| } else { | ||
| toSeat || Fail`Transfer must have at least one of fromSeat or toSeat`; | ||
| // Transfer only to toSeat | ||
| !fromAmounts || | ||
| Fail`Transfer without fromSeat cannot have fromAmounts ${fromAmounts}`; | ||
| !fromAmountBounds || | ||
| Fail`Transfer without fromSeat cannot have fromAmountBounds ${fromAmountBounds}`; | ||
| toAmounts || Fail`Transfer to ${toSeat} must say how much`; | ||
| incrementAllocation(toSeat, toAmounts); | ||
| } | ||
|
|
@@ -93,5 +98,5 @@ export const makeAllocationMap = transfers => { | |
| } | ||
| resultingAllocations.push([seat, newAlloc]); | ||
| } | ||
| return resultingAllocations; | ||
| return harden(resultingAllocations); | ||
|
||
| }; | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,15 +1,15 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| import { Fail } from '@endo/errors'; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| import { Fail, b } from '@endo/errors'; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| import { E } from '@endo/eventual-send'; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| import { makePromiseKit } from '@endo/promise-kit'; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| import { mustMatch, keyEQ } from '@agoric/store'; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| import { mustMatch, keyEQ, isKey, isPattern } from '@endo/patterns'; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| import { AssetKind } from '@agoric/ertp'; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| import { fromUniqueEntries } from '@agoric/internal'; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| import { satisfiesWant } from '../contractFacet/offerSafety.js'; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| import { atomicTransfer, fromOnly, toOnly } from './atomicTransfer.js'; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||||||||||
| * @import {Pattern} from '@endo/patterns'; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| * @import {ContractMeta, Invitation, Proposal, ZCF, ZCFSeat} from '@agoric/zoe'; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| * @import {Invitation, Proposal, ZCF, ZCFSeat, AmountBoundKeywordRecord} from '@agoric/zoe'; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| export const defaultAcceptanceMsg = `The offer has been accepted. Once the contract has been completed, please check your payout`; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -73,16 +73,42 @@ export const swap = (zcf, leftSeat, rightSeat) => { | |||||||||||||||||||||||||||||||||||||||||||||||||
| return defaultAcceptanceMsg; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||||||||||
| * @param {AmountBoundKeywordRecord} want | ||||||||||||||||||||||||||||||||||||||||||||||||||
| * @param {string} complaint | ||||||||||||||||||||||||||||||||||||||||||||||||||
| * @returns {AmountKeywordRecord} | ||||||||||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| export const mustBeKey = (want, complaint) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| if (isKey(want)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| return want; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| if (isPattern(want)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| throw Fail`${b(complaint)}: ${want}`; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| throw Fail`Must be key: ${want}`; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+77
to
+88
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| * @param {AmountBoundKeywordRecord} want | |
| * @param {string} complaint | |
| * @returns {AmountKeywordRecord} | |
| */ | |
| export const mustBeKey = (want, complaint) => { | |
| if (isKey(want)) { | |
| return want; | |
| } | |
| if (isPattern(want)) { | |
| throw Fail`${b(complaint)}: ${want}`; | |
| } | |
| throw Fail`Must be key: ${want}`; | |
| * @param {AmountBoundKeywordRecord} value | |
| * @param {string} complaint | |
| * @returns {AmountKeywordRecord} | |
| */ | |
| export const mustBeKey = (value, complaint) => { | |
| if (isKey(value)) { | |
| return value; | |
| } | |
| if (isPattern(value)) { | |
| throw Fail`${b(complaint)}: ${value}`; | |
| } | |
| throw Fail`Must be key: ${value}`; |
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.
"atomicRearange" should be "atomicRearrange" (missing 'r').