Per-order terminal reorg linkage
This commit is contained in:
@@ -3,7 +3,7 @@ import { ADDITIONAL_MARKET_FEE } from '../../shared/market.ts';
|
||||
import type { CustodyOrder } from '../../shared/custody.ts';
|
||||
import { saleTransactionSchema, saleTermsMessage } from '../../shared/sale-candidate.ts';
|
||||
import { applySaleBlock, initialSaleState, saleContext, saleDecision, saleId, saleStateRoot,
|
||||
termsForCustodyOrder, type SaleContext } from '../testnet/sale-candidate.ts';
|
||||
saleCandidateTransactionId, termsForCustodyOrder, type SaleContext } from '../testnet/sale-candidate.ts';
|
||||
import { sha256, verifySignature } from '../testnet/consensus.ts';
|
||||
|
||||
const height = z.number().int().min(0).max(1000000);
|
||||
@@ -71,14 +71,17 @@ export function replayReservedSale(order: CustodyOrder, custodianId: string, raw
|
||||
order.hostFeeAddress ?? ADDITIONAL_MARKET_FEE.address, binding]));
|
||||
let state = initialSaleState({ [order.cardHash]: { owner: order.seller, sequence: order.sequence,
|
||||
mintedHeight: input.seed.mintedHeight, pageId: input.seed.pageId } }, input.seed.height);
|
||||
let lockTransactionId: string | undefined, terminalTransactionId: string | undefined;
|
||||
for (const block of input.blocks) {
|
||||
for (const tx of block) {
|
||||
if (tx.type === 'sale-lock' ? saleId(tx.terms) !== saleId(terms) : tx.saleId !== saleId(terms)) throw new Error('Unrelated sale in rehearsal');
|
||||
if (tx.type === 'sale-complete' && tx.reservationDigest !== reservationDigest) throw new Error('Completion reservation commitment mismatch');
|
||||
if (tx.type === 'sale-lock') lockTransactionId = saleCandidateTransactionId(tx);
|
||||
else terminalTransactionId = saleCandidateTransactionId(tx);
|
||||
}
|
||||
state = applySaleBlock(state, block, context);
|
||||
}
|
||||
const previous = order.status === 'settled' ? 'settled' : order.status === 'cancelled' ? 'refunded' : 'reserved';
|
||||
return { input, binding, reservationDigest, stateRoot: saleStateRoot(state, context),
|
||||
return { input, binding, reservationDigest, lockTransactionId, terminalTransactionId, stateRoot: saleStateRoot(state, context),
|
||||
decision: saleDecision(state, terms, context, previous), context };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user