in src/GetDocumentHistory.ts [34:60]
export async function getDocumentRevisionByIdAndBlock(txn: TransactionExecutor, tableName: string, documentId: string, blockAddress: ValueHolder): Promise<dom.Value> {
const fcnName = "[GetDocumentHistory.getDocumentRevisionByIdAndBlock]"
const startTime: number = new Date().getTime();
try {
const blockAddressIon: dom.Value = dom.load(blockAddress.IonText);
const blockSequenceNo = blockAddressIon.get("sequenceNo");
validateTableNameConstrains(tableName);
const query = `SELECT * FROM history( ${tableName} ) AS h WHERE h.metadata.id = ? AND h.blockAddress.sequenceNo = ?`;
logger.debug(`${fcnName} Retrieving document values for Id: ${documentId} and Block Sequence Number: ${blockSequenceNo}`);
logger.debug(`${fcnName} Query statement: ${query}`);
const result: Result = await txn.execute(query, documentId, blockSequenceNo);
const endTime = new Date().getTime();
logger.debug(`${fcnName} Execution time: ${endTime - startTime}ms`)
const resultList: dom.Value[] = result.getResultList();
if (resultList.length === 0) {
throw new Error(`${fcnName} Unable to find document with Id: ${documentId} and Block Sequence Number: ${blockSequenceNo}`);
}
return resultList[0];
} catch (err) {
const endTime: number = new Date().getTime();
logger.debug(`${fcnName} Execution time: ${endTime - startTime}ms`)
throw err;
}
}