-
Notifications
You must be signed in to change notification settings - Fork 5
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
refactor: use named fields in atomicRearrange #65
base: dc-narrow-powers
Are you sure you want to change the base?
Changes from 4 commits
65d8ef6
fd8d9ec
593e65c
6df24ef
04f7376
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Platform Goals | ||
|
||
Work on this dapp shows some ways that the platform could be improved. | ||
|
||
The code in this directory shows some possible platform refinements. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// @ts-check | ||
import { atomicRearrange as atomicRearrangeTuples } from '@agoric/zoe/src/contractSupport/atomicTransfer.js'; | ||
import { mapKeywords } from '@agoric/zoe/src/contractSupport/zoeHelpers.js'; | ||
|
||
/** @typedef {import("@agoric/zoe/src/contractSupport/atomicTransfer").TransferPart} TransferPart */ | ||
|
||
/** | ||
* Refine atomicRearrange to support naming the fields of transfer parts. | ||
* | ||
* @param {ZCF} zcf | ||
* @param { Array<TransferPartRecord | TransferPart>} transferParts | ||
* | ||
* @typedef {{ | ||
* from?: ZCFSeat, | ||
* to?: ZCFSeat, | ||
* amounts?: AmountKeywordRecord, | ||
* mappedTo?: KeywordKeywordRecord | ||
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. I am surprised by this. When I saw @dtribble 's suggestion that the optional fourth field be named On first blush, both are plausble. As an AmountKeywordRecord, the original meaning of Btw, when I said 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. 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. Given that the amounts must match, the |
||
* }} TransferPartRecord | ||
*/ | ||
export const atomicRearrange = (zcf, transferParts) => { | ||
/** @type {TransferPart[]} */ | ||
const tuples = harden( | ||
transferParts.map(part => { | ||
if (Array.isArray(part)) { | ||
return part; | ||
} | ||
const toAmounts = part.mappedTo | ||
? mapKeywords(part.amounts, part.mappedTo) | ||
: undefined; | ||
return [part.from, part.to, part.amounts, toAmounts]; | ||
}), | ||
); | ||
return atomicRearrangeTuples(zcf, tuples); | ||
}; |
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.
Please restore the harden
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.
Sorry, already stated. (I thought I was commenting on another PR where I hadn't yet said this.)