From 2c085f5710a23e58995c4e7b604bdcd8eef5dd07 Mon Sep 17 00:00:00 2001 From: Dan Connolly Date: Wed, 14 Feb 2024 23:06:04 -0600 Subject: [PATCH] chore: refine names, add mappedTo in TransferPartRecord --- contract/src/offer-up.contract.js | 4 ++-- contract/src/platform-goals/zcfTools.js | 23 ++++++++++++++--------- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/contract/src/offer-up.contract.js b/contract/src/offer-up.contract.js index 983c00a..4080f80 100644 --- a/contract/src/offer-up.contract.js +++ b/contract/src/offer-up.contract.js @@ -109,8 +109,8 @@ export const start = async zcf => { const newItems = itemMint.mintGains(want); const charge = { Price: tradePrice }; atomicRearrange(zcf, [ - { fromSeat: buyerSeat, toSeat: proceeds, fromAmounts: charge }, - { fromSeat: newItems, toSeat: buyerSeat, fromAmounts: want }, + { from: buyerSeat, to: proceeds, amounts: charge }, + { from: newItems, to: buyerSeat, amounts: want }, ]); buyerSeat.exit(true); diff --git a/contract/src/platform-goals/zcfTools.js b/contract/src/platform-goals/zcfTools.js index f4fe569..f34e4ed 100644 --- a/contract/src/platform-goals/zcfTools.js +++ b/contract/src/platform-goals/zcfTools.js @@ -1,5 +1,6 @@ // @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 */ @@ -10,20 +11,24 @@ import { atomicRearrange as atomicRearrangeTuples } from '@agoric/zoe/src/contra * @param { Array} transferParts * * @typedef {{ - * fromSeat?: ZCFSeat, - * toSeat?: ZCFSeat, - * fromAmounts?: AmountKeywordRecord, - * toAmounts?: AmountKeywordRecord + * from?: ZCFSeat, + * to?: ZCFSeat, + * amounts?: AmountKeywordRecord, + * mappedTo?: KeywordKeywordRecord * }} TransferPartRecord */ export const atomicRearrange = (zcf, transferParts) => { /** @type {TransferPart[]} */ const tuples = harden( - transferParts.map(part => - Array.isArray(part) - ? part - : [part.fromSeat, part.toSeat, part.fromAmounts, part.toAmounts], - ), + 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); };