From 093635e9a8c750ecb8e5f93d321d94e5eb97e48f Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 30 Jan 2019 23:15:44 -1100 Subject: [PATCH] Initial validation skeleton --- src/cc/rewards.cpp | 2 +- src/cc/sudoku.cpp | 33 ++++++++++++++++++++++++++++++++- 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/src/cc/rewards.cpp b/src/cc/rewards.cpp index bd5a6d919..b9f4677be 100644 --- a/src/cc/rewards.cpp +++ b/src/cc/rewards.cpp @@ -203,7 +203,7 @@ bool RewardsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &t else { txid = tx.GetHash(); - if ( (funcid= DecodeRewardsOpRet(txid,tx.vout[numvouts-1].scriptPubKey,sbits,fundingtxid)) != 0 ) + if ( (funcid= DecodeRewardsOpRet(txid,tx.vout[numvouts-1].scriptPubKey,sbits,fundingtxid)) != 0 ) { if ( eval->GetTxUnconfirmed(fundingtxid,fundingTx,hashBlock) == 0 ) return eval->Invalid("cant find fundingtxid"); diff --git a/src/cc/sudoku.cpp b/src/cc/sudoku.cpp index 5968f59d9..9d52728a3 100644 --- a/src/cc/sudoku.cpp +++ b/src/cc/sudoku.cpp @@ -2909,5 +2909,36 @@ UniValue sudoku_solution(uint64_t txfee,struct CCcontract_info *cp,cJSON *params bool sudoku_validate(struct CCcontract_info *cp,int32_t height,Eval *eval,const CTransaction tx) { - return(true); + CScript scriptPubKey; std::vector vopret; uint8_t *script,e,f,funcid; int32_t score,numvouts; char unsolved[82]; + if ( (numvouts= tx.vout.size()) > 1 ) + { + scriptPubKey = tx.vout[numvouts-1].scriptPubKey; + GetOpReturnData(scriptPubKey,vopret); + if ( vopret.size() > 2 ) + { + script = (uint8_t *)vopret.data(); + if ( script[0] == EVAL_SUDOKU ) + { + switch ( script[1] ) + { + case 'G': + if ( sudoku_genopreturndecode(unsolved,scriptPubKey) == 'G' ) + { + if ( dupree_solver(&score,unsolved) != 1 || score*COIN != tx.vout[1].nValue ) + { + fprintf(stderr,"ht.%d score.%d vs %.8f %s\n",height,score,(double)tx.vout[1].nValue/COIN,tx.GetHash().ToString()); + } + } + return(true); + case 'S': + fprintf(stderr,"SOLVED ht.%d %.8f %s\n",height,score,(double)tx.vout[0].nValue/COIN,tx.GetHash().ToString()); + return(true); + default: return eval->Invalid("invalid funcid"); + } + } else return eval->Invalid("invalid evalcode"); + + } + } + return eval->Invalid("not enough vouts"); } +