import "cat20Proto.scrypt";import "openMinterV2Proto.scrypt";import "../utils/stateUtils.scrypt";import "../utils/backtrace.scrypt";import "../utils/sigHashUtils.scrypt";import "../utils/txUtil.scrypt"; contract OpenMinterV2 { bytes genesisOutpoint; int maxCount; int premine; int premineCount; int limit; bytes premineAddr; public function mint(bytes[5] curTxoStateHashes, CAT20State tokenMint, int[2] nextMinterCounts, bytes preminerPubKeyPrefix, PubKey preminerPubKey, Sig preminerSig, bytes minterSatoshis, bytes tokenSatoshis, OpenMinterV2State preState, PreTxStatesInfo preTxStatesInfo, BacktraceInfo backtraceInfo, SHPreimage shPreimage, PrevoutsCtx prevoutsCtx, bytes[6] spentScriptsCtx, ChangeInfo changeInfo) { require(checkSig(SigHashUtils.checkSHPreimage(shPreimage), SigHashUtils.Gx)); SigHashUtils.checkPrevoutsCtx(prevoutsCtx, shPreimage.hashPrevouts, shPreimage.inputIndex); SigHashUtils.checkSpentScriptsCtx(spentScriptsCtx, shPreimage.hashSpentScripts); StateUtils.verifyPreStateHash(preTxStatesInfo, OpenMinterV2Proto.stateHash(preState), backtraceInfo.preTx.outputScriptList[0], prevoutsCtx.outputIndexVal); bytes preScript = spentScriptsCtx[(prevoutsCtx.inputIndexVal)]; Backtrace.verifyUnique(prevoutsCtx.spentTxhash, backtraceInfo, this.genesisOutpoint, preScript); bytes openMinterOutputs = b''; bytes curStateHashes = b''; int curStateCnt = 1; int mintCount = 0; loop (2) : i { int count = nextMinterCounts[i]; if(count > 0) { mintCount += count; curStateCnt += 1; openMinterOutputs += TxUtil.buildOutput(preScript, minterSatoshis); curStateHashes += hash160(OpenMinterV2Proto.stateHash({preState.tokenScript, true, count})); } } curStateHashes += hash160(CAT20Proto.stateHash({tokenMint.ownerAddr, tokenMint.amount})); bytes tokenOutput = TxUtil.buildOutput(preState.tokenScript, tokenSatoshis); if(!preState.isPremined && this.premine > 0) { require(hash160(preminerPubKeyPrefix + preminerPubKey) == this.premineAddr); require(checkSig(preminerSig, preminerPubKey)); require(mintCount == preState.remainingSupplyCount); require(this.maxCount == preState.remainingSupplyCount + this.premineCount); require(tokenMint.amount == this.premine); } else { mintCount += 1; require(mintCount == preState.remainingSupplyCount); require(tokenMint.amount == this.limit); } bytes stateOutput = StateUtils.getCurrentStateOutput(curStateHashes, curStateCnt, curTxoStateHashes); bytes changeOutput = TxUtil.getChangeOutput(changeInfo); Sha256 hashOutputs = sha256(stateOutput + openMinterOutputs + tokenOutput + changeOutput); require(hashOutputs == shPreimage.hashOutputs); } }