From 5b6a65f30a86e816166351e1c1292b8e37cfcf75 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 10 Jan 2019 07:30:00 -1100 Subject: [PATCH 001/110] -prints --- src/wallet/rpcwallet.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 6e5bc5b83..79710969a 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -2979,7 +2979,7 @@ UniValue z_listunspent(const UniValue& params, bool fHelp) BlockMap::const_iterator it = mapBlockIndex.find(hashBlock); if (it != mapBlockIndex.end()) { nHeight = it->second->GetHeight(); - fprintf(stderr,"blockHash %s height %d\n",hashBlock.ToString().c_str(), nHeight); + //fprintf(stderr,"blockHash %s height %d\n",hashBlock.ToString().c_str(), nHeight); } else { // TODO: should we throw JSONRPCError ? fprintf(stderr,"block hash %s does not exist!\n", hashBlock.ToString().c_str() ); @@ -3013,7 +3013,7 @@ UniValue z_listunspent(const UniValue& params, bool fHelp) BlockMap::const_iterator it = mapBlockIndex.find(hashBlock); if (it != mapBlockIndex.end()) { nHeight = it->second->GetHeight(); - fprintf(stderr,"blockHash %s height %d\n",hashBlock.ToString().c_str(), nHeight); + //fprintf(stderr,"blockHash %s height %d\n",hashBlock.ToString().c_str(), nHeight); } else { // TODO: should we throw JSONRPCError ? fprintf(stderr,"block hash %s does not exist!\n", hashBlock.ToString().c_str() ); @@ -3804,7 +3804,7 @@ UniValue z_listreceivedbyaddress(const UniValue& params, bool fHelp) BlockMap::const_iterator it = mapBlockIndex.find(hashBlock); if (it != mapBlockIndex.end()) { nHeight = it->second->GetHeight(); - fprintf(stderr,"blockHash %s height %d\n",hashBlock.ToString().c_str(), nHeight); + //fprintf(stderr,"blockHash %s height %d\n",hashBlock.ToString().c_str(), nHeight); } else { fprintf(stderr,"block hash %s does not exist!\n", hashBlock.ToString().c_str() ); } @@ -3836,7 +3836,7 @@ UniValue z_listreceivedbyaddress(const UniValue& params, bool fHelp) BlockMap::const_iterator it = mapBlockIndex.find(hashBlock); if (it != mapBlockIndex.end()) { nHeight = it->second->GetHeight(); - fprintf(stderr,"blockHash %s height %d\n",hashBlock.ToString().c_str(), nHeight); + //fprintf(stderr,"blockHash %s height %d\n",hashBlock.ToString().c_str(), nHeight); } else { fprintf(stderr,"block hash %s does not exist!\n", hashBlock.ToString().c_str() ); } From 9392a2b9ecbbd3f2c802df817eb56cfa1e1b1081 Mon Sep 17 00:00:00 2001 From: Anton Lysakov Date: Sat, 12 Jan 2019 15:27:17 +0700 Subject: [PATCH 002/110] oracles autotests fixed --- qa/rpc-tests/cryptoconditions_oracles.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/qa/rpc-tests/cryptoconditions_oracles.py b/qa/rpc-tests/cryptoconditions_oracles.py index f295bf020..048b577d1 100755 --- a/qa/rpc-tests/cryptoconditions_oracles.py +++ b/qa/rpc-tests/cryptoconditions_oracles.py @@ -112,17 +112,15 @@ class CryptoconditionsOraclesTest(CryptoconditionsTestFramework): # baton oraclesdata_d = self.send_and_mine(result["hex"], rpc) result = rpc.oraclessamples(globals()["oracle_{}".format("d")], oraclesdata_d, "1") - # TODO: working not correct now! - #assert_equal("[u'01']", str(result["samples"][0]), "Data match") + assert_equal("[u'01']", str(result["samples"][0]), "Data match") # D type - result = rpc.oraclesdata(globals()["oracle_{}".format("D")], "0101") + result = rpc.oraclesdata(globals()["oracle_{}".format("D")], "010001") assert_success(result) # baton oraclesdata_D = self.send_and_mine(result["hex"], rpc) result = rpc.oraclessamples(globals()["oracle_{}".format("D")], oraclesdata_D, "1") - # TODO: working not correct now! - #assert_equal("[u'01']", str(result["samples"][0]), "Data match") + assert_equal("[u'01']", str(result["samples"][0]), "Data match") # c type result = rpc.oraclesdata(globals()["oracle_{}".format("c")], "ff") @@ -198,12 +196,12 @@ class CryptoconditionsOraclesTest(CryptoconditionsTestFramework): assert_equal("[u'ffffffff00000000ffffffff00000000ffffffff00000000ffffffff00000000']", str(result["samples"][0]), "Data match") # Ihh type - result = rpc.oraclesdata(globals()["oracle_{}".format("Ihh")], "00000000ffffffff00000000ffffffff00000000ffffffff00000000ffffffff") + result = rpc.oraclesdata(globals()["oracle_{}".format("Ihh")], "ffffffff00000000ffffffff00000000ffffffff00000000ffffffff00000000ffffffff00000000ffffffff00000000ffffffff00000000ffffffff00000000ffffffff") assert_success(result) # baton oraclesdata_Ihh = self.send_and_mine(result["hex"], rpc) result = rpc.oraclessamples(globals()["oracle_{}".format("Ihh")], oraclesdata_Ihh, "1") - assert_equal("[u'0']", str(result["samples"][0]), "Data match") + assert_equal("[u'4294967295', u'ffffffff00000000ffffffff00000000ffffffff00000000ffffffff00000000', u'ffffffff00000000ffffffff00000000ffffffff00000000ffffffff00000000']", str(result["samples"][0]), "Data match") def run_test(self): From 2bde89c9ce4b3ae6d068a47bc3e2d43c070d829e Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 00:29:37 -1100 Subject: [PATCH 003/110] Marmara coinbase initial impl --- src/cc/CCMarmara.h | 5 ++++ src/cc/marmara.cpp | 64 ++++++++++++++++++++++++++++++++++++++++++++ src/chainparams.cpp | 2 +- src/komodo_gateway.h | 10 +++++++ src/komodo_globals.h | 2 +- src/komodo_utils.h | 5 +++- 6 files changed, 85 insertions(+), 3 deletions(-) diff --git a/src/cc/CCMarmara.h b/src/cc/CCMarmara.h index 45fda83bd..5fc7fd673 100644 --- a/src/cc/CCMarmara.h +++ b/src/cc/CCMarmara.h @@ -19,6 +19,11 @@ #include "CCinclude.h" +#define MARMARA_GROUPSIZE 60 +#define MARMARA_MINLOCK (1440 * 3 * 30) +#define MARMARA_MAXLOCK (1440 * 24 * 30) +uint64_t komodo_block_prg(uint32_t nHeight); + bool MarmaraValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); // CCcustom diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 4bbccee4a..0f166e5df 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -71,6 +71,70 @@ bool MarmaraExactAmounts(struct CCcontract_info *cp,Eval* eval,const CTransactio else return(true); } +int32_t MarmaraRandomize(uint32_t ind) +{ + uint64_t val64; uint32_t val,range = (MARMARA_MAXLOCK - MARMARA_MINLOCK); + val64 = komodo_block_prg(ind); + val = (uint32_t)(val64 >> 32); + val ^= (uint32_t)val64; + return(val % range); +} + +int32_t MarmaraUnlockht(int32_t height) +{ + uint32_t ind = height / MARMARA_GROUPSIZE; + return(height + MarmaraRandomize(ind)); +} + +CScript EncodeMarmaraCoinbaseOpRet(CPubKey pk,int32_t height) +{ + CScript opret; int32_t unlockht; uint8_t evalcode = EVAL_ORACLES; + unlockht = MarmaraUnlockht(ht); + opret << OP_RETURN << E_MARSHAL(ss << evalcode << 'C' << pk << height << unlockht); + return(opret); +} + +uint8_t DecodeMaramaraCoinbaseOpRet(const CScript &scriptPubKey,CPubKey &pk,int32_t &height,int32_t &unlckht) +{ + std::vector vopret; uint8_t *script,e,f,funcid; + GetOpReturnData(scriptPubKey,vopret); + script = (uint8_t *)vopret.data(); + if ( vopret.size() > 2 && script[0] == EVAL_MARMARA ) + { + if ( script[1] == 'C' ) + { + if ( E_UNMARSHAL(vopret,ss >> e; ss >> f; ss >> pk; ss >> height; ss >> unlockht) != 0 ) + { + return(script[1]); + } else fprintf(stderr,"DecodeMaramaraCoinbaseOpRet unmarshal error for C\n"); + } + } + return(0); +} + +int32_t MarmaraValidateCoinbase(int32_t height,CTransaction tx) +{ + struct CCcontract_info *cp,C; CPubKey pk; int32_t ht,unlockht; CTxOut ccvout; + cp = CCinit(&C,EVAL_MARMARA); + for (ht=0; ht<10000; ht+=MARMARA_GROUPSIZE/3) + fprintf(stderr,"%d ",MarmaraUnlockht(ht)); + fprintf(stderr,"<- unlock hts\n"); + if ( tx.vout.size() == 2 && tx.vout[1].nValue == 0 ) + { + if ( DecodeMaramaraCoinbaseOpRet(tx.vout[1].scriptPubKey,pk,ht,unlockht) == 'C' ) + { + if ( ht == height && MarmaraUnlockht(height) == unlockht ) + { + ccvout = MakeCC1vout(EVAL_MARMARA,0,pk); + if ( ccvout.scriptPubKey == tx.vout[0].scriptPubKey ) + return(0); + fprintf(stderr,"ht.%d mismatched CCvout scriptPubKey\n",height); + } else fprintf(stderr,"ht.%d %d vs %d unlock.%d\n",height,MarmaraUnlockht(height),ht,unlockht); + } else fprintf(stderr,"ht.%d error decoding coinbase opret\n"); + } + return(-1); +} + bool MarmaraValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn) { int32_t numvins,numvouts,preventCCvins,preventCCvouts,i,numblocks; bool retval; uint256 txid; uint8_t hash[32]; char str[65],destaddr[64]; diff --git a/src/chainparams.cpp b/src/chainparams.cpp index 23d900d4e..47f4d48a8 100644 --- a/src/chainparams.cpp +++ b/src/chainparams.cpp @@ -107,7 +107,7 @@ public: strNetworkID = "main"; strCurrencyUnits = "KMD"; - bip44CoinType = 141; // As registered in https://github.com/satoshilabs/slips/blob/master/slip-0044.md (ZCASH, should be VRSC) + bip44CoinType = 141; // As registered in https://github.com/satoshilabs/slips/blob/master/slip-0044.md consensus.fCoinbaseMustBeProtected = false; // true this is only true wuth Verus and enforced after block 12800 consensus.nSubsidySlowStartInterval = 20000; consensus.nSubsidyHalvingInterval = 840000; diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 982f16b0b..360ddfcc0 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -16,6 +16,8 @@ // paxdeposit equivalent in reverse makes opreturn and KMD does the same in reverse #include "komodo_defs.h" +int32_t MarmaraValidateCoinbase(int32_t height,CTransaction tx); + int32_t pax_fiatstatus(uint64_t *available,uint64_t *deposited,uint64_t *issued,uint64_t *withdrawn,uint64_t *approved,uint64_t *redeemed,char *base) { int32_t baseid; struct komodo_state *sp; int64_t netliability,maxallowed,maxval; @@ -687,6 +689,14 @@ int32_t komodo_check_deposit(int32_t height,const CBlock& block,uint32_t prevtim } } } + if ( ASSETCHAINS_MARMARA != 0 && (height & 1) != 0 ) + { + if ( MarmaraValidateCoinbase(height,block.vtx[0]) < 0 ) + { + fprintf(stderr,"MARMARA constrains odd height blocks to pay 100% to CC in vout0\n"); + return(-1); + } + } // we don't want these checks in VRSC, leave it at the Sapling upgrade if ( ASSETCHAINS_SYMBOL[0] == 0 || (ASSETCHAINS_COMMISSION != 0 && height > 1) || diff --git a/src/komodo_globals.h b/src/komodo_globals.h index 8a72b5ad7..f434674b7 100644 --- a/src/komodo_globals.h +++ b/src/komodo_globals.h @@ -49,7 +49,7 @@ unsigned int WITNESS_CACHE_SIZE = _COINBASE_MATURITY+10; int32_t KOMODO_MININGTHREADS = -1,IS_KOMODO_NOTARY,USE_EXTERNAL_PUBKEY,KOMODO_CHOSEN_ONE,ASSETCHAINS_SEED,KOMODO_ON_DEMAND,KOMODO_EXTERNAL_NOTARIES,KOMODO_PASSPORT_INITDONE,KOMODO_PAX,KOMODO_EXCHANGEWALLET,KOMODO_REWIND,KOMODO_CONNECTING = -1,KOMODO_DEALERNODE,KOMODO_EXTRASATOSHI,ASSETCHAINS_FOUNDERS; int32_t KOMODO_INSYNC,KOMODO_LASTMINED,prevKOMODO_LASTMINED,KOMODO_CCACTIVATE,JUMBLR_PAUSE = 1; std::string NOTARY_PUBKEY,ASSETCHAINS_NOTARIES,ASSETCHAINS_OVERRIDE_PUBKEY,DONATION_PUBKEY,ASSETCHAINS_SCRIPTPUB,ASSETCHAINS_SELFIMPORT; -uint8_t NOTARY_PUBKEY33[33],ASSETCHAINS_OVERRIDE_PUBKEY33[33],ASSETCHAINS_OVERRIDE_PUBKEYHASH[20],ASSETCHAINS_PUBLIC,ASSETCHAINS_PRIVATE,ASSETCHAINS_TXPOW; +uint8_t NOTARY_PUBKEY33[33],ASSETCHAINS_OVERRIDE_PUBKEY33[33],ASSETCHAINS_OVERRIDE_PUBKEYHASH[20],ASSETCHAINS_PUBLIC,ASSETCHAINS_PRIVATE,ASSETCHAINS_TXPOW,ASSETCHAINS_MARMARA; bool VERUS_MINTBLOCKS; char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN],ASSETCHAINS_USERPASS[4096]; diff --git a/src/komodo_utils.h b/src/komodo_utils.h index a5b22e592..55b9bec35 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1778,6 +1778,7 @@ void komodo_args(char *argv0) ASSETCHAINS_SCRIPTPUB = GetArg("-ac_script",""); ASSETCHAINS_BEAMPORT = GetArg("-ac_beam",0); ASSETCHAINS_CODAPORT = GetArg("-ac_coda",0); + ASSETCHAINS_MARMARA = GetArg("-ac_marmara",0); if ( ASSETCHAINS_BEAMPORT != 0 && ASSETCHAINS_CODAPORT != 0 ) { fprintf(stderr,"can only have one of -ac_beam or -ac_coda\n"); @@ -1857,7 +1858,7 @@ void komodo_args(char *argv0) printf("ASSETCHAINS_FOUNDERS needs an ASETCHAINS_OVERRIDE_PUBKEY\n"); } } - if ( ASSETCHAINS_ENDSUBSIDY[0] != 0 || ASSETCHAINS_REWARD[0] != 0 || ASSETCHAINS_HALVING[0] != 0 || ASSETCHAINS_DECAY[0] != 0 || ASSETCHAINS_COMMISSION != 0 || ASSETCHAINS_PUBLIC != 0 || ASSETCHAINS_PRIVATE != 0 || ASSETCHAINS_TXPOW != 0 || ASSETCHAINS_FOUNDERS != 0 || ASSETCHAINS_SCRIPTPUB.size() > 1 || ASSETCHAINS_SELFIMPORT.size() > 0 || ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 || ASSETCHAINS_TIMELOCKGTE != _ASSETCHAINS_TIMELOCKOFF|| ASSETCHAINS_ALGO != ASSETCHAINS_EQUIHASH || ASSETCHAINS_LWMAPOS != 0 || ASSETCHAINS_LASTERA > 0 || ASSETCHAINS_BEAMPORT != 0 || ASSETCHAINS_CODAPORT != 0 ) + if ( ASSETCHAINS_ENDSUBSIDY[0] != 0 || ASSETCHAINS_REWARD[0] != 0 || ASSETCHAINS_HALVING[0] != 0 || ASSETCHAINS_DECAY[0] != 0 || ASSETCHAINS_COMMISSION != 0 || ASSETCHAINS_PUBLIC != 0 || ASSETCHAINS_PRIVATE != 0 || ASSETCHAINS_TXPOW != 0 || ASSETCHAINS_FOUNDERS != 0 || ASSETCHAINS_SCRIPTPUB.size() > 1 || ASSETCHAINS_SELFIMPORT.size() > 0 || ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 || ASSETCHAINS_TIMELOCKGTE != _ASSETCHAINS_TIMELOCKOFF|| ASSETCHAINS_ALGO != ASSETCHAINS_EQUIHASH || ASSETCHAINS_LWMAPOS != 0 || ASSETCHAINS_LASTERA > 0 || ASSETCHAINS_BEAMPORT != 0 || ASSETCHAINS_CODAPORT != 0 || ASSETCHAINS_MARMARA != 0 ) { fprintf(stderr,"perc %.4f%% ac_pub=[%02x%02x%02x...] acsize.%d\n",dstr(ASSETCHAINS_COMMISSION)*100,ASSETCHAINS_OVERRIDE_PUBKEY33[0],ASSETCHAINS_OVERRIDE_PUBKEY33[1],ASSETCHAINS_OVERRIDE_PUBKEY33[2],(int32_t)ASSETCHAINS_SCRIPTPUB.size()); extraptr = extrabuf; @@ -1931,6 +1932,8 @@ void komodo_args(char *argv0) extraptr[extralen++] = 'b'; if ( ASSETCHAINS_CODAPORT != 0 ) extraptr[extralen++] = 'c'; + if ( ASSETCHAINS_MARMARA != 0 ) + extraptr[extralen++] = ASSETCHAINS_MARMARA; } addn = GetArg("-seednode",""); From 2515d72e58e6d8606344476da150cd43c0e3447b Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 00:32:20 -1100 Subject: [PATCH 004/110] Syntax --- src/cc/marmara.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 0f166e5df..1a67b4df6 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -86,15 +86,15 @@ int32_t MarmaraUnlockht(int32_t height) return(height + MarmaraRandomize(ind)); } -CScript EncodeMarmaraCoinbaseOpRet(CPubKey pk,int32_t height) +CScript EncodeMarmaraCoinbaseOpRet(CPubKey pk,int32_t ht) { CScript opret; int32_t unlockht; uint8_t evalcode = EVAL_ORACLES; unlockht = MarmaraUnlockht(ht); - opret << OP_RETURN << E_MARSHAL(ss << evalcode << 'C' << pk << height << unlockht); + opret << OP_RETURN << E_MARSHAL(ss << evalcode << 'C' << pk << ht << unlockht); return(opret); } -uint8_t DecodeMaramaraCoinbaseOpRet(const CScript &scriptPubKey,CPubKey &pk,int32_t &height,int32_t &unlckht) +uint8_t DecodeMaramaraCoinbaseOpRet(const CScript &scriptPubKey,CPubKey &pk,int32_t &height,int32_t &unlockht) { std::vector vopret; uint8_t *script,e,f,funcid; GetOpReturnData(scriptPubKey,vopret); @@ -130,7 +130,7 @@ int32_t MarmaraValidateCoinbase(int32_t height,CTransaction tx) return(0); fprintf(stderr,"ht.%d mismatched CCvout scriptPubKey\n",height); } else fprintf(stderr,"ht.%d %d vs %d unlock.%d\n",height,MarmaraUnlockht(height),ht,unlockht); - } else fprintf(stderr,"ht.%d error decoding coinbase opret\n"); + } else fprintf(stderr,"ht.%d error decoding coinbase opret\n",height); } return(-1); } From 99f0709686d756806394ef7fd07472529d1ab1f8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 00:34:24 -1100 Subject: [PATCH 005/110] Fix --- src/komodo_gateway.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 360ddfcc0..0ad1b66ad 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -693,7 +693,7 @@ int32_t komodo_check_deposit(int32_t height,const CBlock& block,uint32_t prevtim { if ( MarmaraValidateCoinbase(height,block.vtx[0]) < 0 ) { - fprintf(stderr,"MARMARA constrains odd height blocks to pay 100% to CC in vout0\n"); + fprintf(stderr,"MARMARA constrains odd height blocks to pay 100%% to CC in vout0 with opreturn\n"); return(-1); } } From c0a9c015adcc209562af07492d9f7bc4b097d0d1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 00:37:41 -1100 Subject: [PATCH 006/110] Even heights with constraint so ac_supply is unlocked --- src/cc/marmara.cpp | 2 ++ src/komodo_gateway.h | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 1a67b4df6..359092ef9 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -119,6 +119,8 @@ int32_t MarmaraValidateCoinbase(int32_t height,CTransaction tx) for (ht=0; ht<10000; ht+=MARMARA_GROUPSIZE/3) fprintf(stderr,"%d ",MarmaraUnlockht(ht)); fprintf(stderr,"<- unlock hts\n"); + if ( (height & 1) != 0 ) + return(0); if ( tx.vout.size() == 2 && tx.vout[1].nValue == 0 ) { if ( DecodeMaramaraCoinbaseOpRet(tx.vout[1].scriptPubKey,pk,ht,unlockht) == 'C' ) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 0ad1b66ad..fcdf4b85e 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -689,11 +689,11 @@ int32_t komodo_check_deposit(int32_t height,const CBlock& block,uint32_t prevtim } } } - if ( ASSETCHAINS_MARMARA != 0 && (height & 1) != 0 ) + if ( height > 0 && ASSETCHAINS_MARMARA != 0 && (height & 1) == 0 ) { if ( MarmaraValidateCoinbase(height,block.vtx[0]) < 0 ) { - fprintf(stderr,"MARMARA constrains odd height blocks to pay 100%% to CC in vout0 with opreturn\n"); + fprintf(stderr,"MARMARA constrains even height blocks to pay 100%% to CC in vout0 with opreturn\n"); return(-1); } } From 5435d63aedd64fa8eb3abdf11d5872bdbe8331c6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 00:57:16 -1100 Subject: [PATCH 007/110] Histogram --- src/cc/marmara.cpp | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 359092ef9..908e3557d 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -116,9 +116,18 @@ int32_t MarmaraValidateCoinbase(int32_t height,CTransaction tx) { struct CCcontract_info *cp,C; CPubKey pk; int32_t ht,unlockht; CTxOut ccvout; cp = CCinit(&C,EVAL_MARMARA); - for (ht=0; ht<10000; ht+=MARMARA_GROUPSIZE/3) - fprintf(stderr,"%d ",MarmaraUnlockht(ht)); - fprintf(stderr,"<- unlock hts\n"); + int32_t d,histo[365*2]; + for (ht=2; ht<1000000; ht+=MARMARA_GROUPSIZE) + { + memset(histo,0,sizeof(histo)); + d = (MarmaraUnlockht(ht) - ht) / 1440 + if ( d < 0 || d > sizeof(histo)/sizeof(*histo) ) + fprintf(stderr,"d error.%d at ht.%d\n",d,ht); + else histo[d]++; + } + for (ht=0; ht Date: Sat, 12 Jan 2019 00:57:55 -1100 Subject: [PATCH 008/110] ; --- src/cc/marmara.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 908e3557d..254b62efd 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -120,7 +120,7 @@ int32_t MarmaraValidateCoinbase(int32_t height,CTransaction tx) for (ht=2; ht<1000000; ht+=MARMARA_GROUPSIZE) { memset(histo,0,sizeof(histo)); - d = (MarmaraUnlockht(ht) - ht) / 1440 + d = (MarmaraUnlockht(ht) - ht) / 1440; if ( d < 0 || d > sizeof(histo)/sizeof(*histo) ) fprintf(stderr,"d error.%d at ht.%d\n",d,ht); else histo[d]++; From f816960557f9fe8e868bad5733372adf5023dc72 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 01:00:08 -1100 Subject: [PATCH 009/110] memset Outside loop --- src/cc/marmara.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 254b62efd..389ed0227 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -117,9 +117,9 @@ int32_t MarmaraValidateCoinbase(int32_t height,CTransaction tx) struct CCcontract_info *cp,C; CPubKey pk; int32_t ht,unlockht; CTxOut ccvout; cp = CCinit(&C,EVAL_MARMARA); int32_t d,histo[365*2]; + memset(histo,0,sizeof(histo)); for (ht=2; ht<1000000; ht+=MARMARA_GROUPSIZE) { - memset(histo,0,sizeof(histo)); d = (MarmaraUnlockht(ht) - ht) / 1440; if ( d < 0 || d > sizeof(histo)/sizeof(*histo) ) fprintf(stderr,"d error.%d at ht.%d\n",d,ht); @@ -127,7 +127,7 @@ int32_t MarmaraValidateCoinbase(int32_t height,CTransaction tx) } for (ht=0; ht Date: Sat, 12 Jan 2019 01:03:22 -1100 Subject: [PATCH 010/110] += MARMARA_MINLOCK --- src/cc/marmara.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 389ed0227..dadbb9249 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -77,7 +77,7 @@ int32_t MarmaraRandomize(uint32_t ind) val64 = komodo_block_prg(ind); val = (uint32_t)(val64 >> 32); val ^= (uint32_t)val64; - return(val % range); + return((val % range) + MARMARA_MINLOCK); } int32_t MarmaraUnlockht(int32_t height) @@ -116,7 +116,7 @@ int32_t MarmaraValidateCoinbase(int32_t height,CTransaction tx) { struct CCcontract_info *cp,C; CPubKey pk; int32_t ht,unlockht; CTxOut ccvout; cp = CCinit(&C,EVAL_MARMARA); - int32_t d,histo[365*2]; + int32_t d,histo[365*2+30]; memset(histo,0,sizeof(histo)); for (ht=2; ht<1000000; ht+=MARMARA_GROUPSIZE) { From 9e55c207256cf83cc98aaa6c792ebb51ac2450d8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 01:08:17 -1100 Subject: [PATCH 011/110] -print --- src/cc/marmara.cpp | 23 +++++++++++++---------- src/komodo_gateway.h | 2 +- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index dadbb9249..8cfd6f6de 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -116,18 +116,21 @@ int32_t MarmaraValidateCoinbase(int32_t height,CTransaction tx) { struct CCcontract_info *cp,C; CPubKey pk; int32_t ht,unlockht; CTxOut ccvout; cp = CCinit(&C,EVAL_MARMARA); - int32_t d,histo[365*2+30]; - memset(histo,0,sizeof(histo)); - for (ht=2; ht<1000000; ht+=MARMARA_GROUPSIZE) + if ( 0 ) { - d = (MarmaraUnlockht(ht) - ht) / 1440; - if ( d < 0 || d > sizeof(histo)/sizeof(*histo) ) - fprintf(stderr,"d error.%d at ht.%d\n",d,ht); - else histo[d]++; + int32_t d,histo[365*2+30]; + memset(histo,0,sizeof(histo)); + for (ht=2; ht<1000000; ht+=MARMARA_GROUPSIZE) + { + d = (MarmaraUnlockht(ht) - ht) / 1440; + if ( d < 0 || d > sizeof(histo)/sizeof(*histo) ) + fprintf(stderr,"d error.%d at ht.%d\n",d,ht); + else histo[d]++; + } + for (ht=0; ht Date: Sat, 12 Jan 2019 01:36:01 -1100 Subject: [PATCH 012/110] Marmara coinbase opret --- src/cc/marmara.cpp | 29 +++++++++++++++++++++++++++++ src/miner.cpp | 14 ++++++++++++-- 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 8cfd6f6de..a7e9f2d1f 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -112,6 +112,35 @@ uint8_t DecodeMaramaraCoinbaseOpRet(const CScript &scriptPubKey,CPubKey &pk,int3 return(0); } +CScript Marmara_scriptPubKey(int32_t height,CScript scriptPubKey) +{ + CTxOut ccvout; uint8_t *ptr; CPubKey pk; + if ( height > 0 && ASSETCHAINS_MARMARA != 0 && (height & 1) == 0 && scriptPubKey.size() == 35 ) + { + ptr = (uint8_t *)pubkey.begin(); + if ( ptr[0] == 33 && ptr[34] == OP_CHECKSIG ) + pk = buf2pk(ptr+1); + ccvout = MakeCC1vout(EVAL_MARMARA,0,pk); + return(ccvout.scriptPubKey); + } + return(scriptPubKey); +} + +CScript MarmaraCoinbaseOpret(int32_t height,CScript scriptPubKey) +{ + uint8_t *ptr; CPubKey pk; + if ( height > 0 && (height & 1) == 0 && scriptPubKey.size() == 35 ) + { + ptr = (uint8_t *)pubkey.begin(); + if ( ptr[0] == 33 && ptr[34] == OP_CHECKSIG ) + { + pk = buf2pk(ptr+1); + return(EncodeMarmaraCoinbaseOpRet(pk,height); + } + } + return(scriptPubKey); +} + int32_t MarmaraValidateCoinbase(int32_t height,CTransaction tx) { struct CCcontract_info *cp,C; CPubKey pk; int32_t ht,unlockht; CTxOut ccvout; diff --git a/src/miner.cpp b/src/miner.cpp index 7948fd0cd..223972c80 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -141,7 +141,7 @@ extern char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN]; extern std::string NOTARY_PUBKEY,ASSETCHAINS_OVERRIDE_PUBKEY,ASSETCHAINS_SCRIPTPUB; void vcalc_sha256(char deprecated[(256 >> 3) * 2 + 1],uint8_t hash[256 >> 3],uint8_t *src,int32_t len); -extern uint8_t NOTARY_PUBKEY33[33],ASSETCHAINS_OVERRIDE_PUBKEY33[33]; +extern uint8_t NOTARY_PUBKEY33[33],ASSETCHAINS_OVERRIDE_PUBKEY33[33],ASSETCHAINS_MARMARA; uint32_t Mining_start,Mining_height; int32_t My_notaryid = -1; int32_t komodo_chosennotary(int32_t *notaryidp,int32_t height,uint8_t *pubkey33,uint32_t timestamp); @@ -155,6 +155,8 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt int32_t verus_staked(CBlock *pBlock, CMutableTransaction &txNew, uint32_t &nBits, arith_uint256 &hashResult, uint8_t *utxosig, CPubKey &pk); int32_t komodo_notaryvin(CMutableTransaction &txNew,uint8_t *notarypub33); int32_t decode_hex(uint8_t *bytes,int32_t n,char *hex); +CScript Marmara_scriptPubKey(int32_t height,CScript scriptPubKey); +CScript MarmaraCoinbaseOpret(int32_t height,CScript scriptPubKey); CBlockTemplate* CreateNewBlock(const CScript& _scriptPubKeyIn, int32_t gpucount, bool isStake) { @@ -534,7 +536,13 @@ CBlockTemplate* CreateNewBlock(const CScript& _scriptPubKeyIn, int32_t gpucount, // check if coinbase transactions must be time locked at current subsidy and prepend the time lock // to transaction if so, cast for GTE operator - if ((uint64_t)(txNew.vout[0].nValue) >= ASSETCHAINS_TIMELOCKGTE) + if ( ASSETCHAINS_MARMARA != 0 && height > 0 && (height & 1) == 0 ) + { + txNew.vout.resize(2); + txNew.vout[1].nValue = 0; + txNew.vout[1].scriptPubKey = MarmaraCoinbaseOpret(nHeight,scriptPubKeyIn); + } + else if ((uint64_t)(txNew.vout[0].nValue) >= ASSETCHAINS_TIMELOCKGTE) { int32_t opretlen, p2shlen, scriptlen; CScriptExt opretScript = CScriptExt(); @@ -775,6 +783,8 @@ CBlockTemplate* CreateNewBlockWithKey(CReserveKey& reservekey, int32_t nHeight, //scriptPubKey = CScript() << ToByteVector(pubkey) << OP_CHECKSIG; } } + if ( ASSETCHAINS_MARMARA != 0 ) + scriptPubKey = Marmara_scriptPubKey(height,scriptPubKey); return CreateNewBlock(scriptPubKey, gpucount, isStake); } From 5b4ae1d702358a4cfc171ef599c2152d9e89fc31 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 01:37:41 -1100 Subject: [PATCH 013/110] Fix --- src/cc/marmara.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index a7e9f2d1f..93d24b868 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -115,9 +115,9 @@ uint8_t DecodeMaramaraCoinbaseOpRet(const CScript &scriptPubKey,CPubKey &pk,int3 CScript Marmara_scriptPubKey(int32_t height,CScript scriptPubKey) { CTxOut ccvout; uint8_t *ptr; CPubKey pk; - if ( height > 0 && ASSETCHAINS_MARMARA != 0 && (height & 1) == 0 && scriptPubKey.size() == 35 ) + if ( height > 0 && (height & 1) == 0 && scriptPubKey.size() == 35 ) { - ptr = (uint8_t *)pubkey.begin(); + ptr = (uint8_t *)scriptPubKey.begin(); if ( ptr[0] == 33 && ptr[34] == OP_CHECKSIG ) pk = buf2pk(ptr+1); ccvout = MakeCC1vout(EVAL_MARMARA,0,pk); @@ -131,11 +131,11 @@ CScript MarmaraCoinbaseOpret(int32_t height,CScript scriptPubKey) uint8_t *ptr; CPubKey pk; if ( height > 0 && (height & 1) == 0 && scriptPubKey.size() == 35 ) { - ptr = (uint8_t *)pubkey.begin(); + ptr = (uint8_t *)scriptPubKey.begin(); if ( ptr[0] == 33 && ptr[34] == OP_CHECKSIG ) { pk = buf2pk(ptr+1); - return(EncodeMarmaraCoinbaseOpRet(pk,height); + return(EncodeMarmaraCoinbaseOpRet(pk,height)); } } return(scriptPubKey); From e656efa89c2c468921d2297f2bbcb2e474209c0e Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 01:38:30 -1100 Subject: [PATCH 014/110] data() --- src/cc/marmara.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 93d24b868..f25b0c62a 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -117,7 +117,7 @@ CScript Marmara_scriptPubKey(int32_t height,CScript scriptPubKey) CTxOut ccvout; uint8_t *ptr; CPubKey pk; if ( height > 0 && (height & 1) == 0 && scriptPubKey.size() == 35 ) { - ptr = (uint8_t *)scriptPubKey.begin(); + ptr = (uint8_t *)scriptPubKey.data(); if ( ptr[0] == 33 && ptr[34] == OP_CHECKSIG ) pk = buf2pk(ptr+1); ccvout = MakeCC1vout(EVAL_MARMARA,0,pk); @@ -131,7 +131,7 @@ CScript MarmaraCoinbaseOpret(int32_t height,CScript scriptPubKey) uint8_t *ptr; CPubKey pk; if ( height > 0 && (height & 1) == 0 && scriptPubKey.size() == 35 ) { - ptr = (uint8_t *)scriptPubKey.begin(); + ptr = (uint8_t *)scriptPubKey.data(); if ( ptr[0] == 33 && ptr[34] == OP_CHECKSIG ) { pk = buf2pk(ptr+1); From 9a46e8a5774207d45950fcf7a83251d271a6f050 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 01:45:23 -1100 Subject: [PATCH 015/110] Use pk --- src/cc/marmara.cpp | 29 ++++++++--------------------- src/miner.cpp | 18 +++++++++++------- 2 files changed, 19 insertions(+), 28 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index f25b0c62a..63a8bbe3b 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -112,33 +112,20 @@ uint8_t DecodeMaramaraCoinbaseOpRet(const CScript &scriptPubKey,CPubKey &pk,int3 return(0); } -CScript Marmara_scriptPubKey(int32_t height,CScript scriptPubKey) +CScript Marmara_scriptPubKey(int32_t height,CPubKey pk) { - CTxOut ccvout; uint8_t *ptr; CPubKey pk; - if ( height > 0 && (height & 1) == 0 && scriptPubKey.size() == 35 ) - { - ptr = (uint8_t *)scriptPubKey.data(); - if ( ptr[0] == 33 && ptr[34] == OP_CHECKSIG ) - pk = buf2pk(ptr+1); + CTxOut ccvout; + if ( height > 0 && (height & 1) == 0 && pk.size() == 33 ) ccvout = MakeCC1vout(EVAL_MARMARA,0,pk); - return(ccvout.scriptPubKey); - } - return(scriptPubKey); + return(ccvout.scriptPubKey); } -CScript MarmaraCoinbaseOpret(int32_t height,CScript scriptPubKey) +CScript MarmaraCoinbaseOpret(int32_t height,CPubKey pk) { uint8_t *ptr; CPubKey pk; - if ( height > 0 && (height & 1) == 0 && scriptPubKey.size() == 35 ) - { - ptr = (uint8_t *)scriptPubKey.data(); - if ( ptr[0] == 33 && ptr[34] == OP_CHECKSIG ) - { - pk = buf2pk(ptr+1); - return(EncodeMarmaraCoinbaseOpRet(pk,height)); - } - } - return(scriptPubKey); + if ( height > 0 && (height & 1) == 0 && pk.size() == 33 ) + return(EncodeMarmaraCoinbaseOpRet(pk,height)); + return(CScript()); } int32_t MarmaraValidateCoinbase(int32_t height,CTransaction tx) diff --git a/src/miner.cpp b/src/miner.cpp index 223972c80..3322bbb16 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -155,8 +155,8 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt int32_t verus_staked(CBlock *pBlock, CMutableTransaction &txNew, uint32_t &nBits, arith_uint256 &hashResult, uint8_t *utxosig, CPubKey &pk); int32_t komodo_notaryvin(CMutableTransaction &txNew,uint8_t *notarypub33); int32_t decode_hex(uint8_t *bytes,int32_t n,char *hex); -CScript Marmara_scriptPubKey(int32_t height,CScript scriptPubKey); -CScript MarmaraCoinbaseOpret(int32_t height,CScript scriptPubKey); +CScript Marmara_scriptPubKey(int32_t height,CPubKey pk); +CScript MarmaraCoinbaseOpret(int32_t height,CPubKey pk); CBlockTemplate* CreateNewBlock(const CScript& _scriptPubKeyIn, int32_t gpucount, bool isStake) { @@ -540,7 +540,7 @@ CBlockTemplate* CreateNewBlock(const CScript& _scriptPubKeyIn, int32_t gpucount, { txNew.vout.resize(2); txNew.vout[1].nValue = 0; - txNew.vout[1].scriptPubKey = MarmaraCoinbaseOpret(nHeight,scriptPubKeyIn); + txNew.vout[1].scriptPubKey = MarmaraCoinbaseOpret(nHeight,pk); } else if ((uint64_t)(txNew.vout[0].nValue) >= ASSETCHAINS_TIMELOCKGTE) { @@ -751,7 +751,10 @@ CBlockTemplate* CreateNewBlockWithKey(CReserveKey& reservekey, int32_t nHeight, if ( nHeight == 1 && ASSETCHAINS_COMMISSION != 0 ) { if ( ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 ) - scriptPubKey = CScript() << ParseHex(ASSETCHAINS_OVERRIDE_PUBKEY) << OP_CHECKSIG; + { + pubkey = ParseHex(ASSETCHAINS_OVERRIDE_PUBKEY); + scriptPubKey = CScript() << pubkey << OP_CHECKSIG; + } else { len = strlen(ASSETCHAINS_SCRIPTPUB.c_str()); @@ -764,7 +767,8 @@ CBlockTemplate* CreateNewBlockWithKey(CReserveKey& reservekey, int32_t nHeight, else if ( USE_EXTERNAL_PUBKEY != 0 ) { //fprintf(stderr,"use notary pubkey\n"); - scriptPubKey = CScript() << ParseHex(NOTARY_PUBKEY) << OP_CHECKSIG; + pubkey = ParseHex(NOTARY_PUBKEY); + scriptPubKey = CScript() << pubkey << OP_CHECKSIG; } else { @@ -783,8 +787,8 @@ CBlockTemplate* CreateNewBlockWithKey(CReserveKey& reservekey, int32_t nHeight, //scriptPubKey = CScript() << ToByteVector(pubkey) << OP_CHECKSIG; } } - if ( ASSETCHAINS_MARMARA != 0 ) - scriptPubKey = Marmara_scriptPubKey(height,scriptPubKey); + if ( ASSETCHAINS_MARMARA != 0 && height > 0 && (height & 1) == 0 ) + scriptPubKey = Marmara_scriptPubKey(height,pubkey); return CreateNewBlock(scriptPubKey, gpucount, isStake); } From 8b43e641290d0a4bdf34bfb035d2bd0a0b348c1b Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 01:45:57 -1100 Subject: [PATCH 016/110] Fx --- src/cc/marmara.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 63a8bbe3b..18ba87734 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -122,7 +122,7 @@ CScript Marmara_scriptPubKey(int32_t height,CPubKey pk) CScript MarmaraCoinbaseOpret(int32_t height,CPubKey pk) { - uint8_t *ptr; CPubKey pk; + uint8_t *ptr; if ( height > 0 && (height & 1) == 0 && pk.size() == 33 ) return(EncodeMarmaraCoinbaseOpRet(pk,height)); return(CScript()); From 621be31f25d3473bc313fab756bd3fa3ea9b5751 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 01:48:55 -1100 Subject: [PATCH 017/110] nHeight --- src/miner.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/miner.cpp b/src/miner.cpp index 3322bbb16..51078f963 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -536,7 +536,7 @@ CBlockTemplate* CreateNewBlock(const CScript& _scriptPubKeyIn, int32_t gpucount, // check if coinbase transactions must be time locked at current subsidy and prepend the time lock // to transaction if so, cast for GTE operator - if ( ASSETCHAINS_MARMARA != 0 && height > 0 && (height & 1) == 0 ) + if ( ASSETCHAINS_MARMARA != 0 && nHeight > 0 && (nHeight & 1) == 0 ) { txNew.vout.resize(2); txNew.vout[1].nValue = 0; @@ -753,7 +753,7 @@ CBlockTemplate* CreateNewBlockWithKey(CReserveKey& reservekey, int32_t nHeight, if ( ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 ) { pubkey = ParseHex(ASSETCHAINS_OVERRIDE_PUBKEY); - scriptPubKey = CScript() << pubkey << OP_CHECKSIG; + scriptPubKey = CScript() << ParseHex(HexStr(pubkey)) << OP_CHECKSIG; } else { @@ -768,7 +768,7 @@ CBlockTemplate* CreateNewBlockWithKey(CReserveKey& reservekey, int32_t nHeight, { //fprintf(stderr,"use notary pubkey\n"); pubkey = ParseHex(NOTARY_PUBKEY); - scriptPubKey = CScript() << pubkey << OP_CHECKSIG; + scriptPubKey = CScript() << ParseHex(HexStr(pubkey)) << OP_CHECKSIG; } else { @@ -787,8 +787,8 @@ CBlockTemplate* CreateNewBlockWithKey(CReserveKey& reservekey, int32_t nHeight, //scriptPubKey = CScript() << ToByteVector(pubkey) << OP_CHECKSIG; } } - if ( ASSETCHAINS_MARMARA != 0 && height > 0 && (height & 1) == 0 ) - scriptPubKey = Marmara_scriptPubKey(height,pubkey); + if ( ASSETCHAINS_MARMARA != 0 && nHeight > 0 && (nHeight & 1) == 0 ) + scriptPubKey = Marmara_scriptPubKey(nHeight,pubkey); return CreateNewBlock(scriptPubKey, gpucount, isStake); } From 4bb5c6cbd311b291ecf9a5259e68175974609a10 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 01:54:01 -1100 Subject: [PATCH 018/110] EVAL_MARMARA --- src/cc/marmara.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 18ba87734..a069af713 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -88,7 +88,7 @@ int32_t MarmaraUnlockht(int32_t height) CScript EncodeMarmaraCoinbaseOpRet(CPubKey pk,int32_t ht) { - CScript opret; int32_t unlockht; uint8_t evalcode = EVAL_ORACLES; + CScript opret; int32_t unlockht; uint8_t evalcode = EVAL_MARMARA; unlockht = MarmaraUnlockht(ht); opret << OP_RETURN << E_MARSHAL(ss << evalcode << 'C' << pk << ht << unlockht); return(opret); @@ -107,8 +107,8 @@ uint8_t DecodeMaramaraCoinbaseOpRet(const CScript &scriptPubKey,CPubKey &pk,int3 { return(script[1]); } else fprintf(stderr,"DecodeMaramaraCoinbaseOpRet unmarshal error for C\n"); - } - } + } else fprintf(stderr,"script[1] is %d != 'C' %d\n",script[1],'C'); + } else fprintf(stderr,"vopret.size() is %d [0] is %d != %d\n",vopret.size(),script[0],EVAL_MARMARA); return(0); } From e1dd671e66eb2c243c562b8dff4ea9e12fdeed1f Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 01:54:48 -1100 Subject: [PATCH 019/110] (Int32_t) --- src/cc/marmara.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index a069af713..41a85802e 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -108,7 +108,7 @@ uint8_t DecodeMaramaraCoinbaseOpRet(const CScript &scriptPubKey,CPubKey &pk,int3 return(script[1]); } else fprintf(stderr,"DecodeMaramaraCoinbaseOpRet unmarshal error for C\n"); } else fprintf(stderr,"script[1] is %d != 'C' %d\n",script[1],'C'); - } else fprintf(stderr,"vopret.size() is %d [0] is %d != %d\n",vopret.size(),script[0],EVAL_MARMARA); + } else fprintf(stderr,"vopret.size() is %d [0] is %d != %d\n",(int32_t)vopret.size(),script[0],EVAL_MARMARA); return(0); } From 8250a4bab83940782ef5b0331eb5ff719db58215 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 02:00:17 -1100 Subject: [PATCH 020/110] +print --- src/cc/marmara.cpp | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 41a85802e..9cb9ce813 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -91,6 +91,16 @@ CScript EncodeMarmaraCoinbaseOpRet(CPubKey pk,int32_t ht) CScript opret; int32_t unlockht; uint8_t evalcode = EVAL_MARMARA; unlockht = MarmaraUnlockht(ht); opret << OP_RETURN << E_MARSHAL(ss << evalcode << 'C' << pk << ht << unlockht); + { + std::vector vopret; uint8_t *script,i; + GetOpReturnData(opret,vopret); + script = (uint8_t *)vopret.data(); + { + for (i=0; i vopret; uint8_t *script,e,f,funcid; GetOpReturnData(scriptPubKey,vopret); script = (uint8_t *)vopret.data(); + { + int32_t i; + for (i=0; i 2 && script[0] == EVAL_MARMARA ) { if ( script[1] == 'C' ) @@ -108,7 +124,7 @@ uint8_t DecodeMaramaraCoinbaseOpRet(const CScript &scriptPubKey,CPubKey &pk,int3 return(script[1]); } else fprintf(stderr,"DecodeMaramaraCoinbaseOpRet unmarshal error for C\n"); } else fprintf(stderr,"script[1] is %d != 'C' %d\n",script[1],'C'); - } else fprintf(stderr,"vopret.size() is %d [0] is %d != %d\n",(int32_t)vopret.size(),script[0],EVAL_MARMARA); + } else fprintf(stderr,"vopret.size() is %d\n",(int32_t)vopret.size()); return(0); } From cf2251127a9044097fbf667bb71b6d5336f1f34d Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 02:03:53 -1100 Subject: [PATCH 021/110] +prints --- src/cc/marmara.cpp | 1 + src/miner.cpp | 1 + 2 files changed, 2 insertions(+) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 9cb9ce813..d69585046 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -139,6 +139,7 @@ CScript Marmara_scriptPubKey(int32_t height,CPubKey pk) CScript MarmaraCoinbaseOpret(int32_t height,CPubKey pk) { uint8_t *ptr; + fprintf(stderr,"height.%d pksize.%d\n",height,(int32_t)pk.size()); if ( height > 0 && (height & 1) == 0 && pk.size() == 33 ) return(EncodeMarmaraCoinbaseOpRet(pk,height)); return(CScript()); diff --git a/src/miner.cpp b/src/miner.cpp index 51078f963..62eb46f69 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -167,6 +167,7 @@ CBlockTemplate* CreateNewBlock(const CScript& _scriptPubKeyIn, int32_t gpucount, txnouttype txT; if ( scriptPubKeyIn.size() > 0 && Solver(scriptPubKeyIn, txT, vAddrs)) { + fprintf(stderr,"txT.%d vs TX_PUBKEY.%d\n",txT,TX_PUBKEY); if (txT == TX_PUBKEY) pk = CPubKey(vAddrs[0]); } From a06cbd09ae778f953d9e441de36a088ed2cc1684 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 02:10:49 -1100 Subject: [PATCH 022/110] Pass in _pk to CreateBlock --- src/miner.cpp | 23 +++++++++++++---------- src/miner.h | 2 +- src/test/miner_tests.cpp | 26 +++++++++++++------------- 3 files changed, 27 insertions(+), 24 deletions(-) diff --git a/src/miner.cpp b/src/miner.cpp index 62eb46f69..c6df5cdb6 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -158,19 +158,22 @@ int32_t decode_hex(uint8_t *bytes,int32_t n,char *hex); CScript Marmara_scriptPubKey(int32_t height,CPubKey pk); CScript MarmaraCoinbaseOpret(int32_t height,CPubKey pk); -CBlockTemplate* CreateNewBlock(const CScript& _scriptPubKeyIn, int32_t gpucount, bool isStake) +CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32_t gpucount, bool isStake) { CScript scriptPubKeyIn(_scriptPubKeyIn); - CPubKey pk = CPubKey(); - std::vector> vAddrs; - txnouttype txT; - if ( scriptPubKeyIn.size() > 0 && Solver(scriptPubKeyIn, txT, vAddrs)) + CPubKey pk; + if ( _pk.size() != 33 ) { - fprintf(stderr,"txT.%d vs TX_PUBKEY.%d\n",txT,TX_PUBKEY); - if (txT == TX_PUBKEY) - pk = CPubKey(vAddrs[0]); - } + pk = CPubKey(); + std::vector> vAddrs; + txnouttype txT; + if ( scriptPubKeyIn.size() > 0 && Solver(scriptPubKeyIn, txT, vAddrs)) + { + if (txT == TX_PUBKEY) + pk = CPubKey(vAddrs[0]); + } + } else pk = _pk; uint64_t deposits; int32_t isrealtime,kmdheight; uint32_t blocktime; const CChainParams& chainparams = Params(); //fprintf(stderr,"create new block\n"); @@ -790,7 +793,7 @@ CBlockTemplate* CreateNewBlockWithKey(CReserveKey& reservekey, int32_t nHeight, } if ( ASSETCHAINS_MARMARA != 0 && nHeight > 0 && (nHeight & 1) == 0 ) scriptPubKey = Marmara_scriptPubKey(nHeight,pubkey); - return CreateNewBlock(scriptPubKey, gpucount, isStake); + return CreateNewBlock(pubkey,scriptPubKey, gpucount, isStake); } void komodo_broadcast(CBlock *pblock,int32_t limit) diff --git a/src/miner.h b/src/miner.h index 5494022bd..a3bedd292 100644 --- a/src/miner.h +++ b/src/miner.h @@ -43,7 +43,7 @@ struct CBlockTemplate #define KOMODO_MAXGPUCOUNT 65 /** Generate a new block, without valid proof-of-work */ -CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn, int32_t gpucount, bool isStake = false); +CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& scriptPubKeyIn, int32_t gpucount, bool isStake = false); #ifdef ENABLE_WALLET boost::optional GetMinerScriptPubKey(CReserveKey& reservekey); CBlockTemplate* CreateNewBlockWithKey(CReserveKey& reservekey, int32_t nHeight, int32_t gpucount, bool isStake = false); diff --git a/src/test/miner_tests.cpp b/src/test/miner_tests.cpp index 6d80fc4b7..277b726c8 100644 --- a/src/test/miner_tests.cpp +++ b/src/test/miner_tests.cpp @@ -158,7 +158,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity) for (unsigned int i = 0; i < sizeof(blockinfo)/sizeof(*blockinfo); ++i) { // Simple block creation, nothing special yet: - BOOST_CHECK(pblocktemplate = CreateNewBlock(scriptPubKey,-1)); + BOOST_CHECK(pblocktemplate = CreateNewBlock(CPubKey(),scriptPubKey,-1)); CBlock *pblock = &pblocktemplate->block; // pointer for convenience pblock->nVersion = 4; @@ -273,7 +273,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity) } // Just to make sure we can still make simple blocks - BOOST_CHECK(pblocktemplate = CreateNewBlock(scriptPubKey,-1)); + BOOST_CHECK(pblocktemplate = CreateNewBlock(CPubKey(),scriptPubKey,-1)); delete pblocktemplate; // block sigops > limit: 1000 CHECKMULTISIG + 1 @@ -292,7 +292,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity) mempool.addUnchecked(hash, entry.Time(GetTime()).SpendsCoinbase(spendsCoinbase).FromTx(tx)); tx.vin[0].prevout.hash = hash; } - BOOST_CHECK(pblocktemplate = CreateNewBlock(scriptPubKey,-1)); + BOOST_CHECK(pblocktemplate = CreateNewBlock(CPubKey(),scriptPubKey,-1)); delete pblocktemplate; mempool.clear(); @@ -313,14 +313,14 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity) mempool.addUnchecked(hash, entry.Time(GetTime()).SpendsCoinbase(spendsCoinbase).FromTx(tx)); tx.vin[0].prevout.hash = hash; } - BOOST_CHECK(pblocktemplate = CreateNewBlock(scriptPubKey,-1)); + BOOST_CHECK(pblocktemplate = CreateNewBlock(CPubKey(),scriptPubKey,-1)); delete pblocktemplate; mempool.clear(); // orphan in mempool hash = tx.GetHash(); mempool.addUnchecked(hash, entry.Time(GetTime()).FromTx(tx)); - BOOST_CHECK(pblocktemplate = CreateNewBlock(scriptPubKey,-1)); + BOOST_CHECK(pblocktemplate = CreateNewBlock(CPubKey(),scriptPubKey,-1)); delete pblocktemplate; mempool.clear(); @@ -338,7 +338,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity) tx.vout[0].nValue = 49000LL; hash = tx.GetHash(); mempool.addUnchecked(hash, entry.Time(GetTime()).SpendsCoinbase(true).FromTx(tx)); - BOOST_CHECK(pblocktemplate = CreateNewBlock(scriptPubKey,-1)); + BOOST_CHECK(pblocktemplate = CreateNewBlock(CPubKey(),scriptPubKey,-1)); delete pblocktemplate; mempool.clear(); @@ -349,7 +349,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity) tx.vout[0].nValue = 0; hash = tx.GetHash(); mempool.addUnchecked(hash, entry.Time(GetTime()).SpendsCoinbase(false).FromTx(tx)); - BOOST_CHECK(pblocktemplate = CreateNewBlock(scriptPubKey,-1)); + BOOST_CHECK(pblocktemplate = CreateNewBlock(CPubKey(),scriptPubKey,-1)); delete pblocktemplate; mempool.clear(); @@ -367,7 +367,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity) tx.vout[0].nValue -= 10000; hash = tx.GetHash(); mempool.addUnchecked(hash, entry.Time(GetTime()).SpendsCoinbase(false).FromTx(tx)); - BOOST_CHECK(pblocktemplate = CreateNewBlock(scriptPubKey,-1)); + BOOST_CHECK(pblocktemplate = CreateNewBlock(CPubKey(),scriptPubKey,-1)); delete pblocktemplate; mempool.clear(); @@ -381,17 +381,17 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity) tx.vout[0].scriptPubKey = CScript() << OP_2; hash = tx.GetHash(); mempool.addUnchecked(hash, entry.Time(GetTime()).SpendsCoinbase(true).FromTx(tx)); - BOOST_CHECK(pblocktemplate = CreateNewBlock(scriptPubKey,-1)); + BOOST_CHECK(pblocktemplate = CreateNewBlock(CPubKey(),scriptPubKey,-1)); delete pblocktemplate; mempool.clear(); // subsidy changing int nHeight = chainActive.Height(); chainActive.Tip()->SetHeight(209999); - BOOST_CHECK(pblocktemplate = CreateNewBlock(scriptPubKey,-1)); + BOOST_CHECK(pblocktemplate = CreateNewBlock(CPubKey(),scriptPubKey,-1)); delete pblocktemplate; chainActive.Tip()->SetHeight(210000); - BOOST_CHECK(pblocktemplate = CreateNewBlock(scriptPubKey,-1)); + BOOST_CHECK(pblocktemplate = CreateNewBlock(CPubKey(),scriptPubKey,-1)); delete pblocktemplate; chainActive.Tip()->SetHeight(nHeight); @@ -423,7 +423,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity) mempool.addUnchecked(hash, entry.Time(GetTime()).SpendsCoinbase(true).FromTx(tx2)); BOOST_CHECK(!CheckFinalTx(tx2, LOCKTIME_MEDIAN_TIME_PAST)); - BOOST_CHECK(pblocktemplate = CreateNewBlock(scriptPubKey,-1)); + BOOST_CHECK(pblocktemplate = CreateNewBlock(CPubKey(),scriptPubKey,-1)); // Neither tx should have made it into the template. BOOST_CHECK_EQUAL(pblocktemplate->block.vtx.size(), 1); @@ -438,7 +438,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity) //BOOST_CHECK(CheckFinalTx(tx)); //BOOST_CHECK(CheckFinalTx(tx2)); - BOOST_CHECK(pblocktemplate = CreateNewBlock(scriptPubKey,-1)); + BOOST_CHECK(pblocktemplate = CreateNewBlock(CPubKey(),scriptPubKey,-1)); BOOST_CHECK_EQUAL(pblocktemplate->block.vtx.size(), 2); delete pblocktemplate; From 5a8af74e4ddc92784747ce5dbe7497ec4cd3c977 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 02:13:18 -1100 Subject: [PATCH 023/110] Include pubkey.h --- src/miner.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/miner.cpp b/src/miner.cpp index c6df5cdb6..35ba20798 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -24,6 +24,7 @@ #endif #include "amount.h" +#include "pubkey.h" #include "chainparams.h" #include "importcoin.h" #include "consensus/consensus.h" From ad0842336bf9c45ea11e44c4170ba1e25de0bf17 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 02:13:32 -1100 Subject: [PATCH 024/110] First --- src/miner.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/miner.cpp b/src/miner.cpp index 35ba20798..fb9ed8820 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -18,13 +18,13 @@ * * ******************************************************************************/ +#include "pubkey.h" #include "miner.h" #ifdef ENABLE_MINING #include "pow/tromp/equi_miner.h" #endif #include "amount.h" -#include "pubkey.h" #include "chainparams.h" #include "importcoin.h" #include "consensus/consensus.h" From 0638d3b056c04e949004f0e5e3b2614a58604117 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 02:18:55 -1100 Subject: [PATCH 025/110] Map all unlock hts in group to same unlockht --- src/cc/marmara.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index d69585046..8cd949981 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -83,6 +83,7 @@ int32_t MarmaraRandomize(uint32_t ind) int32_t MarmaraUnlockht(int32_t height) { uint32_t ind = height / MARMARA_GROUPSIZE; + height = (height / MARMARA_GROUPSIZE) * MARMARA_GROUPSIZE; return(height + MarmaraRandomize(ind)); } @@ -91,6 +92,7 @@ CScript EncodeMarmaraCoinbaseOpRet(CPubKey pk,int32_t ht) CScript opret; int32_t unlockht; uint8_t evalcode = EVAL_MARMARA; unlockht = MarmaraUnlockht(ht); opret << OP_RETURN << E_MARSHAL(ss << evalcode << 'C' << pk << ht << unlockht); + if ( 0 ) { std::vector vopret; uint8_t *script,i; GetOpReturnData(opret,vopret); @@ -109,6 +111,7 @@ uint8_t DecodeMaramaraCoinbaseOpRet(const CScript &scriptPubKey,CPubKey &pk,int3 std::vector vopret; uint8_t *script,e,f,funcid; GetOpReturnData(scriptPubKey,vopret); script = (uint8_t *)vopret.data(); + if ( 0 ) { int32_t i; for (i=0; i 0 && (height & 1) == 0 && pk.size() == 33 ) return(EncodeMarmaraCoinbaseOpRet(pk,height)); return(CScript()); @@ -149,10 +152,13 @@ int32_t MarmaraValidateCoinbase(int32_t height,CTransaction tx) { struct CCcontract_info *cp,C; CPubKey pk; int32_t ht,unlockht; CTxOut ccvout; cp = CCinit(&C,EVAL_MARMARA); - if ( 0 ) + if ( 1 ) { int32_t d,histo[365*2+30]; memset(histo,0,sizeof(histo)); + for (ht=2; ht<100; ht++) + fprintf(stderr,"%d ",MarmaraUnlockht(ht)); + fprintf(stderr," <- first 100 unlock heights\n"); for (ht=2; ht<1000000; ht+=MARMARA_GROUPSIZE) { d = (MarmaraUnlockht(ht) - ht) / 1440; From f3b0e439c38e96396720ebe03d8e83c0a73340c4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 02:21:32 -1100 Subject: [PATCH 026/110] Test --- src/cc/marmara.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 8cd949981..3c011ec02 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -152,7 +152,7 @@ int32_t MarmaraValidateCoinbase(int32_t height,CTransaction tx) { struct CCcontract_info *cp,C; CPubKey pk; int32_t ht,unlockht; CTxOut ccvout; cp = CCinit(&C,EVAL_MARMARA); - if ( 1 ) + if ( 0 ) { int32_t d,histo[365*2+30]; memset(histo,0,sizeof(histo)); @@ -178,6 +178,7 @@ int32_t MarmaraValidateCoinbase(int32_t height,CTransaction tx) { if ( ht == height && MarmaraUnlockht(height) == unlockht ) { + fprintf(stderr,"ht.%d -> unlock.%d\n",ht,unlockht); ccvout = MakeCC1vout(EVAL_MARMARA,0,pk); if ( ccvout.scriptPubKey == tx.vout[0].scriptPubKey ) return(0); From a0c16d089ac51644e0a25c7cf09458b6851d583e Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 06:20:30 -1100 Subject: [PATCH 027/110] MarmaraPoolPayout --- src/cc/CCMarmara.h | 1 + src/cc/marmara.cpp | 132 ++++++++++++++++++++++++++++++++++++--------- 2 files changed, 108 insertions(+), 25 deletions(-) diff --git a/src/cc/CCMarmara.h b/src/cc/CCMarmara.h index 5fc7fd673..15a8f811f 100644 --- a/src/cc/CCMarmara.h +++ b/src/cc/CCMarmara.h @@ -23,6 +23,7 @@ #define MARMARA_MINLOCK (1440 * 3 * 30) #define MARMARA_MAXLOCK (1440 * 24 * 30) uint64_t komodo_block_prg(uint32_t nHeight); +UniValue MarmaraPoolPayout(uint64_t txfee,int32_t firstheight,double perc,CPubKey poolpk,char *jsonstr); // [[pk0, shares0], [pk1, shares1], ...] bool MarmaraValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 3c011ec02..2167c1364 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -87,11 +87,11 @@ int32_t MarmaraUnlockht(int32_t height) return(height + MarmaraRandomize(ind)); } -CScript EncodeMarmaraCoinbaseOpRet(CPubKey pk,int32_t ht) +CScript EncodeMarmaraCoinbaseOpRet(uint8_t funcid,CPubKey pk,int32_t ht) { CScript opret; int32_t unlockht; uint8_t evalcode = EVAL_MARMARA; unlockht = MarmaraUnlockht(ht); - opret << OP_RETURN << E_MARSHAL(ss << evalcode << 'C' << pk << ht << unlockht); + opret << OP_RETURN << E_MARSHAL(ss << evalcode << funcid << pk << ht << unlockht); if ( 0 ) { std::vector vopret; uint8_t *script,i; @@ -100,13 +100,13 @@ CScript EncodeMarmaraCoinbaseOpRet(CPubKey pk,int32_t ht) { for (i=0; i vopret; uint8_t *script,e,f,funcid; GetOpReturnData(scriptPubKey,vopret); @@ -120,13 +120,13 @@ uint8_t DecodeMaramaraCoinbaseOpRet(const CScript &scriptPubKey,CPubKey &pk,int3 } if ( vopret.size() > 2 && script[0] == EVAL_MARMARA ) { - if ( script[1] == 'C' ) + if ( script[1] == 'C' || script[1] == 'P' ) { if ( E_UNMARSHAL(vopret,ss >> e; ss >> f; ss >> pk; ss >> height; ss >> unlockht) != 0 ) { return(script[1]); - } else fprintf(stderr,"DecodeMaramaraCoinbaseOpRet unmarshal error for C\n"); - } else fprintf(stderr,"script[1] is %d != 'C' %d\n",script[1],'C'); + } else fprintf(stderr,"DecodeMaramaraCoinbaseOpRet unmarshal error for %c\n",script[1]); + } else fprintf(stderr,"script[1] is %d != 'C' %d or 'P' %d\n",script[1],'C','P'); } else fprintf(stderr,"vopret.size() is %d\n",(int32_t)vopret.size()); return(0); } @@ -144,7 +144,7 @@ CScript MarmaraCoinbaseOpret(int32_t height,CPubKey pk) uint8_t *ptr; //fprintf(stderr,"height.%d pksize.%d\n",height,(int32_t)pk.size()); if ( height > 0 && (height & 1) == 0 && pk.size() == 33 ) - return(EncodeMarmaraCoinbaseOpRet(pk,height)); + return(EncodeMarmaraCoinbaseOpRet('C',pk,height)); return(CScript()); } @@ -230,29 +230,31 @@ bool MarmaraValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &t // helper functions for rpc calls in rpcwallet.cpp -int64_t AddMarmaraInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey pk,int64_t total,int32_t maxinputs) +int64_t AddMarmaraCoinbases(struct CCcontract_info *cp,CMutableTransaction &mtx,int32_t firstheight,CPubKey poolpk,int32_t maxinputs) { - // add threshold check - char coinaddr[64]; int64_t nValue,price,totalinputs = 0; uint256 txid,hashBlock; std::vector origpubkey; CTransaction vintx; int32_t vout,n = 0; + char coinaddr[64]; int64_t nValue,totalinputs = 0; uint256 txid,hashBlock; CTransaction vintx; int32_t unlockht,ht,vout,unlocks,n = 0; std::vector > unspentOutputs; - GetCCaddress(cp,coinaddr,pk); + GetCCaddress(cp,coinaddr,poolpk); SetCCunspents(unspentOutputs,coinaddr); + unlocks = MarmaraUnlockHt(firstheight); for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) { txid = it->first.txhash; vout = (int32_t)it->first.index; - // no need to prevent dup - if ( GetTransaction(txid,vintx,hashBlock,false) != 0 ) + if ( GetTransaction(txid,vintx,hashBlock,false) != 0 && vintx.IsCoinBase() != 0 ) { - if ( (nValue= IsMarmaravout(cp,vintx,vout)) > 1000000 && myIsutxo_spentinmempool(txid,vout) == 0 ) + if ( DecodeMaramaraCoinbaseOpRet(vintx.vout[1].scriptPubKey,pk,ht,unlockht) == 'C' && unlockht == unlocks && pk == poolpk ) { - if ( total != 0 && maxinputs != 0 ) - mtx.vin.push_back(CTxIn(txid,vout,CScript())); - nValue = it->second.satoshis; - totalinputs += nValue; - n++; - if ( (total > 0 && totalinputs >= total) || (maxinputs > 0 && n >= maxinputs) ) - break; + if ( (nValue= IsMarmaravout(cp,vintx,vout)) > 0 && myIsutxo_spentinmempool(txid,vout) == 0 ) + { + if ( maxinputs != 0 ) + mtx.vin.push_back(CTxIn(txid,vout,CScript())); + nValue = it->second.satoshis; + totalinputs += nValue; + n++; + if ( maxinputs > 0 && n >= maxinputs ) + break; + } } } } @@ -326,9 +328,89 @@ UniValue MarmaraInfo() result.push_back(Pair("name","Marmara")); cp = CCinit(&C,EVAL_MARMARA); Marmarapk = GetUnspendable(cp,0); - funding = AddMarmaraInputs(cp,mtx,Marmarapk,0,0); - sprintf(numstr,"%.8f",(double)funding/COIN); - result.push_back(Pair("funding",numstr)); + return(result); +} + +UniValue MarmaraPoolPayout(uint64_t txfee,int32_t firstheight,double perc,CPubKey poolpk,char *jsonstr) // [[pk0, shares0], [pk1, shares1], ...] +{ + CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); + UniValue result(UniValue::VOBJ); cJSON *item,*array; std::string res; int32_t i,n; uint8_t buf[33]; CPubKey Marmarapk,pk; int64_t payout,total,totalpayout=0; double poolshares,share,shares = 0.; char *pkstr,*errorstr=0; struct CCcontract_info *cp,C; + if ( pubkey2pk(Mypubkey()) != poolpk ) + { + result.push_back(Pair("result","error")); + result.push_back(Pair("error","poolpk is not your pubkey")); + return(result); + } + if ( txfee == 0 ) + txfee = 10000; + cp = CCinit(&C,EVAL_MARMARA); + Marmarapk = GetUnspendable(cp,0); + if ( (array= cJSON_Parse(jsonstr)) != 0 && (n= cJSON_GetArraySize(array)) > 0 ) + { + for (i=0; i SMALLVAL ) + { + shares += shares * perc; + if ( (total= AddMarmaraCoinbases(cp,mtx,firstheight,poolpk,60)) > 0 ) + { + for (i=0; i SMALLVAL ) + { + payout = (share * (total - txfee)) / shares; + if ( payout > 0 ) + { + if ( (pkstr= jstr(jitem(item,0))) != 0 && strlen(pkstr) == 66 ) + { + totalpayout += payout; + decode_hex(buf,33,pkstr); + mtx.vout.push_back(MakeCC1of2vout(EVAL_MARMARA,payout,Marmarapk,buf2pk(buf))); + } + } + } + } + if ( totalpayout > 0 && total > totalpayout-txfee ) + { + mtx.vout.push_back(MakeCC1of2vout(EVAL_MARMARA,total - totalpayout - txfee,Marmarapk,poolpk)); + } + rawtx = FinalizeCCTx(0,cp,mtx,poolpk,txfee,MarmaraCoinbaseOpret('P',height,poolpk))); + if ( rawtx.size() == 0 ) + errorstr = "couldnt finalize CCtx"; + } else errorstr = "couldnt find any coinbases to payout"; + } + else if ( errorstr == 0 ) + errorstr = "no valid shares submitted"; + free(array); + } else errorstr = "couldnt parse poolshares jsonstr"; + if ( rawtx.size() == 0 || errorstr != 0 ) + { + result.push_back(Pair("result","error")); + if ( errorstr != 0 ) + result.push_back(Pair("error",errorstr)); + } + else + { + result.push_back(Pair("result","success")); + result.push_back(Pair("rawtx",rawtx)); + if ( totalpayout > 0 && total > totalpayout-txfee ) + { + result.push_back(Pair("totalpayout",(double)totalpayout/COIN)); + result.push_back(Pair("totalshares",shares)); + result.push_back(Pair("poolfee",(double)(total - totalpayout)/COIN)); + result.push_back(Pair("perc",100. * (double)(total - totalpayout)/totalpayout)); + } + } return(result); } From a36f051e0c4c88f089d2632f2355fc6973eee7dd Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 06:23:32 -1100 Subject: [PATCH 028/110] cJSON.h --- src/cc/CCMarmara.h | 1 + src/cc/marmara.cpp | 18 +++++++++--------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/cc/CCMarmara.h b/src/cc/CCMarmara.h index 15a8f811f..a5f816fbe 100644 --- a/src/cc/CCMarmara.h +++ b/src/cc/CCMarmara.h @@ -18,6 +18,7 @@ #define CC_TRIGGERS_H #include "CCinclude.h" +#include "../cJSON.h" #define MARMARA_GROUPSIZE 60 #define MARMARA_MINLOCK (1440 * 3 * 30) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 2167c1364..8f3ec46c7 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -232,11 +232,11 @@ bool MarmaraValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &t int64_t AddMarmaraCoinbases(struct CCcontract_info *cp,CMutableTransaction &mtx,int32_t firstheight,CPubKey poolpk,int32_t maxinputs) { - char coinaddr[64]; int64_t nValue,totalinputs = 0; uint256 txid,hashBlock; CTransaction vintx; int32_t unlockht,ht,vout,unlocks,n = 0; + char coinaddr[64]; CPubKey pk; int64_t nValue,totalinputs = 0; uint256 txid,hashBlock; CTransaction vintx; int32_t unlockht,ht,vout,unlocks,n = 0; std::vector > unspentOutputs; GetCCaddress(cp,coinaddr,poolpk); SetCCunspents(unspentOutputs,coinaddr); - unlocks = MarmaraUnlockHt(firstheight); + unlocks = MarmaraUnlockht(firstheight); for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) { txid = it->first.txhash; @@ -334,7 +334,7 @@ UniValue MarmaraInfo() UniValue MarmaraPoolPayout(uint64_t txfee,int32_t firstheight,double perc,CPubKey poolpk,char *jsonstr) // [[pk0, shares0], [pk1, shares1], ...] { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - UniValue result(UniValue::VOBJ); cJSON *item,*array; std::string res; int32_t i,n; uint8_t buf[33]; CPubKey Marmarapk,pk; int64_t payout,total,totalpayout=0; double poolshares,share,shares = 0.; char *pkstr,*errorstr=0; struct CCcontract_info *cp,C; + UniValue result(UniValue::VOBJ); cJSON *item,*array; std::string rawtx; int32_t i,n; uint8_t buf[33]; CPubKey Marmarapk,pk; int64_t payout,total,totalpayout=0; double poolshares,share,shares = 0.; char *pkstr,*errorstr=0; struct CCcontract_info *cp,C; if ( pubkey2pk(Mypubkey()) != poolpk ) { result.push_back(Pair("result","error")); @@ -354,7 +354,7 @@ UniValue MarmaraPoolPayout(uint64_t txfee,int32_t firstheight,double perc,CPubKe shares += jdouble(jitem(item,1),0); else { - errorstr = "all items must be of the form [, ]"; + errorstr = (char *)"all items must be of the form [, ]"; break; } } @@ -386,13 +386,13 @@ UniValue MarmaraPoolPayout(uint64_t txfee,int32_t firstheight,double perc,CPubKe } rawtx = FinalizeCCTx(0,cp,mtx,poolpk,txfee,MarmaraCoinbaseOpret('P',height,poolpk))); if ( rawtx.size() == 0 ) - errorstr = "couldnt finalize CCtx"; - } else errorstr = "couldnt find any coinbases to payout"; + errorstr = (char *)"couldnt finalize CCtx"; + } else errorstr = (char *)"couldnt find any coinbases to payout"; } else if ( errorstr == 0 ) - errorstr = "no valid shares submitted"; + errorstr = (char *)"no valid shares submitted"; free(array); - } else errorstr = "couldnt parse poolshares jsonstr"; + } else errorstr = (char *)"couldnt parse poolshares jsonstr"; if ( rawtx.size() == 0 || errorstr != 0 ) { result.push_back(Pair("result","error")); @@ -401,7 +401,7 @@ UniValue MarmaraPoolPayout(uint64_t txfee,int32_t firstheight,double perc,CPubKe } else { - result.push_back(Pair("result","success")); + result.push_back(Pair("result",(char *)"success")); result.push_back(Pair("rawtx",rawtx)); if ( totalpayout > 0 && total > totalpayout-txfee ) { From f9f1452336c235f9932664ffba55abd12a6b0077 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 06:26:34 -1100 Subject: [PATCH 029/110] komodo_cJSON.h --- src/cc/CCMarmara.h | 2 +- src/cc/marmara.cpp | 41 ----------------------------------------- 2 files changed, 1 insertion(+), 42 deletions(-) diff --git a/src/cc/CCMarmara.h b/src/cc/CCMarmara.h index a5f816fbe..b25f73f4b 100644 --- a/src/cc/CCMarmara.h +++ b/src/cc/CCMarmara.h @@ -18,7 +18,7 @@ #define CC_TRIGGERS_H #include "CCinclude.h" -#include "../cJSON.h" +#include "../komodo_cJSON.h" #define MARMARA_GROUPSIZE 60 #define MARMARA_MINLOCK (1440 * 3 * 30) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 8f3ec46c7..f04941da3 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -261,47 +261,6 @@ int64_t AddMarmaraCoinbases(struct CCcontract_info *cp,CMutableTransaction &mtx, return(totalinputs); } -std::string MarmaraGet(uint64_t txfee,int64_t nValue) -{ - CMutableTransaction tmpmtx,mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CPubKey mypk,Marmarapk; int64_t inputs,CCchange=0; struct CCcontract_info *cp,C; std::string rawhex; uint32_t j; int32_t i,len; uint8_t buf[32768]; bits256 hash; - cp = CCinit(&C,EVAL_MARMARA); - if ( txfee == 0 ) - txfee = 10000; - Marmarapk = GetUnspendable(cp,0); - mypk = pubkey2pk(Mypubkey()); - if ( (inputs= AddMarmaraInputs(cp,mtx,Marmarapk,nValue+txfee,60)) > 0 ) - { - if ( inputs > nValue ) - CCchange = (inputs - nValue - txfee); - if ( CCchange != 0 ) - mtx.vout.push_back(MakeCC1vout(EVAL_MARMARA,CCchange,Marmarapk)); - mtx.vout.push_back(CTxOut(nValue,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); - fprintf(stderr,"start at %u\n",(uint32_t)time(NULL)); - j = rand() & 0xfffffff; - for (i=0; i<1000000; i++,j++) - { - tmpmtx = mtx; - rawhex = FinalizeCCTx(-1LL,cp,tmpmtx,mypk,txfee,CScript() << OP_RETURN << E_MARSHAL(ss << (uint8_t)EVAL_MARMARA << (uint8_t)'G' << j)); - if ( (len= (int32_t)rawhex.size()) > 0 && len < 65536 ) - { - len >>= 1; - decode_hex(buf,len,(char *)rawhex.c_str()); - hash = bits256_doublesha256(0,buf,len); - if ( (hash.bytes[0] & 0xff) == 0 && (hash.bytes[31] & 0xff) == 0 ) - { - fprintf(stderr,"found valid txid after %d iterations %u\n",i,(uint32_t)time(NULL)); - return(rawhex); - } - //fprintf(stderr,"%02x%02x ",hash.bytes[0],hash.bytes[31]); - } - } - fprintf(stderr,"couldnt generate valid txid %u\n",(uint32_t)time(NULL)); - return(""); - } else fprintf(stderr,"cant find Marmara inputs\n"); - return(""); -} - std::string MarmaraFund(uint64_t txfee,int64_t funds) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); From 38705bdb2168e0cc4a328a618524ec43d6f7bceb Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 06:28:04 -1100 Subject: [PATCH 030/110] Syntax --- src/cc/marmara.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index f04941da3..5e9706ca9 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -309,7 +309,7 @@ UniValue MarmaraPoolPayout(uint64_t txfee,int32_t firstheight,double perc,CPubKe for (i=0; i 0 ) { - if ( (pkstr= jstr(jitem(item,0))) != 0 && strlen(pkstr) == 66 ) + if ( (pkstr= jstr(jitem(item,0),0)) != 0 && strlen(pkstr) == 66 ) { totalpayout += payout; decode_hex(buf,33,pkstr); @@ -343,7 +343,7 @@ UniValue MarmaraPoolPayout(uint64_t txfee,int32_t firstheight,double perc,CPubKe { mtx.vout.push_back(MakeCC1of2vout(EVAL_MARMARA,total - totalpayout - txfee,Marmarapk,poolpk)); } - rawtx = FinalizeCCTx(0,cp,mtx,poolpk,txfee,MarmaraCoinbaseOpret('P',height,poolpk))); + rawtx = FinalizeCCTx(0,cp,mtx,poolpk,txfee,MarmaraCoinbaseOpret('P',firstheight,poolpk))); if ( rawtx.size() == 0 ) errorstr = (char *)"couldnt finalize CCtx"; } else errorstr = (char *)"couldnt find any coinbases to payout"; From ee21bd6bc8156e99b3eeb76ef4c552b4b0e19db9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 06:31:29 -1100 Subject: [PATCH 031/110] Coinbaseopret --- src/cc/marmara.cpp | 4 ++-- src/miner.cpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 5e9706ca9..6ba46dc8f 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -139,12 +139,12 @@ CScript Marmara_scriptPubKey(int32_t height,CPubKey pk) return(ccvout.scriptPubKey); } -CScript MarmaraCoinbaseOpret(int32_t height,CPubKey pk) +CScript MarmaraCoinbaseOpret(uint8_t funcid,int32_t height,CPubKey pk) { uint8_t *ptr; //fprintf(stderr,"height.%d pksize.%d\n",height,(int32_t)pk.size()); if ( height > 0 && (height & 1) == 0 && pk.size() == 33 ) - return(EncodeMarmaraCoinbaseOpRet('C',pk,height)); + return(EncodeMarmaraCoinbaseOpRet(funcid,pk,height)); return(CScript()); } diff --git a/src/miner.cpp b/src/miner.cpp index fb9ed8820..5ea5aafe0 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -157,7 +157,7 @@ int32_t verus_staked(CBlock *pBlock, CMutableTransaction &txNew, uint32_t &nBits int32_t komodo_notaryvin(CMutableTransaction &txNew,uint8_t *notarypub33); int32_t decode_hex(uint8_t *bytes,int32_t n,char *hex); CScript Marmara_scriptPubKey(int32_t height,CPubKey pk); -CScript MarmaraCoinbaseOpret(int32_t height,CPubKey pk); +CScript MarmaraCoinbaseOpret(uint8_t funcid,int32_t height,CPubKey pk); CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32_t gpucount, bool isStake) { @@ -545,7 +545,7 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 { txNew.vout.resize(2); txNew.vout[1].nValue = 0; - txNew.vout[1].scriptPubKey = MarmaraCoinbaseOpret(nHeight,pk); + txNew.vout[1].scriptPubKey = MarmaraCoinbaseOpret('C',nHeight,pk); } else if ((uint64_t)(txNew.vout[0].nValue) >= ASSETCHAINS_TIMELOCKGTE) { From 386286c95d7220174ef1a838db0c2a09639d7b82 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 06:47:18 -1100 Subject: [PATCH 032/110] +prints --- src/komodo_bitcoind.h | 8 ++++---- src/komodo_utils.h | 5 +++++ 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index c6eb05324..00ce20853 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1721,10 +1721,10 @@ int64_t komodo_checkcommission(CBlock *pblock,int32_t height) matched = 25; if ( matched == 0 ) { - //int32_t i; - //for (i=0; i<25; i++) - // fprintf(stderr,"%02x",script[i]); - //fprintf(stderr," payment to wrong pubkey scriptlen.%d, scriptpub[%d]\n",scriptlen,(int32_t)ASSETCHAINS_SCRIPTPUB.size()/2); + int32_t i; + for (i=0; i 1 && ASSETCHAINS_MARMARA != 0 ) + { + fprintf(stderr,"-ac_script and -ac_marmara are mutually exclusive\n"); + exit(0); + } if ( ASSETCHAINS_ENDSUBSIDY[0] != 0 || ASSETCHAINS_REWARD[0] != 0 || ASSETCHAINS_HALVING[0] != 0 || ASSETCHAINS_DECAY[0] != 0 || ASSETCHAINS_COMMISSION != 0 || ASSETCHAINS_PUBLIC != 0 || ASSETCHAINS_PRIVATE != 0 || ASSETCHAINS_TXPOW != 0 || ASSETCHAINS_FOUNDERS != 0 || ASSETCHAINS_SCRIPTPUB.size() > 1 || ASSETCHAINS_SELFIMPORT.size() > 0 || ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 || ASSETCHAINS_TIMELOCKGTE != _ASSETCHAINS_TIMELOCKOFF|| ASSETCHAINS_ALGO != ASSETCHAINS_EQUIHASH || ASSETCHAINS_LWMAPOS != 0 || ASSETCHAINS_LASTERA > 0 || ASSETCHAINS_BEAMPORT != 0 || ASSETCHAINS_CODAPORT != 0 || ASSETCHAINS_MARMARA != 0 ) { fprintf(stderr,"perc %.4f%% ac_pub=[%02x%02x%02x...] acsize.%d\n",dstr(ASSETCHAINS_COMMISSION)*100,ASSETCHAINS_OVERRIDE_PUBKEY33[0],ASSETCHAINS_OVERRIDE_PUBKEY33[1],ASSETCHAINS_OVERRIDE_PUBKEY33[2],(int32_t)ASSETCHAINS_SCRIPTPUB.size()); From b02113975d8ca9be2a1d122b0649e6f6d4043bf0 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 06:48:09 -1100 Subject: [PATCH 033/110] -) --- src/cc/marmara.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 6ba46dc8f..bdd7b2be7 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -343,7 +343,7 @@ UniValue MarmaraPoolPayout(uint64_t txfee,int32_t firstheight,double perc,CPubKe { mtx.vout.push_back(MakeCC1of2vout(EVAL_MARMARA,total - totalpayout - txfee,Marmarapk,poolpk)); } - rawtx = FinalizeCCTx(0,cp,mtx,poolpk,txfee,MarmaraCoinbaseOpret('P',firstheight,poolpk))); + rawtx = FinalizeCCTx(0,cp,mtx,poolpk,txfee,MarmaraCoinbaseOpret('P',firstheight,poolpk)); if ( rawtx.size() == 0 ) errorstr = (char *)"couldnt finalize CCtx"; } else errorstr = (char *)"couldnt find any coinbases to payout"; From dda3ecd759fdae1216ad653bd1f85c25fe4f408a Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 06:58:58 -1100 Subject: [PATCH 034/110] Connect marmara_poolpayout --- src/cc/CCMarmara.h | 2 +- src/cc/marmara.cpp | 11 +++-------- src/rpc/server.cpp | 1 + src/rpc/server.h | 1 + src/wallet/rpcwallet.cpp | 13 +++++++++++++ 5 files changed, 19 insertions(+), 9 deletions(-) diff --git a/src/cc/CCMarmara.h b/src/cc/CCMarmara.h index b25f73f4b..4a50c2539 100644 --- a/src/cc/CCMarmara.h +++ b/src/cc/CCMarmara.h @@ -24,7 +24,7 @@ #define MARMARA_MINLOCK (1440 * 3 * 30) #define MARMARA_MAXLOCK (1440 * 24 * 30) uint64_t komodo_block_prg(uint32_t nHeight); -UniValue MarmaraPoolPayout(uint64_t txfee,int32_t firstheight,double perc,CPubKey poolpk,char *jsonstr); // [[pk0, shares0], [pk1, shares1], ...] +UniValue MarmaraPoolPayout(uint64_t txfee,int32_t firstheight,double perc,char *jsonstr); // [[pk0, shares0], [pk1, shares1], ...] bool MarmaraValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index bdd7b2be7..bce201383 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -290,16 +290,11 @@ UniValue MarmaraInfo() return(result); } -UniValue MarmaraPoolPayout(uint64_t txfee,int32_t firstheight,double perc,CPubKey poolpk,char *jsonstr) // [[pk0, shares0], [pk1, shares1], ...] +UniValue MarmaraPoolPayout(uint64_t txfee,int32_t firstheight,double perc,char *jsonstr) // [[pk0, shares0], [pk1, shares1], ...] { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - UniValue result(UniValue::VOBJ); cJSON *item,*array; std::string rawtx; int32_t i,n; uint8_t buf[33]; CPubKey Marmarapk,pk; int64_t payout,total,totalpayout=0; double poolshares,share,shares = 0.; char *pkstr,*errorstr=0; struct CCcontract_info *cp,C; - if ( pubkey2pk(Mypubkey()) != poolpk ) - { - result.push_back(Pair("result","error")); - result.push_back(Pair("error","poolpk is not your pubkey")); - return(result); - } + UniValue result(UniValue::VOBJ); cJSON *item,*array; std::string rawtx; int32_t i,n; uint8_t buf[33]; CPubKey Marmarapk,pk,poolpk; int64_t payout,total,totalpayout=0; double poolshares,share,shares = 0.; char *pkstr,*errorstr=0; struct CCcontract_info *cp,C; + poolpk = pubkey2pk(Mypubkey()); if ( txfee == 0 ) txfee = 10000; cp = CCinit(&C,EVAL_MARMARA); diff --git a/src/rpc/server.cpp b/src/rpc/server.cpp index 1a932382e..56b32c837 100644 --- a/src/rpc/server.cpp +++ b/src/rpc/server.cpp @@ -443,6 +443,7 @@ static const CRPCCommand vRPCCommands[] = // Marmara { "marmara", "Marmaraaddress", &marmaraaddress, true }, + { "marmara", "Marmarapoolpayout", &marmara_poolpayout, true }, // Payments { "payments", "paymentsaddress", &paymentsaddress, true }, diff --git a/src/rpc/server.h b/src/rpc/server.h index 5bdf62799..bd00bb9d1 100644 --- a/src/rpc/server.h +++ b/src/rpc/server.h @@ -272,6 +272,7 @@ extern UniValue pricesstatus(const UniValue& params, bool fHelp); extern UniValue pricesfinish(const UniValue& params, bool fHelp); extern UniValue pegsaddress(const UniValue& params, bool fHelp); extern UniValue marmaraaddress(const UniValue& params, bool fHelp); +extern UniValue marmara_poolpayout(const UniValue& params, bool fHelp); extern UniValue paymentsaddress(const UniValue& params, bool fHelp); extern UniValue gatewaysaddress(const UniValue& params, bool fHelp); extern UniValue gatewayslist(const UniValue& params, bool fHelp); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 79710969a..36e23c93d 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5531,6 +5531,19 @@ UniValue tokenaddress(const UniValue& params, bool fHelp) return(CCaddress(cp,(char *)"Assets",pubkey)); } +UniValue marmara_poolpayout(const UniValue& params, bool fHelp) +{ + int32_t firstheight; double perc; char *jsonstr; + if ( fHelp || params.size() != 3 ) + throw runtime_error("marmara_poolpayout perc firstheight \"[[pubkey:shares], ...]\"\n"); + if ( ensure_CCrequirements() < 0 ) + throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + perc = atof(params[0].get_str().c_str()) / 100.; + firstheight = atol(params[1].get_str().c_str()); + jsonstr = (char *)params[2].get_str().c_str(); + return(MarmaraPoolPayout(0,firstheight,perc,jsonstr)); // [[pk0, shares0], [pk1, shares1], ...] +} + UniValue channelslist(const UniValue& params, bool fHelp) { if ( fHelp || params.size() > 0 ) From 45096107db5fa0104989c9b1105e4a71ebb1e4ea Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 07:24:19 -1100 Subject: [PATCH 035/110] Test --- src/komodo_bitcoind.h | 3 ++- src/miner.cpp | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 00ce20853..b6173def9 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1704,7 +1704,8 @@ int64_t komodo_checkcommission(CBlock *pblock,int32_t height) return(-1); else*/ if ( checktoshis != 0 ) { - script = (uint8_t *)&pblock->vtx[0].vout[1].scriptPubKey[0]; + //script = (uint8_t *)&pblock->vtx[0].vout[1].scriptPubKey[0]; + script = (uint8_t *)pblock->vtx[0].vout[1].scriptPubKey.data(); scriptlen = (int32_t)pblock->vtx[0].vout[1].scriptPubKey.size(); if ( ASSETCHAINS_SCRIPTPUB.size() > 1 ) { diff --git a/src/miner.cpp b/src/miner.cpp index 5ea5aafe0..bdbf7a570 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -589,8 +589,12 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 ptr = (uint8_t *)&txNew.vout[1].scriptPubKey[0]; ptr[0] = 33; for (i=0; i<33; i++) + { ptr[i+1] = ASSETCHAINS_OVERRIDE_PUBKEY33[i]; + fprintf(stderr,"%02x",ptr[i+1]); + } ptr[34] = OP_CHECKSIG; + fprintf(stderr," set ASSETCHAINS_OVERRIDE_PUBKEY33 into vout[1]\n"); } //printf("autocreate commision vout\n"); } From bbc8c98e7180a35287bc699b6595807010dd9ac6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 07:26:24 -1100 Subject: [PATCH 036/110] Syntax --- src/komodo_bitcoind.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index b6173def9..00ce20853 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1704,8 +1704,7 @@ int64_t komodo_checkcommission(CBlock *pblock,int32_t height) return(-1); else*/ if ( checktoshis != 0 ) { - //script = (uint8_t *)&pblock->vtx[0].vout[1].scriptPubKey[0]; - script = (uint8_t *)pblock->vtx[0].vout[1].scriptPubKey.data(); + script = (uint8_t *)&pblock->vtx[0].vout[1].scriptPubKey[0]; scriptlen = (int32_t)pblock->vtx[0].vout[1].scriptPubKey.size(); if ( ASSETCHAINS_SCRIPTPUB.size() > 1 ) { From 18c82335b59c122e76e5f9f81c8208e1083d0cc6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 07:34:05 -1100 Subject: [PATCH 037/110] Test --- src/komodo_bitcoind.h | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 00ce20853..1b8bb85b0 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1699,13 +1699,19 @@ int64_t komodo_checkcommission(CBlock *pblock,int32_t height) if ( ASSETCHAINS_COMMISSION != 0 ) { checktoshis = komodo_commission(pblock,height); - //fprintf(stderr,"height.%d commission %.8f\n",height,(double)checktoshis/COIN); - /*if ( checktoshis > 10000 && pblock->vtx[0].vout.size() != 2 ) jl777: not sure why this was here + if ( checktoshis >= 10000 && pblock->vtx[0].vout.size() < 2 ) + { + fprintf(stderr,"komodo_checkcommission vsize.%d height.%d commission %.8f\n",(int32_t)pblock->vtx[0].vout.size(),height,(double)checktoshis/COIN); return(-1); - else*/ if ( checktoshis != 0 ) + } + else if ( checktoshis != 0 ) { script = (uint8_t *)&pblock->vtx[0].vout[1].scriptPubKey[0]; scriptlen = (int32_t)pblock->vtx[0].vout[1].scriptPubKey.size(); + int32_t i; + for (i=0; ivtx[0].vout[1].nValue/COIN)); if ( ASSETCHAINS_SCRIPTPUB.size() > 1 ) { if ( ASSETCHAINS_SCRIPTPUB.size()/2 == scriptlen && scriptlen < sizeof(scripthex) ) @@ -1721,9 +1727,6 @@ int64_t komodo_checkcommission(CBlock *pblock,int32_t height) matched = 25; if ( matched == 0 ) { - int32_t i; - for (i=0; ivtx[0].vout[0].scriptPubKey[0]; - if ( script[0] != 33 || script[34] != OP_CHECKSIG || memcmp(script+1,ASSETCHAINS_OVERRIDE_PUBKEY33,33) != 0 ) + scriptlen = (int32_t)pblock->vtx[0].vout[0].scriptPubKey.size(); + if ( scriptlen != 35 || script[0] != 33 || script[34] != OP_CHECKSIG || memcmp(script+1,ASSETCHAINS_OVERRIDE_PUBKEY33,33) != 0 ) return(-1); } } From 36a74b8d2787ba7ee5ab2976daa33e94c1cf0090 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 07:34:48 -1100 Subject: [PATCH 038/110] -) --- src/komodo_bitcoind.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 1b8bb85b0..a36e1f744 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1711,7 +1711,7 @@ int64_t komodo_checkcommission(CBlock *pblock,int32_t height) int32_t i; for (i=0; ivtx[0].vout[1].nValue/COIN)); + fprintf(stderr," vout[1] %.8f vs %.8f\n",(double)checktoshis/COIN,(double)pblock->vtx[0].vout[1].nValue/COIN); if ( ASSETCHAINS_SCRIPTPUB.size() > 1 ) { if ( ASSETCHAINS_SCRIPTPUB.size()/2 == scriptlen && scriptlen < sizeof(scripthex) ) From 43cbde9fe4f46baf17f6a6618c13e2f60a07cfed Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 07:35:50 -1100 Subject: [PATCH 039/110] scriptlen --- src/komodo_bitcoind.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index a36e1f744..341ee49e2 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1745,7 +1745,7 @@ bool KOMODO_TEST_ASSETCHAIN_SKIP_POW = 0; int32_t komodo_checkPOW(int32_t slowflag,CBlock *pblock,int32_t height) { - uint256 hash; arith_uint256 bnTarget,bhash; bool fNegative,fOverflow; uint8_t *script,pubkey33[33],pubkeys[64][33]; int32_t i,possible,PoSperc,is_PoSblock=0,n,failed = 0,notaryid = -1; int64_t checktoshis,value; CBlockIndex *pprev; + uint256 hash; arith_uint256 bnTarget,bhash; bool fNegative,fOverflow; uint8_t *script,pubkey33[33],pubkeys[64][33]; int32_t i,scriptlen,possible,PoSperc,is_PoSblock=0,n,failed = 0,notaryid = -1; int64_t checktoshis,value; CBlockIndex *pprev; if ( KOMODO_TEST_ASSETCHAIN_SKIP_POW == 0 && Params().NetworkIDString() == "regtest" ) KOMODO_TEST_ASSETCHAIN_SKIP_POW = 1; if ( !CheckEquihashSolution(pblock, Params()) ) From e3110f16fb9b75524cb11688d67d6cad8068dc37 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 07:41:26 -1100 Subject: [PATCH 040/110] Change priority of mining ac_variants --- src/miner.cpp | 44 ++++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/src/miner.cpp b/src/miner.cpp index bdbf7a570..5bf230050 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -547,28 +547,6 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 txNew.vout[1].nValue = 0; txNew.vout[1].scriptPubKey = MarmaraCoinbaseOpret('C',nHeight,pk); } - else if ((uint64_t)(txNew.vout[0].nValue) >= ASSETCHAINS_TIMELOCKGTE) - { - int32_t opretlen, p2shlen, scriptlen; - CScriptExt opretScript = CScriptExt(); - - txNew.vout.resize(2); - - // prepend time lock to original script unless original script is P2SH, in which case, we will leave the coins - // protected only by the time lock rather than 100% inaccessible - opretScript.AddCheckLockTimeVerify(komodo_block_unlocktime(nHeight)); - if (scriptPubKeyIn.IsPayToScriptHash() || scriptPubKeyIn.IsPayToCryptoCondition()) - { - fprintf(stderr,"CreateNewBlock: attempt to add timelock to pay2sh or pay2cc\n"); - return 0; - } - - opretScript += scriptPubKeyIn; - - txNew.vout[0].scriptPubKey = CScriptExt().PayToScriptHash(CScriptID(opretScript)); - txNew.vout[1].scriptPubKey = CScriptExt().OpReturnScript(opretScript, OPRETTYPE_TIMELOCK); - txNew.vout[1].nValue = 0; - } // timelocks and commissions are currently incompatible due to validation complexity of the combination else if ( nHeight > 1 && ASSETCHAINS_SYMBOL[0] != 0 && (ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 || ASSETCHAINS_SCRIPTPUB.size() > 1) && ASSETCHAINS_COMMISSION != 0 && (commission= komodo_commission((CBlock*)&pblocktemplate->block,(int32_t)nHeight)) != 0 ) { int32_t i; uint8_t *ptr; @@ -598,6 +576,28 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 } //printf("autocreate commision vout\n"); } + else if ((uint64_t)(txNew.vout[0].nValue) >= ASSETCHAINS_TIMELOCKGTE) + { + int32_t opretlen, p2shlen, scriptlen; + CScriptExt opretScript = CScriptExt(); + + txNew.vout.resize(2); + + // prepend time lock to original script unless original script is P2SH, in which case, we will leave the coins + // protected only by the time lock rather than 100% inaccessible + opretScript.AddCheckLockTimeVerify(komodo_block_unlocktime(nHeight)); + if (scriptPubKeyIn.IsPayToScriptHash() || scriptPubKeyIn.IsPayToCryptoCondition()) + { + fprintf(stderr,"CreateNewBlock: attempt to add timelock to pay2sh or pay2cc\n"); + return 0; + } + + opretScript += scriptPubKeyIn; + + txNew.vout[0].scriptPubKey = CScriptExt().PayToScriptHash(CScriptID(opretScript)); + txNew.vout[1].scriptPubKey = CScriptExt().OpReturnScript(opretScript, OPRETTYPE_TIMELOCK); + txNew.vout[1].nValue = 0; + } // timelocks and commissions are currently incompatible due to validation complexity of the combination pblock->vtx[0] = txNew; pblocktemplate->vTxFees[0] = -nFees; From 6f345c4ed1e0247a148df575756ec062a12ad743 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 07:48:13 -1100 Subject: [PATCH 041/110] +prints --- src/komodo_bitcoind.h | 10 +++++----- src/miner.cpp | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 341ee49e2..c647b1692 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1162,7 +1162,7 @@ uint64_t komodo_commission(const CBlock *pblock,int32_t height) n = pblock->vtx[i].vout.size(); for (j=0; jvtx[i].vout[j].nValue; } @@ -1708,10 +1708,10 @@ int64_t komodo_checkcommission(CBlock *pblock,int32_t height) { script = (uint8_t *)&pblock->vtx[0].vout[1].scriptPubKey[0]; scriptlen = (int32_t)pblock->vtx[0].vout[1].scriptPubKey.size(); - int32_t i; - for (i=0; ivtx[0].vout[1].nValue/COIN); + //int32_t i; + //for (i=0; ivtx[0].vout[1].nValue/COIN); if ( ASSETCHAINS_SCRIPTPUB.size() > 1 ) { if ( ASSETCHAINS_SCRIPTPUB.size()/2 == scriptlen && scriptlen < sizeof(scripthex) ) diff --git a/src/miner.cpp b/src/miner.cpp index 5bf230050..dc476b4c3 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -576,7 +576,7 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 } //printf("autocreate commision vout\n"); } - else if ((uint64_t)(txNew.vout[0].nValue) >= ASSETCHAINS_TIMELOCKGTE) + else if ( (uint64_t)(txNew.vout[0].nValue) >= ASSETCHAINS_TIMELOCKGTE) { int32_t opretlen, p2shlen, scriptlen; CScriptExt opretScript = CScriptExt(); From 8ffe7c1119f6a8b3bf3aba589be0ca5bc2280b46 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 07:48:58 -1100 Subject: [PATCH 042/110] Block --- src/komodo_bitcoind.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index c647b1692..64faa28bc 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1162,7 +1162,7 @@ uint64_t komodo_commission(const CBlock *pblock,int32_t height) n = pblock->vtx[i].vout.size(); for (j=0; jvtx[i].vout[j].nValue),j); if ( i != 0 || j != 1 ) total += pblock->vtx[i].vout[j].nValue; } From 5ddb8a234694978fa34034a2e48e043f9c5fedf5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 07:56:04 -1100 Subject: [PATCH 043/110] Test --- src/komodo_bitcoind.h | 1 + src/miner.cpp | 1 + 2 files changed, 2 insertions(+) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 64faa28bc..82abfb1f2 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1171,6 +1171,7 @@ uint64_t komodo_commission(const CBlock *pblock,int32_t height) } if ( commission < 10000 ) commission = 0; + fprintf(stderr,"-> %.8f\n",(double)commission/COIN); return(commission); } diff --git a/src/miner.cpp b/src/miner.cpp index dc476b4c3..71366bd12 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -554,6 +554,7 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 txNew.vout[1].nValue = commission; if ( ASSETCHAINS_SCRIPTPUB.size() > 1 ) { + fprintf(stderr,"mine to -ac_script\n"); //txNew.vout[1].scriptPubKey = CScript() << ParseHex(); int32_t len = strlen(ASSETCHAINS_SCRIPTPUB.c_str()); len >>= 1; From 36a962d0b58d95ed61acd640776149d2130e052b Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 08:02:03 -1100 Subject: [PATCH 044/110] Test --- src/miner.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/miner.cpp b/src/miner.cpp index 71366bd12..0e7c093de 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -539,6 +539,7 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 if ( ASSETCHAINS_SYMBOL[0] == 0 && IS_KOMODO_NOTARY != 0 && My_notaryid >= 0 ) txNew.vout[0].nValue += 5000; + fprintf(stderr,"ht.%d cmp.%d\n",nHeight,nHeight > 1 && ASSETCHAINS_SYMBOL[0] != 0 && (ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 || ASSETCHAINS_SCRIPTPUB.size() > 1) && ASSETCHAINS_COMMISSION != 0 && (commission= komodo_commission((CBlock*)&pblocktemplate->block,(int32_t)nHeight)) != 0); // check if coinbase transactions must be time locked at current subsidy and prepend the time lock // to transaction if so, cast for GTE operator if ( ASSETCHAINS_MARMARA != 0 && nHeight > 0 && (nHeight & 1) == 0 ) From c877777d7b88874b098fcdae3a42bc884e22115f Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 08:04:38 -1100 Subject: [PATCH 045/110] +print --- src/miner.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/miner.cpp b/src/miner.cpp index 0e7c093de..a5712025f 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -539,7 +539,7 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 if ( ASSETCHAINS_SYMBOL[0] == 0 && IS_KOMODO_NOTARY != 0 && My_notaryid >= 0 ) txNew.vout[0].nValue += 5000; - fprintf(stderr,"ht.%d cmp.%d\n",nHeight,nHeight > 1 && ASSETCHAINS_SYMBOL[0] != 0 && (ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 || ASSETCHAINS_SCRIPTPUB.size() > 1) && ASSETCHAINS_COMMISSION != 0 && (commission= komodo_commission((CBlock*)&pblocktemplate->block,(int32_t)nHeight)) != 0); + fprintf(stderr,"ht.%d cmp.%d [%d %d %d %d %d]\n",nHeight,nHeight > 1 && ASSETCHAINS_SYMBOL[0] != 0 && (ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 || ASSETCHAINS_SCRIPTPUB.size() > 1) && ASSETCHAINS_COMMISSION != 0 && (commission= komodo_commission((CBlock*)&pblocktemplate->block,(int32_t)nHeight)) != 0,nHeight > 1,ASSETCHAINS_SYMBOL[0] != 0, (ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 || ASSETCHAINS_SCRIPTPUB.size() > 1), ASSETCHAINS_COMMISSION != 0,(commission= komodo_commission((CBlock*)&pblocktemplate->block,(int32_t)nHeight)) != 0); // check if coinbase transactions must be time locked at current subsidy and prepend the time lock // to transaction if so, cast for GTE operator if ( ASSETCHAINS_MARMARA != 0 && nHeight > 0 && (nHeight & 1) == 0 ) From de4aed1a620e2406b01e53116b12c9970c0c1efb Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 08:07:56 -1100 Subject: [PATCH 046/110] pblock->vtx[0] = txNew; --- src/miner.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/miner.cpp b/src/miner.cpp index a5712025f..f634be072 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -538,6 +538,7 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 if ( ASSETCHAINS_SYMBOL[0] == 0 && IS_KOMODO_NOTARY != 0 && My_notaryid >= 0 ) txNew.vout[0].nValue += 5000; + pblock->vtx[0] = txNew; fprintf(stderr,"ht.%d cmp.%d [%d %d %d %d %d]\n",nHeight,nHeight > 1 && ASSETCHAINS_SYMBOL[0] != 0 && (ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 || ASSETCHAINS_SCRIPTPUB.size() > 1) && ASSETCHAINS_COMMISSION != 0 && (commission= komodo_commission((CBlock*)&pblocktemplate->block,(int32_t)nHeight)) != 0,nHeight > 1,ASSETCHAINS_SYMBOL[0] != 0, (ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 || ASSETCHAINS_SCRIPTPUB.size() > 1), ASSETCHAINS_COMMISSION != 0,(commission= komodo_commission((CBlock*)&pblocktemplate->block,(int32_t)nHeight)) != 0); // check if coinbase transactions must be time locked at current subsidy and prepend the time lock From 34a26023f206dbbad74abe4cacfa469af4cd6c2b Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 08:09:54 -1100 Subject: [PATCH 047/110] Test --- src/komodo_bitcoind.h | 6 +++--- src/miner.cpp | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 82abfb1f2..6e6dc7b35 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1162,7 +1162,7 @@ uint64_t komodo_commission(const CBlock *pblock,int32_t height) n = pblock->vtx[i].vout.size(); for (j=0; jvtx[i].vout[j].nValue),j); + //fprintf(stderr,"(%d %.8f).%d ",i,dstr(pblock->vtx[i].vout[j].nValue),j); if ( i != 0 || j != 1 ) total += pblock->vtx[i].vout[j].nValue; } @@ -1171,7 +1171,7 @@ uint64_t komodo_commission(const CBlock *pblock,int32_t height) } if ( commission < 10000 ) commission = 0; - fprintf(stderr,"-> %.8f\n",(double)commission/COIN); + //fprintf(stderr,"-> %.8f\n",(double)commission/COIN); return(commission); } @@ -1702,7 +1702,7 @@ int64_t komodo_checkcommission(CBlock *pblock,int32_t height) checktoshis = komodo_commission(pblock,height); if ( checktoshis >= 10000 && pblock->vtx[0].vout.size() < 2 ) { - fprintf(stderr,"komodo_checkcommission vsize.%d height.%d commission %.8f\n",(int32_t)pblock->vtx[0].vout.size(),height,(double)checktoshis/COIN); + //fprintf(stderr,"komodo_checkcommission vsize.%d height.%d commission %.8f\n",(int32_t)pblock->vtx[0].vout.size(),height,(double)checktoshis/COIN); return(-1); } else if ( checktoshis != 0 ) diff --git a/src/miner.cpp b/src/miner.cpp index f634be072..128a94e3a 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -540,7 +540,7 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 txNew.vout[0].nValue += 5000; pblock->vtx[0] = txNew; - fprintf(stderr,"ht.%d cmp.%d [%d %d %d %d %d]\n",nHeight,nHeight > 1 && ASSETCHAINS_SYMBOL[0] != 0 && (ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 || ASSETCHAINS_SCRIPTPUB.size() > 1) && ASSETCHAINS_COMMISSION != 0 && (commission= komodo_commission((CBlock*)&pblocktemplate->block,(int32_t)nHeight)) != 0,nHeight > 1,ASSETCHAINS_SYMBOL[0] != 0, (ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 || ASSETCHAINS_SCRIPTPUB.size() > 1), ASSETCHAINS_COMMISSION != 0,(commission= komodo_commission((CBlock*)&pblocktemplate->block,(int32_t)nHeight)) != 0); + //fprintf(stderr,"ht.%d cmp.%d [%d %d %d %d %d]\n",nHeight,nHeight > 1 && ASSETCHAINS_SYMBOL[0] != 0 && (ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 || ASSETCHAINS_SCRIPTPUB.size() > 1) && ASSETCHAINS_COMMISSION != 0 && (commission= komodo_commission((CBlock*)&pblocktemplate->block,(int32_t)nHeight)) != 0,nHeight > 1,ASSETCHAINS_SYMBOL[0] != 0, (ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 || ASSETCHAINS_SCRIPTPUB.size() > 1), ASSETCHAINS_COMMISSION != 0,(commission= komodo_commission((CBlock*)&pblocktemplate->block,(int32_t)nHeight)) != 0); // check if coinbase transactions must be time locked at current subsidy and prepend the time lock // to transaction if so, cast for GTE operator if ( ASSETCHAINS_MARMARA != 0 && nHeight > 0 && (nHeight & 1) == 0 ) @@ -572,10 +572,10 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 for (i=0; i<33; i++) { ptr[i+1] = ASSETCHAINS_OVERRIDE_PUBKEY33[i]; - fprintf(stderr,"%02x",ptr[i+1]); + //fprintf(stderr,"%02x",ptr[i+1]); } ptr[34] = OP_CHECKSIG; - fprintf(stderr," set ASSETCHAINS_OVERRIDE_PUBKEY33 into vout[1]\n"); + //fprintf(stderr," set ASSETCHAINS_OVERRIDE_PUBKEY33 into vout[1]\n"); } //printf("autocreate commision vout\n"); } From 4c900a4708e44e4cc68a689ccc9f503a78f6dc11 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 08:21:57 -1100 Subject: [PATCH 048/110] Son --- src/rpc/server.cpp | 4 ++-- src/wallet/rpcwallet.cpp | 5 ++++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/rpc/server.cpp b/src/rpc/server.cpp index 56b32c837..d6b801dd5 100644 --- a/src/rpc/server.cpp +++ b/src/rpc/server.cpp @@ -442,8 +442,8 @@ static const CRPCCommand vRPCCommands[] = { "pegs", "pegsaddress", &pegsaddress, true }, // Marmara - { "marmara", "Marmaraaddress", &marmaraaddress, true }, - { "marmara", "Marmarapoolpayout", &marmara_poolpayout, true }, + { "marmara", "marmaraaddress", &marmaraaddress, true }, + { "marmara", "marmarapoolpayout", &marmara_poolpayout, true }, // Payments { "payments", "paymentsaddress", &paymentsaddress, true }, diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 36e23c93d..a4b30e383 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5535,7 +5535,10 @@ UniValue marmara_poolpayout(const UniValue& params, bool fHelp) { int32_t firstheight; double perc; char *jsonstr; if ( fHelp || params.size() != 3 ) - throw runtime_error("marmara_poolpayout perc firstheight \"[[pubkey:shares], ...]\"\n"); + { + fprintf(stderr,"params.size %d\n",(int32_t)params.size()); + throw runtime_error("marmara_poolpayout perc firstheight \"[[\\\"pubkey\\\":shares], ...]\"\n"); + } if ( ensure_CCrequirements() < 0 ) throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); perc = atof(params[0].get_str().c_str()) / 100.; From 3fb0d3a82adaf30138f5d98a4575cc17d6312d67 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 08:24:41 -1100 Subject: [PATCH 049/110] Test --- src/cc/marmara.cpp | 2 +- src/wallet/rpcwallet.cpp | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index bce201383..bb06b3e39 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -178,7 +178,7 @@ int32_t MarmaraValidateCoinbase(int32_t height,CTransaction tx) { if ( ht == height && MarmaraUnlockht(height) == unlockht ) { - fprintf(stderr,"ht.%d -> unlock.%d\n",ht,unlockht); + //fprintf(stderr,"ht.%d -> unlock.%d\n",ht,unlockht); ccvout = MakeCC1vout(EVAL_MARMARA,0,pk); if ( ccvout.scriptPubKey == tx.vout[0].scriptPubKey ) return(0); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index a4b30e383..4a7024eb4 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5534,7 +5534,7 @@ UniValue tokenaddress(const UniValue& params, bool fHelp) UniValue marmara_poolpayout(const UniValue& params, bool fHelp) { int32_t firstheight; double perc; char *jsonstr; - if ( fHelp || params.size() != 3 ) + if ( fHelp || params.size() < 3 ) { fprintf(stderr,"params.size %d\n",(int32_t)params.size()); throw runtime_error("marmara_poolpayout perc firstheight \"[[\\\"pubkey\\\":shares], ...]\"\n"); @@ -5544,6 +5544,7 @@ UniValue marmara_poolpayout(const UniValue& params, bool fHelp) perc = atof(params[0].get_str().c_str()) / 100.; firstheight = atol(params[1].get_str().c_str()); jsonstr = (char *)params[2].get_str().c_str(); + fprintf(stderr,"perc %.2f ht.%d (%s)\n",perc,firstheight,jsonstr); return(MarmaraPoolPayout(0,firstheight,perc,jsonstr)); // [[pk0, shares0], [pk1, shares1], ...] } From 1e17cbc61790d8c0c0bd8ee4df21b05aff73908c Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 08:26:54 -1100 Subject: [PATCH 050/110] -print --- src/main.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index cd3c0d35f..44dab5ed1 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3462,7 +3462,8 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin { if ( block.vtx[0].vout.size() >= 2 && block.vtx[0].vout[1].nValue == checktoshis ) blockReward += checktoshis; - else fprintf(stderr,"checktoshis %.8f numvouts %d\n",dstr(checktoshis),(int32_t)block.vtx[0].vout.size()); + else if ( pindex->nHeight > 1 ) + fprintf(stderr,"checktoshis %.8f vs %.8f numvouts %d\n",dstr(checktoshis),dstr(block.vtx[0].vout[1].nValue),(int32_t)block.vtx[0].vout.size()); } } if (ASSETCHAINS_SYMBOL[0] != 0 && pindex->GetHeight() == 1 && block.vtx[0].GetValueOut() != blockReward) From 7ebf1d817686b6dfe32465235b5ba3739bd250a2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 08:41:23 -1100 Subject: [PATCH 051/110] +print --- src/cc/marmara.cpp | 31 ++++++++++++++++++------------- src/wallet/rpcwallet.cpp | 2 +- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index bb06b3e39..353f3edba 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -237,26 +237,31 @@ int64_t AddMarmaraCoinbases(struct CCcontract_info *cp,CMutableTransaction &mtx, GetCCaddress(cp,coinaddr,poolpk); SetCCunspents(unspentOutputs,coinaddr); unlocks = MarmaraUnlockht(firstheight); + fprintf(stderr,"check coinaddr.(%s)\n",coinaddr); for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) { txid = it->first.txhash; vout = (int32_t)it->first.index; - if ( GetTransaction(txid,vintx,hashBlock,false) != 0 && vintx.IsCoinBase() != 0 ) + fprintf(stderr,"txid.%s/v%d\n",txid.GetHex().c_str(),vout); + if ( GetTransaction(txid,vintx,hashBlock,false) != 0 ) { - if ( DecodeMaramaraCoinbaseOpRet(vintx.vout[1].scriptPubKey,pk,ht,unlockht) == 'C' && unlockht == unlocks && pk == poolpk ) + if ( vintx.IsCoinBase() != 0 ) { - if ( (nValue= IsMarmaravout(cp,vintx,vout)) > 0 && myIsutxo_spentinmempool(txid,vout) == 0 ) + if ( DecodeMaramaraCoinbaseOpRet(vintx.vout[1].scriptPubKey,pk,ht,unlockht) == 'C' && unlockht == unlocks && pk == poolpk ) { - if ( maxinputs != 0 ) - mtx.vin.push_back(CTxIn(txid,vout,CScript())); - nValue = it->second.satoshis; - totalinputs += nValue; - n++; - if ( maxinputs > 0 && n >= maxinputs ) - break; - } - } - } + if ( (nValue= IsMarmaravout(cp,vintx,vout)) > 0 && myIsutxo_spentinmempool(txid,vout) == 0 ) + { + if ( maxinputs != 0 ) + mtx.vin.push_back(CTxIn(txid,vout,CScript())); + nValue = it->second.satoshis; + totalinputs += nValue; + n++; + if ( maxinputs > 0 && n >= maxinputs ) + break; + } else fprintf(stderr,"nValue.%8f\n",(double)nValue/COIN); + } else fprintf(stderr,"decode error\n"); + } else fprintf(stderr,"not coinbase\n"); + } else fprintf(stderr,"error getting tx\n"); } return(totalinputs); } diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 4a7024eb4..6a2a351dc 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5544,7 +5544,7 @@ UniValue marmara_poolpayout(const UniValue& params, bool fHelp) perc = atof(params[0].get_str().c_str()) / 100.; firstheight = atol(params[1].get_str().c_str()); jsonstr = (char *)params[2].get_str().c_str(); - fprintf(stderr,"perc %.2f ht.%d (%s)\n",perc,firstheight,jsonstr); + fprintf(stderr,"perc %.8f ht.%d (%s)\n",perc,firstheight,jsonstr); return(MarmaraPoolPayout(0,firstheight,perc,jsonstr)); // [[pk0, shares0], [pk1, shares1], ...] } From 80c61ba5053b5ba20898e6134aa29217b3634b3a Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 08:44:14 -1100 Subject: [PATCH 052/110] ->GetHeight() --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 44dab5ed1..929ec9d5e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3462,7 +3462,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin { if ( block.vtx[0].vout.size() >= 2 && block.vtx[0].vout[1].nValue == checktoshis ) blockReward += checktoshis; - else if ( pindex->nHeight > 1 ) + else if ( pindex->GetHeight() > 1 ) fprintf(stderr,"checktoshis %.8f vs %.8f numvouts %d\n",dstr(checktoshis),dstr(block.vtx[0].vout[1].nValue),(int32_t)block.vtx[0].vout.size()); } } From c31f8ea3d57d400bd4d51967196efd345a4399ca Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 08:52:30 -1100 Subject: [PATCH 053/110] Test --- src/cc/marmara.cpp | 5 +++-- src/wallet/rpcwallet.cpp | 3 +-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 353f3edba..66d082cb9 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -124,6 +124,7 @@ uint8_t DecodeMaramaraCoinbaseOpRet(const CScript scriptPubKey,CPubKey &pk,int32 { if ( E_UNMARSHAL(vopret,ss >> e; ss >> f; ss >> pk; ss >> height; ss >> unlockht) != 0 ) { + fprintf(stderr,"return %c\n",script[1]); return(script[1]); } else fprintf(stderr,"DecodeMaramaraCoinbaseOpRet unmarshal error for %c\n",script[1]); } else fprintf(stderr,"script[1] is %d != 'C' %d or 'P' %d\n",script[1],'C','P'); @@ -245,7 +246,7 @@ int64_t AddMarmaraCoinbases(struct CCcontract_info *cp,CMutableTransaction &mtx, fprintf(stderr,"txid.%s/v%d\n",txid.GetHex().c_str(),vout); if ( GetTransaction(txid,vintx,hashBlock,false) != 0 ) { - if ( vintx.IsCoinBase() != 0 ) + if ( vintx.IsCoinBase() != 0 && vintx.vout.size() == 2 && vintx.vout[1].nValue == 0 ) { if ( DecodeMaramaraCoinbaseOpRet(vintx.vout[1].scriptPubKey,pk,ht,unlockht) == 'C' && unlockht == unlocks && pk == poolpk ) { @@ -259,7 +260,7 @@ int64_t AddMarmaraCoinbases(struct CCcontract_info *cp,CMutableTransaction &mtx, if ( maxinputs > 0 && n >= maxinputs ) break; } else fprintf(stderr,"nValue.%8f\n",(double)nValue/COIN); - } else fprintf(stderr,"decode error\n"); + } else fprintf(stderr,"decode error unlockht.%d vs %d pk.%d\n",unlockht,unlocks,pk == poolpk); } else fprintf(stderr,"not coinbase\n"); } else fprintf(stderr,"error getting tx\n"); } diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 6a2a351dc..fc9655ec1 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5536,7 +5536,7 @@ UniValue marmara_poolpayout(const UniValue& params, bool fHelp) int32_t firstheight; double perc; char *jsonstr; if ( fHelp || params.size() < 3 ) { - fprintf(stderr,"params.size %d\n",(int32_t)params.size()); + // marmarapoolpayout "0.5" 2 '[["024131032ed90941e714db8e6dd176fe5a86c9d873d279edecf005c06f773da686",1000],["02ebc786cb83de8dc3922ab83c21f3f8a2f3216940c3bf9da43ce39e2a3a882c92",100]]'; throw runtime_error("marmara_poolpayout perc firstheight \"[[\\\"pubkey\\\":shares], ...]\"\n"); } if ( ensure_CCrequirements() < 0 ) @@ -5544,7 +5544,6 @@ UniValue marmara_poolpayout(const UniValue& params, bool fHelp) perc = atof(params[0].get_str().c_str()) / 100.; firstheight = atol(params[1].get_str().c_str()); jsonstr = (char *)params[2].get_str().c_str(); - fprintf(stderr,"perc %.8f ht.%d (%s)\n",perc,firstheight,jsonstr); return(MarmaraPoolPayout(0,firstheight,perc,jsonstr)); // [[pk0, shares0], [pk1, shares1], ...] } From f6af25e545ee3ff9e9da583c8039d4c88bd8b7f1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 08:56:00 -1100 Subject: [PATCH 054/110] Test --- src/cc/marmara.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 66d082cb9..304d97f74 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -250,7 +250,7 @@ int64_t AddMarmaraCoinbases(struct CCcontract_info *cp,CMutableTransaction &mtx, { if ( DecodeMaramaraCoinbaseOpRet(vintx.vout[1].scriptPubKey,pk,ht,unlockht) == 'C' && unlockht == unlocks && pk == poolpk ) { - if ( (nValue= IsMarmaravout(cp,vintx,vout)) > 0 && myIsutxo_spentinmempool(txid,vout) == 0 ) + if ( (nValue= vintx.vout[vout].nValue) > 0 && myIsutxo_spentinmempool(txid,vout) == 0 ) { if ( maxinputs != 0 ) mtx.vin.push_back(CTxIn(txid,vout,CScript())); From fefe5dbd246bfc1139d0556ffed441d45bf3265b Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 08:59:23 -1100 Subject: [PATCH 055/110] Args 3 --- src/cc/marmara.cpp | 1 - src/wallet/rpcwallet.cpp | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 304d97f74..b3be7cb32 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -124,7 +124,6 @@ uint8_t DecodeMaramaraCoinbaseOpRet(const CScript scriptPubKey,CPubKey &pk,int32 { if ( E_UNMARSHAL(vopret,ss >> e; ss >> f; ss >> pk; ss >> height; ss >> unlockht) != 0 ) { - fprintf(stderr,"return %c\n",script[1]); return(script[1]); } else fprintf(stderr,"DecodeMaramaraCoinbaseOpRet unmarshal error for %c\n",script[1]); } else fprintf(stderr,"script[1] is %d != 'C' %d or 'P' %d\n",script[1],'C','P'); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index fc9655ec1..2bc4aeeba 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5534,7 +5534,7 @@ UniValue tokenaddress(const UniValue& params, bool fHelp) UniValue marmara_poolpayout(const UniValue& params, bool fHelp) { int32_t firstheight; double perc; char *jsonstr; - if ( fHelp || params.size() < 3 ) + if ( fHelp || params.size() != 3 ) { // marmarapoolpayout "0.5" 2 '[["024131032ed90941e714db8e6dd176fe5a86c9d873d279edecf005c06f773da686",1000],["02ebc786cb83de8dc3922ab83c21f3f8a2f3216940c3bf9da43ce39e2a3a882c92",100]]'; throw runtime_error("marmara_poolpayout perc firstheight \"[[\\\"pubkey\\\":shares], ...]\"\n"); From 028725471c7a176605512ec4e3d5e7c9185f8b2b Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 09:17:22 -1100 Subject: [PATCH 056/110] Total field --- src/cc/marmara.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index b3be7cb32..103e8d51a 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -364,6 +364,7 @@ UniValue MarmaraPoolPayout(uint64_t txfee,int32_t firstheight,double perc,char * result.push_back(Pair("rawtx",rawtx)); if ( totalpayout > 0 && total > totalpayout-txfee ) { + result.push_back(Pair("total",(double)total/COIN)); result.push_back(Pair("totalpayout",(double)totalpayout/COIN)); result.push_back(Pair("totalshares",shares)); result.push_back(Pair("poolfee",(double)(total - totalpayout)/COIN)); From 1b46c66023b207223070d06740516e1e8082987c Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 09:21:54 -1100 Subject: [PATCH 057/110] Payouts --- src/cc/marmara.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 103e8d51a..852ac8469 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -237,12 +237,12 @@ int64_t AddMarmaraCoinbases(struct CCcontract_info *cp,CMutableTransaction &mtx, GetCCaddress(cp,coinaddr,poolpk); SetCCunspents(unspentOutputs,coinaddr); unlocks = MarmaraUnlockht(firstheight); - fprintf(stderr,"check coinaddr.(%s)\n",coinaddr); + //fprintf(stderr,"check coinaddr.(%s)\n",coinaddr); for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) { txid = it->first.txhash; vout = (int32_t)it->first.index; - fprintf(stderr,"txid.%s/v%d\n",txid.GetHex().c_str(),vout); + //fprintf(stderr,"txid.%s/v%d\n",txid.GetHex().c_str(),vout); if ( GetTransaction(txid,vintx,hashBlock,false) != 0 ) { if ( vintx.IsCoinBase() != 0 && vintx.vout.size() == 2 && vintx.vout[1].nValue == 0 ) @@ -259,7 +259,7 @@ int64_t AddMarmaraCoinbases(struct CCcontract_info *cp,CMutableTransaction &mtx, if ( maxinputs > 0 && n >= maxinputs ) break; } else fprintf(stderr,"nValue.%8f\n",(double)nValue/COIN); - } else fprintf(stderr,"decode error unlockht.%d vs %d pk.%d\n",unlockht,unlocks,pk == poolpk); + } //else fprintf(stderr,"decode error unlockht.%d vs %d pk.%d\n",unlockht,unlocks,pk == poolpk); } else fprintf(stderr,"not coinbase\n"); } else fprintf(stderr,"error getting tx\n"); } @@ -298,7 +298,7 @@ UniValue MarmaraInfo() UniValue MarmaraPoolPayout(uint64_t txfee,int32_t firstheight,double perc,char *jsonstr) // [[pk0, shares0], [pk1, shares1], ...] { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - UniValue result(UniValue::VOBJ); cJSON *item,*array; std::string rawtx; int32_t i,n; uint8_t buf[33]; CPubKey Marmarapk,pk,poolpk; int64_t payout,total,totalpayout=0; double poolshares,share,shares = 0.; char *pkstr,*errorstr=0; struct CCcontract_info *cp,C; + UniValue result(UniValue::VOBJ),a(UniValue::VARR); cJSON *item,*array; std::string rawtx; int32_t i,n; uint8_t buf[33]; CPubKey Marmarapk,pk,poolpk; int64_t payout,total,totalpayout=0; double poolshares,share,shares = 0.; char *pkstr,*errorstr=0; struct CCcontract_info *cp,C; poolpk = pubkey2pk(Mypubkey()); if ( txfee == 0 ) txfee = 10000; @@ -335,6 +335,7 @@ UniValue MarmaraPoolPayout(uint64_t txfee,int32_t firstheight,double perc,char * totalpayout += payout; decode_hex(buf,33,pkstr); mtx.vout.push_back(MakeCC1of2vout(EVAL_MARMARA,payout,Marmarapk,buf2pk(buf))); + a.push_back(Pair(pkstr,(double)payout/COIN)); } } } @@ -369,6 +370,7 @@ UniValue MarmaraPoolPayout(uint64_t txfee,int32_t firstheight,double perc,char * result.push_back(Pair("totalshares",shares)); result.push_back(Pair("poolfee",(double)(total - totalpayout)/COIN)); result.push_back(Pair("perc",100. * (double)(total - totalpayout)/totalpayout)); + result.push_back(Pair("payouts",a); } } return(result); From cdbdf8662b712b643266f44a736f56c1b81967d1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 09:23:02 -1100 Subject: [PATCH 058/110] +) --- src/cc/marmara.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 852ac8469..82d0a9995 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -370,7 +370,7 @@ UniValue MarmaraPoolPayout(uint64_t txfee,int32_t firstheight,double perc,char * result.push_back(Pair("totalshares",shares)); result.push_back(Pair("poolfee",(double)(total - totalpayout)/COIN)); result.push_back(Pair("perc",100. * (double)(total - totalpayout)/totalpayout)); - result.push_back(Pair("payouts",a); + result.push_back(Pair("payouts",a)); } } return(result); From 9e94b62aa3f83d9a422d5c9a7332df6aea9a8455 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 09:25:30 -1100 Subject: [PATCH 059/110] Payout --- src/cc/marmara.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 82d0a9995..b1603cfbc 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -335,7 +335,7 @@ UniValue MarmaraPoolPayout(uint64_t txfee,int32_t firstheight,double perc,char * totalpayout += payout; decode_hex(buf,33,pkstr); mtx.vout.push_back(MakeCC1of2vout(EVAL_MARMARA,payout,Marmarapk,buf2pk(buf))); - a.push_back(Pair(pkstr,(double)payout/COIN)); + a.push_back((double)payout/COIN); } } } From 70de1f76bd446c74e9a11752a2228e1882af805f Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 09:28:12 -1100 Subject: [PATCH 060/110] x(UniValue::VOBJ), --- src/cc/marmara.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index b1603cfbc..f993d5555 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -332,10 +332,12 @@ UniValue MarmaraPoolPayout(uint64_t txfee,int32_t firstheight,double perc,char * { if ( (pkstr= jstr(jitem(item,0),0)) != 0 && strlen(pkstr) == 66 ) { + UniValue x(UniValue::VOBJ); totalpayout += payout; decode_hex(buf,33,pkstr); mtx.vout.push_back(MakeCC1of2vout(EVAL_MARMARA,payout,Marmarapk,buf2pk(buf))); - a.push_back((double)payout/COIN); + x.push_back(Pair(pkstr, (double)payout/COIN)); + a.push_back(item); } } } From 78b7341aa5aa03248bd3ba74fd1f3cec2e3b555e Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 09:29:45 -1100 Subject: [PATCH 061/110] x --- src/cc/marmara.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index f993d5555..4a32639af 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -337,7 +337,7 @@ UniValue MarmaraPoolPayout(uint64_t txfee,int32_t firstheight,double perc,char * decode_hex(buf,33,pkstr); mtx.vout.push_back(MakeCC1of2vout(EVAL_MARMARA,payout,Marmarapk,buf2pk(buf))); x.push_back(Pair(pkstr, (double)payout/COIN)); - a.push_back(item); + a.push_back(x); } } } From 513c19d096298af8ee832cab2b3471642056ce36 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 09:38:33 -1100 Subject: [PATCH 062/110] Split commission calc into 2 divs --- src/komodo_bitcoind.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 6e6dc7b35..079e58fc5 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1167,7 +1167,8 @@ uint64_t komodo_commission(const CBlock *pblock,int32_t height) total += pblock->vtx[i].vout[j].nValue; } } - commission = ((total * ASSETCHAINS_COMMISSION) / COIN); + commission = ((total / 10000) * ASSETCHAINS_COMMISSION) / 10000); + //commission = ((total * ASSETCHAINS_COMMISSION) / COIN); } if ( commission < 10000 ) commission = 0; From 59bb5fd47030ff9d5221edf19108d879e45ca960 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 09:46:58 -1100 Subject: [PATCH 063/110] -) --- src/komodo_bitcoind.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 079e58fc5..841396a00 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1167,7 +1167,7 @@ uint64_t komodo_commission(const CBlock *pblock,int32_t height) total += pblock->vtx[i].vout[j].nValue; } } - commission = ((total / 10000) * ASSETCHAINS_COMMISSION) / 10000); + commission = ((total / 10000) * ASSETCHAINS_COMMISSION) / 10000; //commission = ((total * ASSETCHAINS_COMMISSION) / COIN); } if ( commission < 10000 ) From f105e133b972f9fdae7ce56eebd304ea0ae85911 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 09:54:12 -1100 Subject: [PATCH 064/110] First/last heights --- src/cc/marmara.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 4a32639af..763c19ebe 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -367,6 +367,8 @@ UniValue MarmaraPoolPayout(uint64_t txfee,int32_t firstheight,double perc,char * result.push_back(Pair("rawtx",rawtx)); if ( totalpayout > 0 && total > totalpayout-txfee ) { + result.push_back(Pair("firstheight",firstheight)); + result.push_back(Pair("lastheight",((firstheight / MARMARA_GROUPSIZE)+1) * MARMARA_GROUPSIZE - 1)); result.push_back(Pair("total",(double)total/COIN)); result.push_back(Pair("totalpayout",(double)totalpayout/COIN)); result.push_back(Pair("totalshares",shares)); From cae219a0c8970d80efb52d8cdf810d1fb67d24fe Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 09:56:52 -1100 Subject: [PATCH 065/110] Test --- src/cc/marmara.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 763c19ebe..4b154cc8c 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -247,7 +247,7 @@ int64_t AddMarmaraCoinbases(struct CCcontract_info *cp,CMutableTransaction &mtx, { if ( vintx.IsCoinBase() != 0 && vintx.vout.size() == 2 && vintx.vout[1].nValue == 0 ) { - if ( DecodeMaramaraCoinbaseOpRet(vintx.vout[1].scriptPubKey,pk,ht,unlockht) == 'C' && unlockht == unlocks && pk == poolpk ) + if ( DecodeMaramaraCoinbaseOpRet(vintx.vout[1].scriptPubKey,pk,ht,unlockht) == 'C' && unlockht == unlocks && pk == poolpk && ht >= firstheight ) { if ( (nValue= vintx.vout[vout].nValue) > 0 && myIsutxo_spentinmempool(txid,vout) == 0 ) { From 7949fcb64857a72118307ae7818575ab4689fe92 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 15:51:07 -1100 Subject: [PATCH 066/110] Tweak perc calc --- src/cc/marmara.cpp | 2 +- src/wallet/rpcwallet.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 4b154cc8c..ccce9083f 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -319,7 +319,7 @@ UniValue MarmaraPoolPayout(uint64_t txfee,int32_t firstheight,double perc,char * } if ( errorstr == 0 && shares > SMALLVAL ) { - shares += shares * perc; + shares += (shares / (1. - perc)); if ( (total= AddMarmaraCoinbases(cp,mtx,firstheight,poolpk,60)) > 0 ) { for (i=0; i Date: Sat, 12 Jan 2019 15:55:31 -1100 Subject: [PATCH 067/110] Fix perc math --- src/cc/marmara.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index ccce9083f..639a69567 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -319,7 +319,9 @@ UniValue MarmaraPoolPayout(uint64_t txfee,int32_t firstheight,double perc,char * } if ( errorstr == 0 && shares > SMALLVAL ) { - shares += (shares / (1. - perc)); + //shares += shares * perc; + shares /= (1. - perc); + if ( (total= AddMarmaraCoinbases(cp,mtx,firstheight,poolpk,60)) > 0 ) { for (i=0; i Date: Sat, 12 Jan 2019 16:00:11 -1100 Subject: [PATCH 068/110] Revert --- src/cc/marmara.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 639a69567..4b154cc8c 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -319,9 +319,7 @@ UniValue MarmaraPoolPayout(uint64_t txfee,int32_t firstheight,double perc,char * } if ( errorstr == 0 && shares > SMALLVAL ) { - //shares += shares * perc; - shares /= (1. - perc); - + shares += shares * perc; if ( (total= AddMarmaraCoinbases(cp,mtx,firstheight,poolpk,60)) > 0 ) { for (i=0; i Date: Sat, 12 Jan 2019 16:04:43 -1100 Subject: [PATCH 069/110] Adjust pool fee disp by three --- src/cc/marmara.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 4b154cc8c..751eb569b 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -298,7 +298,7 @@ UniValue MarmaraInfo() UniValue MarmaraPoolPayout(uint64_t txfee,int32_t firstheight,double perc,char *jsonstr) // [[pk0, shares0], [pk1, shares1], ...] { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - UniValue result(UniValue::VOBJ),a(UniValue::VARR); cJSON *item,*array; std::string rawtx; int32_t i,n; uint8_t buf[33]; CPubKey Marmarapk,pk,poolpk; int64_t payout,total,totalpayout=0; double poolshares,share,shares = 0.; char *pkstr,*errorstr=0; struct CCcontract_info *cp,C; + UniValue result(UniValue::VOBJ),a(UniValue::VARR); cJSON *item,*array; std::string rawtx; int32_t i,n; uint8_t buf[33]; CPubKey Marmarapk,pk,poolpk; int64_t payout,poolfee=0,total,totalpayout=0; double poolshares,share,shares = 0.; char *pkstr,*errorstr=0; struct CCcontract_info *cp,C; poolpk = pubkey2pk(Mypubkey()); if ( txfee == 0 ) txfee = 10000; @@ -344,7 +344,8 @@ UniValue MarmaraPoolPayout(uint64_t txfee,int32_t firstheight,double perc,char * } if ( totalpayout > 0 && total > totalpayout-txfee ) { - mtx.vout.push_back(MakeCC1of2vout(EVAL_MARMARA,total - totalpayout - txfee,Marmarapk,poolpk)); + poolfee = (total - totalpayout - txfee); + mtx.vout.push_back(MakeCC1of2vout(EVAL_MARMARA,poolfee,Marmarapk,poolpk)); } rawtx = FinalizeCCTx(0,cp,mtx,poolpk,txfee,MarmaraCoinbaseOpret('P',firstheight,poolpk)); if ( rawtx.size() == 0 ) @@ -372,8 +373,8 @@ UniValue MarmaraPoolPayout(uint64_t txfee,int32_t firstheight,double perc,char * result.push_back(Pair("total",(double)total/COIN)); result.push_back(Pair("totalpayout",(double)totalpayout/COIN)); result.push_back(Pair("totalshares",shares)); - result.push_back(Pair("poolfee",(double)(total - totalpayout)/COIN)); - result.push_back(Pair("perc",100. * (double)(total - totalpayout)/totalpayout)); + result.push_back(Pair("poolfee",(double)poolfee/COIN)); + result.push_back(Pair("perc",100. * (double)poolfee/totalpayout)); result.push_back(Pair("payouts",a)); } } From 5ee45ecb45990a3f3d51480d9f08e5a7d070a2c2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 16:12:24 -1100 Subject: [PATCH 070/110] ValueFromAmount( --- src/cc/marmara.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 751eb569b..ef2f62b40 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -370,10 +370,10 @@ UniValue MarmaraPoolPayout(uint64_t txfee,int32_t firstheight,double perc,char * { result.push_back(Pair("firstheight",firstheight)); result.push_back(Pair("lastheight",((firstheight / MARMARA_GROUPSIZE)+1) * MARMARA_GROUPSIZE - 1)); - result.push_back(Pair("total",(double)total/COIN)); - result.push_back(Pair("totalpayout",(double)totalpayout/COIN)); + result.push_back(Pair("total",ValueFromAmount(total)); + result.push_back(Pair("totalpayout",ValueFromAmount(totalpayout)); result.push_back(Pair("totalshares",shares)); - result.push_back(Pair("poolfee",(double)poolfee/COIN)); + result.push_back(Pair("poolfee",ValueFromAmount(poolfee)); result.push_back(Pair("perc",100. * (double)poolfee/totalpayout)); result.push_back(Pair("payouts",a)); } From 857bf5f4e6ea57df49c2e1debff69421e7428a39 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 16:13:54 -1100 Subject: [PATCH 071/110] UniValue ValueFromAmount(const CAmount& amount) --- src/cc/CCinclude.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/cc/CCinclude.h b/src/cc/CCinclude.h index 0906a57c6..aaeadcc61 100644 --- a/src/cc/CCinclude.h +++ b/src/cc/CCinclude.h @@ -187,5 +187,6 @@ bits256 curve25519_basepoint9(); bits256 curve25519(bits256 mysecret,bits256 basepoint); void vcalc_sha256(char deprecated[(256 >> 3) * 2 + 1],uint8_t hash[256 >> 3],uint8_t *src,int32_t len); bits256 bits256_doublesha256(char *deprecated,uint8_t *data,int32_t datalen); +UniValue ValueFromAmount(const CAmount& amount); #endif From ba5462eec9a2172a9c60344ee0cb646cdc013807 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 16:16:21 -1100 Subject: [PATCH 072/110] +))) --- src/cc/marmara.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index ef2f62b40..593ee48f7 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -370,10 +370,10 @@ UniValue MarmaraPoolPayout(uint64_t txfee,int32_t firstheight,double perc,char * { result.push_back(Pair("firstheight",firstheight)); result.push_back(Pair("lastheight",((firstheight / MARMARA_GROUPSIZE)+1) * MARMARA_GROUPSIZE - 1)); - result.push_back(Pair("total",ValueFromAmount(total)); - result.push_back(Pair("totalpayout",ValueFromAmount(totalpayout)); + result.push_back(Pair("total",ValueFromAmount(total))); + result.push_back(Pair("totalpayout",ValueFromAmount(totalpayout))); result.push_back(Pair("totalshares",shares)); - result.push_back(Pair("poolfee",ValueFromAmount(poolfee)); + result.push_back(Pair("poolfee",ValueFromAmount(poolfee))); result.push_back(Pair("perc",100. * (double)poolfee/totalpayout)); result.push_back(Pair("payouts",a)); } From 24cd52e8956201c8a8b01d91f686dda6f8486259 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 16:20:09 -1100 Subject: [PATCH 073/110] return eval->Invalid("no validation yet"); --- src/cc/auction.cpp | 2 +- src/cc/fsm.cpp | 2 +- src/cc/heir.cpp | 2 +- src/cc/lotto.cpp | 2 +- src/cc/marmara.cpp | 2 +- src/cc/payments.cpp | 2 +- src/cc/pegs.cpp | 2 +- src/cc/prices.cpp | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/cc/auction.cpp b/src/cc/auction.cpp index 70bc64379..0858facfa 100644 --- a/src/cc/auction.cpp +++ b/src/cc/auction.cpp @@ -73,7 +73,7 @@ bool AuctionExactAmounts(struct CCcontract_info *cp,Eval* eval,const CTransactio bool AuctionValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn) { int32_t numvins,numvouts,preventCCvins,preventCCvouts,i; bool retval; - return(false); // reject any auction CC for now + return eval->Invalid("no validation yet"); numvins = tx.vin.size(); numvouts = tx.vout.size(); preventCCvins = preventCCvouts = -1; diff --git a/src/cc/fsm.cpp b/src/cc/fsm.cpp index 04ca1d5a0..0bcc61a1b 100644 --- a/src/cc/fsm.cpp +++ b/src/cc/fsm.cpp @@ -75,7 +75,7 @@ bool FSMExactAmounts(struct CCcontract_info *cp,Eval* eval,const CTransaction &t bool FSMValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn) { int32_t numvins,numvouts,preventCCvins,preventCCvouts,i; bool retval; - return(false); // reject any FSM CC for now + return eval->Invalid("no validation yet"); numvins = tx.vin.size(); numvouts = tx.vout.size(); preventCCvins = preventCCvouts = -1; diff --git a/src/cc/heir.cpp b/src/cc/heir.cpp index 5caa6594a..44f01a8a4 100644 --- a/src/cc/heir.cpp +++ b/src/cc/heir.cpp @@ -74,7 +74,7 @@ bool HeirExactAmounts(struct CCcontract_info *cp,Eval* eval,const CTransaction & bool HeirValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn) { int32_t numvins,numvouts,preventCCvins,preventCCvouts,i,numblocks; bool retval; uint256 txid; uint8_t hash[32]; char str[65],destaddr[64]; - return(false); + return eval->Invalid("no validation yet"); std::vector > txids; numvins = tx.vin.size(); numvouts = tx.vout.size(); diff --git a/src/cc/lotto.cpp b/src/cc/lotto.cpp index 7b44a99b7..e9c263ff1 100644 --- a/src/cc/lotto.cpp +++ b/src/cc/lotto.cpp @@ -115,7 +115,7 @@ bool LottoExactAmounts(struct CCcontract_info *cp,Eval* eval,const CTransaction bool LottoValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn) { int32_t numvins,numvouts,preventCCvins,preventCCvouts,i; bool retval; - return(false); // reject any lotto CC for now + return eval->Invalid("no validation yet"); numvins = tx.vin.size(); numvouts = tx.vout.size(); preventCCvins = preventCCvouts = -1; diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 593ee48f7..a4d548176 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -192,7 +192,7 @@ int32_t MarmaraValidateCoinbase(int32_t height,CTransaction tx) bool MarmaraValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn) { int32_t numvins,numvouts,preventCCvins,preventCCvouts,i,numblocks; bool retval; uint256 txid; uint8_t hash[32]; char str[65],destaddr[64]; - return(false); + return eval->Invalid("no validation yet"); std::vector > txids; numvins = tx.vin.size(); numvouts = tx.vout.size(); diff --git a/src/cc/payments.cpp b/src/cc/payments.cpp index 1b6d88214..859a5ba3f 100644 --- a/src/cc/payments.cpp +++ b/src/cc/payments.cpp @@ -75,7 +75,7 @@ bool PaymentsExactAmounts(struct CCcontract_info *cp,Eval* eval,const CTransacti bool PaymentsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn) { int32_t numvins,numvouts,preventCCvins,preventCCvouts,i,numblocks; bool retval; uint256 txid; uint8_t hash[32]; char str[65],destaddr[64]; - return(false); + return eval->Invalid("no validation yet"); std::vector > txids; numvins = tx.vin.size(); numvouts = tx.vout.size(); diff --git a/src/cc/pegs.cpp b/src/cc/pegs.cpp index 4e414d695..e2893bec8 100644 --- a/src/cc/pegs.cpp +++ b/src/cc/pegs.cpp @@ -82,7 +82,7 @@ bool PegsExactAmounts(struct CCcontract_info *cp,Eval* eval,const CTransaction & bool PegsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn) { int32_t numvins,numvouts,preventCCvins,preventCCvouts,i,numblocks; bool retval; uint256 txid; uint8_t hash[32]; char str[65],destaddr[64]; - return(false); + return eval->Invalid("no validation yet"); std::vector > txids; numvins = tx.vin.size(); numvouts = tx.vout.size(); diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 8c2ecc021..5d919d6e8 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -89,7 +89,7 @@ uint8_t DecodePricesFundingOpRet(CScript scriptPubKey,CPubKey &planpk,uint256 &o bool PricesValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn) { int32_t numvins,numvouts,preventCCvins,preventCCvouts,i,numblocks; bool retval; uint256 txid; uint8_t hash[32]; char str[65],destaddr[64]; - return(false); + return eval->Invalid("no validation yet"); std::vector > txids; numvins = tx.vin.size(); numvouts = tx.vout.size(); From b6eed136785c5662cc18d83d231c588943d32392 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 16:22:59 -1100 Subject: [PATCH 074/110] Truncate perc print --- src/cc/marmara.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index a4d548176..171ef713d 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -374,7 +374,7 @@ UniValue MarmaraPoolPayout(uint64_t txfee,int32_t firstheight,double perc,char * result.push_back(Pair("totalpayout",ValueFromAmount(totalpayout))); result.push_back(Pair("totalshares",shares)); result.push_back(Pair("poolfee",ValueFromAmount(poolfee))); - result.push_back(Pair("perc",100. * (double)poolfee/totalpayout)); + result.push_back(Pair("perc",ValueFromAmount((int64_t)(100. * (double)poolfee/totalpayout)))); result.push_back(Pair("payouts",a)); } } From c38e4a0521534e81e81a25f95c9f33afd52730c5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 16:24:23 -1100 Subject: [PATCH 075/110] * COIN --- src/cc/marmara.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 171ef713d..2e56c21b2 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -374,7 +374,7 @@ UniValue MarmaraPoolPayout(uint64_t txfee,int32_t firstheight,double perc,char * result.push_back(Pair("totalpayout",ValueFromAmount(totalpayout))); result.push_back(Pair("totalshares",shares)); result.push_back(Pair("poolfee",ValueFromAmount(poolfee))); - result.push_back(Pair("perc",ValueFromAmount((int64_t)(100. * (double)poolfee/totalpayout)))); + result.push_back(Pair("perc",ValueFromAmount((int64_t)(100. * (double)poolfee/totalpayout * COIN)))); result.push_back(Pair("payouts",a)); } } From 0b58392fff0671169aa06f16c8cab9bb2869daac Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 17:29:18 -1100 Subject: [PATCH 076/110] Validation for marmara 'P' --- src/cc/eval.cpp | 5 +++-- src/cc/marmara.cpp | 45 ++++++++++++++++++++++----------------------- 2 files changed, 25 insertions(+), 25 deletions(-) diff --git a/src/cc/eval.cpp b/src/cc/eval.cpp index d50bc8a0d..9161f2007 100644 --- a/src/cc/eval.cpp +++ b/src/cc/eval.cpp @@ -38,8 +38,9 @@ bool RunCCEval(const CC *cond, const CTransaction &tx, unsigned int nIn) pthread_mutex_lock(&KOMODO_CC_mutex); bool out = eval->Dispatch(cond, tx, nIn); pthread_mutex_unlock(&KOMODO_CC_mutex); - //fprintf(stderr,"out %d vs %d isValid\n",(int32_t)out,(int32_t)eval->state.IsValid()); - assert(eval->state.IsValid() == out); + if ( eval->state.IsValid() != out) + fprintf(stderr,"out %d vs %d isValid\n",(int32_t)out,(int32_t)eval->state.IsValid()); + //assert(eval->state.IsValid() == out); if (eval->state.IsValid()) return true; diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 2e56c21b2..d12959d2a 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -191,40 +191,39 @@ int32_t MarmaraValidateCoinbase(int32_t height,CTransaction tx) bool MarmaraValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn) { - int32_t numvins,numvouts,preventCCvins,preventCCvouts,i,numblocks; bool retval; uint256 txid; uint8_t hash[32]; char str[65],destaddr[64]; - return eval->Invalid("no validation yet"); - std::vector > txids; + CTransaction vinTx; uint256 hashBlock; int32_t numvins,numvouts,i,ht,unlockht,vht,vunlockht; uint8_t funcid; CPubKey pk,vpk; numvins = tx.vin.size(); numvouts = tx.vout.size(); preventCCvins = preventCCvouts = -1; if ( numvouts < 1 ) return eval->Invalid("no vouts"); - else + else if ( tx.vout.size() >= 2 ) { - for (i=0; iInvalid("illegal normal vini"); + if ( (*cp->ismyvin)(tx.vin[i].scriptSig) != 0 ) + { + if ( eval->GetTxUnconfirmed(tx.vin[i].prevout.hash,vinTx,hashBlock) == 0 ) + return eval->Invalid("cant find vinTx"); + else + { + if ( vinTx.IsCoinbase() == 0 ) + return eval->Invalid("noncoinbase input"); + else if ( vinTx.size() != 2 ) + return eval->Invalid("coinbase doesnt have 2 vouts"); + vfuncid = DecodeMaramaraCoinbaseOpRet(vinTx.vout[1].scriptPubKey,vpk,vht,vunlockht); + if ( vfuncid != 'C' || vpk != pk || vunlockht != unlockht ) + return eval->Invalid("mismatched opreturn"); + } + } } - } - //fprintf(stderr,"check amounts\n"); - if ( MarmaraExactAmounts(cp,eval,tx,1,10000) == false ) - { - fprintf(stderr,"Marmaraget invalid amount\n"); - return false; - } - else - { - txid = tx.GetHash(); - memcpy(hash,&txid,sizeof(hash)); - retval = PreventCC(eval,tx,preventCCvins,numvins,preventCCvouts,numvouts); - if ( retval != 0 ) - fprintf(stderr,"Marmaraget validated\n"); - else fprintf(stderr,"Marmaraget invalid\n"); - return(retval); + return(true); } } + return eval->Invalid("fall through error"); } // end of consensus code From 7c0fb95d183384df38838e634e7555f19bba8a0e Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 17:29:47 -1100 Subject: [PATCH 077/110] Syntax --- src/cc/marmara.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index d12959d2a..f272ecf8d 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -194,7 +194,6 @@ bool MarmaraValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &t CTransaction vinTx; uint256 hashBlock; int32_t numvins,numvouts,i,ht,unlockht,vht,vunlockht; uint8_t funcid; CPubKey pk,vpk; numvins = tx.vin.size(); numvouts = tx.vout.size(); - preventCCvins = preventCCvouts = -1; if ( numvouts < 1 ) return eval->Invalid("no vouts"); else if ( tx.vout.size() >= 2 ) From ba281dae9f79fd287151c09211552a01a2736031 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 17:32:15 -1100 Subject: [PATCH 078/110] syntax --- src/cc/marmara.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index f272ecf8d..dd8e304cf 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -191,7 +191,7 @@ int32_t MarmaraValidateCoinbase(int32_t height,CTransaction tx) bool MarmaraValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn) { - CTransaction vinTx; uint256 hashBlock; int32_t numvins,numvouts,i,ht,unlockht,vht,vunlockht; uint8_t funcid; CPubKey pk,vpk; + CTransaction vinTx; uint256 hashBlock; int32_t numvins,numvouts,i,ht,unlockht,vht,vunlockht; uint8_t funcid,vfuncid; CPubKey pk,vpk; numvins = tx.vin.size(); numvouts = tx.vout.size(); if ( numvouts < 1 ) @@ -209,9 +209,9 @@ bool MarmaraValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &t return eval->Invalid("cant find vinTx"); else { - if ( vinTx.IsCoinbase() == 0 ) + if ( vinTx.IsCoinBase() == 0 ) return eval->Invalid("noncoinbase input"); - else if ( vinTx.size() != 2 ) + else if ( vinTx.vout.size() != 2 ) return eval->Invalid("coinbase doesnt have 2 vouts"); vfuncid = DecodeMaramaraCoinbaseOpRet(vinTx.vout[1].scriptPubKey,vpk,vht,vunlockht); if ( vfuncid != 'C' || vpk != pk || vunlockht != unlockht ) From fe9d96b291bc4bdfdcf164b11765e4d02fb75cf2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 17:35:48 -1100 Subject: [PATCH 079/110] Last vout is I-return --- src/cc/marmara.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index dd8e304cf..5c36eb563 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -198,7 +198,7 @@ bool MarmaraValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &t return eval->Invalid("no vouts"); else if ( tx.vout.size() >= 2 ) { - funcid = DecodeMaramaraCoinbaseOpRet(tx.vout[1].scriptPubKey,pk,ht,unlockht); + funcid = DecodeMaramaraCoinbaseOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,pk,ht,unlockht); if ( funcid == 'P' ) { for (i=0; i Date: Sat, 12 Jan 2019 17:38:17 -1100 Subject: [PATCH 080/110] -print --- src/cc/marmara.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 5c36eb563..6415671f8 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -256,7 +256,7 @@ int64_t AddMarmaraCoinbases(struct CCcontract_info *cp,CMutableTransaction &mtx, n++; if ( maxinputs > 0 && n >= maxinputs ) break; - } else fprintf(stderr,"nValue.%8f\n",(double)nValue/COIN); + } //else fprintf(stderr,"nValue.%8f\n",(double)nValue/COIN); } //else fprintf(stderr,"decode error unlockht.%d vs %d pk.%d\n",unlockht,unlocks,pk == poolpk); } else fprintf(stderr,"not coinbase\n"); } else fprintf(stderr,"error getting tx\n"); From e149a4e4d798b31c6cdc69ba16b5bdcd6ab19530 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 13 Jan 2019 02:34:07 -1100 Subject: [PATCH 081/110] Initial MarmaraReceive --- src/cc/marmara.cpp | 73 +++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 69 insertions(+), 4 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 6415671f8..ba4e4b005 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -33,7 +33,7 @@ int64_t IsMarmaravout(struct CCcontract_info *cp,const CTransaction& tx,int32_t return(0); } -bool MarmaraExactAmounts(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx,int32_t minage,uint64_t txfee) +/*bool MarmaraExactAmounts(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx,int32_t minage,uint64_t txfee) { static uint256 zerohash; CTransaction vinTx; uint256 hashBlock,activehash; int32_t i,numvins,numvouts; int64_t inputs=0,outputs=0,assetoshis; @@ -69,7 +69,7 @@ bool MarmaraExactAmounts(struct CCcontract_info *cp,Eval* eval,const CTransactio return eval->Invalid("mismatched inputs != outputs + txfee"); } else return(true); -} +}*/ int32_t MarmaraRandomize(uint32_t ind) { @@ -191,16 +191,21 @@ int32_t MarmaraValidateCoinbase(int32_t height,CTransaction tx) bool MarmaraValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn) { - CTransaction vinTx; uint256 hashBlock; int32_t numvins,numvouts,i,ht,unlockht,vht,vunlockht; uint8_t funcid,vfuncid; CPubKey pk,vpk; + std::vector vopret; CTransaction vinTx; uint256 hashBlock; int32_t numvins,numvouts,i,ht,unlockht,vht,vunlockht; uint8_t funcid,vfuncid,*script; CPubKey pk,vpk; numvins = tx.vin.size(); numvouts = tx.vout.size(); if ( numvouts < 1 ) return eval->Invalid("no vouts"); else if ( tx.vout.size() >= 2 ) { - funcid = DecodeMaramaraCoinbaseOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,pk,ht,unlockht); + GetOpReturnData(tx.vout[tx.vout.size()-1].scriptPubKey,vopret); + script = (uint8_t *)vopret.data(); + if ( vopret.size() < 2 || script[0] != EVAL_MARMARA ) + return eval->Invalid("no opreturn"); + funcid = script[1]; if ( funcid == 'P' ) { + funcid = DecodeMaramaraCoinbaseOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,pk,ht,unlockht); for (i=0; iismyvin)(tx.vin[i].scriptSig) != 0 ) @@ -221,6 +226,38 @@ bool MarmaraValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &t } return(true); } + else if ( funcid == 'L' ) // lock -> lock funds with a unlockht + { + return(true); + } + else if ( funcid == 'R' ) // receive -> agree to receive 'I' from pk, amount, currency, dueht + { + return(true); + } + else if ( funcid == 'I' ) // issue -> issue currency to pk with due date height + { + return(true); + } + else if ( funcid == 'T' ) // transfer -> given 'R' transfer 'I' or 'T' to the pk of 'R' + { + return(true); + } + else if ( funcid == 'S' ) // collect -> automatically spend issuers locked funds, given 'I' + { + return(true); + } + else if ( funcid == 'A' ) // agree -> agree that 'I' is unable to be redeemed, remainder + { + return(true); + } + else if ( funcid == 'D' ) // dispute -> given 'I' submit for manual arbitration + { + return(true); + } + else if ( funcid == 'F' ) // foreclose -> given 'A' collect as much of remainder from credit loop + { + return(true); + } } return eval->Invalid("fall through error"); } @@ -264,6 +301,34 @@ int64_t AddMarmaraCoinbases(struct CCcontract_info *cp,CMutableTransaction &mtx, return(totalinputs); } +UniValue MarmaraReceive(uint64_t txfee,CPubKey senderpk,int64_t amount,std::string currency,int32_t matures,uint256 issuetxid) +{ + CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); + UniValue result(UniValue::VOBJ); struct CCcontract_info *cp,C; std::string rawtx; char *errorstr=0; + cp = CCinit(&C,EVAL_MARMARA); + if ( txfee == 0 ) + txfee = 10000; + mypk = pubkey2pk(Mypubkey()); + errorstr = (char *)"couldnt finalize CCtx"; + if ( AddNormalinputs(mtx,mypk,2*txfee,1) > 0 ) + { + mtx.vout.push_back(CTxOut(txfee,CScript() << ParseHex(HexStr(senderpk)) << OP_CHECKSIG)); + rawtx = FinalizeCCTx(0,cp,mtx,mypk,txfee,MarmaraOpret('R',issuetxid,senderpk,amount,matures,currency)); + } else errorstr = "dont have enough normal inputs for 2*txfee"; + if ( rawtx.size() == 0 || errorstr != 0 ) + { + result.push_back(Pair("result","error")); + if ( errorstr != 0 ) + result.push_back(Pair("error",errorstr)); + } + else + { + result.push_back(Pair("result",(char *)"success")); + result.push_back(Pair("rawtx",rawtx)); + } + return(result); +} + std::string MarmaraFund(uint64_t txfee,int64_t funds) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); From b7341671fa97623020bf8e4781549761775f05cf Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 13 Jan 2019 02:45:51 -1100 Subject: [PATCH 082/110] CC baton for credit loop --- src/cc/marmara.cpp | 73 +++++++++++++++++++++++++++++----------------- 1 file changed, 47 insertions(+), 26 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index ba4e4b005..75f9e0ee4 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -87,25 +87,6 @@ int32_t MarmaraUnlockht(int32_t height) return(height + MarmaraRandomize(ind)); } -CScript EncodeMarmaraCoinbaseOpRet(uint8_t funcid,CPubKey pk,int32_t ht) -{ - CScript opret; int32_t unlockht; uint8_t evalcode = EVAL_MARMARA; - unlockht = MarmaraUnlockht(ht); - opret << OP_RETURN << E_MARSHAL(ss << evalcode << funcid << pk << ht << unlockht); - if ( 0 ) - { - std::vector vopret; uint8_t *script,i; - GetOpReturnData(opret,vopret); - script = (uint8_t *)vopret.data(); - { - for (i=0; i vopret; uint8_t *script,e,f,funcid; @@ -131,6 +112,32 @@ uint8_t DecodeMaramaraCoinbaseOpRet(const CScript scriptPubKey,CPubKey &pk,int32 return(0); } +CScript EncodeMarmaraCoinbaseOpRet(uint8_t funcid,CPubKey pk,int32_t ht) +{ + CScript opret; int32_t unlockht; uint8_t evalcode = EVAL_MARMARA; + unlockht = MarmaraUnlockht(ht); + opret << OP_RETURN << E_MARSHAL(ss << evalcode << funcid << pk << ht << unlockht); + if ( 0 ) + { + std::vector vopret; uint8_t *script,i; + GetOpReturnData(opret,vopret); + script = (uint8_t *)vopret.data(); + { + for (i=0; i 0 ) + if ( currency != "MARMARA" ) + errorstr = "for now, only MARMARA loops are supported"; + else if ( amount < txfee ) + errorstr = "amount must be for more than txfee"; + else if ( matures <= chainActive.LastTip->GetHeight() ) + errorstr = "it must mature in the future"; + if ( errorstr == 0 ) { - mtx.vout.push_back(CTxOut(txfee,CScript() << ParseHex(HexStr(senderpk)) << OP_CHECKSIG)); - rawtx = FinalizeCCTx(0,cp,mtx,mypk,txfee,MarmaraOpret('R',issuetxid,senderpk,amount,matures,currency)); - } else errorstr = "dont have enough normal inputs for 2*txfee"; + if ( AddNormalinputs(mtx,mypk,2*txfee,1) > 0 ) + { + errorstr = (char *)"couldnt finalize CCtx"; + mtx.vout.push_back(MakeCC1vout(EVAL_MARMARA,txfee,senderpk)); + rawtx = FinalizeCCTx(0,cp,mtx,mypk,txfee,MarmaraLoopOpret('R',createtxid,senderpk,amount,matures,currency)); + } else errorstr = (char *)"dont have enough normal inputs for 2*txfee"; + } if ( rawtx.size() == 0 || errorstr != 0 ) { result.push_back(Pair("result","error")); @@ -325,6 +341,11 @@ UniValue MarmaraReceive(uint64_t txfee,CPubKey senderpk,int64_t amount,std::stri { result.push_back(Pair("result",(char *)"success")); result.push_back(Pair("rawtx",rawtx)); + result.push_back(Pair("createtxid",createtxid)); + result.push_back(Pair("senderpk",senderpk)); + result.push_back(Pair("amount",ValueFromAmount(amount))); + result.push_back(Pair("matures",matures)); + result.push_back(Pair("currency",currency)); } return(result); } From cd4b54dfeae90ccfadb39435f99b2eda88bbbb89 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 13 Jan 2019 02:47:18 -1100 Subject: [PATCH 083/110] Strings --- src/cc/marmara.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 75f9e0ee4..5db0c07c3 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -341,8 +341,8 @@ UniValue MarmaraReceive(uint64_t txfee,CPubKey senderpk,int64_t amount,std::stri { result.push_back(Pair("result",(char *)"success")); result.push_back(Pair("rawtx",rawtx)); - result.push_back(Pair("createtxid",createtxid)); - result.push_back(Pair("senderpk",senderpk)); + result.push_back(Pair("createtxid",createtxid.GetHex())); + result.push_back(Pair("senderpk",HexStr(senderpk))); result.push_back(Pair("amount",ValueFromAmount(amount))); result.push_back(Pair("matures",matures)); result.push_back(Pair("currency",currency)); From 85271fb3a507ae79e8325b2450c2ed48881ce1b7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 13 Jan 2019 02:48:20 -1100 Subject: [PATCH 084/110] Test --- src/cc/marmara.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 5db0c07c3..a50059305 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -317,11 +317,11 @@ UniValue MarmaraReceive(uint64_t txfee,CPubKey senderpk,int64_t amount,std::stri txfee = 10000; mypk = pubkey2pk(Mypubkey()); if ( currency != "MARMARA" ) - errorstr = "for now, only MARMARA loops are supported"; + errorstr = (char *)"for now, only MARMARA loops are supported"; else if ( amount < txfee ) - errorstr = "amount must be for more than txfee"; - else if ( matures <= chainActive.LastTip->GetHeight() ) - errorstr = "it must mature in the future"; + errorstr = (char *)"amount must be for more than txfee"; + else if ( matures <= chainActive.LastTip()->GetHeight() ) + errorstr = (char *)"it must mature in the future"; if ( errorstr == 0 ) { if ( AddNormalinputs(mtx,mypk,2*txfee,1) > 0 ) From 38093ec82aeacf182fd322b69f89498256d5c495 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 13 Jan 2019 02:52:29 -1100 Subject: [PATCH 085/110] Need baton in 'R' --- src/cc/marmara.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index a50059305..1ff1855dd 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -311,7 +311,7 @@ int64_t AddMarmaraCoinbases(struct CCcontract_info *cp,CMutableTransaction &mtx, UniValue MarmaraReceive(uint64_t txfee,CPubKey senderpk,int64_t amount,std::string currency,int32_t matures,uint256 createtxid) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - UniValue result(UniValue::VOBJ); CPubKey mypk; struct CCcontract_info *cp,C; std::string rawtx; char *errorstr=0; + UniValue result(UniValue::VOBJ); CPubKey mypk; struct CCcontract_info *cp,C; std::string rawtx; char *errorstr=0; int32_t needbaton = 0; cp = CCinit(&C,EVAL_MARMARA); if ( txfee == 0 ) txfee = 10000; @@ -324,10 +324,13 @@ UniValue MarmaraReceive(uint64_t txfee,CPubKey senderpk,int64_t amount,std::stri errorstr = (char *)"it must mature in the future"; if ( errorstr == 0 ) { - if ( AddNormalinputs(mtx,mypk,2*txfee,1) > 0 ) + if ( createtxid == zeroid ) + needbaton = 1; + if ( AddNormalinputs(mtx,mypk,(1+needbaton)*txfee,1) > 0 ) { errorstr = (char *)"couldnt finalize CCtx"; - mtx.vout.push_back(MakeCC1vout(EVAL_MARMARA,txfee,senderpk)); + if ( needbaton != 0 ) + mtx.vout.push_back(MakeCC1vout(EVAL_MARMARA,txfee,senderpk)); rawtx = FinalizeCCTx(0,cp,mtx,mypk,txfee,MarmaraLoopOpret('R',createtxid,senderpk,amount,matures,currency)); } else errorstr = (char *)"dont have enough normal inputs for 2*txfee"; } From 908ee69451cc2cceb48775b0a9344d331234a261 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 13 Jan 2019 03:04:34 -1100 Subject: [PATCH 086/110] Marmarareceive roc --- src/cc/CCMarmara.h | 1 + src/rpc/server.cpp | 1 + src/rpc/server.h | 1 + src/wallet/rpcwallet.cpp | 27 ++++++++++++++++++++++++++- 4 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/cc/CCMarmara.h b/src/cc/CCMarmara.h index 4a50c2539..d3eb67b77 100644 --- a/src/cc/CCMarmara.h +++ b/src/cc/CCMarmara.h @@ -25,6 +25,7 @@ #define MARMARA_MAXLOCK (1440 * 24 * 30) uint64_t komodo_block_prg(uint32_t nHeight); UniValue MarmaraPoolPayout(uint64_t txfee,int32_t firstheight,double perc,char *jsonstr); // [[pk0, shares0], [pk1, shares1], ...] +UniValue MarmaraReceive(uint64_t txfee,CPubKey senderpk,int64_t amount,std::string currency,int32_t matures,uint256 createtxid); bool MarmaraValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); diff --git a/src/rpc/server.cpp b/src/rpc/server.cpp index d6b801dd5..5baadf34a 100644 --- a/src/rpc/server.cpp +++ b/src/rpc/server.cpp @@ -444,6 +444,7 @@ static const CRPCCommand vRPCCommands[] = // Marmara { "marmara", "marmaraaddress", &marmaraaddress, true }, { "marmara", "marmarapoolpayout", &marmara_poolpayout, true }, + { "marmara", "marmarareceive", &marmara_receive, true }, // Payments { "payments", "paymentsaddress", &paymentsaddress, true }, diff --git a/src/rpc/server.h b/src/rpc/server.h index bd00bb9d1..4787130e2 100644 --- a/src/rpc/server.h +++ b/src/rpc/server.h @@ -273,6 +273,7 @@ extern UniValue pricesfinish(const UniValue& params, bool fHelp); extern UniValue pegsaddress(const UniValue& params, bool fHelp); extern UniValue marmaraaddress(const UniValue& params, bool fHelp); extern UniValue marmara_poolpayout(const UniValue& params, bool fHelp); +extern UniValue marmara_receive(const UniValue& params, bool fHelp); extern UniValue paymentsaddress(const UniValue& params, bool fHelp); extern UniValue gatewaysaddress(const UniValue& params, bool fHelp); extern UniValue gatewayslist(const UniValue& params, bool fHelp); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 1790a574a..a2b0afa37 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5537,7 +5537,7 @@ UniValue marmara_poolpayout(const UniValue& params, bool fHelp) if ( fHelp || params.size() != 3 ) { // marmarapoolpayout 0.5 2 '[["024131032ed90941e714db8e6dd176fe5a86c9d873d279edecf005c06f773da686",1000],["02ebc786cb83de8dc3922ab83c21f3f8a2f3216940c3bf9da43ce39e2a3a882c92",100]]'; - throw runtime_error("marmara_poolpayout perc firstheight \"[[\\\"pubkey\\\":shares], ...]\"\n"); + throw runtime_error("marmarapoolpayout perc firstheight \"[[\\\"pubkey\\\":shares], ...]\"\n"); } if ( ensure_CCrequirements() < 0 ) throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); @@ -5547,6 +5547,31 @@ UniValue marmara_poolpayout(const UniValue& params, bool fHelp) return(MarmaraPoolPayout(0,firstheight,perc,jsonstr)); // [[pk0, shares0], [pk1, shares1], ...] } +UniValue marmara_receive(const UniValue& params, bool fHelp) +{ + uint256 createtxid; std::vector senderpub; int64_t amount; int32_t matures; + if ( fHelp || (params.size() != 5 && params.size() != 4) ) + { + // marmarareceive 039433dc3749aece1bd568f374a45da3b0bc6856990d7da3cd175399577940a775 7.5 MARMARA 1440 + throw runtime_error("marmarareceive senderpk amount currency matures createtxid\n"); + } + if ( ensure_CCrequirements() < 0 ) + throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + memset(&createtxid,0,sizeof(createtxid)); + senderpub = ParseHex(params[0].get_str().c_str()); + if (senderpub.size()!= 33) + { + ERR_RESULT("invalid sender pubkey"); + return result; + } + amount = atof(params[1].get_str().c_str()) * COIN + 0.00000000499999; + currency = params[2].get_str(); + matures = atol(params[3].get_str().c_str()) + chainActive.LastTip()->GetHeight() + 1; + if ( params.size() == 5 ) + createtxid = Parseuint256((char *)params[4].get_str().c_str()); + return(MarmaraReceive(0,pubkey2pk(senderpub),amount,currency,matures,createtxid)); +} + UniValue channelslist(const UniValue& params, bool fHelp) { if ( fHelp || params.size() > 0 ) From 2084694843126a610875b6a5294219b30e0c3925 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 13 Jan 2019 03:08:37 -1100 Subject: [PATCH 087/110] Syntax --- src/wallet/rpcwallet.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index a2b0afa37..7160489de 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5549,10 +5549,11 @@ UniValue marmara_poolpayout(const UniValue& params, bool fHelp) UniValue marmara_receive(const UniValue& params, bool fHelp) { - uint256 createtxid; std::vector senderpub; int64_t amount; int32_t matures; + UniValue result(UniValue::VOBJ); uint256 createtxid; std::vector senderpub; int64_t amount; int32_t matures; std::string currency; if ( fHelp || (params.size() != 5 && params.size() != 4) ) { - // marmarareceive 039433dc3749aece1bd568f374a45da3b0bc6856990d7da3cd175399577940a775 7.5 MARMARA 1440 + // 1st marmarareceive 039433dc3749aece1bd568f374a45da3b0bc6856990d7da3cd175399577940a775 7.5 MARMARA 1440 + // after marmarareceive 039433dc3749aece1bd568f374a45da3b0bc6856990d7da3cd175399577940a775 7.5 MARMARA 1440 throw runtime_error("marmarareceive senderpk amount currency matures createtxid\n"); } if ( ensure_CCrequirements() < 0 ) From a90b1bb7d516a9e21d8ae9f5bb751024923ef016 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 13 Jan 2019 03:10:35 -1100 Subject: [PATCH 088/110] Clear default errorstr --- src/cc/marmara.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 1ff1855dd..353e07a30 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -332,6 +332,8 @@ UniValue MarmaraReceive(uint64_t txfee,CPubKey senderpk,int64_t amount,std::stri if ( needbaton != 0 ) mtx.vout.push_back(MakeCC1vout(EVAL_MARMARA,txfee,senderpk)); rawtx = FinalizeCCTx(0,cp,mtx,mypk,txfee,MarmaraLoopOpret('R',createtxid,senderpk,amount,matures,currency)); + if ( rawtx.size() > 0 ) + errorstr = 0; } else errorstr = (char *)"dont have enough normal inputs for 2*txfee"; } if ( rawtx.size() == 0 || errorstr != 0 ) From 46069b7159ed360f0ec32e92d79a9553468cfd58 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 13 Jan 2019 03:12:07 -1100 Subject: [PATCH 089/110] funcid --- src/cc/marmara.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 353e07a30..85487f748 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -346,6 +346,7 @@ UniValue MarmaraReceive(uint64_t txfee,CPubKey senderpk,int64_t amount,std::stri { result.push_back(Pair("result",(char *)"success")); result.push_back(Pair("rawtx",rawtx)); + result.push_back(Pair("funcid","R")); result.push_back(Pair("createtxid",createtxid.GetHex())); result.push_back(Pair("senderpk",HexStr(senderpk))); result.push_back(Pair("amount",ValueFromAmount(amount))); From c10dfbb858ed1f36384043a82ff1a033f2a6299c Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 13 Jan 2019 03:21:20 -1100 Subject: [PATCH 090/110] marmara_issue --- src/cc/CCMarmara.h | 1 + src/cc/marmara.cpp | 45 ++++++++++++++++++++++++++++++++++++++++ src/rpc/server.cpp | 1 + src/rpc/server.h | 1 + src/wallet/rpcwallet.cpp | 23 ++++++++++++++++++++ 5 files changed, 71 insertions(+) diff --git a/src/cc/CCMarmara.h b/src/cc/CCMarmara.h index d3eb67b77..5fc1ce891 100644 --- a/src/cc/CCMarmara.h +++ b/src/cc/CCMarmara.h @@ -26,6 +26,7 @@ uint64_t komodo_block_prg(uint32_t nHeight); UniValue MarmaraPoolPayout(uint64_t txfee,int32_t firstheight,double perc,char *jsonstr); // [[pk0, shares0], [pk1, shares1], ...] UniValue MarmaraReceive(uint64_t txfee,CPubKey senderpk,int64_t amount,std::string currency,int32_t matures,uint256 createtxid); +UniValue MarmaraIssue(uint64_t txfee,CPubKey senderpk,int64_t amount,std::string currency,int32_t matures,uint256 createtxid); bool MarmaraValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 85487f748..5cd623966 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -356,6 +356,51 @@ UniValue MarmaraReceive(uint64_t txfee,CPubKey senderpk,int64_t amount,std::stri return(result); } +UniValue MarmaraIssue(uint64_t txfee,CPubKey receiverpk,int64_t amount,std::string currency,int32_t matures,uint256 createtxid) +{ + CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); + UniValue result(UniValue::VOBJ); CPubKey mypk; struct CCcontract_info *cp,C; std::string rawtx; char *errorstr=0; + cp = CCinit(&C,EVAL_MARMARA); + if ( txfee == 0 ) + txfee = 10000; + mypk = pubkey2pk(Mypubkey()); + if ( currency != "MARMARA" ) + errorstr = (char *)"for now, only MARMARA loops are supported"; + else if ( amount < txfee ) + errorstr = (char *)"amount must be for more than txfee"; + else if ( matures <= chainActive.LastTip()->GetHeight() ) + errorstr = (char *)"it must mature in the future"; + if ( errorstr == 0 ) + { + if ( AddNormalinputs(mtx,mypk,2*txfee,1) > 0 ) + { + errorstr = (char *)"couldnt finalize CCtx"; + mtx.vout.push_back(MakeCC1vout(EVAL_MARMARA,txfee,receiverpk)); + rawtx = FinalizeCCTx(0,cp,mtx,mypk,txfee,MarmaraLoopOpret('I',createtxid,receiverpk,amount,matures,currency)); + if ( rawtx.size() > 0 ) + errorstr = 0; + } else errorstr = (char *)"dont have enough normal inputs for 2*txfee"; + } + if ( rawtx.size() == 0 || errorstr != 0 ) + { + result.push_back(Pair("result","error")); + if ( errorstr != 0 ) + result.push_back(Pair("error",errorstr)); + } + else + { + result.push_back(Pair("result",(char *)"success")); + result.push_back(Pair("rawtx",rawtx)); + result.push_back(Pair("funcid","R")); + result.push_back(Pair("createtxid",createtxid.GetHex())); + result.push_back(Pair("receiverpk",HexStr(receiverpk))); + result.push_back(Pair("amount",ValueFromAmount(amount))); + result.push_back(Pair("matures",matures)); + result.push_back(Pair("currency",currency)); + } + return(result); +} + std::string MarmaraFund(uint64_t txfee,int64_t funds) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); diff --git a/src/rpc/server.cpp b/src/rpc/server.cpp index 5baadf34a..add90902c 100644 --- a/src/rpc/server.cpp +++ b/src/rpc/server.cpp @@ -445,6 +445,7 @@ static const CRPCCommand vRPCCommands[] = { "marmara", "marmaraaddress", &marmaraaddress, true }, { "marmara", "marmarapoolpayout", &marmara_poolpayout, true }, { "marmara", "marmarareceive", &marmara_receive, true }, + { "marmara", "marmaraissue", &marmara_issue, true }, // Payments { "payments", "paymentsaddress", &paymentsaddress, true }, diff --git a/src/rpc/server.h b/src/rpc/server.h index 4787130e2..b7654da38 100644 --- a/src/rpc/server.h +++ b/src/rpc/server.h @@ -274,6 +274,7 @@ extern UniValue pegsaddress(const UniValue& params, bool fHelp); extern UniValue marmaraaddress(const UniValue& params, bool fHelp); extern UniValue marmara_poolpayout(const UniValue& params, bool fHelp); extern UniValue marmara_receive(const UniValue& params, bool fHelp); +extern UniValue marmara_issue(const UniValue& params, bool fHelp); extern UniValue paymentsaddress(const UniValue& params, bool fHelp); extern UniValue gatewaysaddress(const UniValue& params, bool fHelp); extern UniValue gatewayslist(const UniValue& params, bool fHelp); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 7160489de..bb6bb8c12 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5573,6 +5573,29 @@ UniValue marmara_receive(const UniValue& params, bool fHelp) return(MarmaraReceive(0,pubkey2pk(senderpub),amount,currency,matures,createtxid)); } +UniValue marmara_issue(const UniValue& params, bool fHelp) +{ + UniValue result(UniValue::VOBJ); uint256 createtxid; std::vector receiverpub; int64_t amount; int32_t matures; std::string currency; + if ( fHelp || params.size() != 5 ) + { + // marmaraissue 039433dc3749aece1bd568f374a45da3b0bc6856990d7da3cd175399577940a775 7.5 MARMARA 1440 e5b1ef8ec90e981d3011c8e024cef869b69af2d4dd6837d1ab1d394d3730b7cb + throw runtime_error("marmarareceive receiverpk amount currency matures createtxid\n"); + } + if ( ensure_CCrequirements() < 0 ) + throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + receiverpub = ParseHex(params[0].get_str().c_str()); + if (receiverpub.size()!= 33) + { + ERR_RESULT("invalid receiverpub pubkey"); + return result; + } + amount = atof(params[1].get_str().c_str()) * COIN + 0.00000000499999; + currency = params[2].get_str(); + matures = atol(params[3].get_str().c_str()) + chainActive.LastTip()->GetHeight() + 1; + createtxid = Parseuint256((char *)params[4].get_str().c_str()); + return(MarmaraIssue(0,pubkey2pk(receiverpub),amount,currency,matures,createtxid)); +} + UniValue channelslist(const UniValue& params, bool fHelp) { if ( fHelp || params.size() > 0 ) From 8ae7b65569a4f5dc8b0aee5929841a544e518539 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 13 Jan 2019 03:26:43 -1100 Subject: [PATCH 091/110] Off by 1 --- src/cc/marmara.cpp | 2 +- src/wallet/rpcwallet.cpp | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 5cd623966..1b06dfd2f 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -391,7 +391,7 @@ UniValue MarmaraIssue(uint64_t txfee,CPubKey receiverpk,int64_t amount,std::stri { result.push_back(Pair("result",(char *)"success")); result.push_back(Pair("rawtx",rawtx)); - result.push_back(Pair("funcid","R")); + result.push_back(Pair("funcid","I")); result.push_back(Pair("createtxid",createtxid.GetHex())); result.push_back(Pair("receiverpk",HexStr(receiverpk))); result.push_back(Pair("amount",ValueFromAmount(amount))); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index bb6bb8c12..e77f8e55a 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5578,8 +5578,8 @@ UniValue marmara_issue(const UniValue& params, bool fHelp) UniValue result(UniValue::VOBJ); uint256 createtxid; std::vector receiverpub; int64_t amount; int32_t matures; std::string currency; if ( fHelp || params.size() != 5 ) { - // marmaraissue 039433dc3749aece1bd568f374a45da3b0bc6856990d7da3cd175399577940a775 7.5 MARMARA 1440 e5b1ef8ec90e981d3011c8e024cef869b69af2d4dd6837d1ab1d394d3730b7cb - throw runtime_error("marmarareceive receiverpk amount currency matures createtxid\n"); + // marmaraissue 039433dc3749aece1bd568f374a45da3b0bc6856990d7da3cd175399577940a775 7.5 MARMARA 2693 e5b1ef8ec90e981d3011c8e024cef869b69af2d4dd6837d1ab1d394d3730b7cb + throw runtime_error("marmaraissue receiverpk amount currency matures createtxid\n"); } if ( ensure_CCrequirements() < 0 ) throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); @@ -5591,7 +5591,7 @@ UniValue marmara_issue(const UniValue& params, bool fHelp) } amount = atof(params[1].get_str().c_str()) * COIN + 0.00000000499999; currency = params[2].get_str(); - matures = atol(params[3].get_str().c_str()) + chainActive.LastTip()->GetHeight() + 1; + matures = atol(params[3].get_str().c_str()); createtxid = Parseuint256((char *)params[4].get_str().c_str()); return(MarmaraIssue(0,pubkey2pk(receiverpub),amount,currency,matures,createtxid)); } From c334d5c2e426605445bb6a5372dcfb3c99d634d9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 13 Jan 2019 03:36:14 -1100 Subject: [PATCH 092/110] Marmara transfer --- src/cc/CCMarmara.h | 2 +- src/cc/marmara.cpp | 5 +++-- src/rpc/server.cpp | 1 + src/rpc/server.h | 1 + src/wallet/rpcwallet.cpp | 25 ++++++++++++++++++++++++- 5 files changed, 30 insertions(+), 4 deletions(-) diff --git a/src/cc/CCMarmara.h b/src/cc/CCMarmara.h index 5fc1ce891..8fbe25b62 100644 --- a/src/cc/CCMarmara.h +++ b/src/cc/CCMarmara.h @@ -26,7 +26,7 @@ uint64_t komodo_block_prg(uint32_t nHeight); UniValue MarmaraPoolPayout(uint64_t txfee,int32_t firstheight,double perc,char *jsonstr); // [[pk0, shares0], [pk1, shares1], ...] UniValue MarmaraReceive(uint64_t txfee,CPubKey senderpk,int64_t amount,std::string currency,int32_t matures,uint256 createtxid); -UniValue MarmaraIssue(uint64_t txfee,CPubKey senderpk,int64_t amount,std::string currency,int32_t matures,uint256 createtxid); +UniValue MarmaraIssue(uint64_t txfee,uint8_t funcid,CPubKey senderpk,int64_t amount,std::string currency,int32_t matures,uint256 createtxid); bool MarmaraValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 1b06dfd2f..41287c76f 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -356,7 +356,7 @@ UniValue MarmaraReceive(uint64_t txfee,CPubKey senderpk,int64_t amount,std::stri return(result); } -UniValue MarmaraIssue(uint64_t txfee,CPubKey receiverpk,int64_t amount,std::string currency,int32_t matures,uint256 createtxid) +UniValue MarmaraIssue(uint64_t txfee,uint8_t funcid,CPubKey receiverpk,int64_t amount,std::string currency,int32_t matures,uint256 createtxid) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); UniValue result(UniValue::VOBJ); CPubKey mypk; struct CCcontract_info *cp,C; std::string rawtx; char *errorstr=0; @@ -391,7 +391,8 @@ UniValue MarmaraIssue(uint64_t txfee,CPubKey receiverpk,int64_t amount,std::stri { result.push_back(Pair("result",(char *)"success")); result.push_back(Pair("rawtx",rawtx)); - result.push_back(Pair("funcid","I")); + char str[2]; str[0] = funcid, str[1] = 0; + result.push_back(Pair("funcid",str)); result.push_back(Pair("createtxid",createtxid.GetHex())); result.push_back(Pair("receiverpk",HexStr(receiverpk))); result.push_back(Pair("amount",ValueFromAmount(amount))); diff --git a/src/rpc/server.cpp b/src/rpc/server.cpp index add90902c..497cb1ae2 100644 --- a/src/rpc/server.cpp +++ b/src/rpc/server.cpp @@ -446,6 +446,7 @@ static const CRPCCommand vRPCCommands[] = { "marmara", "marmarapoolpayout", &marmara_poolpayout, true }, { "marmara", "marmarareceive", &marmara_receive, true }, { "marmara", "marmaraissue", &marmara_issue, true }, + { "marmara", "marmaratransfer", &marmara_transfer, true }, // Payments { "payments", "paymentsaddress", &paymentsaddress, true }, diff --git a/src/rpc/server.h b/src/rpc/server.h index b7654da38..19680c0ef 100644 --- a/src/rpc/server.h +++ b/src/rpc/server.h @@ -275,6 +275,7 @@ extern UniValue marmaraaddress(const UniValue& params, bool fHelp); extern UniValue marmara_poolpayout(const UniValue& params, bool fHelp); extern UniValue marmara_receive(const UniValue& params, bool fHelp); extern UniValue marmara_issue(const UniValue& params, bool fHelp); +extern UniValue marmara_transfer(const UniValue& params, bool fHelp); extern UniValue paymentsaddress(const UniValue& params, bool fHelp); extern UniValue gatewaysaddress(const UniValue& params, bool fHelp); extern UniValue gatewayslist(const UniValue& params, bool fHelp); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index e77f8e55a..d0dc60489 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5593,7 +5593,30 @@ UniValue marmara_issue(const UniValue& params, bool fHelp) currency = params[2].get_str(); matures = atol(params[3].get_str().c_str()); createtxid = Parseuint256((char *)params[4].get_str().c_str()); - return(MarmaraIssue(0,pubkey2pk(receiverpub),amount,currency,matures,createtxid)); + return(MarmaraIssue(0,'I',pubkey2pk(receiverpub),amount,currency,matures,createtxid)); +} + +UniValue marmara_transfer(const UniValue& params, bool fHelp) +{ + UniValue result(UniValue::VOBJ); uint256 createtxid; std::vector receiverpub; int64_t amount; int32_t matures; std::string currency; + if ( fHelp || params.size() != 5 ) + { + // marmaraissue 039433dc3749aece1bd568f374a45da3b0bc6856990d7da3cd175399577940a775 7.5 MARMARA 2693 e5b1ef8ec90e981d3011c8e024cef869b69af2d4dd6837d1ab1d394d3730b7cb + throw runtime_error("marmaratransfer receiverpk amount currency matures createtxid\n"); + } + if ( ensure_CCrequirements() < 0 ) + throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + receiverpub = ParseHex(params[0].get_str().c_str()); + if (receiverpub.size()!= 33) + { + ERR_RESULT("invalid receiverpub pubkey"); + return result; + } + amount = atof(params[1].get_str().c_str()) * COIN + 0.00000000499999; + currency = params[2].get_str(); + matures = atol(params[3].get_str().c_str()); + createtxid = Parseuint256((char *)params[4].get_str().c_str()); + return(MarmaraIssue(0,'T',pubkey2pk(receiverpub),amount,currency,matures,createtxid)); } UniValue channelslist(const UniValue& params, bool fHelp) From e06138fecf70ac4e36ce1e084e64b1336738ec42 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 13 Jan 2019 05:34:42 -1100 Subject: [PATCH 093/110] Cap -ac_perc to be based on million max --- src/cc/marmara.cpp | 19 +++++-------------- src/komodo_bitcoind.h | 6 ++++-- src/wallet/rpcwallet.cpp | 2 +- 3 files changed, 10 insertions(+), 17 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 41287c76f..9a5a1e6ef 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -251,20 +251,9 @@ bool MarmaraValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &t } else if ( funcid == 'S' ) // collect -> automatically spend issuers locked funds, given 'I' { - return(true); - } - else if ( funcid == 'A' ) // agree -> agree that 'I' is unable to be redeemed, remainder - { - return(true); - } - else if ( funcid == 'D' ) // dispute -> given 'I' submit for manual arbitration - { - return(true); - } - else if ( funcid == 'F' ) // foreclose -> given 'A' collect as much of remainder from credit loop - { - return(true); + return(true); // iterate from issuer all remainder after maturity } + // staking only for locked utxo } return eval->Invalid("fall through error"); } @@ -315,6 +304,7 @@ UniValue MarmaraReceive(uint64_t txfee,CPubKey senderpk,int64_t amount,std::stri cp = CCinit(&C,EVAL_MARMARA); if ( txfee == 0 ) txfee = 10000; + // check for batonownership by senderpk and parameters match createtxid mypk = pubkey2pk(Mypubkey()); if ( currency != "MARMARA" ) errorstr = (char *)"for now, only MARMARA loops are supported"; @@ -363,6 +353,7 @@ UniValue MarmaraIssue(uint64_t txfee,uint8_t funcid,CPubKey receiverpk,int64_t a cp = CCinit(&C,EVAL_MARMARA); if ( txfee == 0 ) txfee = 10000; + // make sure if transfer that it is not too late mypk = pubkey2pk(Mypubkey()); if ( currency != "MARMARA" ) errorstr = (char *)"for now, only MARMARA loops are supported"; @@ -376,7 +367,7 @@ UniValue MarmaraIssue(uint64_t txfee,uint8_t funcid,CPubKey receiverpk,int64_t a { errorstr = (char *)"couldnt finalize CCtx"; mtx.vout.push_back(MakeCC1vout(EVAL_MARMARA,txfee,receiverpk)); - rawtx = FinalizeCCTx(0,cp,mtx,mypk,txfee,MarmaraLoopOpret('I',createtxid,receiverpk,amount,matures,currency)); + rawtx = FinalizeCCTx(0,cp,mtx,mypk,txfee,MarmaraLoopOpret(funcid,createtxid,receiverpk,amount,matures,currency)); if ( rawtx.size() > 0 ) errorstr = 0; } else errorstr = (char *)"dont have enough normal inputs for 2*txfee"; diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 841396a00..9ecb8ce77 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1165,10 +1165,12 @@ uint64_t komodo_commission(const CBlock *pblock,int32_t height) //fprintf(stderr,"(%d %.8f).%d ",i,dstr(pblock->vtx[i].vout[j].nValue),j); if ( i != 0 || j != 1 ) total += pblock->vtx[i].vout[j].nValue; + if ( total > 1000000 * COIN ) + total = 1000000 * COIN; } } - commission = ((total / 10000) * ASSETCHAINS_COMMISSION) / 10000; - //commission = ((total * ASSETCHAINS_COMMISSION) / COIN); + //commission = ((total / 10000) * ASSETCHAINS_COMMISSION) / 10000; + commission = ((total * ASSETCHAINS_COMMISSION) / COIN); } if ( commission < 10000 ) commission = 0; diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index d0dc60489..f17faca58 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5601,7 +5601,7 @@ UniValue marmara_transfer(const UniValue& params, bool fHelp) UniValue result(UniValue::VOBJ); uint256 createtxid; std::vector receiverpub; int64_t amount; int32_t matures; std::string currency; if ( fHelp || params.size() != 5 ) { - // marmaraissue 039433dc3749aece1bd568f374a45da3b0bc6856990d7da3cd175399577940a775 7.5 MARMARA 2693 e5b1ef8ec90e981d3011c8e024cef869b69af2d4dd6837d1ab1d394d3730b7cb + // marmaratransfer 039433dc3749aece1bd568f374a45da3b0bc6856990d7da3cd175399577940a775 7.5 MARMARA 2693 e5b1ef8ec90e981d3011c8e024cef869b69af2d4dd6837d1ab1d394d3730b7cb throw runtime_error("marmaratransfer receiverpk amount currency matures createtxid\n"); } if ( ensure_CCrequirements() < 0 ) From e565e0b7204314b2e48fdf83d6454a97a9b04df3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 13 Jan 2019 06:15:44 -1100 Subject: [PATCH 094/110] Break --- src/komodo_bitcoind.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 9ecb8ce77..b99b998e1 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1166,7 +1166,10 @@ uint64_t komodo_commission(const CBlock *pblock,int32_t height) if ( i != 0 || j != 1 ) total += pblock->vtx[i].vout[j].nValue; if ( total > 1000000 * COIN ) + { total = 1000000 * COIN; + break; + } } } //commission = ((total / 10000) * ASSETCHAINS_COMMISSION) / 10000; From aa7d0e8d888b5f11e4caf5e031924d2b196e8c93 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 13 Jan 2019 06:57:20 -1100 Subject: [PATCH 095/110] Fix pos64 with verushash --- src/miner.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/miner.cpp b/src/miner.cpp index 128a94e3a..ce2b88156 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -1197,7 +1197,7 @@ void static BitcoinMiner_noeq() miningTimer.start(); #ifdef ENABLE_WALLET - CBlockTemplate *ptr = CreateNewBlockWithKey(reservekey, Mining_height, 0); + CBlockTemplate *ptr = CreateNewBlockWithKey(reservekey, Mining_height, ASSETCHAINS_STAKED != 0 && GetArg("-genproclimit", -1) == 0); #else CBlockTemplate *ptr = CreateNewBlockWithKey(); #endif From 530fb3901342196b595572ffe6519d0516ec525f Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 13 Jan 2019 07:04:45 -1100 Subject: [PATCH 096/110] +print --- src/komodo_bitcoind.h | 4 ++-- src/miner.cpp | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index b99b998e1..b640d3db0 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -2084,7 +2084,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt komodo_segids(hashbuf,nHeight-101,100); if ( *blocktimep < tipindex->nTime+60 ) *blocktimep = tipindex->nTime+60; - //fprintf(stderr,"Start scan of utxo for staking %u ht.%d\n",(uint32_t)time(NULL),nHeight); +fprintf(stderr,"Start scan of utxo for staking %u ht.%d\n",(uint32_t)time(NULL),nHeight); bool resetstaker = false; if ( array != 0 ) @@ -2140,7 +2140,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt lasttime = (uint32_t)time(NULL); //fprintf(stderr,"finished kp data of utxo for staking %u ht.%d numkp.%d maxkp.%d\n",(uint32_t)time(NULL),nHeight,numkp,maxkp); } -//fprintf(stderr,"numkp.%d blocktime.%u\n",numkp,*blocktimep); +fprintf(stderr,"numkp.%d blocktime.%u\n",numkp,*blocktimep); block_from_future_rejecttime = (uint32_t)GetAdjustedTime() + 57; for (i=winners=0; inBits); + printf("isStake.%d\n",isStake); if ( ASSETCHAINS_SYMBOL[0] != 0 && isStake ) { LEAVE_CRITICAL_SECTION(cs_main); From 6c9d66ed0de5ca0af847cbf139251fefa6669dab Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 13 Jan 2019 07:10:50 -1100 Subject: [PATCH 097/110] Set isStaked --- src/miner.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/miner.cpp b/src/miner.cpp index 02a3e1a91..2c6f4af8d 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -482,7 +482,6 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 int32_t stakeHeight = chainActive.Height() + 1; //LogPrintf("CreateNewBlock(): total size %u blocktime.%u nBits.%08x\n", nBlockSize,blocktime,pblock->nBits); - printf("isStake.%d\n",isStake); if ( ASSETCHAINS_SYMBOL[0] != 0 && isStake ) { LEAVE_CRITICAL_SECTION(cs_main); @@ -802,6 +801,8 @@ CBlockTemplate* CreateNewBlockWithKey(CReserveKey& reservekey, int32_t nHeight, } if ( ASSETCHAINS_MARMARA != 0 && nHeight > 0 && (nHeight & 1) == 0 ) scriptPubKey = Marmara_scriptPubKey(nHeight,pubkey); + if ( ASSETCHAINS_STAKED != 0 && KOMODO_MININGTHREADS == 0 ) + isStake = true; return CreateNewBlock(pubkey,scriptPubKey, gpucount, isStake); } @@ -1198,7 +1199,7 @@ void static BitcoinMiner_noeq() miningTimer.start(); #ifdef ENABLE_WALLET - CBlockTemplate *ptr = CreateNewBlockWithKey(reservekey, Mining_height, ASSETCHAINS_STAKED != 0 && GetArg("-genproclimit", -1) == 0); + CBlockTemplate *ptr = CreateNewBlockWithKey(reservekey, Mining_height, 0); #else CBlockTemplate *ptr = CreateNewBlockWithKey(); #endif From db879566f571cc7c123b554fe83769d845ead722 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 13 Jan 2019 07:16:34 -1100 Subject: [PATCH 098/110] Test --- src/komodo_bitcoind.h | 8 ++++---- src/miner.cpp | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index b640d3db0..66097b3f9 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1312,12 +1312,12 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh } if ( validateflag != 0 ) { - /*for (i=31; i>=24; i--) + for (i=31; i>=24; i--) fprintf(stderr,"%02x",((uint8_t *)&hashval)[i]); fprintf(stderr," vs "); for (i=31; i>=24; i--) fprintf(stderr,"%02x",((uint8_t *)&bnTarget)[i]); - fprintf(stderr," segid.%d iter.%d winner.%d coinage.%llu %d ht.%d t.%u v%d diff.%d\n",segid,iter,winner,(long long)coinage,(int32_t)(blocktime - txtime),nHeight,blocktime,(int32_t)value,(int32_t)diff);*/ + fprintf(stderr," segid.%d iter.%d winner.%d coinage.%llu %d ht.%d t.%u v%d diff.%d\n",segid,iter,winner,(long long)coinage,(int32_t)(blocktime - txtime),nHeight,blocktime,(int32_t)value,(int32_t)diff); break; } } @@ -2084,7 +2084,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt komodo_segids(hashbuf,nHeight-101,100); if ( *blocktimep < tipindex->nTime+60 ) *blocktimep = tipindex->nTime+60; -fprintf(stderr,"Start scan of utxo for staking %u ht.%d\n",(uint32_t)time(NULL),nHeight); +//fprintf(stderr,"Start scan of utxo for staking %u ht.%d\n",(uint32_t)time(NULL),nHeight); bool resetstaker = false; if ( array != 0 ) @@ -2140,7 +2140,7 @@ fprintf(stderr,"Start scan of utxo for staking %u ht.%d\n",(uint32_t)time(NULL), lasttime = (uint32_t)time(NULL); //fprintf(stderr,"finished kp data of utxo for staking %u ht.%d numkp.%d maxkp.%d\n",(uint32_t)time(NULL),nHeight,numkp,maxkp); } -fprintf(stderr,"numkp.%d blocktime.%u\n",numkp,*blocktimep); +//fprintf(stderr,"numkp.%d blocktime.%u\n",numkp,*blocktimep); block_from_future_rejecttime = (uint32_t)GetAdjustedTime() + 57; for (i=winners=0; iGetHeight()+1, gpucount, ASSETCHAINS_STAKED != 0 && GetArg("-genproclimit", -1) == 0); + CBlockTemplate *ptr = CreateNewBlockWithKey(reservekey, pindexPrev->GetHeight()+1, gpucount, ASSETCHAINS_STAKED != 0 && KOMODO_MININGTHREADS == 0); #else CBlockTemplate *ptr = CreateNewBlockWithKey(); #endif @@ -1502,7 +1502,7 @@ void static BitcoinMiner() { static uint32_t counter; if ( counter++ < 100 && ASSETCHAINS_STAKED == 0 ) - fprintf(stderr,"created illegal block, retry\n"); + fprintf(stderr,"created illegal blockB, retry\n"); sleep(1); continue; } From 3118af7d07ab9b9375a8b8c1b4fb6a579a6100be Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 13 Jan 2019 07:24:38 -1100 Subject: [PATCH 099/110] +print --- src/komodo_bitcoind.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 66097b3f9..478aa9ac4 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -2039,9 +2039,9 @@ uint32_t komodo_eligible(arith_uint256 bnTarget,arith_uint256 ratio,struct komod kp->hashval = UintToArith256(hash); segid = ((nHeight + kp->segid32) & 0x3f); hashval = _komodo_eligible(kp,ratio,blocktime,maxiters,minage,segid,nHeight,prevtime); - //for (int i=32; i>=0; i--) - // fprintf(stderr,"%02x",((uint8_t *)&hashval)[i]); - //fprintf(stderr," b.%u minage.%d segid.%d ht.%d prev.%u\n",blocktime,minage,segid,nHeight,prevtime); + for (int i=32; i>=0; i--) + fprintf(stderr,"%02x",((uint8_t *)&hashval)[i]); + fprintf(stderr," b.%u minage.%d segid.%d ht.%d prev.%u\n",blocktime,minage,segid,nHeight,prevtime); if ( hashval <= bnTarget ) { for (iter=0; iter Date: Sun, 13 Jan 2019 07:26:02 -1100 Subject: [PATCH 100/110] Test --- src/miner.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/miner.cpp b/src/miner.cpp index f88b8f260..f6c3e1aac 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -1199,14 +1199,14 @@ void static BitcoinMiner_noeq() miningTimer.start(); #ifdef ENABLE_WALLET - CBlockTemplate *ptr = CreateNewBlockWithKey(reservekey, Mining_height, 0); + CBlockTemplate *ptr = CreateNewBlockWithKey(reservekey, Mining_height, ASSETCHAINS_STAKED != 0 && KOMODO_MININGTHREADS == 0); #else CBlockTemplate *ptr = CreateNewBlockWithKey(); #endif if ( ptr == 0 ) { static uint32_t counter; - if ( counter++ < 100 ) + if ( counter++ < 10 ) fprintf(stderr,"created illegal block, retry\n"); continue; } @@ -1501,7 +1501,7 @@ void static BitcoinMiner() if ( ptr == 0 ) { static uint32_t counter; - if ( counter++ < 100 && ASSETCHAINS_STAKED == 0 ) + if ( counter++ < 10 && ASSETCHAINS_STAKED == 0 ) fprintf(stderr,"created illegal blockB, retry\n"); sleep(1); continue; From 290926a05f81cbb586d60d24f106415507851981 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 13 Jan 2019 07:34:22 -1100 Subject: [PATCH 101/110] Test --- src/komodo_bitcoind.h | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 478aa9ac4..fb5ca24a0 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1312,12 +1312,12 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh } if ( validateflag != 0 ) { - for (i=31; i>=24; i--) + /*for (i=31; i>=24; i--) fprintf(stderr,"%02x",((uint8_t *)&hashval)[i]); fprintf(stderr," vs "); for (i=31; i>=24; i--) fprintf(stderr,"%02x",((uint8_t *)&bnTarget)[i]); - fprintf(stderr," segid.%d iter.%d winner.%d coinage.%llu %d ht.%d t.%u v%d diff.%d\n",segid,iter,winner,(long long)coinage,(int32_t)(blocktime - txtime),nHeight,blocktime,(int32_t)value,(int32_t)diff); + fprintf(stderr," segid.%d iter.%d winner.%d coinage.%llu %d ht.%d t.%u v%d diff.%d\n",segid,iter,winner,(long long)coinage,(int32_t)(blocktime - txtime),nHeight,blocktime,(int32_t)value,(int32_t)diff);*/ break; } } @@ -2039,8 +2039,11 @@ uint32_t komodo_eligible(arith_uint256 bnTarget,arith_uint256 ratio,struct komod kp->hashval = UintToArith256(hash); segid = ((nHeight + kp->segid32) & 0x3f); hashval = _komodo_eligible(kp,ratio,blocktime,maxiters,minage,segid,nHeight,prevtime); - for (int i=32; i>=0; i--) + for (int i=31; i>=16; i--) fprintf(stderr,"%02x",((uint8_t *)&hashval)[i]); + fprintf(stderr," vs "); + for (int i=31; i>=16; i--) + fprintf(stderr,"%02x",((uint8_t *)&bnTarget)[i]); fprintf(stderr," b.%u minage.%d segid.%d ht.%d prev.%u\n",blocktime,minage,segid,nHeight,prevtime); if ( hashval <= bnTarget ) { From 265c9b3c3b04bc1234594bc5aaee344502dff81c Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 13 Jan 2019 07:40:06 -1100 Subject: [PATCH 102/110] Test --- src/komodo_bitcoind.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index fb5ca24a0..9e05ea1f9 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -2052,9 +2052,15 @@ uint32_t komodo_eligible(arith_uint256 bnTarget,arith_uint256 ratio,struct komod if ( blocktime+iter+segid*2 < kp->txtime+minage ) continue; hashval = _komodo_eligible(kp,ratio,blocktime,iter,minage,segid,nHeight,prevtime); + for (int i=31; i>=16; i--) + fprintf(stderr,"%02x",((uint8_t *)&hashval)[i]); + fprintf(stderr," vs "); + for (int i=31; i>=16; i--) + fprintf(stderr,"%02x",((uint8_t *)&bnTarget)[i]); + fprintf(stderr," iter.%d\n",iter); if ( hashval <= bnTarget ) { - //fprintf(stderr,"winner %.8f blocktime.%u iter.%d segid.%d\n",(double)kp->nValue/COIN,blocktime,iter,segid); + fprintf(stderr,"winner %.8f blocktime.%u iter.%d segid.%d\n",(double)kp->nValue/COIN,blocktime,iter,segid); blocktime += iter; blocktime += segid * 2; return(blocktime); From 6922cdfa835e697a850bfed64e0a90f61ab42e39 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 13 Jan 2019 07:43:40 -1100 Subject: [PATCH 103/110] Test --- src/komodo_bitcoind.h | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 9e05ea1f9..bf7dff756 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -2039,12 +2039,12 @@ uint32_t komodo_eligible(arith_uint256 bnTarget,arith_uint256 ratio,struct komod kp->hashval = UintToArith256(hash); segid = ((nHeight + kp->segid32) & 0x3f); hashval = _komodo_eligible(kp,ratio,blocktime,maxiters,minage,segid,nHeight,prevtime); - for (int i=31; i>=16; i--) + /*for (int i=31; i>=16; i--) fprintf(stderr,"%02x",((uint8_t *)&hashval)[i]); fprintf(stderr," vs "); for (int i=31; i>=16; i--) fprintf(stderr,"%02x",((uint8_t *)&bnTarget)[i]); - fprintf(stderr," b.%u minage.%d segid.%d ht.%d prev.%u\n",blocktime,minage,segid,nHeight,prevtime); + fprintf(stderr," b.%u minage.%d segid.%d ht.%d prev.%u\n",blocktime,minage,segid,nHeight,prevtime);*/ if ( hashval <= bnTarget ) { for (iter=0; itertxtime+minage ) continue; hashval = _komodo_eligible(kp,ratio,blocktime,iter,minage,segid,nHeight,prevtime); - for (int i=31; i>=16; i--) - fprintf(stderr,"%02x",((uint8_t *)&hashval)[i]); - fprintf(stderr," vs "); - for (int i=31; i>=16; i--) - fprintf(stderr,"%02x",((uint8_t *)&bnTarget)[i]); - fprintf(stderr," iter.%d\n",iter); if ( hashval <= bnTarget ) { fprintf(stderr,"winner %.8f blocktime.%u iter.%d segid.%d\n",(double)kp->nValue/COIN,blocktime,iter,segid); @@ -2164,7 +2158,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt if ( (eligible2= komodo_eligible(bnTarget,ratio,kp,nHeight,*blocktimep,(uint32_t)tipindex->nTime+27,minage,hashbuf)) == 0 ) continue; eligible = komodo_stake(0,bnTarget,nHeight,kp->txid,kp->vout,0,(uint32_t)tipindex->nTime+27,kp->address); -//fprintf(stderr,"i.%d %u vs %u\n",i,eligible2,eligible); +fprintf(stderr,"i.%d %u vs %u\n",i,eligible2,eligible); if ( eligible > 0 ) { besttime = m = 0; @@ -2177,7 +2171,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt if ( eligible < block_from_future_rejecttime ) // nothing gained by going earlier break; m++; -//fprintf(stderr,"m.%d ht.%d validated winning blocktime %u -> %.8f eligible.%u test prior\n",m,nHeight,*blocktimep,(double)kp->nValue/COIN,eligible); +fprintf(stderr,"m.%d ht.%d validated winning blocktime %u -> %.8f eligible.%u test prior\n",m,nHeight,*blocktimep,(double)kp->nValue/COIN,eligible); } } else @@ -2187,7 +2181,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt } eligible = besttime; winners++; -//fprintf(stderr,"ht.%d validated winning [%d] -> %.8f eligible.%u test prior\n",nHeight,(int32_t)(eligible - tipindex->nTime),(double)kp->nValue/COIN,eligible); +fprintf(stderr,"ht.%d validated winning [%d] -> %.8f eligible.%u test prior\n",nHeight,(int32_t)(eligible - tipindex->nTime),(double)kp->nValue/COIN,eligible); if ( earliest == 0 || eligible < earliest || (eligible == earliest && (*utxovaluep == 0 || kp->nValue < *utxovaluep)) ) { earliest = eligible; @@ -2199,7 +2193,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt *txtimep = kp->txtime;//(uint32_t)out.tx->nLockTime; fprintf(stderr,"ht.%d earliest.%u [%d].%d (%s) nValue %.8f locktime.%u counter.%d winners.%d\n",nHeight,earliest,(int32_t)(earliest - tipindex->nTime),m,kp->address,(double)kp->nValue/COIN,*txtimep,counter,winners); } - } //else fprintf(stderr,"utxo not eligible\n"); + } else fprintf(stderr,"utxo not eligible\n"); } if ( numkp < 1000 && array != 0 ) { From 31bad59a04c8a09aa92c53a4d96e203fe4ef9094 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 13 Jan 2019 07:46:32 -1100 Subject: [PATCH 104/110] Test --- src/komodo_bitcoind.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index bf7dff756..634f61abf 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1267,7 +1267,7 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh } if ( value == 0 || txtime == 0 || blocktime == 0 || prevtime == 0 ) { - //fprintf(stderr,"komodo_stake null %.8f %u %u %u\n",dstr(value),txtime,blocktime,prevtime); + fprintf(stderr,"komodo_stake null %.8f %u %u %u\n",dstr(value),txtime,blocktime,prevtime); return(0); } if ( value < SATOSHIDEN ) @@ -1312,12 +1312,12 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh } if ( validateflag != 0 ) { - /*for (i=31; i>=24; i--) + for (i=31; i>=24; i--) fprintf(stderr,"%02x",((uint8_t *)&hashval)[i]); fprintf(stderr," vs "); for (i=31; i>=24; i--) fprintf(stderr,"%02x",((uint8_t *)&bnTarget)[i]); - fprintf(stderr," segid.%d iter.%d winner.%d coinage.%llu %d ht.%d t.%u v%d diff.%d\n",segid,iter,winner,(long long)coinage,(int32_t)(blocktime - txtime),nHeight,blocktime,(int32_t)value,(int32_t)diff);*/ + fprintf(stderr," segid.%d iter.%d winner.%d coinage.%llu %d ht.%d t.%u v%d diff.%d\n",segid,iter,winner,(long long)coinage,(int32_t)(blocktime - txtime),nHeight,blocktime,(int32_t)value,(int32_t)diff); break; } } @@ -2054,7 +2054,7 @@ uint32_t komodo_eligible(arith_uint256 bnTarget,arith_uint256 ratio,struct komod hashval = _komodo_eligible(kp,ratio,blocktime,iter,minage,segid,nHeight,prevtime); if ( hashval <= bnTarget ) { - fprintf(stderr,"winner %.8f blocktime.%u iter.%d segid.%d\n",(double)kp->nValue/COIN,blocktime,iter,segid); + //fprintf(stderr,"winner %.8f blocktime.%u iter.%d segid.%d\n",(double)kp->nValue/COIN,blocktime,iter,segid); blocktime += iter; blocktime += segid * 2; return(blocktime); From 05f3d0f8723ba0810ba099ba5cdcc5e094fcbadf Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 13 Jan 2019 07:52:01 -1100 Subject: [PATCH 105/110] Test --- src/komodo_bitcoind.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 634f61abf..ae564dc80 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1304,7 +1304,7 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh winner = 1; if ( validateflag == 0 ) { - //fprintf(stderr,"winner blocktime.%u iter.%d segid.%d\n",blocktime,iter,segid); + fprintf(stderr,"winner blocktime.%u iter.%d segid.%d\n",blocktime,iter,segid); blocktime += iter; blocktime += segid * 2; } @@ -1312,17 +1312,17 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh } if ( validateflag != 0 ) { - for (i=31; i>=24; i--) + /*for (i=31; i>=24; i--) fprintf(stderr,"%02x",((uint8_t *)&hashval)[i]); fprintf(stderr," vs "); for (i=31; i>=24; i--) fprintf(stderr,"%02x",((uint8_t *)&bnTarget)[i]); - fprintf(stderr," segid.%d iter.%d winner.%d coinage.%llu %d ht.%d t.%u v%d diff.%d\n",segid,iter,winner,(long long)coinage,(int32_t)(blocktime - txtime),nHeight,blocktime,(int32_t)value,(int32_t)diff); + fprintf(stderr," segid.%d iter.%d winner.%d coinage.%llu %d ht.%d t.%u v%d diff.%d\n",segid,iter,winner,(long long)coinage,(int32_t)(blocktime - txtime),nHeight,blocktime,(int32_t)value,(int32_t)diff);*/ break; } } //fprintf(stderr,"iterated until i.%d winner.%d\n",i,winner); - if ( 0 && validateflag != 0 ) + //if ( 0 && validateflag != 0 ) { for (i=31; i>=24; i--) fprintf(stderr,"%02x",((uint8_t *)&hashval)[i]); From b7f3a6778a92c16a5d93eb8ffa2906c2910a2eba Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 13 Jan 2019 07:58:01 -1100 Subject: [PATCH 106/110] Test --- src/komodo_bitcoind.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index ae564dc80..7741bfb11 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -2158,7 +2158,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt if ( (eligible2= komodo_eligible(bnTarget,ratio,kp,nHeight,*blocktimep,(uint32_t)tipindex->nTime+27,minage,hashbuf)) == 0 ) continue; eligible = komodo_stake(0,bnTarget,nHeight,kp->txid,kp->vout,0,(uint32_t)tipindex->nTime+27,kp->address); -fprintf(stderr,"i.%d %u vs %u\n",i,eligible2,eligible); +//fprintf(stderr,"i.%d %u vs %u\n",i,eligible2,eligible); if ( eligible > 0 ) { besttime = m = 0; @@ -2171,7 +2171,7 @@ fprintf(stderr,"i.%d %u vs %u\n",i,eligible2,eligible); if ( eligible < block_from_future_rejecttime ) // nothing gained by going earlier break; m++; -fprintf(stderr,"m.%d ht.%d validated winning blocktime %u -> %.8f eligible.%u test prior\n",m,nHeight,*blocktimep,(double)kp->nValue/COIN,eligible); +//fprintf(stderr,"m.%d ht.%d validated winning blocktime %u -> %.8f eligible.%u test prior\n",m,nHeight,*blocktimep,(double)kp->nValue/COIN,eligible); } } else @@ -2181,7 +2181,7 @@ fprintf(stderr,"m.%d ht.%d validated winning blocktime %u -> %.8f eligible.%u te } eligible = besttime; winners++; -fprintf(stderr,"ht.%d validated winning [%d] -> %.8f eligible.%u test prior\n",nHeight,(int32_t)(eligible - tipindex->nTime),(double)kp->nValue/COIN,eligible); +//fprintf(stderr,"ht.%d validated winning [%d] -> %.8f eligible.%u test prior\n",nHeight,(int32_t)(eligible - tipindex->nTime),(double)kp->nValue/COIN,eligible); if ( earliest == 0 || eligible < earliest || (eligible == earliest && (*utxovaluep == 0 || kp->nValue < *utxovaluep)) ) { earliest = eligible; @@ -2193,7 +2193,7 @@ fprintf(stderr,"ht.%d validated winning [%d] -> %.8f eligible.%u test prior\n",n *txtimep = kp->txtime;//(uint32_t)out.tx->nLockTime; fprintf(stderr,"ht.%d earliest.%u [%d].%d (%s) nValue %.8f locktime.%u counter.%d winners.%d\n",nHeight,earliest,(int32_t)(earliest - tipindex->nTime),m,kp->address,(double)kp->nValue/COIN,*txtimep,counter,winners); } - } else fprintf(stderr,"utxo not eligible\n"); + } //else fprintf(stderr,"utxo not eligible\n"); } if ( numkp < 1000 && array != 0 ) { @@ -2229,7 +2229,7 @@ fprintf(stderr,"ht.%d validated winning [%d] -> %.8f eligible.%u test prior\n",n for (i=0; i Date: Sun, 13 Jan 2019 07:59:28 -1100 Subject: [PATCH 107/110] Split commission calc --- src/komodo_bitcoind.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 7741bfb11..9dc481529 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1172,8 +1172,8 @@ uint64_t komodo_commission(const CBlock *pblock,int32_t height) } } } - //commission = ((total / 10000) * ASSETCHAINS_COMMISSION) / 10000; - commission = ((total * ASSETCHAINS_COMMISSION) / COIN); + commission = ((total / 10000) * ASSETCHAINS_COMMISSION) / 10000; + //commission = ((total * ASSETCHAINS_COMMISSION) / COIN); } if ( commission < 10000 ) commission = 0; From c50181ee6b42b611016553b37fb8615d1de78ce2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 13 Jan 2019 08:10:52 -1100 Subject: [PATCH 108/110] Use BitcoinMiner for staking verushash --- src/komodo_bitcoind.h | 2 +- src/miner.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 9dc481529..a469ad2ed 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1322,7 +1322,7 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh } } //fprintf(stderr,"iterated until i.%d winner.%d\n",i,winner); - //if ( 0 && validateflag != 0 ) + if ( 0 && validateflag != 0 ) { for (i=31; i>=24; i--) fprintf(stderr,"%02x",((uint8_t *)&hashval)[i]); diff --git a/src/miner.cpp b/src/miner.cpp index f6c3e1aac..d68ea7369 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -1907,12 +1907,12 @@ void static BitcoinMiner() for (int i = 0; i < nThreads; i++) { #ifdef ENABLE_WALLET - if (ASSETCHAINS_ALGO == ASSETCHAINS_EQUIHASH) + if (ASSETCHAINS_ALGO == ASSETCHAINS_EQUIHASH || (ASSETCHAINS_STAKED != 0 && KOMODO_MININGTHREADS == 0) ) minerThreads->create_thread(boost::bind(&BitcoinMiner, pwallet)); else minerThreads->create_thread(boost::bind(&BitcoinMiner_noeq, pwallet)); #else - if (ASSETCHAINS_ALGO == ASSETCHAINS_EQUIHASH) + if (ASSETCHAINS_ALGO == ASSETCHAINS_EQUIHASH || (ASSETCHAINS_STAKED != 0 && KOMODO_MININGTHREADS == 0) ) minerThreads->create_thread(&BitcoinMiner); else minerThreads->create_thread(&BitcoinMiner_noeq); From 5ee83c628c943094f7ab2c5b60c6d22ed65e5503 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 13 Jan 2019 08:24:46 -1100 Subject: [PATCH 109/110] -print --- src/komodo_bitcoind.h | 6 +++--- src/miner.cpp | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index a469ad2ed..ebc50fa62 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1267,7 +1267,7 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh } if ( value == 0 || txtime == 0 || blocktime == 0 || prevtime == 0 ) { - fprintf(stderr,"komodo_stake null %.8f %u %u %u\n",dstr(value),txtime,blocktime,prevtime); + //fprintf(stderr,"komodo_stake null %.8f %u %u %u\n",dstr(value),txtime,blocktime,prevtime); return(0); } if ( value < SATOSHIDEN ) @@ -1304,7 +1304,7 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh winner = 1; if ( validateflag == 0 ) { - fprintf(stderr,"winner blocktime.%u iter.%d segid.%d\n",blocktime,iter,segid); + //fprintf(stderr,"winner blocktime.%u iter.%d segid.%d\n",blocktime,iter,segid); blocktime += iter; blocktime += segid * 2; } @@ -2229,7 +2229,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt for (i=0; i 1 ) { - fprintf(stderr,"mine to -ac_script\n"); + //fprintf(stderr,"mine to -ac_script\n"); //txNew.vout[1].scriptPubKey = CScript() << ParseHex(); int32_t len = strlen(ASSETCHAINS_SCRIPTPUB.c_str()); len >>= 1; From cf9f6577fc260772a5f47ac022246577599d7622 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 13 Jan 2019 14:10:11 -1100 Subject: [PATCH 110/110] Adjust assert --- src/wallet/rpcwallet.cpp | 1 + src/wallet/wallet.cpp | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index f17faca58..007c187a6 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5537,6 +5537,7 @@ UniValue marmara_poolpayout(const UniValue& params, bool fHelp) if ( fHelp || params.size() != 3 ) { // marmarapoolpayout 0.5 2 '[["024131032ed90941e714db8e6dd176fe5a86c9d873d279edecf005c06f773da686",1000],["02ebc786cb83de8dc3922ab83c21f3f8a2f3216940c3bf9da43ce39e2a3a882c92",100]]'; + marmarapoolpayout 0 2 '[["024131032ed90941e714db8e6dd176fe5a86c9d873d279edecf005c06f773da686",1000]]' throw runtime_error("marmarapoolpayout perc firstheight \"[[\\\"pubkey\\\":shares], ...]\"\n"); } if ( ensure_CCrequirements() < 0 ) diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index dd188d418..0000f8d42 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -1180,7 +1180,7 @@ bool DecrementNoteWitnesses(NoteDataMap& noteDataMap, int indexHeight, int64_t n assert((nWitnessCacheSize - 1) >= nd->witnesses.size()); } } - assert(KOMODO_REWIND != 0 || nWitnessCacheSize > 0); + assert(KOMODO_REWIND != 0 || nWitnessCacheSize > 0 || WITNESS_CACHE_SIZE != _COINBASE_MATURITY+10); return true; }