import "../types/structs.scrypt"; import "txHashPreimageUtils.scrypt"; import "txUtils.scrypt"; import "stdUtils.scrypt"; struct _opcat_labs_scrypt_ts_opcat_4_0_0__rs__ChainTxVerifyResponse { bytes prevPrevScript; bytes prevPrevOutpoint; } library _opcat_labs_scrypt_ts_opcat_4_0_0__rs__Backtrace { static const bytes GENESIS_SCRIPT_HASH = b'6712360d7ad09ba9a59cd236aab61db7183c8d881c74ea029debd1f6b26711f8'; static function checkPrevTxHashPreimage(_opcat_labs_scrypt_ts_opcat_4_0_0__rs__TxHashPreimage txHashPreimage, bytes t_outpoint) : bool { bytes txHash = _opcat_labs_scrypt_ts_opcat_4_0_0__rs__TxHashPreimageUtils.getTxHashFromTxHashPreimage(txHashPreimage); require(txHash == t_outpoint[0 : 32]); return true; } static function verifyFromOutpoint(_opcat_labs_scrypt_ts_opcat_4_0_0__rs__BacktraceInfo backtraceInfo, int t_prevOutputIndex, bytes t_genesisOutpoint, bytes t_selfScript, bytes t_prevTxInputList) : bool { _opcat_labs_scrypt_ts_opcat_4_0_0__rs__ChainTxVerifyResponse res = _opcat_labs_scrypt_ts_opcat_4_0_0__rs__Backtrace.verifyChainTxs(backtraceInfo, t_prevTxInputList); if(res.prevPrevOutpoint == t_genesisOutpoint) { require(res.prevPrevScript == _opcat_labs_scrypt_ts_opcat_4_0_0__rs__Backtrace.GENESIS_SCRIPT_HASH); require(t_prevOutputIndex == 0); } require(res.prevPrevOutpoint == t_genesisOutpoint || res.prevPrevScript == t_selfScript); return true; } static function verifyFromScript(_opcat_labs_scrypt_ts_opcat_4_0_0__rs__BacktraceInfo backtraceInfo, bytes t_genesisScript, bytes t_selfScript, bytes t_prevTxInputList) : bool { _opcat_labs_scrypt_ts_opcat_4_0_0__rs__ChainTxVerifyResponse res = _opcat_labs_scrypt_ts_opcat_4_0_0__rs__Backtrace.verifyChainTxs(backtraceInfo, t_prevTxInputList); require(res.prevPrevScript == t_genesisScript || res.prevPrevScript == t_selfScript); return true; } static function verifyChainTxs(_opcat_labs_scrypt_ts_opcat_4_0_0__rs__BacktraceInfo backtraceInfo, bytes t_prevTxInputList) : _opcat_labs_scrypt_ts_opcat_4_0_0__rs__ChainTxVerifyResponse { require(t_prevTxInputList[backtraceInfo.prevTxInputIndex * 72 : (backtraceInfo.prevTxInputIndex + 1) * 72] == _opcat_labs_scrypt_ts_opcat_4_0_0__rs__TxUtils.mergeInput(backtraceInfo.prevTxInput)); bytes prevPrevTxHash = backtraceInfo.prevTxInput.prevTxHash; require(prevPrevTxHash == _opcat_labs_scrypt_ts_opcat_4_0_0__rs__TxHashPreimageUtils.getTxHashFromTxHashPreimage(backtraceInfo.prevPrevTxPreimage)); bytes prevPrevScript = backtraceInfo.prevPrevTxPreimage.outputList[backtraceInfo.prevTxInput.prevOutputIndex * 72 + 8 : (backtraceInfo.prevTxInput.prevOutputIndex) * 72 + 8 + 32]; bytes prevPrevOutpoint = prevPrevTxHash + _opcat_labs_scrypt_ts_opcat_4_0_0__rs__StdUtils.uint32ToByteString(backtraceInfo.prevTxInput.prevOutputIndex); return {prevPrevScript, prevPrevOutpoint}; } }