Skip to content
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

misc refactorings #7131

Merged
merged 2 commits into from
Mar 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doh! Thx.

return makeRatio(
BigInt(`${whole}${part}`),
numeratorBrand,
Expand Down