'use strict'; /* An open Internet exchange offer ran out of time: the escrow goes back to the POP. Payload { offerId }. Idempotent: acts only * while the offer is still open (accepted/cancelled offers cancel their own expiry event, this is the second line of defence). */ const T = require('../trade'); module.exports = function tradeExpire(ctx, ev) { const o = T.getOffer(ctx.db, ev.payload.offerId); if (!o || o.status !== 'open') return; const back = T.closeOffer(ctx, o, 'expired', ev.dueAt); const uid = T.userOfOperator(ctx.db, o.operator_id); if (uid) ctx.notify(uid, o.world_id, 'trade_expired', { offerId: o.id, townId: o.town_id, returned: { resource: o.give_res, amount: Math.round(back.credited) } }); };