Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const escrowPayment = async (payoutRule, offerPayment, purse, extentOps) => {
// if the user's contractual understanding includes
// "offerExactly" or "offerAtMost", make sure that they have supplied a
// payment with that exact balance
if (['offerExactly', 'offerAtMost'].includes(payoutRule.kind)) {
const { extent } = await E(purse).depositExactly(
payoutRule.units,
offerPayment,
);
return extent;
}
insist(
offerPayment === undefined,
)`payment was included, but the rule kind was ${payoutRule.kind}`;
return extentOps.empty();
};
recordAssay: async assay => {
if (!assayToPurse.has(assay)) {
const unitOpsP = E(assay).getUnitOps();
const labelP = E(assay).getLabel();
const purseP = E(assay).makeEmptyPurse();
const extentOpsDescP = E(assay).getExtentOps();
const [unitOps, label, purse, extentOpsDesc] = await Promise.all([
unitOpsP,
labelP,
purseP,
extentOpsDescP,
]);
assayToDescOps.init(assay, unitOps);
assayToLabel.init(assay, label);
assayToPurse.init(assay, purse);
const { name, extentOpArgs = [] } = extentOpsDesc;
assayToExtentOps.init(assay, extentOpsLib[name](...extentOpArgs));
const recordAssayLater = assayP => {
const extentOpsDescP = E(assayP).getExtentOps();
const labelP = E(assayP).getLabel();
const purseP = E(assayP).makeEmptyPurse();
return Promise.all([assayP, extentOpsDescP, labelP, purseP]).then(
([assay, extentOpsDesc, label, purse]) => {
if (assayToAssayRecord.has(assay)) {
return assayToAssayRecord.get(assay);
}
const { name, extentOpsArgs = [] } = extentOpsDesc;
const extentOps = extentOpsLib[name](...extentOpsArgs);
assayToPurse.init(assay, purse);
return makeAssayRecord(assay, extentOps, label);
},
);
};
const recordAssayLater = assayP => {
const extentOpsDescP = E(assayP).getExtentOps();
const labelP = E(assayP).getLabel();
const purseP = E(assayP).makeEmptyPurse();
return Promise.all([assayP, extentOpsDescP, labelP, purseP]).then(
([assay, extentOpsDesc, label, purse]) => {
if (assayToAssayRecord.has(assay)) {
return assayToAssayRecord.get(assay);
}
const { name, extentOpsArgs = [] } = extentOpsDesc;
const extentOps = extentOpsLib[name](...extentOpsArgs);
assayToPurse.init(assay, purse);
return makeAssayRecord(assay, extentOps, label);
},
);
};
recordAssay: async assay => {
if (!assayToPurse.has(assay)) {
const unitOpsP = E(assay).getUnitOps();
const labelP = E(assay).getLabel();
const purseP = E(assay).makeEmptyPurse();
const extentOpsDescP = E(assay).getExtentOps();
const [unitOps, label, purse, extentOpsDesc] = await Promise.all([
unitOpsP,
labelP,
purseP,
extentOpsDescP,
]);
assayToDescOps.init(assay, unitOps);
assayToLabel.init(assay, label);
assayToPurse.init(assay, purse);
const { name, extentOpArgs = [] } = extentOpsDesc;
assayToExtentOps.init(assay, extentOpsLib[name](...extentOpArgs));
}
return harden({
recordAssay: async assay => {
if (!assayToPurse.has(assay)) {
const unitOpsP = E(assay).getUnitOps();
const labelP = E(assay).getLabel();
const purseP = E(assay).makeEmptyPurse();
const extentOpsDescP = E(assay).getExtentOps();
const [unitOps, label, purse, extentOpsDesc] = await Promise.all([
unitOpsP,
labelP,
purseP,
extentOpsDescP,
]);
assayToDescOps.init(assay, unitOps);
assayToLabel.init(assay, label);
assayToPurse.init(assay, purse);
const { name, extentOpArgs = [] } = extentOpsDesc;
assayToExtentOps.init(assay, extentOpsLib[name](...extentOpArgs));
}
return harden({
unitOps: assayToDescOps.get(assay),
recordAssay: async assay => {
if (!assayToPurse.has(assay)) {
const unitOpsP = E(assay).getUnitOps();
const labelP = E(assay).getLabel();
const purseP = E(assay).makeEmptyPurse();
const extentOpsDescP = E(assay).getExtentOps();
const [unitOps, label, purse, extentOpsDesc] = await Promise.all([
unitOpsP,
labelP,
purseP,
extentOpsDescP,
]);
assayToDescOps.init(assay, unitOps);
assayToLabel.init(assay, label);
assayToPurse.init(assay, purse);
const { name, extentOpArgs = [] } = extentOpsDesc;
assayToExtentOps.init(assay, extentOpsLib[name](...extentOpArgs));
}
const recordAssayLater = assayP => {
const extentOpsDescP = E(assayP).getExtentOps();
const labelP = E(assayP).getLabel();
const purseP = E(assayP).makeEmptyPurse();
return Promise.all([assayP, extentOpsDescP, labelP, purseP]).then(
([assay, extentOpsDesc, label, purse]) => {
if (assayToAssayRecord.has(assay)) {
return assayToAssayRecord.get(assay);
}
const { name, extentOpsArgs = [] } = extentOpsDesc;
const extentOps = extentOpsLib[name](...extentOpsArgs);
assayToPurse.init(assay, purse);
return makeAssayRecord(assay, extentOps, label);
},
);
};
row.map((units, i) => E(purses[i]).withdraw(units, 'payout')),
);