MCPcopy Create free account
hub / github.com/EvoMap/evolver / orderAndWait

Function orderAndWait

src/atp/consumerAgent.js:118–146  ·  view source on GitHub ↗

* Full order lifecycle: place -> wait -> verify -> settle. * @param {object} opts - same as orderService * @param {number} [opts.pollIntervalMs] - how often to check status (default 10s) * @param {number} [opts.timeoutMs] - max wait time (default 300s) * @returns {Promise<{ok: boolean, order?: o

(opts)

Source from the content-addressed store, hash-verified

116 * @returns {Promise<{ok: boolean, order?: object, finalStatus?: object, error?: string}>}
117 */
118async function orderAndWait(opts) {
119 const order = await orderService(opts);
120 if (!order.ok) return order;
121
122 const orderId = order.data.order_id;
123 const pollMs = opts.pollIntervalMs || 10000;
124 const timeoutMs = opts.timeoutMs || 300000;
125 const deadline = Date.now() + timeoutMs;
126
127 while (Date.now() < deadline) {
128 await new Promise(resolve => setTimeout(resolve, pollMs));
129
130 const status = await checkOrder(orderId);
131 if (!status.ok) continue;
132
133 const proofStatus = status.data.proof_status;
134 if (proofStatus === 'settled') {
135 return { ok: true, order: order.data, finalStatus: status.data };
136 }
137 if (proofStatus === 'verified' && order.data.verify_mode === 'auto') {
138 return { ok: true, order: order.data, finalStatus: status.data };
139 }
140 if (proofStatus === 'disputed') {
141 return { ok: false, order: order.data, finalStatus: status.data, error: 'order_disputed' };
142 }
143 }
144
145 return { ok: false, order: order.data, error: 'order_timeout' };
146}
147
148module.exports = {
149 orderService,

Callers

nothing calls this directly

Calls 2

orderServiceFunction · 0.85
checkOrderFunction · 0.85

Tested by

no test coverage detected