Skip to content

Commit fd8d9ec

Browse files
committed
feat: atomicRearrange with named field support
1 parent 65d8ef6 commit fd8d9ec

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// @ts-check
2+
import { atomicRearrange as atomicRearrangeTuples } from '@agoric/zoe/src/contractSupport/atomicTransfer.js';
3+
4+
/** @typedef {import("@agoric/zoe/src/contractSupport/atomicTransfer").TransferPart} TransferPart */
5+
6+
/**
7+
* Refine atomicRearrange to support naming the fields of transfer parts.
8+
*
9+
* @param {ZCF} zcf
10+
* @param { Array<TransferPartRecord | TransferPart>} transferParts
11+
*
12+
* @typedef {{
13+
* fromSeat?: ZCFSeat,
14+
* toSeat?: ZCFSeat,
15+
* fromAmounts?: AmountKeywordRecord,
16+
* toAmounts?: AmountKeywordRecord
17+
* }} TransferPartRecord
18+
*/
19+
export const atomicRearrange = (zcf, transferParts) => {
20+
/** @type {TransferPart[]} */
21+
const tuples = harden(
22+
transferParts.map(part =>
23+
Array.isArray(part)
24+
? part
25+
: [part.fromSeat, part.toSeat, part.fromAmounts, part.toAmounts],
26+
),
27+
);
28+
return atomicRearrangeTuples(zcf, tuples);
29+
};

0 commit comments

Comments
 (0)