From a90b77bdd188efc935125300a5e6a996e6c1488c Mon Sep 17 00:00:00 2001 From: Turadg Aleahmad Date: Tue, 7 Mar 2023 16:47:07 -0800 Subject: [PATCH 1/2] refactor: extract appendToStoredArray --- .../inter-protocol/src/auction/auctioneer.js | 8 ++------ packages/smart-wallet/src/smartWallet.js | 10 +++------- packages/store/src/stores/store-utils.js | 16 ++++++++++++++++ 3 files changed, 21 insertions(+), 13 deletions(-) diff --git a/packages/inter-protocol/src/auction/auctioneer.js b/packages/inter-protocol/src/auction/auctioneer.js index 06c5d63b4ec..caef4538c58 100644 --- a/packages/inter-protocol/src/auction/auctioneer.js +++ b/packages/inter-protocol/src/auction/auctioneer.js @@ -21,7 +21,7 @@ import { import { handleParamGovernance } from '@agoric/governance'; import { makeTracer, BASIS_POINTS } from '@agoric/internal'; import { FullProposalShape } from '@agoric/zoe/src/typeGuards.js'; - +import { appendToStoredArray } from '@agoric/store/src/stores/store-utils.js'; import { makeAuctionBook } from './auctionBook.js'; import { AuctionState } from './util.js'; import { makeScheduler } from './scheduler.js'; @@ -135,11 +135,7 @@ export const start = async (zcf, privateArgs, baggage) => { const reserveFunds = provideEmptySeat(zcf, baggage, 'collateral'); const addDeposit = (seat, amount) => { - const depositListForBrand = deposits.get(amount.brand); - deposits.set( - amount.brand, - harden([...depositListForBrand, { seat, amount }]), - ); + appendToStoredArray(deposits, amount.brand, { seat, amount }); }; // Called "discount" rate even though it can be above or below 100%. diff --git a/packages/smart-wallet/src/smartWallet.js b/packages/smart-wallet/src/smartWallet.js index b753e966399..a25dad75765 100644 --- a/packages/smart-wallet/src/smartWallet.js +++ b/packages/smart-wallet/src/smartWallet.js @@ -7,6 +7,7 @@ import { PaymentShape, PurseShape, } from '@agoric/ertp'; +import { makeTypeGuards } from '@agoric/internal'; import { observeNotifier, pipeTopicToStorage, @@ -14,8 +15,8 @@ import { SubscriberShape, TopicsRecordShape, } from '@agoric/notifier'; -import { makeTypeGuards } from '@agoric/internal'; import { M, mustMatch } from '@agoric/store'; +import { appendToStoredArray } from '@agoric/store/src/stores/store-utils.js'; import { makeScalarBigMapStore, prepareExoClassKit } from '@agoric/vat-data'; import { makeStorageNodePathProvider } from '@agoric/zoe/src/contractSupport/durability.js'; import { E } from '@endo/far'; @@ -377,12 +378,7 @@ export const prepareSmartWallet = (baggage, shared) => { // When there is no purse, save the payment into a queue. // It's not yet ever read but a future version of the contract can - if (queues.has(brand)) { - const extant = queues.get(brand); - queues.set(brand, harden([...extant, payment])); - } else { - queues.init(brand, harden([payment])); - } + appendToStoredArray(queues, brand, payment); return AmountMath.makeEmpty(brand); }, }, diff --git a/packages/store/src/stores/store-utils.js b/packages/store/src/stores/store-utils.js index 40c9f1c5699..a1fe998da47 100644 --- a/packages/store/src/stores/store-utils.js +++ b/packages/store/src/stores/store-utils.js @@ -169,3 +169,19 @@ harden(makeAtomicProvider); * @template V * @typedef {ReturnType>} AtomicProvider */ + +/** + * @template K, V + * @param {MapStore} mapStore + * @param {K} key + * @param {V} item + */ +export const appendToStoredArray = (mapStore, key, item) => { + if (mapStore.has(key)) { + const extant = mapStore.get(key); + mapStore.set(key, harden([...extant, item])); + } else { + mapStore.init(key, harden([item])); + } +}; +harden(appendToStoredArray); From d792b5d5d2fbd93a34c008ae2697390354cfa351 Mon Sep 17 00:00:00 2001 From: Turadg Aleahmad Date: Tue, 7 Mar 2023 16:47:26 -0800 Subject: [PATCH 2/2] refactor(ratio): match destructure --- packages/zoe/src/contractSupport/ratio.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/zoe/src/contractSupport/ratio.js b/packages/zoe/src/contractSupport/ratio.js index 17d252455f2..741dc656ace 100644 --- a/packages/zoe/src/contractSupport/ratio.js +++ b/packages/zoe/src/contractSupport/ratio.js @@ -373,7 +373,7 @@ export const parseRatio = ( throw Fail`Invalid numeric data: ${numeric}`; } - const [whole, part = ''] = [match[1], match[2]]; + const [_, whole, part = ''] = match; return makeRatio( BigInt(`${whole}${part}`), numeratorBrand,