Per-order terminal reorg linkage
This commit is contained in:
@@ -98,7 +98,8 @@ async function checkOrders(client: PoolClient, rows: OrderRow[]) {
|
||||
c(`customer:${o.seller}:available`, o.sellerAtomicXmr), c(`author:${o.authorAddress}`, o.authorAtomicXmr),
|
||||
c(o.hostFeeAddress ? `revenue:host:${o.hostFeeAddress}` : 'revenue:host', o.hostAtomicXmr)] : null);
|
||||
const evidenceRows = await client.query('SELECT key,value FROM wk_custody.custody_meta WHERE key=ANY($1::text[])',
|
||||
[[`sale-rehearsal-binding:${o.id}`, `sale-rehearsal-observation:${o.id}`, `sale-rehearsal-terminal:${o.id}`]]);
|
||||
[[`sale-rehearsal-binding:${o.id}`, `sale-rehearsal-observation:${o.id}`, `sale-rehearsal-terminal:${o.id}`,
|
||||
`sale-rehearsal-terminal-index:${o.id}`]]);
|
||||
if (evidenceRows.rowCount) {
|
||||
try {
|
||||
const records = new Map<string, string>(evidenceRows.rows.map(r => [r.key, r.value]));
|
||||
@@ -113,11 +114,24 @@ async function checkOrders(client: PoolClient, rows: OrderRow[]) {
|
||||
};
|
||||
verify(`sale-rehearsal-observation:${o.id}`);
|
||||
if (o.status === 'awaiting-lock') {
|
||||
if (records.has(`sale-rehearsal-terminal:${o.id}`)) fail('sale-rehearsal-evidence-mismatch');
|
||||
if (records.has(`sale-rehearsal-terminal:${o.id}`) || records.has(`sale-rehearsal-terminal-index:${o.id}`)) {
|
||||
fail('sale-rehearsal-evidence-mismatch');
|
||||
}
|
||||
} else {
|
||||
const replay = verify(`sale-rehearsal-terminal:${o.id}`);
|
||||
if (replay.decision.action !== (o.status === 'settled' ? 'settle' : 'refund') ||
|
||||
(o.status === 'settled' && row.box_data !== `fixture:${replay.stateRoot}`)) fail('sale-rehearsal-evidence-mismatch');
|
||||
const index = JSON.parse(records.get(`sale-rehearsal-terminal-index:${o.id}`) ?? '');
|
||||
if (index.version !== 1 || index.stateRoot !== replay.stateRoot ||
|
||||
index.terminalTransactionId !== (replay.terminalTransactionId ?? null)) fail('sale-rehearsal-evidence-mismatch');
|
||||
if (replay.terminalTransactionId) {
|
||||
const link = await client.query('SELECT value FROM wk_custody.custody_meta WHERE key=$1',
|
||||
[`sale-rehearsal-tx:${replay.terminalTransactionId}`]);
|
||||
const parsedLink = JSON.parse(link.rows[0]?.value ?? '');
|
||||
if (parsedLink.version !== 1 || parsedLink.orderId !== o.id || parsedLink.stateRoot !== replay.stateRoot) {
|
||||
fail('sale-rehearsal-terminal-index-mismatch');
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch { fail('sale-rehearsal-evidence-mismatch'); }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user