Skip to content

Commit

Permalink
Merge pull request #7131 from Agoric/ta/appendToStoredArray
Browse files Browse the repository at this point in the history
misc refactorings
  • Loading branch information
mergify[bot] authored Mar 9, 2023
2 parents 97f6488 + d792b5d commit 2e33306
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 14 deletions.
8 changes: 2 additions & 6 deletions packages/inter-protocol/src/auction/auctioneer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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%.
Expand Down
10 changes: 3 additions & 7 deletions packages/smart-wallet/src/smartWallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,16 @@ import {
PaymentShape,
PurseShape,
} from '@agoric/ertp';
import { makeTypeGuards } from '@agoric/internal';
import {
observeNotifier,
pipeTopicToStorage,
prepareDurablePublishKit,
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';
Expand Down Expand Up @@ -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);
},
},
Expand Down
16 changes: 16 additions & 0 deletions packages/store/src/stores/store-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,3 +169,19 @@ harden(makeAtomicProvider);
* @template V
* @typedef {ReturnType<typeof makeAtomicProvider<K, V>>} AtomicProvider<K, V>
*/

/**
* @template K, V
* @param {MapStore<K, V[]>} 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);
2 changes: 1 addition & 1 deletion packages/zoe/src/contractSupport/ratio.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 2e33306

Please sign in to comment.