Skip to content

Commit

Permalink
feat: check inventory is not empty and has the same brand at contract…
Browse files Browse the repository at this point in the history
… start
  • Loading branch information
LuqiPan committed Feb 15, 2024
1 parent 216b293 commit 02bde11
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions contract/src/sell-concert-tickets.contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,9 @@ export const bagPrice = (bag, inventory) => {
/** @type {[string, bigint][]} */
const entries = getCopyBagEntries(bag);
const values = Object.values(inventory);
values.length > 0 || Fail`inventory must not be empty`;
const brand = values[0].tradePrice.brand;
return entries.reduce(
(sum, entry) => addMultiples(sum, entry, inventory),
// TODO: a better way to create empty amount
AmountMath.makeEmpty(brand),
);
};
Expand Down Expand Up @@ -106,6 +104,15 @@ export const bagPrice = (bag, inventory) => {
export const start = async zcf => {
const { inventory } = zcf.getTerms();

const inventoryValues = Object.values(inventory);

// make sure inventory is not empty
inventoryValues.length > 0 || Fail`inventory must not be empty`;
// make sure all kinds of tickets have the same brand for tradePrice
inventoryValues.every(
v => v.tradePrice.brand === inventoryValues[0].tradePrice.brand,
) || Fail`inventory must have the same brand for all tickets' tradePrice`;

/**
* a new ERTP mint for tickets, accessed thru the Zoe Contract Facet.
* Note: `makeZCFMint` makes the associated brand and issuer available
Expand Down

0 comments on commit 02bde11

Please sign in to comment.