From e71748db73d43d9340fb9cf82b53ead7f7e4206c Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Thu, 14 Mar 2019 16:44:37 +0800 Subject: [PATCH 001/447] fix 100% PoS chain --- 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 c530db4fb..ae9a9360b 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1527,7 +1527,7 @@ int32_t komodo_is_PoSblock(int32_t slowflag,int32_t height,CBlock *pblock,arith_ fprintf(stderr,"ht.%d isPoS.%d utxo not validated -> must be PoW fake\n",height,isPoS); isPoS = 0; } - else + else if ( ASSETCHAINS_STAKED != 100 ) { bnTarget = komodo_PoWtarget(&PoSperc,bnTarget,height,ASSETCHAINS_STAKED); if ( bhash < bnTarget ) From ab7558ab9db8c38d9bb6a84fd3ac3f5d4cd76aab Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Wed, 17 Apr 2019 17:42:24 +0800 Subject: [PATCH 002/447] inital commit for notarypay 0BR --- src/chain.h | 10 ++++- src/komodo_utils.h | 7 ++- src/main.cpp | 11 ++++- src/rpc/misc.cpp | 104 ++++++++++++++++++++++++++++++++++++++++++++- src/rpc/server.cpp | 2 + src/rpc/server.h | 2 + src/txdb.cpp | 2 + 7 files changed, 131 insertions(+), 7 deletions(-) diff --git a/src/chain.h b/src/chain.h index d810ed4cb..7ed6c4b4d 100644 --- a/src/chain.h +++ b/src/chain.h @@ -118,7 +118,7 @@ enum BlockStatus: uint32_t { BLOCK_FAILED_MASK = BLOCK_FAILED_VALID | BLOCK_FAILED_CHILD, BLOCK_ACTIVATES_UPGRADE = 128, //! block activates a network upgrade - BLOCK_IN_TMPFILE = 256 + BLOCK_IN_TMPFILE = 256 }; //! Short-hand for the highest consensus validity we implement. @@ -238,7 +238,7 @@ public: CBlockIndex* pskip; //! height of the entry in the chain. The genesis block has height 0 - int64_t newcoins,zfunds,sproutfunds; int8_t segid; // jl777 fields + int64_t newcoins,zfunds,sproutfunds,nNotaryPay; int8_t segid; // jl777 fields //! Which # file this block is stored in (blk?????.dat) int nFile; @@ -309,6 +309,7 @@ public: phashBlock = NULL; newcoins = zfunds = 0; segid = -2; + nNotaryPay = 0; pprev = NULL; pskip = NULL; nFile = 0; @@ -531,6 +532,11 @@ public: READWRITE(nBits); READWRITE(nNonce); READWRITE(nSolution); + + // LABS extra blockindex stuff. + // only read/write nNotaryPay if it has a value. This should be backwards compatible with all existing chains. + if ( nNotaryPay != 0 ) + READWRITE(nNotaryPay); // Only read/write nSproutValue if the client version used to create // this index was storing them. diff --git a/src/komodo_utils.h b/src/komodo_utils.h index d87b50716..a5c7a6a0d 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1539,7 +1539,7 @@ uint16_t komodo_port(char *symbol,uint64_t supply,uint32_t *magicp,uint8_t *extr printf("ports\n"); }*/ -char *iguanafmtstr = (char *)"curl --url \"http://127.0.0.1:7776\" --data \"{\\\"conf\\\":\\\"%s.conf\\\",\\\"path\\\":\\\"${HOME#\"/\"}/.komodo/%s\\\",\\\"unitval\\\":\\\"20\\\",\\\"zcash\\\":1,\\\"RELAY\\\":-1,\\\"VALIDATE\\\":0,\\\"prefetchlag\\\":-1,\\\"poll\\\":100,\\\"active\\\":1,\\\"agent\\\":\\\"iguana\\\",\\\"method\\\":\\\"addcoin\\\",\\\"startpend\\\":4,\\\"endpend\\\":4,\\\"services\\\":129,\\\"maxpeers\\\":8,\\\"newcoin\\\":\\\"%s\\\",\\\"name\\\":\\\"%s\\\",\\\"hasheaders\\\":1,\\\"useaddmultisig\\\":0,\\\"netmagic\\\":\\\"%s\\\",\\\"p2p\\\":%u,\\\"rpc\\\":%u,\\\"pubval\\\":60,\\\"p2shval\\\":85,\\\"wifval\\\":188,\\\"txfee_satoshis\\\":\\\"10000\\\",\\\"isPoS\\\":0,\\\"minoutput\\\":10000,\\\"minconfirms\\\":2,\\\"genesishash\\\":\\\"027e3758c3a65b12aa1046462b486d0a63bfa1beae327897f56c5cfb7daaae71\\\",\\\"protover\\\":170002,\\\"genesisblock\\\":\\\"0100000000000000000000000000000000000000000000000000000000000000000000003ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a000000000000000000000000000000000000000000000000000000000000000029ab5f490f0f0f200b00000000000000000000000000000000000000000000000000000000000000fd4005000d5ba7cda5d473947263bf194285317179d2b0d307119c2e7cc4bd8ac456f0774bd52b0cd9249be9d40718b6397a4c7bbd8f2b3272fed2823cd2af4bd1632200ba4bf796727d6347b225f670f292343274cc35099466f5fb5f0cd1c105121b28213d15db2ed7bdba490b4cedc69742a57b7c25af24485e523aadbb77a0144fc76f79ef73bd8530d42b9f3b9bed1c135ad1fe152923fafe98f95f76f1615e64c4abb1137f4c31b218ba2782bc15534788dda2cc08a0ee2987c8b27ff41bd4e31cd5fb5643dfe862c9a02ca9f90c8c51a6671d681d04ad47e4b53b1518d4befafefe8cadfb912f3d03051b1efbf1dfe37b56e93a741d8dfd80d576ca250bee55fab1311fc7b3255977558cdda6f7d6f875306e43a14413facdaed2f46093e0ef1e8f8a963e1632dcbeebd8e49fd16b57d49b08f9762de89157c65233f60c8e38a1f503a48c555f8ec45dedecd574a37601323c27be597b956343107f8bd80f3a925afaf30811df83c402116bb9c1e5231c70fff899a7c82f73c902ba54da53cc459b7bf1113db65cc8f6914d3618560ea69abd13658fa7b6af92d374d6eca9529f8bd565166e4fcbf2a8dfb3c9b69539d4d2ee2e9321b85b331925df195915f2757637c2805e1d4131e1ad9ef9bc1bb1c732d8dba4738716d351ab30c996c8657bab39567ee3b29c6d054b711495c0d52e1cd5d8e55b4f0f0325b97369280755b46a02afd54be4ddd9f77c22272b8bbb17ff5118fedbae2564524e797bd28b5f74f7079d532ccc059807989f94d267f47e724b3f1ecfe00ec9e6541c961080d8891251b84b4480bc292f6a180bea089fef5bbda56e1e41390d7c0e85ba0ef530f7177413481a226465a36ef6afe1e2bca69d2078712b3912bba1a99b1fbff0d355d6ffe726d2bb6fbc103c4ac5756e5bee6e47e17424ebcbf1b63d8cb90ce2e40198b4f4198689daea254307e52a25562f4c1455340f0ffeb10f9d8e914775e37d0edca019fb1b9c6ef81255ed86bc51c5391e0591480f66e2d88c5f4fd7277697968656a9b113ab97f874fdd5f2465e5559533e01ba13ef4a8f7a21d02c30c8ded68e8c54603ab9c8084ef6d9eb4e92c75b078539e2ae786ebab6dab73a09e0aa9ac575bcefb29e930ae656e58bcb513f7e3c17e079dce4f05b5dbc18c2a872b22509740ebe6a3903e00ad1abc55076441862643f93606e3dc35e8d9f2caef3ee6be14d513b2e062b21d0061de3bd56881713a1a5c17f5ace05e1ec09da53f99442df175a49bd154aa96e4949decd52fed79ccf7ccbce32941419c314e374e4a396ac553e17b5340336a1a25c22f9e42a243ba5404450b650acfc826a6e432971ace776e15719515e1634ceb9a4a35061b668c74998d3dfb5827f6238ec015377e6f9c94f38108768cf6e5c8b132e0303fb5a200368f845ad9d46343035a6ff94031df8d8309415bb3f6cd5ede9c135fdabcc030599858d803c0f85be7661c88984d88faa3d26fb0e9aac0056a53f1b5d0baed713c853c4a2726869a0a124a8a5bbc0fc0ef80c8ae4cb53636aa02503b86a1eb9836fcc259823e2692d921d88e1ffc1e6cb2bde43939ceb3f32a611686f539f8f7c9f0bf00381f743607d40960f06d347d1cd8ac8a51969c25e37150efdf7aa4c2037a2fd0516fb444525ab157a0ed0a7412b2fa69b217fe397263153782c0f64351fbdf2678fa0dc8569912dcd8e3ccad38f34f23bbbce14c6a26ac24911b308b82c7e43062d180baeac4ba7153858365c72c63dcf5f6a5b08070b730adb017aeae925b7d0439979e2679f45ed2f25a7edcfd2fb77a8794630285ccb0a071f5cce410b46dbf9750b0354aae8b65574501cc69efb5b6a43444074fee116641bb29da56c2b4a7f456991fc92b2\\\",\\\"debug\\\":0,\\\"seedipaddr\\\":\\\"%s\\\",\\\"sapling\\\":1}\""; +char *iguanafmtstr = (char *)"curl --url \"http://127.0.0.1:7776\" --data \"{\\\"conf\\\":\\\"%s.conf\\\",\\\"path\\\":\\\"${HOME#\"/\"}/.komodo/%s\\\",\\\"unitval\\\":\\\"20\\\",\\\"zcash\\\":1,\\\"RELAY\\\":-1,\\\"VALIDATE\\\":0,\\\"prefetchlag\\\":-1,\\\"poll\\\":100,\\\"active\\\":1,\\\"agent\\\":\\\"iguana\\\",\\\"method\\\":\\\"addcoin\\\",\\\"startpend\\\":4,\\\"endpend\\\":4,\\\"services\\\":129,\\\"maxpeers\\\":8,\\\"newcoin\\\":\\\"%s\\\",\\\"name\\\":\\\"%s\\\",\\\"hasheaders\\\":1,\\\"useaddmultisig\\\":0,\\\"netmagic\\\":\\\"%s\\\",\\\"p2p\\\":%u,\\\"rpc\\\":%u,\\\"pubval\\\":60,\\\"p2shval\\\":85,\\\"wifval\\\":188,\\\"txfee_satoshis\\\":\\\"10000\\\",\\\"isPoS\\\":0,\\\"minoutput\\\":10000,\\\"minconfirms\\\":2,\\\"genesishash\\\":\\\"027e3758c3a65b12aa1046462b486d0a63bfa1beae327897f56c5cfb7daaae71\\\",\\\"protover\\\":170002,\\\"genesisblock\\\":\\\"0100000000000000000000000000000000000000000000000000000000000000000000003ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a000000000000000000000000000000000000000000000000000000000000000029ab5f490f0f0f200b00000000000000000000000000000000000000000000000000000000000000fd4005000d5ba7cda5d473947263bf194285317179d2b0d307119c2e7cc4bd8ac456f0774bd52b0cd9249be9d40718b6397a4c7bbd8f2b3272fed2823cd2af4bd1632200ba4bf796727d6347b225f670f292343274cc35099466f5fb5f0cd1c105121b28213d15db2ed7bdba490b4cedc69742a57b7c25af24485e523aadbb77a0144fc76f79ef73bd8530d42b9f3b9bed1c135ad1fe152923fafe98f95f76f1615e64c4abb1137f4c31b218ba2782bc15534788dda2cc08a0ee2987c8b27ff41bd4e31cd5fb5643dfe862c9a02ca9f90c8c51a6671d681d04ad47e4b53b1518d4befafefe8cadfb912f3d03051b1efbf1dfe37b56e93a741d8dfd80d576ca250bee55fab1311fc7b3255977558cdda6f7d6f875306e43a14413facdaed2f46093e0ef1e8f8a963e1632dcbeebd8e49fd16b57d49b08f9762de89157c65233f60c8e38a1f503a48c555f8ec45dedecd574a37601323c27be597b956343107f8bd80f3a925afaf30811df83c402116bb9c1e5231c70fff899a7c82f73c902ba54da53cc459b7bf1113db65cc8f6914d3618560ea69abd13658fa7b6af92d374d6eca9529f8bd565166e4fcbf2a8dfb3c9b69539d4d2ee2e9321b85b331925df195915f2757637c2805e1d4131e1ad9ef9bc1bb1c732d8dba4738716d351ab30c996c8657bab39567ee3b29c6d054b711495c0d52e1cd5d8e55b4f0f0325b97369280755b46a02afd54be4ddd9f77c22272b8bbb17ff5118fedbae2564524e797bd28b5f74f7079d532ccc059807989f94d267f47e724b3f1ecfe00ec9e6541c961080d8891251b84b4480bc292f6a180bea089fef5bbda56e1e41390d7c0e85ba0ef530f7177413481a226465a36ef6afe1e2bca69d2078712b3912bba1a99b1fbff0d355d6ffe726d2bb6fbc103c4ac5756e5bee6e47e17424ebcbf1b63d8cb90ce2e40198b4f4198689daea254307e52a25562f4c1455340f0ffeb10f9d8e914775e37d0edca019fb1b9c6ef81255ed86bc51c5391e0591480f66e2d88c5f4fd7277697968656a9b113ab97f874fdd5f2465e5559533e01ba13ef4a8f7a21d02c30c8ded68e8c54603ab9c8084ef6d9eb4e92c75b078539e2ae786ebab6dab73a09e0aa9ac575bcefb29e930ae656e58bcb513f7e3c17e079dce4f05b5dbc18c2a872b22509740ebe6a3903e00ad1abc55076441862643f93606e3dc35e8d9f2caef3ee6be14d513b2e062b21d0061de3bd56881713a1a5c17f5ace05e1ec09da53f99442df175a49bd154aa96e4949decd52fed79ccf7ccbce32941419c314e374e4a396ac553e17b5340336a1a25c22f9e42a243ba5404450b650acfc826a6e432971ace776e15719515e1634ceb9a4a35061b668c74998d3dfb5827f6238ec015377e6f9c94f38108768cf6e5c8b132e0303fb5a200368f845ad9d46343035a6ff94031df8d8309415bb3f6cd5ede9c135fdabcc030599858d803c0f85be7661c88984d88faa3d26fb0e9aac0056a53f1b5d0baed713c853c4a2726869a0a124a8a5bbc0fc0ef80c8ae4cb53636aa02503b86a1eb9836fcc259823e2692d921d88e1ffc1e6cb2bde43939ceb3f32a611686f539f8f7c9f0bf00381f743607d40960f06d347d1cd8ac8a51969c25e37150efdf7aa4c2037a2fd0516fb444525ab157a0ed0a7412b2fa69b217fe397263153782c0f64351fbdf2678fa0dc8569912dcd8e3ccad38f34f23bbbce14c6a26ac24911b308b82c7e43062d180baeac4ba7153858365c72c63dcf5f6a5b08070b730adb017aeae925b7d0439979e2679f45ed2f25a7edcfd2fb77a8794630285ccb0a071f5cce410b46dbf9750b0354aae8b65574501cc69efb5b6a43444074fee116641bb29da56c2b4a7f456991fc92b2\\\",\\\"debug\\\":0,\\\"seedipaddr\\\":\\\"%s\\\",\\\"sapling\\\":1,\\\"notarypay\\\":%i}\""; @@ -2207,7 +2207,10 @@ void komodo_args(char *argv0) sprintf(fname,"%s_7776",ASSETCHAINS_SYMBOL); if ( (fp= fopen(fname,"wb")) != 0 ) { - fprintf(fp,iguanafmtstr,name.c_str(),name.c_str(),name.c_str(),name.c_str(),magicstr,ASSETCHAINS_P2PPORT,ASSETCHAINS_RPCPORT,"78.47.196.146"); + int8_t notarypay = 0; + if ( ASSETCHAINS_NOTARY_PAY[0] != 0 ) + notarypay = 1; + fprintf(fp,iguanafmtstr,name.c_str(),name.c_str(),name.c_str(),name.c_str(),magicstr,ASSETCHAINS_P2PPORT,ASSETCHAINS_RPCPORT,"78.47.196.146",notarypay); fclose(fp); //printf("created (%s)\n",fname); } else printf("error creating (%s)\n",fname); diff --git a/src/main.cpp b/src/main.cpp index 40da1b855..b8861bf9a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3269,7 +3269,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin auto verifier = libzcash::ProofVerifier::Strict(); auto disabledVerifier = libzcash::ProofVerifier::Disabled(); int32_t futureblock; - CAmount blockReward = 0; + CAmount blockReward = 0; uint64_t notarypaycheque = 0; // Check it again to verify JoinSplit proofs, and in case a previous version let a bad block in if (!CheckBlock(&futureblock,pindex->GetHeight(),pindex,block, state, fExpensiveChecks ? verifier : disabledVerifier, fCheckPOW, !fJustCheck) || futureblock != 0 ) { @@ -3307,7 +3307,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin return state.DoS(100, error("ConnectBlock(): Notaries have not been paid!"), REJECT_INVALID, "bad-cb-amount"); // calculate the notaries compensation and validate the amounts and pubkeys are correct. - uint64_t notarypaycheque = komodo_checknotarypay((CBlock *)&block,(int32_t)pindex->GetHeight()); + notarypaycheque = komodo_checknotarypay((CBlock *)&block,(int32_t)pindex->GetHeight()); //fprintf(stderr, "notarypaycheque.%lu\n", notarypaycheque); if ( notarypaycheque > 0 ) blockReward += notarypaycheque; @@ -3714,6 +3714,12 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin //FlushStateToDisk(); komodo_connectblock(false,pindex,*(CBlock *)&block); // dPoW state update. + if ( ASSETCHAINS_NOTARY_PAY[0] != 0 && pindex->GetHeight() > 10 ) + { + // Update the notary pay with the latest payment. + pindex->nNotaryPay = pindex->pprev->nNotaryPay + notarypaycheque; + fprintf(stderr, "total notary pay.%li\n", pindex->nNotaryPay); + } return true; } @@ -3923,6 +3929,7 @@ bool static DisconnectTip(CValidationState &state, bool fBare = false) { DisconnectNotarisations(block); } pindexDelete->segid = -2; + pindexDelete->nNotaryPay = 0; pindexDelete->newcoins = 0; pindexDelete->zfunds = 0; diff --git a/src/rpc/misc.cpp b/src/rpc/misc.cpp index 4e21ab9e9..c2ba9d702 100644 --- a/src/rpc/misc.cpp +++ b/src/rpc/misc.cpp @@ -75,6 +75,8 @@ uint32_t komodo_segid32(char *coinaddr); int64_t komodo_coinsupply(int64_t *zfundsp,int64_t *sproutfundsp,int32_t height); int32_t notarizedtxid_height(char *dest,char *txidstr,int32_t *kmdnotarized_heightp); int8_t StakedNotaryID(std::string ¬aryname, char *Raddress); +uint64_t komodo_notarypayamount(int32_t nHeight, int64_t notarycount); +int32_t komodo_notaries(uint8_t pubkeys[64][33],int32_t height,uint32_t timestamp); #define KOMODO_VERSION "0.3.3b" #define VERUS_VERSION "0.4.0g" @@ -168,7 +170,7 @@ UniValue geterablockheights(const UniValue& params, bool fHelp) { if (fHelp || params.size() != 0) throw runtime_error( - "getnotarysendmany\n" + "geterablockheights\n" "Returns a JSON object with the first block in each era.\n" ); @@ -1216,6 +1218,106 @@ UniValue getaddressdeltas(const UniValue& params, bool fHelp) } } +CAmount checkburnaddress(CAmount &received, int64_t &nNotaryPay, int32_t &height, std::string sAddress) +{ + CBitcoinAddress address(sAddress); + uint160 hashBytes; int type = 0; CAmount balance = 0; + if (address.GetIndexKey(hashBytes, type, false)) + { + std::vector > addressIndex; + if (GetAddressIndex(hashBytes, type, addressIndex)) + { + for (std::vector >::const_iterator it=addressIndex.begin(); it!=addressIndex.end(); it++) + { + if (it->second > 0) + received += it->second; + balance += it->second; + } + // Get notary pay from current chain tip + CBlockIndex* pindex = chainActive.LastTip(); + nNotaryPay = pindex->nNotaryPay; + height = pindex->GetHeight(); + } + } + return balance; +} + +UniValue checknotarization(const UniValue& params, bool fHelp) +{ + if (fHelp || params.size() != 0) + throw runtime_error( + "checknotarization\n" + "\nReturns true if burn address balance is greater than total notary pay. (requires addressindex to be enabled).\n" + ); + + UniValue result(UniValue::VOBJ); CAmount balance = 0, received = 0; int64_t nNotaryPay = 0; int32_t height; + + // helper to test burn address's + /*uint8_t priv[32] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; + uint8_t pub[33] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; + char coinaddr[64]; uint8_t buf33[33]; + //pubkey2addr(coinaddr, pub); + priv2addr(coinaddr,buf33,priv); + fprintf(stderr, "what.%s\n", coinaddr); + result.push_back(Pair("address", coinaddr)); + return result; + */ + + if ( ASSETCHAINS_NOTARY_PAY[0] == 0 ) + throw runtime_error("only works for ac_notarypay chains"); + // pubkey 020000000000000000000000000000000 + balance = checkburnaddress(received, nNotaryPay, height, "REDVp3ox1pbcWYCzySadfHhk8UU3HM4k5x"); + if ( nNotaryPay >= balance || received != balance ) + return false; + return true; +} + +UniValue getnotarypayinfo(const UniValue& params, bool fHelp) +{ + if (fHelp || params.size() != 0) + throw runtime_error( + "getnotarypayinfo\n" + "\nReturns infomation about ac_notaypay status (requires addressindex to be enabled).\n" + "\nResult:\n" + "{\n" + " \"height\" (number) The current block height\n" + " \"balance\" (number) The current balance of the burn address\n" + " \"spent\" (bool) true if coins have been spent from the burn address\n" + " \"Total_NotaryPay\" (number) Total amount paid to notaries\n" + " \"Estimated_Notarizations_Left\" (number) the estimated amount of notarizations left before the balance is consumed\n" + " \"Estimated_Days_Left\" (number) the estimated amount of days the current balance will last\n" + " \"Estimated_Height\" (number) the estimated block height funds will run out\n" + "}\n" + ); + + if ( ASSETCHAINS_NOTARY_PAY[0] == 0 ) + throw runtime_error("only works for ac_notarypay chains"); + + UniValue result(UniValue::VOBJ); CAmount balance = 0, received = 0; int64_t TotalNotaryPay = 0, NotaryPay, notaleft = 0, daysleft = 0, notarycount; int32_t height, endheight = 0; uint8_t notarypubkeys[64][33] = {0}; + + // pubkey 020000000000000000000000000000000 + balance = checkburnaddress(received, TotalNotaryPay, height, "REDVp3ox1pbcWYCzySadfHhk8UU3HM4k5x"); + + notarycount = komodo_notaries(notarypubkeys, height, chainActive[height]->GetBlockTime()); + NotaryPay = komodo_notarypayamount(height, notarycount); + bool spent = (received != balance); + if ( !spent ) + { + notaleft = (balance - TotalNotaryPay) / NotaryPay; + daysleft = (((ASSETCHAINS_BLOCKTIME * 5) * notaleft) / 3600) / 24; + endheight = (notaleft * 5) + height; + } + + result.push_back(Pair("height", height)); + result.push_back(Pair("balance", ValueFromAmount(balance))); + result.push_back(Pair("spent", spent)); + result.push_back(Pair("Total_NotaryPay", ValueFromAmount(TotalNotaryPay))); + result.push_back(Pair("Estimated_Notarizations_Left", notaleft)); + result.push_back(Pair("Estimated_Days_Left", daysleft)); + result.push_back(Pair("Estimated_Height", endheight)); + return result; +} + UniValue getaddressbalance(const UniValue& params, bool fHelp) { if (fHelp ||params.size() > 2 || params.size() == 0) diff --git a/src/rpc/server.cpp b/src/rpc/server.cpp index fc34a2a3f..969f937cf 100644 --- a/src/rpc/server.cpp +++ b/src/rpc/server.cpp @@ -538,6 +538,8 @@ static const CRPCCommand vRPCCommands[] = /* Address index */ { "addressindex", "getaddressmempool", &getaddressmempool, true }, { "addressindex", "getaddressutxos", &getaddressutxos, false }, + { "addressindex", "checknotarization", &checknotarization, false }, + { "addressindex", "getnotarypayinfo", &getnotarypayinfo, false }, { "addressindex", "getaddressdeltas", &getaddressdeltas, false }, { "addressindex", "getaddresstxids", &getaddresstxids, false }, { "addressindex", "getaddressbalance", &getaddressbalance, false }, diff --git a/src/rpc/server.h b/src/rpc/server.h index d8fd0e736..87f391dfa 100644 --- a/src/rpc/server.h +++ b/src/rpc/server.h @@ -210,6 +210,8 @@ extern UniValue getaddresstxids(const UniValue& params, bool fHelp); extern UniValue getsnapshot(const UniValue& params, bool fHelp); extern UniValue getaddressbalance(const UniValue& params, bool fHelp); extern UniValue getpeerinfo(const UniValue& params, bool fHelp); +extern UniValue checknotarization(const UniValue& params, bool fHelp); +extern UniValue getnotarypayinfo(const UniValue& params, bool fHelp); extern UniValue ping(const UniValue& params, bool fHelp); extern UniValue addnode(const UniValue& params, bool fHelp); extern UniValue disconnectnode(const UniValue& params, bool fHelp); diff --git a/src/txdb.cpp b/src/txdb.cpp index 4c9ea31ca..e6b4970db 100644 --- a/src/txdb.cpp +++ b/src/txdb.cpp @@ -712,6 +712,8 @@ bool CBlockTreeDB::LoadBlockIndexGuts() pindexNew->nTx = diskindex.nTx; pindexNew->nSproutValue = diskindex.nSproutValue; pindexNew->nSaplingValue = diskindex.nSaplingValue; + pindexNew->segid = diskindex.segid; + pindexNew->nNotaryPay = diskindex.nNotaryPay; //fprintf(stderr,"loadguts ht.%d\n",pindexNew->GetHeight()); // Consistency checks auto header = pindexNew->GetBlockHeader(); From 25bf471dddfa5efda2ad024ee4824d25619b0aee Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Wed, 17 Apr 2019 18:36:00 +0800 Subject: [PATCH 003/447] add notary pay stuff without breaking blockindex. --- src/chain.h | 13 ++++++++----- src/komodo_nk.h | 4 ++-- src/main.cpp | 4 ++-- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/chain.h b/src/chain.h index 7ed6c4b4d..4e5d7e48d 100644 --- a/src/chain.h +++ b/src/chain.h @@ -28,6 +28,7 @@ class CChainPower; #include "pow.h" #include "tinyformat.h" #include "uint256.h" +extern int8_t is_STAKED(const char *chain_name); #include @@ -36,6 +37,8 @@ class CChainPower; static const int SPROUT_VALUE_VERSION = 1001400; static const int SAPLING_VALUE_VERSION = 1010100; extern int32_t ASSETCHAINS_LWMAPOS; +extern char ASSETCHAINS_SYMBOL[65]; +//extern uint64_t ASSETCHAINS_NOTARY_PAY; struct CDiskBlockPos { @@ -532,11 +535,6 @@ public: READWRITE(nBits); READWRITE(nNonce); READWRITE(nSolution); - - // LABS extra blockindex stuff. - // only read/write nNotaryPay if it has a value. This should be backwards compatible with all existing chains. - if ( nNotaryPay != 0 ) - READWRITE(nNotaryPay); // Only read/write nSproutValue if the client version used to create // this index was storing them. @@ -549,6 +547,11 @@ public: if ((s.GetType() & SER_DISK) && (nVersion >= SAPLING_VALUE_VERSION)) { READWRITE(nSaplingValue); } + if ( (s.GetType() & SER_DISK) && (is_STAKED(ASSETCHAINS_SYMBOL) != 0) ) + { + READWRITE(nNotaryPay); + READWRITE(segid); + } } uint256 GetBlockHash() const diff --git a/src/komodo_nk.h b/src/komodo_nk.h index 3c9034dde..ed994c13f 100644 --- a/src/komodo_nk.h +++ b/src/komodo_nk.h @@ -1,7 +1,7 @@ #ifndef KOMODO_NK_H #define KOMODO_NK_H -#define ASSETCHAINS_N 96 -#define ASSETCHAINS_K 5 +#define ASSETCHAINS_N 77 +#define ASSETCHAINS_K 3 #endif diff --git a/src/main.cpp b/src/main.cpp index b8861bf9a..f5b57b364 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3714,11 +3714,11 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin //FlushStateToDisk(); komodo_connectblock(false,pindex,*(CBlock *)&block); // dPoW state update. - if ( ASSETCHAINS_NOTARY_PAY[0] != 0 && pindex->GetHeight() > 10 ) + if ( ASSETCHAINS_NOTARY_PAY[0] != 0 ) { // Update the notary pay with the latest payment. pindex->nNotaryPay = pindex->pprev->nNotaryPay + notarypaycheque; - fprintf(stderr, "total notary pay.%li\n", pindex->nNotaryPay); + //fprintf(stderr, "total notary pay.%li\n", pindex->nNotaryPay); } return true; } From 451773dcc13387036aac90daf52080dfc245395a Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 22 Apr 2019 00:00:01 +0800 Subject: [PATCH 004/447] initial commit for -earlytxid use with ac_script and ccvout_opret --- src/cc/CCutils.cpp | 4 +-- src/cc/payments.cpp | 62 ++++++++++++++++++++++++++++++++++------ src/komodo_bitcoind.h | 44 +++++++++++++++++++++++++--- src/komodo_defs.h | 2 +- src/komodo_utils.h | 1 + src/miner.cpp | 11 +++++-- src/rpc/server.cpp | 1 + src/rpc/server.h | 1 + src/wallet/rpcwallet.cpp | 36 ++++++++++++++++++++++- 9 files changed, 143 insertions(+), 19 deletions(-) diff --git a/src/cc/CCutils.cpp b/src/cc/CCutils.cpp index 3c4c6c67c..1610e2426 100644 --- a/src/cc/CCutils.cpp +++ b/src/cc/CCutils.cpp @@ -76,11 +76,9 @@ CScript getCCopret(const CScript &scriptPubKey) CScript dummy; CScript opret; if ( scriptPubKey.IsPayToCryptoCondition(&dummy, vParams) ) { - //opret << E_MARSHAL(ss << vParams[0]); + //fprintf(stderr, "vparams.%s\n", HexStr(vParams[0].begin(), vParams[0].end()).c_str()); opret = CScript(vParams[0].begin()+6, vParams[0].end()); } - //fprintf(stderr, "params_size.%li parmas_hexstr.%s\n", vParams.size(), HexStr(vParams[0].begin(),vParams[0].end()).c_str()); - //opret = CScript(vParams[0].begin(), vParams[0].end()); return opret; } diff --git a/src/cc/payments.cpp b/src/cc/payments.cpp index 526fea52f..7d6fcba32 100644 --- a/src/cc/payments.cpp +++ b/src/cc/payments.cpp @@ -16,11 +16,59 @@ #include "CCPayments.h" /* +--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- +ac_script + -earlytxid instructions with payments cc + rewards CC as an example. +How this works: + - earlytxid must be a transaction included in the chain before block 100. The chain MUST not have any other of these type of tx before block 100, or someone may be able to change it and mess things up. + - When it gets to block 100, it takes the txid specified by the -earlytxid param (does not affect magic) + - Looks up the transaction searches for the opreturn, then permenantly appends it to the end of ac_script in RAM. + - After every daemon restart, the first time the daemon mines a block, or receives a block that pays ac_script it will look up the op_return and save it again. + - this enables it to always reach consensus but doesnt need to constantly keep looking up the tx in the chain. + - The trick is to use ac_founders=101 or higher so that nothing is ever paid to the unspendable CC address. Although it should still work without this it burns coins. + +-ac_script can be any Global CC address you can spend to with an OP_RETURN. Here we use example of paymentsCC being used to fund a rewards plan, and a set of founders address's. + you can get the ac_script from another chain, but the op_return payload must generated on the chain itself. this command gives you the needed info to get the scripPubKey Hex: + ./komodo-cli -ac_name=TEST paymentsfund '["5d536f54332db09f2be04593c54f764cf569e225f4d8df5155658c679e663682",1000]' + append: b8, to the end of ac_script, this changes magic value for -earlytxid chains vs normal ac_script and allows bypass of ac_supply paid to the scritpt as it would be unspendable and you would be unable to create the needed plans with no coins. + -ac_script=2ea22c8020987fad30df055db6fd922c3a57e55d76601229ed3da3b31340112e773df3d0d28103120c008203000401ccb8 --earlytxid is not an -ac_param, so it doesnt affect the chain magics -extra data after the normal CCvout is whatever data we want and can represent whatever we want -so -ac_script= -in the validation if you see the useearlytxid in the opreturn data or extra data, you use the earlytxid as the txid that specifies the payment +start chain and make sure to do the following steps before block 100 (set generate false/true is a good idea between steps) +create rewards plan and fund it with all or a % of the premine. Must be some amount. eg. + ./komodo-cli -ac_name=TEST rewardscreatefunding test 1000 10 0 10 10 + +do rewards add funding and get the script pubkey and op_return from this tx (no need to send it) eg. + scriptPubKey: 2ea22c802065686d47a4049c2c845a71895a915eb84c04445896eec5dc0be40df0b31372da8103120c008203000401cc + OP_RETURN: 6a2ae541746573740000000061e7063fa8f99ef92a47e4aebf7ea28c59aeadaf3c1784312de64e4bcb3666f1 + +create txidopreturn for this payment: + ./komodo-cli -ac_name=TEST paymentstxidopret '[50,"2ea22c802065686d47a4049c2c845a71895a915eb84c04445896eec5dc0be40df0b31372da8103120c008203000401cc","6a2ae541746573740000000061e7063fa8f99ef92a47e4aebf7ea28c59aeadaf3c1784312de64e4bcb3666f1"]' + +create the txidopret for the founders reward(s) pubkeys: should be able to be a few here, not sure of max number yet. These can pay anything that does not need an opreturn. allocation and scriptpubkey hex. + ./komodo-cli -ac_name=TEST paymentstxidopret '[50,"76a9146bf5dd9f679c87a3f83ea176f82148d26653c04388ac"]' + +create payments plan: + ./komodo-cli -ac_name=TEST paymentscreate '[0,0,"273d193e5d09928e471926827dcac1f06c4801bdaa5524a84b17a00f4eaf8d38","81264daf7874b2041802ac681e49618413313cc2f29b47d47bd8e63dc2a06cad"]' +gives plan txid eg. 5d536f54332db09f2be04593c54f764cf569e225f4d8df5155658c679e663682 + +paymentsfund: + send some of the premine to this payments fund to get the rest of the scriptpubkey payload. (could skip send and just gen/decode the tx if required.) + send opret path this time to get the required script pubkey. For payments this mode is enabled by default rather than a traditional OP_RETURN, + for other CC we would need to modify daemon to get the correct info. + ./komodo-cli -ac_name=TEST paymentsfund '["5d536f54332db09f2be04593c54f764cf569e225f4d8df5155658c679e663682",1000,1]' + +get the payment fund script pubkey: (the split it at OP_CHECKCRYPTOCONDITION or 'cc' ) + 2ea22c8020987fad30df055db6fd922c3a57e55d76601229ed3da3b31340112e773df3d0d28103120c008203000401cc 2a0401f00101246a22f0466b75e35aa4d8ea6c3dd1b76141a0acbd06dfb4897288a62b8a8ec31b75a5b6cb75 + + put the second half into an OP_RETURN: (the remaining part of the the above scriptpubkey) eg. + ./komodo-cli -ac_name=TEST opreturn_burn 1 2a0401f00101246a22f0466b75e35aa4d8ea6c3dd1b76141a0acbd06dfb4897288a62b8a8ec31b75a5b6cb75 + opret_burn takes any burn amount and arbitrary hex string. (RPC works, but may have bugs, likely use this for LABS too with some fixes) + this gives a txid to locate it in the chain eg: + -earlytxid=1acd0b9b728feaea37a3f52d4106c35b0f8cfd19f9f3e64815d23ace0721d69d + restart the chain with earlytxid param before height 100 on BOTH NODES! + +once the payments plan has been funded with the mined coinbase you can issue payments release when conditions of the plan are met to fund founders reward/rewards plan. eg. + ./komodo-cli -ac_name=TEST paymentsrelease '["5d536f54332db09f2be04593c54f764cf569e225f4d8df5155658c679e663682",500]' +------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ 0) txidopret <- allocation, scriptPubKey, opret 1) create <- locked_blocks, minrelease, list of txidopret @@ -643,13 +691,11 @@ UniValue PaymentsFund(struct CCcontract_info *cp,char *jsonstr) else { opret = EncodePaymentsFundOpRet(txid); - fprintf(stderr, "opret.%s\n", HexStr(opret.begin(), opret.end()).c_str()); std::vector> vData = std::vector>(); if ( makeCCopret(opret, vData) ) - { mtx.vout.push_back(MakeCC1vout(EVAL_PAYMENTS,amount,Paymentspk,&vData)); - fprintf(stderr, "params_size.%li parmas_hexstr.%s\n", vData.size(), HexStr(vData[0].begin(),vData[0].end()).c_str()); - } + //fprintf(stderr, "scriptpubkey.%s\n", mtx.vout.back().scriptPubKey.ToString().c_str()); + //fprintf(stderr, "hex.%s\n", HexStr(mtx.vout.back().scriptPubKey.begin(), mtx.vout.back().scriptPubKey.end()).c_str()); } rawtx = FinalizeCCTx(0,cp,mtx,mypk,PAYMENTS_TXFEE,CScript()); if ( params != 0 ) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index bb5a093d3..3dd590417 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -2030,9 +2030,39 @@ uint64_t komodo_checknotarypay(CBlock *pblock,int32_t height) return(0); } +bool komodo_appendACscriptpub() +{ + static bool didinit = false; + if ( didinit ) + return didinit; + if ( ASSETCHAINS_SCRIPTPUB[ASSETCHAINS_SCRIPTPUB.back()] == 49 && ASSETCHAINS_SCRIPTPUB[ASSETCHAINS_SCRIPTPUB.back()-1] == 51 ) + { + CTransaction tx; uint256 blockhash; + // get transaction and check that it occured before height 100. + if ( myGetTransaction(KOMODO_EARLYTXID,tx,blockhash) && mapBlockIndex[blockhash]->GetHeight() < 100 ) + { + for (int i = 0; i < tx.vout.size(); i++) + { + if ( tx.vout[i].scriptPubKey[0] == OP_RETURN ) + { + ASSETCHAINS_SCRIPTPUB.pop_back(); ASSETCHAINS_SCRIPTPUB.pop_back(); // remove last 2 chars. + // get OP_RETURN from txid and append the HexStr of it to scriptpub + ASSETCHAINS_SCRIPTPUB.append(HexStr(tx.vout[i].scriptPubKey.begin()+3, tx.vout[i].scriptPubKey.end())); + //fprintf(stderr, "ac_script.%s\n",ASSETCHAINS_SCRIPTPUB.c_str()); + didinit = true; + return true; + } + } + } + fprintf(stderr, "could not get KOMODO_EARLYTXID.%s OP_RETURN data. Restart with correct txid!\n", KOMODO_EARLYTXID.GetHex().c_str()); + StartShutdown(); + } + return false; +} + int64_t komodo_checkcommission(CBlock *pblock,int32_t height) { - int64_t checktoshis=0; uint8_t *script,scripthex[8192]; int32_t scriptlen,matched = 0; + int64_t checktoshis=0; uint8_t *script,scripthex[8192]; int32_t scriptlen,matched = 0; static bool didinit = false; if ( ASSETCHAINS_COMMISSION != 0 || ASSETCHAINS_FOUNDERS_REWARD != 0 ) { checktoshis = komodo_commission(pblock,height); @@ -2054,6 +2084,12 @@ int64_t komodo_checkcommission(CBlock *pblock,int32_t height) } if ( ASSETCHAINS_SCRIPTPUB.size() > 1 ) { + static bool didinit = false; + if ( !didinit && height > 100 && KOMODO_EARLYTXID != zeroid && komodo_appendACscriptpub() ) + { + fprintf(stderr, "appended CC_op_return to ASSETCHAINS_SCRIPTPUB.%s\n", ASSETCHAINS_SCRIPTPUB.c_str()); + didinit = true; + } if ( ASSETCHAINS_SCRIPTPUB.size()/2 == scriptlen && scriptlen < sizeof(scripthex) ) { decode_hex(scripthex,scriptlen,(char *)ASSETCHAINS_SCRIPTPUB.c_str()); @@ -2190,11 +2226,11 @@ int32_t komodo_checkPOW(int32_t slowflag,CBlock *pblock,int32_t height) else if ( ASSETCHAINS_STAKED != 0 ) failed = 0; } - if ( failed == 0 && ASSETCHAINS_COMMISSION != 0 ) //ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 ) + if ( failed == 0 && ASSETCHAINS_COMMISSION != 0 ) { if ( height == 1 ) { - if ( ASSETCHAINS_SCRIPTPUB.size() > 1 ) + if ( ASSETCHAINS_SCRIPTPUB.size() > 1 && ASSETCHAINS_SCRIPTPUB[ASSETCHAINS_SCRIPTPUB.back()] != 49 && ASSETCHAINS_SCRIPTPUB[ASSETCHAINS_SCRIPTPUB.back()-1] != 51 ) { int32_t scriptlen; uint8_t scripthex[10000]; script = (uint8_t *)&pblock->vtx[0].vout[0].scriptPubKey[0]; @@ -2206,7 +2242,7 @@ int32_t komodo_checkPOW(int32_t slowflag,CBlock *pblock,int32_t height) return(-1); } else return(-1); } - else + else if ( ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 ) { script = (uint8_t *)&pblock->vtx[0].vout[0].scriptPubKey[0]; scriptlen = (int32_t)pblock->vtx[0].vout[0].scriptPubKey.size(); diff --git a/src/komodo_defs.h b/src/komodo_defs.h index ecaf7339a..ecb503be9 100644 --- a/src/komodo_defs.h +++ b/src/komodo_defs.h @@ -63,7 +63,7 @@ extern uint8_t NOTARY_PUBKEY33[33],ASSETCHAINS_OVERRIDE_PUBKEY33[33],ASSETCHAINS extern std::vector ASSETCHAINS_PRICES,ASSETCHAINS_STOCKS; extern int32_t VERUS_BLOCK_POSUNITS, VERUS_CONSECUTIVE_POS_THRESHOLD, VERUS_NOPOS_THRESHHOLD; - +extern uint256 KOMODO_EARLYTXID; extern int32_t KOMODO_CONNECTING,KOMODO_CCACTIVATE,KOMODO_DEALERNODE; extern uint32_t ASSETCHAINS_CC; diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 88efb0264..cfb133a9d 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -2072,6 +2072,7 @@ void komodo_args(char *argv0) extralen += iguana_rwnum(1,&extraptr[extralen],sizeof(ASSETCHAINS_FOUNDERS),(void *)&ASSETCHAINS_FOUNDERS); if ( ASSETCHAINS_FOUNDERS_REWARD != 0 ) { + fprintf(stderr, "set founders reward.%li\n",ASSETCHAINS_FOUNDERS_REWARD); extralen += iguana_rwnum(1,&extraptr[extralen],sizeof(ASSETCHAINS_FOUNDERS_REWARD),(void *)&ASSETCHAINS_FOUNDERS_REWARD); } } diff --git a/src/miner.cpp b/src/miner.cpp index e199acccd..a2ff8c933 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -156,6 +156,7 @@ uint64_t komodo_notarypay(CMutableTransaction &txNew, std::vector &Notar int32_t komodo_notaries(uint8_t pubkeys[64][33],int32_t height,uint32_t timestamp); int32_t komodo_getnotarizedheight(uint32_t timestamp,int32_t height, uint8_t *script, int32_t len); CScript komodo_mineropret(int32_t nHeight); +bool komodo_appendACscriptpub(); CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32_t gpucount, bool isStake) { @@ -652,6 +653,12 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 txNew.vout[1].nValue = commission; if ( ASSETCHAINS_SCRIPTPUB.size() > 1 ) { + static bool didinit = false; + if ( !didinit && nHeight > 100 && KOMODO_EARLYTXID != zeroid && komodo_appendACscriptpub() ) + { + fprintf(stderr, "appended ccopreturn to ASSETCHAINS_SCRIPTPUB.%s\n", ASSETCHAINS_SCRIPTPUB.c_str()); + didinit = true; + } //fprintf(stderr,"mine to -ac_script\n"); //txNew.vout[1].scriptPubKey = CScript() << ParseHex(); int32_t len = strlen(ASSETCHAINS_SCRIPTPUB.c_str()); @@ -895,14 +902,14 @@ void IncrementExtraNonce(CBlock* pblock, CBlockIndex* pindexPrev, unsigned int& CBlockTemplate* CreateNewBlockWithKey(CReserveKey& reservekey, int32_t nHeight, int32_t gpucount, bool isStake) { CPubKey pubkey; CScript scriptPubKey; uint8_t *script,*ptr; int32_t i,len; - if ( nHeight == 1 && ASSETCHAINS_COMMISSION != 0 ) + if ( nHeight == 1 && ASSETCHAINS_COMMISSION != 0 && ASSETCHAINS_SCRIPTPUB[ASSETCHAINS_SCRIPTPUB.back()] != 49 && ASSETCHAINS_SCRIPTPUB[ASSETCHAINS_SCRIPTPUB.back()-1] != 51 ) { if ( ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 ) { pubkey = ParseHex(ASSETCHAINS_OVERRIDE_PUBKEY); scriptPubKey = CScript() << ParseHex(HexStr(pubkey)) << OP_CHECKSIG; } - else + else { len = strlen(ASSETCHAINS_SCRIPTPUB.c_str()); len >>= 1; diff --git a/src/rpc/server.cpp b/src/rpc/server.cpp index 3ed082455..79a782c35 100644 --- a/src/rpc/server.cpp +++ b/src/rpc/server.cpp @@ -639,6 +639,7 @@ static const CRPCCommand vRPCCommands[] = { "wallet", "z_importviewingkey", &z_importviewingkey, true }, { "wallet", "z_exportwallet", &z_exportwallet, true }, { "wallet", "z_importwallet", &z_importwallet, true }, + { "wallet", "opreturn_burn", &opreturn_burn, true }, // TODO: rearrange into another category { "disclosure", "z_getpaymentdisclosure", &z_getpaymentdisclosure, true }, diff --git a/src/rpc/server.h b/src/rpc/server.h index 8e0054e6f..bcbe644a3 100644 --- a/src/rpc/server.h +++ b/src/rpc/server.h @@ -466,6 +466,7 @@ extern UniValue z_shieldcoinbase(const UniValue& params, bool fHelp); // in rpcw extern UniValue z_getoperationstatus(const UniValue& params, bool fHelp); // in rpcwallet.cpp extern UniValue z_getoperationresult(const UniValue& params, bool fHelp); // in rpcwallet.cpp extern UniValue z_listoperationids(const UniValue& params, bool fHelp); // in rpcwallet.cpp +extern UniValue opreturn_burn(const UniValue& params, bool fHelp); // in rpcwallet.cpp extern UniValue z_validateaddress(const UniValue& params, bool fHelp); // in rpcmisc.cpp extern UniValue z_getpaymentdisclosure(const UniValue& params, bool fHelp); // in rpcdisclosure.cpp extern UniValue z_validatepaymentdisclosure(const UniValue ¶ms, bool fHelp); // in rpcdisclosure.cpp diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 847205ec1..de446390e 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -7979,9 +7979,11 @@ UniValue test_ac(const UniValue& params, bool fHelp) return(FinalizeCCTx(0, cp, mtx, myPubkey, txfee, opret)); } +extern bool komodo_appendACscriptpub(); + UniValue test_heirmarker(const UniValue& params, bool fHelp) { - // make fake token tx: + //make fake token tx: struct CCcontract_info *cp, C; if (fHelp || (params.size() != 1)) @@ -8010,6 +8012,38 @@ UniValue test_heirmarker(const UniValue& params, bool fHelp) return(FinalizeCCTx(0, cp, mtx, myPubkey, 10000, opret)); } +UniValue opreturn_burn(const UniValue& params, bool fHelp) +{ + struct CCcontract_info *cp, C; UniValue ret(UniValue::VOBJ); + if (ensure_CCrequirements(EVAL_PAYMENTS) < 0) + throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + cp = CCinit(&C, EVAL_PAYMENTS); + if (fHelp || (params.size() != 2)) + throw runtime_error("amount to burn, hexstring to send\n"); + + CAmount nAmount = AmountFromValue(params[0]); + if (nAmount <= 10000) + throw JSONRPCError(RPC_TYPE_ERROR, "must send at least 10000 sat"); + std::string strHex = params[1].get_str(); + CPubKey myPubkey = pubkey2pk(Mypubkey()); + CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); + + int64_t normalInputs = AddNormalinputs(mtx, myPubkey, nAmount, 60); + if (normalInputs < nAmount) + throw runtime_error("not enough normals\n"); + + CScript opret; uint8_t scripthex[8192]; + + decode_hex(scripthex,strHex.size()/2,(char *)strHex.c_str()); + std::string test; + test.append((char*)scripthex); + std::vector opretdata(test.begin(), test.end()); + opret << OP_RETURN << E_MARSHAL(ss << opretdata); + mtx.vout.push_back(CTxOut(nAmount,opret)); + ret.push_back(Pair("hex",FinalizeCCTx(0, cp, mtx, myPubkey, 10000, CScript()))); + return(ret); +} + UniValue test_burntx(const UniValue& params, bool fHelp) { // make fake token tx: From 489485252b68597bc9173328ed21674b58f90b8b Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 22 Apr 2019 18:02:19 +0800 Subject: [PATCH 005/447] fixes for TESTHC chain and add notes for others to make similar chains. --- src/cc/hempcoin_notes.txt | 65 +++++++++++++++++++++++++++++++ src/cc/payments.cpp | 80 +++++++-------------------------------- src/komodo_bitcoind.h | 3 +- src/wallet/rpcwallet.cpp | 20 +++++----- 4 files changed, 91 insertions(+), 77 deletions(-) create mode 100644 src/cc/hempcoin_notes.txt diff --git a/src/cc/hempcoin_notes.txt b/src/cc/hempcoin_notes.txt new file mode 100644 index 000000000..f8003ac95 --- /dev/null +++ b/src/cc/hempcoin_notes.txt @@ -0,0 +1,65 @@ +How this works: + - earlytxid must be a transaction included in the chain before block 100. The chain MUST not have any other of these type of tx before block 100, or someone may be able to change it and mess things up. + - When it gets to block 100, it takes the txid specified by the -earlytxid param (does not affect magic) + - Looks up the transaction searches for the opreturn, then permenantly appends it to the end of ac_script in RAM. + - After every daemon restart, the first time the daemon mines a block, or receives a block that pays ac_script it will look up the op_return and save it again. + - this enables it to always reach consensus but doesnt need to constantly keep looking up the tx in the chain. + - The trick is to use ac_founders=101 or higher so that nothing is ever paid to the unspendable CC address. Although it should still work without this it burns coins. + +-ac_script can be any Global CC address you can spend to with an OP_RETURN. Here we use example of paymentsCC being used to fund a rewards plan, and a set of founders address's. + you can get the ac_script from another chain, but the op_return payload must generated on the chain itself. this command gives you the needed info to get the scripPubKey Hex: + ./komodo-cli -ac_name=TEST paymentsfund '["5d536f54332db09f2be04593c54f764cf569e225f4d8df5155658c679e663682",1000]' + append: b8, to the end of ac_script, this changes magic value for -earlytxid chains vs normal ac_script and allows bypass of ac_supply paid to the scritpt as it would be unspendable and you would be unable to create the needed plans with no coins. + -ac_script=2ea22c8020987fad30df055db6fd922c3a57e55d76601229ed3da3b31340112e773df3d0d28103120c008203000401ccb8 + +-testnode=1 is not affecting magic and allows mining on a single node, we can use this to bootstrap the chain before syncing a second node to save time. + +start chain and make sure to do the following steps before block 100 (set generate false/true is a good idea between steps) + ./komodod -ac_name=TESTHC -ac_supply=1000000 -ac_reward=100000000000 -ac_cc=2 -ac_script=2ea22c8020987fad30df055db6fd922c3a57e55d76601229ed3da3b31340112e773df3d0d28103120c008203000401ccb8 -ac_founders=150 -ac_blocktime=20 -ac_nk=96,5 -testnode=1 + +create rewards plan and fund it with all or a % of the premine. Must be some amount. eg. + ./komodo-cli -ac_name=TESTHC rewardscreatefunding test 50000 25 0 2 500 + +do rewards add funding: + ./komodo-cli -ac_name=TESTHC rewardsaddfunding test 47a3150150bd196bd2086cae5e0c6b01a23785a04139fa660d169121a534b38e 1000 + +and get the script pubkey and op_return from this tx (no need to send it) +./komodo-cli -ac_name=TESTHC decoderawtransaction 010000000204ca4c7aaae62bb8fc9412ac010e047fa8d33c3f87d2adeb3e02170642ddfe370000000049483045022100d7b9a +4f28ca3a35f34dcdb6075e905cde1eaa962bd0619d0a8ed8e17e952bc99022077308e12325fc2a02c752ec3df9aeee1fc219ea54a4d3884834582b75c89815e01ffffffff08800132da3233d80c65e87b6db6a76dcf +188e4fdfa23198d69f647e67754cfb0000000049483045022100d6a8f7a1c4f6013f5897768ae0117fe61dfb72352d3e6652e64a6588db3ffcb102202aa1d041b24f9cbbf7028295b7c5e7f18b4f95ae39c13031dab +7f06634438e6801ffffffff0300e8764817000000302ea22c802065686d47a4049c2c845a71895a915eb84c04445896eec5dc0be40df0b31372da8103120c008203000401ccf0c0764817000000232103bbec93af84 +0933ae2d35fc56eff24f34dbe26871402552f84c44f690945ccd79ac00000000000000002c6a2ae54174657374000000008eb334a52191160d66fa3941a08537a2016b0c5eae6c08d26b19bd500115a34700000000 + +From the return of this you need the scriptpubkey hex of vout 0: + scriptPubKey: 2ea22c802065686d47a4049c2c845a71895a915eb84c04445896eec5dc0be40df0b31372da8103120c008203000401cc +and the scriptpubkey hex of the OP_RETURN in vout 2. + OP_RETURN: 6a2ae54174657374000000008eb334a52191160d66fa3941a08537a2016b0c5eae6c08d26b19bd500115a347 + +create txidopreturn for this payment: + ./komodo-cli -ac_name=TESTHC paymentstxidopret '[50,"2ea22c802065686d47a4049c2c845a71895a915eb84c04445896eec5dc0be40df0b31372da8103120c008203000401cc","6a2ae54174657374000000008eb334a52191160d66fa3941a08537a2016b0c5eae6c08d26b19bd500115a347"]' + +create the txidopret for the founders reward(s) pubkeys: should be able to be a few here, not sure of max number yet. These can pay anything that does not need an opreturn. allocation and scriptpubkey hex. + ./komodo-cli -ac_name=TESTHC paymentstxidopret '[50,"76a9146bf5dd9f679c87a3f83ea176f82148d26653c04388ac"]' + +create payments plan: + ./komodo-cli -ac_name=TESTHC paymentscreate '[0,0,"61f55f2f87dad3a37d42731a8cb73b3ebea1817abfa176218162c360a8bd7145","0550014823ffa0aa99d7dd7ca5292f4dd0a1b9156eddec03412c953f095181bc"]' +gives plan txid: ee7765be874fb084c00538b1b0488e8ecb857de253f09a9ba6ea8d3579b77d33 + +paymentsfund: + To do this you first need to change the type of tx generated by paymentsfund RPC. in payments.cpp go to line: 639 and comment it out, then uncomment the block of code under this. + change the line 646 to line 647 with comments, and line 650/651 aswell. This enables the RPC to generate the ccvout opreturn payload you need without sending the payment on the chain. Just decode the raw hex. + ./komodo-cli -ac_name=TESTHC paymentsfund '["ee7765be874fb084c00538b1b0488e8ecb857de253f09a9ba6ea8d3579b77d33",1000,1]' + +get the payment fund scriptpubkey hex from vout 0: (the split it at OP_CHECKCRYPTOCONDITION or 'cc' ) + 2ea22c8020987fad30df055db6fd922c3a57e55d76601229ed3da3b31340112e773df3d0d28103120c008203000401cc 2a0401f00101246a22f046337db779358deaa69b9af053e27d85cb8e8e48b0b13805c084b04f87be6577ee75 + + put the second half into an OP_RETURN: (the remaining part of the the above scriptpubkey) eg. + ./komodo-cli -ac_name=TESTHC opreturn_burn 1 2a0401f00101246a22f046337db779358deaa69b9af053e27d85cb8e8e48b0b13805c084b04f87be6577ee75 + opret_burn takes any burn amount and arbitrary hex string. (RPC works, but may have bugs, likely use this for LABS too with some fixes) + this gives a raw hex. Decode it and check the OP_RETURN is right before sending (using this RPC currently adds 3 extra bytes to the front (6a2d2c), which is truncated later on, this should be fixed if possible before making any real chains as its consensus code. Need to try diffrent methods to decode the hex correctly.) + -earlytxid=810bd62fb8353fad20267ff2050684b8829affa3edf6b366633931530791dfce + restart the chain with earlytxid param before height 100 on all nodes (if not using -testnode=1) + ./komodod -ac_name=TESTHC -ac_supply=1000000 -ac_reward=100000000000 -ac_cc=2 -ac_script=2ea22c8020987fad30df055db6fd922c3a57e55d76601229ed3da3b31340112e773df3d0d28103120c008203000401ccb8 -ac_founders=150 -ac_blocktime=20 -ac_nk=96,5 -earlytxid=810bd62fb8353fad20267ff2050684b8829affa3edf6b366633931530791dfce + +once the payments plan has been funded with the mined coinbase you can issue payments release when conditions of the plan are met to fund founders reward/rewards plan. eg. + ./komodo-cli -ac_name=TESTHC paymentsrelease '["ee7765be874fb084c00538b1b0488e8ecb857de253f09a9ba6ea8d3579b77d33",500]' diff --git a/src/cc/payments.cpp b/src/cc/payments.cpp index 7d6fcba32..ba915e586 100644 --- a/src/cc/payments.cpp +++ b/src/cc/payments.cpp @@ -16,60 +16,6 @@ #include "CCPayments.h" /* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -ac_script + -earlytxid instructions with payments cc + rewards CC as an example. -How this works: - - earlytxid must be a transaction included in the chain before block 100. The chain MUST not have any other of these type of tx before block 100, or someone may be able to change it and mess things up. - - When it gets to block 100, it takes the txid specified by the -earlytxid param (does not affect magic) - - Looks up the transaction searches for the opreturn, then permenantly appends it to the end of ac_script in RAM. - - After every daemon restart, the first time the daemon mines a block, or receives a block that pays ac_script it will look up the op_return and save it again. - - this enables it to always reach consensus but doesnt need to constantly keep looking up the tx in the chain. - - The trick is to use ac_founders=101 or higher so that nothing is ever paid to the unspendable CC address. Although it should still work without this it burns coins. - --ac_script can be any Global CC address you can spend to with an OP_RETURN. Here we use example of paymentsCC being used to fund a rewards plan, and a set of founders address's. - you can get the ac_script from another chain, but the op_return payload must generated on the chain itself. this command gives you the needed info to get the scripPubKey Hex: - ./komodo-cli -ac_name=TEST paymentsfund '["5d536f54332db09f2be04593c54f764cf569e225f4d8df5155658c679e663682",1000]' - append: b8, to the end of ac_script, this changes magic value for -earlytxid chains vs normal ac_script and allows bypass of ac_supply paid to the scritpt as it would be unspendable and you would be unable to create the needed plans with no coins. - -ac_script=2ea22c8020987fad30df055db6fd922c3a57e55d76601229ed3da3b31340112e773df3d0d28103120c008203000401ccb8 - -start chain and make sure to do the following steps before block 100 (set generate false/true is a good idea between steps) -create rewards plan and fund it with all or a % of the premine. Must be some amount. eg. - ./komodo-cli -ac_name=TEST rewardscreatefunding test 1000 10 0 10 10 - -do rewards add funding and get the script pubkey and op_return from this tx (no need to send it) eg. - scriptPubKey: 2ea22c802065686d47a4049c2c845a71895a915eb84c04445896eec5dc0be40df0b31372da8103120c008203000401cc - OP_RETURN: 6a2ae541746573740000000061e7063fa8f99ef92a47e4aebf7ea28c59aeadaf3c1784312de64e4bcb3666f1 - -create txidopreturn for this payment: - ./komodo-cli -ac_name=TEST paymentstxidopret '[50,"2ea22c802065686d47a4049c2c845a71895a915eb84c04445896eec5dc0be40df0b31372da8103120c008203000401cc","6a2ae541746573740000000061e7063fa8f99ef92a47e4aebf7ea28c59aeadaf3c1784312de64e4bcb3666f1"]' - -create the txidopret for the founders reward(s) pubkeys: should be able to be a few here, not sure of max number yet. These can pay anything that does not need an opreturn. allocation and scriptpubkey hex. - ./komodo-cli -ac_name=TEST paymentstxidopret '[50,"76a9146bf5dd9f679c87a3f83ea176f82148d26653c04388ac"]' - -create payments plan: - ./komodo-cli -ac_name=TEST paymentscreate '[0,0,"273d193e5d09928e471926827dcac1f06c4801bdaa5524a84b17a00f4eaf8d38","81264daf7874b2041802ac681e49618413313cc2f29b47d47bd8e63dc2a06cad"]' -gives plan txid eg. 5d536f54332db09f2be04593c54f764cf569e225f4d8df5155658c679e663682 - -paymentsfund: - send some of the premine to this payments fund to get the rest of the scriptpubkey payload. (could skip send and just gen/decode the tx if required.) - send opret path this time to get the required script pubkey. For payments this mode is enabled by default rather than a traditional OP_RETURN, - for other CC we would need to modify daemon to get the correct info. - ./komodo-cli -ac_name=TEST paymentsfund '["5d536f54332db09f2be04593c54f764cf569e225f4d8df5155658c679e663682",1000,1]' - -get the payment fund script pubkey: (the split it at OP_CHECKCRYPTOCONDITION or 'cc' ) - 2ea22c8020987fad30df055db6fd922c3a57e55d76601229ed3da3b31340112e773df3d0d28103120c008203000401cc 2a0401f00101246a22f0466b75e35aa4d8ea6c3dd1b76141a0acbd06dfb4897288a62b8a8ec31b75a5b6cb75 - - put the second half into an OP_RETURN: (the remaining part of the the above scriptpubkey) eg. - ./komodo-cli -ac_name=TEST opreturn_burn 1 2a0401f00101246a22f0466b75e35aa4d8ea6c3dd1b76141a0acbd06dfb4897288a62b8a8ec31b75a5b6cb75 - opret_burn takes any burn amount and arbitrary hex string. (RPC works, but may have bugs, likely use this for LABS too with some fixes) - this gives a txid to locate it in the chain eg: - -earlytxid=1acd0b9b728feaea37a3f52d4106c35b0f8cfd19f9f3e64815d23ace0721d69d - restart the chain with earlytxid param before height 100 on BOTH NODES! - -once the payments plan has been funded with the mined coinbase you can issue payments release when conditions of the plan are met to fund founders reward/rewards plan. eg. - ./komodo-cli -ac_name=TEST paymentsrelease '["5d536f54332db09f2be04593c54f764cf569e225f4d8df5155658c679e663682",500]' ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- - 0) txidopret <- allocation, scriptPubKey, opret 1) create <- locked_blocks, minrelease, list of txidopret @@ -347,14 +293,14 @@ bool PaymentsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction & CScript opret; uint256 checktxid; int32_t opret_ind; if ( (opret_ind= has_opret(txin, EVAL_PAYMENTS)) == 0 ) { - // get op_return from CCvout - opret = getCCopret(txin.vout[0].scriptPubKey); + // get op_return from CCvout, + opret = getCCopret(txin.vout[vin.prevout.n].scriptPubKey); } else { // get op_return from the op_return opret = txin.vout[opret_ind].scriptPubKey; - } // else return(eval->Invalid("vin has wrong amount of vouts")); // dont think this is needed? + } if ( DecodePaymentsFundOpRet(opret,checktxid) != 'F' || checktxid != createtxid ) { fprintf(stderr, "vin.%i is not a payments CC vout: txid.%s\n", i, txin.GetHash().ToString().c_str()); @@ -381,7 +327,7 @@ bool PaymentsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction & int64_t AddPaymentsInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey txidpk,int64_t total,int32_t maxinputs,uint256 createtxid,int32_t latestheight) { - char coinaddr[64]; CPubKey Paymentspk; int64_t nValue,threshold,price,totalinputs = 0; uint256 txid,checktxid,hashBlock; std::vector origpubkey; CTransaction vintx,tx; int32_t iter,vout,ht,n = 0; + char coinaddr[64]; CPubKey Paymentspk; int64_t nValue,threshold,price,totalinputs = 0; uint256 txid,checktxid,hashBlock; std::vector origpubkey; CTransaction vintx; int32_t iter,vout,ht,n = 0; std::vector > unspentOutputs; if ( maxinputs > CC_MAXVINS ) maxinputs = CC_MAXVINS; @@ -400,7 +346,7 @@ int64_t AddPaymentsInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CP txid = it->first.txhash; vout = (int32_t)it->first.index; //fprintf(stderr,"iter.%d %s/v%d %s\n",iter,txid.GetHex().c_str(),vout,coinaddr); - if ( vout == 0 && GetTransaction(txid,vintx,hashBlock,false) != 0 ) + if ( (vout == 0 || vout == 1) && GetTransaction(txid,vintx,hashBlock,false) != 0 ) { if ( latestheight != 0 ) { @@ -421,14 +367,14 @@ int64_t AddPaymentsInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CP if ( (opret_ind= has_opret(vintx, EVAL_PAYMENTS)) == 0 ) { // get op_return from CCvout - opret = getCCopret(vintx.vout[0].scriptPubKey); + opret = getCCopret(vintx.vout[vout].scriptPubKey); } else { // get op_return from the op_return opret = vintx.vout[opret_ind].scriptPubKey; } - if ( myGetTransaction(txid,tx,hashBlock) == 0 || DecodePaymentsFundOpRet(opret,checktxid) != 'F' || checktxid != createtxid ) + if ( DecodePaymentsFundOpRet(opret,checktxid) != 'F' || checktxid != createtxid ) { fprintf(stderr,"bad opret %s vs %s\n",checktxid.GetHex().c_str(),createtxid.GetHex().c_str()); continue; @@ -690,16 +636,18 @@ UniValue PaymentsFund(struct CCcontract_info *cp,char *jsonstr) } else { - opret = EncodePaymentsFundOpRet(txid); + mtx.vout.push_back(MakeCC1vout(EVAL_PAYMENTS,amount,Paymentspk)); + // Use the below one along with other FinalizeCCTx/return, to get the ccvout scriptpubkey + /*opret = EncodePaymentsFundOpRet(txid); std::vector> vData = std::vector>(); if ( makeCCopret(opret, vData) ) - mtx.vout.push_back(MakeCC1vout(EVAL_PAYMENTS,amount,Paymentspk,&vData)); - //fprintf(stderr, "scriptpubkey.%s\n", mtx.vout.back().scriptPubKey.ToString().c_str()); - //fprintf(stderr, "hex.%s\n", HexStr(mtx.vout.back().scriptPubKey.begin(), mtx.vout.back().scriptPubKey.end()).c_str()); + mtx.vout.push_back(MakeCC1vout(EVAL_PAYMENTS,amount,Paymentspk,&vData)); */ } - rawtx = FinalizeCCTx(0,cp,mtx,mypk,PAYMENTS_TXFEE,CScript()); + rawtx = FinalizeCCTx(0,cp,mtx,mypk,PAYMENTS_TXFEE,EncodePaymentsFundOpRet(txid)); + //rawtx = FinalizeCCTx(0,cp,mtx,mypk,PAYMENTS_TXFEE,CScript()); // use this one to get ccvout scriptpubkey. if ( params != 0 ) free_json(params); + //return(payments_rawtxresult(result,rawtx,0)); // disable sending for CCvout, as we only need to decode the tx. return(payments_rawtxresult(result,rawtx,1)); } else diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 3dd590417..788f3795a 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -2047,7 +2047,8 @@ bool komodo_appendACscriptpub() { ASSETCHAINS_SCRIPTPUB.pop_back(); ASSETCHAINS_SCRIPTPUB.pop_back(); // remove last 2 chars. // get OP_RETURN from txid and append the HexStr of it to scriptpub - ASSETCHAINS_SCRIPTPUB.append(HexStr(tx.vout[i].scriptPubKey.begin()+3, tx.vout[i].scriptPubKey.end())); + // encoded opreturn incorrectly on TESTHC chain, once we no longer need this it can be changed to a straight +1 to drop OP_RETURN opcode. + ASSETCHAINS_SCRIPTPUB.append(HexStr(tx.vout[i].scriptPubKey.begin()+(strcmp("TESTHC",ASSETCHAINS_SYMBOL) == 0 ? 3 : 1), tx.vout[i].scriptPubKey.end())); //fprintf(stderr, "ac_script.%s\n",ASSETCHAINS_SCRIPTPUB.c_str()); didinit = true; return true; diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index de446390e..8152e22b8 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -8014,13 +8014,13 @@ UniValue test_heirmarker(const UniValue& params, bool fHelp) UniValue opreturn_burn(const UniValue& params, bool fHelp) { + if (fHelp || (params.size() != 2)) + throw runtime_error("amount to burn, hexstring to send\n"); struct CCcontract_info *cp, C; UniValue ret(UniValue::VOBJ); if (ensure_CCrequirements(EVAL_PAYMENTS) < 0) throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); cp = CCinit(&C, EVAL_PAYMENTS); - if (fHelp || (params.size() != 2)) - throw runtime_error("amount to burn, hexstring to send\n"); - + CAmount nAmount = AmountFromValue(params[0]); if (nAmount <= 10000) throw JSONRPCError(RPC_TYPE_ERROR, "must send at least 10000 sat"); @@ -8032,13 +8032,13 @@ UniValue opreturn_burn(const UniValue& params, bool fHelp) if (normalInputs < nAmount) throw runtime_error("not enough normals\n"); - CScript opret; uint8_t scripthex[8192]; - - decode_hex(scripthex,strHex.size()/2,(char *)strHex.c_str()); - std::string test; - test.append((char*)scripthex); - std::vector opretdata(test.begin(), test.end()); - opret << OP_RETURN << E_MARSHAL(ss << opretdata); + CScript opret; uint8_t *ptr; + opret << OP_RETURN; + int32_t len = strlen(strHex.c_str()); + len >>=1; + opret.resize(len+1); + ptr = (uint8_t *)&opret[1]; + decode_hex(ptr,len,(char *)strHex.c_str()); mtx.vout.push_back(CTxOut(nAmount,opret)); ret.push_back(Pair("hex",FinalizeCCTx(0, cp, mtx, myPubkey, 10000, CScript()))); return(ret); From 1a9ed2ac488b3788610176d0e3d1d1be72d626eb Mon Sep 17 00:00:00 2001 From: dimxy Date: Sun, 7 Apr 2019 22:42:54 +0500 Subject: [PATCH 006/447] univalue ptr test --- src/wallet/rpcwallet.cpp | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 6fe061727..3a4331b25 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5848,8 +5848,26 @@ UniValue assetsaddress(const UniValue& params, bool fHelp) return(CCaddress(cp, (char *)"Assets", pubkey)); } +void f(UniValue *p1, UniValue *p2) { + + if (p1) + p1->push_back(make_pair("x", "y")); + + // or... + if (p2) + (*p2).push_back(make_pair("a", "b")); + +} + UniValue tokenaddress(const UniValue& params, bool fHelp) { + UniValue v1, v2; + f(&v1, &v2); + + std::cerr << v1.getValues()[0].get_str() << std::endl; + std::cerr << v2.getValues()[0].get_str() << std::endl; + + struct CCcontract_info *cp,C; std::vector pubkey; cp = CCinit(&C,EVAL_TOKENS); if ( fHelp || params.size() > 1 ) @@ -8102,3 +8120,14 @@ UniValue test_proof(const UniValue& params, bool fHelp) return result; } + +void f(UniValue *p) { + + if (p) + p->push_back(make_pair("x", "y")); + + // or... + if (p) + (*p).push_back(make_pair("x", "y")); + +} \ No newline at end of file From b4b55290a2f85f41e4a7d714e79a5894d5ae1ae1 Mon Sep 17 00:00:00 2001 From: dimxy Date: Sun, 7 Apr 2019 23:02:28 +0500 Subject: [PATCH 007/447] corr univalue init --- src/wallet/rpcwallet.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 3a4331b25..64c32fa05 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5861,7 +5861,7 @@ void f(UniValue *p1, UniValue *p2) { UniValue tokenaddress(const UniValue& params, bool fHelp) { - UniValue v1, v2; + UniValue v1(UniValue::VARR), v2(UniValue::VARR); f(&v1, &v2); std::cerr << v1.getValues()[0].get_str() << std::endl; From 161b75b7f8ee0fbbc8ee6b02db95ad35a67a759d Mon Sep 17 00:00:00 2001 From: dimxy Date: Sun, 7 Apr 2019 23:10:46 +0500 Subject: [PATCH 008/447] more init corr --- src/wallet/rpcwallet.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 64c32fa05..1f0d1c5ca 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5861,7 +5861,7 @@ void f(UniValue *p1, UniValue *p2) { UniValue tokenaddress(const UniValue& params, bool fHelp) { - UniValue v1(UniValue::VARR), v2(UniValue::VARR); + UniValue v1(UniValue::VOBJ), v2(UniValue::VOBJ); f(&v1, &v2); std::cerr << v1.getValues()[0].get_str() << std::endl; From f0eeb7efe1cb812a0c11be05d7567cd0c2d5ef25 Mon Sep 17 00:00:00 2001 From: dimxy Date: Mon, 8 Apr 2019 00:23:42 +0500 Subject: [PATCH 009/447] added pricesbet rpc --- src/rpc/server.cpp | 1 + src/rpc/server.h | 1 + src/wallet/rpcwallet.cpp | 18 ------------------ 3 files changed, 2 insertions(+), 18 deletions(-) diff --git a/src/rpc/server.cpp b/src/rpc/server.cpp index 3ed082455..581676763 100644 --- a/src/rpc/server.cpp +++ b/src/rpc/server.cpp @@ -464,6 +464,7 @@ static const CRPCCommand vRPCCommands[] = { "prices", "pricesaddress", &pricesaddress, true }, { "prices", "priceslist", &priceslist, true }, { "prices", "pricesinfo", &pricesinfo, true }, + { "prices", "pricesbet", &pricesbet, true }, // Pegs { "pegs", "pegsaddress", &pegsaddress, true }, diff --git a/src/rpc/server.h b/src/rpc/server.h index 8e0054e6f..3df78de9f 100644 --- a/src/rpc/server.h +++ b/src/rpc/server.h @@ -497,6 +497,7 @@ extern UniValue paxdeposit(const UniValue& params, bool fHelp); extern UniValue paxwithdraw(const UniValue& params, bool fHelp); extern UniValue prices(const UniValue& params, bool fHelp); +extern UniValue pricesbet(const UniValue& params, bool fHelp); // test rpc: extern UniValue test_ac(const UniValue& params, bool fHelp); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 1f0d1c5ca..96e201bc3 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5848,26 +5848,8 @@ UniValue assetsaddress(const UniValue& params, bool fHelp) return(CCaddress(cp, (char *)"Assets", pubkey)); } -void f(UniValue *p1, UniValue *p2) { - - if (p1) - p1->push_back(make_pair("x", "y")); - - // or... - if (p2) - (*p2).push_back(make_pair("a", "b")); - -} - UniValue tokenaddress(const UniValue& params, bool fHelp) { - UniValue v1(UniValue::VOBJ), v2(UniValue::VOBJ); - f(&v1, &v2); - - std::cerr << v1.getValues()[0].get_str() << std::endl; - std::cerr << v2.getValues()[0].get_str() << std::endl; - - struct CCcontract_info *cp,C; std::vector pubkey; cp = CCinit(&C,EVAL_TOKENS); if ( fHelp || params.size() > 1 ) From ffb14229e55884e71d459efc4d706a6356c39697 Mon Sep 17 00:00:00 2001 From: dimxy Date: Mon, 8 Apr 2019 01:22:48 +0500 Subject: [PATCH 010/447] logging added --- src/cc/prices.cpp | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 407cd81fa..acf2fce4d 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -274,8 +274,10 @@ UniValue prices_rawtxresult(UniValue &result,std::string rawtx,int32_t broadcast int32_t prices_syntheticvec(std::vector &vec,std::vector synthetic) { int32_t i,need,ind,depth = 0; std::string opstr; uint16_t opcode,weight; - if ( synthetic.size() == 0 ) + if (synthetic.size() == 0) { + std::cerr << "synthetic expression is empty" << std::endl; return(-1); + } for (i=0; i &vec,std::vector { opcode = PRICES_WEIGHT | weight; need = 1; - } else return(-2); - if ( depth < need ) + } + else { + std::cerr << "incorrect opcode=" << opstr << std::endl; + return(-2); + } + if (depth < need) { + std::cerr << "incorrect not enough operands for opcode=" << opstr << std::endl; return(-3); + } depth -= need; if ( (opcode & KOMODO_PRICEMASK) != PRICES_WEIGHT ) // weight depth++; - if ( depth > 3 ) + if (depth > 3) { + std::cerr << "to many operands, last=" << opstr << std::endl; return(-4); + } vec.push_back(opcode); } if ( depth != 0 ) From 0b1ab063e096919f4f11b758795ac90e42c09037 Mon Sep 17 00:00:00 2001 From: dimxy Date: Mon, 8 Apr 2019 14:02:45 +0500 Subject: [PATCH 011/447] deb logging added --- src/komodo_gateway.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 0ff1c0b66..d12d2467f 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -2337,6 +2337,7 @@ int64_t komodo_pricemult(int32_t ind) return(0); } +// returns index name for ind value char *komodo_pricename(char *name,int32_t ind) { strcpy(name,"error"); @@ -2401,14 +2402,18 @@ char *komodo_pricename(char *name,int32_t ind) return(0); } +// finds index value for its char* name int32_t komodo_priceind(char *symbol) { char name[65]; int32_t i,n = (int32_t)(komodo_cbopretsize(ASSETCHAINS_CBOPRET) / sizeof(uint32_t)); for (i=1; i s uint32_t get_dailyfx(uint32_t *prices) { //{"base":"USD","rates":{"BGN":1.74344803,"NZD":1.471652701,"ILS":3.6329113924,"RUB":65.1997682296,"CAD":1.3430201462,"USD":1.0,"PHP":52.8641469068,"CHF":0.9970582992,"AUD":1.4129078267,"JPY":110.6792654662,"TRY":5.6523444464,"HKD":7.8499732573,"MYR":4.0824567659,"HRK":6.6232840078,"CZK":22.9862720628,"IDR":14267.4986628633,"DKK":6.6551078624,"NOK":8.6806917454,"HUF":285.131039401,"GBP":0.7626582278,"MXN":19.4183455161,"THB":31.8702085933,"ISK":122.5708682475,"ZAR":14.7033339276,"BRL":3.9750401141,"SGD":1.3573720806,"PLN":3.8286682118,"INR":69.33187734,"KRW":1139.1602781244,"RON":4.2423783206,"CNY":6.7387234801,"SEK":9.3385630237,"EUR":0.8914244963},"date":"2019-03-28"} + char url[512],*datestr; cJSON *json,*rates; int32_t i; uint32_t datenum=0,price = 0; + sprintf(url,"https://api.openrates.io/latest?base=USD"); if ( (json= get_urljson(url)) != 0 ) //if ( (json= send_curl(url,(char *)"dailyfx")) != 0 ) { + std::cerr << "Forex rates:" << std::endl; if ( (rates= jobj(json,(char *)"rates")) != 0 ) { for (i=0; i strvec) { int32_t i,errs=0; uint32_t price; char *symbol; + std::cerr << "Crypto rates:" << std::endl; + for (i=0; i Date: Mon, 8 Apr 2019 14:57:49 +0500 Subject: [PATCH 014/447] logging --- src/komodo_gateway.h | 1 - 1 file changed, 1 deletion(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 99759d043..9418f7333 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -2102,7 +2102,6 @@ uint32_t get_binanceprice(const char *symbol) if ( (json= get_urljson(url)) != 0 ) //if ( (json= send_curl(url,(char *)"bnbprice")) != 0 ) { price = jdouble(json,(char *)"price")*SATOSHIDEN + 0.0000000049; - std::cerr << price << std::endl; free_json(json); } usleep(100000); From 4cd2814aa83d235cf35882e31409ac521f86ed40 Mon Sep 17 00:00:00 2001 From: dimxy Date: Mon, 8 Apr 2019 15:59:48 +0500 Subject: [PATCH 015/447] logging --- src/cc/prices.cpp | 24 ++++++++++++++++++++---- src/komodo_gateway.h | 8 ++++---- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index acf2fce4d..a2a78c9ed 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -144,6 +144,16 @@ CBOPRET creates trustless oracles, which can be used for making a synthetic cash */ +// helpers: + +// returns true if there are only digits and no alphas in 's' +inline bool is_weight(std::string s) { + return + std::count_if(s.begin(), s.end(), [](unsigned char c) { return std::isdigit(c); } ) > 0 && + std::count_if(s.begin(), s.end(), [](unsigned char c) { return std::isalpha(c); } ) == 0; +} + + // start of consensus code CScript prices_betopret(CPubKey mypk,int32_t height,int64_t amount,int16_t leverage,int64_t firstprice,std::vector vec,uint256 tokenid) @@ -296,7 +306,7 @@ int32_t prices_syntheticvec(std::vector &vec,std::vector opcode = PRICES_MMM, need = 3; else if ( opstr == "///" ) opcode = PRICES_DDD, need = 3; - else if ( (ind= komodo_priceind((char *)opstr.c_str())) >= 0 ) + else if (!is_weight(opstr) && (ind= komodo_priceind(opstr.c_str())) >= 0 ) opcode = ind, need = 0; else if ( (weight= atoi(opstr.c_str())) > 0 && weight < KOMODO_MAXPRICES ) { @@ -429,12 +439,18 @@ int64_t prices_syntheticprice(std::vector vec,int32_t height,int32_t m if ( errcode != 0 ) break; } - if ( den == 0 ) + if (den == 0) { + std::cerr << "prices_syntheticprice den==0 return err=-11" << std::endl; return(-11); - else if ( depth != 0 ) + } + else if (depth != 0) { + std::cerr << "prices_syntheticprice depth!=0 err=-12" << std::endl; return(-12); - else if ( errcode != 0 ) + } + else if (errcode != 0) { + std::cerr << "prices_syntheticprice err=" << errcode << std::endl; return(errcode); + } return(price / den); } diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 9418f7333..204960693 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -2111,7 +2111,7 @@ uint32_t get_binanceprice(const char *symbol) int32_t get_cryptoprices(uint32_t *prices,const char *list[],int32_t n,std::vector strvec) { int32_t i,errs=0; uint32_t price; char *symbol; - std::cerr << "Crypto rates:" << std::endl; + std::cerr << "Crypto binance rates:" << std::endl; for (i=0; i &vec,std::vector opcode = PRICES_MMM, need = 3; else if ( opstr == "///" ) opcode = PRICES_DDD, need = 3; - else if (!is_weight(opstr) && (ind= komodo_priceind(opstr.c_str())) >= 0 ) + else if (!is_weight_str(opstr) && (ind= komodo_priceind(opstr.c_str())) >= 0 ) opcode = ind, need = 0; else if ( (weight= atoi(opstr.c_str())) > 0 && weight < KOMODO_MAXPRICES ) { @@ -314,30 +314,34 @@ int32_t prices_syntheticvec(std::vector &vec,std::vector need = 1; } else { - std::cerr << "incorrect opcode=" << opstr << std::endl; + std::cerr << "prices_syntheticvec() incorrect opcode=" << opstr << std::endl; return(-2); } if (depth < need) { - std::cerr << "incorrect not enough operands for opcode=" << opstr << std::endl; + std::cerr << "prices_syntheticvec() incorrect not enough operands for opcode=" << opstr << std::endl; return(-3); } depth -= need; - if ( (opcode & KOMODO_PRICEMASK) != PRICES_WEIGHT ) // weight - depth++; + std::cerr << "opcode=" << opcode << " opstr=" << opstr << " depth-=need=" << depth << std::endl; + if ((opcode & KOMODO_PRICEMASK) != PRICES_WEIGHT) { // skip weight + depth++; // increase operands count + std::cerr << "depth++=" << depth << std::endl; + } if (depth > 3) { - std::cerr << "to many operands, last=" << opstr << std::endl; + std::cerr << "prices_syntheticvec() to many operands, last=" << opstr << std::endl; return(-4); } vec.push_back(opcode); } if ( depth != 0 ) { - fprintf(stderr,"depth.%d not empty\n",depth); + fprintf(stderr,"prices_syntheticvec() depth.%d not empty\n",depth); return(-5); } return(0); } +// calculate price for synthetic expression int64_t prices_syntheticprice(std::vector vec,int32_t height,int32_t minmax,int16_t leverage) { int32_t i,ind,errcode,depth,retval = -1; uint16_t opcode; int64_t pricedata[PRICES_MAXDATAPOINTS],pricestack[4],price,den,a,b,c; @@ -345,7 +349,7 @@ int64_t prices_syntheticprice(std::vector vec,int32_t height,int32_t m for (i=0; i vec,int32_t height,int32_t m { if ( leverage > 0 ) pricestack[depth] = (pricedata[1] > pricedata[2]) ? pricedata[1] : pricedata[2]; // MAX - else pricestack[depth] = (pricedata[1] < pricedata[2]) ? pricedata[1] : pricedata[2]; // MIN + else + pricestack[depth] = (pricedata[1] < pricedata[2]) ? pricedata[1] : pricedata[2]; // MIN } } if ( pricestack[depth] == 0 ) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 204960693..c9e3d0470 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -2077,7 +2077,7 @@ uint32_t get_dailyfx(uint32_t *prices) sprintf(url,"https://api.openrates.io/latest?base=USD"); if ( (json= get_urljson(url)) != 0 ) //if ( (json= send_curl(url,(char *)"dailyfx")) != 0 ) { - std::cerr << "Forex rates:" << std::endl; + std::cerr << "Forex USD rates:" << std::endl; if ( (rates= jobj(json,(char *)"rates")) != 0 ) { for (i=0; i strvec) { int32_t i,errs=0; uint32_t price; char *symbol; - std::cerr << "Crypto binance rates:" << std::endl; + std::cerr << "Crypto binance BTC rates:" << std::endl; for (i=0; i Date: Mon, 8 Apr 2019 17:54:49 +0500 Subject: [PATCH 017/447] logging --- src/cc/prices.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index d1fc1aba9..bb77c8f30 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -322,7 +322,7 @@ int32_t prices_syntheticvec(std::vector &vec,std::vector return(-3); } depth -= need; - std::cerr << "opcode=" << opcode << " opstr=" << opstr << " depth-=need=" << depth << std::endl; + std::cerr << "opcode=" << opcode << " opstr=" << opstr << " need=" << need << " depth-=need=" << depth << std::endl; if ((opcode & KOMODO_PRICEMASK) != PRICES_WEIGHT) { // skip weight depth++; // increase operands count std::cerr << "depth++=" << depth << std::endl; From fce9b0581a813cfbff8c2f0bedef6fcc5817ba4a Mon Sep 17 00:00:00 2001 From: dimxy Date: Mon, 8 Apr 2019 18:24:36 +0500 Subject: [PATCH 018/447] logging --- src/cc/prices.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index bb77c8f30..6cdfb1e8a 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -352,7 +352,7 @@ int64_t prices_syntheticprice(std::vector vec,int32_t height,int32_t m ind = (opcode & (KOMODO_MAXPRICES-1)); // weight value switch ( opcode & KOMODO_PRICEMASK ) { - case 0: + case 0: // indices pricestack[depth] = 0; if ( komodo_priceget(pricedata,ind,height,1) > 0 ) { @@ -375,7 +375,7 @@ int64_t prices_syntheticprice(std::vector vec,int32_t height,int32_t m { depth--; price += pricestack[0] * ind; - den += ind; + den += ind; // acc weight values } else errcode = -2; break; case PRICES_MULT: @@ -444,6 +444,10 @@ int64_t prices_syntheticprice(std::vector vec,int32_t height,int32_t m if ( errcode != 0 ) break; } + + if (errcode != 0) + std::cerr << "prices_syntheticprice warning: errcode in switch=" << errcode << std::endl; + if (den == 0) { std::cerr << "prices_syntheticprice den==0 return err=-11" << std::endl; return(-11); From 9e4ef902f864660126371de3eb43c4938d4b0e35 Mon Sep 17 00:00:00 2001 From: dimxy Date: Mon, 8 Apr 2019 19:21:36 +0500 Subject: [PATCH 019/447] loggin --- src/cc/prices.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 6cdfb1e8a..e5922cfa7 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -349,7 +349,7 @@ int64_t prices_syntheticprice(std::vector vec,int32_t height,int32_t m for (i=0; i vec,int32_t height,int32_t m errcode = -1; depth++; break; + case PRICES_WEIGHT: // multiply by weight and consume top of stack by updating price if ( depth == 1 ) { @@ -378,6 +379,7 @@ int64_t prices_syntheticprice(std::vector vec,int32_t height,int32_t m den += ind; // acc weight values } else errcode = -2; break; + case PRICES_MULT: if ( depth >= 2 ) { @@ -386,6 +388,7 @@ int64_t prices_syntheticprice(std::vector vec,int32_t height,int32_t m pricestack[depth++] = (a * b) / SATOSHIDEN; } else errcode = -3; break; + case PRICES_DIV: if ( depth >= 2 ) { @@ -394,6 +397,7 @@ int64_t prices_syntheticprice(std::vector vec,int32_t height,int32_t m pricestack[depth++] = (a * SATOSHIDEN) / b; } else errcode = -4; break; + case PRICES_INV: if ( depth >= 1 ) { @@ -401,6 +405,7 @@ int64_t prices_syntheticprice(std::vector vec,int32_t height,int32_t m pricestack[depth++] = (SATOSHIDEN * SATOSHIDEN) / a; } else errcode = -5; break; + case PRICES_MDD: if ( depth >= 3 ) { @@ -410,6 +415,7 @@ int64_t prices_syntheticprice(std::vector vec,int32_t height,int32_t m pricestack[depth++] = (((a * SATOSHIDEN) / b) * SATOSHIDEN) / c; } else errcode = -6; break; + case PRICES_MMD: if ( depth >= 3 ) { @@ -419,6 +425,7 @@ int64_t prices_syntheticprice(std::vector vec,int32_t height,int32_t m pricestack[depth++] = (a * b) / c; } else errcode = -7; break; + case PRICES_MMM: if ( depth >= 3 ) { @@ -428,6 +435,7 @@ int64_t prices_syntheticprice(std::vector vec,int32_t height,int32_t m pricestack[depth++] = ((a * b) / SATOSHIDEN) * c; } else errcode = -8; break; + case PRICES_DDD: if ( depth >= 3 ) { @@ -437,6 +445,7 @@ int64_t prices_syntheticprice(std::vector vec,int32_t height,int32_t m pricestack[depth++] = (((((SATOSHIDEN * SATOSHIDEN) / a) * SATOSHIDEN) / b) * SATOSHIDEN) / c; } else errcode = -9; break; + default: errcode = -10; break; From 0c017ca582fc547fc4ef6beebe275c2dc0e67543 Mon Sep 17 00:00:00 2001 From: dimxy Date: Mon, 8 Apr 2019 23:38:37 +0500 Subject: [PATCH 020/447] loggin in correlation --- src/komodo_gateway.h | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index c9e3d0470..1ae6440d3 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -2471,7 +2471,7 @@ int64_t komodo_pricecorrelated(uint64_t seed,int32_t ind,uint32_t *rawprices,int if ( lowprice == refprice ) lowprice--; sum = 0; - //fprintf(stderr,"firsti.%d: ",i); + fprintf(stderr,"firsti.%d: ",i); for (j=0; j= PRICES_DAYWINDOW ) @@ -2483,14 +2483,14 @@ int64_t komodo_pricecorrelated(uint64_t seed,int32_t ind,uint32_t *rawprices,int } if ( price >= lowprice && price <= highprice ) { - //fprintf(stderr,"%.1f ",(double)price/10000); + fprintf(stderr,"%.1f ",(double)price/10000); sum += price; correlation++; if ( correlation > (PRICES_DAYWINDOW>>1) ) { if ( nonzprices == 0 ) return(refprice * mult); - //fprintf(stderr,"-> %.4f\n",(double)sum*mult/correlation); + fprintf(stderr,"-> %.4f\n",(double)sum*mult/correlation); //return(sum*mult/correlation); n = 0; i = (iter + seed) % PRICES_DAYWINDOW; @@ -2508,12 +2508,12 @@ int64_t komodo_pricecorrelated(uint64_t seed,int32_t ind,uint32_t *rawprices,int else { nonzprices[i] = price; - //fprintf(stderr,"(%d %u) ",i,rawprices[i*rawskip]); + fprintf(stderr,"(%d %u) ",i,rawprices[i*rawskip]); n++; } } } - //fprintf(stderr,"ind.%d iter.%d j.%d i.%d n.%d correlation.%d ref %llu -> %llu\n",ind,iter,j,i,n,correlation,(long long)refprice,(long long)sum/correlation); + fprintf(stderr,"ind.%d iter.%d j.%d i.%d n.%d correlation.%d ref %llu -> %llu\n",ind,iter,j,i,n,correlation,(long long)refprice,(long long)sum/correlation); if ( n != correlation ) return(-1); sum = den = n = 0; @@ -2521,7 +2521,7 @@ int64_t komodo_pricecorrelated(uint64_t seed,int32_t ind,uint32_t *rawprices,int if ( nonzprices[i] != 0 ) break; firstprice = nonzprices[i]; - //fprintf(stderr,"firsti.%d: ",i); + fprintf(stderr,"firsti.%d: ",i); for (i=0; i %.8f\n",(long long)firstprice,((double)(sum*mult) / den) / COIN); + std::cerr << "sum=" << sum << " mul=" << mul << " den=" << den << std::endl; + fprintf(stderr,"firstprice.%llu weighted -> %.8f\n",(long long)firstprice,((double)(sum*mult) / den) / COIN); return((sum * mult) / den); } } From e92c6c4c1bfc10a3971ea4ef39cfe57ed61708d6 Mon Sep 17 00:00:00 2001 From: dimxy Date: Mon, 8 Apr 2019 23:42:17 +0500 Subject: [PATCH 021/447] mult --- 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 1ae6440d3..a18723338 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -2536,7 +2536,7 @@ int64_t komodo_pricecorrelated(uint64_t seed,int32_t ind,uint32_t *rawprices,int fprintf(stderr,"seed.%llu n.%d vs correlation.%d sum %llu, den %llu\n",(long long)seed,n,correlation,(long long)sum,(long long)den); return(-1); } - std::cerr << "sum=" << sum << " mul=" << mul << " den=" << den << std::endl; + std::cerr << "sum=" << sum << " mult=" << mult << " den=" << den << std::endl; fprintf(stderr,"firstprice.%llu weighted -> %.8f\n",(long long)firstprice,((double)(sum*mult) / den) / COIN); return((sum * mult) / den); } From dc1257a85db65510ffa782e2744a773421bb73c2 Mon Sep 17 00:00:00 2001 From: dimxy Date: Tue, 9 Apr 2019 01:00:37 +0500 Subject: [PATCH 022/447] changed to SplitStr --- src/util.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/util.h b/src/util.h index dc421092a..9cdbabf70 100644 --- a/src/util.h +++ b/src/util.h @@ -287,6 +287,8 @@ template void TraceThread(const char* name, Callable func) } } +void SplitStr(const std::string& strVal, std::vector &outVals); + #define KOMODO_ASSETCHAIN_MAXLEN 65 From dee17205d2f9cffd63b5f633201473f49fb53d56 Mon Sep 17 00:00:00 2001 From: dimxy Date: Tue, 9 Apr 2019 12:40:44 +0500 Subject: [PATCH 023/447] SplitStr add support for comma and space delims --- src/util.cpp | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/src/util.cpp b/src/util.cpp index 980d82ac9..e1d37b4a9 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -394,27 +394,25 @@ void ParseParameters(int argc, const char* const argv[]) } } +// split string using by space or comma as delimiter char void SplitStr(const std::string& strVal, std::vector &outVals) { stringstream ss(strVal); - std::string str; - while ( ss.peek() == ' ' ) - ss.ignore(); - - while ( ss >> str ) - { - if ( str.size() == 0 ) - continue; - if ( str[str.size()-1] == ',' ) - str.resize(str.size()-1); - outVals.push_back(str); - while ( ss.peek() == ' ' ) - ss.ignore(); - if ( ss.peek() == ',' ) - ss.ignore(); - while ( ss.peek() == ' ' ) + while (true) { + int c; + std::string str; + + while (std::isspace(ss.peek())) ss.ignore(); + + while (!ss.eofbit && !std::isspace(c = ss.get() && c != ',')) + str += c; + + if (!str.empty()) + outVals.push_back(str); + else + break; } } From e85fbb10c9d39e7b8b96afd80227979d1c7c3f62 Mon Sep 17 00:00:00 2001 From: dimxy Date: Tue, 9 Apr 2019 12:48:41 +0500 Subject: [PATCH 024/447] corr SplitStr --- src/util.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/util.cpp b/src/util.cpp index e1d37b4a9..163e4aad3 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -406,7 +406,7 @@ void SplitStr(const std::string& strVal, std::vector &outVals) while (std::isspace(ss.peek())) ss.ignore(); - while (!ss.eofbit && !std::isspace(c = ss.get() && c != ',')) + while (!ss.eofbit && !std::isspace(c = ss.get()) && c != ',') str += c; if (!str.empty()) From 2f24cf602f4410ce67416bfa57075a8d279cfe61 Mon Sep 17 00:00:00 2001 From: dimxy Date: Tue, 9 Apr 2019 12:58:55 +0500 Subject: [PATCH 025/447] corr SplitStr --- src/util.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/util.cpp b/src/util.cpp index 163e4aad3..7d0b9cc3d 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -406,7 +406,7 @@ void SplitStr(const std::string& strVal, std::vector &outVals) while (std::isspace(ss.peek())) ss.ignore(); - while (!ss.eofbit && !std::isspace(c = ss.get()) && c != ',') + while (!ss.eof() && !std::isspace(c = ss.get()) && c != ',') str += c; if (!str.empty()) From 8231a83db8f3603d2155760829e9c4591706405e Mon Sep 17 00:00:00 2001 From: dimxy Date: Tue, 9 Apr 2019 13:28:02 +0500 Subject: [PATCH 026/447] corr eof state SplitStr --- src/util.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/util.cpp b/src/util.cpp index 7d0b9cc3d..fe28acf75 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -399,20 +399,18 @@ void SplitStr(const std::string& strVal, std::vector &outVals) { stringstream ss(strVal); - while (true) { + while (!ss.eof()) { int c; std::string str; while (std::isspace(ss.peek())) ss.ignore(); - while (!ss.eof() && !std::isspace(c = ss.get()) && c != ',') + while ((c = ss.get()) != EOF && !std::isspace(c = ss.get()) && c != ',') str += c; if (!str.empty()) outVals.push_back(str); - else - break; } } From 124983720d06ecdf194d7cffb2feea5097021af5 Mon Sep 17 00:00:00 2001 From: dimxy Date: Tue, 9 Apr 2019 13:33:28 +0500 Subject: [PATCH 027/447] corr SplitStr c --- src/util.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/util.cpp b/src/util.cpp index fe28acf75..70f638f93 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -406,7 +406,7 @@ void SplitStr(const std::string& strVal, std::vector &outVals) while (std::isspace(ss.peek())) ss.ignore(); - while ((c = ss.get()) != EOF && !std::isspace(c = ss.get()) && c != ',') + while ((c = ss.get()) != EOF && !std::isspace(c) && c != ',') str += c; if (!str.empty()) From 78a9a071067da35eae46bae077ab5dcd52fe25f9 Mon Sep 17 00:00:00 2001 From: dimxy Date: Tue, 9 Apr 2019 14:13:14 +0500 Subject: [PATCH 028/447] commented logging --- src/util.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/util.cpp b/src/util.cpp index 70f638f93..1aa079085 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -394,7 +394,7 @@ void ParseParameters(int argc, const char* const argv[]) } } -// split string using by space or comma as delimiter char +// split string using by space or comma as a delimiter char void SplitStr(const std::string& strVal, std::vector &outVals) { stringstream ss(strVal); From a3da9aa68ca4f49b7d2542123fdd5dbb2ae46d6b Mon Sep 17 00:00:00 2001 From: dimxy Date: Tue, 9 Apr 2019 14:19:17 +0500 Subject: [PATCH 029/447] more logging commented out --- src/komodo_gateway.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index a18723338..3f1d5ec5e 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -2483,7 +2483,7 @@ int64_t komodo_pricecorrelated(uint64_t seed,int32_t ind,uint32_t *rawprices,int } if ( price >= lowprice && price <= highprice ) { - fprintf(stderr,"%.1f ",(double)price/10000); + //fprintf(stderr,"%.1f ",(double)price/10000); sum += price; correlation++; if ( correlation > (PRICES_DAYWINDOW>>1) ) @@ -2521,7 +2521,7 @@ int64_t komodo_pricecorrelated(uint64_t seed,int32_t ind,uint32_t *rawprices,int if ( nonzprices[i] != 0 ) break; firstprice = nonzprices[i]; - fprintf(stderr,"firsti.%d: ",i); + //fprintf(stderr,"firsti.%d: ",i); for (i=0; i Date: Tue, 9 Apr 2019 14:37:31 +0500 Subject: [PATCH 030/447] more logging --- src/cc/prices.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index e5922cfa7..0a4ce90ae 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -469,6 +469,7 @@ int64_t prices_syntheticprice(std::vector vec,int32_t height,int32_t m std::cerr << "prices_syntheticprice err=" << errcode << std::endl; return(errcode); } + std::cerr << "prices_syntheticprice price=" << price << " den=" << den << std::endl; return(price / den); } From ca97519ccda161e30d8efcca3852da79eb1e4bde Mon Sep 17 00:00:00 2001 From: dimxy Date: Tue, 9 Apr 2019 18:35:53 +0500 Subject: [PATCH 031/447] loggin --- src/cc/prices.cpp | 54 ++++++++++++++++++++++++++++++++++------------- src/util.h | 1 + 2 files changed, 40 insertions(+), 15 deletions(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 0a4ce90ae..058bd314d 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -344,18 +344,25 @@ int32_t prices_syntheticvec(std::vector &vec,std::vector // calculate price for synthetic expression int64_t prices_syntheticprice(std::vector vec,int32_t height,int32_t minmax,int16_t leverage) { - int32_t i,ind,errcode,depth,retval = -1; uint16_t opcode; int64_t pricedata[PRICES_MAXDATAPOINTS],pricestack[4],price,den,a,b,c; + int32_t i,value,errcode,depth,retval = -1; + uint16_t opcode; + int64_t *pricedata,pricestack[4],price,den,a,b,c; + + pricedata = (int64_t *)calloc(sizeof(*pricedata)*3,1 + PRICES_DAYWINDOW*2 + PRICES_SMOOTHWIDTH); price = den = depth = errcode = 0; + for (i=0; i= amount+4*txfee ) + if ( AddNormalinputs(mtx,mypk,amount+5*txfee,64) >= amount+5*txfee ) { betamount = (amount * 199) / 200; + mtx.vout.push_back(CTxOut(txfee, CScript() << std::vector(pricespk.begin(), pricespk.end()))); // marker mtx.vout.push_back(MakeCC1vout(cp->evalcode,txfee,mypk)); // baton for total funding mtx.vout.push_back(MakeCC1vout(cp->evalcode,(amount-betamount)+2*txfee,pricespk)); mtx.vout.push_back(MakeCC1of2vout(cp->evalcode,betamount,pricespk,mypk)); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 96e201bc3..a5ff4fdc4 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -6931,7 +6931,7 @@ UniValue priceslist(const UniValue& params, bool fHelp) UniValue pricesinfo(const UniValue& params, bool fHelp) { uint256 bettxid; int32_t height; - if ( fHelp || params.size() != 2 ) + if ( fHelp || params.size() != 1 ) throw runtime_error("pricesinfo fundingtxid\n"); if ( ensure_CCrequirements(EVAL_PRICES) < 0 ) throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); From 7c4b7eb7d4c3f82c29fd54bbbe53b6a8b26173ae Mon Sep 17 00:00:00 2001 From: dimxy Date: Tue, 9 Apr 2019 21:13:48 +0500 Subject: [PATCH 037/447] corr marker --- src/cc/prices.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 0e7b06197..fe9d47a89 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -567,7 +567,7 @@ UniValue PricesBet(uint64_t txfee,int64_t amount,int16_t leverage,std::vector= amount+5*txfee ) { betamount = (amount * 199) / 200; - mtx.vout.push_back(CTxOut(txfee, CScript() << std::vector(pricespk.begin(), pricespk.end()))); // marker + mtx.vout.push_back(CTxOut(txfee, CScript() << ParseHex(HexStr(pricespk)))); // marker mtx.vout.push_back(MakeCC1vout(cp->evalcode,txfee,mypk)); // baton for total funding mtx.vout.push_back(MakeCC1vout(cp->evalcode,(amount-betamount)+2*txfee,pricespk)); mtx.vout.push_back(MakeCC1of2vout(cp->evalcode,betamount,pricespk,mypk)); From e6474a62af89e7a4a02c11b8e8e44f100832c5b6 Mon Sep 17 00:00:00 2001 From: dimxy Date: Tue, 9 Apr 2019 21:26:07 +0500 Subject: [PATCH 038/447] corr marker --- src/cc/prices.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index fe9d47a89..3d4603c7a 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -567,7 +567,7 @@ UniValue PricesBet(uint64_t txfee,int64_t amount,int16_t leverage,std::vector= amount+5*txfee ) { betamount = (amount * 199) / 200; - mtx.vout.push_back(CTxOut(txfee, CScript() << ParseHex(HexStr(pricespk)))); // marker + mtx.vout.push_back(CTxOut(txfee, CScript() << ParseHex(HexStr(pricespk)) << OP_CHECKSIG)); // marker mtx.vout.push_back(MakeCC1vout(cp->evalcode,txfee,mypk)); // baton for total funding mtx.vout.push_back(MakeCC1vout(cp->evalcode,(amount-betamount)+2*txfee,pricespk)); mtx.vout.push_back(MakeCC1of2vout(cp->evalcode,betamount,pricespk,mypk)); From 0aba8374f1e7096ac672bb0e0d50ae185e40bc94 Mon Sep 17 00:00:00 2001 From: dimxy Date: Tue, 9 Apr 2019 21:40:23 +0500 Subject: [PATCH 039/447] rpc height added --- src/wallet/rpcwallet.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index a5ff4fdc4..05283c0b9 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -6931,8 +6931,8 @@ UniValue priceslist(const UniValue& params, bool fHelp) UniValue pricesinfo(const UniValue& params, bool fHelp) { uint256 bettxid; int32_t height; - if ( fHelp || params.size() != 1 ) - throw runtime_error("pricesinfo fundingtxid\n"); + if ( fHelp || params.size() != 2 ) + throw runtime_error("pricesinfo fundingtxid height\n"); if ( ensure_CCrequirements(EVAL_PRICES) < 0 ) throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); bettxid = Parseuint256((char *)params[0].get_str().c_str()); From 2e576d596749e1473c2fdb1546578d12c0a8530c Mon Sep 17 00:00:00 2001 From: dimxy Date: Tue, 9 Apr 2019 22:28:45 +0500 Subject: [PATCH 040/447] costbasis == 0 --- src/cc/prices.cpp | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 3d4603c7a..a8542df6b 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -509,7 +509,7 @@ int64_t prices_syntheticprofits(int64_t &costbasis,int32_t firstheight,int32_t h else if ( leverage < 0 && (costbasis == 0 || price < costbasis) ) costbasis = price; } - profits = ((price * SATOSHIDEN) / costbasis) - SATOSHIDEN; + profits = costbasis > 0 ? ((price * SATOSHIDEN) / costbasis) - SATOSHIDEN : 0; profits *= leverage * positionsize; return(positionsize + addedbets + profits); } @@ -747,18 +747,29 @@ UniValue PricesCashout(uint64_t txfee,uint256 bettxid) UniValue PricesInfo(uint256 bettxid,int32_t refheight) { - UniValue result(UniValue::VOBJ); CTransaction bettx; uint256 hashBlock,batontxid,tokenid; int64_t myfee,ignore,positionsize=0,addedbets=0,firstprice=0,profits=0,costbasis=0; int32_t i,firstheight=0,height,numvouts; int16_t leverage=0; std::vector vec; CPubKey pk,mypk,pricespk; std::string rawtx; - if ( myGetTransaction(bettxid,bettx,hashBlock) != 0 && (numvouts= bettx.vout.size()) > 3 ) + UniValue result(UniValue::VOBJ); + CTransaction bettx; + uint256 hashBlock,batontxid,tokenid; + int64_t myfee,ignore=0,positionsize=0,addedbets=0,firstprice=0,profits=0,costbasis=0; + int32_t i,firstheight=0,height,numvouts; + int16_t leverage=0; + std::vector vec; + CPubKey pk,mypk,pricespk; + std::string rawtx; + + if( myGetTransaction(bettxid,bettx,hashBlock) != 0 && (numvouts= bettx.vout.size()) > 3 ) { - if ( prices_betopretdecode(bettx.vout[numvouts-1].scriptPubKey,pk,firstheight,positionsize,leverage,firstprice,vec,tokenid) == 'B' ) + if( prices_betopretdecode(bettx.vout[numvouts-1].scriptPubKey,pk,firstheight,positionsize,leverage,firstprice,vec,tokenid) == 'B' ) { costbasis = prices_costbasis(bettx); addedbets = prices_batontxid(batontxid,bettx,bettxid); - if ( (profits= prices_syntheticprofits(ignore,firstheight,refheight,leverage,vec,positionsize,addedbets)) < 0 ) + if ((profits= prices_syntheticprofits(ignore,firstheight,refheight,leverage,vec,positionsize,addedbets)) < 0) { result.push_back(Pair("rekt",1)); result.push_back(Pair("rektfee",(positionsize + addedbets) / 500)); - } else result.push_back(Pair("rekt",0)); + } + else + result.push_back(Pair("rekt",0)); result.push_back(Pair("batontxid",batontxid.GetHex())); prices_betjson(result,profits,costbasis,positionsize,addedbets,leverage,firstheight,firstprice); result.push_back(Pair("height",(int64_t)refheight)); From cf059070245b7d621ef5d5889b939a0dcdf4d226 Mon Sep 17 00:00:00 2001 From: dimxy Date: Thu, 11 Apr 2019 19:09:46 +0500 Subject: [PATCH 041/447] pricessetcostbasis added --- src/cc/CCPrices.h | 2 +- src/cc/prices.cpp | 57 +++++++++++++++++++++++++++------------------- src/rpc/server.cpp | 1 + src/rpc/server.h | 1 + 4 files changed, 37 insertions(+), 24 deletions(-) diff --git a/src/cc/CCPrices.h b/src/cc/CCPrices.h index f88a5fe55..a32264a88 100644 --- a/src/cc/CCPrices.h +++ b/src/cc/CCPrices.h @@ -40,7 +40,7 @@ bool PricesValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx // CCcustom UniValue PricesBet(uint64_t txfee,int64_t amount,int16_t leverage,std::vector synthetic); UniValue PricesAddFunding(uint64_t txfee,uint256 bettxid,int64_t amount); -UniValue PricesSetcostbasis(uint64_t txfee,uint256 bettxid); +UniValue PricesSetcostbasis(int64_t txfee,uint256 bettxid); UniValue PricesRekt(uint64_t txfee,uint256 bettxid,int32_t rektheight); UniValue PricesCashout(uint64_t txfee,uint256 bettxid); UniValue PricesInfo(uint256 bettxid,int32_t refheight); diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index a8542df6b..525a42cda 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -362,12 +362,13 @@ int64_t prices_syntheticprice(std::vector vec,int32_t height,int32_t m pricestack[depth] = 0; if ( prices_extract(pricedata,height,1,value) == 0 ) { - // push to the prices stack + // push price to the prices stack if ( minmax == 0 ) - pricestack[depth] = pricedata[2]; + pricestack[depth] = pricedata[2]; // use smoothed value if we are over 24h else { - if ( leverage > 0 ) + // if we are within 24h use min or max price + if ( leverage > 0 ) pricestack[depth] = (pricedata[1] > pricedata[2]) ? pricedata[1] : pricedata[2]; // MAX else pricestack[depth] = (pricedata[1] < pricedata[2]) ? pricedata[1] : pricedata[2]; // MIN @@ -495,20 +496,29 @@ int64_t prices_syntheticprice(std::vector vec,int32_t height,int32_t m int64_t prices_syntheticprofits(int64_t &costbasis,int32_t firstheight,int32_t height,int16_t leverage,std::vector vec,int64_t positionsize,int64_t addedbets) { - int64_t price,profits = 0; int32_t minmax; - minmax = (height > firstheight+PRICES_DAYWINDOW); - if ( (price= prices_syntheticprice(vec,height,minmax,leverage)) < 0 ) - { - fprintf(stderr,"unexpected zero synthetic price at height.%d\n",height); - return(0); - } - if ( minmax != 0 ) - { - if ( leverage > 0 && price > costbasis ) - costbasis = price; - else if ( leverage < 0 && (costbasis == 0 || price < costbasis) ) - costbasis = price; + int64_t price, profits = 0; + + if (firstheight >= 0) { // >=0 means request to find costbase + int32_t minmax = (height < firstheight + PRICES_DAYWINDOW); // use minmax value if we are within 24h + + if ((price = prices_syntheticprice(vec, height, minmax, leverage)) < 0) + { + fprintf(stderr, "unexpected zero synthetic price at height.%d\n", height); + return(0); + } + if (minmax /*!= 0*/) // if we are within day window, use bigger or lesser value + { + if (leverage > 0 && price > costbasis) + costbasis = price; // set costbasis + else if (leverage < 0 && (costbasis == 0 || price < costbasis)) + costbasis = price; + // else -> use the previous value + } + else + costbasis = price; //?? } + // else < 0 then use the passed costbase + profits = costbasis > 0 ? ((price * SATOSHIDEN) / costbasis) - SATOSHIDEN : 0; profits *= leverage * positionsize; return(positionsize + addedbets + profits); @@ -567,10 +577,10 @@ UniValue PricesBet(uint64_t txfee,int64_t amount,int16_t leverage,std::vector= amount+5*txfee ) { betamount = (amount * 199) / 200; - mtx.vout.push_back(CTxOut(txfee, CScript() << ParseHex(HexStr(pricespk)) << OP_CHECKSIG)); // marker mtx.vout.push_back(MakeCC1vout(cp->evalcode,txfee,mypk)); // baton for total funding mtx.vout.push_back(MakeCC1vout(cp->evalcode,(amount-betamount)+2*txfee,pricespk)); mtx.vout.push_back(MakeCC1of2vout(cp->evalcode,betamount,pricespk,mypk)); + mtx.vout.push_back(CTxOut(txfee, CScript() << ParseHex(HexStr(pricespk)) << OP_CHECKSIG)); // marker rawtx = FinalizeCCTx(0,cp,mtx,mypk,txfee,prices_betopret(mypk,nextheight-1,amount,leverage,firstprice,vec,zeroid)); return(prices_rawtxresult(result,rawtx,0)); } @@ -612,7 +622,7 @@ UniValue PricesAddFunding(uint64_t txfee,uint256 bettxid,int64_t amount) return(result); } -UniValue PricesSetcostbasis(uint64_t txfee,uint256 bettxid) +UniValue PricesSetcostbasis(int64_t txfee,uint256 bettxid) { int32_t nextheight = komodo_nextheight(); CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(),nextheight); UniValue result(UniValue::VOBJ); @@ -626,12 +636,12 @@ UniValue PricesSetcostbasis(uint64_t txfee,uint256 bettxid) { if ( prices_betopretdecode(bettx.vout[numvouts-1].scriptPubKey,pk,firstheight,positionsize,leverage,firstprice,vec,tokenid) == 'B' ) { - addedbets = prices_batontxid(batontxid,bettx,bettxid); + addedbets = prices_batontxid(batontxid, bettx, bettxid); mtx.vin.push_back(CTxIn(bettxid,1,CScript())); - for (i=0; ievalcode,bettx.vout[1].nValue-myfee-txfee,pricespk)); @@ -669,7 +680,7 @@ UniValue PricesRekt(uint64_t txfee,uint256 bettxid,int32_t rektheight) { costbasis = prices_costbasis(bettx); addedbets = prices_batontxid(batontxid,bettx,bettxid); - if ( (profits= prices_syntheticprofits(ignore,firstheight,rektheight,leverage,vec,positionsize,addedbets)) < 0 ) + if ( (profits= prices_syntheticprofits(costbasis /*ignore*/, -1, rektheight, leverage, vec, positionsize, addedbets)) < 0 ) { myfee = (positionsize + addedbets) / 500; } diff --git a/src/rpc/server.cpp b/src/rpc/server.cpp index 581676763..d132dabd5 100644 --- a/src/rpc/server.cpp +++ b/src/rpc/server.cpp @@ -465,6 +465,7 @@ static const CRPCCommand vRPCCommands[] = { "prices", "priceslist", &priceslist, true }, { "prices", "pricesinfo", &pricesinfo, true }, { "prices", "pricesbet", &pricesbet, true }, + { "prices", "pricesbet", &pricessetcostbasis, true }, // Pegs { "pegs", "pegsaddress", &pegsaddress, true }, diff --git a/src/rpc/server.h b/src/rpc/server.h index 3df78de9f..94d16ecdc 100644 --- a/src/rpc/server.h +++ b/src/rpc/server.h @@ -498,6 +498,7 @@ extern UniValue paxwithdraw(const UniValue& params, bool fHelp); extern UniValue prices(const UniValue& params, bool fHelp); extern UniValue pricesbet(const UniValue& params, bool fHelp); +extern UniValue pricessetcostbasis(const UniValue& params, bool fHelp); // test rpc: extern UniValue test_ac(const UniValue& params, bool fHelp); From 3cc12f4a023c8fb62c004a11be60b371bc9674aa Mon Sep 17 00:00:00 2001 From: dimxy Date: Thu, 11 Apr 2019 19:11:18 +0500 Subject: [PATCH 042/447] pricessetcostbasis + --- src/rpc/server.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rpc/server.cpp b/src/rpc/server.cpp index d132dabd5..c2cead4a4 100644 --- a/src/rpc/server.cpp +++ b/src/rpc/server.cpp @@ -465,7 +465,7 @@ static const CRPCCommand vRPCCommands[] = { "prices", "priceslist", &priceslist, true }, { "prices", "pricesinfo", &pricesinfo, true }, { "prices", "pricesbet", &pricesbet, true }, - { "prices", "pricesbet", &pricessetcostbasis, true }, + { "prices", "pricesbetsetcostbasis", &pricessetcostbasis, true }, // Pegs { "pegs", "pegsaddress", &pegsaddress, true }, From f0c14e77d5f5c20775f9ff8bb155cdca31dc7a69 Mon Sep 17 00:00:00 2001 From: dimxy Date: Sat, 13 Apr 2019 20:45:42 +0500 Subject: [PATCH 043/447] rpc rekt cashout logging, formatting --- src/cc/prices.cpp | 420 ++++++++++++++++++++------------------------- src/rpc/server.cpp | 4 +- src/rpc/server.h | 3 + 3 files changed, 195 insertions(+), 232 deletions(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 525a42cda..ec099e7e1 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -22,127 +22,25 @@ CBOPRET creates trustless oracles, which can be used for making a synthetic cash 0.5% fee based on betamount, NOT leveraged betamount!! 0.1% collected by price basis determinant 0.2% collected by rekt tx - - At the simplest, prices CC allows to make leveraged cash settled bets on long and short BTCUSD: - BTCUSD, 1 with positive leverage parameter up to 777 - BTCUSD, 1 with negative leverage parameter up to -777 - These specific limits of 0.5%, 0.1%, 0.2%, 777 should be able to be changed based on #define + PricesBet -> +/-leverage, amount, synthetic -> opreturn includes current price + funds are locked into 1of2 global CC address + for first day, long basis is MAX(correlated,smoothed), short is MIN() + reference price is the smoothed of the previous block + if synthetic value + amount goes negative, then anybody can rekt it to collect a rektfee, proof of rekt must be included to show cost basis, rekt price + original creator can liquidate at anytime and collect (synthetic value + amount) from globalfund + 0.5% of bet -> globalfund + + PricesStatus -> bettxid maxsamples returns initial params, cost basis, amount left, rekt:true/false, rektheight, initial synthetic price, current synthetic price, net gain - Another configuration is to send the 0.4% (or 0.2%) fees to a fee collection address (this is not currently implemented, but would be needed for systems that dont use -ac_perc to collect a global override) + PricesRekt -> bettxid height -> 0.1% to miner, rest to global CC - The definition of the synthetic instrument that is being tracked is actually defined with a forth type of syntax and is quite flexible to allow unlimited combinations and weights, but that is an independent aspect and will be covered later. + PricesClose -> bettxid returns (synthetic value + amount) - Let us discuss the simplest synthetic case of a long or short of BTCUSD (or any other direct pricepoint from the trustless oracle). If you look at the charts, you will see the blue line that is direct from the miners (and therefore cant be directly used). The orange line is the 51% correlated price that is deterministically random selected from the prior 24 hours. And finally the green line which is simply the average value from the priot 24 hours. - - We will assume that the orange and green prices are able to be deterministically calculated from the raw coinbase data (blue). The prices rpc is currently working reasonably well and appears to return deterministic prices, however for use in the prices CC, it is often needed to find just a single data point. To that effect there is the temporary function prices_syntheticprice, which uses a bruteforce and totally inefficient way to calculate the correlated and smoothed prices. This inefficient process will need to be changed to a permanent storage of correlated and smoothed prices for each trustless oracle that is updated each block. This will then allow to directly lookup each value for any of the trustless prices. Such speed will indeed be needed to scale up usage of a REKT chain. - - Since the mined prices can be manipulated by any miner, combined with the +/-1% tolerance, it would be possible for an external miner to obtain a large hashrate and skew the price +1%, then to -1% to create a 2% price difference, which under high leverage might be able to generate a large profit. - - To avoid this precisely controllable biasing, the 51% correlation of past day is used (orange), which makes the price jump around a lot. The green line that sums the prior day is needed to remove this jitter back to the average value. However, this creates a 1.5 day delay to the price movement of the smoothed price compared to the current price. What this means is that if we want to use the green line to settle prices automatically, a trivial way to make money is to bet in the direct that the mined prices are relative to the smoothed prices. Given 1.5 day head start, it wont be any mystery which direction the smoothed line will move in the next 24 hours. - - So this makes the smoothed price unusable for settling the bets with. However, we cant use the correlated price either, as it would also allow to make bets when the correlated price picked a significantly lower/higher price than the raw price. The solution is to have a floating basis for the costbasis of the bet. In order to allow finding the right costbasis, for long bets the maximum price between the correlated and smoothed price is needed over the first day after the bet. For short bets, the minimum price is needed. - - What this means is that the actual starting price for a bet wont be known for sure when the bet is made, but if the price is relatively stable, there wont be much of a change. If there is a lot of recent volatility, then the starting price will have a high variability. In order to calculate the costbasis, it currently requires many calculations to find the MAX (or MIN) for the first day. Even when this is made to be a lookup, it still requires to issue a transaction to change the state of a bet from a "starting" state to a "in effect" state and this state change is indicated by whether the bettx vout that contains the costbasis utxo is spent or not. - - Once a bet goes into effect, then block by block, it is checked by the decentralized set of rekt scanners if it is rekt or not, in this case for double the reward for calculating the cost basis. This fully decentralized mechanism ensures that some node will decide to collect the free money and ensures that the bankroll is growing. To miss a rekt bet and not close it out when it can be is to allow it to survive for another block, which can change it profitability from negative to positive. - - Which comes to how profits are calculated. Once the costbasis is locked, then the profit calculation can be made based on the ratio between the costbasis and the current price, multiplied by the leverage. So, if a long position gains 10% at a 10x leverage, then approximately the entire bet amount will be made, ie. a double. Similarily with a short position, a 10% drop in price at 10x leverage will double the bet amount. Since it takes a full day to establish the costbasis, it is not possible to allow changing the costbasis for an existing bet, however it is possible to add funds so that it is less likely to be rekt. The sum of the initial bet and all added funds must be greater than the loss at every block to prevent a position from being rekt. To make it simple to calculate the amount of funds added, another bettx vout is used as a baton. Techniques similar to rogue CC to find where the bettx vout was spent and looking at each such transaction to find the total funds added can be used. - - The once that makes the bet is able to add funds or cashout at any block, as long as it isnt rekt. If it is rekt, the bettor is able to collect the rekt fee, so at least that is some consolation, but it is advised to increase the total funding to avoid being rekt. On a cashout all the funds that were bet adjusted by the profits can be collected. - - Hopefully the above description makes it clear what the following rpc calls should be doing: - - UniValue PricesBet(uint64_t txfee,int64_t amount,int16_t leverage,std::vector synthetic) - funds are locked into 1of2 global CC address - for first day, long basis is MAX(correlated,smoothed), short is MIN() - reference price is the smoothed of the previous block - if synthetic value + amount goes negative, then anybody can rekt it to collect a rektfee, proof of rekt must be included to show cost basis, rekt price - original creator can liquidate at anytime and collect (synthetic value + amount) from globalfund - 0.5% of bet -> globalfund - - UniValue PricesAddFunding(uint64_t txfee,uint256 bettxid,int64_t amount) - add funding to an existing bet, doesnt change the profit calcs but does make the bet less likely to be rekt - - UniValue PricesSetcostbasis(uint64_t txfee,uint256 bettxid) - in the first day from the bet, the costbasis can (and usually does) change based on the MAX(correlated,smoothed) for long and MIN() for shorts - to calculate this requires a bit of work, so whatever node is first to get the proper calculation confirmed, gets a 0.1% costbasis fee - - UniValue PricesRekt(uint64_t txfee,uint256 bettxid,int32_t rektheight) - similarily, any node can submit a rekt tx and cash in on 0.2% fee if their claim is confirmed - - UniValue PricesCashout(uint64_t txfee,uint256 bettxid) - only the actually creator of bet is able to cashout and only if it isnt rekt at that moment - - UniValue PricesInfo(uint256 bettxid,int32_t refheight) - all relevant info about a bet - - UniValue PricesList() - a list of all pending and completed bets in different lists + PricesList -> all bettxid -> list [bettxid, netgain] - Appendix Synthetic position definition language: - - Let us start from the familiar BTCUSD nomenclature. this is similar (identical) to forex EURUSD and the equivalent. Notice the price needs two things as it is actually a ratio, ie. BTCUSD is how many USD does 1 BTC get converted to. It can be thought of as the value of BTC/USD, in other words a ratio. - - The value of BTC alone, or USD alone, it is actually quite an abstract issue and it can only be approximated. Specific ways of how to do this can be discussed later, for now it is only important to understand that all prices are actually ratios. - - And these ratios work as normal algebra does. So a/b * b/c == a/c! You can try this out with BTCUSD and USDJPY -> BTC/USD * USD/JPY -> BTC/JPY or the BTCJPY price - - division is the reciprocal, so BTCUSD reciprocated is USDBTC - - Without getting into all the possible combinations of things, let us first understand what the language allows. It uses a stack based language, where individual tokens update the state. The final state needs to have an empty stack and it will have a calculated price. - - The most important is pushing a specific price onto the stack. All the correlated and smoothed prices are normalized so it has each integer unit equal to 0.00000001, amounts above 100 million are above one, amounts less are below one. 100 million is the unit constant. - - In the prices CC synthetic definition language, the symbol that is returned pushes the adjusted price to the stack. The adjustment is selecting between the correlated and smoothed if within a day from the bet creation, or just the smoothed if after a day. You can have a maximum depth of 3, any more than that and it should return an error. - - This means there are operations that are possible on 1, 2 and 3 symbols. For 1 symbol, it is easy, the only direct operation is the inverse, which is represented by "!". All items in the language are separated by "," - - "BTCUSD, !" - - The above is the inverse or USD/BTC, which is another way to short BTCUSD. It is also possible to short the entire synthetic with a negative leverage. The exact results of a -1 leverage and inverse, might not be exact due to the math involved with calculating the profit, but it should generally be similar. - - For two symbols, there is a bit more we can do, namely multiply and divide, combined with inverting, however to simplify the language any inverting is required to be done by the ordering of the symbols and usage of multiply or divide. multiply is "*" and divide is "/" the top of the stack (last to be pushed) is the divisor, the one right before the divisor is the numerator. - - "BTCUSD, USDJPY, *" <- That will create a BTCJPY synthetic - - "BTCEUR, BTCUSD, /" <- That will create a USDEUR synthetic - - If you experiment around with this, you will see that given two symbols and the proper order and * or /, you can always create the synthetic that you want, assuming what you want is the cancelling out of the term in common with the two symbols and the resulting ratio is between the two unique terms. - */ - -// Now we get to the three symbol operations, which there are 4 of *//, **/, *** and /// - -/* - these four operators work on the top of the stack in left to right order as the syntax of the definition lists it, though it is even possible to have the value from an earlier computation on the top of the stack. Ultimately all three will be multiplied together, so a * in a spot means it us used without changing. A / means its inverse will be used. - - "KMDBTC, BTCUSD, USDJPY, ***" <- this would create a KMDJPY synthetic. The various location of the / to make an inverse is to orient the raw symbol into the right orientation as the pricefeed is only getting one orientation of the ratio. - - So now we have covered all ways to map 1, 2 and 3 values on the top of the stack. A value can be on the top of the stack directly from a symbol, or as the result of some 1, 2 or 3 symbol operation. With a maximum stack depth of 3, it might require some experimentation to get a very complex synthetic to compile. Alternately, a stack deeper than 3 might be the acceptable solution if there are a family of synthetics that need it. - - At this point, it is time to describe the weights. It turns out that all above examples are incomplete and the synthetic descriptions are all insufficient and should generate an error. The reason is that the actual synthetic price is the value of the accumulator, which adds up all the weighted prices. In order to assign a weight to a price value on the stack, you simply use a number that is less than 2048. - - What such a weight number does, is consume the top of the stack, which also must be at depth of 1 and adds it to the accumulator. This allows combining multiple different synthetics into a meta synthetic, like for an aggregated index that is weighted by marketcap, or whatever other type of ratio trade that is desired. - - "BTCUSD, 1000, ETHBTC, BTCUSD, *, 300" -> that creates a dual index of BTCUSD and ETHUSD with a 30% ETH weight - - all weight operations consumes the one and only stack element and adds its weight to the accumulator, using this a very large number of terms can be all added together. Using inverses, allows to get the short direction into the equation mixed with longs, but all terms must be positive. If you want to create a spread between two synthetics, you need to create two different synthetics and go long with one and short with another. - - "BTCUSD, 1" with leverage -2 and "KMDBTC, BTCUSD, *, 1" with leverage 1 this will setup a +KMDUSD -2 BTCUSD spread when the two are combined, and would be at breakeven when KMDUSD gains 2x more percentage wise than BTC does. anytime KMD gains more, will be positive, if the gains are less, would be negative. - - Believe it or not, the string to binary compiler for synthetic description and interpretation of it is less than 200 lines of code. - - todo: complete all the above, bet tokens, cross chain prices within cluster These specific limits of 0.5%, 0.1%, 0.2%, 777 should be able to be changed based on #define - - Another configuration is to send the 0.4% (or 0.2%) fees to a fee collection scriptPubKey (this is not currently implemented, but would be needed for systems that dont use -ac_perc to collect a global override) this requires adding new vouts - - Modification: in the event there is one price in the accumulator and one price on the stack at the end, then it is a (A - B) spread - - Monetizations should be sent to: RGsWqwFviaNJSbmgWi6338NL2tKkY7ZqKL - - */ - +*/ // helpers: @@ -240,7 +138,7 @@ int64_t AddPricesInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,char { int64_t nValue,price,totalinputs = 0; uint256 txid,hashBlock; std::vector origpubkey; CTransaction vintx; int32_t vout,n = 0; std::vector > unspentOutputs; - SetCCunspents(unspentOutputs,destaddr,true); + SetCCunspents(unspentOutputs,destaddr); for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) { txid = it->first.txhash; @@ -494,19 +392,19 @@ int64_t prices_syntheticprice(std::vector vec,int32_t height,int32_t m return(price / den); } -int64_t prices_syntheticprofits(int64_t &costbasis,int32_t firstheight,int32_t height,int16_t leverage,std::vector vec,int64_t positionsize,int64_t addedbets) +int64_t prices_syntheticprofits(bool isCalcCostBasis, int64_t &costbasis,int32_t firstheight,int32_t height,int16_t leverage,std::vector vec,int64_t positionsize,int64_t addedbets) { int64_t price, profits = 0; - if (firstheight >= 0) { // >=0 means request to find costbase - int32_t minmax = (height < firstheight + PRICES_DAYWINDOW); // use minmax value if we are within 24h + int32_t minmax = (height < firstheight + PRICES_DAYWINDOW); // if we are within 24h then use min or max value - if ((price = prices_syntheticprice(vec, height, minmax, leverage)) < 0) - { - fprintf(stderr, "unexpected zero synthetic price at height.%d\n", height); - return(0); - } - if (minmax /*!= 0*/) // if we are within day window, use bigger or lesser value + if ((price = prices_syntheticprice(vec, height, minmax, leverage)) < 0) + { + fprintf(stderr, "unexpected zero synthetic price at height.%d\n", height); + return(0); + } + if (isCalcCostBasis) { + if (minmax) // if we are within day window, set costbasis to max or min value { if (leverage > 0 && price > costbasis) costbasis = price; // set costbasis @@ -514,10 +412,7 @@ int64_t prices_syntheticprofits(int64_t &costbasis,int32_t firstheight,int32_t h costbasis = price; // else -> use the previous value } - else - costbasis = price; //?? } - // else < 0 then use the passed costbase profits = costbasis > 0 ? ((price * SATOSHIDEN) / costbasis) - SATOSHIDEN : 0; profits *= leverage * positionsize; @@ -540,8 +435,29 @@ int64_t prices_costbasis(CTransaction bettx) int64_t costbasis = 0; // if vout1 is spent, follow and extract costbasis from opreturn //uint8_t prices_costbasisopretdecode(CScript scriptPubKey,uint256 &bettxid,CPubKey &pk,int32_t &height,int64_t &costbasis) + uint256 txidCostbasis; + int32_t vini; + int32_t height; + if (CCgetspenttxid(txidCostbasis, vini, height, bettx.GetHash(), 1) < 0) { + std::cerr << "prices_costbasis() no costbasis txid found" << std::endl; + return 0; + } - return(costbasis); + CTransaction txCostbasis; + uint256 hashBlock; + uint256 bettxid; + CPubKey pk; + bool isLoaded = false; + uint8_t funcId = 0; + + if ((isLoaded = myGetTransaction(txidCostbasis, txCostbasis, hashBlock)) && + txCostbasis.vout.size() > 0 && + (funcId = prices_costbasisopretdecode(txCostbasis.vout.back().scriptPubKey, bettxid, pk, height, costbasis)) != 0) { + return costbasis; + } + + std::cerr << "prices_costbasis() cannot load costbasis tx or decode opret" << " isLoaded=" << isLoaded << " funcId=" << funcId << std::endl; + return 0; } int64_t prices_batontxid(uint256 &batontxid,CTransaction bettx,uint256 bettxid) @@ -622,190 +538,232 @@ UniValue PricesAddFunding(uint64_t txfee,uint256 bettxid,int64_t amount) return(result); } -UniValue PricesSetcostbasis(int64_t txfee,uint256 bettxid) +UniValue PricesSetcostbasis(int64_t txfee, uint256 bettxid) { int32_t nextheight = komodo_nextheight(); - CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(),nextheight); UniValue result(UniValue::VOBJ); - struct CCcontract_info *cp,C; CTransaction bettx; uint256 hashBlock,batontxid,tokenid; int64_t myfee,positionsize=0,addedbets,firstprice=0,profits=0,costbasis=0; int32_t i,firstheight=0,height,numvouts; int16_t leverage=0; std::vector vec; CPubKey pk,mypk,pricespk; std::string rawtx; - cp = CCinit(&C,EVAL_PRICES); - if ( txfee == 0 ) + CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), nextheight); + UniValue result(UniValue::VOBJ); + struct CCcontract_info *cp, C; CTransaction bettx; uint256 hashBlock, batontxid, tokenid; + int64_t myfee, positionsize = 0, addedbets, firstprice = 0, profits = 0, costbasis = 0; + int32_t i, firstheight = 0, height, numvouts; int16_t leverage = 0; + std::vector vec; + CPubKey pk, mypk, pricespk; std::string rawtx; + + cp = CCinit(&C, EVAL_PRICES); + if (txfee == 0) txfee = PRICES_TXFEE; + mypk = pubkey2pk(Mypubkey()); - pricespk = GetUnspendable(cp,0); - if ( myGetTransaction(bettxid,bettx,hashBlock) != 0 && (numvouts= bettx.vout.size()) > 3 ) + pricespk = GetUnspendable(cp, 0); + if (myGetTransaction(bettxid, bettx, hashBlock) != 0 && (numvouts = bettx.vout.size()) > 3) { - if ( prices_betopretdecode(bettx.vout[numvouts-1].scriptPubKey,pk,firstheight,positionsize,leverage,firstprice,vec,tokenid) == 'B' ) + if (prices_betopretdecode(bettx.vout[numvouts - 1].scriptPubKey, pk, firstheight, positionsize, leverage, firstprice, vec, tokenid) == 'B') { + if (nextheight < firstheight + PRICES_DAYWINDOW) { + result.push_back(Pair("result", "error")); + result.push_back(Pair("error", "cannot calculate costbasis yet")); + return(result); + } + addedbets = prices_batontxid(batontxid, bettx, bettxid); - mtx.vin.push_back(CTxIn(bettxid,1,CScript())); - for (i=0; ievalcode,bettx.vout[1].nValue-myfee-txfee,pricespk)); - rawtx = FinalizeCCTx(0,cp,mtx,mypk,txfee,prices_costbasisopret(bettxid,mypk,firstheight+PRICES_DAYWINDOW-1,costbasis)); - return(prices_rawtxresult(result,rawtx,0)); + result.push_back(Pair("myfee", myfee)); + mtx.vout.push_back(CTxOut(myfee, CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); + mtx.vout.push_back(MakeCC1vout(cp->evalcode, bettx.vout[1].nValue - myfee - txfee, pricespk)); + rawtx = FinalizeCCTx(0, cp, mtx, mypk, txfee, prices_costbasisopret(bettxid, mypk, firstheight + PRICES_DAYWINDOW - 1, costbasis)); + return(prices_rawtxresult(result, rawtx, 0)); } } - result.push_back(Pair("result","error")); - result.push_back(Pair("error","cant find bettxid")); + result.push_back(Pair("result", "error")); + result.push_back(Pair("error", "cant find bettxid")); return(result); } -UniValue PricesRekt(uint64_t txfee,uint256 bettxid,int32_t rektheight) +UniValue PricesRekt(uint64_t txfee, uint256 bettxid, int32_t rektheight) { int32_t nextheight = komodo_nextheight(); - CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(),nextheight); UniValue result(UniValue::VOBJ); - struct CCcontract_info *cp,C; CTransaction bettx; uint256 hashBlock,tokenid,batontxid; int64_t myfee=0,positionsize,addedbets,firstprice,profits,ignore,costbasis=0; int32_t firstheight,numvouts; int16_t leverage; std::vector vec; CPubKey pk,mypk,pricespk; std::string rawtx; - cp = CCinit(&C,EVAL_PRICES); - if ( txfee == 0 ) + CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), nextheight); UniValue result(UniValue::VOBJ); + struct CCcontract_info *cp, C; CTransaction bettx; uint256 hashBlock, tokenid, batontxid; int64_t myfee = 0, positionsize, addedbets, firstprice, profits, ignore, costbasis = 0; int32_t firstheight, numvouts; int16_t leverage; std::vector vec; CPubKey pk, mypk, pricespk; std::string rawtx; + cp = CCinit(&C, EVAL_PRICES); + if (txfee == 0) txfee = PRICES_TXFEE; mypk = pubkey2pk(Mypubkey()); - pricespk = GetUnspendable(cp,0); - if ( myGetTransaction(bettxid,bettx,hashBlock) != 0 && (numvouts= bettx.vout.size()) > 3 ) + pricespk = GetUnspendable(cp, 0); + if (myGetTransaction(bettxid, bettx, hashBlock) != 0 && (numvouts = bettx.vout.size()) > 3) { - if ( prices_betopretdecode(bettx.vout[numvouts-1].scriptPubKey,pk,firstheight,positionsize,leverage,firstprice,vec,tokenid) == 'B' ) + if (prices_betopretdecode(bettx.vout[numvouts - 1].scriptPubKey, pk, firstheight, positionsize, leverage, firstprice, vec, tokenid) == 'B') { costbasis = prices_costbasis(bettx); - addedbets = prices_batontxid(batontxid,bettx,bettxid); - if ( (profits= prices_syntheticprofits(costbasis /*ignore*/, -1, rektheight, leverage, vec, positionsize, addedbets)) < 0 ) + if (costbasis == 0) { + result.push_back(Pair("result", "error")); + result.push_back(Pair("error", "costbasis not defined yet")); + return(result); + } + + addedbets = prices_batontxid(batontxid, bettx, bettxid); + if ((profits = prices_syntheticprofits(false, costbasis /*ignore*/, firstheight, rektheight, leverage, vec, positionsize, addedbets)) < 0) { myfee = (positionsize + addedbets) / 500; } - prices_betjson(result,profits,costbasis,positionsize,addedbets,leverage,firstheight,firstprice); - if ( myfee != 0 ) + prices_betjson(result, profits, costbasis, positionsize, addedbets, leverage, firstheight, firstprice); + if (myfee != 0) { - mtx.vin.push_back(CTxIn(bettxid,2,CScript())); - mtx.vout.push_back(CTxOut(myfee,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); - mtx.vout.push_back(MakeCC1vout(cp->evalcode,bettx.vout[2].nValue-myfee-txfee,pricespk)); - rawtx = FinalizeCCTx(0,cp,mtx,mypk,txfee,prices_finalopret(bettxid,profits,rektheight,mypk,firstprice,costbasis,addedbets,positionsize,leverage)); - return(prices_rawtxresult(result,rawtx,0)); + mtx.vin.push_back(CTxIn(bettxid, 2, CScript())); + mtx.vout.push_back(CTxOut(myfee, CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); + mtx.vout.push_back(MakeCC1vout(cp->evalcode, bettx.vout[2].nValue - myfee - txfee, pricespk)); + rawtx = FinalizeCCTx(0, cp, mtx, mypk, txfee, prices_finalopret(bettxid, profits, rektheight, mypk, firstprice, costbasis, addedbets, positionsize, leverage)); + return(prices_rawtxresult(result, rawtx, 0)); } else { - result.push_back(Pair("result","error")); - result.push_back(Pair("error","position not rekt")); + result.push_back(Pair("result", "error")); + result.push_back(Pair("error", "position not rekt")); return(result); } } else { - result.push_back(Pair("result","error")); - result.push_back(Pair("error","cant decode opret")); + result.push_back(Pair("result", "error")); + result.push_back(Pair("error", "cant decode opret")); return(result); } } - result.push_back(Pair("result","error")); - result.push_back(Pair("error","cant find bettxid")); + result.push_back(Pair("result", "error")); + result.push_back(Pair("error", "cant find bettxid")); return(result); } -UniValue PricesCashout(uint64_t txfee,uint256 bettxid) +UniValue PricesCashout(uint64_t txfee, uint256 bettxid) { int32_t nextheight = komodo_nextheight(); - CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(),nextheight); UniValue result(UniValue::VOBJ); - struct CCcontract_info *cp,C; char destaddr[64]; CTransaction bettx; uint256 hashBlock,batontxid,tokenid; int64_t CCchange=0,positionsize,inputsum,ignore,addedbets,firstprice,profits,costbasis=0; int32_t i,firstheight,height,numvouts; int16_t leverage; std::vector vec; CPubKey pk,mypk,pricespk; std::string rawtx; - cp = CCinit(&C,EVAL_PRICES); - if ( txfee == 0 ) + CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), nextheight); UniValue result(UniValue::VOBJ); + struct CCcontract_info *cp, C; char destaddr[64]; + CTransaction bettx; + uint256 hashBlock, batontxid, tokenid; + int64_t CCchange = 0, positionsize, inputsum, ignore, addedbets, firstprice, profits, costbasis = 0; + int32_t i, firstheight, height, numvouts; + int16_t leverage; + std::vector vec; + CPubKey pk, mypk, pricespk; + std::string rawtx; + + cp = CCinit(&C, EVAL_PRICES); + if (txfee == 0) txfee = PRICES_TXFEE; + mypk = pubkey2pk(Mypubkey()); - pricespk = GetUnspendable(cp,0); - GetCCaddress(cp,destaddr,pricespk); - if ( myGetTransaction(bettxid,bettx,hashBlock) != 0 && (numvouts= bettx.vout.size()) > 3 ) + pricespk = GetUnspendable(cp, 0); + GetCCaddress(cp, destaddr, pricespk); + if (myGetTransaction(bettxid, bettx, hashBlock) != 0 && (numvouts = bettx.vout.size()) > 3) { - if ( prices_betopretdecode(bettx.vout[numvouts-1].scriptPubKey,pk,firstheight,positionsize,leverage,firstprice,vec,tokenid) == 'B' ) + if (prices_betopretdecode(bettx.vout[numvouts - 1].scriptPubKey, pk, firstheight, positionsize, leverage, firstprice, vec, tokenid) == 'B') { costbasis = prices_costbasis(bettx); - addedbets = prices_batontxid(batontxid,bettx,bettxid); - if ( (profits= prices_syntheticprofits(ignore,firstheight,nextheight-1,leverage,vec,positionsize,addedbets)) < 0 ) - { - prices_betjson(result,profits,costbasis,positionsize,addedbets,leverage,firstheight,firstprice); - result.push_back(Pair("result","error")); - result.push_back(Pair("error","position rekt")); + if (costbasis == 0) { + result.push_back(Pair("result", "error")); + result.push_back(Pair("error", "costbasis not defined yet")); return(result); } - prices_betjson(result,profits,costbasis,positionsize,addedbets,leverage,firstheight,firstprice); - mtx.vin.push_back(CTxIn(bettxid,2,CScript())); - if ( (inputsum= AddPricesInputs(cp,mtx,destaddr,profits+txfee,64,bettxid,2)) > profits+txfee ) + + addedbets = prices_batontxid(batontxid, bettx, bettxid); + if ((profits = prices_syntheticprofits(false, costbasis, firstheight, nextheight - 1, leverage, vec, positionsize, addedbets)) < 0) + { + prices_betjson(result, profits, costbasis, positionsize, addedbets, leverage, firstheight, firstprice); + result.push_back(Pair("result", "error")); + result.push_back(Pair("error", "position rekt")); + return(result); + } + prices_betjson(result, profits, costbasis, positionsize, addedbets, leverage, firstheight, firstprice); + mtx.vin.push_back(CTxIn(bettxid, 2, CScript())); + if ((inputsum = AddPricesInputs(cp, mtx, destaddr, profits + txfee, 64, bettxid, 2)) > profits + txfee) CCchange = (inputsum - profits); - mtx.vout.push_back(CTxOut(bettx.vout[2].nValue + profits,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); - if ( CCchange >= txfee ) - mtx.vout.push_back(MakeCC1vout(cp->evalcode,CCchange,pricespk)); - rawtx = FinalizeCCTx(0,cp,mtx,mypk,txfee,prices_finalopret(bettxid,profits,nextheight-1,mypk,firstprice,costbasis,addedbets,positionsize,leverage)); - return(prices_rawtxresult(result,rawtx,0)); + mtx.vout.push_back(CTxOut(bettx.vout[2].nValue + profits, CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); + if (CCchange >= txfee) + mtx.vout.push_back(MakeCC1vout(cp->evalcode, CCchange, pricespk)); + rawtx = FinalizeCCTx(0, cp, mtx, mypk, txfee, prices_finalopret(bettxid, profits, nextheight - 1, mypk, firstprice, costbasis, addedbets, positionsize, leverage)); + return(prices_rawtxresult(result, rawtx, 0)); } else { - result.push_back(Pair("result","error")); - result.push_back(Pair("error","cant decode opret")); + result.push_back(Pair("result", "error")); + result.push_back(Pair("error", "cant decode opret")); return(result); } } return(result); } -UniValue PricesInfo(uint256 bettxid,int32_t refheight) +UniValue PricesInfo(uint256 bettxid, int32_t refheight) { - UniValue result(UniValue::VOBJ); - CTransaction bettx; - uint256 hashBlock,batontxid,tokenid; - int64_t myfee,ignore=0,positionsize=0,addedbets=0,firstprice=0,profits=0,costbasis=0; - int32_t i,firstheight=0,height,numvouts; - int16_t leverage=0; - std::vector vec; - CPubKey pk,mypk,pricespk; + UniValue result(UniValue::VOBJ); + CTransaction bettx; + uint256 hashBlock, batontxid, tokenid; + int64_t myfee, ignore = 0, positionsize = 0, addedbets = 0, firstprice = 0, profits = 0, costbasis = 0; + int32_t i, firstheight = 0, height, numvouts; + int16_t leverage = 0; + std::vector vec; + CPubKey pk, mypk, pricespk; std::string rawtx; - if( myGetTransaction(bettxid,bettx,hashBlock) != 0 && (numvouts= bettx.vout.size()) > 3 ) + if (myGetTransaction(bettxid, bettx, hashBlock) != 0 && (numvouts = bettx.vout.size()) > 3) { - if( prices_betopretdecode(bettx.vout[numvouts-1].scriptPubKey,pk,firstheight,positionsize,leverage,firstprice,vec,tokenid) == 'B' ) + if (prices_betopretdecode(bettx.vout[numvouts - 1].scriptPubKey, pk, firstheight, positionsize, leverage, firstprice, vec, tokenid) == 'B') { costbasis = prices_costbasis(bettx); - addedbets = prices_batontxid(batontxid,bettx,bettxid); - if ((profits= prices_syntheticprofits(ignore,firstheight,refheight,leverage,vec,positionsize,addedbets)) < 0) + addedbets = prices_batontxid(batontxid, bettx, bettxid); + if ((profits = prices_syntheticprofits(false, costbasis, firstheight, refheight, leverage, vec, positionsize, addedbets)) < 0) { - result.push_back(Pair("rekt",1)); - result.push_back(Pair("rektfee",(positionsize + addedbets) / 500)); - } - else - result.push_back(Pair("rekt",0)); - result.push_back(Pair("batontxid",batontxid.GetHex())); - prices_betjson(result,profits,costbasis,positionsize,addedbets,leverage,firstheight,firstprice); - result.push_back(Pair("height",(int64_t)refheight)); + result.push_back(Pair("rekt", 1)); + result.push_back(Pair("rektfee", (positionsize + addedbets) / 500)); + } + else + result.push_back(Pair("rekt", 0)); + result.push_back(Pair("batontxid", batontxid.GetHex())); + prices_betjson(result, profits, costbasis, positionsize, addedbets, leverage, firstheight, firstprice); + result.push_back(Pair("height", (int64_t)refheight)); return(result); } } - result.push_back(Pair("result","error")); - result.push_back(Pair("error","cant find bettxid")); + result.push_back(Pair("result", "error")); + result.push_back(Pair("error", "cant find bettxid")); return(result); } UniValue PricesList() { - UniValue result(UniValue::VARR); std::vector > addressIndex; struct CCcontract_info *cp,C; int64_t amount,firstprice; int32_t height; int16_t leverage; uint256 txid,hashBlock,tokenid; CPubKey pk,pricespk; std::vector vec; CTransaction vintx; char str[65]; - cp = CCinit(&C,EVAL_PRICES); - pricespk = GetUnspendable(cp,0); - SetCCtxids(addressIndex,cp->normaladdr,false); - for (std::vector >::const_iterator it=addressIndex.begin(); it!=addressIndex.end(); it++) + UniValue result(UniValue::VARR); std::vector > addressIndex; + struct CCcontract_info *cp, C; + int64_t amount, firstprice; int32_t height; int16_t leverage; uint256 txid, hashBlock, tokenid; + CPubKey pk, pricespk; + std::vector vec; + CTransaction vintx; + char str[65]; + + cp = CCinit(&C, EVAL_PRICES); + pricespk = GetUnspendable(cp, 0); + SetCCtxids(addressIndex, cp->normaladdr); + for (std::vector >::const_iterator it = addressIndex.begin(); it != addressIndex.end(); it++) { txid = it->first.txhash; - if ( GetTransaction(txid,vintx,hashBlock,false) != 0 ) + if (GetTransaction(txid, vintx, hashBlock, false) != 0) { - if ( vintx.vout.size() > 0 && prices_betopretdecode(vintx.vout[vintx.vout.size()-1].scriptPubKey,pk,height,amount,leverage,firstprice,vec,tokenid) == 'B' ) + if (vintx.vout.size() > 0 && prices_betopretdecode(vintx.vout[vintx.vout.size() - 1].scriptPubKey, pk, height, amount, leverage, firstprice, vec, tokenid) == 'B') { - result.push_back(uint256_str(str,txid)); + result.push_back(uint256_str(str, txid)); } } } diff --git a/src/rpc/server.cpp b/src/rpc/server.cpp index c2cead4a4..3cc23a4fd 100644 --- a/src/rpc/server.cpp +++ b/src/rpc/server.cpp @@ -465,7 +465,9 @@ static const CRPCCommand vRPCCommands[] = { "prices", "priceslist", &priceslist, true }, { "prices", "pricesinfo", &pricesinfo, true }, { "prices", "pricesbet", &pricesbet, true }, - { "prices", "pricesbetsetcostbasis", &pricessetcostbasis, true }, + { "prices", "pricessetcostbasis", &pricessetcostbasis, true }, + { "prices", "pricescashout", &pricescashout, true }, + { "prices", "pricesrekt", &pricesrekt, true }, // Pegs { "pegs", "pegsaddress", &pegsaddress, true }, diff --git a/src/rpc/server.h b/src/rpc/server.h index 94d16ecdc..aef17d931 100644 --- a/src/rpc/server.h +++ b/src/rpc/server.h @@ -499,6 +499,9 @@ extern UniValue paxwithdraw(const UniValue& params, bool fHelp); extern UniValue prices(const UniValue& params, bool fHelp); extern UniValue pricesbet(const UniValue& params, bool fHelp); extern UniValue pricessetcostbasis(const UniValue& params, bool fHelp); +extern UniValue pricescashout(const UniValue& params, bool fHelp); +extern UniValue pricesrekt(const UniValue& params, bool fHelp); + // test rpc: extern UniValue test_ac(const UniValue& params, bool fHelp); From 829fb4d0cd33f5fdc052f2bc53fdcbe9c0b2953b Mon Sep 17 00:00:00 2001 From: dimxy Date: Mon, 15 Apr 2019 20:57:05 +0500 Subject: [PATCH 044/447] added 'add bet funds' added comments --- src/cc/prices.cpp | 89 ++++++++++++++++++++++++++++++++--------------- 1 file changed, 60 insertions(+), 29 deletions(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index ec099e7e1..fe3ae9c3a 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -239,7 +239,7 @@ int32_t prices_syntheticvec(std::vector &vec,std::vector return(0); } -// calculate price for synthetic expression +// calculates price for synthetic expression int64_t prices_syntheticprice(std::vector vec,int32_t height,int32_t minmax,int16_t leverage) { int32_t i,value,errcode,depth,retval = -1; @@ -261,7 +261,7 @@ int64_t prices_syntheticprice(std::vector vec,int32_t height,int32_t m if ( prices_extract(pricedata,height,1,value) == 0 ) { // push price to the prices stack - if ( minmax == 0 ) + if ( !minmax ) pricestack[depth] = pricedata[2]; // use smoothed value if we are over 24h else { @@ -392,7 +392,8 @@ int64_t prices_syntheticprice(std::vector vec,int32_t height,int32_t m return(price / den); } -int64_t prices_syntheticprofits(bool isCalcCostBasis, int64_t &costbasis,int32_t firstheight,int32_t height,int16_t leverage,std::vector vec,int64_t positionsize,int64_t addedbets) +// calculates profit/loss for the bet +int64_t prices_syntheticprofits(bool calcCostbasis, int64_t &costbasis, int32_t firstheight, int32_t height, int16_t leverage, std::vector vec, int64_t positionsize, int64_t addedbets) { int64_t price, profits = 0; @@ -403,15 +404,17 @@ int64_t prices_syntheticprofits(bool isCalcCostBasis, int64_t &costbasis,int32_t fprintf(stderr, "unexpected zero synthetic price at height.%d\n", height); return(0); } - if (isCalcCostBasis) { - if (minmax) // if we are within day window, set costbasis to max or min value - { + if (calcCostbasis) { + if (minmax) { // if we are within day window, set costbasis to max or min price value if (leverage > 0 && price > costbasis) costbasis = price; // set costbasis else if (leverage < 0 && (costbasis == 0 || price < costbasis)) costbasis = price; // else -> use the previous value } + else { + costbasis = price; // smoothed value + } } profits = costbasis > 0 ? ((price * SATOSHIDEN) / costbasis) - SATOSHIDEN : 0; @@ -456,14 +459,41 @@ int64_t prices_costbasis(CTransaction bettx) return costbasis; } - std::cerr << "prices_costbasis() cannot load costbasis tx or decode opret" << " isLoaded=" << isLoaded << " funcId=" << funcId << std::endl; + std::cerr << "prices_costbasis() cannot load costbasis tx or decode opret" << " isLoaded=" << isLoaded << " funcId=" << (int)funcId << std::endl; return 0; } +// calculates added bet total, returns the last baton txid int64_t prices_batontxid(uint256 &batontxid,CTransaction bettx,uint256 bettxid) { int64_t addedbets = 0; + int32_t vini; + int32_t height; + int32_t retcode; + // iterate through batons, adding up vout1 -> addedbets + while ((retcode = CCgetspenttxid(batontxid, vini, height, bettxid, 1)) == 0) { + + CTransaction txBaton; + uint256 hashBlock; + uint256 bettxid; + CPubKey pk; + bool isLoaded = false; + uint8_t funcId = 0; + int64_t amount; + + if ((isLoaded = myGetTransaction(batontxid, txBaton, hashBlock)) && + txBaton.vout.size() > 0 && + (funcId = prices_addopretdecode(txBaton.vout.back().scriptPubKey, bettxid, pk, amount)) != 0) { + addedbets += amount; + std::cerr << "prices_batontxid() added amount=" << amount << std::endl; + } + else { + std::cerr << "prices_batontxid() cannot load or decode add bet tx, isLoaded=" << isLoaded << " funcId=" << (int)funcId << std::endl; + } + } + + return(addedbets); } @@ -493,7 +523,7 @@ UniValue PricesBet(uint64_t txfee,int64_t amount,int16_t leverage,std::vector= amount+5*txfee ) { betamount = (amount * 199) / 200; - mtx.vout.push_back(MakeCC1vout(cp->evalcode,txfee,mypk)); // baton for total funding + mtx.vout.push_back(MakeCC1vout(cp->evalcode,txfee,mypk)); // vout0 baton for total funding mtx.vout.push_back(MakeCC1vout(cp->evalcode,(amount-betamount)+2*txfee,pricespk)); mtx.vout.push_back(MakeCC1of2vout(cp->evalcode,betamount,pricespk,mypk)); mtx.vout.push_back(CTxOut(txfee, CScript() << ParseHex(HexStr(pricespk)) << OP_CHECKSIG)); // marker @@ -505,39 +535,40 @@ UniValue PricesBet(uint64_t txfee,int64_t amount,int16_t leverage,std::vector vec; uint256 batontxid; std::string rawtx; char myaddr[64]; - cp = CCinit(&C,EVAL_PRICES); - if ( txfee == 0 ) + CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), nextheight); UniValue result(UniValue::VOBJ); + struct CCcontract_info *cp, C; CTransaction bettx; CPubKey pricespk, mypk; int64_t addedbets = 0, betamount, firstprice; std::vector vec; uint256 batontxid; std::string rawtx; char myaddr[64]; + cp = CCinit(&C, EVAL_PRICES); + if (txfee == 0) txfee = PRICES_TXFEE; mypk = pubkey2pk(Mypubkey()); - pricespk = GetUnspendable(cp,0); - GetCCaddress(cp,myaddr,mypk); - if ( AddNormalinputs(mtx,mypk,amount+txfee,64) >= amount+txfee ) + pricespk = GetUnspendable(cp, 0); + GetCCaddress(cp, myaddr, mypk); + if (AddNormalinputs(mtx, mypk, amount + txfee, 64) >= amount + txfee) { - if ( prices_batontxid(batontxid,bettx,bettxid) >= 0 ) + if (prices_batontxid(batontxid, bettx, bettxid) >= 0) { - mtx.vin.push_back(CTxIn(batontxid,0,CScript())); - mtx.vout.push_back(MakeCC1vout(cp->evalcode,txfee,mypk)); // baton for total funding - mtx.vout.push_back(MakeCC1vout(cp->evalcode,amount,pricespk)); - rawtx = FinalizeCCTx(0,cp,mtx,mypk,txfee,prices_addopret(bettxid,mypk,amount)); - return(prices_rawtxresult(result,rawtx,0)); + mtx.vin.push_back(CTxIn(batontxid, 0, CScript())); + mtx.vout.push_back(MakeCC1vout(cp->evalcode, txfee, mypk)); // baton for total funding + mtx.vout.push_back(MakeCC1vout(cp->evalcode, amount, pricespk)); + rawtx = FinalizeCCTx(0, cp, mtx, mypk, txfee, prices_addopret(bettxid, mypk, amount)); + return(prices_rawtxresult(result, rawtx, 0)); } else { - result.push_back(Pair("result","error")); - result.push_back(Pair("error","couldnt find batonttxid")); + result.push_back(Pair("result", "error")); + result.push_back(Pair("error", "couldnt find batonttxid")); return(result); } } - result.push_back(Pair("result","error")); - result.push_back(Pair("error","not enough funds")); + result.push_back(Pair("result", "error")); + result.push_back(Pair("error", "not enough funds")); return(result); } +// set cost basis (open price) for the bet UniValue PricesSetcostbasis(int64_t txfee, uint256 bettxid) { int32_t nextheight = komodo_nextheight(); @@ -559,7 +590,7 @@ UniValue PricesSetcostbasis(int64_t txfee, uint256 bettxid) { if (prices_betopretdecode(bettx.vout[numvouts - 1].scriptPubKey, pk, firstheight, positionsize, leverage, firstprice, vec, tokenid) == 'B') { - if (nextheight < firstheight + PRICES_DAYWINDOW) { + if (nextheight <= firstheight + PRICES_DAYWINDOW + PRICES_SMOOTHWIDTH) { result.push_back(Pair("result", "error")); result.push_back(Pair("error", "cannot calculate costbasis yet")); return(result); @@ -567,7 +598,7 @@ UniValue PricesSetcostbasis(int64_t txfee, uint256 bettxid) addedbets = prices_batontxid(batontxid, bettx, bettxid); mtx.vin.push_back(CTxIn(bettxid, 1, CScript())); // spend vin1 - for (i = 0; i < PRICES_DAYWINDOW; i++) // we need a full day to check if there was a rekt + for (i = 0; i < PRICES_DAYWINDOW + PRICES_SMOOTHWIDTH; i++) // the last datum for 24h is the costbasis value { if ((profits = prices_syntheticprofits(true, costbasis, firstheight, firstheight + i, leverage, vec, positionsize, addedbets)) < 0) { // we are in loss @@ -584,7 +615,7 @@ UniValue PricesSetcostbasis(int64_t txfee, uint256 bettxid) result.push_back(Pair("myfee", myfee)); mtx.vout.push_back(CTxOut(myfee, CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); mtx.vout.push_back(MakeCC1vout(cp->evalcode, bettx.vout[1].nValue - myfee - txfee, pricespk)); - rawtx = FinalizeCCTx(0, cp, mtx, mypk, txfee, prices_costbasisopret(bettxid, mypk, firstheight + PRICES_DAYWINDOW - 1, costbasis)); + rawtx = FinalizeCCTx(0, cp, mtx, mypk, txfee, prices_costbasisopret(bettxid, mypk, firstheight + PRICES_DAYWINDOW /*- 1*/, costbasis)); return(prices_rawtxresult(result, rawtx, 0)); } } From 2f077d3103d057c1a6292df41fc937dd9a81a7e1 Mon Sep 17 00:00:00 2001 From: dimxy Date: Mon, 15 Apr 2019 21:19:19 +0500 Subject: [PATCH 045/447] yet logging --- src/cc/prices.cpp | 214 +++++++++++++++++++++++----------------------- 1 file changed, 107 insertions(+), 107 deletions(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index fe3ae9c3a..cac6c15e2 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -240,142 +240,142 @@ int32_t prices_syntheticvec(std::vector &vec,std::vector } // calculates price for synthetic expression -int64_t prices_syntheticprice(std::vector vec,int32_t height,int32_t minmax,int16_t leverage) +int64_t prices_syntheticprice(std::vector vec, int32_t height, int32_t minmax, int16_t leverage) { - int32_t i,value,errcode,depth,retval = -1; - uint16_t opcode; - int64_t *pricedata,pricestack[4],price,den,a,b,c; + int32_t i, value, errcode, depth, retval = -1; + uint16_t opcode; + int64_t *pricedata, pricestack[4], price, den, a, b, c; - pricedata = (int64_t *)calloc(sizeof(*pricedata)*3,1 + PRICES_DAYWINDOW*2 + PRICES_SMOOTHWIDTH); + pricedata = (int64_t *)calloc(sizeof(*pricedata) * 3, 1 + PRICES_DAYWINDOW * 2 + PRICES_SMOOTHWIDTH); price = den = depth = errcode = 0; - for (i=0; i Date: Mon, 15 Apr 2019 21:43:22 +0500 Subject: [PATCH 046/447] addfunding rpc added --- src/cc/CCPrices.h | 8 +-- src/cc/prices.cpp | 8 +-- src/rpc/blockchain.cpp | 107 +++++++++++++++++++++++++++++++++++++++++ src/rpc/server.cpp | 1 + src/rpc/server.h | 1 + 5 files changed, 117 insertions(+), 8 deletions(-) diff --git a/src/cc/CCPrices.h b/src/cc/CCPrices.h index a32264a88..62da19aab 100644 --- a/src/cc/CCPrices.h +++ b/src/cc/CCPrices.h @@ -38,11 +38,11 @@ int32_t komodo_priceget(int64_t *buf64,int32_t ind,int32_t height,int32_t numblo bool PricesValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); // CCcustom -UniValue PricesBet(uint64_t txfee,int64_t amount,int16_t leverage,std::vector synthetic); -UniValue PricesAddFunding(uint64_t txfee,uint256 bettxid,int64_t amount); +UniValue PricesBet(int64_t txfee,int64_t amount,int16_t leverage,std::vector synthetic); +UniValue PricesAddFunding(int64_t txfee,uint256 bettxid,int64_t amount); UniValue PricesSetcostbasis(int64_t txfee,uint256 bettxid); -UniValue PricesRekt(uint64_t txfee,uint256 bettxid,int32_t rektheight); -UniValue PricesCashout(uint64_t txfee,uint256 bettxid); +UniValue PricesRekt(int64_t txfee,uint256 bettxid,int32_t rektheight); +UniValue PricesCashout(int64_t txfee,uint256 bettxid); UniValue PricesInfo(uint256 bettxid,int32_t refheight); UniValue PricesList(); diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index cac6c15e2..e6f5db97d 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -497,7 +497,7 @@ int64_t prices_batontxid(uint256 &batontxid,CTransaction bettx,uint256 bettxid) return(addedbets); } -UniValue PricesBet(uint64_t txfee,int64_t amount,int16_t leverage,std::vector synthetic) +UniValue PricesBet(int64_t txfee,int64_t amount,int16_t leverage,std::vector synthetic) { int32_t nextheight = komodo_nextheight(); CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(),nextheight); UniValue result(UniValue::VOBJ); @@ -535,7 +535,7 @@ UniValue PricesBet(uint64_t txfee,int64_t amount,int16_t leverage,std::vector vexpr; + SplitStr(sexpr, vexpr); + + // debug print parsed strings: + std::cerr << "parsed synthetic: "; + for (auto s : vexpr) + std::cerr << s << " "; + std::cerr << std::endl; + + return PricesBet(txfee, amount, leverage, vexpr); +} + +// pricesaddfunding rpc implementation +UniValue pricesaddfunding(const UniValue& params, bool fHelp) +{ + if (fHelp || params.size() != 2) + throw runtime_error("pricesaddfunding bettxid amount\n"); + LOCK(cs_main); + UniValue ret(UniValue::VOBJ); + + if (ASSETCHAINS_CBOPRET == 0) + throw JSONRPCError(RPC_INVALID_PARAMETER, "only -ac_cbopret chains have prices"); + + CAmount txfee = 10000; + uint256 bettxid = Parseuint256(params[0].get_str().c_str()); + CAmount amount = atoll(params[1].get_str().c_str()); + + return PricesAddFunding(txfee, bettxid, amount); +} + +// rpc pricessetcostbasis implementation +UniValue pricessetcostbasis(const UniValue& params, bool fHelp) +{ + if (fHelp || params.size() != 1) + throw runtime_error("pricessetcostbasis bettxid\n"); + LOCK(cs_main); + UniValue ret(UniValue::VOBJ); + + if (ASSETCHAINS_CBOPRET == 0) + throw JSONRPCError(RPC_INVALID_PARAMETER, "only -ac_cbopret chains have prices"); + + uint256 bettxid = Parseuint256(params[0].get_str().c_str()); + if( bettxid.IsNull() ) + throw runtime_error("invalid bettxid\n"); + + int64_t txfee = 10000; + + return PricesSetcostbasis(txfee, bettxid); +} + +UniValue pricescashout(const UniValue& params, bool fHelp) +{ + if (fHelp || params.size() != 1) + throw runtime_error("pricescashout bettxid\n"); + LOCK(cs_main); + UniValue ret(UniValue::VOBJ); + + if (ASSETCHAINS_CBOPRET == 0) + throw JSONRPCError(RPC_INVALID_PARAMETER, "only -ac_cbopret chains have prices"); + + uint256 bettxid = Parseuint256(params[0].get_str().c_str()); + if (bettxid.IsNull()) + throw runtime_error("invalid bettxid\n"); + + int64_t txfee = 10000; + + return PricesCashout(txfee, bettxid); +} + +UniValue pricesrekt(const UniValue& params, bool fHelp) +{ + if (fHelp || params.size() != 2) + throw runtime_error("pricesrekt bettxid height\n"); + LOCK(cs_main); + UniValue ret(UniValue::VOBJ); + + if (ASSETCHAINS_CBOPRET == 0) + throw JSONRPCError(RPC_INVALID_PARAMETER, "only -ac_cbopret chains have prices"); + + uint256 bettxid = Parseuint256(params[0].get_str().c_str()); + if (bettxid.IsNull()) + throw runtime_error("invalid bettxid\n"); + + int32_t height = atoi(params[0].get_str().c_str()); + + int64_t txfee = 10000; + + return PricesRekt(txfee, bettxid, height); +} + UniValue gettxout(const UniValue& params, bool fHelp) { if (fHelp || params.size() < 2 || params.size() > 3) diff --git a/src/rpc/server.cpp b/src/rpc/server.cpp index 3cc23a4fd..29e616bca 100644 --- a/src/rpc/server.cpp +++ b/src/rpc/server.cpp @@ -468,6 +468,7 @@ static const CRPCCommand vRPCCommands[] = { "prices", "pricessetcostbasis", &pricessetcostbasis, true }, { "prices", "pricescashout", &pricescashout, true }, { "prices", "pricesrekt", &pricesrekt, true }, + { "prices", "pricesaddfunding", &pricesaddfunding, true }, // Pegs { "pegs", "pegsaddress", &pegsaddress, true }, diff --git a/src/rpc/server.h b/src/rpc/server.h index aef17d931..2bd0b91c6 100644 --- a/src/rpc/server.h +++ b/src/rpc/server.h @@ -501,6 +501,7 @@ extern UniValue pricesbet(const UniValue& params, bool fHelp); extern UniValue pricessetcostbasis(const UniValue& params, bool fHelp); extern UniValue pricescashout(const UniValue& params, bool fHelp); extern UniValue pricesrekt(const UniValue& params, bool fHelp); +extern UniValue pricesaddfunding(const UniValue& params, bool fHelp); // test rpc: From 505619e202dac0e23759cc80be162d3c76e0e6f4 Mon Sep 17 00:00:00 2001 From: dimxy Date: Mon, 15 Apr 2019 22:15:12 +0500 Subject: [PATCH 047/447] init batontxid added checks for rpc --- src/cc/prices.cpp | 2 ++ src/rpc/blockchain.cpp | 8 +++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index e6f5db97d..28bfaf848 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -471,6 +471,8 @@ int64_t prices_batontxid(uint256 &batontxid,CTransaction bettx,uint256 bettxid) int32_t height; int32_t retcode; + batontxid = bettxid; // initially set to the source bet tx + // iterate through batons, adding up vout1 -> addedbets while ((retcode = CCgetspenttxid(batontxid, vini, height, bettxid, 1)) == 0) { diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index aad8c4c6c..550355cff 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -1348,7 +1348,8 @@ UniValue pricesbet(const UniValue& params, bool fHelp) UniValue pricesaddfunding(const UniValue& params, bool fHelp) { if (fHelp || params.size() != 2) - throw runtime_error("pricesaddfunding bettxid amount\n"); + throw runtime_error("pricesaddfunding bettxid amount\n" + "where amount is in satoshis\n"); LOCK(cs_main); UniValue ret(UniValue::VOBJ); @@ -1357,7 +1358,12 @@ UniValue pricesaddfunding(const UniValue& params, bool fHelp) CAmount txfee = 10000; uint256 bettxid = Parseuint256(params[0].get_str().c_str()); + if( bettxid.IsNull() ) + throw runtime_error("invalid bettxid\n"); + CAmount amount = atoll(params[1].get_str().c_str()); + if( amount <= 0 ) + throw runtime_error("invalid amount\n"); return PricesAddFunding(txfee, bettxid, amount); } From b7756c071b9718005651fa2a93bd0af40ddd8840 Mon Sep 17 00:00:00 2001 From: dimxy Date: Mon, 15 Apr 2019 22:37:26 +0500 Subject: [PATCH 048/447] txfee --- src/cc/prices.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 28bfaf848..f3b0c71ef 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -464,7 +464,7 @@ int64_t prices_costbasis(CTransaction bettx) } // calculates added bet total, returns the last baton txid -int64_t prices_batontxid(uint256 &batontxid,CTransaction bettx,uint256 bettxid) +int64_t prices_batontxid(uint256 &batontxid, CTransaction bettx, uint256 bettxid) { int64_t addedbets = 0; int32_t vini; @@ -490,12 +490,11 @@ int64_t prices_batontxid(uint256 &batontxid,CTransaction bettx,uint256 bettxid) addedbets += amount; std::cerr << "prices_batontxid() added amount=" << amount << std::endl; } - else { + else { std::cerr << "prices_batontxid() cannot load or decode add bet tx, isLoaded=" << isLoaded << " funcId=" << (int)funcId << std::endl; } } - return(addedbets); } @@ -548,7 +547,7 @@ UniValue PricesAddFunding(int64_t txfee, uint256 bettxid, int64_t amount) mypk = pubkey2pk(Mypubkey()); pricespk = GetUnspendable(cp, 0); GetCCaddress(cp, myaddr, mypk); - if (AddNormalinputs(mtx, mypk, amount + txfee, 64) >= amount + txfee) + if (AddNormalinputs(mtx, mypk, amount + 2*txfee, 64) >= amount + 2*txfee) { if (prices_batontxid(batontxid, bettx, bettxid) >= 0) { From 411f68ab807b51684f602cef3c0535838de5381d Mon Sep 17 00:00:00 2001 From: dimxy Date: Mon, 15 Apr 2019 23:16:19 +0500 Subject: [PATCH 049/447] corr batontxid change --- src/cc/prices.cpp | 63 ++++++++++++++++++++++++++++------------------- 1 file changed, 38 insertions(+), 25 deletions(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index f3b0c71ef..7808a38ee 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -472,9 +472,9 @@ int64_t prices_batontxid(uint256 &batontxid, CTransaction bettx, uint256 bettxid int32_t retcode; batontxid = bettxid; // initially set to the source bet tx - + uint256 sourcetxid = bettxid; // iterate through batons, adding up vout1 -> addedbets - while ((retcode = CCgetspenttxid(batontxid, vini, height, bettxid, 1)) == 0) { + while ((retcode = CCgetspenttxid(batontxid, vini, height, sourcetxid, 1)) == 0) { CTransaction txBaton; uint256 hashBlock; @@ -492,47 +492,53 @@ int64_t prices_batontxid(uint256 &batontxid, CTransaction bettx, uint256 bettxid } else { std::cerr << "prices_batontxid() cannot load or decode add bet tx, isLoaded=" << isLoaded << " funcId=" << (int)funcId << std::endl; + return -1; } + sourcetxid = batontxid; } return(addedbets); } -UniValue PricesBet(int64_t txfee,int64_t amount,int16_t leverage,std::vector synthetic) +UniValue PricesBet(int64_t txfee, int64_t amount, int16_t leverage, std::vector synthetic) { int32_t nextheight = komodo_nextheight(); - CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(),nextheight); UniValue result(UniValue::VOBJ); - struct CCcontract_info *cp,C; CPubKey pricespk,mypk; int64_t betamount,firstprice; std::vector vec; char myaddr[64]; std::string rawtx; - if ( leverage > PRICES_MAXLEVERAGE || leverage < -PRICES_MAXLEVERAGE ) + CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), nextheight); UniValue result(UniValue::VOBJ); + struct CCcontract_info *cp, C; CPubKey pricespk, mypk; int64_t betamount, firstprice; + std::vector vec; + char myaddr[64]; + std::string rawtx; + + if (leverage > PRICES_MAXLEVERAGE || leverage < -PRICES_MAXLEVERAGE) { - result.push_back(Pair("result","error")); - result.push_back(Pair("error","leverage too big")); + result.push_back(Pair("result", "error")); + result.push_back(Pair("error", "leverage too big")); return(result); } - cp = CCinit(&C,EVAL_PRICES); - if ( txfee == 0 ) + cp = CCinit(&C, EVAL_PRICES); + if (txfee == 0) txfee = PRICES_TXFEE; mypk = pubkey2pk(Mypubkey()); - pricespk = GetUnspendable(cp,0); - GetCCaddress(cp,myaddr,mypk); - if ( prices_syntheticvec(vec,synthetic) < 0 || (firstprice= prices_syntheticprice(vec,nextheight-1,1,leverage)) < 0 || vec.size() == 0 || vec.size() > 4096 ) + pricespk = GetUnspendable(cp, 0); + GetCCaddress(cp, myaddr, mypk); + if (prices_syntheticvec(vec, synthetic) < 0 || (firstprice = prices_syntheticprice(vec, nextheight - 1, 1, leverage)) < 0 || vec.size() == 0 || vec.size() > 4096) { - result.push_back(Pair("result","error")); - result.push_back(Pair("error","invalid synthetic")); + result.push_back(Pair("result", "error")); + result.push_back(Pair("error", "invalid synthetic")); return(result); } - if ( AddNormalinputs(mtx,mypk,amount+5*txfee,64) >= amount+5*txfee ) + if (AddNormalinputs(mtx, mypk, amount + 5 * txfee, 64) >= amount + 5 * txfee) { betamount = (amount * 199) / 200; - mtx.vout.push_back(MakeCC1vout(cp->evalcode,txfee,mypk)); // vout0 baton for total funding - mtx.vout.push_back(MakeCC1vout(cp->evalcode,(amount-betamount)+2*txfee,pricespk)); - mtx.vout.push_back(MakeCC1of2vout(cp->evalcode,betamount,pricespk,mypk)); + mtx.vout.push_back(MakeCC1vout(cp->evalcode, txfee, mypk)); // vout0 baton for total funding + mtx.vout.push_back(MakeCC1vout(cp->evalcode, (amount - betamount) + 2 * txfee, pricespk)); + mtx.vout.push_back(MakeCC1of2vout(cp->evalcode, betamount, pricespk, mypk)); mtx.vout.push_back(CTxOut(txfee, CScript() << ParseHex(HexStr(pricespk)) << OP_CHECKSIG)); // marker - rawtx = FinalizeCCTx(0,cp,mtx,mypk,txfee,prices_betopret(mypk,nextheight-1,amount,leverage,firstprice,vec,zeroid)); - return(prices_rawtxresult(result,rawtx,0)); + rawtx = FinalizeCCTx(0, cp, mtx, mypk, txfee, prices_betopret(mypk, nextheight - 1, amount, leverage, firstprice, vec, zeroid)); + return(prices_rawtxresult(result, rawtx, 0)); } - result.push_back(Pair("result","error")); - result.push_back(Pair("error","not enough funds")); + result.push_back(Pair("result", "error")); + result.push_back(Pair("error", "not enough funds")); return(result); } @@ -540,13 +546,20 @@ UniValue PricesAddFunding(int64_t txfee, uint256 bettxid, int64_t amount) { int32_t nextheight = komodo_nextheight(); CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), nextheight); UniValue result(UniValue::VOBJ); - struct CCcontract_info *cp, C; CTransaction bettx; CPubKey pricespk, mypk; int64_t addedbets = 0, betamount, firstprice; std::vector vec; uint256 batontxid; std::string rawtx; char myaddr[64]; + struct CCcontract_info *cp, C; CTransaction bettx; + CPubKey pricespk, mypk; + //int64_t addedbets = 0, betamount, firstprice; + std::vector vec; + uint256 batontxid; + std::string rawtx; + //char myaddr[64]; + cp = CCinit(&C, EVAL_PRICES); if (txfee == 0) txfee = PRICES_TXFEE; mypk = pubkey2pk(Mypubkey()); pricespk = GetUnspendable(cp, 0); - GetCCaddress(cp, myaddr, mypk); + //GetCCaddress(cp, myaddr, mypk); if (AddNormalinputs(mtx, mypk, amount + 2*txfee, 64) >= amount + 2*txfee) { if (prices_batontxid(batontxid, bettx, bettxid) >= 0) From e4de8aca2d791136e1a190efd73a50527aa1532f Mon Sep 17 00:00:00 2001 From: dimxy Date: Mon, 15 Apr 2019 23:27:06 +0500 Subject: [PATCH 050/447] corr baton vin --- src/cc/prices.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 7808a38ee..dfed22378 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -474,7 +474,7 @@ int64_t prices_batontxid(uint256 &batontxid, CTransaction bettx, uint256 bettxid batontxid = bettxid; // initially set to the source bet tx uint256 sourcetxid = bettxid; // iterate through batons, adding up vout1 -> addedbets - while ((retcode = CCgetspenttxid(batontxid, vini, height, sourcetxid, 1)) == 0) { + while ((retcode = CCgetspenttxid(batontxid, vini, height, sourcetxid, 0)) == 0) { CTransaction txBaton; uint256 hashBlock; @@ -531,7 +531,7 @@ UniValue PricesBet(int64_t txfee, int64_t amount, int16_t leverage, std::vector< { betamount = (amount * 199) / 200; mtx.vout.push_back(MakeCC1vout(cp->evalcode, txfee, mypk)); // vout0 baton for total funding - mtx.vout.push_back(MakeCC1vout(cp->evalcode, (amount - betamount) + 2 * txfee, pricespk)); + mtx.vout.push_back(MakeCC1vout(cp->evalcode, (amount - betamount) + 2 * txfee, pricespk)); // vout1, when spent, costbasis is set mtx.vout.push_back(MakeCC1of2vout(cp->evalcode, betamount, pricespk, mypk)); mtx.vout.push_back(CTxOut(txfee, CScript() << ParseHex(HexStr(pricespk)) << OP_CHECKSIG)); // marker rawtx = FinalizeCCTx(0, cp, mtx, mypk, txfee, prices_betopret(mypk, nextheight - 1, amount, leverage, firstprice, vec, zeroid)); From 59fbfbcae7e42f3354a50b74524c6907e3eeea21 Mon Sep 17 00:00:00 2001 From: dimxy Date: Tue, 16 Apr 2019 00:19:10 +0500 Subject: [PATCH 051/447] pricesinfo height opt --- src/cc/prices.cpp | 13 +++++++++++++ src/wallet/rpcwallet.cpp | 10 ++++++---- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index dfed22378..486d97f8c 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -397,6 +397,11 @@ int64_t prices_syntheticprofits(bool calcCostbasis, int64_t &costbasis, int32_t { int64_t price, profits = 0; + if (height < firstheight) { + fprintf(stderr, "requested height is lower than bet firstheight.%d\n", height); + return 0; + } + int32_t minmax = (height < firstheight + PRICES_DAYWINDOW); // if we are within 24h then use min or max value if ((price = prices_syntheticprice(vec, height, minmax, leverage)) < 0) @@ -768,6 +773,14 @@ UniValue PricesInfo(uint256 bettxid, int32_t refheight) { if (prices_betopretdecode(bettx.vout[numvouts - 1].scriptPubKey, pk, firstheight, positionsize, leverage, firstprice, vec, tokenid) == 'B') { + if (refheight > 0 && refheight < firstheight) { + result.push_back(Pair("result", "error")); + result.push_back(Pair("error", "incorrect height")); + return(result); + } + if (refheight == 0) + refheight = komodo_nextheight()-1; + costbasis = prices_costbasis(bettx); addedbets = prices_batontxid(batontxid, bettx, bettxid); if ((profits = prices_syntheticprofits(false, costbasis, firstheight, refheight, leverage, vec, positionsize, addedbets)) < 0) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 05283c0b9..8d6af20c2 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -6931,13 +6931,15 @@ UniValue priceslist(const UniValue& params, bool fHelp) UniValue pricesinfo(const UniValue& params, bool fHelp) { uint256 bettxid; int32_t height; - if ( fHelp || params.size() != 2 ) - throw runtime_error("pricesinfo fundingtxid height\n"); + if ( fHelp || params.size() != 1 && params.size() != 2) + throw runtime_error("pricesinfo fundingtxid [height]\n"); if ( ensure_CCrequirements(EVAL_PRICES) < 0 ) throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); bettxid = Parseuint256((char *)params[0].get_str().c_str()); - height = atoi(params[1].get_str().c_str()); - return(PricesInfo(bettxid,height)); + height = 0; + if (params.size() == 2) + height = atoi(params[1].get_str().c_str()); + return(PricesInfo(bettxid, height)); } UniValue dicefund(const UniValue& params, bool fHelp) From e0fa061cc9f09695a081171a83ede61cf545d9b0 Mon Sep 17 00:00:00 2001 From: dimxy Date: Tue, 16 Apr 2019 13:25:07 +0500 Subject: [PATCH 052/447] help message --- src/wallet/rpcwallet.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 8d6af20c2..a155603d9 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -6932,7 +6932,7 @@ UniValue pricesinfo(const UniValue& params, bool fHelp) { uint256 bettxid; int32_t height; if ( fHelp || params.size() != 1 && params.size() != 2) - throw runtime_error("pricesinfo fundingtxid [height]\n"); + throw runtime_error("pricesinfo bettxid [height]\n"); if ( ensure_CCrequirements(EVAL_PRICES) < 0 ) throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); bettxid = Parseuint256((char *)params[0].get_str().c_str()); From efaedac711614e3973f4f5ffde5a12dbba101f98 Mon Sep 17 00:00:00 2001 From: dimxy Date: Tue, 16 Apr 2019 23:08:39 +0500 Subject: [PATCH 053/447] first validation code added --- src/cc/prices.cpp | 284 ++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 248 insertions(+), 36 deletions(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 486d97f8c..0dd667c1f 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -126,35 +126,240 @@ uint8_t prices_finalopretdecode(CScript scriptPubKey,uint256 &bettxid,int64_t &p return(0); } +bool CheckPricesOpret(const CTransaction & tx, vscript_t &opret) +{ + return (tx.vout.size() == 0 || !GetOpReturnData(tx.vout.back().scriptPubKey, opret) || opret.size() < 3 || opret.begin()[0] != EVAL_PRICES) || opret.begin()[1] == 0; +} + +bool ValidateBetTx(struct CCcontract_info *cp, Eval *eval, const CTransaction & bettx) +{ + uint256 tokenid; + int64_t positionsize, firstprice; + int32_t firstheight; + int16_t leverage; + CPubKey pk, pricespk; + std::vector vec; + + if (bettx.vout.size() < 5 || bettx.vout.size() > 6) + return eval->Invalid("incorrect vout number for bet tx"); + + vscript_t opret; + if( prices_betopretdecode(bettx.vout.back().scriptPubKey, pk, firstheight, positionsize, leverage, firstprice, vec, tokenid) != 'B') + return eval->Invalid("cannot decode opreturn for bet tx"); + + pricespk = GetUnspendable(cp, 0); + + if (MakeCC1vout(cp->evalcode, bettx.vout[0].nValue, pk) != bettx.vout[0]) + return eval->Invalid("cannot validate vout0 in bet tx with pk from opreturn"); + if (MakeCC1vout(cp->evalcode, bettx.vout[1].nValue, pricespk) != bettx.vout[1]) + return eval->Invalid("cannot validate vout1 in bet tx with global pk"); + if( MakeCC1of2vout(cp->evalcode, bettx.vout[2].nValue, pk, pricespk) != bettx.vout[2] ) + return eval->Invalid("cannot validate 1of2 vout2 in bet tx with pk from opreturn"); + + return true; +} + + +bool ValidateAddFundingTx(struct CCcontract_info *cp, Eval *eval, const CTransaction & addfundingtx) +{ + uint256 bettxid; + int64_t amount; + CPubKey pk, pricespk; + + if (addfundingtx.vout.size() < 3 || addfundingtx.vout.size() > 4) + return eval->Invalid("incorrect vout number for add funding tx"); + + vscript_t opret; + if (prices_addopretdecode(addfundingtx.vout.back().scriptPubKey, bettxid, pk, amount) != 'A') + return eval->Invalid("cannot decode opreturn for add funding tx"); + + pricespk = GetUnspendable(cp, 0); + + if (MakeCC1vout(cp->evalcode, addfundingtx.vout[0].nValue, pk) != addfundingtx.vout[0]) + return eval->Invalid("cannot validate vout0 in add funding tx with pk from opreturn"); + if (MakeCC1vout(cp->evalcode, addfundingtx.vout[1].nValue, pricespk) != addfundingtx.vout[1]) + return eval->Invalid("cannot validate vout1 in add funding tx with global pk"); + + return true; +} + +bool ValidateCostbasisTx(struct CCcontract_info *cp, Eval *eval, const CTransaction & costbasistx, const CTransaction & bettx) +{ + uint256 bettxid; + int64_t amount; + CPubKey pk, pricespk; + int32_t height; + + // check basic structure: + if (costbasistx.vout.size() < 3 || costbasistx.vout.size() > 4) + return eval->Invalid("incorrect vout number for add funding tx"); + + vscript_t opret; + if (prices_costbasisopretdecode(costbasistx.vout.back().scriptPubKey, bettxid, pk, height, amount) != 'C') + return eval->Invalid("cannot decode opreturn for setcostbasis tx"); + + pricespk = GetUnspendable(cp, 0); + if (MakeCC1vout(cp->evalcode, costbasistx.vout[0].nValue, pk) != costbasistx.vout[0]) + return eval->Invalid("cannot validate vout0 in add funding tx with pk from opreturn"); + if (MakeCC1vout(cp->evalcode, costbasistx.vout[1].nValue, pricespk) != costbasistx.vout[1]) + return eval->Invalid("cannot validate vout1 in add funding tx with global pk"); + + if (bettx.vout.size() < 1) // maybe this is already checked outside, but it is safe to check here too and have encapsulated check + return eval->Invalid("incorrect bettx"); + + // check costbasis rules: + if (costbasistx.vout[0].nValue > bettx.vout[1].nValue / 10) + return eval->Invalid("costbasis myfee too big"); + + uint256 tokenid; + int64_t positionsize, firstprice; + int32_t firstheight; + int16_t leverage; + std::vector vec; + if (prices_betopretdecode(bettx.vout.back().scriptPubKey, pk, firstheight, positionsize, leverage, firstprice, vec, tokenid) != 'B') + return eval->Invalid("cannot decode opreturn for bet tx"); + + if( firstheight + PRICES_DAYWINDOW + PRICES_SMOOTHWIDTH > chainActive.Height() ) + return eval->Invalid("cannot calculate costbasis yet"); + + return true; +} + +bool ValidateFinalTx(struct CCcontract_info *cp, Eval *eval, const CTransaction & finaltx) +{ + uint256 bettxid; + int64_t amount; + CPubKey pk, pricespk; + int64_t profits; + int32_t height; + int64_t firstprice, costbasis, addedbets, positionsize; + int16_t leverage; + + if (finaltx.vout.size() < 2 || finaltx.vout.size() > 3) + return eval->Invalid("incorrect vout number for final tx"); + + vscript_t opret; + if (prices_finalopretdecode(finaltx.vout.back().scriptPubKey, bettxid, profits, height, pk, firstprice, costbasis, addedbets, positionsize, leverage) != 'F') + return eval->Invalid("cannot decode opreturn for final tx"); + + pricespk = GetUnspendable(cp, 0); + + if (MakeCC1vout(cp->evalcode, finaltx.vout[0].nValue, pk) != finaltx.vout[0]) + return eval->Invalid("cannot validate vout0 in final tx with pk from opreturn"); + + if( finaltx.vout.size() == 3 && MakeCC1vout(cp->evalcode, finaltx.vout[1].nValue, pricespk) != finaltx.vout[1] ) + return eval->Invalid("cannot validate vout1 in final tx with global pk"); + + return true; +} + bool PricesValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn) { + vscript_t vopret; + + // check basic opret rules: + if (CheckPricesOpret(tx, vopret)) + return eval->Invalid("tx has no prices opreturn"); + + uint8_t funcId = vopret.begin()[1]; + + CTransaction vintx; + vscript_t vintxOpret; + int32_t ccVinCount = 0; + int32_t prevoutN = 0; + // load vintx: + for (auto vin : tx.vin) + if (cp->ismyvin(vin.scriptSig)) { + uint256 hashBlock; + if (myGetTransaction(vin.prevout.hash, vintx, hashBlock)) + return eval->Invalid("cannot load vin tx"); + prevoutN = vin.prevout.n; + ccVinCount++; + } + if (ccVinCount != 1) // must be only one cc vintx + return eval->Invalid("incorrect cc vin txns num"); + + if (!CheckPricesOpret(vintx, vintxOpret)) + return eval->Invalid("cannot find prices opret in vintx"); + + if (vintxOpret.begin()[1] == 'B' && prevoutN == 3) { // check basic spending rules + return eval->Invalid("cannot spend bet marker"); + } + + switch (funcId) { + case 'B': // bet + return eval->Invalid("unexpected validate for bet funcid"); + + case 'A': // add funding + // check tx structure: + if (!ValidateAddFundingTx(cp, eval, tx)) + return false; // invalid state is already set in the func + + if (vintxOpret.begin()[1] == 'B') { + if (!ValidateBetTx(cp, eval, vintx)) // check tx structure + return false; + } + else if (vintxOpret.begin()[1] == 'A') { + // no need to validate the previous addfunding tx (it was validated when added) + } + + if (prevoutN != 0) { // check spending rules + return eval->Invalid("incorrect vout to spend"); + } + break; + + case 'C': // set costbasis + if (!ValidateBetTx(cp, eval, vintx)) // first check bet tx + return false; + if (!ValidateCostbasisTx(cp, eval, tx, vintx)) + return false; + if (prevoutN != 1) { // check spending rules + return eval->Invalid("incorrect vout to spend"); + } + break; + + case 'F': // final tx + if (!ValidateBetTx(cp, eval, vintx)) // first check bet tx + return false; + if (!ValidateFinalTx(cp, eval, tx)) + return false; + if (prevoutN != 2) { // check spending rules + return eval->Invalid("incorrect vout to spend"); + } + break; + + default: + return eval->Invalid("invalid funcid"); + } + return true; } // end of consensus code // helper functions for rpc calls in rpcwallet.cpp -int64_t AddPricesInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,char *destaddr,int64_t total,int32_t maxinputs,uint256 vintxid,int32_t vinvout) +int64_t AddPricesInputs(struct CCcontract_info *cp, CMutableTransaction &mtx, char *destaddr, int64_t total, int32_t maxinputs, uint256 vintxid, int32_t vinvout) { - int64_t nValue,price,totalinputs = 0; uint256 txid,hashBlock; std::vector origpubkey; CTransaction vintx; int32_t vout,n = 0; + int64_t nValue, price, totalinputs = 0; uint256 txid, hashBlock; std::vector origpubkey; CTransaction vintx; int32_t vout, n = 0; std::vector > unspentOutputs; - SetCCunspents(unspentOutputs,destaddr); - for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) + + SetCCunspents(unspentOutputs, destaddr); + for (std::vector >::const_iterator it = unspentOutputs.begin(); it != unspentOutputs.end(); it++) { txid = it->first.txhash; vout = (int32_t)it->first.index; - if ( vout == vinvout && txid == vintxid ) + if (vout == vinvout && txid == vintxid) continue; - if ( GetTransaction(txid,vintx,hashBlock,false) != 0 && vout < vintx.vout.size() ) + if (GetTransaction(txid, vintx, hashBlock, false) != 0 && vout < vintx.vout.size()) { - if ( (nValue= vintx.vout[vout].nValue) >= total/maxinputs && myIsutxo_spentinmempool(ignoretxid,ignorevin,txid,vout) == 0 ) + if ((nValue = vintx.vout[vout].nValue) >= total / maxinputs && myIsutxo_spentinmempool(ignoretxid, ignorevin, txid, vout) == 0) { - if ( total != 0 && maxinputs != 0 ) - mtx.vin.push_back(CTxIn(txid,vout,CScript())); + 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) ) + if ((total > 0 && totalinputs >= total) || (maxinputs > 0 && n >= maxinputs)) break; } } @@ -162,51 +367,55 @@ int64_t AddPricesInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,char return(totalinputs); } -UniValue prices_rawtxresult(UniValue &result,std::string rawtx,int32_t broadcastflag) +UniValue prices_rawtxresult(UniValue &result, std::string rawtx, int32_t broadcastflag) { CTransaction tx; - if ( rawtx.size() > 0 ) + if (rawtx.size() > 0) { - result.push_back(Pair("hex",rawtx)); - if ( DecodeHexTx(tx,rawtx) != 0 ) + result.push_back(Pair("hex", rawtx)); + if (DecodeHexTx(tx, rawtx) != 0) { - if ( broadcastflag != 0 && myAddtomempool(tx) != 0 ) + if (broadcastflag != 0 && myAddtomempool(tx) != 0) RelayTransaction(tx); - result.push_back(Pair("txid",tx.GetHash().ToString())); - result.push_back(Pair("result","success")); - } else result.push_back(Pair("error","decode hex")); - } else result.push_back(Pair("error","couldnt finalize CCtx")); + result.push_back(Pair("txid", tx.GetHash().ToString())); + result.push_back(Pair("result", "success")); + } + else + result.push_back(Pair("error", "decode hex")); + } + else + result.push_back(Pair("error", "couldnt finalize CCtx")); return(result); } -int32_t prices_syntheticvec(std::vector &vec,std::vector synthetic) +int32_t prices_syntheticvec(std::vector &vec, std::vector synthetic) { - int32_t i,need,ind,depth = 0; std::string opstr; uint16_t opcode,weight; + int32_t i, need, ind, depth = 0; std::string opstr; uint16_t opcode, weight; if (synthetic.size() == 0) { std::cerr << "prices_syntheticvec() expression is empty" << std::endl; return(-1); } - for (i=0; i= 0 ) + else if (!is_weight_str(opstr) && (ind = komodo_priceind(opstr.c_str())) >= 0) opcode = ind, need = 0; - else if ( (weight= atoi(opstr.c_str())) > 0 && weight < KOMODO_MAXPRICES ) + else if ((weight = atoi(opstr.c_str())) > 0 && weight < KOMODO_MAXPRICES) { opcode = PRICES_WEIGHT | weight; need = 1; @@ -231,9 +440,9 @@ int32_t prices_syntheticvec(std::vector &vec,std::vector } vec.push_back(opcode); } - if ( depth != 0 ) + if (depth != 0) { - fprintf(stderr,"prices_syntheticvec() depth.%d not empty\n",depth); + fprintf(stderr, "prices_syntheticvec() depth.%d not empty\n", depth); return(-5); } return(0); @@ -446,6 +655,7 @@ int64_t prices_costbasis(CTransaction bettx) uint256 txidCostbasis; int32_t vini; int32_t height; + if (CCgetspenttxid(txidCostbasis, vini, height, bettx.GetHash(), 1) < 0) { std::cerr << "prices_costbasis() no costbasis txid found" << std::endl; return 0; @@ -509,9 +719,11 @@ UniValue PricesBet(int64_t txfee, int64_t amount, int16_t leverage, std::vector< { int32_t nextheight = komodo_nextheight(); CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), nextheight); UniValue result(UniValue::VOBJ); - struct CCcontract_info *cp, C; CPubKey pricespk, mypk; int64_t betamount, firstprice; + struct CCcontract_info *cp, C; + CPubKey pricespk, mypk; + int64_t betamount, firstprice; std::vector vec; - char myaddr[64]; + //char myaddr[64]; std::string rawtx; if (leverage > PRICES_MAXLEVERAGE || leverage < -PRICES_MAXLEVERAGE) @@ -525,7 +737,7 @@ UniValue PricesBet(int64_t txfee, int64_t amount, int16_t leverage, std::vector< txfee = PRICES_TXFEE; mypk = pubkey2pk(Mypubkey()); pricespk = GetUnspendable(cp, 0); - GetCCaddress(cp, myaddr, mypk); + //GetCCaddress(cp, myaddr, mypk); if (prices_syntheticvec(vec, synthetic) < 0 || (firstprice = prices_syntheticprice(vec, nextheight - 1, 1, leverage)) < 0 || vec.size() == 0 || vec.size() > 4096) { result.push_back(Pair("result", "error")); From ea4fc69f0cf0fa91bbc9d2a099852bbaf60e7ef6 Mon Sep 17 00:00:00 2001 From: dimxy Date: Tue, 16 Apr 2019 23:20:57 +0500 Subject: [PATCH 054/447] test invalid costabasis --- src/cc/prices.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 0dd667c1f..817120fc3 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -316,6 +316,7 @@ bool PricesValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx if (prevoutN != 1) { // check spending rules return eval->Invalid("incorrect vout to spend"); } + return eval->Invalid("test: costbasis is good"); break; case 'F': // final tx From bf4f084d082636610363473a63e07347ef046127 Mon Sep 17 00:00:00 2001 From: dimxy Date: Tue, 16 Apr 2019 23:38:52 +0500 Subject: [PATCH 055/447] costbasis tx added txfee input --- src/cc/prices.cpp | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 817120fc3..6773a0314 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -843,12 +843,20 @@ UniValue PricesSetcostbasis(int64_t txfee, uint256 bettxid) result.push_back(Pair("rekt", 0)); prices_betjson(result, profits, costbasis, positionsize, addedbets, leverage, firstheight, firstprice); - myfee = bettx.vout[1].nValue / 10; // fee for setting costbasis - result.push_back(Pair("myfee", myfee)); - mtx.vout.push_back(CTxOut(myfee, CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); - mtx.vout.push_back(MakeCC1vout(cp->evalcode, bettx.vout[1].nValue - myfee - txfee, pricespk)); - rawtx = FinalizeCCTx(0, cp, mtx, mypk, txfee, prices_costbasisopret(bettxid, mypk, firstheight + PRICES_DAYWINDOW /*- 1*/, costbasis)); - return(prices_rawtxresult(result, rawtx, 0)); + + if (AddNormalinputs(mtx, mypk, txfee, 64) >= txfee) + { + myfee = bettx.vout[1].nValue / 10; // fee for setting costbasis + result.push_back(Pair("myfee", myfee)); + + mtx.vout.push_back(CTxOut(myfee, CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); + mtx.vout.push_back(MakeCC1vout(cp->evalcode, bettx.vout[1].nValue - myfee - txfee, pricespk)); + rawtx = FinalizeCCTx(0, cp, mtx, mypk, txfee, prices_costbasisopret(bettxid, mypk, firstheight + PRICES_DAYWINDOW /*- 1*/, costbasis)); + return(prices_rawtxresult(result, rawtx, 0)); + } + result.push_back(Pair("result", "error")); + result.push_back(Pair("error", "not enough funds")); + return(result); } } result.push_back(Pair("result", "error")); From ec783e9a4e18099dc9979fe967a4ffd3624aa19b Mon Sep 17 00:00:00 2001 From: dimxy Date: Wed, 17 Apr 2019 00:00:27 +0500 Subject: [PATCH 056/447] txfee costbasis corr --- src/cc/prices.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 6773a0314..b996348a4 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -829,7 +829,7 @@ UniValue PricesSetcostbasis(int64_t txfee, uint256 bettxid) } addedbets = prices_batontxid(batontxid, bettx, bettxid); - mtx.vin.push_back(CTxIn(bettxid, 1, CScript())); // spend vin1 + mtx.vin.push_back(CTxIn(bettxid, 1, CScript())); // spend vin1 with betamount for (i = 0; i < PRICES_DAYWINDOW + PRICES_SMOOTHWIDTH; i++) // the last datum for 24h is the costbasis value { if ((profits = prices_syntheticprofits(true, costbasis, firstheight, firstheight + i, leverage, vec, positionsize, addedbets)) < 0) @@ -844,13 +844,13 @@ UniValue PricesSetcostbasis(int64_t txfee, uint256 bettxid) prices_betjson(result, profits, costbasis, positionsize, addedbets, leverage, firstheight, firstprice); - if (AddNormalinputs(mtx, mypk, txfee, 64) >= txfee) + if (AddNormalinputs(mtx, mypk, txfee, 4) >= txfee) { myfee = bettx.vout[1].nValue / 10; // fee for setting costbasis result.push_back(Pair("myfee", myfee)); mtx.vout.push_back(CTxOut(myfee, CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); - mtx.vout.push_back(MakeCC1vout(cp->evalcode, bettx.vout[1].nValue - myfee - txfee, pricespk)); + mtx.vout.push_back(MakeCC1vout(cp->evalcode, bettx.vout[1].nValue - myfee, pricespk)); rawtx = FinalizeCCTx(0, cp, mtx, mypk, txfee, prices_costbasisopret(bettxid, mypk, firstheight + PRICES_DAYWINDOW /*- 1*/, costbasis)); return(prices_rawtxresult(result, rawtx, 0)); } From e5905381dfc218d67244e7d080c09807f958bae5 Mon Sep 17 00:00:00 2001 From: dimxy Date: Wed, 17 Apr 2019 00:10:14 +0500 Subject: [PATCH 057/447] corr not cond --- src/cc/prices.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index b996348a4..16c85440d 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -271,7 +271,7 @@ bool PricesValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx for (auto vin : tx.vin) if (cp->ismyvin(vin.scriptSig)) { uint256 hashBlock; - if (myGetTransaction(vin.prevout.hash, vintx, hashBlock)) + if (!myGetTransaction(vin.prevout.hash, vintx, hashBlock)) return eval->Invalid("cannot load vin tx"); prevoutN = vin.prevout.n; ccVinCount++; From 1269c4d9d014e9deb9b4f73095b105c8929a1bde Mon Sep 17 00:00:00 2001 From: dimxy Date: Wed, 17 Apr 2019 00:24:24 +0500 Subject: [PATCH 058/447] corr CheckPricesOpret --- src/cc/prices.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 16c85440d..a027f6065 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -16,6 +16,8 @@ #include "CCassets.h" #include "CCPrices.h" +#define IS_CHARINSTR(c, str) (std::string(str).find((char)(c)) != std::string::npos) + /* CBOPRET creates trustless oracles, which can be used for making a synthetic cash settlement system based on real world prices; @@ -128,7 +130,8 @@ uint8_t prices_finalopretdecode(CScript scriptPubKey,uint256 &bettxid,int64_t &p bool CheckPricesOpret(const CTransaction & tx, vscript_t &opret) { - return (tx.vout.size() == 0 || !GetOpReturnData(tx.vout.back().scriptPubKey, opret) || opret.size() < 3 || opret.begin()[0] != EVAL_PRICES) || opret.begin()[1] == 0; + return !(tx.vout.size() < 1 || !GetOpReturnData(tx.vout.back().scriptPubKey, opret) || opret.size() < 3 || opret.begin()[0] != EVAL_PRICES || + IS_CHARINSTR(opret.begin()[1], "BACF")); } bool ValidateBetTx(struct CCcontract_info *cp, Eval *eval, const CTransaction & bettx) From 41cad58fe7a747e199a40f6edd73f93baca0ebda Mon Sep 17 00:00:00 2001 From: dimxy Date: Wed, 17 Apr 2019 00:30:00 +0500 Subject: [PATCH 059/447] yet CheckPriceOpret corr --- src/cc/prices.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index a027f6065..73a2ecd15 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -130,8 +130,7 @@ uint8_t prices_finalopretdecode(CScript scriptPubKey,uint256 &bettxid,int64_t &p bool CheckPricesOpret(const CTransaction & tx, vscript_t &opret) { - return !(tx.vout.size() < 1 || !GetOpReturnData(tx.vout.back().scriptPubKey, opret) || opret.size() < 3 || opret.begin()[0] != EVAL_PRICES || - IS_CHARINSTR(opret.begin()[1], "BACF")); + return tx.vout.size() > 0 && GetOpReturnData(tx.vout.back().scriptPubKey, opret) && opret.size() > 2 && opret.begin()[0] == EVAL_PRICES && IS_CHARINSTR(opret.begin()[1], "BACF"); } bool ValidateBetTx(struct CCcontract_info *cp, Eval *eval, const CTransaction & bettx) From aa728ec1a99c2e92b36a25fb3bcd3dfdee180032 Mon Sep 17 00:00:00 2001 From: dimxy Date: Wed, 17 Apr 2019 00:36:42 +0500 Subject: [PATCH 060/447] corr validate code op ! --- src/cc/prices.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 73a2ecd15..3477b1394 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -128,6 +128,7 @@ uint8_t prices_finalopretdecode(CScript scriptPubKey,uint256 &bettxid,int64_t &p return(0); } +// price opret basic validation and retrieval bool CheckPricesOpret(const CTransaction & tx, vscript_t &opret) { return tx.vout.size() > 0 && GetOpReturnData(tx.vout.back().scriptPubKey, opret) && opret.size() > 2 && opret.begin()[0] == EVAL_PRICES && IS_CHARINSTR(opret.begin()[1], "BACF"); @@ -260,7 +261,7 @@ bool PricesValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx vscript_t vopret; // check basic opret rules: - if (CheckPricesOpret(tx, vopret)) + if (!CheckPricesOpret(tx, vopret)) return eval->Invalid("tx has no prices opreturn"); uint8_t funcId = vopret.begin()[1]; From c427df8e9852c5dcd20b3297b136bdb25b76f853 Mon Sep 17 00:00:00 2001 From: dimxy Date: Wed, 17 Apr 2019 11:07:10 +0500 Subject: [PATCH 061/447] corr vout0 check costbasis --- src/cc/prices.cpp | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 3477b1394..600ef08a1 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -195,17 +195,17 @@ bool ValidateCostbasisTx(struct CCcontract_info *cp, Eval *eval, const CTransact // check basic structure: if (costbasistx.vout.size() < 3 || costbasistx.vout.size() > 4) - return eval->Invalid("incorrect vout number for add funding tx"); + return eval->Invalid("incorrect vout count for costbasis tx"); vscript_t opret; if (prices_costbasisopretdecode(costbasistx.vout.back().scriptPubKey, bettxid, pk, height, amount) != 'C') - return eval->Invalid("cannot decode opreturn for setcostbasis tx"); + return eval->Invalid("cannot decode opreturn for costbasis tx"); pricespk = GetUnspendable(cp, 0); - if (MakeCC1vout(cp->evalcode, costbasistx.vout[0].nValue, pk) != costbasistx.vout[0]) - return eval->Invalid("cannot validate vout0 in add funding tx with pk from opreturn"); + if (CTxOut(costbasistx.vout[0].nValue, CScript() << ParseHex(HexStr(pk)) << OP_CHECKSIG) != costbasistx.vout[0]) //might go to any pk who calculated costbasis + return eval->Invalid("cannot validate vout0 in costbasis tx with pk from opreturn"); if (MakeCC1vout(cp->evalcode, costbasistx.vout[1].nValue, pricespk) != costbasistx.vout[1]) - return eval->Invalid("cannot validate vout1 in add funding tx with global pk"); + return eval->Invalid("cannot validate vout1 in costbasis tx with global pk"); if (bettx.vout.size() < 1) // maybe this is already checked outside, but it is safe to check here too and have encapsulated check return eval->Invalid("incorrect bettx"); @@ -218,8 +218,9 @@ bool ValidateCostbasisTx(struct CCcontract_info *cp, Eval *eval, const CTransact int64_t positionsize, firstprice; int32_t firstheight; int16_t leverage; + CPubKey betpk; std::vector vec; - if (prices_betopretdecode(bettx.vout.back().scriptPubKey, pk, firstheight, positionsize, leverage, firstprice, vec, tokenid) != 'B') + if (prices_betopretdecode(bettx.vout.back().scriptPubKey, betpk, firstheight, positionsize, leverage, firstprice, vec, tokenid) != 'B') return eval->Invalid("cannot decode opreturn for bet tx"); if( firstheight + PRICES_DAYWINDOW + PRICES_SMOOTHWIDTH > chainActive.Height() ) @@ -270,7 +271,7 @@ bool PricesValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx vscript_t vintxOpret; int32_t ccVinCount = 0; int32_t prevoutN = 0; - // load vintx: + // load vintx (might be either bet or add funding tx): for (auto vin : tx.vin) if (cp->ismyvin(vin.scriptSig)) { uint256 hashBlock; @@ -651,6 +652,7 @@ void prices_betjson(UniValue &result,int64_t profits,int64_t costbasis,int64_t p result.push_back(Pair("firstprice",ValueFromAmount(firstprice))); } +// retrives costbasis from a tx spending bettx vout1 int64_t prices_costbasis(CTransaction bettx) { int64_t costbasis = 0; From 1eccfc7485b0e6f70179e26f9f9a70661e2bbda3 Mon Sep 17 00:00:00 2001 From: dimxy Date: Wed, 17 Apr 2019 15:20:35 +0500 Subject: [PATCH 062/447] corr errors after rebase added comments --- src/komodo_defs.h | 2 +- src/komodo_gateway.h | 3 ++- src/rpc/blockchain.cpp | 33 ++++++++++++++++++++------------- 3 files changed, 23 insertions(+), 15 deletions(-) diff --git a/src/komodo_defs.h b/src/komodo_defs.h index ee44132bc..94d7300aa 100644 --- a/src/komodo_defs.h +++ b/src/komodo_defs.h @@ -101,7 +101,7 @@ int32_t komodo_dpowconfs(int32_t height,int32_t numconfs); int8_t komodo_segid(int32_t nocache,int32_t height); int32_t komodo_heightpricebits(uint64_t *seedp,uint32_t *heightbits,int32_t nHeight); char *komodo_pricename(char *name,int32_t ind); -int32_t komodo_priceind(char *symbol); +int32_t komodo_priceind(const char *symbol); int32_t komodo_pricesinit(); int64_t komodo_priceave(int64_t *tmpbuf,int64_t *correlated,int32_t cskip); int64_t komodo_pricecorrelated(uint64_t seed,int32_t ind,uint32_t *rawprices,int32_t rawskip,uint32_t *nonzprices,int32_t smoothwidth); diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 3f1d5ec5e..5ce9d223f 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -2448,6 +2448,7 @@ int32_t komodo_priceind(const char *symbol) return(-1); } +// returns price value which is in a 10% interval for more than 50% points for the preceding 24 hours int64_t komodo_pricecorrelated(uint64_t seed,int32_t ind,uint32_t *rawprices,int32_t rawskip,uint32_t *nonzprices,int32_t smoothwidth) { int32_t i,j,k,n,iter,correlation,maxcorrelation=0; int64_t firstprice,price,sum,den,mult,refprice,lowprice,highprice; @@ -2486,7 +2487,7 @@ int64_t komodo_pricecorrelated(uint64_t seed,int32_t ind,uint32_t *rawprices,int //fprintf(stderr,"%.1f ",(double)price/10000); sum += price; correlation++; - if ( correlation > (PRICES_DAYWINDOW>>1) ) + if ( correlation > (PRICES_DAYWINDOW>>1) ) // if there are more than 50% raw price values lay within +/-5% interval from the refprice picked from random pos { if ( nonzprices == 0 ) return(refprice * mult); diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index 550355cff..26a7f6867 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -43,6 +43,9 @@ #include +#include "cc/CCinclude.h" +#include "cc/CCPrices.h" + using namespace std; extern void TxToJSON(const CTransaction& tx, const uint256 hashBlock, UniValue& entry); @@ -1165,7 +1168,7 @@ UniValue paxprice(const UniValue& params, bool fHelp) return(-1); for (i=0; i vexpr; @@ -1349,7 +1353,7 @@ UniValue pricesaddfunding(const UniValue& params, bool fHelp) { if (fHelp || params.size() != 2) throw runtime_error("pricesaddfunding bettxid amount\n" - "where amount is in satoshis\n"); + "where amount is in satoshis\n"); LOCK(cs_main); UniValue ret(UniValue::VOBJ); @@ -1358,11 +1362,11 @@ UniValue pricesaddfunding(const UniValue& params, bool fHelp) CAmount txfee = 10000; uint256 bettxid = Parseuint256(params[0].get_str().c_str()); - if( bettxid.IsNull() ) + if (bettxid.IsNull()) throw runtime_error("invalid bettxid\n"); CAmount amount = atoll(params[1].get_str().c_str()); - if( amount <= 0 ) + if (amount <= 0) throw runtime_error("invalid amount\n"); return PricesAddFunding(txfee, bettxid, amount); @@ -1380,7 +1384,7 @@ UniValue pricessetcostbasis(const UniValue& params, bool fHelp) throw JSONRPCError(RPC_INVALID_PARAMETER, "only -ac_cbopret chains have prices"); uint256 bettxid = Parseuint256(params[0].get_str().c_str()); - if( bettxid.IsNull() ) + if (bettxid.IsNull()) throw runtime_error("invalid bettxid\n"); int64_t txfee = 10000; @@ -1388,6 +1392,7 @@ UniValue pricessetcostbasis(const UniValue& params, bool fHelp) return PricesSetcostbasis(txfee, bettxid); } +// pricescashout rpc implementation UniValue pricescashout(const UniValue& params, bool fHelp) { if (fHelp || params.size() != 1) @@ -1407,6 +1412,7 @@ UniValue pricescashout(const UniValue& params, bool fHelp) return PricesCashout(txfee, bettxid); } +// pricesrekt rpc implementation UniValue pricesrekt(const UniValue& params, bool fHelp) { if (fHelp || params.size() != 2) @@ -1428,6 +1434,7 @@ UniValue pricesrekt(const UniValue& params, bool fHelp) return PricesRekt(txfee, bettxid, height); } + UniValue gettxout(const UniValue& params, bool fHelp) { if (fHelp || params.size() < 2 || params.size() > 3) @@ -2057,4 +2064,4 @@ void RegisterBlockchainRPCCommands(CRPCTable &tableRPC) { for (unsigned int vcidx = 0; vcidx < ARRAYLEN(commands); vcidx++) tableRPC.appendCommand(commands[vcidx].name, &commands[vcidx]); -} +} \ No newline at end of file From e66d51a261ffde9610a6e20c2cb1fcc0c320c0f3 Mon Sep 17 00:00:00 2001 From: dimxy Date: Wed, 17 Apr 2019 15:55:15 +0500 Subject: [PATCH 063/447] komodo_gateway.h back into fsm state plus some comments --- src/komodo_gateway.h | 58 ++++++++---------------------------------- src/rpc/blockchain.cpp | 4 +-- 2 files changed, 12 insertions(+), 50 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 5ce9d223f..0ae1b6b44 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -16,23 +16,6 @@ // paxdeposit equivalent in reverse makes opreturn and KMD does the same in reverse #include "komodo_defs.h" -#ifdef _WIN32 -#ifdef _MSC_VER -#define sleep(x) Sleep(1000*(x)) -#endif -#endif - -#ifdef _WIN32 -#ifdef _MSC_VER -void usleep(int32_t micros) -{ - if (micros < 1000) - Sleep(1); - else Sleep(micros / 1000); -} -#endif -#endif - /*#include "secp256k1/include/secp256k1.h" #include "secp256k1/include/secp256k1_schnorrsig.h" #include "secp256k1/include/secp256k1_musig.h" @@ -2071,13 +2054,10 @@ int32_t get_stockprices(uint32_t now,uint32_t *prices,std::vector s uint32_t get_dailyfx(uint32_t *prices) { //{"base":"USD","rates":{"BGN":1.74344803,"NZD":1.471652701,"ILS":3.6329113924,"RUB":65.1997682296,"CAD":1.3430201462,"USD":1.0,"PHP":52.8641469068,"CHF":0.9970582992,"AUD":1.4129078267,"JPY":110.6792654662,"TRY":5.6523444464,"HKD":7.8499732573,"MYR":4.0824567659,"HRK":6.6232840078,"CZK":22.9862720628,"IDR":14267.4986628633,"DKK":6.6551078624,"NOK":8.6806917454,"HUF":285.131039401,"GBP":0.7626582278,"MXN":19.4183455161,"THB":31.8702085933,"ISK":122.5708682475,"ZAR":14.7033339276,"BRL":3.9750401141,"SGD":1.3573720806,"PLN":3.8286682118,"INR":69.33187734,"KRW":1139.1602781244,"RON":4.2423783206,"CNY":6.7387234801,"SEK":9.3385630237,"EUR":0.8914244963},"date":"2019-03-28"} - char url[512],*datestr; cJSON *json,*rates; int32_t i; uint32_t datenum=0,price = 0; - sprintf(url,"https://api.openrates.io/latest?base=USD"); if ( (json= get_urljson(url)) != 0 ) //if ( (json= send_curl(url,(char *)"dailyfx")) != 0 ) { - std::cerr << "Forex USD rates:" << std::endl; if ( (rates= jobj(json,(char *)"rates")) != 0 ) { for (i=0; i strvec) { int32_t i,errs=0; uint32_t price; char *symbol; - std::cerr << "Crypto binance BTC rates:" << std::endl; - for (i=0; i= PRICES_DAYWINDOW ) @@ -2487,11 +2451,11 @@ int64_t komodo_pricecorrelated(uint64_t seed,int32_t ind,uint32_t *rawprices,int //fprintf(stderr,"%.1f ",(double)price/10000); sum += price; correlation++; - if ( correlation > (PRICES_DAYWINDOW>>1) ) // if there are more than 50% raw price values lay within +/-5% interval from the refprice picked from random pos + if ( correlation > (PRICES_DAYWINDOW>>1) ) { if ( nonzprices == 0 ) return(refprice * mult); - fprintf(stderr,"-> %.4f\n",(double)sum*mult/correlation); + //fprintf(stderr,"-> %.4f\n",(double)sum*mult/correlation); //return(sum*mult/correlation); n = 0; i = (iter + seed) % PRICES_DAYWINDOW; @@ -2509,12 +2473,12 @@ int64_t komodo_pricecorrelated(uint64_t seed,int32_t ind,uint32_t *rawprices,int else { nonzprices[i] = price; - fprintf(stderr,"(%d %u) ",i,rawprices[i*rawskip]); + //fprintf(stderr,"(%d %u) ",i,rawprices[i*rawskip]); n++; } } } - fprintf(stderr,"ind.%d iter.%d j.%d i.%d n.%d correlation.%d ref %llu -> %llu\n",ind,iter,j,i,n,correlation,(long long)refprice,(long long)sum/correlation); + //fprintf(stderr,"ind.%d iter.%d j.%d i.%d n.%d correlation.%d ref %llu -> %llu\n",ind,iter,j,i,n,correlation,(long long)refprice,(long long)sum/correlation); if ( n != correlation ) return(-1); sum = den = n = 0; @@ -2537,8 +2501,7 @@ int64_t komodo_pricecorrelated(uint64_t seed,int32_t ind,uint32_t *rawprices,int fprintf(stderr,"seed.%llu n.%d vs correlation.%d sum %llu, den %llu\n",(long long)seed,n,correlation,(long long)sum,(long long)den); return(-1); } - std::cerr << "sum=" << sum << " mult=" << mult << " den=" << den << std::endl; - fprintf(stderr,"firstprice.%llu weighted -> %.8f\n",(long long)firstprice,((double)(sum*mult) / den) / COIN); + //fprintf(stderr,"firstprice.%llu weighted -> %.8f\n",(long long)firstprice,((double)(sum*mult) / den) / COIN); return((sum * mult) / den); } } @@ -2838,4 +2801,3 @@ int32_t komodo_priceget(int64_t *buf64,int32_t ind,int32_t height,int32_t numblo pthread_mutex_unlock(&pricemutex); return(retval); } - diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index 26a7f6867..afb81e706 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -1158,11 +1158,11 @@ UniValue paxprice(const UniValue& params, bool fHelp) } return ret; } - +// fills pricedata with raw price, correlated and smoothed values for numblock /*int32_t prices_extract(int64_t *pricedata,int32_t firstheight,int32_t numblocks,int32_t ind) { int32_t height,i,n,width,numpricefeeds = -1; uint64_t seed,ignore,rngval; uint32_t rawprices[1440*6],*ptr; int64_t *tmpbuf; - width = numblocks+PRICES_DAYWINDOW*2+PRICES_SMOOTHWIDTH; + width = numblocks+PRICES_DAYWINDOW*2+PRICES_SMOOTHWIDTH; // need 2*PRICES_DAYWINDOW previous raw price points to calc PRICES_DAYWINDOW correlated points to calc, in turn, smoothed point komodo_heightpricebits(&seed,rawprices,firstheight + numblocks - 1); if ( firstheight < width ) return(-1); From 6a1d7d5bbe27364dab39b27bd78257abd27dc9a8 Mon Sep 17 00:00:00 2001 From: dimxy Date: Wed, 17 Apr 2019 19:34:56 +0500 Subject: [PATCH 064/447] komodo_defs.h reset --- src/komodo_defs.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_defs.h b/src/komodo_defs.h index 94d7300aa..c42c725f8 100644 --- a/src/komodo_defs.h +++ b/src/komodo_defs.h @@ -101,7 +101,7 @@ int32_t komodo_dpowconfs(int32_t height,int32_t numconfs); int8_t komodo_segid(int32_t nocache,int32_t height); int32_t komodo_heightpricebits(uint64_t *seedp,uint32_t *heightbits,int32_t nHeight); char *komodo_pricename(char *name,int32_t ind); -int32_t komodo_priceind(const char *symbol); +int32_t komodo_priceind(char *symbol); int32_t komodo_pricesinit(); int64_t komodo_priceave(int64_t *tmpbuf,int64_t *correlated,int32_t cskip); int64_t komodo_pricecorrelated(uint64_t seed,int32_t ind,uint32_t *rawprices,int32_t rawskip,uint32_t *nonzprices,int32_t smoothwidth); @@ -112,4 +112,4 @@ int32_t komodo_priceget(int64_t *buf64,int32_t ind,int32_t height,int32_t numblo uint64_t komodo_accrued_interest(int32_t *txheightp,uint32_t *locktimep,uint256 hash,int32_t n,int32_t checkheight,uint64_t checkvalue,int32_t tipheight); -#endif +#endif \ No newline at end of file From c99acae5fa58b02f7ad945d3fca29aa7753f7f7a Mon Sep 17 00:00:00 2001 From: dimxy Date: Wed, 17 Apr 2019 19:55:30 +0500 Subject: [PATCH 065/447] switched to komodo_pricesget --- src/cc/prices.cpp | 2 +- src/komodo_defs.h | 2 +- src/komodo_gateway.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 600ef08a1..e9265c51a 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -472,7 +472,7 @@ int64_t prices_syntheticprice(std::vector vec, int32_t height, int32_t { case 0: // indices pricestack[depth] = 0; - if (prices_extract(pricedata, height, 1, value) == 0) + if (komodo_priceget(pricedata, height, 1, value) == 0) { // push price to the prices stack if (!minmax) diff --git a/src/komodo_defs.h b/src/komodo_defs.h index c42c725f8..2fcd29df3 100644 --- a/src/komodo_defs.h +++ b/src/komodo_defs.h @@ -101,7 +101,7 @@ int32_t komodo_dpowconfs(int32_t height,int32_t numconfs); int8_t komodo_segid(int32_t nocache,int32_t height); int32_t komodo_heightpricebits(uint64_t *seedp,uint32_t *heightbits,int32_t nHeight); char *komodo_pricename(char *name,int32_t ind); -int32_t komodo_priceind(char *symbol); +int32_t komodo_priceind(const char *symbol); int32_t komodo_pricesinit(); int64_t komodo_priceave(int64_t *tmpbuf,int64_t *correlated,int32_t cskip); int64_t komodo_pricecorrelated(uint64_t seed,int32_t ind,uint32_t *rawprices,int32_t rawskip,uint32_t *nonzprices,int32_t smoothwidth); diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 0ae1b6b44..1fafcc856 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -2401,7 +2401,7 @@ char *komodo_pricename(char *name,int32_t ind) return(0); } // finds index for its symbol name -int32_t komodo_priceind(char *symbol) +int32_t komodo_priceind(const char *symbol) { char name[65]; int32_t i,n = (int32_t)(komodo_cbopretsize(ASSETCHAINS_CBOPRET) / sizeof(uint32_t)); for (i=1; i Date: Wed, 17 Apr 2019 21:02:32 +0500 Subject: [PATCH 066/447] ccflag = false --- src/cc/prices.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index e9265c51a..56f357257 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -1035,11 +1035,10 @@ UniValue PricesList() CPubKey pk, pricespk; std::vector vec; CTransaction vintx; - char str[65]; cp = CCinit(&C, EVAL_PRICES); pricespk = GetUnspendable(cp, 0); - SetCCtxids(addressIndex, cp->normaladdr); + SetCCtxids(addressIndex, cp->normaladdr, false); for (std::vector >::const_iterator it = addressIndex.begin(); it != addressIndex.end(); it++) { txid = it->first.txhash; @@ -1047,7 +1046,7 @@ UniValue PricesList() { if (vintx.vout.size() > 0 && prices_betopretdecode(vintx.vout[vintx.vout.size() - 1].scriptPubKey, pk, height, amount, leverage, firstprice, vec, tokenid) == 'B') { - result.push_back(uint256_str(str, txid)); + result.push_back(txid.GetHex()); } } } From 8a46a75d0ea7d80e6e3f73d737db653947851706 Mon Sep 17 00:00:00 2001 From: dimxy Date: Wed, 17 Apr 2019 21:59:25 +0500 Subject: [PATCH 067/447] skip till 2100 --- src/cc/prices.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 56f357257..6331f1bec 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -261,6 +261,9 @@ bool PricesValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx { vscript_t vopret; + + if (strcmp(ASSETCHAINS_SYMBOL, "REKT0") == 0 && chainActive.Height() < 2100) + return true; // check basic opret rules: if (!CheckPricesOpret(tx, vopret)) return eval->Invalid("tx has no prices opreturn"); From a80dd2763e9191fdf0ea933e6fc16bf8315fcb3c Mon Sep 17 00:00:00 2001 From: dimxy Date: Thu, 18 Apr 2019 21:17:29 +0500 Subject: [PATCH 068/447] 1of2 change to 1 for bettx --- src/cc/prices.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 6331f1bec..a800e9c23 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -156,7 +156,7 @@ bool ValidateBetTx(struct CCcontract_info *cp, Eval *eval, const CTransaction & return eval->Invalid("cannot validate vout0 in bet tx with pk from opreturn"); if (MakeCC1vout(cp->evalcode, bettx.vout[1].nValue, pricespk) != bettx.vout[1]) return eval->Invalid("cannot validate vout1 in bet tx with global pk"); - if( MakeCC1of2vout(cp->evalcode, bettx.vout[2].nValue, pk, pricespk) != bettx.vout[2] ) + if( MakeCC1vout(cp->evalcode, bettx.vout[2].nValue, pricespk) != bettx.vout[2] ) return eval->Invalid("cannot validate 1of2 vout2 in bet tx with pk from opreturn"); return true; @@ -323,7 +323,7 @@ bool PricesValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx if (prevoutN != 1) { // check spending rules return eval->Invalid("incorrect vout to spend"); } - return eval->Invalid("test: costbasis is good"); + //return eval->Invalid("test: costbasis is good"); break; case 'F': // final tx @@ -758,7 +758,7 @@ UniValue PricesBet(int64_t txfee, int64_t amount, int16_t leverage, std::vector< betamount = (amount * 199) / 200; mtx.vout.push_back(MakeCC1vout(cp->evalcode, txfee, mypk)); // vout0 baton for total funding mtx.vout.push_back(MakeCC1vout(cp->evalcode, (amount - betamount) + 2 * txfee, pricespk)); // vout1, when spent, costbasis is set - mtx.vout.push_back(MakeCC1of2vout(cp->evalcode, betamount, pricespk, mypk)); + mtx.vout.push_back(MakeCC1vout(cp->evalcode, betamount, pricespk)); mtx.vout.push_back(CTxOut(txfee, CScript() << ParseHex(HexStr(pricespk)) << OP_CHECKSIG)); // marker rawtx = FinalizeCCTx(0, cp, mtx, mypk, txfee, prices_betopret(mypk, nextheight - 1, amount, leverage, firstprice, vec, zeroid)); return(prices_rawtxresult(result, rawtx, 0)); From f6a0ede3868260f0670c9cb7bffa0a21d871a01a Mon Sep 17 00:00:00 2001 From: dimxy Date: Thu, 18 Apr 2019 21:44:46 +0500 Subject: [PATCH 069/447] corr priceget params --- src/cc/prices.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index a800e9c23..92500e6c0 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -475,7 +475,7 @@ int64_t prices_syntheticprice(std::vector vec, int32_t height, int32_t { case 0: // indices pricestack[depth] = 0; - if (komodo_priceget(pricedata, height, 1, value) == 0) + if (komodo_priceget(pricedata, value, height, 1) == 0) { // push price to the prices stack if (!minmax) From 26724cae9038ff17a0f487205370ebb28bb2136e Mon Sep 17 00:00:00 2001 From: dimxy Date: Thu, 18 Apr 2019 21:53:53 +0500 Subject: [PATCH 070/447] pricesget ret check corr --- src/cc/prices.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 92500e6c0..91d3ad1b0 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -437,7 +437,7 @@ int32_t prices_syntheticvec(std::vector &vec, std::vector return(-3); } depth -= need; - std::cerr << "opcode=" << opcode << " opstr=" << opstr << " need=" << need << " depth-=need=" << depth << std::endl; + std::cerr << "opcode=" << opcode << " opstr=" << opstr << " need=" << need << " depth=" << depth << std::endl; if ((opcode & KOMODO_PRICEMASK) != PRICES_WEIGHT) { // skip weight depth++; // increase operands count std::cerr << "depth++=" << depth << std::endl; @@ -475,7 +475,7 @@ int64_t prices_syntheticprice(std::vector vec, int32_t height, int32_t { case 0: // indices pricestack[depth] = 0; - if (komodo_priceget(pricedata, value, height, 1) == 0) + if (komodo_priceget(pricedata, value, height, 1) >= 0) { // push price to the prices stack if (!minmax) From a031847df53cc5fcb3d7211369fe7d5537329c60 Mon Sep 17 00:00:00 2001 From: dimxy Date: Fri, 19 Apr 2019 01:08:02 +0500 Subject: [PATCH 071/447] leverage check 0 coin as double --- src/rpc/blockchain.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index afb81e706..fefec1337 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -1324,7 +1324,10 @@ UniValue prices(const UniValue& params, bool fHelp) UniValue pricesbet(const UniValue& params, bool fHelp) { if (fHelp || params.size() != 3) - throw runtime_error("pricesbet amount leverage \"synthetic-expression\"\n"); + throw runtime_error("pricesbet amount leverage \"synthetic-expression\"\n" + "amount is in coins\n" + "leverage is integer non-zero value, positive for long, negative for short position\n" + "synthetic-expression example \"BTC_USD, 1\"\n"); LOCK(cs_main); UniValue ret(UniValue::VOBJ); @@ -1332,8 +1335,10 @@ UniValue pricesbet(const UniValue& params, bool fHelp) throw JSONRPCError(RPC_INVALID_PARAMETER, "only -ac_cbopret chains have prices"); CAmount txfee = 10000; - CAmount amount = atoll(params[0].get_str().c_str()); + CAmount amount = atof(params[0].get_str().c_str()) * COIN; int16_t leverage = (int16_t)atoi(params[1].get_str().c_str()); + if (leverage == 0) + throw runtime_error("invalid leverage\n"); std::string sexpr = params[2].get_str(); std::vector vexpr; From acd979ea067bdc414e2ae3632c2fa0a6589c905e Mon Sep 17 00:00:00 2001 From: dimxy Date: Fri, 19 Apr 2019 01:16:12 +0500 Subject: [PATCH 072/447] set costbasis before 24 as temp show it txid --- src/cc/prices.cpp | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 91d3ad1b0..60b8dff51 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -656,14 +656,15 @@ void prices_betjson(UniValue &result,int64_t profits,int64_t costbasis,int64_t p } // retrives costbasis from a tx spending bettx vout1 -int64_t prices_costbasis(CTransaction bettx) +int64_t prices_costbasis(CTransaction bettx, uint256 &txidCostbasis) { int64_t costbasis = 0; // if vout1 is spent, follow and extract costbasis from opreturn //uint8_t prices_costbasisopretdecode(CScript scriptPubKey,uint256 &bettxid,CPubKey &pk,int32_t &height,int64_t &costbasis) - uint256 txidCostbasis; + //uint256 txidCostbasis; int32_t vini; int32_t height; + txidCostbasis = zeroid; if (CCgetspenttxid(txidCostbasis, vini, height, bettx.GetHash(), 1) < 0) { std::cerr << "prices_costbasis() no costbasis txid found" << std::endl; @@ -886,7 +887,8 @@ UniValue PricesRekt(int64_t txfee, uint256 bettxid, int32_t rektheight) { if (prices_betopretdecode(bettx.vout[numvouts - 1].scriptPubKey, pk, firstheight, positionsize, leverage, firstprice, vec, tokenid) == 'B') { - costbasis = prices_costbasis(bettx); + uint256 costbasistxid; + costbasis = prices_costbasis(bettx, costbasistxid); if (costbasis == 0) { result.push_back(Pair("result", "error")); result.push_back(Pair("error", "costbasis not defined yet")); @@ -951,7 +953,9 @@ UniValue PricesCashout(int64_t txfee, uint256 bettxid) { if (prices_betopretdecode(bettx.vout[numvouts - 1].scriptPubKey, pk, firstheight, positionsize, leverage, firstprice, vec, tokenid) == 'B') { - costbasis = prices_costbasis(bettx); + uint256 costbasistxid; + + costbasis = prices_costbasis(bettx, costbasistxid); if (costbasis == 0) { result.push_back(Pair("result", "error")); result.push_back(Pair("error", "costbasis not defined yet")); @@ -997,6 +1001,7 @@ UniValue PricesInfo(uint256 bettxid, int32_t refheight) std::vector vec; CPubKey pk, mypk, pricespk; std::string rawtx; + uint256 costbasistxid; if (myGetTransaction(bettxid, bettx, hashBlock) != 0 && (numvouts = bettx.vout.size()) > 3) { @@ -1010,9 +1015,9 @@ UniValue PricesInfo(uint256 bettxid, int32_t refheight) if (refheight == 0) refheight = komodo_nextheight()-1; - costbasis = prices_costbasis(bettx); + costbasis = prices_costbasis(bettx, costbasistxid); addedbets = prices_batontxid(batontxid, bettx, bettxid); - if ((profits = prices_syntheticprofits(false, costbasis, firstheight, refheight, leverage, vec, positionsize, addedbets)) < 0) + if ((profits = prices_syntheticprofits(true, costbasis, firstheight, refheight, leverage, vec, positionsize, addedbets)) < 0) { result.push_back(Pair("rekt", 1)); result.push_back(Pair("rektfee", (positionsize + addedbets) / 500)); @@ -1020,6 +1025,8 @@ UniValue PricesInfo(uint256 bettxid, int32_t refheight) else result.push_back(Pair("rekt", 0)); result.push_back(Pair("batontxid", batontxid.GetHex())); + if(!costbasistxid.IsNull()) + result.push_back(Pair("costbasistxid", costbasistxid.GetHex())); prices_betjson(result, profits, costbasis, positionsize, addedbets, leverage, firstheight, firstprice); result.push_back(Pair("height", (int64_t)refheight)); return(result); From 771273f195b94869eef5c918350710c34ad78ab2 Mon Sep 17 00:00:00 2001 From: dimxy Date: Fri, 19 Apr 2019 01:29:55 +0500 Subject: [PATCH 073/447] costbasis logging --- src/cc/prices.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 60b8dff51..26bc5b403 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -628,14 +628,22 @@ int64_t prices_syntheticprofits(bool calcCostbasis, int64_t &costbasis, int32_t } if (calcCostbasis) { if (minmax) { // if we are within day window, set costbasis to max or min price value - if (leverage > 0 && price > costbasis) + if (leverage > 0 && price > costbasis) { costbasis = price; // set costbasis - else if (leverage < 0 && (costbasis == 0 || price < costbasis)) + std::cerr << "prices_syntheticprofits() minmax costbasis=" << costbasis << " price=" << price << std::endl; + } + else if (leverage < 0 && (costbasis == 0 || price < costbasis)) { costbasis = price; - // else -> use the previous value + std::cerr << "prices_syntheticprofits() minmax costbasis=" << costbasis << " price=" << price << std::endl; + } + else { //-> use the previous value + std::cerr << "prices_syntheticprofits() unchanged costbasis=" << costbasis << " price=" << price << std::endl; + } + } else { costbasis = price; // smoothed value + std::cerr << "prices_syntheticprofits() smoothed costbasis=" << costbasis << " price=" << price << std::endl; } } From d7565e75b252b1e6fda0676a2401eb446fc65edb Mon Sep 17 00:00:00 2001 From: dimxy Date: Fri, 19 Apr 2019 01:36:26 +0500 Subject: [PATCH 074/447] lev log --- src/cc/prices.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 26bc5b403..7228e478b 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -637,7 +637,7 @@ int64_t prices_syntheticprofits(bool calcCostbasis, int64_t &costbasis, int32_t std::cerr << "prices_syntheticprofits() minmax costbasis=" << costbasis << " price=" << price << std::endl; } else { //-> use the previous value - std::cerr << "prices_syntheticprofits() unchanged costbasis=" << costbasis << " price=" << price << std::endl; + std::cerr << "prices_syntheticprofits() unchanged costbasis=" << costbasis << " price=" << price << " leverage=" << leverage << std::endl; } } @@ -1025,6 +1025,7 @@ UniValue PricesInfo(uint256 bettxid, int32_t refheight) costbasis = prices_costbasis(bettx, costbasistxid); addedbets = prices_batontxid(batontxid, bettx, bettxid); + bool calcCostbasis = costbasis == 0 ? true : false; if ((profits = prices_syntheticprofits(true, costbasis, firstheight, refheight, leverage, vec, positionsize, addedbets)) < 0) { result.push_back(Pair("rekt", 1)); From 24a35a4bb05574527aee0fc6b5fd402f8858018b Mon Sep 17 00:00:00 2001 From: dimxy Date: Fri, 19 Apr 2019 01:44:31 +0500 Subject: [PATCH 075/447] more lev log --- src/cc/prices.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 7228e478b..b07ba4551 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -60,6 +60,7 @@ CScript prices_betopret(CPubKey mypk,int32_t height,int64_t amount,int16_t lever { CScript opret; opret << OP_RETURN << E_MARSHAL(ss << EVAL_PRICES << 'B' << mypk << height << amount << leverage << firstprice << vec << tokenid); + std::cerr << "prices_betopret() leverage=" << leverage << std::endl; return(opret); } @@ -69,6 +70,7 @@ uint8_t prices_betopretdecode(CScript scriptPubKey,CPubKey &pk,int32_t &height,i GetOpReturnData(scriptPubKey,vopret); if ( vopret.size() > 2 && E_UNMARSHAL(vopret,ss >> e; ss >> f; ss >> pk; ss >> height; ss >> amount; ss >> leverage; ss >> firstprice; ss >> vec; ss >> tokenid) != 0 && e == EVAL_PRICES && f == 'B' ) { + std::cerr << "prices_betopretdecode() leverage=" << leverage << std::endl; return(f); } return(0); From 7e312afc9e83da472569719c5aeaf3211652cde0 Mon Sep 17 00:00:00 2001 From: dimxy Date: Fri, 19 Apr 2019 02:18:00 +0500 Subject: [PATCH 076/447] char ptrs --- src/cc/prices.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index b07ba4551..31e316c6d 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -67,9 +67,13 @@ CScript prices_betopret(CPubKey mypk,int32_t height,int64_t amount,int16_t lever uint8_t prices_betopretdecode(CScript scriptPubKey,CPubKey &pk,int32_t &height,int64_t &amount,int16_t &leverage,int64_t &firstprice,std::vector &vec,uint256 &tokenid) { std::vector vopret; uint8_t e,f; + unsigned char u, l; GetOpReturnData(scriptPubKey,vopret); - if ( vopret.size() > 2 && E_UNMARSHAL(vopret,ss >> e; ss >> f; ss >> pk; ss >> height; ss >> amount; ss >> leverage; ss >> firstprice; ss >> vec; ss >> tokenid) != 0 && e == EVAL_PRICES && f == 'B' ) + if (vopret.size() > 2 && E_UNMARSHAL(vopret, ss >> e; ss >> f; ss >> pk; ss >> height; ss >> amount; ss >> l; ss >> u; ss >> firstprice; ss >> vec; ss >> tokenid) != 0 && e == EVAL_PRICES && f == 'B') { + unsigned char *p = (unsigned char*)&leverage; + *p = l; + *(p + 1) = u; std::cerr << "prices_betopretdecode() leverage=" << leverage << std::endl; return(f); } From f0f091ba0a5e73bcea28737cd05ffe3b2c9b48ee Mon Sep 17 00:00:00 2001 From: dimxy Date: Fri, 19 Apr 2019 02:31:07 +0500 Subject: [PATCH 077/447] lev deser restored --- src/cc/prices.cpp | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 31e316c6d..42559fd9d 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -60,21 +60,16 @@ CScript prices_betopret(CPubKey mypk,int32_t height,int64_t amount,int16_t lever { CScript opret; opret << OP_RETURN << E_MARSHAL(ss << EVAL_PRICES << 'B' << mypk << height << amount << leverage << firstprice << vec << tokenid); - std::cerr << "prices_betopret() leverage=" << leverage << std::endl; return(opret); } uint8_t prices_betopretdecode(CScript scriptPubKey,CPubKey &pk,int32_t &height,int64_t &amount,int16_t &leverage,int64_t &firstprice,std::vector &vec,uint256 &tokenid) { std::vector vopret; uint8_t e,f; - unsigned char u, l; + GetOpReturnData(scriptPubKey,vopret); - if (vopret.size() > 2 && E_UNMARSHAL(vopret, ss >> e; ss >> f; ss >> pk; ss >> height; ss >> amount; ss >> l; ss >> u; ss >> firstprice; ss >> vec; ss >> tokenid) != 0 && e == EVAL_PRICES && f == 'B') + if (vopret.size() > 2 && E_UNMARSHAL(vopret, ss >> e; ss >> f; ss >> pk; ss >> height; ss >> amount; ss >> leverage; ss >> firstprice; ss >> vec; ss >> tokenid) != 0 && e == EVAL_PRICES && f == 'B') { - unsigned char *p = (unsigned char*)&leverage; - *p = l; - *(p + 1) = u; - std::cerr << "prices_betopretdecode() leverage=" << leverage << std::endl; return(f); } return(0); From d3dbbacaefc24cbd66fa649d39a82aaf8343022a Mon Sep 17 00:00:00 2001 From: dimxy Date: Fri, 19 Apr 2019 02:33:52 +0500 Subject: [PATCH 078/447] set calcCostbasis for temp --- src/cc/prices.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 42559fd9d..96042b076 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -1027,7 +1027,7 @@ UniValue PricesInfo(uint256 bettxid, int32_t refheight) costbasis = prices_costbasis(bettx, costbasistxid); addedbets = prices_batontxid(batontxid, bettx, bettxid); bool calcCostbasis = costbasis == 0 ? true : false; - if ((profits = prices_syntheticprofits(true, costbasis, firstheight, refheight, leverage, vec, positionsize, addedbets)) < 0) + if ((profits = prices_syntheticprofits(calcCostbasis, costbasis, firstheight, refheight, leverage, vec, positionsize, addedbets)) < 0) { result.push_back(Pair("rekt", 1)); result.push_back(Pair("rektfee", (positionsize + addedbets) / 500)); From 9642776c0a1ea44d3a54cdf7d20de7fa78d97aa7 Mon Sep 17 00:00:00 2001 From: dimxy Date: Fri, 19 Apr 2019 02:47:51 +0500 Subject: [PATCH 079/447] profits log --- src/cc/prices.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 96042b076..e1c64782c 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -649,7 +649,10 @@ int64_t prices_syntheticprofits(bool calcCostbasis, int64_t &costbasis, int32_t } profits = costbasis > 0 ? ((price * SATOSHIDEN) / costbasis) - SATOSHIDEN : 0; + std::cerr << "prices_syntheticprofits() profits1=" << profits << std::endl; profits *= leverage * positionsize; + std::cerr << "prices_syntheticprofits() profits2=" << profits << std::endl; + return(positionsize + addedbets + profits); } From 5fa528c0ab5b7a192f9c3ac2e3d9c151da42c9ae Mon Sep 17 00:00:00 2001 From: dimxy Date: Fri, 19 Apr 2019 03:00:16 +0500 Subject: [PATCH 080/447] try double profits --- src/cc/prices.cpp | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index e1c64782c..4579371fc 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -649,11 +649,20 @@ int64_t prices_syntheticprofits(bool calcCostbasis, int64_t &costbasis, int32_t } profits = costbasis > 0 ? ((price * SATOSHIDEN) / costbasis) - SATOSHIDEN : 0; - std::cerr << "prices_syntheticprofits() profits1=" << profits << std::endl; - profits *= leverage * positionsize; - std::cerr << "prices_syntheticprofits() profits2=" << profits << std::endl; + std::cerr << "prices_syntheticprofits() (price * SATOSHIDEN)=" << (price * SATOSHIDEN) << std::endl; + std::cerr << "prices_syntheticprofits() (price * SATOSHIDEN)/costbasis=" << (price * SATOSHIDEN)/costbasis << std::endl; - return(positionsize + addedbets + profits); + std::cerr << "prices_syntheticprofits() profits1=" << profits << std::endl; + std::cerr << "prices_syntheticprofits() profits double=" << (double)price / (double)costbasis -1.0 << std::endl; + double dprofits = (double)price / (double)costbasis - 1.0; + + profits *= leverage * positionsize; + dprofits *= leverage * positionsize; + std::cerr << "prices_syntheticprofits() profits2=" << profits << std::endl; + std::cerr << "prices_syntheticprofits() dprofits=" << dprofits << std::endl; + + + return(positionsize + addedbets + dprofits); } void prices_betjson(UniValue &result,int64_t profits,int64_t costbasis,int64_t positionsize,int64_t addedbets,int16_t leverage,int32_t firstheight,int64_t firstprice) From 3d2c1ea5e062c92f3b578693d10cd68091e58774 Mon Sep 17 00:00:00 2001 From: dimxy Date: Fri, 19 Apr 2019 03:15:55 +0500 Subject: [PATCH 081/447] calc costbasis for firstheight --- src/cc/prices.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 4579371fc..bcd9ee497 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -1038,8 +1038,13 @@ UniValue PricesInfo(uint256 bettxid, int32_t refheight) costbasis = prices_costbasis(bettx, costbasistxid); addedbets = prices_batontxid(batontxid, bettx, bettxid); - bool calcCostbasis = costbasis == 0 ? true : false; - if ((profits = prices_syntheticprofits(calcCostbasis, costbasis, firstheight, refheight, leverage, vec, positionsize, addedbets)) < 0) + if( costbasis == 0 && prices_syntheticprofits(true, costbasis, firstheight, firstheight, leverage, vec, positionsize, addedbets) < 0) { + result.push_back(Pair("result", "error")); + result.push_back(Pair("error", "cannot calculate costbasis")); + return(result); + } + + if ((profits = prices_syntheticprofits(false, costbasis, firstheight, refheight, leverage, vec, positionsize, addedbets)) < 0) { result.push_back(Pair("rekt", 1)); result.push_back(Pair("rektfee", (positionsize + addedbets) / 500)); From d36e8227d0e74c6442e0892e9b7fc636a1c8a4b7 Mon Sep 17 00:00:00 2001 From: dimxy Date: Fri, 19 Apr 2019 12:26:20 +0500 Subject: [PATCH 082/447] corr costbasis & profits calc added json params --- src/cc/prices.cpp | 105 ++++++++++++++++++++++++++-------------------- 1 file changed, 60 insertions(+), 45 deletions(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index bcd9ee497..483e48937 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -611,9 +611,9 @@ int64_t prices_syntheticprice(std::vector vec, int32_t height, int32_t } // calculates profit/loss for the bet -int64_t prices_syntheticprofits(bool calcCostbasis, int64_t &costbasis, int32_t firstheight, int32_t height, int16_t leverage, std::vector vec, int64_t positionsize, int64_t addedbets) +int64_t prices_syntheticprofits(int64_t &costbasis, int32_t firstheight, int32_t height, int16_t leverage, std::vector vec, int64_t positionsize, int64_t addedbets, int64_t &price) { - int64_t price, profits = 0; + int64_t profits = 0; if (height < firstheight) { fprintf(stderr, "requested height is lower than bet firstheight.%d\n", height); @@ -627,53 +627,57 @@ int64_t prices_syntheticprofits(bool calcCostbasis, int64_t &costbasis, int32_t fprintf(stderr, "unexpected zero synthetic price at height.%d\n", height); return(0); } - if (calcCostbasis) { - if (minmax) { // if we are within day window, set costbasis to max or min price value - if (leverage > 0 && price > costbasis) { - costbasis = price; // set costbasis - std::cerr << "prices_syntheticprofits() minmax costbasis=" << costbasis << " price=" << price << std::endl; - } - else if (leverage < 0 && (costbasis == 0 || price < costbasis)) { - costbasis = price; - std::cerr << "prices_syntheticprofits() minmax costbasis=" << costbasis << " price=" << price << std::endl; - } - else { //-> use the previous value - std::cerr << "prices_syntheticprofits() unchanged costbasis=" << costbasis << " price=" << price << " leverage=" << leverage << std::endl; - } + + if (minmax) { // if we are within day window, set costbasis to max or min price value + if (leverage > 0 && price > costbasis) { + costbasis = price; // set temp costbasis + std::cerr << "prices_syntheticprofits() minmax costbasis=" << costbasis << " price=" << price << std::endl; + } + else if (leverage < 0 && (costbasis == 0 || price < costbasis)) { + costbasis = price; + std::cerr << "prices_syntheticprofits() minmax costbasis=" << costbasis << " price=" << price << std::endl; + } + else { //-> use the previous value + std::cerr << "prices_syntheticprofits() unchanged costbasis=" << costbasis << " price=" << price << " leverage=" << leverage << std::endl; + } - } - else { - costbasis = price; // smoothed value - std::cerr << "prices_syntheticprofits() smoothed costbasis=" << costbasis << " price=" << price << std::endl; - } } + else { + // use provided costbasis + std::cerr << "prices_syntheticprofits() provided costbasis=" << costbasis << " price=" << price << std::endl; + if (costbasis == 0) + costbasis = price; + } + - profits = costbasis > 0 ? ((price * SATOSHIDEN) / costbasis) - SATOSHIDEN : 0; - std::cerr << "prices_syntheticprofits() (price * SATOSHIDEN)=" << (price * SATOSHIDEN) << std::endl; - std::cerr << "prices_syntheticprofits() (price * SATOSHIDEN)/costbasis=" << (price * SATOSHIDEN)/costbasis << std::endl; + profits = costbasis > 0 ? ( ((price / 10000 * SATOSHIDEN) / costbasis) - SATOSHIDEN / 10000 ) : 0; + std::cerr << "prices_syntheticprofits() (price /10000 * SATOSHIDEN)=" << (price /10000 * SATOSHIDEN) << std::endl; + std::cerr << "prices_syntheticprofits() (price /10000 * SATOSHIDEN)/costbasis=" << (price /10000 * SATOSHIDEN)/costbasis << std::endl; std::cerr << "prices_syntheticprofits() profits1=" << profits << std::endl; - std::cerr << "prices_syntheticprofits() profits double=" << (double)price / (double)costbasis -1.0 << std::endl; - double dprofits = (double)price / (double)costbasis - 1.0; + //std::cerr << "prices_syntheticprofits() profits double=" << (double)price / (double)costbasis -1.0 << std::endl; + //double dprofits = (double)price / (double)costbasis - 1.0; profits *= leverage * positionsize; - dprofits *= leverage * positionsize; + //dprofits *= leverage * positionsize; std::cerr << "prices_syntheticprofits() profits2=" << profits << std::endl; - std::cerr << "prices_syntheticprofits() dprofits=" << dprofits << std::endl; + //std::cerr << "prices_syntheticprofits() dprofits=" << dprofits << std::endl; - return(positionsize + addedbets + dprofits); + return profits; // (positionsize + addedbets + profits); } -void prices_betjson(UniValue &result,int64_t profits,int64_t costbasis,int64_t positionsize,int64_t addedbets,int16_t leverage,int32_t firstheight,int64_t firstprice) +void prices_betjson(UniValue &result,int64_t profits,int64_t costbasis,int64_t positionsize,int64_t addedbets,int16_t leverage,int32_t firstheight,int64_t firstprice, int64_t lastprice) { result.push_back(Pair("profits",ValueFromAmount(profits))); result.push_back(Pair("costbasis",ValueFromAmount(costbasis))); result.push_back(Pair("positionsize",ValueFromAmount(positionsize))); + result.push_back(Pair("equity", ValueFromAmount(positionsize + addedbets + profits))); result.push_back(Pair("addedbets",ValueFromAmount(addedbets))); result.push_back(Pair("leverage",(int64_t)leverage)); result.push_back(Pair("firstheight",(int64_t)firstheight)); result.push_back(Pair("firstprice",ValueFromAmount(firstprice))); + result.push_back(Pair("lastprice", ValueFromAmount(lastprice))); } // retrives costbasis from a tx spending bettx vout1 @@ -837,7 +841,7 @@ UniValue PricesSetcostbasis(int64_t txfee, uint256 bettxid) CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), nextheight); UniValue result(UniValue::VOBJ); struct CCcontract_info *cp, C; CTransaction bettx; uint256 hashBlock, batontxid, tokenid; - int64_t myfee, positionsize = 0, addedbets, firstprice = 0, profits = 0, costbasis = 0; + int64_t myfee, positionsize = 0, addedbets, firstprice = 0, lastprice, profits = 0, costbasis = 0; int32_t i, firstheight = 0, height, numvouts; int16_t leverage = 0; std::vector vec; CPubKey pk, mypk, pricespk; std::string rawtx; @@ -852,7 +856,7 @@ UniValue PricesSetcostbasis(int64_t txfee, uint256 bettxid) { if (prices_betopretdecode(bettx.vout[numvouts - 1].scriptPubKey, pk, firstheight, positionsize, leverage, firstprice, vec, tokenid) == 'B') { - if (nextheight <= firstheight + PRICES_DAYWINDOW + PRICES_SMOOTHWIDTH) { + if (nextheight <= firstheight + PRICES_DAYWINDOW + 1) { result.push_back(Pair("result", "error")); result.push_back(Pair("error", "cannot calculate costbasis yet")); return(result); @@ -860,9 +864,9 @@ UniValue PricesSetcostbasis(int64_t txfee, uint256 bettxid) addedbets = prices_batontxid(batontxid, bettx, bettxid); mtx.vin.push_back(CTxIn(bettxid, 1, CScript())); // spend vin1 with betamount - for (i = 0; i < PRICES_DAYWINDOW + PRICES_SMOOTHWIDTH; i++) // the last datum for 24h is the costbasis value + for (i = 0; i < PRICES_DAYWINDOW + 1; i++) // the last datum for 24h is the costbasis value { - if ((profits = prices_syntheticprofits(true, costbasis, firstheight, firstheight + i, leverage, vec, positionsize, addedbets)) < 0) + if ((profits = prices_syntheticprofits(costbasis, firstheight, firstheight + i, leverage, vec, positionsize, addedbets, lastprice)) < 0) { // we are in loss result.push_back(Pair("rekt", (int64_t)1)); result.push_back(Pair("rektheight", (int64_t)firstheight + i)); @@ -872,7 +876,7 @@ UniValue PricesSetcostbasis(int64_t txfee, uint256 bettxid) if (i == PRICES_DAYWINDOW) result.push_back(Pair("rekt", 0)); - prices_betjson(result, profits, costbasis, positionsize, addedbets, leverage, firstheight, firstprice); + prices_betjson(result, profits, costbasis, positionsize, addedbets, leverage, firstheight, firstprice, lastprice); if (AddNormalinputs(mtx, mypk, txfee, 4) >= txfee) { @@ -898,7 +902,16 @@ UniValue PricesRekt(int64_t txfee, uint256 bettxid, int32_t rektheight) { int32_t nextheight = komodo_nextheight(); CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), nextheight); UniValue result(UniValue::VOBJ); - struct CCcontract_info *cp, C; CTransaction bettx; uint256 hashBlock, tokenid, batontxid; int64_t myfee = 0, positionsize, addedbets, firstprice, profits, ignore, costbasis = 0; int32_t firstheight, numvouts; int16_t leverage; std::vector vec; CPubKey pk, mypk, pricespk; std::string rawtx; + struct CCcontract_info *cp, C; + CTransaction bettx; + uint256 hashBlock, tokenid, batontxid; + int64_t myfee = 0, positionsize, addedbets, firstprice, lastprice, profits, ignore, costbasis = 0; + int32_t firstheight, numvouts; + int16_t leverage; + std::vector vec; + CPubKey pk, mypk, pricespk; + std::string rawtx; + cp = CCinit(&C, EVAL_PRICES); if (txfee == 0) txfee = PRICES_TXFEE; @@ -917,11 +930,11 @@ UniValue PricesRekt(int64_t txfee, uint256 bettxid, int32_t rektheight) } addedbets = prices_batontxid(batontxid, bettx, bettxid); - if ((profits = prices_syntheticprofits(false, costbasis /*ignore*/, firstheight, rektheight, leverage, vec, positionsize, addedbets)) < 0) + if ((profits = prices_syntheticprofits(costbasis /*ignore*/, firstheight, rektheight, leverage, vec, positionsize, addedbets, lastprice)) < 0) { myfee = (positionsize + addedbets) / 500; } - prices_betjson(result, profits, costbasis, positionsize, addedbets, leverage, firstheight, firstprice); + prices_betjson(result, profits, costbasis, positionsize, addedbets, leverage, firstheight, firstprice, lastprice); if (myfee != 0) { mtx.vin.push_back(CTxIn(bettxid, 2, CScript())); @@ -956,7 +969,7 @@ UniValue PricesCashout(int64_t txfee, uint256 bettxid) struct CCcontract_info *cp, C; char destaddr[64]; CTransaction bettx; uint256 hashBlock, batontxid, tokenid; - int64_t CCchange = 0, positionsize, inputsum, ignore, addedbets, firstprice, profits, costbasis = 0; + int64_t CCchange = 0, positionsize, inputsum, ignore, addedbets, firstprice, lastprice, profits, costbasis = 0; int32_t i, firstheight, height, numvouts; int16_t leverage; std::vector vec; @@ -984,14 +997,14 @@ UniValue PricesCashout(int64_t txfee, uint256 bettxid) } addedbets = prices_batontxid(batontxid, bettx, bettxid); - if ((profits = prices_syntheticprofits(false, costbasis, firstheight, nextheight - 1, leverage, vec, positionsize, addedbets)) < 0) + if ((profits = prices_syntheticprofits(costbasis, firstheight, nextheight - 1, leverage, vec, positionsize, addedbets, lastprice)) < 0) { - prices_betjson(result, profits, costbasis, positionsize, addedbets, leverage, firstheight, firstprice); + prices_betjson(result, profits, costbasis, positionsize, addedbets, leverage, firstheight, firstprice, lastprice); result.push_back(Pair("result", "error")); result.push_back(Pair("error", "position rekt")); return(result); } - prices_betjson(result, profits, costbasis, positionsize, addedbets, leverage, firstheight, firstprice); + prices_betjson(result, profits, costbasis, positionsize, addedbets, leverage, firstheight, firstprice, lastprice); mtx.vin.push_back(CTxIn(bettxid, 2, CScript())); if ((inputsum = AddPricesInputs(cp, mtx, destaddr, profits + txfee, 64, bettxid, 2)) > profits + txfee) CCchange = (inputsum - profits); @@ -1016,7 +1029,7 @@ UniValue PricesInfo(uint256 bettxid, int32_t refheight) UniValue result(UniValue::VOBJ); CTransaction bettx; uint256 hashBlock, batontxid, tokenid; - int64_t myfee, ignore = 0, positionsize = 0, addedbets = 0, firstprice = 0, profits = 0, costbasis = 0; + int64_t myfee, ignore = 0, positionsize = 0, addedbets = 0, firstprice = 0, lastprice, profits = 0, costbasis = 0; int32_t i, firstheight = 0, height, numvouts; int16_t leverage = 0; std::vector vec; @@ -1038,13 +1051,15 @@ UniValue PricesInfo(uint256 bettxid, int32_t refheight) costbasis = prices_costbasis(bettx, costbasistxid); addedbets = prices_batontxid(batontxid, bettx, bettxid); + + /* if( costbasis == 0 && prices_syntheticprofits(true, costbasis, firstheight, firstheight, leverage, vec, positionsize, addedbets) < 0) { result.push_back(Pair("result", "error")); result.push_back(Pair("error", "cannot calculate costbasis")); return(result); - } + } */ - if ((profits = prices_syntheticprofits(false, costbasis, firstheight, refheight, leverage, vec, positionsize, addedbets)) < 0) + if ((profits = prices_syntheticprofits(costbasis, firstheight, refheight, leverage, vec, positionsize, addedbets, lastprice)) < 0) { result.push_back(Pair("rekt", 1)); result.push_back(Pair("rektfee", (positionsize + addedbets) / 500)); @@ -1054,7 +1069,7 @@ UniValue PricesInfo(uint256 bettxid, int32_t refheight) result.push_back(Pair("batontxid", batontxid.GetHex())); if(!costbasistxid.IsNull()) result.push_back(Pair("costbasistxid", costbasistxid.GetHex())); - prices_betjson(result, profits, costbasis, positionsize, addedbets, leverage, firstheight, firstprice); + prices_betjson(result, profits, costbasis, positionsize, addedbets, leverage, firstheight, firstprice, lastprice); result.push_back(Pair("height", (int64_t)refheight)); return(result); } From 7f59d7c76e35f9f08d98c73e36e8a2aff4b83cac Mon Sep 17 00:00:00 2001 From: dimxy Date: Fri, 19 Apr 2019 13:41:24 +0500 Subject: [PATCH 083/447] pricedata logging --- src/cc/prices.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 483e48937..ef47c5f7f 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -478,6 +478,7 @@ int64_t prices_syntheticprice(std::vector vec, int32_t height, int32_t pricestack[depth] = 0; if (komodo_priceget(pricedata, value, height, 1) >= 0) { + std::cerr << "prices_syntheticprice" << " pricedata[0]=" << pricedata[0] << " pricedata[1]=" << pricedata[1] << " pricedata[2]=" << pricedata[2] << std::endl; // push price to the prices stack if (!minmax) pricestack[depth] = pricedata[2]; // use smoothed value if we are over 24h From f7912ee8f4a8060bca580b5106576afac17344ea Mon Sep 17 00:00:00 2001 From: dimxy Date: Fri, 19 Apr 2019 13:47:14 +0500 Subject: [PATCH 084/447] more pricedata log --- src/cc/prices.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index ef47c5f7f..12d91ad74 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -478,7 +478,7 @@ int64_t prices_syntheticprice(std::vector vec, int32_t height, int32_t pricestack[depth] = 0; if (komodo_priceget(pricedata, value, height, 1) >= 0) { - std::cerr << "prices_syntheticprice" << " pricedata[0]=" << pricedata[0] << " pricedata[1]=" << pricedata[1] << " pricedata[2]=" << pricedata[2] << std::endl; + std::cerr << "prices_syntheticprice" << " pricedata[0]=" << pricedata[0] << " pricedata[1]=" << pricedata[1] << " pricedata[2]=" << pricedata[2] << " pricedata_int32[2]=" << *((uint32_t*)pricedata[2]) << std::endl; // push price to the prices stack if (!minmax) pricestack[depth] = pricedata[2]; // use smoothed value if we are over 24h From bcd6e1a4d9671ddb7e55d3e171bd47f3b54ce187 Mon Sep 17 00:00:00 2001 From: dimxy Date: Fri, 19 Apr 2019 13:51:53 +0500 Subject: [PATCH 085/447] clear lowest pos in price --- src/cc/prices.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 12d91ad74..de20efcff 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -628,6 +628,10 @@ int64_t prices_syntheticprofits(int64_t &costbasis, int32_t firstheight, int32_t fprintf(stderr, "unexpected zero synthetic price at height.%d\n", height); return(0); } + + // clear lowest positions: + price /= 10000; + price *= 10000; if (minmax) { // if we are within day window, set costbasis to max or min price value if (leverage > 0 && price > costbasis) { From d15e1b3a8f52c45d1cbfaf745f1361ff57a70770 Mon Sep 17 00:00:00 2001 From: dimxy Date: Fri, 19 Apr 2019 13:57:14 +0500 Subject: [PATCH 086/447] removed bad logging --- src/cc/prices.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index de20efcff..51f4d7ddf 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -478,7 +478,7 @@ int64_t prices_syntheticprice(std::vector vec, int32_t height, int32_t pricestack[depth] = 0; if (komodo_priceget(pricedata, value, height, 1) >= 0) { - std::cerr << "prices_syntheticprice" << " pricedata[0]=" << pricedata[0] << " pricedata[1]=" << pricedata[1] << " pricedata[2]=" << pricedata[2] << " pricedata_int32[2]=" << *((uint32_t*)pricedata[2]) << std::endl; + std::cerr << "prices_syntheticprice" << " pricedata[0]=" << pricedata[0] << " pricedata[1]=" << pricedata[1] << " pricedata[2]=" << pricedata[2] << std::endl; // push price to the prices stack if (!minmax) pricestack[depth] = pricedata[2]; // use smoothed value if we are over 24h From 41f5437f09c0f98b36004c482962d1d0c9bd5c93 Mon Sep 17 00:00:00 2001 From: dimxy Date: Fri, 19 Apr 2019 14:26:14 +0500 Subject: [PATCH 087/447] define for 10000 factor added --- src/cc/CCPrices.h | 1 + src/cc/prices.cpp | 14 +++++++------- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/cc/CCPrices.h b/src/cc/CCPrices.h index 62da19aab..1402a995c 100644 --- a/src/cc/CCPrices.h +++ b/src/cc/CCPrices.h @@ -34,6 +34,7 @@ int32_t komodo_priceget(int64_t *buf64,int32_t ind,int32_t height,int32_t numblo #define PRICES_MMD (KOMODO_MAXPRICES * 6) // 0011 0000 0000 0000 #define PRICES_MMM (KOMODO_MAXPRICES * 7) // 0011 1000 0000 0000 #define PRICES_DDD (KOMODO_MAXPRICES * 8) // 0100 0000 0000 0000 +#define PRICES_NORMFACTOR 10000 bool PricesValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 51f4d7ddf..4454c4d0d 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -630,8 +630,8 @@ int64_t prices_syntheticprofits(int64_t &costbasis, int32_t firstheight, int32_t } // clear lowest positions: - price /= 10000; - price *= 10000; + price /= PRICES_NORMFACTOR; + price *= PRICES_NORMFACTOR; if (minmax) { // if we are within day window, set costbasis to max or min price value if (leverage > 0 && price > costbasis) { @@ -655,17 +655,17 @@ int64_t prices_syntheticprofits(int64_t &costbasis, int32_t firstheight, int32_t } - profits = costbasis > 0 ? ( ((price / 10000 * SATOSHIDEN) / costbasis) - SATOSHIDEN / 10000 ) : 0; - std::cerr << "prices_syntheticprofits() (price /10000 * SATOSHIDEN)=" << (price /10000 * SATOSHIDEN) << std::endl; - std::cerr << "prices_syntheticprofits() (price /10000 * SATOSHIDEN)/costbasis=" << (price /10000 * SATOSHIDEN)/costbasis << std::endl; + profits = costbasis > 0 ? ((price / PRICES_NORMFACTOR * SATOSHIDEN) / costbasis) - SATOSHIDEN / PRICES_NORMFACTOR : 0; + std::cerr << "prices_syntheticprofits() test value1 (price/PRICES_NORMFACTOR * SATOSHIDEN)=" << (price / PRICES_NORMFACTOR * SATOSHIDEN) << std::endl; + std::cerr << "prices_syntheticprofits() test value2 (price/PRICES_NORMFACTOR * SATOSHIDEN)/costbasis=" << (price / PRICES_NORMFACTOR * SATOSHIDEN)/costbasis << std::endl; - std::cerr << "prices_syntheticprofits() profits1=" << profits << std::endl; + std::cerr << "prices_syntheticprofits() fract profits=" << profits << std::endl; //std::cerr << "prices_syntheticprofits() profits double=" << (double)price / (double)costbasis -1.0 << std::endl; //double dprofits = (double)price / (double)costbasis - 1.0; profits *= leverage * positionsize; //dprofits *= leverage * positionsize; - std::cerr << "prices_syntheticprofits() profits2=" << profits << std::endl; + std::cerr << "prices_syntheticprofits() val profits=" << profits << std::endl; //std::cerr << "prices_syntheticprofits() dprofits=" << dprofits << std::endl; From 0684f7ab6e086cf6ebdff057bd5ecd2985dab030 Mon Sep 17 00:00:00 2001 From: dimxy Date: Fri, 19 Apr 2019 20:32:18 +0500 Subject: [PATCH 088/447] corrected temp costbasis calculation for priceinfo corrected equity loss check --- src/cc/prices.cpp | 78 ++++++++++++++++++++++++++++++----------------- 1 file changed, 50 insertions(+), 28 deletions(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 4454c4d0d..b94cb7dfe 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -672,12 +672,12 @@ int64_t prices_syntheticprofits(int64_t &costbasis, int32_t firstheight, int32_t return profits; // (positionsize + addedbets + profits); } -void prices_betjson(UniValue &result,int64_t profits,int64_t costbasis,int64_t positionsize,int64_t addedbets,int16_t leverage,int32_t firstheight,int64_t firstprice, int64_t lastprice) +void prices_betjson(UniValue &result,int64_t profits,int64_t costbasis,int64_t positionsize,int64_t addedbets,int16_t leverage,int32_t firstheight,int64_t firstprice, int64_t lastprice, int64_t equity) { result.push_back(Pair("profits",ValueFromAmount(profits))); result.push_back(Pair("costbasis",ValueFromAmount(costbasis))); result.push_back(Pair("positionsize",ValueFromAmount(positionsize))); - result.push_back(Pair("equity", ValueFromAmount(positionsize + addedbets + profits))); + result.push_back(Pair("equity", ValueFromAmount(equity))); result.push_back(Pair("addedbets",ValueFromAmount(addedbets))); result.push_back(Pair("leverage",(int64_t)leverage)); result.push_back(Pair("firstheight",(int64_t)firstheight)); @@ -846,7 +846,7 @@ UniValue PricesSetcostbasis(int64_t txfee, uint256 bettxid) CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), nextheight); UniValue result(UniValue::VOBJ); struct CCcontract_info *cp, C; CTransaction bettx; uint256 hashBlock, batontxid, tokenid; - int64_t myfee, positionsize = 0, addedbets, firstprice = 0, lastprice, profits = 0, costbasis = 0; + int64_t myfee, positionsize = 0, addedbets, firstprice = 0, lastprice, profits = 0, costbasis = 0, equity; int32_t i, firstheight = 0, height, numvouts; int16_t leverage = 0; std::vector vec; CPubKey pk, mypk, pricespk; std::string rawtx; @@ -871,17 +871,19 @@ UniValue PricesSetcostbasis(int64_t txfee, uint256 bettxid) mtx.vin.push_back(CTxIn(bettxid, 1, CScript())); // spend vin1 with betamount for (i = 0; i < PRICES_DAYWINDOW + 1; i++) // the last datum for 24h is the costbasis value { - if ((profits = prices_syntheticprofits(costbasis, firstheight, firstheight + i, leverage, vec, positionsize, addedbets, lastprice)) < 0) + profits = prices_syntheticprofits(costbasis, firstheight, firstheight + i, leverage, vec, positionsize, addedbets, lastprice); + equity = positionsize + addedbets + profits; + if (equity < 0) { // we are in loss result.push_back(Pair("rekt", (int64_t)1)); result.push_back(Pair("rektheight", (int64_t)firstheight + i)); break; } } - if (i == PRICES_DAYWINDOW) + if (i == PRICES_DAYWINDOW + 1) result.push_back(Pair("rekt", 0)); - prices_betjson(result, profits, costbasis, positionsize, addedbets, leverage, firstheight, firstprice, lastprice); + prices_betjson(result, profits, costbasis, positionsize, addedbets, leverage, firstheight, firstprice, lastprice, equity); if (AddNormalinputs(mtx, mypk, txfee, 4) >= txfee) { @@ -910,7 +912,7 @@ UniValue PricesRekt(int64_t txfee, uint256 bettxid, int32_t rektheight) struct CCcontract_info *cp, C; CTransaction bettx; uint256 hashBlock, tokenid, batontxid; - int64_t myfee = 0, positionsize, addedbets, firstprice, lastprice, profits, ignore, costbasis = 0; + int64_t myfee = 0, positionsize, addedbets, firstprice, lastprice, profits, ignore, costbasis = 0, equity; int32_t firstheight, numvouts; int16_t leverage; std::vector vec; @@ -935,11 +937,13 @@ UniValue PricesRekt(int64_t txfee, uint256 bettxid, int32_t rektheight) } addedbets = prices_batontxid(batontxid, bettx, bettxid); - if ((profits = prices_syntheticprofits(costbasis /*ignore*/, firstheight, rektheight, leverage, vec, positionsize, addedbets, lastprice)) < 0) + profits = prices_syntheticprofits(costbasis, firstheight, rektheight, leverage, vec, positionsize, addedbets, lastprice); + equity = positionsize + addedbets + profits; + if (equity < 0) { myfee = (positionsize + addedbets) / 500; } - prices_betjson(result, profits, costbasis, positionsize, addedbets, leverage, firstheight, firstprice, lastprice); + prices_betjson(result, profits, costbasis, positionsize, addedbets, leverage, firstheight, firstprice, lastprice, equity); if (myfee != 0) { mtx.vin.push_back(CTxIn(bettxid, 2, CScript())); @@ -974,7 +978,7 @@ UniValue PricesCashout(int64_t txfee, uint256 bettxid) struct CCcontract_info *cp, C; char destaddr[64]; CTransaction bettx; uint256 hashBlock, batontxid, tokenid; - int64_t CCchange = 0, positionsize, inputsum, ignore, addedbets, firstprice, lastprice, profits, costbasis = 0; + int64_t CCchange = 0, positionsize, inputsum, ignore, addedbets, firstprice, lastprice, profits, costbasis = 0, equity; int32_t i, firstheight, height, numvouts; int16_t leverage; std::vector vec; @@ -1002,14 +1006,16 @@ UniValue PricesCashout(int64_t txfee, uint256 bettxid) } addedbets = prices_batontxid(batontxid, bettx, bettxid); - if ((profits = prices_syntheticprofits(costbasis, firstheight, nextheight - 1, leverage, vec, positionsize, addedbets, lastprice)) < 0) + profits = prices_syntheticprofits(costbasis, firstheight, nextheight - 1, leverage, vec, positionsize, addedbets, lastprice); + equity = positionsize + addedbets + profits; + if (equity < 0) { - prices_betjson(result, profits, costbasis, positionsize, addedbets, leverage, firstheight, firstprice, lastprice); + prices_betjson(result, profits, costbasis, positionsize, addedbets, leverage, firstheight, firstprice, lastprice, equity); result.push_back(Pair("result", "error")); result.push_back(Pair("error", "position rekt")); return(result); } - prices_betjson(result, profits, costbasis, positionsize, addedbets, leverage, firstheight, firstprice, lastprice); + prices_betjson(result, profits, costbasis, positionsize, addedbets, leverage, firstheight, firstprice, lastprice, equity); mtx.vin.push_back(CTxIn(bettxid, 2, CScript())); if ((inputsum = AddPricesInputs(cp, mtx, destaddr, profits + txfee, 64, bettxid, 2)) > profits + txfee) CCchange = (inputsum - profits); @@ -1034,7 +1040,7 @@ UniValue PricesInfo(uint256 bettxid, int32_t refheight) UniValue result(UniValue::VOBJ); CTransaction bettx; uint256 hashBlock, batontxid, tokenid; - int64_t myfee, ignore = 0, positionsize = 0, addedbets = 0, firstprice = 0, lastprice, profits = 0, costbasis = 0; + int64_t myfee, ignore = 0, positionsize = 0, addedbets = 0, firstprice = 0, lastprice, profits = 0, costbasis = 0, equity; int32_t i, firstheight = 0, height, numvouts; int16_t leverage = 0; std::vector vec; @@ -1057,24 +1063,40 @@ UniValue PricesInfo(uint256 bettxid, int32_t refheight) costbasis = prices_costbasis(bettx, costbasistxid); addedbets = prices_batontxid(batontxid, bettx, bettxid); - /* - if( costbasis == 0 && prices_syntheticprofits(true, costbasis, firstheight, firstheight, leverage, vec, positionsize, addedbets) < 0) { - result.push_back(Pair("result", "error")); - result.push_back(Pair("error", "cannot calculate costbasis")); - return(result); - } */ - - if ((profits = prices_syntheticprofits(costbasis, firstheight, refheight, leverage, vec, positionsize, addedbets, lastprice)) < 0) - { - result.push_back(Pair("rekt", 1)); - result.push_back(Pair("rektfee", (positionsize + addedbets) / 500)); + if (costbasis != 0) { // costbasis fixed + profits = prices_syntheticprofits(costbasis, firstheight, refheight, leverage, vec, positionsize, addedbets, lastprice); + equity = positionsize + addedbets + profits; + if (equity < 0) + { + result.push_back(Pair("rekt", 1)); + result.push_back(Pair("rektfee", (positionsize + addedbets) / 500)); + result.push_back(Pair("rektheight", (int64_t)refheight)); + } + else + result.push_back(Pair("rekt", 0)); } - else - result.push_back(Pair("rekt", 0)); + else { + for (i = 0; i < PRICES_DAYWINDOW + 1; i++) // the last datum for 24h is the costbasis value + { + profits = prices_syntheticprofits(costbasis, firstheight, firstheight + i, leverage, vec, positionsize, addedbets, lastprice); + equity = positionsize + addedbets + profits; + if (equity < 0) + { // we are in loss + result.push_back(Pair("rekt", (int64_t)1)); + result.push_back(Pair("rektfee", (positionsize + addedbets) / 500)); + result.push_back(Pair("rektheight", (int64_t)firstheight + i)); + break; + } + } + if (i == PRICES_DAYWINDOW + 1) + result.push_back(Pair("rekt", 0)); + } + + result.push_back(Pair("batontxid", batontxid.GetHex())); if(!costbasistxid.IsNull()) result.push_back(Pair("costbasistxid", costbasistxid.GetHex())); - prices_betjson(result, profits, costbasis, positionsize, addedbets, leverage, firstheight, firstprice, lastprice); + prices_betjson(result, profits, costbasis, positionsize, addedbets, leverage, firstheight, firstprice, lastprice, equity); result.push_back(Pair("height", (int64_t)refheight)); return(result); } From 01dfdc6b67a1d2b540c1458deabe2ccabe0b3255 Mon Sep 17 00:00:00 2001 From: dimxy Date: Fri, 19 Apr 2019 22:12:21 +0500 Subject: [PATCH 089/447] addfunding now in coins try correct fraction of profits --- src/cc/prices.cpp | 2 +- src/rpc/blockchain.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index b94cb7dfe..026c75181 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -663,7 +663,7 @@ int64_t prices_syntheticprofits(int64_t &costbasis, int32_t firstheight, int32_t //std::cerr << "prices_syntheticprofits() profits double=" << (double)price / (double)costbasis -1.0 << std::endl; //double dprofits = (double)price / (double)costbasis - 1.0; - profits *= leverage * positionsize; + profits *= leverage * positionsize / SATOSHIDEN; //dprofits *= leverage * positionsize; std::cerr << "prices_syntheticprofits() val profits=" << profits << std::endl; //std::cerr << "prices_syntheticprofits() dprofits=" << dprofits << std::endl; diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index fefec1337..1f6fcadcf 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -1358,7 +1358,7 @@ UniValue pricesaddfunding(const UniValue& params, bool fHelp) { if (fHelp || params.size() != 2) throw runtime_error("pricesaddfunding bettxid amount\n" - "where amount is in satoshis\n"); + "where amount is in coins\n"); LOCK(cs_main); UniValue ret(UniValue::VOBJ); @@ -1370,7 +1370,7 @@ UniValue pricesaddfunding(const UniValue& params, bool fHelp) if (bettxid.IsNull()) throw runtime_error("invalid bettxid\n"); - CAmount amount = atoll(params[1].get_str().c_str()); + CAmount amount = atof(params[1].get_str().c_str()) * COIN; if (amount <= 0) throw runtime_error("invalid amount\n"); From 71b960a1e144cf3c77803789ca368ffb1d31126f Mon Sep 17 00:00:00 2001 From: dimxy Date: Fri, 19 Apr 2019 22:22:06 +0500 Subject: [PATCH 090/447] yet corr profits fraction --- src/cc/prices.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 026c75181..23e3aa22a 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -655,7 +655,7 @@ int64_t prices_syntheticprofits(int64_t &costbasis, int32_t firstheight, int32_t } - profits = costbasis > 0 ? ((price / PRICES_NORMFACTOR * SATOSHIDEN) / costbasis) - SATOSHIDEN / PRICES_NORMFACTOR : 0; + profits = costbasis > 0 ? (((price / PRICES_NORMFACTOR * SATOSHIDEN) / costbasis) - SATOSHIDEN / PRICES_NORMFACTOR) * PRICES_NORMFACTOR : 0; std::cerr << "prices_syntheticprofits() test value1 (price/PRICES_NORMFACTOR * SATOSHIDEN)=" << (price / PRICES_NORMFACTOR * SATOSHIDEN) << std::endl; std::cerr << "prices_syntheticprofits() test value2 (price/PRICES_NORMFACTOR * SATOSHIDEN)/costbasis=" << (price / PRICES_NORMFACTOR * SATOSHIDEN)/costbasis << std::endl; From 5f30987ad68a0201b5a1036b667e53b3db7867a7 Mon Sep 17 00:00:00 2001 From: dimxy Date: Fri, 19 Apr 2019 22:30:25 +0500 Subject: [PATCH 091/447] outprice --- src/cc/prices.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 23e3aa22a..9c1935ac4 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -612,9 +612,10 @@ int64_t prices_syntheticprice(std::vector vec, int32_t height, int32_t } // calculates profit/loss for the bet -int64_t prices_syntheticprofits(int64_t &costbasis, int32_t firstheight, int32_t height, int16_t leverage, std::vector vec, int64_t positionsize, int64_t addedbets, int64_t &price) +int64_t prices_syntheticprofits(int64_t &costbasis, int32_t firstheight, int32_t height, int16_t leverage, std::vector vec, int64_t positionsize, int64_t addedbets, int64_t &outprice) { int64_t profits = 0; + int64_t price; if (height < firstheight) { fprintf(stderr, "requested height is lower than bet firstheight.%d\n", height); @@ -632,6 +633,7 @@ int64_t prices_syntheticprofits(int64_t &costbasis, int32_t firstheight, int32_t // clear lowest positions: price /= PRICES_NORMFACTOR; price *= PRICES_NORMFACTOR; + outprice = price; if (minmax) { // if we are within day window, set costbasis to max or min price value if (leverage > 0 && price > costbasis) { From d5d633140e107e6e578a063e41af672abc3de80e Mon Sep 17 00:00:00 2001 From: dimxy Date: Fri, 19 Apr 2019 22:51:49 +0500 Subject: [PATCH 092/447] corr calc profits refheight --- src/cc/prices.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 9c1935ac4..3a220b16f 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -1078,7 +1078,8 @@ UniValue PricesInfo(uint256 bettxid, int32_t refheight) result.push_back(Pair("rekt", 0)); } else { - for (i = 0; i < PRICES_DAYWINDOW + 1; i++) // the last datum for 24h is the costbasis value + bool isRekt = false; + for (i = 0; i < PRICES_DAYWINDOW + 1 && firstheight + i <= refheight; i++) // the last datum for 24h is the costbasis value { profits = prices_syntheticprofits(costbasis, firstheight, firstheight + i, leverage, vec, positionsize, addedbets, lastprice); equity = positionsize + addedbets + profits; @@ -1087,10 +1088,11 @@ UniValue PricesInfo(uint256 bettxid, int32_t refheight) result.push_back(Pair("rekt", (int64_t)1)); result.push_back(Pair("rektfee", (positionsize + addedbets) / 500)); result.push_back(Pair("rektheight", (int64_t)firstheight + i)); + isRekt = true; break; } } - if (i == PRICES_DAYWINDOW + 1) + if (!isRekt /*i == PRICES_DAYWINDOW + 1*/) result.push_back(Pair("rekt", 0)); } From 5d296e44f5b14709c747cf6cf6243069591f114d Mon Sep 17 00:00:00 2001 From: dimxy Date: Sun, 21 Apr 2019 12:39:03 +0500 Subject: [PATCH 093/447] try SATOSHIDEN as signed --- src/cc/prices.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 3a220b16f..2fd7a60df 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -158,7 +158,7 @@ bool ValidateBetTx(struct CCcontract_info *cp, Eval *eval, const CTransaction & if (MakeCC1vout(cp->evalcode, bettx.vout[1].nValue, pricespk) != bettx.vout[1]) return eval->Invalid("cannot validate vout1 in bet tx with global pk"); if( MakeCC1vout(cp->evalcode, bettx.vout[2].nValue, pricespk) != bettx.vout[2] ) - return eval->Invalid("cannot validate 1of2 vout2 in bet tx with pk from opreturn"); + return eval->Invalid("cannot validate vout2 in bet tx with pk from opreturn"); return true; } @@ -665,7 +665,7 @@ int64_t prices_syntheticprofits(int64_t &costbasis, int32_t firstheight, int32_t //std::cerr << "prices_syntheticprofits() profits double=" << (double)price / (double)costbasis -1.0 << std::endl; //double dprofits = (double)price / (double)costbasis - 1.0; - profits *= leverage * positionsize / SATOSHIDEN; + profits *= leverage * positionsize / (int64_t)SATOSHIDEN; //dprofits *= leverage * positionsize; std::cerr << "prices_syntheticprofits() val profits=" << profits << std::endl; //std::cerr << "prices_syntheticprofits() dprofits=" << dprofits << std::endl; From 82c656037409f341f0cd803d4384ce875e687efa Mon Sep 17 00:00:00 2001 From: dimxy Date: Sun, 21 Apr 2019 13:19:25 +0500 Subject: [PATCH 094/447] costbasis=0 zero div prevention in logging --- src/cc/prices.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 2fd7a60df..c302e6d73 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -659,7 +659,7 @@ int64_t prices_syntheticprofits(int64_t &costbasis, int32_t firstheight, int32_t profits = costbasis > 0 ? (((price / PRICES_NORMFACTOR * SATOSHIDEN) / costbasis) - SATOSHIDEN / PRICES_NORMFACTOR) * PRICES_NORMFACTOR : 0; std::cerr << "prices_syntheticprofits() test value1 (price/PRICES_NORMFACTOR * SATOSHIDEN)=" << (price / PRICES_NORMFACTOR * SATOSHIDEN) << std::endl; - std::cerr << "prices_syntheticprofits() test value2 (price/PRICES_NORMFACTOR * SATOSHIDEN)/costbasis=" << (price / PRICES_NORMFACTOR * SATOSHIDEN)/costbasis << std::endl; + std::cerr << "prices_syntheticprofits() test value2 (price/PRICES_NORMFACTOR * SATOSHIDEN)/costbasis=" << (costbasis != 0 ? (price / PRICES_NORMFACTOR * SATOSHIDEN)/costbasis : -1) << std::endl; std::cerr << "prices_syntheticprofits() fract profits=" << profits << std::endl; //std::cerr << "prices_syntheticprofits() profits double=" << (double)price / (double)costbasis -1.0 << std::endl; From efec12bcf532b38c917f1ea504d97ea4bac2ab9b Mon Sep 17 00:00:00 2001 From: dimxy Date: Sun, 21 Apr 2019 21:01:02 +0500 Subject: [PATCH 095/447] if TESTMODE PRICES_DAYWINDOW=3 --- src/cc/CCPrices.h | 3 ++- src/cc/prices.cpp | 3 +++ src/komodo_defs.h | 5 +++++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/cc/CCPrices.h b/src/cc/CCPrices.h index 1402a995c..0225ff69b 100644 --- a/src/cc/CCPrices.h +++ b/src/cc/CCPrices.h @@ -17,10 +17,11 @@ #ifndef CC_PRICES_H #define CC_PRICES_H +#include "komodo_defs.h" #include "CCinclude.h" int32_t komodo_priceget(int64_t *buf64,int32_t ind,int32_t height,int32_t numblocks); -#define PRICES_DAYWINDOW ((3600*24/ASSETCHAINS_BLOCKTIME) + 1) +// #define PRICES_DAYWINDOW ((3600*24/ASSETCHAINS_BLOCKTIME) + 1) // defined in komodo_defs.h #define PRICES_TXFEE 10000 #define PRICES_MAXLEVERAGE 777 #define PRICES_SMOOTHWIDTH 1 diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index c302e6d73..d8944df9f 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -1102,6 +1102,9 @@ UniValue PricesInfo(uint256 bettxid, int32_t refheight) result.push_back(Pair("costbasistxid", costbasistxid.GetHex())); prices_betjson(result, profits, costbasis, positionsize, addedbets, leverage, firstheight, firstprice, lastprice, equity); result.push_back(Pair("height", (int64_t)refheight)); +#ifdef TESTMODE + result.push_back(Pair("test_daywindow", PRICES_DAYWINDOW)); +#endif return(result); } } diff --git a/src/komodo_defs.h b/src/komodo_defs.h index 2fcd29df3..d5a9a21e2 100644 --- a/src/komodo_defs.h +++ b/src/komodo_defs.h @@ -38,7 +38,12 @@ #define KOMODO_MAXNVALUE (((uint64_t)1 << 63) - 1) #define KOMODO_BIT63SET(x) ((x) & ((uint64_t)1 << 63)) #define KOMODO_VALUETOOBIG(x) ((x) > (uint64_t)10000000001*COIN) + +#ifndef TESTMODE #define PRICES_DAYWINDOW ((3600*24/ASSETCHAINS_BLOCKTIME) + 1) +#else +#define PRICES_DAYWINDOW (3) +#endif extern uint8_t ASSETCHAINS_TXPOW,ASSETCHAINS_PUBLIC; int32_t MAX_BLOCK_SIZE(int32_t height); From a18ab80ddeef2650345590f2b3d552333835a9aa Mon Sep 17 00:00:00 2001 From: dimxy Date: Mon, 22 Apr 2019 11:30:15 +0500 Subject: [PATCH 096/447] mypriceslist added --- src/cc/CCPrices.h | 2 +- src/cc/prices.cpp | 21 ++++++++++----------- src/rpc/server.cpp | 1 + src/rpc/server.h | 1 + src/wallet/rpcwallet.cpp | 13 ++++++++++++- 5 files changed, 25 insertions(+), 13 deletions(-) diff --git a/src/cc/CCPrices.h b/src/cc/CCPrices.h index 0225ff69b..c7f3961d5 100644 --- a/src/cc/CCPrices.h +++ b/src/cc/CCPrices.h @@ -46,7 +46,7 @@ UniValue PricesSetcostbasis(int64_t txfee,uint256 bettxid); UniValue PricesRekt(int64_t txfee,uint256 bettxid,int32_t rektheight); UniValue PricesCashout(int64_t txfee,uint256 bettxid); UniValue PricesInfo(uint256 bettxid,int32_t refheight); -UniValue PricesList(); +UniValue PricesList(CPubKey mypk); #endif diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index d8944df9f..425b125c1 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -1113,14 +1113,14 @@ UniValue PricesInfo(uint256 bettxid, int32_t refheight) return(result); } -UniValue PricesList() +UniValue PricesList(CPubKey mypk) { - UniValue result(UniValue::VARR); std::vector > addressIndex; - struct CCcontract_info *cp, C; - int64_t amount, firstprice; int32_t height; int16_t leverage; uint256 txid, hashBlock, tokenid; - CPubKey pk, pricespk; - std::vector vec; - CTransaction vintx; + UniValue result(UniValue::VARR); std::vector > addressIndex; + struct CCcontract_info *cp, C; + int64_t amount, firstprice; int32_t height; int16_t leverage; uint256 txid, hashBlock, tokenid; + CPubKey pk, pricespk; + std::vector vec; + CTransaction vintx; cp = CCinit(&C, EVAL_PRICES); pricespk = GetUnspendable(cp, 0); @@ -1130,13 +1130,12 @@ UniValue PricesList() txid = it->first.txhash; if (GetTransaction(txid, vintx, hashBlock, false) != 0) { - if (vintx.vout.size() > 0 && prices_betopretdecode(vintx.vout[vintx.vout.size() - 1].scriptPubKey, pk, height, amount, leverage, firstprice, vec, tokenid) == 'B') + if (vintx.vout.size() > 0 && prices_betopretdecode(vintx.vout[vintx.vout.size() - 1].scriptPubKey, pk, height, amount, leverage, firstprice, vec, tokenid) == 'B' && + (mypk == CPubKey() || mypk == pk)) // if only mypubkey to list { result.push_back(txid.GetHex()); } } } return(result); -} - - +} \ No newline at end of file diff --git a/src/rpc/server.cpp b/src/rpc/server.cpp index 29e616bca..13f235e26 100644 --- a/src/rpc/server.cpp +++ b/src/rpc/server.cpp @@ -463,6 +463,7 @@ static const CRPCCommand vRPCCommands[] = { "prices", "prices", &prices, true }, { "prices", "pricesaddress", &pricesaddress, true }, { "prices", "priceslist", &priceslist, true }, + { "prices", "mypriceslist", &mypriceslist, true }, { "prices", "pricesinfo", &pricesinfo, true }, { "prices", "pricesbet", &pricesbet, true }, { "prices", "pricessetcostbasis", &pricessetcostbasis, true }, diff --git a/src/rpc/server.h b/src/rpc/server.h index 2bd0b91c6..98a0d046f 100644 --- a/src/rpc/server.h +++ b/src/rpc/server.h @@ -271,6 +271,7 @@ extern UniValue oraclesdata(const UniValue& params, bool fHelp); extern UniValue oraclessamples(const UniValue& params, bool fHelp); extern UniValue pricesaddress(const UniValue& params, bool fHelp); extern UniValue priceslist(const UniValue& params, bool fHelp); +extern UniValue mypriceslist(const UniValue& params, bool fHelp); extern UniValue pricesinfo(const UniValue& params, bool fHelp); extern UniValue pegsaddress(const UniValue& params, bool fHelp); extern UniValue marmaraaddress(const UniValue& params, bool fHelp); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index a155603d9..8c6e4530f 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -6925,7 +6925,18 @@ UniValue priceslist(const UniValue& params, bool fHelp) throw runtime_error("priceslist\n"); if ( ensure_CCrequirements(EVAL_PRICES) < 0 ) throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); - return(PricesList()); + CPubKey emptypk; + return(PricesList(emptypk)); +} + +UniValue mypriceslist(const UniValue& params, bool fHelp) +{ + if (fHelp || params.size() > 0) + throw runtime_error("priceslist\n"); + if (ensure_CCrequirements(EVAL_PRICES) < 0) + throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + CPubKey mypk = pubkey2pk(Mypubkey()); + return(PricesList(mypk)); } UniValue pricesinfo(const UniValue& params, bool fHelp) From c19d636d7d5a0091e66354262bd75afc89c1beff Mon Sep 17 00:00:00 2001 From: dimxy Date: Mon, 22 Apr 2019 13:18:32 +0500 Subject: [PATCH 097/447] added all|open|close opt param to priceslist, mypriceslist --- src/cc/CCPrices.h | 2 +- src/cc/prices.cpp | 21 ++++++++++++++++++--- src/wallet/rpcwallet.cpp | 32 +++++++++++++++++++++++++++----- 3 files changed, 46 insertions(+), 9 deletions(-) diff --git a/src/cc/CCPrices.h b/src/cc/CCPrices.h index c7f3961d5..900ee7505 100644 --- a/src/cc/CCPrices.h +++ b/src/cc/CCPrices.h @@ -46,7 +46,7 @@ UniValue PricesSetcostbasis(int64_t txfee,uint256 bettxid); UniValue PricesRekt(int64_t txfee,uint256 bettxid,int32_t rektheight); UniValue PricesCashout(int64_t txfee,uint256 bettxid); UniValue PricesInfo(uint256 bettxid,int32_t refheight); -UniValue PricesList(CPubKey mypk); +UniValue PricesList(uint32_t filter, CPubKey mypk); #endif diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 425b125c1..06e64b739 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -1054,7 +1054,8 @@ UniValue PricesInfo(uint256 bettxid, int32_t refheight) { if (prices_betopretdecode(bettx.vout[numvouts - 1].scriptPubKey, pk, firstheight, positionsize, leverage, firstprice, vec, tokenid) == 'B') { - if (refheight > 0 && refheight < firstheight) { + // check acceptable refheight: + if (refheight < 0 || refheight > 0 && refheight < firstheight) { result.push_back(Pair("result", "error")); result.push_back(Pair("error", "incorrect height")); return(result); @@ -1113,7 +1114,7 @@ UniValue PricesInfo(uint256 bettxid, int32_t refheight) return(result); } -UniValue PricesList(CPubKey mypk) +UniValue PricesList(uint32_t filter, CPubKey mypk) { UniValue result(UniValue::VARR); std::vector > addressIndex; struct CCcontract_info *cp, C; @@ -1133,7 +1134,21 @@ UniValue PricesList(CPubKey mypk) if (vintx.vout.size() > 0 && prices_betopretdecode(vintx.vout[vintx.vout.size() - 1].scriptPubKey, pk, height, amount, leverage, firstprice, vec, tokenid) == 'B' && (mypk == CPubKey() || mypk == pk)) // if only mypubkey to list { - result.push_back(txid.GetHex()); + bool bAppend = false; + if (filter == 0) + bAppend = true; + else { + int32_t vini; + int32_t height; + uint256 finaltxid; + + int32_t spent = CCgetspenttxid(finaltxid, vini, height, txid, 2); + if (filter == 1 && spent < 0 || + filter == 2 && spent == 0) + bAppend = true; + } + if (bAppend) + result.push_back(txid.GetHex()); } } } diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 8c6e4530f..a25c879e2 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -6919,24 +6919,46 @@ UniValue faucetget(const UniValue& params, bool fHelp) return(result); } +uint32_t pricesGetParam(UniValue param) { + uint32_t filter = 0; + if (strcmpi(param.get_str().c_str(), "all") == 0) + filter = 0; + if (strcmpi(param.get_str().c_str(), "open") == 0) + filter = 1; + if (strcmpi(param.get_str().c_str(), "closed") == 0) + filter = 2; + else + throw runtime_error("incorrect parameter\n"); +} + UniValue priceslist(const UniValue& params, bool fHelp) { - if ( fHelp || params.size() > 0 ) - throw runtime_error("priceslist\n"); + if ( fHelp || params.size() != 0 || params.size() != 1) + throw runtime_error("priceslist [all|open|closed]\n"); if ( ensure_CCrequirements(EVAL_PRICES) < 0 ) throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + uint32_t filter = 0; + if (params.size() == 1) + filter = pricesGetParam(params[0]); + CPubKey emptypk; - return(PricesList(emptypk)); + + return(PricesList(filter, emptypk)); } UniValue mypriceslist(const UniValue& params, bool fHelp) { if (fHelp || params.size() > 0) - throw runtime_error("priceslist\n"); + throw runtime_error("mypriceslist [all|open|closed]\n"); if (ensure_CCrequirements(EVAL_PRICES) < 0) throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + + uint32_t filter = 0; + if (params.size() == 1) + filter = pricesGetParam(params[0]); CPubKey mypk = pubkey2pk(Mypubkey()); - return(PricesList(mypk)); + + return(PricesList(filter, mypk)); } UniValue pricesinfo(const UniValue& params, bool fHelp) From 8b763d971b49c3e59062e0a770a0af41cae66014 Mon Sep 17 00:00:00 2001 From: dimxy Date: Mon, 22 Apr 2019 13:24:27 +0500 Subject: [PATCH 098/447] added missing return --- src/wallet/rpcwallet.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index a25c879e2..01b3d72fb 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -59,6 +59,7 @@ #include #include "komodo_defs.h" +#include using namespace std; @@ -6929,6 +6930,7 @@ uint32_t pricesGetParam(UniValue param) { filter = 2; else throw runtime_error("incorrect parameter\n"); + return filter; } UniValue priceslist(const UniValue& params, bool fHelp) From b2c7484255db2743cf0add2dc38de171d6efeff6 Mon Sep 17 00:00:00 2001 From: dimxy Date: Mon, 22 Apr 2019 13:47:35 +0500 Subject: [PATCH 099/447] param to lower case --- src/cc/CCinclude.h | 1 + src/wallet/rpcwallet.cpp | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/cc/CCinclude.h b/src/cc/CCinclude.h index db1ee7475..21c987248 100644 --- a/src/cc/CCinclude.h +++ b/src/cc/CCinclude.h @@ -298,6 +298,7 @@ UniValue ValueFromAmount(const CAmount& amount); int64_t TotalPubkeyNormalInputs(const CTransaction &tx, const CPubKey &pubkey); int64_t TotalPubkeyCCInputs(const CTransaction &tx, const CPubKey &pubkey); +inline std::string STR_TOLOWER(const std::string &str) { std::string out; for (std::string::const_iterator i = str.begin(); i != str.end(); i++) out += std::tolower(*i); return out; } // bitcoin LogPrintStr with category "-debug" cmdarg support for C++ ostringstream: #define CCLOG_INFO 0 diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 01b3d72fb..4ac8c5f4e 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -6922,11 +6922,11 @@ UniValue faucetget(const UniValue& params, bool fHelp) uint32_t pricesGetParam(UniValue param) { uint32_t filter = 0; - if (strcmpi(param.get_str().c_str(), "all") == 0) + if (STR_TOLOWER(param.get_str()) == "all") filter = 0; - if (strcmpi(param.get_str().c_str(), "open") == 0) + if (STR_TOLOWER(param.get_str()) == "open") filter = 1; - if (strcmpi(param.get_str().c_str(), "closed") == 0) + if (STR_TOLOWER(param.get_str()) == "closed") filter = 2; else throw runtime_error("incorrect parameter\n"); From 0e3351557e353963f93c63240575adbb62b130ac Mon Sep 17 00:00:00 2001 From: dimxy Date: Mon, 22 Apr 2019 14:19:49 +0500 Subject: [PATCH 100/447] corr param num check --- 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 4ac8c5f4e..6cb13a1db 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -6924,9 +6924,9 @@ uint32_t pricesGetParam(UniValue param) { uint32_t filter = 0; if (STR_TOLOWER(param.get_str()) == "all") filter = 0; - if (STR_TOLOWER(param.get_str()) == "open") + else if (STR_TOLOWER(param.get_str()) == "open") filter = 1; - if (STR_TOLOWER(param.get_str()) == "closed") + else if (STR_TOLOWER(param.get_str()) == "closed") filter = 2; else throw runtime_error("incorrect parameter\n"); @@ -6935,7 +6935,7 @@ uint32_t pricesGetParam(UniValue param) { UniValue priceslist(const UniValue& params, bool fHelp) { - if ( fHelp || params.size() != 0 || params.size() != 1) + if ( fHelp || params.size() != 0 && params.size() != 1) throw runtime_error("priceslist [all|open|closed]\n"); if ( ensure_CCrequirements(EVAL_PRICES) < 0 ) throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); @@ -6950,7 +6950,7 @@ UniValue priceslist(const UniValue& params, bool fHelp) UniValue mypriceslist(const UniValue& params, bool fHelp) { - if (fHelp || params.size() > 0) + if (fHelp || params.size() != 0 && params.size() != 1) throw runtime_error("mypriceslist [all|open|closed]\n"); if (ensure_CCrequirements(EVAL_PRICES) < 0) throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); From 51e5260627517fab457fd5f9b1ab52dc26d49df8 Mon Sep 17 00:00:00 2001 From: dimxy Date: Mon, 22 Apr 2019 16:33:21 +0500 Subject: [PATCH 101/447] corrected profits calc - cast to int64 --- src/cc/prices.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 06e64b739..188b773ef 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -649,25 +649,25 @@ int64_t prices_syntheticprofits(int64_t &costbasis, int32_t firstheight, int32_t } } - else { + else { // use provided costbasis std::cerr << "prices_syntheticprofits() provided costbasis=" << costbasis << " price=" << price << std::endl; - if (costbasis == 0) - costbasis = price; + //if (costbasis == 0) + // costbasis = price; } profits = costbasis > 0 ? (((price / PRICES_NORMFACTOR * SATOSHIDEN) / costbasis) - SATOSHIDEN / PRICES_NORMFACTOR) * PRICES_NORMFACTOR : 0; std::cerr << "prices_syntheticprofits() test value1 (price/PRICES_NORMFACTOR * SATOSHIDEN)=" << (price / PRICES_NORMFACTOR * SATOSHIDEN) << std::endl; - std::cerr << "prices_syntheticprofits() test value2 (price/PRICES_NORMFACTOR * SATOSHIDEN)/costbasis=" << (costbasis != 0 ? (price / PRICES_NORMFACTOR * SATOSHIDEN)/costbasis : -1) << std::endl; + std::cerr << "prices_syntheticprofits() test value2 (price/PRICES_NORMFACTOR * SATOSHIDEN)/costbasis=" << (costbasis != 0 ? (price / PRICES_NORMFACTOR * SATOSHIDEN)/costbasis : 0) << std::endl; - std::cerr << "prices_syntheticprofits() fract profits=" << profits << std::endl; + std::cerr << "prices_syntheticprofits() fractional profits=" << profits << std::endl; //std::cerr << "prices_syntheticprofits() profits double=" << (double)price / (double)costbasis -1.0 << std::endl; //double dprofits = (double)price / (double)costbasis - 1.0; - profits *= leverage * positionsize / (int64_t)SATOSHIDEN; + profits *= ((int64_t)leverage * (int64_t)positionsize) / (int64_t)SATOSHIDEN; //dprofits *= leverage * positionsize; - std::cerr << "prices_syntheticprofits() val profits=" << profits << std::endl; + std::cerr << "prices_syntheticprofits() value of profits=" << profits << " leverage=" << leverage << " positionsize=" << positionsize << std::endl; //std::cerr << "prices_syntheticprofits() dprofits=" << dprofits << std::endl; @@ -1143,8 +1143,8 @@ UniValue PricesList(uint32_t filter, CPubKey mypk) uint256 finaltxid; int32_t spent = CCgetspenttxid(finaltxid, vini, height, txid, 2); - if (filter == 1 && spent < 0 || - filter == 2 && spent == 0) + if (filter == 1 && spent < 0 || // open positions + filter == 2 && spent == 0) // closed positions bAppend = true; } if (bAppend) From 1bdd83f1d1c690203ddfc0ea2a0a8f737fc4c23f Mon Sep 17 00:00:00 2001 From: dimxy Date: Mon, 22 Apr 2019 16:44:56 +0500 Subject: [PATCH 102/447] changed profits calc (prevent conversion to 0) --- src/cc/prices.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 188b773ef..a22c312b0 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -665,9 +665,10 @@ int64_t prices_syntheticprofits(int64_t &costbasis, int32_t firstheight, int32_t //std::cerr << "prices_syntheticprofits() profits double=" << (double)price / (double)costbasis -1.0 << std::endl; //double dprofits = (double)price / (double)costbasis - 1.0; - profits *= ((int64_t)leverage * (int64_t)positionsize) / (int64_t)SATOSHIDEN; + profits *= ((int64_t)leverage * (int64_t)positionsize); + profits /= (int64_t)SATOSHIDEN; //dprofits *= leverage * positionsize; - std::cerr << "prices_syntheticprofits() value of profits=" << profits << " leverage=" << leverage << " positionsize=" << positionsize << std::endl; + std::cerr << "prices_syntheticprofits() value of profits=" << profits << std::endl; //std::cerr << "prices_syntheticprofits() dprofits=" << dprofits << std::endl; From 96c82c5208f5d70b398fa0eee0896bc466b4c308 Mon Sep 17 00:00:00 2001 From: dimxy Date: Mon, 22 Apr 2019 23:48:47 +0500 Subject: [PATCH 103/447] corr validate for cashout --- src/cc/prices.cpp | 95 +++++++++++++++++++++++++++++++---------------- 1 file changed, 62 insertions(+), 33 deletions(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index a22c312b0..03af42d90 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -130,12 +130,13 @@ uint8_t prices_finalopretdecode(CScript scriptPubKey,uint256 &bettxid,int64_t &p } // price opret basic validation and retrieval -bool CheckPricesOpret(const CTransaction & tx, vscript_t &opret) +static bool CheckPricesOpret(const CTransaction & tx, vscript_t &opret) { return tx.vout.size() > 0 && GetOpReturnData(tx.vout.back().scriptPubKey, opret) && opret.size() > 2 && opret.begin()[0] == EVAL_PRICES && IS_CHARINSTR(opret.begin()[1], "BACF"); } -bool ValidateBetTx(struct CCcontract_info *cp, Eval *eval, const CTransaction & bettx) +// validate bet tx helper +static bool ValidateBetTx(struct CCcontract_info *cp, Eval *eval, const CTransaction & bettx) { uint256 tokenid; int64_t positionsize, firstprice; @@ -163,12 +164,13 @@ bool ValidateBetTx(struct CCcontract_info *cp, Eval *eval, const CTransaction & return true; } - -bool ValidateAddFundingTx(struct CCcontract_info *cp, Eval *eval, const CTransaction & addfundingtx) +// validate add funding tx helper +static bool ValidateAddFundingTx(struct CCcontract_info *cp, Eval *eval, const CTransaction & addfundingtx, const CTransaction & vintx) { uint256 bettxid; int64_t amount; CPubKey pk, pricespk; + vscript_t vintxOpret; if (addfundingtx.vout.size() < 3 || addfundingtx.vout.size() > 4) return eval->Invalid("incorrect vout number for add funding tx"); @@ -179,6 +181,9 @@ bool ValidateAddFundingTx(struct CCcontract_info *cp, Eval *eval, const CTransac pricespk = GetUnspendable(cp, 0); + if (CheckPricesOpret(vintx, vintxOpret) && vintxOpret.begin()[1] == 'B' && vintx.GetHash() != bettxid) // if vintx is bettx + return eval->Invalid("incorrect bettx id"); + if (MakeCC1vout(cp->evalcode, addfundingtx.vout[0].nValue, pk) != addfundingtx.vout[0]) return eval->Invalid("cannot validate vout0 in add funding tx with pk from opreturn"); if (MakeCC1vout(cp->evalcode, addfundingtx.vout[1].nValue, pricespk) != addfundingtx.vout[1]) @@ -187,7 +192,8 @@ bool ValidateAddFundingTx(struct CCcontract_info *cp, Eval *eval, const CTransac return true; } -bool ValidateCostbasisTx(struct CCcontract_info *cp, Eval *eval, const CTransaction & costbasistx, const CTransaction & bettx) +// validate costbasis tx helper +static bool ValidateCostbasisTx(struct CCcontract_info *cp, Eval *eval, const CTransaction & costbasistx, const CTransaction & bettx) { uint256 bettxid; int64_t amount; @@ -208,8 +214,11 @@ bool ValidateCostbasisTx(struct CCcontract_info *cp, Eval *eval, const CTransact if (MakeCC1vout(cp->evalcode, costbasistx.vout[1].nValue, pricespk) != costbasistx.vout[1]) return eval->Invalid("cannot validate vout1 in costbasis tx with global pk"); - if (bettx.vout.size() < 1) // maybe this is already checked outside, but it is safe to check here too and have encapsulated check - return eval->Invalid("incorrect bettx"); + if (bettx.GetHash() != bettxid) + return eval->Invalid("incorrect bettx id"); + + if (bettx.vout.size() < 1) // for safety and for check encapsulation + return eval->Invalid("incorrect bettx no vouts"); // check costbasis rules: if (costbasistx.vout[0].nValue > bettx.vout[1].nValue / 10) @@ -230,7 +239,8 @@ bool ValidateCostbasisTx(struct CCcontract_info *cp, Eval *eval, const CTransact return true; } -bool ValidateFinalTx(struct CCcontract_info *cp, Eval *eval, const CTransaction & finaltx) +// validate final tx helper +static bool ValidateFinalTx(struct CCcontract_info *cp, Eval *eval, const CTransaction & finaltx, const CTransaction & bettx) { uint256 bettxid; int64_t amount; @@ -247,6 +257,9 @@ bool ValidateFinalTx(struct CCcontract_info *cp, Eval *eval, const CTransaction if (prices_finalopretdecode(finaltx.vout.back().scriptPubKey, bettxid, profits, height, pk, firstprice, costbasis, addedbets, positionsize, leverage) != 'F') return eval->Invalid("cannot decode opreturn for final tx"); + if (bettx.GetHash() != bettxid) + return eval->Invalid("incorrect bettx id"); + pricespk = GetUnspendable(cp, 0); if (MakeCC1vout(cp->evalcode, finaltx.vout[0].nValue, pk) != finaltx.vout[0]) @@ -258,11 +271,11 @@ bool ValidateFinalTx(struct CCcontract_info *cp, Eval *eval, const CTransaction return true; } +// validate prices tx function bool PricesValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn) { vscript_t vopret; - if (strcmp(ASSETCHAINS_SYMBOL, "REKT0") == 0 && chainActive.Height() < 2100) return true; // check basic opret rules: @@ -271,28 +284,44 @@ bool PricesValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx uint8_t funcId = vopret.begin()[1]; - CTransaction vintx; - vscript_t vintxOpret; + CTransaction firstVinTx; + vscript_t firstVinTxOpret; + bool foundFirst = false; int32_t ccVinCount = 0; - int32_t prevoutN = 0; - // load vintx (might be either bet or add funding tx): + uint32_t prevoutN = 0; + + // check basic rules: + + // find first cc vin and load vintx (might be either bet or add funding tx): for (auto vin : tx.vin) if (cp->ismyvin(vin.scriptSig)) { + CTransaction vintx; uint256 hashBlock; + vscript_t vintxOpret; + if (!myGetTransaction(vin.prevout.hash, vintx, hashBlock)) - return eval->Invalid("cannot load vin tx"); - prevoutN = vin.prevout.n; + return eval->Invalid("cannot load vintx"); + + if (!CheckPricesOpret(vintx, vintxOpret)) + return eval->Invalid("cannot find prices opret in vintx"); + + if (vintxOpret.begin()[1] == 'B' && prevoutN == 3) { + return eval->Invalid("cannot spend bet marker"); + } + + if (!foundFirst) { + prevoutN = vin.prevout.n; + firstVinTx = vintx; + firstVinTxOpret = vintxOpret; + foundFirst = true; + } ccVinCount++; } - if (ccVinCount != 1) // must be only one cc vintx - return eval->Invalid("incorrect cc vin txns num"); + if (!foundFirst) + return eval->Invalid("prices cc vin not found"); - if (!CheckPricesOpret(vintx, vintxOpret)) - return eval->Invalid("cannot find prices opret in vintx"); - - if (vintxOpret.begin()[1] == 'B' && prevoutN == 3) { // check basic spending rules - return eval->Invalid("cannot spend bet marker"); - } + if (funcId != 'F' && ccVinCount > 1) + return eval->Invalid("only one prices cc vin allowed for this tx"); switch (funcId) { case 'B': // bet @@ -300,26 +329,26 @@ bool PricesValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx case 'A': // add funding // check tx structure: - if (!ValidateAddFundingTx(cp, eval, tx)) + if (!ValidateAddFundingTx(cp, eval, tx, firstVinTx)) return false; // invalid state is already set in the func - if (vintxOpret.begin()[1] == 'B') { - if (!ValidateBetTx(cp, eval, vintx)) // check tx structure + if (firstVinTxOpret.begin()[1] == 'B') { + if (!ValidateBetTx(cp, eval, firstVinTx)) // check tx structure return false; } - else if (vintxOpret.begin()[1] == 'A') { + else if (firstVinTxOpret.begin()[1] == 'A') { // no need to validate the previous addfunding tx (it was validated when added) } if (prevoutN != 0) { // check spending rules - return eval->Invalid("incorrect vout to spend"); + return eval->Invalid("incorrect vintx vout to spend"); } break; case 'C': // set costbasis - if (!ValidateBetTx(cp, eval, vintx)) // first check bet tx - return false; - if (!ValidateCostbasisTx(cp, eval, tx, vintx)) + if (!ValidateCostbasisTx(cp, eval, tx, firstVinTx)) + return false; + if (!ValidateBetTx(cp, eval, firstVinTx)) return false; if (prevoutN != 1) { // check spending rules return eval->Invalid("incorrect vout to spend"); @@ -328,9 +357,9 @@ bool PricesValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx break; case 'F': // final tx - if (!ValidateBetTx(cp, eval, vintx)) // first check bet tx + if (!ValidateFinalTx(cp, eval, tx, firstVinTx)) return false; - if (!ValidateFinalTx(cp, eval, tx)) + if (!ValidateBetTx(cp, eval, firstVinTx)) return false; if (prevoutN != 2) { // check spending rules return eval->Invalid("incorrect vout to spend"); From a4aad9e05b720209dad0c7d41f764f7cb454b98d Mon Sep 17 00:00:00 2001 From: dimxy Date: Tue, 23 Apr 2019 00:09:51 +0500 Subject: [PATCH 104/447] corr check vout0 validation in ValidateFinalTX --- src/cc/prices.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 03af42d90..a22127fe9 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -262,7 +262,7 @@ static bool ValidateFinalTx(struct CCcontract_info *cp, Eval *eval, const CTrans pricespk = GetUnspendable(cp, 0); - if (MakeCC1vout(cp->evalcode, finaltx.vout[0].nValue, pk) != finaltx.vout[0]) + if (CTxOut(finaltx.vout[0].nValue, CScript() << ParseHex(HexStr(pk)) << OP_CHECKSIG) != finaltx.vout[0]) return eval->Invalid("cannot validate vout0 in final tx with pk from opreturn"); if( finaltx.vout.size() == 3 && MakeCC1vout(cp->evalcode, finaltx.vout[1].nValue, pricespk) != finaltx.vout[1] ) @@ -272,6 +272,17 @@ static bool ValidateFinalTx(struct CCcontract_info *cp, Eval *eval, const CTrans } // validate prices tx function +// important checks: +// tx structure +// reference to the bet tx vout +// referenced bet tx structure +// referrenced bet txid in opret +// disable marker spending +// TODO: +// opret params (firstprice,positionsize...) +// cashout balance (PricesExactAmounts) +// costbasis calculation (?) +// use the special addr for fees bool PricesValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn) { vscript_t vopret; From b56dc25c8d95c93117af07e9e306e20a284929b5 Mon Sep 17 00:00:00 2001 From: dimxy Date: Tue, 23 Apr 2019 11:23:24 +0500 Subject: [PATCH 105/447] added logging to PricesList --- src/cc/prices.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index a22127fe9..999d35023 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -1172,10 +1172,10 @@ UniValue PricesList(uint32_t filter, CPubKey mypk) txid = it->first.txhash; if (GetTransaction(txid, vintx, hashBlock, false) != 0) { + bool bAppend = false; if (vintx.vout.size() > 0 && prices_betopretdecode(vintx.vout[vintx.vout.size() - 1].scriptPubKey, pk, height, amount, leverage, firstprice, vec, tokenid) == 'B' && (mypk == CPubKey() || mypk == pk)) // if only mypubkey to list { - bool bAppend = false; if (filter == 0) bAppend = true; else { @@ -1191,6 +1191,7 @@ UniValue PricesList(uint32_t filter, CPubKey mypk) if (bAppend) result.push_back(txid.GetHex()); } + std::cerr << "PricesList() " << " bettxid=" << txid.GetHex() << " mypk=" << HexStr(mypk) << " opret pk=" << HexStr(pk) << " filter=" << filter << " bAppend=" << bAppend << std::endl; } } return(result); From 37aa2fbe88a8897b42e8bdfb92b6cffb5fe13acb Mon Sep 17 00:00:00 2001 From: dimxy Date: Tue, 23 Apr 2019 14:23:16 +0500 Subject: [PATCH 106/447] test transaction moved to a separate file added a new test tx to try to spend bettx marker --- src/Makefile.am | 5 ++ src/cc/prices.cpp | 2 +- src/rpc/server.cpp | 4 - src/rpc/server.h | 6 -- src/wallet/rpcwallet.cpp | 178 --------------------------------------- 5 files changed, 6 insertions(+), 189 deletions(-) diff --git a/src/Makefile.am b/src/Makefile.am index 7e1647a6c..d335e0c04 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -524,6 +524,11 @@ if GLIBC_BACK_COMPAT libbitcoin_util_a_SOURCES += compat/glibc_compat.cpp endif +if ENABLE_TESTS +libbitcoin_util_a_SOURCES += rpc/testtransactions.cpp +endif + + # cli: zcash-cli libbitcoin_cli_a_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES) libbitcoin_cli_a_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 999d35023..99fc34711 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -331,7 +331,7 @@ bool PricesValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx if (!foundFirst) return eval->Invalid("prices cc vin not found"); - if (funcId != 'F' && ccVinCount > 1) + if (funcId != 'F' && ccVinCount > 1) // for all prices tx except final tx only one cc vin is allowed return eval->Invalid("only one prices cc vin allowed for this tx"); switch (funcId) { diff --git a/src/rpc/server.cpp b/src/rpc/server.cpp index 13f235e26..d18f551e6 100644 --- a/src/rpc/server.cpp +++ b/src/rpc/server.cpp @@ -571,10 +571,6 @@ static const CRPCCommand vRPCCommands[] = { "util", "reconsiderblock", &reconsiderblock, true }, /* Not shown in help */ { "hidden", "setmocktime", &setmocktime, true }, - { "hidden", "test_ac", &test_ac, true }, - { "hidden", "test_heirmarker", &test_heirmarker, true }, - { "hidden", "test_proof", &test_proof, true }, - { "hidden", "test_burntx", &test_burntx, true }, #ifdef ENABLE_WALLET diff --git a/src/rpc/server.h b/src/rpc/server.h index 98a0d046f..a215f9bc3 100644 --- a/src/rpc/server.h +++ b/src/rpc/server.h @@ -505,10 +505,4 @@ extern UniValue pricesrekt(const UniValue& params, bool fHelp); extern UniValue pricesaddfunding(const UniValue& params, bool fHelp); -// test rpc: -extern UniValue test_ac(const UniValue& params, bool fHelp); -extern UniValue test_heirmarker(const UniValue& params, bool fHelp); -extern UniValue test_burntx(const UniValue& params, bool fHelp); -extern UniValue test_proof(const UniValue& params, bool fHelp); - #endif // BITCOIN_RPCSERVER_H diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 6cb13a1db..8b9f82920 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -7972,181 +7972,3 @@ void RegisterWalletRPCCommands(CRPCTable &tableRPC) tableRPC.appendCommand(commands[vcidx].name, &commands[vcidx]); } -UniValue test_ac(const UniValue& params, bool fHelp) -{ - // make fake token tx: - struct CCcontract_info *cp, C; - - if (fHelp || (params.size() != 4)) - throw runtime_error("incorrect params\n"); - if (ensure_CCrequirements(EVAL_HEIR) < 0) - throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); - - std::vector pubkey1; - std::vector pubkey2; - - pubkey1 = ParseHex(params[0].get_str().c_str()); - pubkey2 = ParseHex(params[1].get_str().c_str()); - - CPubKey pk1 = pubkey2pk(pubkey1); - CPubKey pk2 = pubkey2pk(pubkey2); - - if(!pk1.IsValid() || !pk2.IsValid()) - throw runtime_error("invalid pubkey\n"); - - int64_t txfee = 10000; - int64_t amount = atoll(params[2].get_str().c_str()) * COIN; - uint256 fundingtxid = Parseuint256((char *)params[3].get_str().c_str()); - - CPubKey myPubkey = pubkey2pk(Mypubkey()); - CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - - int64_t normalInputs = AddNormalinputs(mtx, myPubkey, txfee + amount, 60); - - if( normalInputs < txfee + amount) - throw runtime_error("not enough normals\n"); - - mtx.vout.push_back(MakeCC1of2vout(EVAL_HEIR, amount, pk1, pk2)); - - CScript opret; - fundingtxid = revuint256(fundingtxid); - - opret << OP_RETURN << E_MARSHAL(ss << (uint8_t)EVAL_HEIR << (uint8_t)'A' << fundingtxid << (uint8_t)0); - - cp = CCinit(&C, EVAL_HEIR); - return(FinalizeCCTx(0, cp, mtx, myPubkey, txfee, opret)); -} - -UniValue test_heirmarker(const UniValue& params, bool fHelp) -{ - // make fake token tx: - struct CCcontract_info *cp, C; - - if (fHelp || (params.size() != 1)) - throw runtime_error("incorrect params\n"); - if (ensure_CCrequirements(EVAL_HEIR) < 0) - throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); - - uint256 fundingtxid = Parseuint256((char *)params[0].get_str().c_str()); - - CPubKey myPubkey = pubkey2pk(Mypubkey()); - CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - - int64_t normalInputs = AddNormalinputs(mtx, myPubkey, 10000, 60); - if (normalInputs < 10000) - throw runtime_error("not enough normals\n"); - - mtx.vin.push_back(CTxIn(fundingtxid, 1)); - mtx.vout.push_back(MakeCC1vout(EVAL_HEIR, 10000, myPubkey)); - - CScript opret; - fundingtxid = revuint256(fundingtxid); - - opret << OP_RETURN << E_MARSHAL(ss << (uint8_t)EVAL_HEIR << (uint8_t)'C' << fundingtxid << (uint8_t)0); - - cp = CCinit(&C, EVAL_HEIR); - return(FinalizeCCTx(0, cp, mtx, myPubkey, 10000, opret)); -} - -UniValue test_burntx(const UniValue& params, bool fHelp) -{ - // make fake token tx: - struct CCcontract_info *cp, C; - - if (fHelp || (params.size() != 1)) - throw runtime_error("incorrect params\n"); - if (ensure_CCrequirements(EVAL_TOKENS) < 0) - throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); - - uint256 tokenid = Parseuint256((char *)params[0].get_str().c_str()); - - CPubKey myPubkey = pubkey2pk(Mypubkey()); - CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - - int64_t normalInputs = AddNormalinputs(mtx, myPubkey, 10000, 60); - if (normalInputs < 10000) - throw runtime_error("not enough normals\n"); - - CPubKey burnpk = pubkey2pk(ParseHex(CC_BURNPUBKEY)); - - mtx.vin.push_back(CTxIn(tokenid, 0)); - mtx.vin.push_back(CTxIn(tokenid, 1)); - mtx.vout.push_back(MakeTokensCC1vout(EVAL_TOKENS, 1, burnpk)); - - std::vector voutPubkeys; - voutPubkeys.push_back(burnpk); - - cp = CCinit(&C, EVAL_TOKENS); - - std::vector vopret; - GetNonfungibleData(tokenid, vopret); - if (vopret.size() > 0) - cp->additionalTokensEvalcode2 = vopret.begin()[0]; - - uint8_t tokenpriv[33]; - char unspendableTokenAddr[64]; - CPubKey unspPk = GetUnspendable(cp, tokenpriv); - GetCCaddress(cp, unspendableTokenAddr, unspPk); - CCaddr2set(cp, EVAL_TOKENS, unspPk, tokenpriv, unspendableTokenAddr); - return(FinalizeCCTx(0, cp, mtx, myPubkey, 10000, EncodeTokenOpRet(tokenid, voutPubkeys, std::make_pair(0, vscript_t())))); -} - -UniValue test_proof(const UniValue& params, bool fHelp) -{ - UniValue result(UniValue::VOBJ); - std::vectorproof; - - if (fHelp || (params.size() != 2)) - throw runtime_error("incorrect params\n"); - - - proof = ParseHex(params[0].get_str()); - uint256 cointxid = Parseuint256((char *)params[1].get_str().c_str()); - - std::vector txids; - - CMerkleBlock merkleBlock; - if (!E_UNMARSHAL(proof, ss >> merkleBlock)) { - result.push_back(Pair("error", "could not unmarshal proof")); - return result; - } - uint256 merkleRoot = merkleBlock.txn.ExtractMatches(txids); - - result.push_back(Pair("source_root", merkleRoot.GetHex())); - - for (int i = 0; i < txids.size(); i++) - std::cerr << "merkle block txid=" << txids[0].GetHex() << std::endl; - - - std::vector vMatches(txids.size()); - for (auto v : vMatches) v = true; - CPartialMerkleTree verifTree(txids, vMatches); - - result.push_back(Pair("verif_root", verifTree.ExtractMatches(txids).GetHex())); - - if (std::find(txids.begin(), txids.end(), cointxid) == txids.end()) { - fprintf(stderr, "invalid proof for this cointxid\n"); - } - - std::vector vMerkleTree; - bool f; - ::BuildMerkleTree(&f, txids, vMerkleTree); - - std::vector vMerkleBranch = ::GetMerkleBranch(0, txids.size(), vMerkleTree); - - uint256 ourResult = SafeCheckMerkleBranch(zeroid, vMerkleBranch, 0); - result.push_back(Pair("SafeCheckMerkleBranch", ourResult.GetHex())); - - return result; -} - -void f(UniValue *p) { - - if (p) - p->push_back(make_pair("x", "y")); - - // or... - if (p) - (*p).push_back(make_pair("x", "y")); - -} \ No newline at end of file From c088fa62d59b511d57be83a7ec9caae2bf6b8b10 Mon Sep 17 00:00:00 2001 From: dimxy Date: Tue, 23 Apr 2019 14:32:40 +0500 Subject: [PATCH 107/447] testtransactions.cpp added --- src/rpc/testtransactions.cpp | 261 +++++++++++++++++++++++++++++++++++ 1 file changed, 261 insertions(+) create mode 100644 src/rpc/testtransactions.cpp diff --git a/src/rpc/testtransactions.cpp b/src/rpc/testtransactions.cpp new file mode 100644 index 000000000..3decf862b --- /dev/null +++ b/src/rpc/testtransactions.cpp @@ -0,0 +1,261 @@ +// Copyright (c) 2010 Satoshi Nakamoto +// Copyright (c) 2009-2014 The Bitcoin Core developers +// Distributed under the MIT software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + +#include "amount.h" +#include "chain.h" +#include "chainparams.h" +#include "checkpoints.h" +#include "crosschain.h" +#include "base58.h" +#include "consensus/validation.h" +#include "cc/eval.h" +#include "main.h" +#include "primitives/transaction.h" +#include "rpc/server.h" +#include "streams.h" +#include "sync.h" +#include "util.h" +#include "script/script.h" +#include "script/script_error.h" +#include "script/sign.h" +#include "script/standard.h" + +#include + +#include + +#include + +#include "cc/CCinclude.h" +#include "cc/CCPrices.h" + + +UniValue test_ac(const UniValue& params, bool fHelp) +{ + // make fake token tx: + struct CCcontract_info *cp, C; + + if (fHelp || (params.size() != 4)) + throw runtime_error("incorrect params\n"); + if (ensure_CCrequirements(EVAL_HEIR) < 0) + throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + + std::vector pubkey1; + std::vector pubkey2; + + pubkey1 = ParseHex(params[0].get_str().c_str()); + pubkey2 = ParseHex(params[1].get_str().c_str()); + + CPubKey pk1 = pubkey2pk(pubkey1); + CPubKey pk2 = pubkey2pk(pubkey2); + + if (!pk1.IsValid() || !pk2.IsValid()) + throw runtime_error("invalid pubkey\n"); + + int64_t txfee = 10000; + int64_t amount = atoll(params[2].get_str().c_str()) * COIN; + uint256 fundingtxid = Parseuint256((char *)params[3].get_str().c_str()); + + CPubKey myPubkey = pubkey2pk(Mypubkey()); + CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); + + int64_t normalInputs = AddNormalinputs(mtx, myPubkey, txfee + amount, 60); + + if (normalInputs < txfee + amount) + throw runtime_error("not enough normals\n"); + + mtx.vout.push_back(MakeCC1of2vout(EVAL_HEIR, amount, pk1, pk2)); + + CScript opret; + fundingtxid = revuint256(fundingtxid); + + opret << OP_RETURN << E_MARSHAL(ss << (uint8_t)EVAL_HEIR << (uint8_t)'A' << fundingtxid << (uint8_t)0); + + cp = CCinit(&C, EVAL_HEIR); + return(FinalizeCCTx(0, cp, mtx, myPubkey, txfee, opret)); +} + +UniValue test_heirmarker(const UniValue& params, bool fHelp) +{ + // make fake token tx: + struct CCcontract_info *cp, C; + + if (fHelp || (params.size() != 1)) + throw runtime_error("incorrect params\n"); + if (ensure_CCrequirements(EVAL_HEIR) < 0) + throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + + uint256 fundingtxid = Parseuint256((char *)params[0].get_str().c_str()); + + CPubKey myPubkey = pubkey2pk(Mypubkey()); + CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); + + int64_t normalInputs = AddNormalinputs(mtx, myPubkey, 10000, 60); + if (normalInputs < 10000) + throw runtime_error("not enough normals\n"); + + mtx.vin.push_back(CTxIn(fundingtxid, 1)); + mtx.vout.push_back(MakeCC1vout(EVAL_HEIR, 10000, myPubkey)); + + CScript opret; + fundingtxid = revuint256(fundingtxid); + + opret << OP_RETURN << E_MARSHAL(ss << (uint8_t)EVAL_HEIR << (uint8_t)'C' << fundingtxid << (uint8_t)0); + + cp = CCinit(&C, EVAL_HEIR); + return(FinalizeCCTx(0, cp, mtx, myPubkey, 10000, opret)); +} + +UniValue test_burntx(const UniValue& params, bool fHelp) +{ + // make fake token tx: + struct CCcontract_info *cp, C; + + if (fHelp || (params.size() != 1)) + throw runtime_error("incorrect params\n"); + if (ensure_CCrequirements(EVAL_TOKENS) < 0) + throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + + uint256 tokenid = Parseuint256((char *)params[0].get_str().c_str()); + + CPubKey myPubkey = pubkey2pk(Mypubkey()); + CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); + + int64_t normalInputs = AddNormalinputs(mtx, myPubkey, 10000, 60); + if (normalInputs < 10000) + throw runtime_error("not enough normals\n"); + + CPubKey burnpk = pubkey2pk(ParseHex(CC_BURNPUBKEY)); + + mtx.vin.push_back(CTxIn(tokenid, 0)); + mtx.vin.push_back(CTxIn(tokenid, 1)); + mtx.vout.push_back(MakeTokensCC1vout(EVAL_TOKENS, 1, burnpk)); + + std::vector voutPubkeys; + voutPubkeys.push_back(burnpk); + + cp = CCinit(&C, EVAL_TOKENS); + + std::vector vopret; + GetNonfungibleData(tokenid, vopret); + if (vopret.size() > 0) + cp->additionalTokensEvalcode2 = vopret.begin()[0]; + + uint8_t tokenpriv[33]; + char unspendableTokenAddr[64]; + CPubKey unspPk = GetUnspendable(cp, tokenpriv); + GetCCaddress(cp, unspendableTokenAddr, unspPk); + CCaddr2set(cp, EVAL_TOKENS, unspPk, tokenpriv, unspendableTokenAddr); + return(FinalizeCCTx(0, cp, mtx, myPubkey, 10000, EncodeTokenOpRet(tokenid, voutPubkeys, std::make_pair(0, vscript_t())))); +} + +UniValue test_proof(const UniValue& params, bool fHelp) +{ + UniValue result(UniValue::VOBJ); + std::vectorproof; + + if (fHelp || (params.size() != 2)) + throw runtime_error("incorrect params\n"); + + + proof = ParseHex(params[0].get_str()); + uint256 cointxid = Parseuint256((char *)params[1].get_str().c_str()); + + std::vector txids; + + CMerkleBlock merkleBlock; + if (!E_UNMARSHAL(proof, ss >> merkleBlock)) { + result.push_back(Pair("error", "could not unmarshal proof")); + return result; + } + uint256 merkleRoot = merkleBlock.txn.ExtractMatches(txids); + + result.push_back(Pair("source_root", merkleRoot.GetHex())); + + for (int i = 0; i < txids.size(); i++) + std::cerr << "merkle block txid=" << txids[0].GetHex() << std::endl; + + + std::vector vMatches(txids.size()); + for (auto v : vMatches) v = true; + CPartialMerkleTree verifTree(txids, vMatches); + + result.push_back(Pair("verif_root", verifTree.ExtractMatches(txids).GetHex())); + + if (std::find(txids.begin(), txids.end(), cointxid) == txids.end()) { + fprintf(stderr, "invalid proof for this cointxid\n"); + } + + std::vector vMerkleTree; + bool f; + ::BuildMerkleTree(&f, txids, vMerkleTree); + + std::vector vMerkleBranch = ::GetMerkleBranch(0, txids.size(), vMerkleTree); + + uint256 ourResult = SafeCheckMerkleBranch(zeroid, vMerkleBranch, 0); + result.push_back(Pair("SafeCheckMerkleBranch", ourResult.GetHex())); + + return result; +} + +UniValue test_pricesmarker(const UniValue& params, bool fHelp) +{ + // make fake token tx: + struct CCcontract_info *cp, C; + + if (fHelp || (params.size() != 1)) + throw runtime_error("incorrect params\n"); + if (ensure_CCrequirements(EVAL_PRICES) < 0) + throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + + uint256 bettxid = Parseuint256((char *)params[0].get_str().c_str()); + + cp = CCinit(&C, EVAL_PRICES); + CPubKey myPubkey = pubkey2pk(Mypubkey()); + CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); + + int64_t normalInputs = AddNormalinputs(mtx, myPubkey, 10000, 60); + if (normalInputs < 10000) + throw runtime_error("not enough normals\n"); + + mtx.vin.push_back(CTxIn(bettxid, 1)); + mtx.vout.push_back(CTxOut(1000, ParseHex(HexStr(myPubkey))); + + return(FinalizeCCTx(0, cp, mtx, myPubkey, 10000, CScript())); +} + + +static const CRPCCommand commands[] = +{ // category name actor (function) okSafeMode + // --------------------- ------------------------ ----------------------- ---------- + + /* Not shown in help */ + { "hidden", "test_ac", &test_ac, true }, + { "hidden", "test_heirmarker", &test_heirmarker, true }, + { "hidden", "test_proof", &test_proof, true }, + { "hidden", "test_burntx", &test_burntx, true }, + { "hidden", "test_pricesmarker", &test_pricesmarker, true } +}; + +void RegisterBlockchainRPCCommands(CRPCTable &tableRPC) +{ + for (unsigned int vcidx = 0; vcidx < ARRAYLEN(commands); vcidx++) + tableRPC.appendCommand(commands[vcidx].name, &commands[vcidx]); +} \ No newline at end of file From ea96f4d5284ce4600ef8d774c036045bfdf4eebb Mon Sep 17 00:00:00 2001 From: dimxy Date: Tue, 23 Apr 2019 14:37:45 +0500 Subject: [PATCH 108/447] moved testtransaction to server lib --- src/Makefile.am | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Makefile.am b/src/Makefile.am index d335e0c04..e6c1fbb14 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -525,7 +525,7 @@ libbitcoin_util_a_SOURCES += compat/glibc_compat.cpp endif if ENABLE_TESTS -libbitcoin_util_a_SOURCES += rpc/testtransactions.cpp +libbitcoin_server_a_SOURCES += rpc/testtransactions.cpp endif From f341b517a3a6360a859aa75d58f36c849174777b Mon Sep 17 00:00:00 2001 From: dimxy Date: Tue, 23 Apr 2019 14:51:36 +0500 Subject: [PATCH 109/447] corr include, syntax err --- src/rpc/testtransactions.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/rpc/testtransactions.cpp b/src/rpc/testtransactions.cpp index 3decf862b..85895a2df 100644 --- a/src/rpc/testtransactions.cpp +++ b/src/rpc/testtransactions.cpp @@ -18,6 +18,8 @@ * * ******************************************************************************/ +#include + #include "amount.h" #include "chain.h" #include "chainparams.h" @@ -43,9 +45,13 @@ #include + #include "cc/CCinclude.h" #include "cc/CCPrices.h" +using namespace std; + +int32_t ensure_CCrequirements(uint8_t evalcode); UniValue test_ac(const UniValue& params, bool fHelp) { @@ -236,7 +242,7 @@ UniValue test_pricesmarker(const UniValue& params, bool fHelp) throw runtime_error("not enough normals\n"); mtx.vin.push_back(CTxIn(bettxid, 1)); - mtx.vout.push_back(CTxOut(1000, ParseHex(HexStr(myPubkey))); + mtx.vout.push_back(CTxOut(1000, CScript() << ParseHex(HexStr(myPubkey)) << OP_CHECKSIG)); return(FinalizeCCTx(0, cp, mtx, myPubkey, 10000, CScript())); } From a8065c046224d2311919b97ad7fdadafbc6e4e05 Mon Sep 17 00:00:00 2001 From: dimxy Date: Tue, 23 Apr 2019 15:02:38 +0500 Subject: [PATCH 110/447] added testtransactions rpc to table --- src/rpc/register.h | 7 +++++++ src/rpc/testtransactions.cpp | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/rpc/register.h b/src/rpc/register.h index 072517d88..245f76e22 100644 --- a/src/rpc/register.h +++ b/src/rpc/register.h @@ -35,6 +35,10 @@ void RegisterMiningRPCCommands(CRPCTable &tableRPC); /** Register raw transaction RPC commands */ void RegisterRawTransactionRPCCommands(CRPCTable &tableRPC); +/** Register test transaction RPC commands */ +void RegisterTesttransactionsRPCCommands(CRPCTable &tableRPC); + + static inline void RegisterAllCoreRPCCommands(CRPCTable &tableRPC) { RegisterBlockchainRPCCommands(tableRPC); @@ -42,6 +46,9 @@ static inline void RegisterAllCoreRPCCommands(CRPCTable &tableRPC) RegisterMiscRPCCommands(tableRPC); RegisterMiningRPCCommands(tableRPC); RegisterRawTransactionRPCCommands(tableRPC); +#ifdef TESTMODE + RegisterTesttransactionsRPCCommands(tableRPC); +#endif } #endif diff --git a/src/rpc/testtransactions.cpp b/src/rpc/testtransactions.cpp index 85895a2df..35c35c8f8 100644 --- a/src/rpc/testtransactions.cpp +++ b/src/rpc/testtransactions.cpp @@ -260,7 +260,7 @@ static const CRPCCommand commands[] = { "hidden", "test_pricesmarker", &test_pricesmarker, true } }; -void RegisterBlockchainRPCCommands(CRPCTable &tableRPC) +void RegisterTesttransactionsRPCCommands(CRPCTable &tableRPC) { for (unsigned int vcidx = 0; vcidx < ARRAYLEN(commands); vcidx++) tableRPC.appendCommand(commands[vcidx].name, &commands[vcidx]); From 8982ffd91870b730b51f40f41d31f52216b1235b Mon Sep 17 00:00:00 2001 From: dimxy Date: Tue, 23 Apr 2019 15:10:26 +0500 Subject: [PATCH 111/447] added opret to test tx spending marker --- src/rpc/testtransactions.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/rpc/testtransactions.cpp b/src/rpc/testtransactions.cpp index 35c35c8f8..ddf7c8895 100644 --- a/src/rpc/testtransactions.cpp +++ b/src/rpc/testtransactions.cpp @@ -221,6 +221,7 @@ UniValue test_proof(const UniValue& params, bool fHelp) return result; } +extern CScript prices_costbasisopret(uint256 bettxid, CPubKey mypk, int32_t height, int64_t costbasis); UniValue test_pricesmarker(const UniValue& params, bool fHelp) { // make fake token tx: @@ -244,7 +245,7 @@ UniValue test_pricesmarker(const UniValue& params, bool fHelp) mtx.vin.push_back(CTxIn(bettxid, 1)); mtx.vout.push_back(CTxOut(1000, CScript() << ParseHex(HexStr(myPubkey)) << OP_CHECKSIG)); - return(FinalizeCCTx(0, cp, mtx, myPubkey, 10000, CScript())); + return(FinalizeCCTx(0, cp, mtx, myPubkey, 10000, prices_costbasisopret(bettxid, myPubkey, 100, 100))); } From 1bf4baf408e55b8bf82a43a3de49c566a8bcb480 Mon Sep 17 00:00:00 2001 From: dimxy Date: Tue, 23 Apr 2019 15:56:54 +0500 Subject: [PATCH 112/447] added normal inputs pubkey validation --- src/cc/prices.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 99fc34711..6982771cf 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -161,6 +161,15 @@ static bool ValidateBetTx(struct CCcontract_info *cp, Eval *eval, const CTransac if( MakeCC1vout(cp->evalcode, bettx.vout[2].nValue, pricespk) != bettx.vout[2] ) return eval->Invalid("cannot validate vout2 in bet tx with pk from opreturn"); + // validate if normal inputs are really signed by originator pubkey (someone not cheating with originator pubkey) + CAmount ccOutputs = 0; + for (auto vout : bettx.vout) + if (vout.scriptPubKey.IsPayToCryptoCondition()) + ccOutputs += vout.nValue; + CAmount normalInputs = TotalPubkeyNormalInputs(bettx, pk); + if (normalInputs < ccOutputs) + return eval->Invalid("bettx normal input signed with not pubkey in opret"); + return true; } From 36227f2e9cba7f76533380d2effadb6140db8fdb Mon Sep 17 00:00:00 2001 From: dimxy Date: Tue, 23 Apr 2019 16:39:53 +0500 Subject: [PATCH 113/447] test window=7 --- src/komodo_defs.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_defs.h b/src/komodo_defs.h index d5a9a21e2..02e51cd2f 100644 --- a/src/komodo_defs.h +++ b/src/komodo_defs.h @@ -42,7 +42,7 @@ #ifndef TESTMODE #define PRICES_DAYWINDOW ((3600*24/ASSETCHAINS_BLOCKTIME) + 1) #else -#define PRICES_DAYWINDOW (3) +#define PRICES_DAYWINDOW (7) #endif extern uint8_t ASSETCHAINS_TXPOW,ASSETCHAINS_PUBLIC; From dee7212413689d4d2aa9f100798bc6c5b75d58ea Mon Sep 17 00:00:00 2001 From: dimxy Date: Tue, 23 Apr 2019 16:47:58 +0500 Subject: [PATCH 114/447] temp pubkey validation removed --- src/cc/prices.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 6982771cf..b0d4a7952 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -167,7 +167,7 @@ static bool ValidateBetTx(struct CCcontract_info *cp, Eval *eval, const CTransac if (vout.scriptPubKey.IsPayToCryptoCondition()) ccOutputs += vout.nValue; CAmount normalInputs = TotalPubkeyNormalInputs(bettx, pk); - if (normalInputs < ccOutputs) + if (0 && normalInputs < ccOutputs) return eval->Invalid("bettx normal input signed with not pubkey in opret"); return true; From 3de3298e572e69bc607b81638485ac2e1b479ee9 Mon Sep 17 00:00:00 2001 From: dimxy Date: Tue, 23 Apr 2019 17:05:30 +0500 Subject: [PATCH 115/447] test bad pk to bettx --- src/cc/prices.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index b0d4a7952..e1d69206b 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -167,7 +167,7 @@ static bool ValidateBetTx(struct CCcontract_info *cp, Eval *eval, const CTransac if (vout.scriptPubKey.IsPayToCryptoCondition()) ccOutputs += vout.nValue; CAmount normalInputs = TotalPubkeyNormalInputs(bettx, pk); - if (0 && normalInputs < ccOutputs) + if (normalInputs < ccOutputs) return eval->Invalid("bettx normal input signed with not pubkey in opret"); return true; @@ -289,9 +289,9 @@ static bool ValidateFinalTx(struct CCcontract_info *cp, Eval *eval, const CTrans // disable marker spending // TODO: // opret params (firstprice,positionsize...) +// costbasis calculation // cashout balance (PricesExactAmounts) -// costbasis calculation (?) -// use the special addr for fees +// use the special address for 50% fees bool PricesValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn) { vscript_t vopret; @@ -843,7 +843,7 @@ UniValue PricesBet(int64_t txfee, int64_t amount, int16_t leverage, std::vector< mtx.vout.push_back(MakeCC1vout(cp->evalcode, (amount - betamount) + 2 * txfee, pricespk)); // vout1, when spent, costbasis is set mtx.vout.push_back(MakeCC1vout(cp->evalcode, betamount, pricespk)); mtx.vout.push_back(CTxOut(txfee, CScript() << ParseHex(HexStr(pricespk)) << OP_CHECKSIG)); // marker - rawtx = FinalizeCCTx(0, cp, mtx, mypk, txfee, prices_betopret(mypk, nextheight - 1, amount, leverage, firstprice, vec, zeroid)); + rawtx = FinalizeCCTx(0, cp, mtx, mypk, txfee, prices_betopret(/*mypk*/ pubkey2pk(ParseHex("03069fc09829259b3cd7b53bd97714498614f9ca323287bc783e39b02046f696db")), nextheight - 1, amount, leverage, firstprice, vec, zeroid)); return(prices_rawtxresult(result, rawtx, 0)); } result.push_back(Pair("result", "error")); From 37a09bf6cd180c1db84fbcafa8df0e852e9f7b85 Mon Sep 17 00:00:00 2001 From: dimxy Date: Tue, 23 Apr 2019 17:24:55 +0500 Subject: [PATCH 116/447] test bettx vout0 to fake pk --- src/cc/prices.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index e1d69206b..896cb37d3 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -839,7 +839,7 @@ UniValue PricesBet(int64_t txfee, int64_t amount, int16_t leverage, std::vector< if (AddNormalinputs(mtx, mypk, amount + 5 * txfee, 64) >= amount + 5 * txfee) { betamount = (amount * 199) / 200; - mtx.vout.push_back(MakeCC1vout(cp->evalcode, txfee, mypk)); // vout0 baton for total funding + mtx.vout.push_back(MakeCC1vout(cp->evalcode, txfee, /*mypk*/pubkey2pk(ParseHex("03069fc09829259b3cd7b53bd97714498614f9ca323287bc783e39b02046f696db")))); // vout0 baton for total funding mtx.vout.push_back(MakeCC1vout(cp->evalcode, (amount - betamount) + 2 * txfee, pricespk)); // vout1, when spent, costbasis is set mtx.vout.push_back(MakeCC1vout(cp->evalcode, betamount, pricespk)); mtx.vout.push_back(CTxOut(txfee, CScript() << ParseHex(HexStr(pricespk)) << OP_CHECKSIG)); // marker From db8619363c762ca5f601b80f3e0c57a22cea5628 Mon Sep 17 00:00:00 2001 From: dimxy Date: Tue, 23 Apr 2019 20:07:07 +0500 Subject: [PATCH 117/447] added costbasis validation removed cycling in setcostbasis --- src/cc/prices.cpp | 119 +++++++++++++++++++++++++++++++++------------- 1 file changed, 85 insertions(+), 34 deletions(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 896cb37d3..b9ca2e5d6 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -44,6 +44,8 @@ CBOPRET creates trustless oracles, which can be used for making a synthetic cash */ +int32_t prices_syntheticprofits(int64_t &costbasis, int32_t firstheight, int32_t height, int16_t leverage, std::vector vec, int64_t positionsize, int64_t addedbets, int64_t &profits, int64_t &outprice); + // helpers: // returns true if there are only digits and no alphas or slashes in 's' @@ -161,6 +163,10 @@ static bool ValidateBetTx(struct CCcontract_info *cp, Eval *eval, const CTransac if( MakeCC1vout(cp->evalcode, bettx.vout[2].nValue, pricespk) != bettx.vout[2] ) return eval->Invalid("cannot validate vout2 in bet tx with pk from opreturn"); + int64_t betamount = bettx.vout[2].nValue; + if( betamount != (positionsize * 199) / 200 ) + return eval->Invalid("invalid position size in the opreturn"); + // validate if normal inputs are really signed by originator pubkey (someone not cheating with originator pubkey) CAmount ccOutputs = 0; for (auto vout : bettx.vout) @@ -170,6 +176,9 @@ static bool ValidateBetTx(struct CCcontract_info *cp, Eval *eval, const CTransac if (normalInputs < ccOutputs) return eval->Invalid("bettx normal input signed with not pubkey in opret"); + if (leverage > PRICES_MAXLEVERAGE || leverage < -PRICES_MAXLEVERAGE) + return eval->Invalid("invalid leverage"); + return true; } @@ -205,7 +214,7 @@ static bool ValidateAddFundingTx(struct CCcontract_info *cp, Eval *eval, const C static bool ValidateCostbasisTx(struct CCcontract_info *cp, Eval *eval, const CTransaction & costbasistx, const CTransaction & bettx) { uint256 bettxid; - int64_t amount; + int64_t costbasisInOpret; CPubKey pk, pricespk; int32_t height; @@ -214,7 +223,7 @@ static bool ValidateCostbasisTx(struct CCcontract_info *cp, Eval *eval, const CT return eval->Invalid("incorrect vout count for costbasis tx"); vscript_t opret; - if (prices_costbasisopretdecode(costbasistx.vout.back().scriptPubKey, bettxid, pk, height, amount) != 'C') + if (prices_costbasisopretdecode(costbasistx.vout.back().scriptPubKey, bettxid, pk, height, costbasisInOpret) != 'C') return eval->Invalid("cannot decode opreturn for costbasis tx"); pricespk = GetUnspendable(cp, 0); @@ -244,6 +253,13 @@ static bool ValidateCostbasisTx(struct CCcontract_info *cp, Eval *eval, const CT if( firstheight + PRICES_DAYWINDOW + PRICES_SMOOTHWIDTH > chainActive.Height() ) return eval->Invalid("cannot calculate costbasis yet"); + + int64_t costbasis = 0, profits, lastprice; + int32_t retcode = prices_syntheticprofits(costbasis, firstheight, firstheight + PRICES_DAYWINDOW, leverage, vec, positionsize, 0, profits, lastprice); + if (retcode < 0) + return eval->Invalid("cannot calculate costbasis yet"); + if( costbasis != costbasisInOpret ) + return eval->Invalid("incorrect costbasis value"); return true; } @@ -281,12 +297,16 @@ static bool ValidateFinalTx(struct CCcontract_info *cp, Eval *eval, const CTrans } // validate prices tx function -// important checks: -// tx structure -// reference to the bet tx vout +// performed checks: +// basic tx structure (vout num) +// basic tx opret structure +// reference to the bet tx vout +// referenced bet txid in tx opret // referenced bet tx structure -// referrenced bet txid in opret -// disable marker spending +// non-final tx has only 1 cc vin +// cc vouts to self with mypubkey from opret +// cc vouts to global pk with global pk +// for bet tx that normal inputs digned with my pubkey from the opret >= cc outputs - disable betting for other pubkeys (Do we need this rule?) // TODO: // opret params (firstprice,positionsize...) // costbasis calculation @@ -661,22 +681,21 @@ int64_t prices_syntheticprice(std::vector vec, int32_t height, int32_t } // calculates profit/loss for the bet -int64_t prices_syntheticprofits(int64_t &costbasis, int32_t firstheight, int32_t height, int16_t leverage, std::vector vec, int64_t positionsize, int64_t addedbets, int64_t &outprice) +int32_t prices_syntheticprofits(int64_t &costbasis, int32_t firstheight, int32_t height, int16_t leverage, std::vector vec, int64_t positionsize, int64_t addedbets, int64_t &profits, int64_t &outprice) { - int64_t profits = 0; int64_t price; if (height < firstheight) { fprintf(stderr, "requested height is lower than bet firstheight.%d\n", height); - return 0; + return -1; } int32_t minmax = (height < firstheight + PRICES_DAYWINDOW); // if we are within 24h then use min or max value if ((price = prices_syntheticprice(vec, height, minmax, leverage)) < 0) { - fprintf(stderr, "unexpected zero synthetic price at height.%d\n", height); - return(0); + fprintf(stderr, "error getting synthetic price at height.%d\n", height); + return -1; } // clear lowest positions: @@ -684,7 +703,7 @@ int64_t prices_syntheticprofits(int64_t &costbasis, int32_t firstheight, int32_t price *= PRICES_NORMFACTOR; outprice = price; - if (minmax) { // if we are within day window, set costbasis to max or min price value + if (minmax) { // if we are within day window, set temp costbasis to max (or min) price value if (leverage > 0 && price > costbasis) { costbasis = price; // set temp costbasis std::cerr << "prices_syntheticprofits() minmax costbasis=" << costbasis << " price=" << price << std::endl; @@ -699,13 +718,17 @@ int64_t prices_syntheticprofits(int64_t &costbasis, int32_t firstheight, int32_t } else { - // use provided costbasis - std::cerr << "prices_syntheticprofits() provided costbasis=" << costbasis << " price=" << price << std::endl; - //if (costbasis == 0) - // costbasis = price; + if (costbasis == 0) { + // if costbasis not set, just set it + costbasis = price; + std::cerr << "prices_syntheticprofits() set costbasis=" << costbasis << std::endl; + } + else { + // use provided costbasis + std::cerr << "prices_syntheticprofits() provided costbasis=" << costbasis << " price=" << price << std::endl; + } } - profits = costbasis > 0 ? (((price / PRICES_NORMFACTOR * SATOSHIDEN) / costbasis) - SATOSHIDEN / PRICES_NORMFACTOR) * PRICES_NORMFACTOR : 0; std::cerr << "prices_syntheticprofits() test value1 (price/PRICES_NORMFACTOR * SATOSHIDEN)=" << (price / PRICES_NORMFACTOR * SATOSHIDEN) << std::endl; std::cerr << "prices_syntheticprofits() test value2 (price/PRICES_NORMFACTOR * SATOSHIDEN)/costbasis=" << (costbasis != 0 ? (price / PRICES_NORMFACTOR * SATOSHIDEN)/costbasis : 0) << std::endl; @@ -720,8 +743,7 @@ int64_t prices_syntheticprofits(int64_t &costbasis, int32_t firstheight, int32_t std::cerr << "prices_syntheticprofits() value of profits=" << profits << std::endl; //std::cerr << "prices_syntheticprofits() dprofits=" << dprofits << std::endl; - - return profits; // (positionsize + addedbets + profits); + return 0; // (positionsize + addedbets + profits); } void prices_betjson(UniValue &result,int64_t profits,int64_t costbasis,int64_t positionsize,int64_t addedbets,int16_t leverage,int32_t firstheight,int64_t firstprice, int64_t lastprice, int64_t equity) @@ -839,11 +861,11 @@ UniValue PricesBet(int64_t txfee, int64_t amount, int16_t leverage, std::vector< if (AddNormalinputs(mtx, mypk, amount + 5 * txfee, 64) >= amount + 5 * txfee) { betamount = (amount * 199) / 200; - mtx.vout.push_back(MakeCC1vout(cp->evalcode, txfee, /*mypk*/pubkey2pk(ParseHex("03069fc09829259b3cd7b53bd97714498614f9ca323287bc783e39b02046f696db")))); // vout0 baton for total funding + mtx.vout.push_back(MakeCC1vout(cp->evalcode, txfee, mypk)); // vout0 baton for total funding mtx.vout.push_back(MakeCC1vout(cp->evalcode, (amount - betamount) + 2 * txfee, pricespk)); // vout1, when spent, costbasis is set mtx.vout.push_back(MakeCC1vout(cp->evalcode, betamount, pricespk)); mtx.vout.push_back(CTxOut(txfee, CScript() << ParseHex(HexStr(pricespk)) << OP_CHECKSIG)); // marker - rawtx = FinalizeCCTx(0, cp, mtx, mypk, txfee, prices_betopret(/*mypk*/ pubkey2pk(ParseHex("03069fc09829259b3cd7b53bd97714498614f9ca323287bc783e39b02046f696db")), nextheight - 1, amount, leverage, firstprice, vec, zeroid)); + rawtx = FinalizeCCTx(0, cp, mtx, mypk, txfee, prices_betopret(mypk, nextheight - 1, amount, leverage, firstprice, vec, zeroid)); return(prices_rawtxresult(result, rawtx, 0)); } result.push_back(Pair("result", "error")); @@ -921,19 +943,24 @@ UniValue PricesSetcostbasis(int64_t txfee, uint256 bettxid) addedbets = prices_batontxid(batontxid, bettx, bettxid); mtx.vin.push_back(CTxIn(bettxid, 1, CScript())); // spend vin1 with betamount - for (i = 0; i < PRICES_DAYWINDOW + 1; i++) // the last datum for 24h is the costbasis value - { - profits = prices_syntheticprofits(costbasis, firstheight, firstheight + i, leverage, vec, positionsize, addedbets, lastprice); + //for (i = 0; i < PRICES_DAYWINDOW + 1; i++) // the last datum for 24h is the actual costbasis value + //{ + int32_t retcode = prices_syntheticprofits(costbasis, firstheight, firstheight + PRICES_DAYWINDOW, leverage, vec, positionsize, addedbets, profits, lastprice); + if (retcode < 0) { + result.push_back(Pair("result", "error")); + result.push_back(Pair("error", "cannot calculate costbasis error getting price")); + return(result); + } equity = positionsize + addedbets + profits; - if (equity < 0) + /*if (equity < 0) { // we are in loss result.push_back(Pair("rekt", (int64_t)1)); result.push_back(Pair("rektheight", (int64_t)firstheight + i)); break; - } - } - if (i == PRICES_DAYWINDOW + 1) - result.push_back(Pair("rekt", 0)); + }*/ + //} + //if (i == PRICES_DAYWINDOW + 1) + // result.push_back(Pair("rekt", 0)); prices_betjson(result, profits, costbasis, positionsize, addedbets, leverage, firstheight, firstprice, lastprice, equity); @@ -989,7 +1016,13 @@ UniValue PricesRekt(int64_t txfee, uint256 bettxid, int32_t rektheight) } addedbets = prices_batontxid(batontxid, bettx, bettxid); - profits = prices_syntheticprofits(costbasis, firstheight, rektheight, leverage, vec, positionsize, addedbets, lastprice); + int32_t retcode = prices_syntheticprofits(costbasis, firstheight, rektheight, leverage, vec, positionsize, addedbets, profits, lastprice); + if (retcode < 0) { + result.push_back(Pair("result", "error")); + result.push_back(Pair("error", "cannot get price")); + return(result); + } + equity = positionsize + addedbets + profits; if (equity < 0) { @@ -1058,7 +1091,12 @@ UniValue PricesCashout(int64_t txfee, uint256 bettxid) } addedbets = prices_batontxid(batontxid, bettx, bettxid); - profits = prices_syntheticprofits(costbasis, firstheight, nextheight - 1, leverage, vec, positionsize, addedbets, lastprice); + int32_t retcode = prices_syntheticprofits(costbasis, firstheight, nextheight - 1, leverage, vec, positionsize, addedbets, profits, lastprice); + if (retcode < 0) { + result.push_back(Pair("result", "error")); + result.push_back(Pair("error", "cannot get price")); + return(result); + } equity = positionsize + addedbets + profits; if (equity < 0) { @@ -1102,6 +1140,9 @@ UniValue PricesInfo(uint256 bettxid, int32_t refheight) if (myGetTransaction(bettxid, bettx, hashBlock) != 0 && (numvouts = bettx.vout.size()) > 3) { + if (hashBlock.IsNull()) + throw std::runtime_error("tx still in mempool"); + if (prices_betopretdecode(bettx.vout[numvouts - 1].scriptPubKey, pk, firstheight, positionsize, leverage, firstprice, vec, tokenid) == 'B') { // check acceptable refheight: @@ -1117,7 +1158,12 @@ UniValue PricesInfo(uint256 bettxid, int32_t refheight) addedbets = prices_batontxid(batontxid, bettx, bettxid); if (costbasis != 0) { // costbasis fixed - profits = prices_syntheticprofits(costbasis, firstheight, refheight, leverage, vec, positionsize, addedbets, lastprice); + int32_t retcode = prices_syntheticprofits(costbasis, firstheight, refheight, leverage, vec, positionsize, addedbets, profits, lastprice); + if (retcode < 0) { + result.push_back(Pair("result", "error")); + result.push_back(Pair("error", "cannot get price")); + return(result); + } equity = positionsize + addedbets + profits; if (equity < 0) { @@ -1132,7 +1178,12 @@ UniValue PricesInfo(uint256 bettxid, int32_t refheight) bool isRekt = false; for (i = 0; i < PRICES_DAYWINDOW + 1 && firstheight + i <= refheight; i++) // the last datum for 24h is the costbasis value { - profits = prices_syntheticprofits(costbasis, firstheight, firstheight + i, leverage, vec, positionsize, addedbets, lastprice); + int32_t retcode = prices_syntheticprofits(costbasis, firstheight, firstheight + i, leverage, vec, positionsize, addedbets, profits, lastprice); + if (retcode < 0) { + result.push_back(Pair("result", "error")); + result.push_back(Pair("error", "cannot get price")); + return(result); + } equity = positionsize + addedbets + profits; if (equity < 0) { // we are in loss From 187ce2a657150d5ff1e9b1748bc4f0196a99e200 Mon Sep 17 00:00:00 2001 From: dimxy Date: Tue, 23 Apr 2019 22:04:54 +0500 Subject: [PATCH 118/447] costbasis validation logging --- src/cc/prices.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index b9ca2e5d6..667dc681c 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -258,7 +258,8 @@ static bool ValidateCostbasisTx(struct CCcontract_info *cp, Eval *eval, const CT int32_t retcode = prices_syntheticprofits(costbasis, firstheight, firstheight + PRICES_DAYWINDOW, leverage, vec, positionsize, 0, profits, lastprice); if (retcode < 0) return eval->Invalid("cannot calculate costbasis yet"); - if( costbasis != costbasisInOpret ) + std::cerr << "ValidateCostbasisTx() costbasis=" << costbasis << " costbasisInOpret=" << costbasisInOpret << std::endl; + if( 0 && costbasis != costbasisInOpret ) return eval->Invalid("incorrect costbasis value"); return true; From 58577b64e1a9397d9a3e49ded568409a6e2052f0 Mon Sep 17 00:00:00 2001 From: dimxy Date: Tue, 23 Apr 2019 22:49:13 +0500 Subject: [PATCH 119/447] changed valid height --- src/cc/prices.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 667dc681c..7228ee9a8 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -317,7 +317,7 @@ bool PricesValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx { vscript_t vopret; - if (strcmp(ASSETCHAINS_SYMBOL, "REKT0") == 0 && chainActive.Height() < 2100) + if (strcmp(ASSETCHAINS_SYMBOL, "REKT0") == 0 && chainActive.Height() < 2965) return true; // check basic opret rules: if (!CheckPricesOpret(tx, vopret)) From b6f1b2dcc11007023e030a2c0b206e8573ad9b59 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Thu, 25 Apr 2019 10:14:23 +0800 Subject: [PATCH 120/447] remove print --- src/miner.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/miner.cpp b/src/miner.cpp index e199acccd..3e1ba3be2 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -721,7 +721,7 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 } return(0); } - fprintf(stderr, "Created notary payment coinbase totalsat.%lu\n",totalsats); + //fprintf(stderr, "Created notary payment coinbase totalsat.%lu\n",totalsats); } else fprintf(stderr, "vout 2 of notarisation is not OP_RETURN scriptlen.%i\n", scriptlen); } if ( ASSETCHAINS_CBOPRET != 0 ) From 57ef70d08eba39274364120167304bcc398f43ea Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Thu, 25 Apr 2019 10:48:21 +0800 Subject: [PATCH 121/447] fix notarizations left math error --- src/rpc/misc.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/rpc/misc.cpp b/src/rpc/misc.cpp index c2ba9d702..e8010ede3 100644 --- a/src/rpc/misc.cpp +++ b/src/rpc/misc.cpp @@ -1299,11 +1299,11 @@ UniValue getnotarypayinfo(const UniValue& params, bool fHelp) balance = checkburnaddress(received, TotalNotaryPay, height, "REDVp3ox1pbcWYCzySadfHhk8UU3HM4k5x"); notarycount = komodo_notaries(notarypubkeys, height, chainActive[height]->GetBlockTime()); - NotaryPay = komodo_notarypayamount(height, notarycount); + NotaryPay = komodo_notarypayamount(height, notarycount)*notarycount; bool spent = (received != balance); if ( !spent ) { - notaleft = (balance - TotalNotaryPay) / NotaryPay; + notaleft = ((int64_t)balance - TotalNotaryPay) / NotaryPay; daysleft = (((ASSETCHAINS_BLOCKTIME * 5) * notaleft) / 3600) / 24; endheight = (notaleft * 5) + height; } From 0331607b713b83eebc64ff8a241cdb3fb24bcc9f Mon Sep 17 00:00:00 2001 From: dimxy Date: Thu, 25 Apr 2019 13:15:22 +0500 Subject: [PATCH 122/447] costbasis calc now only for smoothed val added costbasis calc for added bets removed test windows 7 --- src/cc/prices.cpp | 215 +++++++++++++++++++++++++++------------------- src/komodo_defs.h | 8 +- 2 files changed, 132 insertions(+), 91 deletions(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 7228ee9a8..bf6eb46c7 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -132,9 +132,12 @@ uint8_t prices_finalopretdecode(CScript scriptPubKey,uint256 &bettxid,int64_t &p } // price opret basic validation and retrieval -static bool CheckPricesOpret(const CTransaction & tx, vscript_t &opret) +static uint8_t CheckPricesOpret(const CTransaction & tx, vscript_t &opret) { - return tx.vout.size() > 0 && GetOpReturnData(tx.vout.back().scriptPubKey, opret) && opret.size() > 2 && opret.begin()[0] == EVAL_PRICES && IS_CHARINSTR(opret.begin()[1], "BACF"); + if (tx.vout.size() > 0 && GetOpReturnData(tx.vout.back().scriptPubKey, opret) && opret.size() > 2 && opret.begin()[0] == EVAL_PRICES && IS_CHARINSTR(opret.begin()[1], "BACF")) + return opret.begin()[1]; + else + return (uint8_t)0; } // validate bet tx helper @@ -164,8 +167,10 @@ static bool ValidateBetTx(struct CCcontract_info *cp, Eval *eval, const CTransac return eval->Invalid("cannot validate vout2 in bet tx with pk from opreturn"); int64_t betamount = bettx.vout[2].nValue; - if( betamount != (positionsize * 199) / 200 ) + if (betamount != (positionsize * 199) / 200) { return eval->Invalid("invalid position size in the opreturn"); + std::cerr << "ValidateBetTx() " << "invalid position size in the opreturn" << std::endl; + } // validate if normal inputs are really signed by originator pubkey (someone not cheating with originator pubkey) CAmount ccOutputs = 0; @@ -173,11 +178,15 @@ static bool ValidateBetTx(struct CCcontract_info *cp, Eval *eval, const CTransac if (vout.scriptPubKey.IsPayToCryptoCondition()) ccOutputs += vout.nValue; CAmount normalInputs = TotalPubkeyNormalInputs(bettx, pk); - if (normalInputs < ccOutputs) - return eval->Invalid("bettx normal input signed with not pubkey in opret"); + if (normalInputs < ccOutputs) { + // return eval->Invalid("bettx normal inputs not signed with pubkey in opret"); + std::cerr << "ValidateBetTx() " << "warning: bettx normal inputs signed with pubkey in opreturn =" << normalInputs << std::endl; + } - if (leverage > PRICES_MAXLEVERAGE || leverage < -PRICES_MAXLEVERAGE) - return eval->Invalid("invalid leverage"); + if (leverage > PRICES_MAXLEVERAGE || leverage < -PRICES_MAXLEVERAGE) { + // return eval->Invalid("invalid leverage"); + std::cerr << "ValidateBetTx() " << "invalid leverage" << std::endl; + } return true; } @@ -199,8 +208,11 @@ static bool ValidateAddFundingTx(struct CCcontract_info *cp, Eval *eval, const C pricespk = GetUnspendable(cp, 0); - if (CheckPricesOpret(vintx, vintxOpret) && vintxOpret.begin()[1] == 'B' && vintx.GetHash() != bettxid) // if vintx is bettx - return eval->Invalid("incorrect bettx id"); + if (CheckPricesOpret(vintx, vintxOpret) != 'B') // if vintx is bettx + return eval->Invalid("incorrect bettx"); + + if (vintx.GetHash() != bettxid) // if vintx is bettx + return eval->Invalid("incorrect bet txid in opreturn"); if (MakeCC1vout(cp->evalcode, addfundingtx.vout[0].nValue, pk) != addfundingtx.vout[0]) return eval->Invalid("cannot validate vout0 in add funding tx with pk from opreturn"); @@ -239,8 +251,10 @@ static bool ValidateCostbasisTx(struct CCcontract_info *cp, Eval *eval, const CT return eval->Invalid("incorrect bettx no vouts"); // check costbasis rules: - if (costbasistx.vout[0].nValue > bettx.vout[1].nValue / 10) - return eval->Invalid("costbasis myfee too big"); + if (costbasistx.vout[0].nValue > bettx.vout[1].nValue / 10) { + // return eval->Invalid("costbasis myfee too big"); + std::cerr << "ValidateBetTx() " << "costbasis myfee too big" << std::endl; + } uint256 tokenid; int64_t positionsize, firstprice; @@ -251,16 +265,20 @@ static bool ValidateCostbasisTx(struct CCcontract_info *cp, Eval *eval, const CT if (prices_betopretdecode(bettx.vout.back().scriptPubKey, betpk, firstheight, positionsize, leverage, firstprice, vec, tokenid) != 'B') return eval->Invalid("cannot decode opreturn for bet tx"); - if( firstheight + PRICES_DAYWINDOW + PRICES_SMOOTHWIDTH > chainActive.Height() ) - return eval->Invalid("cannot calculate costbasis yet"); + if (firstheight + PRICES_DAYWINDOW + PRICES_SMOOTHWIDTH > chainActive.Height()) { + // return eval->Invalid("cannot calculate costbasis yet"); + std::cerr << "ValidateBetTx() " << "cannot calculate costbasis yet" << std::endl; + } int64_t costbasis = 0, profits, lastprice; int32_t retcode = prices_syntheticprofits(costbasis, firstheight, firstheight + PRICES_DAYWINDOW, leverage, vec, positionsize, 0, profits, lastprice); if (retcode < 0) return eval->Invalid("cannot calculate costbasis yet"); std::cerr << "ValidateCostbasisTx() costbasis=" << costbasis << " costbasisInOpret=" << costbasisInOpret << std::endl; - if( 0 && costbasis != costbasisInOpret ) - return eval->Invalid("incorrect costbasis value"); + if (costbasis != costbasisInOpret) { + // return eval->Invalid("incorrect costbasis value"); + std::cerr << "ValidateBetTx() " << "incorrect costbasis value" << std::endl; + } return true; } @@ -320,7 +338,7 @@ bool PricesValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx if (strcmp(ASSETCHAINS_SYMBOL, "REKT0") == 0 && chainActive.Height() < 2965) return true; // check basic opret rules: - if (!CheckPricesOpret(tx, vopret)) + if (CheckPricesOpret(tx, vopret) == 0) return eval->Invalid("tx has no prices opreturn"); uint8_t funcId = vopret.begin()[1]; @@ -334,7 +352,7 @@ bool PricesValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx // check basic rules: // find first cc vin and load vintx (might be either bet or add funding tx): - for (auto vin : tx.vin) + for (auto vin : tx.vin) { if (cp->ismyvin(vin.scriptSig)) { CTransaction vintx; uint256 hashBlock; @@ -343,12 +361,12 @@ bool PricesValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx if (!myGetTransaction(vin.prevout.hash, vintx, hashBlock)) return eval->Invalid("cannot load vintx"); - if (!CheckPricesOpret(vintx, vintxOpret)) + if (CheckPricesOpret(vintx, vintxOpret) == 0) return eval->Invalid("cannot find prices opret in vintx"); - if (vintxOpret.begin()[1] == 'B' && prevoutN == 3) { - return eval->Invalid("cannot spend bet marker"); - } + //if (vintxOpret.begin()[1] == 'B' && prevoutN == 3) { + // return eval->Invalid("cannot spend bet marker"); + //} if (!foundFirst) { prevoutN = vin.prevout.n; @@ -358,6 +376,7 @@ bool PricesValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx } ccVinCount++; } + } if (!foundFirst) return eval->Invalid("prices cc vin not found"); @@ -550,7 +569,7 @@ int64_t prices_syntheticprice(std::vector vec, int32_t height, int32_t { std::cerr << "prices_syntheticprice" << " pricedata[0]=" << pricedata[0] << " pricedata[1]=" << pricedata[1] << " pricedata[2]=" << pricedata[2] << std::endl; // push price to the prices stack - if (!minmax) + /*if (!minmax) pricestack[depth] = pricedata[2]; // use smoothed value if we are over 24h else { @@ -559,8 +578,12 @@ int64_t prices_syntheticprice(std::vector vec, int32_t height, int32_t pricestack[depth] = (pricedata[1] > pricedata[2]) ? pricedata[1] : pricedata[2]; // MAX else pricestack[depth] = (pricedata[1] < pricedata[2]) ? pricedata[1] : pricedata[2]; // MIN - } + }*/ + pricestack[depth] = pricedata[2]; } + else + errcode = -1; + if (pricestack[depth] == 0) errcode = -1; @@ -682,7 +705,7 @@ int64_t prices_syntheticprice(std::vector vec, int32_t height, int32_t } // calculates profit/loss for the bet -int32_t prices_syntheticprofits(int64_t &costbasis, int32_t firstheight, int32_t height, int16_t leverage, std::vector vec, int64_t positionsize, int64_t addedbets, int64_t &profits, int64_t &outprice) +int32_t prices_syntheticprofits(int64_t &costbasis, int32_t firstheight, int32_t height, int16_t leverage, std::vector vec, int64_t positionsize, int64_t &profits, int64_t &outprice) { int64_t price; @@ -794,30 +817,33 @@ int64_t prices_costbasis(CTransaction bettx, uint256 &txidCostbasis) } // calculates added bet total, returns the last baton txid -int64_t prices_batontxid(uint256 &batontxid, CTransaction bettx, uint256 bettxid) +int64_t prices_enumaddedbets(uint256 &batontxid, std::vector> &addedBets, uint256 bettxid) { - int64_t addedbets = 0; + int64_t addedBetsTotal = 0; int32_t vini; int32_t height; int32_t retcode; batontxid = bettxid; // initially set to the source bet tx uint256 sourcetxid = bettxid; + addedBets.clear(); // iterate through batons, adding up vout1 -> addedbets while ((retcode = CCgetspenttxid(batontxid, vini, height, sourcetxid, 0)) == 0) { CTransaction txBaton; - uint256 hashBlock; - uint256 bettxid; + CBlockIndex blockIdx; + uint256 bettxidInOpret; CPubKey pk; bool isLoaded = false; uint8_t funcId = 0; int64_t amount; + EvalRef eval; - if ((isLoaded = myGetTransaction(batontxid, txBaton, hashBlock)) && + if ((isLoaded = eval->GetTxConfirmed(batontxid, txBaton, blockIdx)) && txBaton.vout.size() > 0 && - (funcId = prices_addopretdecode(txBaton.vout.back().scriptPubKey, bettxid, pk, amount)) != 0) { - addedbets += amount; + (funcId = prices_addopretdecode(txBaton.vout.back().scriptPubKey, bettxidInOpret, pk, amount)) != 0) { + addedBetsTotal += amount; + addedBets.push_back(std::make_pair(blockIdx.GetHeight(), amount)); std::cerr << "prices_batontxid() added amount=" << amount << std::endl; } else { @@ -827,7 +853,7 @@ int64_t prices_batontxid(uint256 &batontxid, CTransaction bettx, uint256 bettxid sourcetxid = batontxid; } - return(addedbets); + return(addedBetsTotal); } UniValue PricesBet(int64_t txfee, int64_t amount, int16_t leverage, std::vector synthetic) @@ -894,7 +920,8 @@ UniValue PricesAddFunding(int64_t txfee, uint256 bettxid, int64_t amount) //GetCCaddress(cp, myaddr, mypk); if (AddNormalinputs(mtx, mypk, amount + 2*txfee, 64) >= amount + 2*txfee) { - if (prices_batontxid(batontxid, bettx, bettxid) >= 0) + std::vector> addedBets; + if (prices_enumaddedbets(batontxid, addedBets, bettxid) >= 0) { mtx.vin.push_back(CTxIn(batontxid, 0, CScript())); mtx.vout.push_back(MakeCC1vout(cp->evalcode, txfee, mypk)); // baton for total funding @@ -915,6 +942,7 @@ UniValue PricesAddFunding(int64_t txfee, uint256 bettxid, int64_t amount) } // set cost basis (open price) for the bet + UniValue PricesSetcostbasis(int64_t txfee, uint256 bettxid) { int32_t nextheight = komodo_nextheight(); @@ -925,7 +953,7 @@ UniValue PricesSetcostbasis(int64_t txfee, uint256 bettxid) int32_t i, firstheight = 0, height, numvouts; int16_t leverage = 0; std::vector vec; CPubKey pk, mypk, pricespk; std::string rawtx; - +/* cp = CCinit(&C, EVAL_PRICES); if (txfee == 0) txfee = PRICES_TXFEE; @@ -942,7 +970,7 @@ UniValue PricesSetcostbasis(int64_t txfee, uint256 bettxid) return(result); } - addedbets = prices_batontxid(batontxid, bettx, bettxid); + addedbets = prices_enumaddedbets(batontxid, bettx, bettxid); mtx.vin.push_back(CTxIn(bettxid, 1, CScript())); // spend vin1 with betamount //for (i = 0; i < PRICES_DAYWINDOW + 1; i++) // the last datum for 24h is the actual costbasis value //{ @@ -953,12 +981,12 @@ UniValue PricesSetcostbasis(int64_t txfee, uint256 bettxid) return(result); } equity = positionsize + addedbets + profits; - /*if (equity < 0) - { // we are in loss - result.push_back(Pair("rekt", (int64_t)1)); - result.push_back(Pair("rektheight", (int64_t)firstheight + i)); - break; - }*/ + //if (equity < 0) + //{ // we are in loss + // result.push_back(Pair("rekt", (int64_t)1)); + // result.push_back(Pair("rektheight", (int64_t)firstheight + i)); + // break; + //} //} //if (i == PRICES_DAYWINDOW + 1) // result.push_back(Pair("rekt", 0)); @@ -972,7 +1000,7 @@ UniValue PricesSetcostbasis(int64_t txfee, uint256 bettxid) mtx.vout.push_back(CTxOut(myfee, CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); mtx.vout.push_back(MakeCC1vout(cp->evalcode, bettx.vout[1].nValue - myfee, pricespk)); - rawtx = FinalizeCCTx(0, cp, mtx, mypk, txfee, prices_costbasisopret(bettxid, mypk, firstheight + PRICES_DAYWINDOW /*- 1*/, costbasis)); + rawtx = FinalizeCCTx(0, cp, mtx, mypk, txfee, prices_costbasisopret(bettxid, mypk, firstheight + PRICES_DAYWINDOW , costbasis)); // -1 return(prices_rawtxresult(result, rawtx, 0)); } result.push_back(Pair("result", "error")); @@ -981,7 +1009,7 @@ UniValue PricesSetcostbasis(int64_t txfee, uint256 bettxid) } } result.push_back(Pair("result", "error")); - result.push_back(Pair("error", "cant find bettxid")); + result.push_back(Pair("error", "cant find bettxid")); */ return(result); } @@ -1009,6 +1037,8 @@ UniValue PricesRekt(int64_t txfee, uint256 bettxid, int32_t rektheight) if (prices_betopretdecode(bettx.vout[numvouts - 1].scriptPubKey, pk, firstheight, positionsize, leverage, firstprice, vec, tokenid) == 'B') { uint256 costbasistxid; + std::vector> addedBets; + costbasis = prices_costbasis(bettx, costbasistxid); if (costbasis == 0) { result.push_back(Pair("result", "error")); @@ -1016,7 +1046,7 @@ UniValue PricesRekt(int64_t txfee, uint256 bettxid, int32_t rektheight) return(result); } - addedbets = prices_batontxid(batontxid, bettx, bettxid); + addedbets = prices_enumaddedbets(batontxid, addedBets, bettxid); int32_t retcode = prices_syntheticprofits(costbasis, firstheight, rektheight, leverage, vec, positionsize, addedbets, profits, lastprice); if (retcode < 0) { result.push_back(Pair("result", "error")); @@ -1083,6 +1113,7 @@ UniValue PricesCashout(int64_t txfee, uint256 bettxid) if (prices_betopretdecode(bettx.vout[numvouts - 1].scriptPubKey, pk, firstheight, positionsize, leverage, firstprice, vec, tokenid) == 'B') { uint256 costbasistxid; + std::vector> addedBets; costbasis = prices_costbasis(bettx, costbasistxid); if (costbasis == 0) { @@ -1091,7 +1122,7 @@ UniValue PricesCashout(int64_t txfee, uint256 bettxid) return(result); } - addedbets = prices_batontxid(batontxid, bettx, bettxid); + addedbets = prices_enumaddedbets(batontxid, addedBets, bettxid); int32_t retcode = prices_syntheticprofits(costbasis, firstheight, nextheight - 1, leverage, vec, positionsize, addedbets, profits, lastprice); if (retcode < 0) { result.push_back(Pair("result", "error")); @@ -1126,12 +1157,24 @@ UniValue PricesCashout(int64_t txfee, uint256 bettxid) return(result); } +int32_t prices_scanchain(const CTransaction &tx, int64_t &costbasis, int64_t lastprice) { + + vscript_t opret; + uint8_t funcId; + if (tx.vout.size() < 1 || (funcId = CheckPricesOpret(tx, opret)) == 0) { + std::cerr << "prices_scanchain() " << "incorrect tx, must be \'B\' or \'A\'" << std::endl; + return -1; + } + return 0; +} + + UniValue PricesInfo(uint256 bettxid, int32_t refheight) { UniValue result(UniValue::VOBJ); CTransaction bettx; uint256 hashBlock, batontxid, tokenid; - int64_t myfee, ignore = 0, positionsize = 0, addedbets = 0, firstprice = 0, lastprice, profits = 0, costbasis = 0, equity; + int64_t myfee, ignore = 0, positionsize = 0, addedbets = 0, firstprice = 0, lastprice = 0, costbasis = 0, equity; int32_t i, firstheight = 0, height, numvouts; int16_t leverage = 0; std::vector vec; @@ -1155,59 +1198,57 @@ UniValue PricesInfo(uint256 bettxid, int32_t refheight) if (refheight == 0) refheight = komodo_nextheight()-1; - costbasis = prices_costbasis(bettx, costbasistxid); - addedbets = prices_batontxid(batontxid, bettx, bettxid); + //costbasis = prices_costbasis(bettx, costbasistxid); + std::vector> addedbets; + prices_enumaddedbets(batontxid, addedbets, bettxid); - if (costbasis != 0) { // costbasis fixed - int32_t retcode = prices_syntheticprofits(costbasis, firstheight, refheight, leverage, vec, positionsize, addedbets, profits, lastprice); + + bool isRekt = false; + int64_t totalprofits = 0, totaladdedbets = 0; + + for (int32_t h = firstheight; ; h++) // the last datum for 24h is the costbasis value + { + int64_t profits, lastprice; + int32_t retcode = prices_syntheticprofits(costbasis, firstheight, h, leverage, vec, positionsize, profits, lastprice); if (retcode < 0) { - result.push_back(Pair("result", "error")); - result.push_back(Pair("error", "cannot get price")); - return(result); + std::cerr << "PricesInfo() prices_syntheticprofits returned -1, stopping" << std::endl; + break; } - equity = positionsize + addedbets + profits; - if (equity < 0) - { - result.push_back(Pair("rekt", 1)); - result.push_back(Pair("rektfee", (positionsize + addedbets) / 500)); - result.push_back(Pair("rektheight", (int64_t)refheight)); - } - else - result.push_back(Pair("rekt", 0)); - } - else { - bool isRekt = false; - for (i = 0; i < PRICES_DAYWINDOW + 1 && firstheight + i <= refheight; i++) // the last datum for 24h is the costbasis value - { - int32_t retcode = prices_syntheticprofits(costbasis, firstheight, firstheight + i, leverage, vec, positionsize, addedbets, profits, lastprice); + totalprofits = profits; + + for (int i = 0; i < addedbets.size(); i++) { + // get profits for added bets: + int64_t costbasis = 0; // costbasis for added bet + int32_t retcode = prices_syntheticprofits(costbasis, addedbets[i].first, h, leverage, vec, addedbets[i].second, profits, lastprice); if (retcode < 0) { - result.push_back(Pair("result", "error")); - result.push_back(Pair("error", "cannot get price")); - return(result); - } - equity = positionsize + addedbets + profits; - if (equity < 0) - { // we are in loss - result.push_back(Pair("rekt", (int64_t)1)); - result.push_back(Pair("rektfee", (positionsize + addedbets) / 500)); - result.push_back(Pair("rektheight", (int64_t)firstheight + i)); - isRekt = true; + std::cerr << "PricesInfo() error: prices_syntheticprofits returned -1 for addedbet" << std::endl; break; } + totalprofits += profits; + totaladdedbets += addedbets[i].second; + } + + equity = positionsize + totaladdedbets + totalprofits; + if (equity < 0) + { // we are in loss + result.push_back(Pair("rekt", (int64_t)1)); + result.push_back(Pair("rektfee", (positionsize + totaladdedbets) / 500)); + result.push_back(Pair("rektheight", (int64_t)h)); + isRekt = true; + break; } - if (!isRekt /*i == PRICES_DAYWINDOW + 1*/) - result.push_back(Pair("rekt", 0)); } - - + if (!isRekt) + result.push_back(Pair("rekt", 0)); + result.push_back(Pair("batontxid", batontxid.GetHex())); if(!costbasistxid.IsNull()) result.push_back(Pair("costbasistxid", costbasistxid.GetHex())); - prices_betjson(result, profits, costbasis, positionsize, addedbets, leverage, firstheight, firstprice, lastprice, equity); + prices_betjson(result, totalprofits, costbasis, positionsize, totaladdedbets, leverage, firstheight, firstprice, lastprice, equity); result.push_back(Pair("height", (int64_t)refheight)); -#ifdef TESTMODE - result.push_back(Pair("test_daywindow", PRICES_DAYWINDOW)); -#endif +//#ifdef TESTMODE +// result.push_back(Pair("test_daywindow", PRICES_DAYWINDOW)); +//#endif return(result); } } diff --git a/src/komodo_defs.h b/src/komodo_defs.h index 02e51cd2f..bcfc4ff4b 100644 --- a/src/komodo_defs.h +++ b/src/komodo_defs.h @@ -39,11 +39,11 @@ #define KOMODO_BIT63SET(x) ((x) & ((uint64_t)1 << 63)) #define KOMODO_VALUETOOBIG(x) ((x) > (uint64_t)10000000001*COIN) -#ifndef TESTMODE +//#ifndef TESTMODE #define PRICES_DAYWINDOW ((3600*24/ASSETCHAINS_BLOCKTIME) + 1) -#else -#define PRICES_DAYWINDOW (7) -#endif +//#else +//#define PRICES_DAYWINDOW (7) +//#endif extern uint8_t ASSETCHAINS_TXPOW,ASSETCHAINS_PUBLIC; int32_t MAX_BLOCK_SIZE(int32_t height); From f290e2e2b3b89f3519f7f2bacb0fcd8666976e73 Mon Sep 17 00:00:00 2001 From: dimxy Date: Thu, 25 Apr 2019 13:23:42 +0500 Subject: [PATCH 123/447] corr link err (corr func def) --- src/cc/prices.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index bf6eb46c7..23e0f50ad 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -44,7 +44,7 @@ CBOPRET creates trustless oracles, which can be used for making a synthetic cash */ -int32_t prices_syntheticprofits(int64_t &costbasis, int32_t firstheight, int32_t height, int16_t leverage, std::vector vec, int64_t positionsize, int64_t addedbets, int64_t &profits, int64_t &outprice); +int32_t prices_syntheticprofits(int64_t &costbasis, int32_t firstheight, int32_t height, int16_t leverage, std::vector vec, int64_t positionsize, int64_t &profits, int64_t &outprice); // helpers: @@ -271,7 +271,7 @@ static bool ValidateCostbasisTx(struct CCcontract_info *cp, Eval *eval, const CT } int64_t costbasis = 0, profits, lastprice; - int32_t retcode = prices_syntheticprofits(costbasis, firstheight, firstheight + PRICES_DAYWINDOW, leverage, vec, positionsize, 0, profits, lastprice); + int32_t retcode = prices_syntheticprofits(costbasis, firstheight, firstheight + PRICES_DAYWINDOW, leverage, vec, positionsize, profits, lastprice); if (retcode < 0) return eval->Invalid("cannot calculate costbasis yet"); std::cerr << "ValidateCostbasisTx() costbasis=" << costbasis << " costbasisInOpret=" << costbasisInOpret << std::endl; @@ -1047,7 +1047,7 @@ UniValue PricesRekt(int64_t txfee, uint256 bettxid, int32_t rektheight) } addedbets = prices_enumaddedbets(batontxid, addedBets, bettxid); - int32_t retcode = prices_syntheticprofits(costbasis, firstheight, rektheight, leverage, vec, positionsize, addedbets, profits, lastprice); + int32_t retcode = prices_syntheticprofits(costbasis, firstheight, rektheight, leverage, vec, positionsize, profits, lastprice); if (retcode < 0) { result.push_back(Pair("result", "error")); result.push_back(Pair("error", "cannot get price")); @@ -1123,7 +1123,7 @@ UniValue PricesCashout(int64_t txfee, uint256 bettxid) } addedbets = prices_enumaddedbets(batontxid, addedBets, bettxid); - int32_t retcode = prices_syntheticprofits(costbasis, firstheight, nextheight - 1, leverage, vec, positionsize, addedbets, profits, lastprice); + int32_t retcode = prices_syntheticprofits(costbasis, firstheight, nextheight - 1, leverage, vec, positionsize, profits, lastprice); if (retcode < 0) { result.push_back(Pair("result", "error")); result.push_back(Pair("error", "cannot get price")); From 1c4c7f677ac2be4c01a6d1abf1897ab680f84ea0 Mon Sep 17 00:00:00 2001 From: dimxy Date: Thu, 25 Apr 2019 15:21:22 +0500 Subject: [PATCH 124/447] added prices_scanchain func added all bets params to json --- src/cc/prices.cpp | 219 ++++++++++++++++++++++++++++------------------ 1 file changed, 136 insertions(+), 83 deletions(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 23e0f50ad..b0147cdd8 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -18,6 +18,13 @@ #define IS_CHARINSTR(c, str) (std::string(str).find((char)(c)) != std::string::npos) +typedef struct BetInfo { + int64_t amount; + int32_t firstheight; + int64_t costbasis; + int64_t profits; +} betinfo; + /* CBOPRET creates trustless oracles, which can be used for making a synthetic cash settlement system based on real world prices; @@ -770,17 +777,30 @@ int32_t prices_syntheticprofits(int64_t &costbasis, int32_t firstheight, int32_t return 0; // (positionsize + addedbets + profits); } -void prices_betjson(UniValue &result,int64_t profits,int64_t costbasis,int64_t positionsize,int64_t addedbets,int16_t leverage,int32_t firstheight,int64_t firstprice, int64_t lastprice, int64_t equity) +void prices_betjson(UniValue &result, std::vector bets, int16_t leverage, int32_t endheight, int64_t lastprice) { - result.push_back(Pair("profits",ValueFromAmount(profits))); - result.push_back(Pair("costbasis",ValueFromAmount(costbasis))); - result.push_back(Pair("positionsize",ValueFromAmount(positionsize))); - result.push_back(Pair("equity", ValueFromAmount(equity))); - result.push_back(Pair("addedbets",ValueFromAmount(addedbets))); - result.push_back(Pair("leverage",(int64_t)leverage)); - result.push_back(Pair("firstheight",(int64_t)firstheight)); - result.push_back(Pair("firstprice",ValueFromAmount(firstprice))); - result.push_back(Pair("lastprice", ValueFromAmount(lastprice))); + + UniValue resultbets(UniValue::VARR); + int64_t totalbets = 0; + int64_t totalprofits = 0; + + for (auto b : bets) { + resultbets.push_back(Pair("positionsize", ValueFromAmount(b.amount))); + resultbets.push_back(Pair("profits", ValueFromAmount(b.profits))); + resultbets.push_back(Pair("costbasis", ValueFromAmount(b.costbasis))); + resultbets.push_back(Pair("firstheight", b.firstheight)); + totalbets += b.amount; + totalprofits += b.profits; + } + int64_t equity = totalbets + totalprofits; + + result.push_back(resultbets); + result.push_back(Pair("leverage", (int64_t)leverage)); + result.push_back(Pair("TotalPositionSize", totalbets)); + result.push_back(Pair("TotalProfits", totalprofits)); + result.push_back(Pair("equity", equity)); + result.push_back(Pair("LastPrice", ValueFromAmount(lastprice))); + result.push_back(Pair("LastHeight", endheight)); } // retrives costbasis from a tx spending bettx vout1 @@ -817,7 +837,7 @@ int64_t prices_costbasis(CTransaction bettx, uint256 &txidCostbasis) } // calculates added bet total, returns the last baton txid -int64_t prices_enumaddedbets(uint256 &batontxid, std::vector> &addedBets, uint256 bettxid) +int64_t prices_enumaddedbets(uint256 &batontxid, std::vector &bets, uint256 bettxid) { int64_t addedBetsTotal = 0; int32_t vini; @@ -826,7 +846,7 @@ int64_t prices_enumaddedbets(uint256 &batontxid, std::vector addedbets while ((retcode = CCgetspenttxid(batontxid, vini, height, sourcetxid, 0)) == 0) { @@ -842,8 +862,12 @@ int64_t prices_enumaddedbets(uint256 &batontxid, std::vectorGetTxConfirmed(batontxid, txBaton, blockIdx)) && txBaton.vout.size() > 0 && (funcId = prices_addopretdecode(txBaton.vout.back().scriptPubKey, bettxidInOpret, pk, amount)) != 0) { + BetInfo added; + addedBetsTotal += amount; - addedBets.push_back(std::make_pair(blockIdx.GetHeight(), amount)); + added.amount = amount; + added.firstheight = blockIdx.GetHeight(); + bets.push_back(added); std::cerr << "prices_batontxid() added amount=" << amount << std::endl; } else { @@ -920,8 +944,8 @@ UniValue PricesAddFunding(int64_t txfee, uint256 bettxid, int64_t amount) //GetCCaddress(cp, myaddr, mypk); if (AddNormalinputs(mtx, mypk, amount + 2*txfee, 64) >= amount + 2*txfee) { - std::vector> addedBets; - if (prices_enumaddedbets(batontxid, addedBets, bettxid) >= 0) + std::vector bets; + if (prices_enumaddedbets(batontxid, bets, bettxid) >= 0) { mtx.vin.push_back(CTxIn(batontxid, 0, CScript())); mtx.vout.push_back(MakeCC1vout(cp->evalcode, txfee, mypk)); // baton for total funding @@ -1036,15 +1060,15 @@ UniValue PricesRekt(int64_t txfee, uint256 bettxid, int32_t rektheight) { if (prices_betopretdecode(bettx.vout[numvouts - 1].scriptPubKey, pk, firstheight, positionsize, leverage, firstprice, vec, tokenid) == 'B') { - uint256 costbasistxid; - std::vector> addedBets; + //uint256 costbasistxid; + std::vector addedBets; - costbasis = prices_costbasis(bettx, costbasistxid); + /*costbasis = prices_costbasis(bettx, costbasistxid); if (costbasis == 0) { result.push_back(Pair("result", "error")); result.push_back(Pair("error", "costbasis not defined yet")); return(result); - } + }*/ addedbets = prices_enumaddedbets(batontxid, addedBets, bettxid); int32_t retcode = prices_syntheticprofits(costbasis, firstheight, rektheight, leverage, vec, positionsize, profits, lastprice); @@ -1059,7 +1083,7 @@ UniValue PricesRekt(int64_t txfee, uint256 bettxid, int32_t rektheight) { myfee = (positionsize + addedbets) / 500; } - prices_betjson(result, profits, costbasis, positionsize, addedbets, leverage, firstheight, firstprice, lastprice, equity); + //prices_betjson(result, profits, costbasis, positionsize, addedbets, leverage, firstheight, firstprice, lastprice, equity); if (myfee != 0) { mtx.vin.push_back(CTxIn(bettxid, 2, CScript())); @@ -1112,15 +1136,16 @@ UniValue PricesCashout(int64_t txfee, uint256 bettxid) { if (prices_betopretdecode(bettx.vout[numvouts - 1].scriptPubKey, pk, firstheight, positionsize, leverage, firstprice, vec, tokenid) == 'B') { - uint256 costbasistxid; - std::vector> addedBets; + //uint256 costbasistxid; + std::vector addedBets; + /* costbasis = prices_costbasis(bettx, costbasistxid); if (costbasis == 0) { result.push_back(Pair("result", "error")); result.push_back(Pair("error", "costbasis not defined yet")); return(result); - } + }*/ addedbets = prices_enumaddedbets(batontxid, addedBets, bettxid); int32_t retcode = prices_syntheticprofits(costbasis, firstheight, nextheight - 1, leverage, vec, positionsize, profits, lastprice); @@ -1132,12 +1157,12 @@ UniValue PricesCashout(int64_t txfee, uint256 bettxid) equity = positionsize + addedbets + profits; if (equity < 0) { - prices_betjson(result, profits, costbasis, positionsize, addedbets, leverage, firstheight, firstprice, lastprice, equity); + //prices_betjson(result, profits, costbasis, positionsize, addedbets, leverage, firstheight, firstprice, lastprice, equity); result.push_back(Pair("result", "error")); result.push_back(Pair("error", "position rekt")); return(result); } - prices_betjson(result, profits, costbasis, positionsize, addedbets, leverage, firstheight, firstprice, lastprice, equity); + //prices_betjson(result, profits, costbasis, positionsize, addedbets, leverage, firstheight, firstprice, lastprice, equity); mtx.vin.push_back(CTxIn(bettxid, 2, CScript())); if ((inputsum = AddPricesInputs(cp, mtx, destaddr, profits + txfee, 64, bettxid, 2)) > profits + txfee) CCchange = (inputsum - profits); @@ -1157,14 +1182,62 @@ UniValue PricesCashout(int64_t txfee, uint256 bettxid) return(result); } -int32_t prices_scanchain(const CTransaction &tx, int64_t &costbasis, int64_t lastprice) { +int32_t prices_scanchain(std::vector &bets, int16_t leverage, std::vector vec, int64_t &lastprice, int32_t &endheight) { vscript_t opret; uint8_t funcId; - if (tx.vout.size() < 1 || (funcId = CheckPricesOpret(tx, opret)) == 0) { + + + /* if (bettx.vout.size() < 1 || (funcId = CheckPricesOpret(bettx, opret)) == 0) { std::cerr << "prices_scanchain() " << "incorrect tx, must be \'B\' or \'A\'" << std::endl; return -1; + }*/ + + + // check acceptable refheight: +/* if (refheight < 0 || refheight > 0 && refheight < firstheight) { + result.push_back(Pair("result", "error")); + result.push_back(Pair("error", "incorrect height")); + return(result); } + if (refheight == 0) + refheight = komodo_nextheight() - 1;*/ + + //costbasis = prices_costbasis(bettx, costbasistxid) + + + + if (bets.size() == 0) + return -1; + + for (int32_t h = bets[0].firstheight; ; h++) // the last datum for 24h is the costbasis value + { + int64_t total = 0; + int64_t totalprofits = 0; + + for (int i = 0; i < bets.size(); i++) { + int64_t costbasis, profits; + + int32_t retcode = prices_syntheticprofits(costbasis, bets[i].firstheight, h, leverage, vec, bets[i].amount, profits, lastprice); + if (retcode < 0) { + std::cerr << "PricesInfo() error: prices_syntheticprofits returned -1 for addedbet" << std::endl; + break; + } + total += bets[i].amount; + totalprofits += profits; + + bets[i].costbasis = costbasis; + bets[i].profits = profits; + endheight = h; + } + + int64_t equity = total + totalprofits; + if (equity < 0) + { // we are in loss + break; + } + } + return 0; } @@ -1174,78 +1247,58 @@ UniValue PricesInfo(uint256 bettxid, int32_t refheight) UniValue result(UniValue::VOBJ); CTransaction bettx; uint256 hashBlock, batontxid, tokenid; - int64_t myfee, ignore = 0, positionsize = 0, addedbets = 0, firstprice = 0, lastprice = 0, costbasis = 0, equity; - int32_t i, firstheight = 0, height, numvouts; + int64_t myfee; + int64_t positionsize = 0, firstprice = 0, lastprice = 0, costbasis = 0, equity; + int32_t i, firstheight = 0, endheight; int16_t leverage = 0; std::vector vec; CPubKey pk, mypk, pricespk; std::string rawtx; - uint256 costbasistxid; + //uint256 costbasistxid; - if (myGetTransaction(bettxid, bettx, hashBlock) != 0 && (numvouts = bettx.vout.size()) > 3) + if (myGetTransaction(bettxid, bettx, hashBlock) && bettx.vout.size() > 3) { if (hashBlock.IsNull()) throw std::runtime_error("tx still in mempool"); - if (prices_betopretdecode(bettx.vout[numvouts - 1].scriptPubKey, pk, firstheight, positionsize, leverage, firstprice, vec, tokenid) == 'B') + if (prices_betopretdecode(bettx.vout.back().scriptPubKey, pk, firstheight, positionsize, leverage, firstprice, vec, tokenid) == 'B') { - // check acceptable refheight: - if (refheight < 0 || refheight > 0 && refheight < firstheight) { + bool isRekt; + std::vector bets; + BetInfo bet1; + bet1.amount = positionsize; + bet1.firstheight = firstheight; + bets.push_back(bet1); + + prices_enumaddedbets(batontxid, bets, bettxid); + + if( prices_scanchain(bets, leverage, vec, lastprice, endheight) < 0 ) { result.push_back(Pair("result", "error")); - result.push_back(Pair("error", "incorrect height")); + result.push_back(Pair("error", "error scanning chain")); return(result); } - if (refheight == 0) - refheight = komodo_nextheight()-1; - - //costbasis = prices_costbasis(bettx, costbasistxid); - std::vector> addedbets; - prices_enumaddedbets(batontxid, addedbets, bettxid); - - - bool isRekt = false; - int64_t totalprofits = 0, totaladdedbets = 0; - - for (int32_t h = firstheight; ; h++) // the last datum for 24h is the costbasis value - { - int64_t profits, lastprice; - int32_t retcode = prices_syntheticprofits(costbasis, firstheight, h, leverage, vec, positionsize, profits, lastprice); - if (retcode < 0) { - std::cerr << "PricesInfo() prices_syntheticprofits returned -1, stopping" << std::endl; - break; - } - totalprofits = profits; - - for (int i = 0; i < addedbets.size(); i++) { - // get profits for added bets: - int64_t costbasis = 0; // costbasis for added bet - int32_t retcode = prices_syntheticprofits(costbasis, addedbets[i].first, h, leverage, vec, addedbets[i].second, profits, lastprice); - if (retcode < 0) { - std::cerr << "PricesInfo() error: prices_syntheticprofits returned -1 for addedbet" << std::endl; - break; - } - totalprofits += profits; - totaladdedbets += addedbets[i].second; - } - - equity = positionsize + totaladdedbets + totalprofits; - if (equity < 0) - { // we are in loss - result.push_back(Pair("rekt", (int64_t)1)); - result.push_back(Pair("rektfee", (positionsize + totaladdedbets) / 500)); - result.push_back(Pair("rektheight", (int64_t)h)); - isRekt = true; - break; - } + + int64_t totalbet = 0; + int64_t totalprofits = 0; + for (auto b : bets) { + totalbet += b.amount; + totalprofits += b.profits; } - if (!isRekt) + int64_t equity = totalbet + totalprofits; + + if (!equity < 0) result.push_back(Pair("rekt", 0)); + else + { + result.push_back(Pair("rekt", (int64_t)1)); + result.push_back(Pair("rektfee", totalbet / 500)); + result.push_back(Pair("rektheight", (int64_t)endheight)); + } result.push_back(Pair("batontxid", batontxid.GetHex())); - if(!costbasistxid.IsNull()) - result.push_back(Pair("costbasistxid", costbasistxid.GetHex())); - prices_betjson(result, totalprofits, costbasis, positionsize, totaladdedbets, leverage, firstheight, firstprice, lastprice, equity); - result.push_back(Pair("height", (int64_t)refheight)); + + prices_betjson(result, bets, leverage, endheight, lastprice); + //result.push_back(Pair("height", (int64_t)endheight)); //#ifdef TESTMODE // result.push_back(Pair("test_daywindow", PRICES_DAYWINDOW)); //#endif @@ -1253,7 +1306,7 @@ UniValue PricesInfo(uint256 bettxid, int32_t refheight) } } result.push_back(Pair("result", "error")); - result.push_back(Pair("error", "cant find bettxid")); + result.push_back(Pair("error", "cant find bettxid or incorrect")); return(result); } From 879a9fbaf85dfc0e72e8137a7701f62b4b45cefb Mon Sep 17 00:00:00 2001 From: dimxy Date: Thu, 25 Apr 2019 15:34:55 +0500 Subject: [PATCH 125/447] corr break from loop --- src/cc/prices.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index b0147cdd8..7b68292f0 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -1210,6 +1210,7 @@ int32_t prices_scanchain(std::vector &bets, int16_t leverage, std::vect if (bets.size() == 0) return -1; + bool stop = false; for (int32_t h = bets[0].firstheight; ; h++) // the last datum for 24h is the costbasis value { int64_t total = 0; @@ -1220,7 +1221,8 @@ int32_t prices_scanchain(std::vector &bets, int16_t leverage, std::vect int32_t retcode = prices_syntheticprofits(costbasis, bets[i].firstheight, h, leverage, vec, bets[i].amount, profits, lastprice); if (retcode < 0) { - std::cerr << "PricesInfo() error: prices_syntheticprofits returned -1 for addedbet" << std::endl; + std::cerr << "prices_scanchain() error: prices_syntheticprofits returned -1 for addedbet" << std::endl; + stop = true; break; } total += bets[i].amount; @@ -1228,9 +1230,12 @@ int32_t prices_scanchain(std::vector &bets, int16_t leverage, std::vect bets[i].costbasis = costbasis; bets[i].profits = profits; - endheight = h; } + if (stop) + break; + + endheight = h; int64_t equity = total + totalprofits; if (equity < 0) { // we are in loss From 91704c0b0addf2400e93657c7dc86ab51cdb3b41 Mon Sep 17 00:00:00 2001 From: dimxy Date: Thu, 25 Apr 2019 15:40:55 +0500 Subject: [PATCH 126/447] result to varr --- src/cc/prices.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 7b68292f0..9c3a34d95 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -794,6 +794,7 @@ void prices_betjson(UniValue &result, std::vector bets, int16_t leverag } int64_t equity = totalbets + totalprofits; + result.setArray(); result.push_back(resultbets); result.push_back(Pair("leverage", (int64_t)leverage)); result.push_back(Pair("TotalPositionSize", totalbets)); From 6005562b6acc9d4247d7416b984a6740d8fd7408 Mon Sep 17 00:00:00 2001 From: dimxy Date: Thu, 25 Apr 2019 15:50:19 +0500 Subject: [PATCH 127/447] corr resultbets entry --- src/cc/prices.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 9c3a34d95..130389702 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -785,16 +785,17 @@ void prices_betjson(UniValue &result, std::vector bets, int16_t leverag int64_t totalprofits = 0; for (auto b : bets) { - resultbets.push_back(Pair("positionsize", ValueFromAmount(b.amount))); - resultbets.push_back(Pair("profits", ValueFromAmount(b.profits))); - resultbets.push_back(Pair("costbasis", ValueFromAmount(b.costbasis))); - resultbets.push_back(Pair("firstheight", b.firstheight)); + UniValue entry(UniValue::VOBJ); + entry.push_back(Pair("positionsize", ValueFromAmount(b.amount))); + entry.push_back(Pair("profits", ValueFromAmount(b.profits))); + entry.push_back(Pair("costbasis", ValueFromAmount(b.costbasis))); + entry.push_back(Pair("firstheight", b.firstheight)); + resultbets.push_back(entry); totalbets += b.amount; totalprofits += b.profits; } int64_t equity = totalbets + totalprofits; - result.setArray(); result.push_back(resultbets); result.push_back(Pair("leverage", (int64_t)leverage)); result.push_back(Pair("TotalPositionSize", totalbets)); From ae4d2faa6927419dc121faf9d4a2ad4e9f1f7f35 Mon Sep 17 00:00:00 2001 From: dimxy Date: Thu, 25 Apr 2019 15:59:07 +0500 Subject: [PATCH 128/447] corr adding array to json res --- src/cc/prices.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 130389702..ef0dfc680 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -796,7 +796,7 @@ void prices_betjson(UniValue &result, std::vector bets, int16_t leverag } int64_t equity = totalbets + totalprofits; - result.push_back(resultbets); + result.push_back(Pair("bets", resultbets)); result.push_back(Pair("leverage", (int64_t)leverage)); result.push_back(Pair("TotalPositionSize", totalbets)); result.push_back(Pair("TotalProfits", totalprofits)); From 1c219dbf67903d2cccd506be1e21458f83573278 Mon Sep 17 00:00:00 2001 From: dimxy Date: Thu, 25 Apr 2019 16:10:05 +0500 Subject: [PATCH 129/447] corr costbasis init corr json vals precision --- src/cc/prices.cpp | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index ef0dfc680..5683f7b3d 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -23,6 +23,8 @@ typedef struct BetInfo { int32_t firstheight; int64_t costbasis; int64_t profits; + + BetInfo() { amount = 0; firstheight = 0; costbasis = 0; profits = 0; } } betinfo; /* @@ -798,9 +800,9 @@ void prices_betjson(UniValue &result, std::vector bets, int16_t leverag result.push_back(Pair("bets", resultbets)); result.push_back(Pair("leverage", (int64_t)leverage)); - result.push_back(Pair("TotalPositionSize", totalbets)); - result.push_back(Pair("TotalProfits", totalprofits)); - result.push_back(Pair("equity", equity)); + result.push_back(Pair("TotalPositionSize", ValueFromAmount(totalbets))); + result.push_back(Pair("TotalProfits", ValueFromAmount(totalprofits))); + result.push_back(Pair("equity", ValueFromAmount(equity))); result.push_back(Pair("LastPrice", ValueFromAmount(lastprice))); result.push_back(Pair("LastHeight", endheight)); } @@ -1215,30 +1217,26 @@ int32_t prices_scanchain(std::vector &bets, int16_t leverage, std::vect bool stop = false; for (int32_t h = bets[0].firstheight; ; h++) // the last datum for 24h is the costbasis value { - int64_t total = 0; + int64_t totalbets = 0; int64_t totalprofits = 0; for (int i = 0; i < bets.size(); i++) { int64_t costbasis, profits; - - int32_t retcode = prices_syntheticprofits(costbasis, bets[i].firstheight, h, leverage, vec, bets[i].amount, profits, lastprice); + int32_t retcode = prices_syntheticprofits(bets[i].costbasis, bets[i].firstheight, h, leverage, vec, bets[i].amount, bets[i].profits, lastprice); if (retcode < 0) { std::cerr << "prices_scanchain() error: prices_syntheticprofits returned -1 for addedbet" << std::endl; stop = true; break; } - total += bets[i].amount; - totalprofits += profits; - - bets[i].costbasis = costbasis; - bets[i].profits = profits; + totalbets += bets[i].amount; + totalprofits += bets[i].profits; } if (stop) break; endheight = h; - int64_t equity = total + totalprofits; + int64_t equity = totalbets + totalprofits; if (equity < 0) { // we are in loss break; From 10447109dddcf59e5181f31757ed84bec9e42aaf Mon Sep 17 00:00:00 2001 From: dimxy Date: Thu, 25 Apr 2019 16:16:18 +0500 Subject: [PATCH 130/447] corr equity compare --- src/cc/prices.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 5683f7b3d..d1c5ea00d 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -1291,7 +1291,7 @@ UniValue PricesInfo(uint256 bettxid, int32_t refheight) } int64_t equity = totalbet + totalprofits; - if (!equity < 0) + if (equity >= 0) result.push_back(Pair("rekt", 0)); else { From 00a39266aafd3df4d4f2d7d559ea84610f2c3988 Mon Sep 17 00:00:00 2001 From: dimxy Date: Thu, 25 Apr 2019 17:15:27 +0500 Subject: [PATCH 131/447] corr perm costbasis calc --- src/cc/prices.cpp | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index d1c5ea00d..caf1f491d 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -739,31 +739,31 @@ int32_t prices_syntheticprofits(int64_t &costbasis, int32_t firstheight, int32_t if (minmax) { // if we are within day window, set temp costbasis to max (or min) price value if (leverage > 0 && price > costbasis) { costbasis = price; // set temp costbasis - std::cerr << "prices_syntheticprofits() minmax costbasis=" << costbasis << " price=" << price << std::endl; + std::cerr << "prices_syntheticprofits() minmax costbasis=" << costbasis << std::endl; } else if (leverage < 0 && (costbasis == 0 || price < costbasis)) { costbasis = price; - std::cerr << "prices_syntheticprofits() minmax costbasis=" << costbasis << " price=" << price << std::endl; - } - else { //-> use the previous value - std::cerr << "prices_syntheticprofits() unchanged costbasis=" << costbasis << " price=" << price << " leverage=" << leverage << std::endl; + std::cerr << "prices_syntheticprofits() minmax costbasis=" << costbasis << std::endl; } + //else { //-> use the previous value + // std::cerr << "prices_syntheticprofits() unchanged costbasis=" << costbasis << " price=" << price << " leverage=" << leverage << std::endl; + //} } else { - if (costbasis == 0) { + if (height == firstheight + PRICES_DAYWINDOW) { // if costbasis not set, just set it costbasis = price; - std::cerr << "prices_syntheticprofits() set costbasis=" << costbasis << std::endl; + std::cerr << "prices_syntheticprofits() permanent costbasis=" << costbasis << " height=" << height << std::endl; } else { // use provided costbasis - std::cerr << "prices_syntheticprofits() provided costbasis=" << costbasis << " price=" << price << std::endl; + //std::cerr << "prices_syntheticprofits() provided costbasis=" << costbasis << " price=" << price << std::endl; } } profits = costbasis > 0 ? (((price / PRICES_NORMFACTOR * SATOSHIDEN) / costbasis) - SATOSHIDEN / PRICES_NORMFACTOR) * PRICES_NORMFACTOR : 0; - std::cerr << "prices_syntheticprofits() test value1 (price/PRICES_NORMFACTOR * SATOSHIDEN)=" << (price / PRICES_NORMFACTOR * SATOSHIDEN) << std::endl; + //std::cerr << "prices_syntheticprofits() test value1 (price/PRICES_NORMFACTOR * SATOSHIDEN)=" << (price / PRICES_NORMFACTOR * SATOSHIDEN) << std::endl; std::cerr << "prices_syntheticprofits() test value2 (price/PRICES_NORMFACTOR * SATOSHIDEN)/costbasis=" << (costbasis != 0 ? (price / PRICES_NORMFACTOR * SATOSHIDEN)/costbasis : 0) << std::endl; std::cerr << "prices_syntheticprofits() fractional profits=" << profits << std::endl; @@ -773,7 +773,7 @@ int32_t prices_syntheticprofits(int64_t &costbasis, int32_t firstheight, int32_t profits *= ((int64_t)leverage * (int64_t)positionsize); profits /= (int64_t)SATOSHIDEN; //dprofits *= leverage * positionsize; - std::cerr << "prices_syntheticprofits() value of profits=" << profits << std::endl; + std::cerr << "prices_syntheticprofits() profits=" << profits << std::endl; //std::cerr << "prices_syntheticprofits() dprofits=" << dprofits << std::endl; return 0; // (positionsize + addedbets + profits); @@ -1220,11 +1220,11 @@ int32_t prices_scanchain(std::vector &bets, int16_t leverage, std::vect int64_t totalbets = 0; int64_t totalprofits = 0; + // scan upto the chain tip for (int i = 0; i < bets.size(); i++) { - int64_t costbasis, profits; int32_t retcode = prices_syntheticprofits(bets[i].costbasis, bets[i].firstheight, h, leverage, vec, bets[i].amount, bets[i].profits, lastprice); if (retcode < 0) { - std::cerr << "prices_scanchain() error: prices_syntheticprofits returned -1 for addedbet" << std::endl; + std::cerr << "prices_scanchain() prices_syntheticprofits returned -1, breaking" << std::endl; stop = true; break; } From fe3e906c46578d28f778c5b505e7a4ee5679cd80 Mon Sep 17 00:00:00 2001 From: dimxy Date: Thu, 25 Apr 2019 17:33:07 +0500 Subject: [PATCH 132/447] added height > firstheight check --- src/cc/prices.cpp | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index caf1f491d..54d883f95 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -1215,27 +1215,31 @@ int32_t prices_scanchain(std::vector &bets, int16_t leverage, std::vect return -1; bool stop = false; - for (int32_t h = bets[0].firstheight; ; h++) // the last datum for 24h is the costbasis value + for (int32_t height = bets[0].firstheight; ; height++) // the last datum for 24h is the costbasis value { int64_t totalbets = 0; int64_t totalprofits = 0; // scan upto the chain tip for (int i = 0; i < bets.size(); i++) { - int32_t retcode = prices_syntheticprofits(bets[i].costbasis, bets[i].firstheight, h, leverage, vec, bets[i].amount, bets[i].profits, lastprice); - if (retcode < 0) { - std::cerr << "prices_scanchain() prices_syntheticprofits returned -1, breaking" << std::endl; - stop = true; - break; + + if (height > bets[i].firstheight) { + + int32_t retcode = prices_syntheticprofits(bets[i].costbasis, bets[i].firstheight, height, leverage, vec, bets[i].amount, bets[i].profits, lastprice); + if (retcode < 0) { + std::cerr << "prices_scanchain() prices_syntheticprofits returned -1, breaking" << std::endl; + stop = true; + break; + } + totalbets += bets[i].amount; + totalprofits += bets[i].profits; } - totalbets += bets[i].amount; - totalprofits += bets[i].profits; } if (stop) break; - endheight = h; + endheight = height; int64_t equity = totalbets + totalprofits; if (equity < 0) { // we are in loss From 02858d910307735e9885be00a7139a74dc4827a2 Mon Sep 17 00:00:00 2001 From: dimxy Date: Thu, 25 Apr 2019 18:59:37 +0500 Subject: [PATCH 133/447] corr Cashout and Rekt funcs --- src/cc/prices.cpp | 230 ++++++++++++++++++++++------------------------ 1 file changed, 108 insertions(+), 122 deletions(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 54d883f95..4cc942b70 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -24,7 +24,7 @@ typedef struct BetInfo { int64_t costbasis; int64_t profits; - BetInfo() { amount = 0; firstheight = 0; costbasis = 0; profits = 0; } + BetInfo() { amount = 0; firstheight = 0; costbasis = 0; profits = 0; } // important to clear costbasis as it will be calculated as minmax } betinfo; /* @@ -713,7 +713,7 @@ int64_t prices_syntheticprice(std::vector vec, int32_t height, int32_t return(price / den); } -// calculates profit/loss for the bet +// calculates costbasis and profit/loss for the bet int32_t prices_syntheticprofits(int64_t &costbasis, int32_t firstheight, int32_t height, int16_t leverage, std::vector vec, int64_t positionsize, int64_t &profits, int64_t &outprice) { int64_t price; @@ -779,6 +779,7 @@ int32_t prices_syntheticprofits(int64_t &costbasis, int32_t firstheight, int32_t return 0; // (positionsize + addedbets + profits); } +// makes result json object void prices_betjson(UniValue &result, std::vector bets, int16_t leverage, int32_t endheight, int64_t lastprice) { @@ -840,7 +841,7 @@ int64_t prices_costbasis(CTransaction bettx, uint256 &txidCostbasis) return 0; } -// calculates added bet total, returns the last baton txid +// enumerates and retrieves added bets, returns the last baton txid int64_t prices_enumaddedbets(uint256 &batontxid, std::vector &bets, uint256 bettxid) { int64_t addedBetsTotal = 0; @@ -969,8 +970,49 @@ UniValue PricesAddFunding(int64_t txfee, uint256 bettxid, int64_t amount) return(result); } -// set cost basis (open price) for the bet +// scan chain from the initial bet's first position upto the chain tip and calculate bet's costbasises and profits, breaks if rekt detected +int32_t prices_scanchain(std::vector &bets, int16_t leverage, std::vector vec, int64_t &lastprice, int32_t &endheight) { + if (bets.size() == 0) + return -1; + + bool stop = false; + for (int32_t height = bets[0].firstheight; ; height++) // the last datum for 24h is the costbasis value + { + int64_t totalbets = 0; + int64_t totalprofits = 0; + + // scan upto the chain tip + for (int i = 0; i < bets.size(); i++) { + + if (height > bets[i].firstheight) { + + int32_t retcode = prices_syntheticprofits(bets[i].costbasis, bets[i].firstheight, height, leverage, vec, bets[i].amount, bets[i].profits, lastprice); + if (retcode < 0) { + std::cerr << "prices_scanchain() prices_syntheticprofits returned -1, breaking" << std::endl; + stop = true; + break; + } + totalbets += bets[i].amount; + totalprofits += bets[i].profits; + } + } + + if (stop) + break; + + endheight = height; + int64_t equity = totalbets + totalprofits; + if (equity < 0) + { // we are in loss + break; + } + } + + return 0; +} + +// set cost basis (open price) for the bet UniValue PricesSetcostbasis(int64_t txfee, uint256 bettxid) { int32_t nextheight = komodo_nextheight(); @@ -1048,8 +1090,8 @@ UniValue PricesRekt(int64_t txfee, uint256 bettxid, int32_t rektheight) struct CCcontract_info *cp, C; CTransaction bettx; uint256 hashBlock, tokenid, batontxid; - int64_t myfee = 0, positionsize, addedbets, firstprice, lastprice, profits, ignore, costbasis = 0, equity; - int32_t firstheight, numvouts; + int64_t myfee = 0, firstprice, lastprice = 0, positionsize; + int32_t firstheight; int16_t leverage; std::vector vec; CPubKey pk, mypk, pricespk; @@ -1060,40 +1102,45 @@ UniValue PricesRekt(int64_t txfee, uint256 bettxid, int32_t rektheight) txfee = PRICES_TXFEE; mypk = pubkey2pk(Mypubkey()); pricespk = GetUnspendable(cp, 0); - if (myGetTransaction(bettxid, bettx, hashBlock) != 0 && (numvouts = bettx.vout.size()) > 3) + if (myGetTransaction(bettxid, bettx, hashBlock) != 0 && bettx.vout.size() > 3) { - if (prices_betopretdecode(bettx.vout[numvouts - 1].scriptPubKey, pk, firstheight, positionsize, leverage, firstprice, vec, tokenid) == 'B') + if (prices_betopretdecode(bettx.vout.back().scriptPubKey, pk, firstheight, positionsize, leverage, firstprice, vec, tokenid) == 'B') { - //uint256 costbasistxid; - std::vector addedBets; + int32_t endheight; + std::vector bets; + BetInfo bet1; + bet1.amount = positionsize; + bet1.firstheight = firstheight; + bets.push_back(bet1); - /*costbasis = prices_costbasis(bettx, costbasistxid); - if (costbasis == 0) { - result.push_back(Pair("result", "error")); - result.push_back(Pair("error", "costbasis not defined yet")); - return(result); - }*/ + prices_enumaddedbets(batontxid, bets, bettxid); - addedbets = prices_enumaddedbets(batontxid, addedBets, bettxid); - int32_t retcode = prices_syntheticprofits(costbasis, firstheight, rektheight, leverage, vec, positionsize, profits, lastprice); - if (retcode < 0) { + if (prices_scanchain(bets, leverage, vec, lastprice, endheight) < 0) { result.push_back(Pair("result", "error")); - result.push_back(Pair("error", "cannot get price")); + result.push_back(Pair("error", "error scanning chain")); return(result); } - equity = positionsize + addedbets + profits; + int64_t totalbets = 0; + int64_t totalprofits = 0; + for (auto b : bets) { + totalbets += b.amount; + totalprofits += b.profits; + } + + prices_betjson(result, bets, leverage, endheight, lastprice); // fill output json + + int64_t equity = totalbets + totalprofits; if (equity < 0) { - myfee = (positionsize + addedbets) / 500; + myfee = totalbets / 500; // consolation fee for loss } - //prices_betjson(result, profits, costbasis, positionsize, addedbets, leverage, firstheight, firstprice, lastprice, equity); if (myfee != 0) { mtx.vin.push_back(CTxIn(bettxid, 2, CScript())); mtx.vout.push_back(CTxOut(myfee, CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); mtx.vout.push_back(MakeCC1vout(cp->evalcode, bettx.vout[2].nValue - myfee - txfee, pricespk)); - rawtx = FinalizeCCTx(0, cp, mtx, mypk, txfee, prices_finalopret(bettxid, profits, rektheight, mypk, firstprice, costbasis, addedbets, positionsize, leverage)); + rawtx = FinalizeCCTx(0, cp, mtx, mypk, txfee, prices_finalopret(bettxid, totalprofits, rektheight, mypk, firstprice, 0, totalbets - positionsize, positionsize, leverage)); return(prices_rawtxresult(result, rawtx, 0)); } else @@ -1111,7 +1158,7 @@ UniValue PricesRekt(int64_t txfee, uint256 bettxid, int32_t rektheight) } } result.push_back(Pair("result", "error")); - result.push_back(Pair("error", "cant find bettxid")); + result.push_back(Pair("error", "cant load or incorrect bettx")); return(result); } @@ -1122,8 +1169,8 @@ UniValue PricesCashout(int64_t txfee, uint256 bettxid) struct CCcontract_info *cp, C; char destaddr[64]; CTransaction bettx; uint256 hashBlock, batontxid, tokenid; - int64_t CCchange = 0, positionsize, inputsum, ignore, addedbets, firstprice, lastprice, profits, costbasis = 0, equity; - int32_t i, firstheight, height, numvouts; + int64_t CCchange = 0, positionsize, inputsum, firstprice, lastprice = 0; + int32_t firstheight, height; int16_t leverage; std::vector vec; CPubKey pk, mypk, pricespk; @@ -1136,44 +1183,48 @@ UniValue PricesCashout(int64_t txfee, uint256 bettxid) mypk = pubkey2pk(Mypubkey()); pricespk = GetUnspendable(cp, 0); GetCCaddress(cp, destaddr, pricespk); - if (myGetTransaction(bettxid, bettx, hashBlock) != 0 && (numvouts = bettx.vout.size()) > 3) + if (myGetTransaction(bettxid, bettx, hashBlock) != 0 && bettx.vout.size() > 3) { - if (prices_betopretdecode(bettx.vout[numvouts - 1].scriptPubKey, pk, firstheight, positionsize, leverage, firstprice, vec, tokenid) == 'B') + if (prices_betopretdecode(bettx.vout.back().scriptPubKey, pk, firstheight, positionsize, leverage, firstprice, vec, tokenid) == 'B') { - //uint256 costbasistxid; - std::vector addedBets; + int32_t endheight; + std::vector bets; + BetInfo bet1; + bet1.amount = positionsize; + bet1.firstheight = firstheight; + bets.push_back(bet1); - /* - costbasis = prices_costbasis(bettx, costbasistxid); - if (costbasis == 0) { - result.push_back(Pair("result", "error")); - result.push_back(Pair("error", "costbasis not defined yet")); - return(result); - }*/ + prices_enumaddedbets(batontxid, bets, bettxid); - addedbets = prices_enumaddedbets(batontxid, addedBets, bettxid); - int32_t retcode = prices_syntheticprofits(costbasis, firstheight, nextheight - 1, leverage, vec, positionsize, profits, lastprice); - if (retcode < 0) { + if (prices_scanchain(bets, leverage, vec, lastprice, endheight) < 0) { result.push_back(Pair("result", "error")); - result.push_back(Pair("error", "cannot get price")); + result.push_back(Pair("error", "error scanning chain")); return(result); } - equity = positionsize + addedbets + profits; + + int64_t totalbets = 0; + int64_t totalprofits = 0; + for (auto b : bets) { + totalbets += b.amount; + totalprofits += b.profits; + } + prices_betjson(result, bets, leverage, endheight, lastprice); // fill output json + + int64_t equity = totalbets + totalprofits; if (equity < 0) { - //prices_betjson(result, profits, costbasis, positionsize, addedbets, leverage, firstheight, firstprice, lastprice, equity); result.push_back(Pair("result", "error")); result.push_back(Pair("error", "position rekt")); return(result); } - //prices_betjson(result, profits, costbasis, positionsize, addedbets, leverage, firstheight, firstprice, lastprice, equity); + mtx.vin.push_back(CTxIn(bettxid, 2, CScript())); - if ((inputsum = AddPricesInputs(cp, mtx, destaddr, profits + txfee, 64, bettxid, 2)) > profits + txfee) - CCchange = (inputsum - profits); - mtx.vout.push_back(CTxOut(bettx.vout[2].nValue + profits, CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); + if ((inputsum = AddPricesInputs(cp, mtx, destaddr, equity + txfee, 64, bettxid, 2)) > equity + txfee) + CCchange = (inputsum - equity); + mtx.vout.push_back(CTxOut(bettx.vout[2].nValue + equity, CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); if (CCchange >= txfee) mtx.vout.push_back(MakeCC1vout(cp->evalcode, CCchange, pricespk)); - rawtx = FinalizeCCTx(0, cp, mtx, mypk, txfee, prices_finalopret(bettxid, profits, nextheight - 1, mypk, firstprice, costbasis, addedbets, positionsize, leverage)); + rawtx = FinalizeCCTx(0, cp, mtx, mypk, txfee, prices_finalopret(bettxid, totalprofits, nextheight - 1, mypk, firstprice, 0, totalbets-positionsize, positionsize, leverage)); return(prices_rawtxresult(result, rawtx, 0)); } else @@ -1183,82 +1234,18 @@ UniValue PricesCashout(int64_t txfee, uint256 bettxid) return(result); } } + result.push_back(Pair("result", "error")); + result.push_back(Pair("error", "cant load or incorrect bettx")); return(result); } -int32_t prices_scanchain(std::vector &bets, int16_t leverage, std::vector vec, int64_t &lastprice, int32_t &endheight) { - - vscript_t opret; - uint8_t funcId; - - - /* if (bettx.vout.size() < 1 || (funcId = CheckPricesOpret(bettx, opret)) == 0) { - std::cerr << "prices_scanchain() " << "incorrect tx, must be \'B\' or \'A\'" << std::endl; - return -1; - }*/ - - - // check acceptable refheight: -/* if (refheight < 0 || refheight > 0 && refheight < firstheight) { - result.push_back(Pair("result", "error")); - result.push_back(Pair("error", "incorrect height")); - return(result); - } - if (refheight == 0) - refheight = komodo_nextheight() - 1;*/ - - //costbasis = prices_costbasis(bettx, costbasistxid) - - - - if (bets.size() == 0) - return -1; - - bool stop = false; - for (int32_t height = bets[0].firstheight; ; height++) // the last datum for 24h is the costbasis value - { - int64_t totalbets = 0; - int64_t totalprofits = 0; - - // scan upto the chain tip - for (int i = 0; i < bets.size(); i++) { - - if (height > bets[i].firstheight) { - - int32_t retcode = prices_syntheticprofits(bets[i].costbasis, bets[i].firstheight, height, leverage, vec, bets[i].amount, bets[i].profits, lastprice); - if (retcode < 0) { - std::cerr << "prices_scanchain() prices_syntheticprofits returned -1, breaking" << std::endl; - stop = true; - break; - } - totalbets += bets[i].amount; - totalprofits += bets[i].profits; - } - } - - if (stop) - break; - - endheight = height; - int64_t equity = totalbets + totalprofits; - if (equity < 0) - { // we are in loss - break; - } - } - - return 0; -} - - UniValue PricesInfo(uint256 bettxid, int32_t refheight) { UniValue result(UniValue::VOBJ); CTransaction bettx; uint256 hashBlock, batontxid, tokenid; - int64_t myfee; - int64_t positionsize = 0, firstprice = 0, lastprice = 0, costbasis = 0, equity; - int32_t i, firstheight = 0, endheight; + int64_t positionsize = 0, firstprice = 0, lastprice = 0; + int32_t firstheight = 0, endheight; int16_t leverage = 0; std::vector vec; CPubKey pk, mypk, pricespk; @@ -1272,7 +1259,6 @@ UniValue PricesInfo(uint256 bettxid, int32_t refheight) if (prices_betopretdecode(bettx.vout.back().scriptPubKey, pk, firstheight, positionsize, leverage, firstprice, vec, tokenid) == 'B') { - bool isRekt; std::vector bets; BetInfo bet1; bet1.amount = positionsize; @@ -1287,20 +1273,20 @@ UniValue PricesInfo(uint256 bettxid, int32_t refheight) return(result); } - int64_t totalbet = 0; + int64_t totalbets = 0; int64_t totalprofits = 0; for (auto b : bets) { - totalbet += b.amount; + totalbets += b.amount; totalprofits += b.profits; } - int64_t equity = totalbet + totalprofits; + int64_t equity = totalbets + totalprofits; if (equity >= 0) result.push_back(Pair("rekt", 0)); else { result.push_back(Pair("rekt", (int64_t)1)); - result.push_back(Pair("rektfee", totalbet / 500)); + result.push_back(Pair("rektfee", totalbets / 500)); result.push_back(Pair("rektheight", (int64_t)endheight)); } From 82557a93a404d1b9e8722583ff78b04d5d555515 Mon Sep 17 00:00:00 2001 From: dimxy Date: Thu, 25 Apr 2019 19:47:33 +0500 Subject: [PATCH 134/447] added checks for closed --- src/cc/prices.cpp | 38 ++++++++++++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 6 deletions(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 4cc942b70..d1bb48b48 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -1077,9 +1077,9 @@ UniValue PricesSetcostbasis(int64_t txfee, uint256 bettxid) result.push_back(Pair("error", "not enough funds")); return(result); } - } + } */ result.push_back(Pair("result", "error")); - result.push_back(Pair("error", "cant find bettxid")); */ + result.push_back(Pair("error", "deprecated")); return(result); } @@ -1106,9 +1106,18 @@ UniValue PricesRekt(int64_t txfee, uint256 bettxid, int32_t rektheight) { if (prices_betopretdecode(bettx.vout.back().scriptPubKey, pk, firstheight, positionsize, leverage, firstprice, vec, tokenid) == 'B') { - int32_t endheight; + uint256 finaltxid; + int32_t vini; + int32_t finalheight, endheight; std::vector bets; BetInfo bet1; + + if (CCgetspenttxid(finaltxid, vini, finalheight, bettxid, 2) < 0) { + result.push_back(Pair("result", "error")); + result.push_back(Pair("error", "position closed")); + return result; + } + bet1.amount = positionsize; bet1.firstheight = firstheight; bets.push_back(bet1); @@ -1170,7 +1179,7 @@ UniValue PricesCashout(int64_t txfee, uint256 bettxid) CTransaction bettx; uint256 hashBlock, batontxid, tokenid; int64_t CCchange = 0, positionsize, inputsum, firstprice, lastprice = 0; - int32_t firstheight, height; + int32_t firstheight; int16_t leverage; std::vector vec; CPubKey pk, mypk, pricespk; @@ -1187,13 +1196,21 @@ UniValue PricesCashout(int64_t txfee, uint256 bettxid) { if (prices_betopretdecode(bettx.vout.back().scriptPubKey, pk, firstheight, positionsize, leverage, firstprice, vec, tokenid) == 'B') { - int32_t endheight; + uint256 finaltxid; + int32_t vini; + int32_t finalheight, endheight; std::vector bets; BetInfo bet1; + + if (CCgetspenttxid(finaltxid, vini, finalheight, bettxid, 2) < 0) { + result.push_back(Pair("result", "error")); + result.push_back(Pair("error", "position closed")); + return result; + } + bet1.amount = positionsize; bet1.firstheight = firstheight; bets.push_back(bet1); - prices_enumaddedbets(batontxid, bets, bettxid); if (prices_scanchain(bets, leverage, vec, lastprice, endheight) < 0) { @@ -1259,8 +1276,17 @@ UniValue PricesInfo(uint256 bettxid, int32_t refheight) if (prices_betopretdecode(bettx.vout.back().scriptPubKey, pk, firstheight, positionsize, leverage, firstprice, vec, tokenid) == 'B') { + uint256 finaltxid; + int32_t vini; + int32_t finalheight, endheight; std::vector bets; BetInfo bet1; + + if (CCgetspenttxid(finaltxid, vini, finalheight, bettxid, 2) < 0) + result.push_back(Pair("status", "closed")); + else + result.push_back(Pair("status", "open")); + bet1.amount = positionsize; bet1.firstheight = firstheight; bets.push_back(bet1); From c3854b80841c5f7595f4cc3b55f55809f2aeea2a Mon Sep 17 00:00:00 2001 From: dimxy Date: Thu, 25 Apr 2019 20:22:04 +0500 Subject: [PATCH 135/447] corr cashout amount --- src/cc/prices.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index d1bb48b48..5fca48739 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -917,10 +917,10 @@ UniValue PricesBet(int64_t txfee, int64_t amount, int16_t leverage, std::vector< if (AddNormalinputs(mtx, mypk, amount + 5 * txfee, 64) >= amount + 5 * txfee) { betamount = (amount * 199) / 200; - mtx.vout.push_back(MakeCC1vout(cp->evalcode, txfee, mypk)); // vout0 baton for total funding + mtx.vout.push_back(MakeCC1vout(cp->evalcode, txfee, mypk)); // vout0 baton for total funding mtx.vout.push_back(MakeCC1vout(cp->evalcode, (amount - betamount) + 2 * txfee, pricespk)); // vout1, when spent, costbasis is set - mtx.vout.push_back(MakeCC1vout(cp->evalcode, betamount, pricespk)); - mtx.vout.push_back(CTxOut(txfee, CScript() << ParseHex(HexStr(pricespk)) << OP_CHECKSIG)); // marker + mtx.vout.push_back(MakeCC1vout(cp->evalcode, betamount, pricespk)); // betamount + mtx.vout.push_back(CTxOut(txfee, CScript() << ParseHex(HexStr(pricespk)) << OP_CHECKSIG)); // normal marker rawtx = FinalizeCCTx(0, cp, mtx, mypk, txfee, prices_betopret(mypk, nextheight - 1, amount, leverage, firstprice, vec, zeroid)); return(prices_rawtxresult(result, rawtx, 0)); } @@ -1235,10 +1235,10 @@ UniValue PricesCashout(int64_t txfee, uint256 bettxid) return(result); } - mtx.vin.push_back(CTxIn(bettxid, 2, CScript())); + //mtx.vin.push_back(CTxIn(bettxid, 2, CScript())); // take back betamount (with fee subtracted) if ((inputsum = AddPricesInputs(cp, mtx, destaddr, equity + txfee, 64, bettxid, 2)) > equity + txfee) CCchange = (inputsum - equity); - mtx.vout.push_back(CTxOut(bettx.vout[2].nValue + equity, CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); + mtx.vout.push_back(CTxOut(equity, CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); if (CCchange >= txfee) mtx.vout.push_back(MakeCC1vout(cp->evalcode, CCchange, pricespk)); rawtx = FinalizeCCTx(0, cp, mtx, mypk, txfee, prices_finalopret(bettxid, totalprofits, nextheight - 1, mypk, firstprice, 0, totalbets-positionsize, positionsize, leverage)); From 4f5d16905a0722b4fd20ea721f9165a83233fe45 Mon Sep 17 00:00:00 2001 From: dimxy Date: Thu, 25 Apr 2019 20:28:26 +0500 Subject: [PATCH 136/447] corr check open/closed --- src/cc/prices.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 5fca48739..df7817876 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -1112,7 +1112,7 @@ UniValue PricesRekt(int64_t txfee, uint256 bettxid, int32_t rektheight) std::vector bets; BetInfo bet1; - if (CCgetspenttxid(finaltxid, vini, finalheight, bettxid, 2) < 0) { + if (CCgetspenttxid(finaltxid, vini, finalheight, bettxid, 2) == 0) { result.push_back(Pair("result", "error")); result.push_back(Pair("error", "position closed")); return result; @@ -1202,7 +1202,7 @@ UniValue PricesCashout(int64_t txfee, uint256 bettxid) std::vector bets; BetInfo bet1; - if (CCgetspenttxid(finaltxid, vini, finalheight, bettxid, 2) < 0) { + if (CCgetspenttxid(finaltxid, vini, finalheight, bettxid, 2) == 0) { result.push_back(Pair("result", "error")); result.push_back(Pair("error", "position closed")); return result; @@ -1282,7 +1282,7 @@ UniValue PricesInfo(uint256 bettxid, int32_t refheight) std::vector bets; BetInfo bet1; - if (CCgetspenttxid(finaltxid, vini, finalheight, bettxid, 2) < 0) + if (CCgetspenttxid(finaltxid, vini, finalheight, bettxid, 2) == 0) result.push_back(Pair("status", "closed")); else result.push_back(Pair("status", "open")); From 7b17cd8a365801ca0baa6b641a923e95ad80f56b Mon Sep 17 00:00:00 2001 From: dimxy Date: Thu, 25 Apr 2019 23:52:53 +0500 Subject: [PATCH 137/447] changed to cc marker cc marker excluded for addpricesinputs --- src/cc/prices.cpp | 73 ++++++++++++++++++++++++++++++++--------------- 1 file changed, 50 insertions(+), 23 deletions(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index df7817876..362967e53 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -24,7 +24,7 @@ typedef struct BetInfo { int64_t costbasis; int64_t profits; - BetInfo() { amount = 0; firstheight = 0; costbasis = 0; profits = 0; } // important to clear costbasis as it will be calculated as minmax + BetInfo() { amount = 0; firstheight = 0; costbasis = 0; profits = 0; } // it is important to clear costbasis as it will be calculated as minmax from inital value 0 } betinfo; /* @@ -445,7 +445,7 @@ bool PricesValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx // helper functions for rpc calls in rpcwallet.cpp -int64_t AddPricesInputs(struct CCcontract_info *cp, CMutableTransaction &mtx, char *destaddr, int64_t total, int32_t maxinputs, uint256 vintxid, int32_t vinvout) +int64_t AddPricesInputs(struct CCcontract_info *cp, CMutableTransaction &mtx, char *destaddr, int64_t total, int32_t maxinputs) { int64_t nValue, price, totalinputs = 0; uint256 txid, hashBlock; std::vector origpubkey; CTransaction vintx; int32_t vout, n = 0; std::vector > unspentOutputs; @@ -455,10 +455,15 @@ int64_t AddPricesInputs(struct CCcontract_info *cp, CMutableTransaction &mtx, ch { txid = it->first.txhash; vout = (int32_t)it->first.index; - if (vout == vinvout && txid == vintxid) - continue; + //if (vout == exclvout && txid == excltxid) // exclude vout which is added directly to vins outside this function + // continue; if (GetTransaction(txid, vintx, hashBlock, false) != 0 && vout < vintx.vout.size()) { + vscript_t vopret; + uint8_t funcId = CheckPricesOpret(vintx, vopret); + if (funcId == 'B' && vout == 1) // skip cc marker + continue; + if ((nValue = vintx.vout[vout].nValue) >= total / maxinputs && myIsutxo_spentinmempool(ignoretxid, ignorevin, txid, vout) == 0) { if (total != 0 && maxinputs != 0) @@ -866,7 +871,8 @@ int64_t prices_enumaddedbets(uint256 &batontxid, std::vector &bets, uin if ((isLoaded = eval->GetTxConfirmed(batontxid, txBaton, blockIdx)) && txBaton.vout.size() > 0 && - (funcId = prices_addopretdecode(txBaton.vout.back().scriptPubKey, bettxidInOpret, pk, amount)) != 0) { + (funcId = prices_addopretdecode(txBaton.vout.back().scriptPubKey, bettxidInOpret, pk, amount)) != 0) + { BetInfo added; addedBetsTotal += amount; @@ -914,13 +920,14 @@ UniValue PricesBet(int64_t txfee, int64_t amount, int16_t leverage, std::vector< result.push_back(Pair("error", "invalid synthetic")); return(result); } - if (AddNormalinputs(mtx, mypk, amount + 5 * txfee, 64) >= amount + 5 * txfee) + if (AddNormalinputs(mtx, mypk, amount + 4 * txfee, 64) >= amount + 4 * txfee) { betamount = (amount * 199) / 200; mtx.vout.push_back(MakeCC1vout(cp->evalcode, txfee, mypk)); // vout0 baton for total funding - mtx.vout.push_back(MakeCC1vout(cp->evalcode, (amount - betamount) + 2 * txfee, pricespk)); // vout1, when spent, costbasis is set - mtx.vout.push_back(MakeCC1vout(cp->evalcode, betamount, pricespk)); // betamount - mtx.vout.push_back(CTxOut(txfee, CScript() << ParseHex(HexStr(pricespk)) << OP_CHECKSIG)); // normal marker + // mtx.vout.push_back(MakeCC1vout(cp->evalcode, (amount - betamount) + 2 * txfee, pricespk)); // vout1, when spent, costbasis is set + mtx.vout.push_back(MakeCC1vout(cp->evalcode, txfee, pricespk)); // vout1 cc marker + mtx.vout.push_back(MakeCC1vout(cp->evalcode, betamount, pricespk)); // vout2 betamount + mtx.vout.push_back(CTxOut(txfee, CScript() << ParseHex(HexStr(pricespk)) << OP_CHECKSIG)); // vout3 normal marker rawtx = FinalizeCCTx(0, cp, mtx, mypk, txfee, prices_betopret(mypk, nextheight - 1, amount, leverage, firstprice, vec, zeroid)); return(prices_rawtxresult(result, rawtx, 0)); } @@ -953,8 +960,8 @@ UniValue PricesAddFunding(int64_t txfee, uint256 bettxid, int64_t amount) if (prices_enumaddedbets(batontxid, bets, bettxid) >= 0) { mtx.vin.push_back(CTxIn(batontxid, 0, CScript())); - mtx.vout.push_back(MakeCC1vout(cp->evalcode, txfee, mypk)); // baton for total funding - mtx.vout.push_back(MakeCC1vout(cp->evalcode, amount, pricespk)); + mtx.vout.push_back(MakeCC1vout(cp->evalcode, txfee, mypk)); // vout0 baton for total funding + mtx.vout.push_back(MakeCC1vout(cp->evalcode, amount, pricespk)); // vout1 added amount rawtx = FinalizeCCTx(0, cp, mtx, mypk, txfee, prices_addopret(bettxid, mypk, amount)); return(prices_rawtxresult(result, rawtx, 0)); } @@ -1146,7 +1153,7 @@ UniValue PricesRekt(int64_t txfee, uint256 bettxid, int32_t rektheight) } if (myfee != 0) { - mtx.vin.push_back(CTxIn(bettxid, 2, CScript())); + mtx.vin.push_back(CTxIn(bettxid, 1, CScript())); // spend cc marker mtx.vout.push_back(CTxOut(myfee, CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); mtx.vout.push_back(MakeCC1vout(cp->evalcode, bettx.vout[2].nValue - myfee - txfee, pricespk)); rawtx = FinalizeCCTx(0, cp, mtx, mypk, txfee, prices_finalopret(bettxid, totalprofits, rektheight, mypk, firstprice, 0, totalbets - positionsize, positionsize, leverage)); @@ -1235,8 +1242,8 @@ UniValue PricesCashout(int64_t txfee, uint256 bettxid) return(result); } - //mtx.vin.push_back(CTxIn(bettxid, 2, CScript())); // take back betamount (with fee subtracted) - if ((inputsum = AddPricesInputs(cp, mtx, destaddr, equity + txfee, 64, bettxid, 2)) > equity + txfee) + mtx.vin.push_back(CTxIn(bettxid, 1, CScript())); // spend cc marker + if ((inputsum = AddPricesInputs(cp, mtx, destaddr, equity + txfee, 64)) > equity + txfee) CCchange = (inputsum - equity); mtx.vout.push_back(CTxOut(equity, CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); if (CCchange >= txfee) @@ -1333,23 +1340,29 @@ UniValue PricesInfo(uint256 bettxid, int32_t refheight) UniValue PricesList(uint32_t filter, CPubKey mypk) { - UniValue result(UniValue::VARR); std::vector > addressIndex; + UniValue result(UniValue::VARR); + std::vector > addressIndex; struct CCcontract_info *cp, C; - int64_t amount, firstprice; int32_t height; int16_t leverage; uint256 txid, hashBlock, tokenid; - CPubKey pk, pricespk; - std::vector vec; - CTransaction vintx; + cp = CCinit(&C, EVAL_PRICES); - pricespk = GetUnspendable(cp, 0); - SetCCtxids(addressIndex, cp->normaladdr, false); - for (std::vector >::const_iterator it = addressIndex.begin(); it != addressIndex.end(); it++) + //pricespk = GetUnspendable(cp, 0); + + auto priceslist = [&](std::vector >::const_iterator it) { + int64_t amount, firstprice; + int32_t height; + int16_t leverage; + uint256 txid, hashBlock, tokenid; + CPubKey pk, pricespk; + std::vector vec; + CTransaction vintx; + txid = it->first.txhash; if (GetTransaction(txid, vintx, hashBlock, false) != 0) { bool bAppend = false; - if (vintx.vout.size() > 0 && prices_betopretdecode(vintx.vout[vintx.vout.size() - 1].scriptPubKey, pk, height, amount, leverage, firstprice, vec, tokenid) == 'B' && + if (vintx.vout.size() > 0 && prices_betopretdecode(vintx.vout.back().scriptPubKey, pk, height, amount, leverage, firstprice, vec, tokenid) == 'B' && (mypk == CPubKey() || mypk == pk)) // if only mypubkey to list { if (filter == 0) @@ -1369,6 +1382,20 @@ UniValue PricesList(uint32_t filter, CPubKey mypk) } std::cerr << "PricesList() " << " bettxid=" << txid.GetHex() << " mypk=" << HexStr(mypk) << " opret pk=" << HexStr(pk) << " filter=" << filter << " bAppend=" << bAppend << std::endl; } + }; + + + SetCCtxids(addressIndex, cp->normaladdr, false); // old normal marker + for (std::vector >::const_iterator it = addressIndex.begin(); it != addressIndex.end(); it++) + { + priceslist(it); } + + SetCCtxids(addressIndex, cp->unspendableCCaddr, true); // cc marker + for (std::vector >::const_iterator it = addressIndex.begin(); it != addressIndex.end(); it++) + { + priceslist(it); + } + return(result); } \ No newline at end of file From d1c206b347da8b112e884e09135be4b9fbb310f5 Mon Sep 17 00:00:00 2001 From: dimxy Date: Fri, 26 Apr 2019 00:01:59 +0500 Subject: [PATCH 138/447] corr addrindex --- src/cc/prices.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 362967e53..a86791ddd 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -1341,7 +1341,7 @@ UniValue PricesInfo(uint256 bettxid, int32_t refheight) UniValue PricesList(uint32_t filter, CPubKey mypk) { UniValue result(UniValue::VARR); - std::vector > addressIndex; + std::vector > addressIndex, addressIndexCC; struct CCcontract_info *cp, C; @@ -1391,8 +1391,8 @@ UniValue PricesList(uint32_t filter, CPubKey mypk) priceslist(it); } - SetCCtxids(addressIndex, cp->unspendableCCaddr, true); // cc marker - for (std::vector >::const_iterator it = addressIndex.begin(); it != addressIndex.end(); it++) + SetCCtxids(addressIndexCC, cp->unspendableCCaddr, true); // cc marker + for (std::vector >::const_iterator it = addressIndexCC.begin(); it != addressIndexCC.end(); it++) { priceslist(it); } From 2d677f3addc9c90f09cd299b30529c28bbcbc3d8 Mon Sep 17 00:00:00 2001 From: dimxy Date: Fri, 26 Apr 2019 00:27:58 +0500 Subject: [PATCH 139/447] logging --- src/cc/prices.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index a86791ddd..9dd9091e9 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -1348,7 +1348,7 @@ UniValue PricesList(uint32_t filter, CPubKey mypk) cp = CCinit(&C, EVAL_PRICES); //pricespk = GetUnspendable(cp, 0); - auto priceslist = [&](std::vector >::const_iterator it) + auto priceslist = [&](std::vector >::const_iterator it, int32_t vini) { int64_t amount, firstprice; int32_t height; @@ -1359,6 +1359,7 @@ UniValue PricesList(uint32_t filter, CPubKey mypk) CTransaction vintx; txid = it->first.txhash; + if (GetTransaction(txid, vintx, hashBlock, false) != 0) { bool bAppend = false; @@ -1380,7 +1381,7 @@ UniValue PricesList(uint32_t filter, CPubKey mypk) if (bAppend) result.push_back(txid.GetHex()); } - std::cerr << "PricesList() " << " bettxid=" << txid.GetHex() << " mypk=" << HexStr(mypk) << " opret pk=" << HexStr(pk) << " filter=" << filter << " bAppend=" << bAppend << std::endl; + std::cerr << "PricesList() " << " bettxid=" << txid.GetHex() << " mypk=" << HexStr(mypk) << " opretpk=" << HexStr(pk) << " filter=" << filter << " bAppend=" << bAppend << " index=" << it->first.index << " txindex=" << it->first.txindex << std::endl; } }; @@ -1388,13 +1389,13 @@ UniValue PricesList(uint32_t filter, CPubKey mypk) SetCCtxids(addressIndex, cp->normaladdr, false); // old normal marker for (std::vector >::const_iterator it = addressIndex.begin(); it != addressIndex.end(); it++) { - priceslist(it); + priceslist(it, 3); } SetCCtxids(addressIndexCC, cp->unspendableCCaddr, true); // cc marker for (std::vector >::const_iterator it = addressIndexCC.begin(); it != addressIndexCC.end(); it++) { - priceslist(it); + priceslist(it, 1); } return(result); From d9a1ff169556c7c8b8f12d391eeef75a3cc8e251 Mon Sep 17 00:00:00 2001 From: dimxy Date: Fri, 26 Apr 2019 00:48:35 +0500 Subject: [PATCH 140/447] added check vout==index --- src/cc/prices.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 9dd9091e9..0e4280563 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -1348,7 +1348,8 @@ UniValue PricesList(uint32_t filter, CPubKey mypk) cp = CCinit(&C, EVAL_PRICES); //pricespk = GetUnspendable(cp, 0); - auto priceslist = [&](std::vector >::const_iterator it, int32_t vini) + // filters and outputs prices bet txid + auto priceslist = [&](std::vector >::const_iterator it, int32_t nvout) { int64_t amount, firstprice; int32_t height; @@ -1359,6 +1360,8 @@ UniValue PricesList(uint32_t filter, CPubKey mypk) CTransaction vintx; txid = it->first.txhash; + if (nvout != it->first.index) // our marker vout + return; if (GetTransaction(txid, vintx, hashBlock, false) != 0) { @@ -1392,11 +1395,12 @@ UniValue PricesList(uint32_t filter, CPubKey mypk) priceslist(it, 3); } + /* for future when switch to cc marker only SetCCtxids(addressIndexCC, cp->unspendableCCaddr, true); // cc marker for (std::vector >::const_iterator it = addressIndexCC.begin(); it != addressIndexCC.end(); it++) { priceslist(it, 1); } - + */ return(result); } \ No newline at end of file From 94d6916ca46d4c11c1c25855652b1417a03e83d2 Mon Sep 17 00:00:00 2001 From: dimxy Date: Fri, 26 Apr 2019 00:59:30 +0500 Subject: [PATCH 141/447] final tx vout check commented --- src/cc/prices.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 0e4280563..50115924a 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -303,8 +303,10 @@ static bool ValidateFinalTx(struct CCcontract_info *cp, Eval *eval, const CTrans int64_t firstprice, costbasis, addedbets, positionsize; int16_t leverage; - if (finaltx.vout.size() < 2 || finaltx.vout.size() > 3) - return eval->Invalid("incorrect vout number for final tx"); + if (finaltx.vout.size() < 3 || finaltx.vout.size() > 4) { + //return eval->Invalid("incorrect vout number for final tx"); + std::cerr << "ValidateFinalTx()" << " incorrect vout number for final tx =" << finaltx.vout.size() << std::endl; + } vscript_t opret; if (prices_finalopretdecode(finaltx.vout.back().scriptPubKey, bettxid, profits, height, pk, firstprice, costbasis, addedbets, positionsize, leverage) != 'F') @@ -1155,7 +1157,7 @@ UniValue PricesRekt(int64_t txfee, uint256 bettxid, int32_t rektheight) { mtx.vin.push_back(CTxIn(bettxid, 1, CScript())); // spend cc marker mtx.vout.push_back(CTxOut(myfee, CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); - mtx.vout.push_back(MakeCC1vout(cp->evalcode, bettx.vout[2].nValue - myfee - txfee, pricespk)); + mtx.vout.push_back(MakeCC1vout(cp->evalcode, bettx.vout[2].nValue - myfee - txfee, pricespk)); // change rawtx = FinalizeCCTx(0, cp, mtx, mypk, txfee, prices_finalopret(bettxid, totalprofits, rektheight, mypk, firstprice, 0, totalbets - positionsize, positionsize, leverage)); return(prices_rawtxresult(result, rawtx, 0)); } From fc1e3209fd01a2a2b1f4f9ea2a8ee730a18a5619 Mon Sep 17 00:00:00 2001 From: dimxy Date: Fri, 26 Apr 2019 01:09:51 +0500 Subject: [PATCH 142/447] more relaxed validation --- src/cc/prices.cpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 50115924a..85abc985c 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -375,9 +375,10 @@ bool PricesValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx if (CheckPricesOpret(vintx, vintxOpret) == 0) return eval->Invalid("cannot find prices opret in vintx"); - //if (vintxOpret.begin()[1] == 'B' && prevoutN == 3) { - // return eval->Invalid("cannot spend bet marker"); - //} + if (funcId != 'F' && vintxOpret.begin()[1] == 'B' && prevoutN == 1) { + //return eval->Invalid("cannot spend bet marker"); + std::cerr << "PricesValidate() " << " non-final tx cannot spend cc marker vout=" << prevoutN << std::endl; + } if (!foundFirst) { prevoutN = vin.prevout.n; @@ -412,7 +413,8 @@ bool PricesValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx } if (prevoutN != 0) { // check spending rules - return eval->Invalid("incorrect vintx vout to spend"); + // return eval->Invalid("incorrect vintx vout to spend"); + std::cerr << "PricesValidate() " << "add fund tx incorrect vout to spend=" << prevoutN << std::endl; } break; @@ -432,8 +434,9 @@ bool PricesValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx return false; if (!ValidateBetTx(cp, eval, firstVinTx)) return false; - if (prevoutN != 2) { // check spending rules - return eval->Invalid("incorrect vout to spend"); + if (prevoutN != 1) { // check spending rules + // return eval->Invalid("incorrect vout to spend"); + std::cerr << "PricesValidate() "<< "final tx incorrect vout to spend=" << prevoutN << std::endl; } break; From 1141ce95d88e24592646c2f6849361e2aee505d7 Mon Sep 17 00:00:00 2001 From: dimxy Date: Fri, 26 Apr 2019 01:33:49 +0500 Subject: [PATCH 143/447] bettx comment validation for add fund tx --- src/cc/prices.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 85abc985c..0c6efd755 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -216,9 +216,11 @@ static bool ValidateAddFundingTx(struct CCcontract_info *cp, Eval *eval, const C return eval->Invalid("cannot decode opreturn for add funding tx"); pricespk = GetUnspendable(cp, 0); - - if (CheckPricesOpret(vintx, vintxOpret) != 'B') // if vintx is bettx - return eval->Invalid("incorrect bettx"); + uint8_t funcId; + if ((funcId=CheckPricesOpret(vintx, vintxOpret)) != 'B') { // if vintx is bettx + std::cerr << "ValidateBetTx() " << "bad funcId=" << (funcId?funcId:'0') << std::endl; + //return eval->Invalid("incorrect bettx funcid"); + } if (vintx.GetHash() != bettxid) // if vintx is bettx return eval->Invalid("incorrect bet txid in opreturn"); @@ -262,7 +264,7 @@ static bool ValidateCostbasisTx(struct CCcontract_info *cp, Eval *eval, const CT // check costbasis rules: if (costbasistx.vout[0].nValue > bettx.vout[1].nValue / 10) { // return eval->Invalid("costbasis myfee too big"); - std::cerr << "ValidateBetTx() " << "costbasis myfee too big" << std::endl; + std::cerr << "ValidateCostbasisTx() " << "costbasis myfee too big" << std::endl; } uint256 tokenid; From 50adff8b8c3c4e5f4a1a981c0f1dd63b7b2c4888 Mon Sep 17 00:00:00 2001 From: dimxy Date: Fri, 26 Apr 2019 01:46:25 +0500 Subject: [PATCH 144/447] corr vintx validation for add tx --- src/cc/prices.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 0c6efd755..6f17311c7 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -216,14 +216,16 @@ static bool ValidateAddFundingTx(struct CCcontract_info *cp, Eval *eval, const C return eval->Invalid("cannot decode opreturn for add funding tx"); pricespk = GetUnspendable(cp, 0); - uint8_t funcId; - if ((funcId=CheckPricesOpret(vintx, vintxOpret)) != 'B') { // if vintx is bettx - std::cerr << "ValidateBetTx() " << "bad funcId=" << (funcId?funcId:'0') << std::endl; - //return eval->Invalid("incorrect bettx funcid"); + uint8_t vintxFuncId = CheckPricesOpret(vintx, vintxOpret); + if (vintxFuncId != 'A' && vintxFuncId != 'B') { // if vintx is bettx + std::cerr << "ValidateAddFundingTx() " << "bad vintx funcId=" << (char)(vintxFuncId ? vintxFuncId :'0') << std::endl; + //return eval->Invalid("incorrect vintx funcid"); } - if (vintx.GetHash() != bettxid) // if vintx is bettx - return eval->Invalid("incorrect bet txid in opreturn"); + if (vintxFuncId == 'B' && vintx.GetHash() != bettxid) {// if vintx is bettx + //return eval->Invalid("incorrect bet txid in opreturn"); + std::cerr << "ValidateAddFundingTx() " << "incorrect net txid" << std::endl; + } if (MakeCC1vout(cp->evalcode, addfundingtx.vout[0].nValue, pk) != addfundingtx.vout[0]) return eval->Invalid("cannot validate vout0 in add funding tx with pk from opreturn"); From eb7d77de1df4cfdea627dcc3f8eb9eb0404e9a7e Mon Sep 17 00:00:00 2001 From: dimxy Date: Fri, 26 Apr 2019 01:51:51 +0500 Subject: [PATCH 145/447] off costbasis validation --- src/cc/prices.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 6f17311c7..9357e3719 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -243,6 +243,8 @@ static bool ValidateCostbasisTx(struct CCcontract_info *cp, Eval *eval, const CT CPubKey pk, pricespk; int32_t height; + return true; //deprecated + // check basic structure: if (costbasistx.vout.size() < 3 || costbasistx.vout.size() > 4) return eval->Invalid("incorrect vout count for costbasis tx"); From 25b86870c1ac8601325a3fc226baab45e4770443 Mon Sep 17 00:00:00 2001 From: dimxy Date: Fri, 26 Apr 2019 12:05:57 +0500 Subject: [PATCH 146/447] all return invalid captured --- src/cc/prices.cpp | 78 ++++++++++++++++++++++++++--------------------- 1 file changed, 44 insertions(+), 34 deletions(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 9357e3719..2f8ad287a 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -178,7 +178,6 @@ static bool ValidateBetTx(struct CCcontract_info *cp, Eval *eval, const CTransac int64_t betamount = bettx.vout[2].nValue; if (betamount != (positionsize * 199) / 200) { return eval->Invalid("invalid position size in the opreturn"); - std::cerr << "ValidateBetTx() " << "invalid position size in the opreturn" << std::endl; } // validate if normal inputs are really signed by originator pubkey (someone not cheating with originator pubkey) @@ -188,13 +187,11 @@ static bool ValidateBetTx(struct CCcontract_info *cp, Eval *eval, const CTransac ccOutputs += vout.nValue; CAmount normalInputs = TotalPubkeyNormalInputs(bettx, pk); if (normalInputs < ccOutputs) { - // return eval->Invalid("bettx normal inputs not signed with pubkey in opret"); - std::cerr << "ValidateBetTx() " << "warning: bettx normal inputs signed with pubkey in opreturn =" << normalInputs << std::endl; + return eval->Invalid("bettx normal inputs not signed with pubkey in opret"); } if (leverage > PRICES_MAXLEVERAGE || leverage < -PRICES_MAXLEVERAGE) { - // return eval->Invalid("invalid leverage"); - std::cerr << "ValidateBetTx() " << "invalid leverage" << std::endl; + return eval->Invalid("invalid leverage"); } return true; @@ -218,13 +215,11 @@ static bool ValidateAddFundingTx(struct CCcontract_info *cp, Eval *eval, const C pricespk = GetUnspendable(cp, 0); uint8_t vintxFuncId = CheckPricesOpret(vintx, vintxOpret); if (vintxFuncId != 'A' && vintxFuncId != 'B') { // if vintx is bettx - std::cerr << "ValidateAddFundingTx() " << "bad vintx funcId=" << (char)(vintxFuncId ? vintxFuncId :'0') << std::endl; - //return eval->Invalid("incorrect vintx funcid"); + return eval->Invalid("incorrect vintx funcid"); } if (vintxFuncId == 'B' && vintx.GetHash() != bettxid) {// if vintx is bettx - //return eval->Invalid("incorrect bet txid in opreturn"); - std::cerr << "ValidateAddFundingTx() " << "incorrect net txid" << std::endl; + return eval->Invalid("incorrect bet txid in opreturn"); } if (MakeCC1vout(cp->evalcode, addfundingtx.vout[0].nValue, pk) != addfundingtx.vout[0]) @@ -267,8 +262,7 @@ static bool ValidateCostbasisTx(struct CCcontract_info *cp, Eval *eval, const CT // check costbasis rules: if (costbasistx.vout[0].nValue > bettx.vout[1].nValue / 10) { - // return eval->Invalid("costbasis myfee too big"); - std::cerr << "ValidateCostbasisTx() " << "costbasis myfee too big" << std::endl; + return eval->Invalid("costbasis myfee too big"); } uint256 tokenid; @@ -281,8 +275,7 @@ static bool ValidateCostbasisTx(struct CCcontract_info *cp, Eval *eval, const CT return eval->Invalid("cannot decode opreturn for bet tx"); if (firstheight + PRICES_DAYWINDOW + PRICES_SMOOTHWIDTH > chainActive.Height()) { - // return eval->Invalid("cannot calculate costbasis yet"); - std::cerr << "ValidateBetTx() " << "cannot calculate costbasis yet" << std::endl; + return eval->Invalid("cannot calculate costbasis yet"); } int64_t costbasis = 0, profits, lastprice; @@ -291,8 +284,8 @@ static bool ValidateCostbasisTx(struct CCcontract_info *cp, Eval *eval, const CT return eval->Invalid("cannot calculate costbasis yet"); std::cerr << "ValidateCostbasisTx() costbasis=" << costbasis << " costbasisInOpret=" << costbasisInOpret << std::endl; if (costbasis != costbasisInOpret) { - // return eval->Invalid("incorrect costbasis value"); - std::cerr << "ValidateBetTx() " << "incorrect costbasis value" << std::endl; + //std::cerr << "ValidateBetTx() " << "incorrect costbasis value" << std::endl; + return eval->Invalid("incorrect costbasis value"); } return true; @@ -310,8 +303,8 @@ static bool ValidateFinalTx(struct CCcontract_info *cp, Eval *eval, const CTrans int16_t leverage; if (finaltx.vout.size() < 3 || finaltx.vout.size() > 4) { - //return eval->Invalid("incorrect vout number for final tx"); - std::cerr << "ValidateFinalTx()" << " incorrect vout number for final tx =" << finaltx.vout.size() << std::endl; + //std::cerr << "ValidateFinalTx()" << " incorrect vout number for final tx =" << finaltx.vout.size() << std::endl; + return eval->Invalid("incorrect vout number for final tx"); } vscript_t opret; @@ -378,8 +371,10 @@ bool PricesValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx if (!myGetTransaction(vin.prevout.hash, vintx, hashBlock)) return eval->Invalid("cannot load vintx"); - if (CheckPricesOpret(vintx, vintxOpret) == 0) - return eval->Invalid("cannot find prices opret in vintx"); + if (CheckPricesOpret(vintx, vintxOpret) == 0) { + //return eval->Invalid("cannot find prices opret in vintx"); + std::cerr << "PricesValidate() " << "cannot find prices opret in vintx" << std::endl; + } if (funcId != 'F' && vintxOpret.begin()[1] == 'B' && prevoutN == 1) { //return eval->Invalid("cannot spend bet marker"); @@ -398,8 +393,10 @@ bool PricesValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx if (!foundFirst) return eval->Invalid("prices cc vin not found"); - if (funcId != 'F' && ccVinCount > 1) // for all prices tx except final tx only one cc vin is allowed - return eval->Invalid("only one prices cc vin allowed for this tx"); + if (funcId != 'F' && ccVinCount > 1) {// for all prices tx except final tx only one cc vin is allowed + //return eval->Invalid("only one prices cc vin allowed for this tx"); + std::cerr << "PricesValidate() " << "only one prices cc vin allowed for this tx" << std::endl; + } switch (funcId) { case 'B': // bet @@ -407,12 +404,16 @@ bool PricesValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx case 'A': // add funding // check tx structure: - if (!ValidateAddFundingTx(cp, eval, tx, firstVinTx)) - return false; // invalid state is already set in the func + if (!ValidateAddFundingTx(cp, eval, tx, firstVinTx)) { + //return false; // invalid state is already set in the func + std::cerr << "PricesValidate() " << "ValidateAddFundingTx = false " << eval->state.GetRejectReason() << std::endl; + } if (firstVinTxOpret.begin()[1] == 'B') { - if (!ValidateBetTx(cp, eval, firstVinTx)) // check tx structure - return false; + if (!ValidateBetTx(cp, eval, firstVinTx)) {// check tx structure + // return false; + std::cerr << "PricesValidate() " << "funcId=A ValidatebetTx = false " << eval->state.GetRejectReason() << std::endl; + } } else if (firstVinTxOpret.begin()[1] == 'A') { // no need to validate the previous addfunding tx (it was validated when added) @@ -425,21 +426,30 @@ bool PricesValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx break; case 'C': // set costbasis - if (!ValidateCostbasisTx(cp, eval, tx, firstVinTx)) - return false; - if (!ValidateBetTx(cp, eval, firstVinTx)) - return false; + if (!ValidateCostbasisTx(cp, eval, tx, firstVinTx)) { + //return false; + std::cerr << "PricesValidate() " << "ValidateCostbasisTx=false " << eval->state.GetRejectReason() << std::endl; + } + if (!ValidateBetTx(cp, eval, firstVinTx)) { + //return false; + std::cerr << "PricesValidate() " << "funcId=C ValidateBetTx=false " << eval->state.GetRejectReason() << std::endl; + } if (prevoutN != 1) { // check spending rules - return eval->Invalid("incorrect vout to spend"); + // return eval->Invalid("incorrect vout to spend"); + std::cerr << "PricesValidate() " << "costbasis tx incorrect vout to spend=" << prevoutN << std::endl; } //return eval->Invalid("test: costbasis is good"); break; case 'F': // final tx - if (!ValidateFinalTx(cp, eval, tx, firstVinTx)) - return false; - if (!ValidateBetTx(cp, eval, firstVinTx)) - return false; + if (!ValidateFinalTx(cp, eval, tx, firstVinTx)) { + ///return false; + std::cerr << "PricesValidate() " << "ValidateFinalTx=false " << eval->state.GetRejectReason() << std::endl; + } + if (!ValidateBetTx(cp, eval, firstVinTx)) { + // return false; + std::cerr << "PricesValidate() " << "ValidateBetTx=false " << eval->state.GetRejectReason() << std::endl; + } if (prevoutN != 1) { // check spending rules // return eval->Invalid("incorrect vout to spend"); std::cerr << "PricesValidate() "<< "final tx incorrect vout to spend=" << prevoutN << std::endl; From 8d272e1c5f44b0d1f2fbc01eb680517d28498863 Mon Sep 17 00:00:00 2001 From: dimxy Date: Fri, 26 Apr 2019 19:43:50 +0500 Subject: [PATCH 147/447] val state cleared --- src/cc/prices.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 2f8ad287a..98049164f 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -460,6 +460,7 @@ bool PricesValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx return eval->Invalid("invalid funcid"); } + eval->state = CValidationState(); return true; } // end of consensus code From ed6fd7e8c611aab49250a1aa95c03a056102342f Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Sat, 27 Apr 2019 02:21:40 +0800 Subject: [PATCH 148/447] attempt at daily snapshot --- src/cc/CCPayments.h | 2 + src/cc/hempcoin_notes.txt | 2 +- src/cc/payments.cpp | 86 +++++++----------------------- src/komodo_defs.h | 1 + src/main.cpp | 107 +++++++++++++++++++++++++++++++++++++- src/rpc/server.cpp | 13 ++--- src/rpc/server.h | 1 + src/txdb.cpp | 89 +++++++++++++++---------------- src/txdb.h | 2 +- src/wallet/rpcwallet.cpp | 13 +++++ 10 files changed, 190 insertions(+), 126 deletions(-) diff --git a/src/cc/CCPayments.h b/src/cc/CCPayments.h index 247a0f2ec..6eeb7bcb3 100644 --- a/src/cc/CCPayments.h +++ b/src/cc/CCPayments.h @@ -20,6 +20,7 @@ #include "CCinclude.h" #define PAYMENTS_TXFEE 10000 +bool komodo_snapshot2(std::map &addressAmounts); bool PaymentsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); @@ -28,6 +29,7 @@ UniValue PaymentsRelease(struct CCcontract_info *cp,char *jsonstr); UniValue PaymentsFund(struct CCcontract_info *cp,char *jsonstr); UniValue PaymentsTxidopret(struct CCcontract_info *cp,char *jsonstr); UniValue PaymentsCreate(struct CCcontract_info *cp,char *jsonstr); +UniValue PaymentsAirdrop(struct CCcontract_info *cp,char *jsonstr); UniValue PaymentsInfo(struct CCcontract_info *cp,char *jsonstr); UniValue PaymentsList(struct CCcontract_info *cp,char *jsonstr); diff --git a/src/cc/hempcoin_notes.txt b/src/cc/hempcoin_notes.txt index f8003ac95..2fd72c897 100644 --- a/src/cc/hempcoin_notes.txt +++ b/src/cc/hempcoin_notes.txt @@ -56,7 +56,7 @@ get the payment fund scriptpubkey hex from vout 0: (the split it at OP_CHECKCRYP put the second half into an OP_RETURN: (the remaining part of the the above scriptpubkey) eg. ./komodo-cli -ac_name=TESTHC opreturn_burn 1 2a0401f00101246a22f046337db779358deaa69b9af053e27d85cb8e8e48b0b13805c084b04f87be6577ee75 opret_burn takes any burn amount and arbitrary hex string. (RPC works, but may have bugs, likely use this for LABS too with some fixes) - this gives a raw hex. Decode it and check the OP_RETURN is right before sending (using this RPC currently adds 3 extra bytes to the front (6a2d2c), which is truncated later on, this should be fixed if possible before making any real chains as its consensus code. Need to try diffrent methods to decode the hex correctly.) + this gives a raw hex. Decode it and check the OP_RETURN is right before sending. -earlytxid=810bd62fb8353fad20267ff2050684b8829affa3edf6b366633931530791dfce restart the chain with earlytxid param before height 100 on all nodes (if not using -testnode=1) ./komodod -ac_name=TESTHC -ac_supply=1000000 -ac_reward=100000000000 -ac_cc=2 -ac_script=2ea22c8020987fad30df055db6fd922c3a57e55d76601229ed3da3b31340112e773df3d0d28103120c008203000401ccb8 -ac_founders=150 -ac_blocktime=20 -ac_nk=96,5 -earlytxid=810bd62fb8353fad20267ff2050684b8829affa3edf6b366633931530791dfce diff --git a/src/cc/payments.cpp b/src/cc/payments.cpp index 7dc8cb1b6..6f6ae1a84 100644 --- a/src/cc/payments.cpp +++ b/src/cc/payments.cpp @@ -16,6 +16,18 @@ #include "CCPayments.h" /* +payments airdrop: + - extra RPC to merge all payments inputs to a single utxo, this must be called first and be confirmed before payments release, + or tx will be too big, we can check add payments inputs is only 1 input, at RPC and in validation very early on. + - do getsnapshot2 every 1440 blocks and save the result into some global sorted vector or DB? + -this allows any address balance to be calculated by only iterating each 1439 blocks maximum. + - calculate scriptpubkey to pay from each address, set allocations from balance of each address. allocation = balance? + +payments airdrop paying a token: ( maybe this is more reasonable speed wise? ) + - tokenid, top number of tokens to pay, list of pubkeys to exclude as optional param + - add vector of tokenids to getsnapshot2 - then sort each tokenid by balance. + put the pubkey to pay to as scriptpubkey in the saved vector. + 0) txidopret <- allocation, scriptPubKey, opret 1) create <- locked_blocks, minrelease, list of txidopret @@ -781,76 +793,14 @@ UniValue PaymentsCreate(struct CCcontract_info *cp,char *jsonstr) return(result); } +extern bool komodo_dailysnapshot(int32_t height); + UniValue PaymentsAirdrop(struct CCcontract_info *cp,char *jsonstr) { - // need to code: exclude list of tokenid, dust threshold, maxpayees, excluded pubkeys[] - CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - UniValue result(UniValue::VOBJ); CTransaction tx; CPubKey Paymentspk,mypk; char markeraddr[64]; std::vector txidoprets; uint256 hashBlock; int32_t i,n,numoprets=0,lockedblocks,minrelease; std::string rawtx; int64_t totalallocations = 0; - cJSON *params = payments_reparse(&n,jsonstr); - if ( params != 0 && n >= 4 ) - { - lockedblocks = juint(jitem(params,0),0); - minrelease = juint(jitem(params,1),0); - if ( lockedblocks < 0 || minrelease < 0 ) - { - result.push_back(Pair("result","error")); - result.push_back(Pair("error","negative parameter")); - if ( params != 0 ) - free_json(params); - return(result); - } - for (i=0; i scriptPubKey,opret; int64_t allocation; - if ( myGetTransaction(txidoprets[i],tx,hashBlock) != 0 && tx.vout.size() > 1 && DecodePaymentsTxidOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,allocation,scriptPubKey,opret) == 'T' ) - { - totalallocations += allocation; - if ( opret.size() > 0 ) - numoprets++; - } - else - { - result.push_back(Pair("result","error")); - result.push_back(Pair("error","invalid txidopret")); - result.push_back(Pair("txid",txidoprets[i].GetHex())); - result.push_back(Pair("txi",(int64_t)i)); - if ( params != 0 ) - free_json(params); - return(result); - } - } - if ( numoprets > 1 ) - { - result.push_back(Pair("result","error")); - result.push_back(Pair("error","too many opreturns")); - result.push_back(Pair("numoprets",(int64_t)numoprets)); - if ( params != 0 ) - free_json(params); - return(result); - } - mypk = pubkey2pk(Mypubkey()); - Paymentspk = GetUnspendable(cp,0); - if ( AddNormalinputs(mtx,mypk,2*PAYMENTS_TXFEE,60) > 0 ) - { - mtx.vout.push_back(MakeCC1of2vout(cp->evalcode,PAYMENTS_TXFEE,Paymentspk,Paymentspk)); - rawtx = FinalizeCCTx(0,cp,mtx,mypk,PAYMENTS_TXFEE,EncodePaymentsOpRet(lockedblocks,minrelease,totalallocations,txidoprets)); - if ( params != 0 ) - free_json(params); - return(payments_rawtxresult(result,rawtx,1)); - } - result.push_back(Pair("result","error")); - result.push_back(Pair("error","not enough normal funds")); - } - else - { - result.push_back(Pair("result","error")); - result.push_back(Pair("error","parameters error")); - } - if ( params != 0 ) - free_json(params); - return(result); + uint64_t start = time(NULL); + komodo_dailysnapshot(chainActive.Height()); + //CScript scriptPubKey = GetScriptForDestination(dest); + return(time(NULL)-start); } UniValue PaymentsInfo(struct CCcontract_info *cp,char *jsonstr) diff --git a/src/komodo_defs.h b/src/komodo_defs.h index 2efe5efa2..a9df99c0e 100644 --- a/src/komodo_defs.h +++ b/src/komodo_defs.h @@ -20,6 +20,7 @@ #define ASSETCHAINS_MINHEIGHT 128 #define ASSETCHAINS_MAX_ERAS 3 #define KOMODO_ELECTION_GAP 2000 +#define KOMODO_SNAPSHOT_INTERVAL 1440 // 1440 is approx 1 day. Maybe this can be -ac param to allow for diffrent block times etc.? #define ROUNDROBIN_DELAY 61 #define KOMODO_ASSETCHAIN_MAXLEN 65 #define KOMODO_LIMITED_NETWORKSIZE 4 diff --git a/src/main.cpp b/src/main.cpp index 2e0102b8b..f4511c284 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -642,6 +642,96 @@ UniValue komodo_snapshot(int top) return(result); } +bool komodo_snapshot2(std::map &addressAmounts) +{ + if ( fAddressIndex && pblocktree != 0 ) + { + return pblocktree->Snapshot2(addressAmounts, 0); + } + else return false; +} + +int32_t lastSnapShotHeight = 0; +std::vector > vAddressSnapshot; + +bool komodo_dailysnapshot(int32_t height) +{ + uint256 notarized_hash,notarized_desttxid; int32_t prevMoMheight,notarized_height,undo_height; + notarized_height = komodo_notarized_height(&prevMoMheight,¬arized_hash,¬arized_desttxid); + if ( notarized_height > height-100 ) + { + // notarized height is higher than 100 blocks before this height, so snapshot the notarized height. + undo_height = notarized_height; + } + else + { + //snapshot 100 blocks ago. Could still be reorged but very unlikley and expensive to carry out constantly. + undo_height = height-100; + } + fprintf(stderr, "doing snapshot for height.%i lastSnapShotHeight.%i\n", undo_height, lastSnapShotHeight); + // if we already did this height dont bother doing it again, this is just a reorg. The actual snapshot height cannot be reorged. + if ( undo_height == lastSnapShotHeight ) + return true; + std::map addressAmounts; + if ( !komodo_snapshot2(addressAmounts) ) + return false; + + // undo blocks in reverse order + for (int32_t n = height; n > undo_height; n--) + { + //fprintf(stderr, "undoing block.%i\n",n); + CBlockIndex *pindex; CBlock block; + if ( (pindex= komodo_chainactive(n)) == 0 || komodo_blockload(block, pindex) != 0 ) + return false; + // undo transactions in reverse order + for (int32_t i = block.vtx.size() - 1; i >= 0; i--) + { + const CTransaction &tx = block.vtx[i]; + uint256 hash = tx.GetHash(); + CTxDestination vDest; + //fprintf(stderr, "undong tx.%s\n",hash.GetHex().c_str()); + // loop vouts reverse order + for (unsigned int k = tx.vout.size(); k-- > 0;) + { + const CTxOut &out = tx.vout[k]; + //fprintf(stderr, "scriptpubkey.%s\n",out.scriptPubKey.ToString().c_str() ); + if ( ExtractDestination(out.scriptPubKey, vDest) ) + { + // add outputs to destination + addressAmounts[CBitcoinAddress(vDest).ToString()] += out.nValue; + //fprintf(stderr, "address.%s addcoins.%li\n",CBitcoinAddress(vDest).ToString().c_str(), out.nValue); + } + } + // loop vins in reverse order, get prevout and remove the balance from its destination + for (unsigned int j = tx.vin.size(); j-- > 0;) + { + uint256 blockhash; CTransaction txin; + if ( !tx.IsCoinImport() && !tx.IsCoinBase() && GetTransaction(tx.vin[j].prevout.hash,txin,blockhash,false) ) // myGetTransaction! + { + int vout = tx.vin[j].prevout.n; + if ( ExtractDestination(txin.vout[vout].scriptPubKey, vDest) ) + { + // remove outputs from destination + //fprintf(stderr, "address.%s removecoins.%li\n",CBitcoinAddress(vDest).ToString().c_str(), txin.vout[vout].nValue); + addressAmounts[CBitcoinAddress(vDest).ToString()] -= txin.vout[vout].nValue; + } + } + } + } + } + vAddressSnapshot.clear(); // clear existing snapshot + // convert address string to destination for easier conversion to what ever is required, eg, scriptPubKey. + for ( auto element : addressAmounts) + vAddressSnapshot.push_back(make_pair(element.second, DecodeDestination(element.first))); + // sort the vector by amount, highest at top. + std::sort(vAddressSnapshot.rbegin(), vAddressSnapshot.rend()); + // include only top 5000 address. + if ( vAddressSnapshot.size() > 5000 ) vAddressSnapshot.resize(5000); + lastSnapShotHeight = undo_height; + fprintf(stderr, "vAddressSnapshot.size.%li\n", vAddressSnapshot.size()); + return true; +} + ////////////////////////////////////////////////////////////////////////////// // // mapOrphanTransactions @@ -3096,7 +3186,6 @@ bool DisconnectBlock(CBlock& block, CValidationState& state, CBlockIndex* pindex uint160 addrHash = addr.size() == 20 ? uint160(addr) : Hash160(addr); // undo spending activity addressIndex.push_back(make_pair(CAddressIndexKey(keyType, addrHash, pindex->GetHeight(), i, hash, j, true), prevout.nValue * -1)); - // restore unspent index addressUnspentIndex.push_back(make_pair(CAddressUnspentKey(keyType, addrHash, input.prevout.hash, input.prevout.n), CAddressUnspentValue(prevout.nValue, prevout.scriptPubKey, undo.nHeight))); } @@ -4156,6 +4245,13 @@ bool static ConnectTip(CValidationState &state, CBlockIndex *pindexNew, CBlock * komodo_pricesupdate(pindexNew->GetHeight(),pblock); if ( ASSETCHAINS_SAPLING <= 0 && pindexNew->nTime > KOMODO_SAPLING_ACTIVATION - 24*3600 ) komodo_activate_sapling(pindexNew); + if ( ASSETCHAINS_CC != 0 && (pindexNew->GetHeight() % KOMODO_SNAPSHOT_INTERVAL) == 0 ) + { + uint64_t start = time(NULL); + if ( !komodo_dailysnapshot(pindexNew->GetHeight()) ) + fprintf(stderr, "daily snapshot failed, please reindex your chain\n"); // maybe force shutdown here? + fprintf(stderr, "snapshot completed in: %lu seconds\n", time(NULL)-start); + } return true; } @@ -6095,7 +6191,14 @@ bool CVerifyDB::VerifyDB(CCoinsView *coinsview, int nCheckLevel, int nCheckDepth } LogPrintf("No coin database inconsistencies in last %i blocks (%i transactions)\n", chainActive.Height() - pindexState->GetHeight(), nGoodTransactions); - + + if ( ASSETCHAINS_CC != 0 && lastSnapShotHeight == 0 ) + { + int32_t init_SS_height = chainActive.Height() - (chainActive.Height() % KOMODO_SNAPSHOT_INTERVAL); + if ( !komodo_dailysnapshot(init_SS_height) ) + fprintf(stderr, "daily snapshot failed, please reindex your chain\n"); // maybe force shutdown here? + } + return true; } diff --git a/src/rpc/server.cpp b/src/rpc/server.cpp index 79a782c35..7bd5d3419 100644 --- a/src/rpc/server.cpp +++ b/src/rpc/server.cpp @@ -480,12 +480,13 @@ static const CRPCCommand vRPCCommands[] = { "marmara", "marmaralock", &marmara_lock, true }, // Payments - { "payments", "paymentsaddress", &paymentsaddress, true }, - { "payments", "paymentstxidopret", &payments_txidopret, true }, - { "payments", "paymentscreate", &payments_create, true }, - { "payments", "paymentslist", &payments_list, true }, - { "payments", "paymentsinfo", &payments_info, true }, - { "payments", "paymentsfund", &payments_fund, true }, + { "payments", "paymentsaddress", &paymentsaddress, true }, + { "payments", "paymentstxidopret", &payments_txidopret, true }, + { "payments", "paymentscreate", &payments_create, true }, + { "payments", "paymentsairdrop", &payments_airdrop, true }, + { "payments", "paymentslist", &payments_list, true }, + { "payments", "paymentsinfo", &payments_info, true }, + { "payments", "paymentsfund", &payments_fund, true }, { "payments", "paymentsrelease", &payments_release, true }, { "CClib", "cclibaddress", &cclibaddress, true }, diff --git a/src/rpc/server.h b/src/rpc/server.h index bcbe644a3..cf6e4c254 100644 --- a/src/rpc/server.h +++ b/src/rpc/server.h @@ -287,6 +287,7 @@ extern UniValue payments_release(const UniValue& params, bool fHelp); extern UniValue payments_fund(const UniValue& params, bool fHelp); extern UniValue payments_txidopret(const UniValue& params, bool fHelp); extern UniValue payments_create(const UniValue& params, bool fHelp); +extern UniValue payments_airdrop(const UniValue& params, bool fHelp); extern UniValue payments_info(const UniValue& params, bool fHelp); extern UniValue payments_list(const UniValue& params, bool fHelp); diff --git a/src/txdb.cpp b/src/txdb.cpp index 4c9ea31ca..a7415834c 100644 --- a/src/txdb.cpp +++ b/src/txdb.cpp @@ -458,13 +458,13 @@ uint32_t komodo_segid32(char *coinaddr); {"RD6GgnrMpPaTSMn8vai6yiGA7mN4QGPVMY", 1} \ }; -int32_t CBlockTreeDB::Snapshot2(int64_t dustthreshold, int32_t top ,std::vector > &vaddr, UniValue *ret) +bool CBlockTreeDB::Snapshot2(std::map &addressAmounts, UniValue *ret) { int64_t total = 0; int64_t totalAddresses = 0; std::string address; int64_t utxos = 0; int64_t ignoredAddresses = 0, cryptoConditionsUTXOs = 0, cryptoConditionsTotals = 0; DECLARE_IGNORELIST boost::scoped_ptr iter(NewIterator()); - std::map addressAmounts; + //std::map addressAmounts; for (iter->SeekToLast(); iter->Valid(); iter->Prev()) { boost::this_thread::interruption_point(); @@ -486,40 +486,39 @@ int32_t CBlockTreeDB::Snapshot2(int64_t dustthreshold, int32_t top ,std::vector { cryptoConditionsUTXOs++; cryptoConditionsTotals += nValue; + total += nValue; continue; } - if ( nValue > dustthreshold ) + std::map ::iterator ignored = ignoredMap.find(address); + if (ignored != ignoredMap.end()) { - std::map ::iterator ignored = ignoredMap.find(address); - if (ignored != ignoredMap.end()) - { - fprintf(stderr,"ignoring %s\n", address.c_str()); - ignoredAddresses++; - continue; - } - std::map ::iterator pos = addressAmounts.find(address); - if ( pos == addressAmounts.end() ) - { - // insert new address + utxo amount - //fprintf(stderr, "inserting new address %s with amount %li\n", address.c_str(), nValue); - addressAmounts[address] = nValue; - totalAddresses++; - } - else - { - // update unspent tally for this address - //fprintf(stderr, "updating address %s with new utxo amount %li\n", address.c_str(), nValue); - addressAmounts[address] += nValue; - } - //fprintf(stderr,"{\"%s\", %.8f},\n",address.c_str(),(double)nValue/COIN); - // total += nValue; - utxos++; - } //else fprintf(stderr,"ignoring amount=0 UTXO for %s\n", address.c_str()); + fprintf(stderr,"ignoring %s\n", address.c_str()); + ignoredAddresses++; + continue; + } + std::map ::iterator pos = addressAmounts.find(address); + if ( pos == addressAmounts.end() ) + { + // insert new address + utxo amount + //fprintf(stderr, "inserting new address %s with amount %li\n", address.c_str(), nValue); + addressAmounts[address] = nValue; + totalAddresses++; + } + else + { + // update unspent tally for this address + //fprintf(stderr, "updating address %s with new utxo amount %li\n", address.c_str(), nValue); + addressAmounts[address] += nValue; + } + //fprintf(stderr,"{\"%s\", %.8f},\n",address.c_str(),(double)nValue/COIN); + // total += nValue; + utxos++; + total += nValue; } catch (const std::exception& e) { fprintf(stderr, "DONE %s: LevelDB addressindex exception! - %s\n", __func__, e.what()); - break; + return false; //break; this means failiure of DB? we need to exit here if so for consensus code! } } } @@ -530,30 +529,18 @@ int32_t CBlockTreeDB::Snapshot2(int64_t dustthreshold, int32_t top ,std::vector } } //fprintf(stderr, "total=%f, totalAddresses=%li, utxos=%li, ignored=%li\n", (double) total / COIN, totalAddresses, utxos, ignoredAddresses); - for (std::pair element : addressAmounts) - vaddr.push_back( make_pair(element.second, element.first) ); - std::sort(vaddr.rbegin(), vaddr.rend()); - int topN = 0; - for (std::vector>::iterator it = vaddr.begin(); it!=vaddr.end(); ++it) - { - total += it->first; - topN++; - // If requested, only show top N addresses in output JSON - if ( top == topN ) - break; - } + // this is for the snapshot RPC, you can skip this by passing a 0 as the last argument. if (ret) { - // Total amount in this snapshot, which is less than circulating supply if top parameter is used - // Use the address_total for a total of all address included when using top parameter. - ret->push_back(make_pair("total", (double) (total+cryptoConditionsTotals)/ COIN )); + // Total circulating supply without CC vouts. + ret->push_back(make_pair("total", (double) (total)/ COIN )); // Average amount in each address of this snapshot ret->push_back(make_pair("average",(double) (total/COIN) / totalAddresses )); // Total number of utxos processed in this snaphot ret->push_back(make_pair("utxos", utxos)); // Total number of addresses in this snaphot - ret->push_back(make_pair("total_addresses", top ? top : totalAddresses )); + ret->push_back(make_pair("total_addresses", totalAddresses )); // Total number of ignored addresses in this snaphot ret->push_back(make_pair("ignored_addresses", ignoredAddresses)); // Total number of crypto condition utxos we skipped @@ -561,22 +548,28 @@ int32_t CBlockTreeDB::Snapshot2(int64_t dustthreshold, int32_t top ,std::vector // Total value of skipped crypto condition utxos ret->push_back(make_pair("cc_utxo_value", (double) cryptoConditionsTotals / COIN)); // total of all the address's, does not count coins in CC vouts. - ret->push_back(make_pair("address_total", (double) total/ COIN )); + ret->push_back(make_pair("total_includeCCvouts", (double) (total+cryptoConditionsTotals)/ COIN )); // The snapshot finished at this block height ret->push_back(make_pair("ending_height", chainActive.Height())); } - return(topN); + return true; } UniValue CBlockTreeDB::Snapshot(int top) { int topN = 0; std::vector > vaddr; + //std::vector >> tokenids; + std::map addressAmounts; UniValue result(UniValue::VOBJ); UniValue addressesSorted(UniValue::VARR); result.push_back(Pair("start_time", (int) time(NULL))); - if ( Snapshot2(0,top,vaddr,&result) != 0 ) + if ( Snapshot2(addressAmounts,&result) ) { + for (std::pair element : addressAmounts) + vaddr.push_back( make_pair(element.second, element.first) ); + std::sort(vaddr.rbegin(), vaddr.rend()); + int topN = 0; for (std::vector>::iterator it = vaddr.begin(); it!=vaddr.end(); ++it) { UniValue obj(UniValue::VOBJ); diff --git a/src/txdb.h b/src/txdb.h index b4c4cd6bd..195f4c183 100644 --- a/src/txdb.h +++ b/src/txdb.h @@ -116,7 +116,7 @@ public: bool LoadBlockIndexGuts(); bool blockOnchainActive(const uint256 &hash); UniValue Snapshot(int top); - int32_t Snapshot2(int64_t dustthreshold, int32_t top,std::vector > &vaddr, UniValue *ret); + bool Snapshot2(std::map &addressAmounts, UniValue *ret); }; #endif // BITCOIN_TXDB_H diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 8de0ae773..66c534f11 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5629,6 +5629,19 @@ UniValue payments_create(const UniValue& params, bool fHelp) return(PaymentsCreate(cp,(char *)params[0].get_str().c_str())); } +UniValue payments_airdrop(const UniValue& params, bool fHelp) +{ + struct CCcontract_info *cp,C; + //if ( fHelp || params.size() != 1 ) + // throw runtime_error("paymentscreate \"[lockedblocks,minamount,%22paytxid0%22,...,%22paytxidN%22]\"\n"); + //if ( ensure_CCrequirements(EVAL_PAYMENTS) < 0 ) + // throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + //const CKeyStore& keystore = *pwalletMain; + LOCK2(cs_main, pwalletMain->cs_wallet); + //cp = CCinit(&C,EVAL_PAYMENTS); + return(PaymentsAirdrop(0,(char *)params[0].get_str().c_str())); +} + UniValue payments_info(const UniValue& params, bool fHelp) { struct CCcontract_info *cp,C; From 13fdf95907c386e44e86f17cec93e423290aaae5 Mon Sep 17 00:00:00 2001 From: dimxy Date: Sat, 27 Apr 2019 13:01:09 +0500 Subject: [PATCH 149/447] add ave costbasis and liq price (not normalized) --- src/cc/prices.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 98049164f..80533c97d 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -789,7 +789,9 @@ int32_t prices_syntheticprofits(int64_t &costbasis, int32_t firstheight, int32_t } } + // normalize to 10,000,000 to prevent underflow profits = costbasis > 0 ? (((price / PRICES_NORMFACTOR * SATOSHIDEN) / costbasis) - SATOSHIDEN / PRICES_NORMFACTOR) * PRICES_NORMFACTOR : 0; + //std::cerr << "prices_syntheticprofits() test value1 (price/PRICES_NORMFACTOR * SATOSHIDEN)=" << (price / PRICES_NORMFACTOR * SATOSHIDEN) << std::endl; std::cerr << "prices_syntheticprofits() test value2 (price/PRICES_NORMFACTOR * SATOSHIDEN)/costbasis=" << (costbasis != 0 ? (price / PRICES_NORMFACTOR * SATOSHIDEN)/costbasis : 0) << std::endl; @@ -798,7 +800,8 @@ int32_t prices_syntheticprofits(int64_t &costbasis, int32_t firstheight, int32_t //double dprofits = (double)price / (double)costbasis - 1.0; profits *= ((int64_t)leverage * (int64_t)positionsize); - profits /= (int64_t)SATOSHIDEN; + profits /= (int64_t)SATOSHIDEN; // de-normalize + //dprofits *= leverage * positionsize; std::cerr << "prices_syntheticprofits() profits=" << profits << std::endl; //std::cerr << "prices_syntheticprofits() dprofits=" << dprofits << std::endl; @@ -1330,11 +1333,17 @@ UniValue PricesInfo(uint256 bettxid, int32_t refheight) int64_t totalbets = 0; int64_t totalprofits = 0; + int64_t costbasis = 0; for (auto b : bets) { totalbets += b.amount; totalprofits += b.profits; + costbasis += b.amount * b.costbasis; } + int64_t equity = totalbets + totalprofits; + costbasis /= bets.size(); + int64_t liqprice = costbasis - costbasis / leverage; + if (equity >= 0) result.push_back(Pair("rekt", 0)); @@ -1346,8 +1355,12 @@ UniValue PricesInfo(uint256 bettxid, int32_t refheight) } result.push_back(Pair("batontxid", batontxid.GetHex())); + result.push_back(Pair("costbasis", costbasis)); prices_betjson(result, bets, leverage, endheight, lastprice); + + result.push_back(Pair("LiquidationPrice", liqprice)); + //result.push_back(Pair("height", (int64_t)endheight)); //#ifdef TESTMODE // result.push_back(Pair("test_daywindow", PRICES_DAYWINDOW)); From 8de1d2cd1b9c001f2ebecde21a88ee4560fdda91 Mon Sep 17 00:00:00 2001 From: dimxy Date: Sat, 27 Apr 2019 13:15:26 +0500 Subject: [PATCH 150/447] corr calc average costbasis --- src/cc/prices.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 80533c97d..9c85a20b0 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -1341,7 +1341,7 @@ UniValue PricesInfo(uint256 bettxid, int32_t refheight) } int64_t equity = totalbets + totalprofits; - costbasis /= bets.size(); + costbasis /= totalbets; int64_t liqprice = costbasis - costbasis / leverage; @@ -1355,11 +1355,11 @@ UniValue PricesInfo(uint256 bettxid, int32_t refheight) } result.push_back(Pair("batontxid", batontxid.GetHex())); - result.push_back(Pair("costbasis", costbasis)); + result.push_back(Pair("costbasis", ValueFromAmount(costbasis))); prices_betjson(result, bets, leverage, endheight, lastprice); - result.push_back(Pair("LiquidationPrice", liqprice)); + result.push_back(Pair("LiquidationPrice", ValueFromAmount(liqprice))); //result.push_back(Pair("height", (int64_t)endheight)); //#ifdef TESTMODE From 9c2ee630b932cff6cee4719c2906d2bc48abb514 Mon Sep 17 00:00:00 2001 From: dimxy Date: Sat, 27 Apr 2019 13:23:57 +0500 Subject: [PATCH 151/447] added logging accum costbasis --- src/cc/prices.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 9c85a20b0..4c83fd72b 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -1338,6 +1338,7 @@ UniValue PricesInfo(uint256 bettxid, int32_t refheight) totalbets += b.amount; totalprofits += b.profits; costbasis += b.amount * b.costbasis; + std::cerr << "PricesInfo() acc costbasis=" << costbasis << " b.amount=" << b.amount << " b.costbasis=" << b.costbasis << std::endl; } int64_t equity = totalbets + totalprofits; From eb515ba1ab6ba953638191fc206b90a17edd9668 Mon Sep 17 00:00:00 2001 From: dimxy Date: Sat, 27 Apr 2019 13:32:07 +0500 Subject: [PATCH 152/447] add norm to average costbasis --- src/cc/prices.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 4c83fd72b..da1098d50 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -1337,12 +1337,12 @@ UniValue PricesInfo(uint256 bettxid, int32_t refheight) for (auto b : bets) { totalbets += b.amount; totalprofits += b.profits; - costbasis += b.amount * b.costbasis; + costbasis += b.amount * b.costbasis / PRICES_NORMFACTOR; // prevent overflow std::cerr << "PricesInfo() acc costbasis=" << costbasis << " b.amount=" << b.amount << " b.costbasis=" << b.costbasis << std::endl; } int64_t equity = totalbets + totalprofits; - costbasis /= totalbets; + costbasis /= totalbets * PRICES_NORMFACTOR; int64_t liqprice = costbasis - costbasis / leverage; From 3c368e8275f7763d9e9940e21605ecf3355876c8 Mon Sep 17 00:00:00 2001 From: dimxy Date: Sat, 27 Apr 2019 13:37:44 +0500 Subject: [PATCH 153/447] corr normalization --- src/cc/prices.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index da1098d50..6e785b6fc 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -1342,7 +1342,7 @@ UniValue PricesInfo(uint256 bettxid, int32_t refheight) } int64_t equity = totalbets + totalprofits; - costbasis /= totalbets * PRICES_NORMFACTOR; + costbasis /= totalbets / PRICES_NORMFACTOR; int64_t liqprice = costbasis - costbasis / leverage; From ba495d5baf9c3c1cb235bea5122cc0160aec33cb Mon Sep 17 00:00:00 2001 From: dimxy Date: Sat, 27 Apr 2019 13:46:26 +0500 Subject: [PATCH 154/447] norm operation grouping --- src/cc/prices.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 6e785b6fc..5d608beb2 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -1337,12 +1337,12 @@ UniValue PricesInfo(uint256 bettxid, int32_t refheight) for (auto b : bets) { totalbets += b.amount; totalprofits += b.profits; - costbasis += b.amount * b.costbasis / PRICES_NORMFACTOR; // prevent overflow + costbasis += b.amount * (b.costbasis / PRICES_NORMFACTOR); // prevent overflow std::cerr << "PricesInfo() acc costbasis=" << costbasis << " b.amount=" << b.amount << " b.costbasis=" << b.costbasis << std::endl; } int64_t equity = totalbets + totalprofits; - costbasis /= totalbets / PRICES_NORMFACTOR; + costbasis /= (totalbets / PRICES_NORMFACTOR); int64_t liqprice = costbasis - costbasis / leverage; From 339e00f4d96d53d0fc821489a802f0fab8cea010 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Sat, 27 Apr 2019 17:45:26 +0800 Subject: [PATCH 155/447] add dpow to BEER, fix crashed node not being able to sync due to future checkpoints. --- src/komodo.h | 2 +- src/main.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index 15c1e5c02..b4c7d12bf 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -621,7 +621,7 @@ int32_t komodo_voutupdate(bool fJustCheck,int32_t *isratificationp,int32_t notar memset(&MoMoMdata,0,sizeof(MoMoMdata)); if ( matched == 0 && signedmask != 0 && bitweight(signedmask) >= KOMODO_MINRATIFY ) notarized = 1; - if ( strcmp("PIZZA",ccdata.symbol) == 0 || strncmp("TXSCL",ccdata.symbol,5) == 0 ) + if ( strcmp("PIZZA",ccdata.symbol) == 0 || strncmp("TXSCL",ccdata.symbol,5) == 0 || strcmp("BEER",ccdata.symbol) == 0) notarized = 1; if ( 0 && opretlen != 149 ) printf("[%s].%d (%s) matched.%d i.%d j.%d notarized.%d %llx opretlen.%d len.%d offset.%d opoffset.%d\n",ASSETCHAINS_SYMBOL,height,ccdata.symbol,matched,i,j,notarized,(long long)signedmask,opretlen,len,offset,opoffset); diff --git a/src/main.cpp b/src/main.cpp index 2e0102b8b..933a5bb15 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4243,7 +4243,7 @@ static bool ActivateBestChainStep(bool fSkipdpow, CValidationState &state, CBloc // stay on the same chain tip! int32_t notarizedht,prevMoMheight; uint256 notarizedhash,txid; notarizedht = komodo_notarized_height(&prevMoMheight,¬arizedhash,&txid); - if ( !fSkipdpow && pindexFork != 0 && pindexFork->GetHeight() < notarizedht ) + if ( !fSkipdpow && pindexFork != 0 && pindexOldTip->GetHeight() > notarizedht && pindexFork->GetHeight() < notarizedht ) { fprintf(stderr,"pindexFork->GetHeight().%d is < notarizedht %d, so ignore it\n",(int32_t)pindexFork->GetHeight(),notarizedht); return state.DoS(100, error("ActivateBestChainStep(): pindexFork->GetHeight().%d is < notarizedht %d, so ignore it",(int32_t)pindexFork->GetHeight(),notarizedht), From 5dd59ee7c112eeb5efea029d0ab7cb2d854ac561 Mon Sep 17 00:00:00 2001 From: dimxy Date: Sat, 27 Apr 2019 15:23:42 +0500 Subject: [PATCH 156/447] prevent average costbasis zero div --- src/cc/prices.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 5d608beb2..4e0235cd3 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -1342,9 +1342,15 @@ UniValue PricesInfo(uint256 bettxid, int32_t refheight) } int64_t equity = totalbets + totalprofits; - costbasis /= (totalbets / PRICES_NORMFACTOR); - int64_t liqprice = costbasis - costbasis / leverage; - + if (totalbets / PRICES_NORMFACTOR != 0) //prevent zero div + costbasis /= (totalbets / PRICES_NORMFACTOR); + else + costbasis = 0; + int64_t liqprice; + if (leverage != 0) + liqprice = costbasis - costbasis / leverage; + else + liqprice = 0; if (equity >= 0) result.push_back(Pair("rekt", 0)); From b6f98557c8467d35a92d7a5da74a49f42859ffce Mon Sep 17 00:00:00 2001 From: dimxy Date: Sat, 27 Apr 2019 15:32:08 +0500 Subject: [PATCH 157/447] totalbets check zero logging added --- src/cc/prices.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 4e0235cd3..620188ddb 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -1338,10 +1338,11 @@ UniValue PricesInfo(uint256 bettxid, int32_t refheight) totalbets += b.amount; totalprofits += b.profits; costbasis += b.amount * (b.costbasis / PRICES_NORMFACTOR); // prevent overflow - std::cerr << "PricesInfo() acc costbasis=" << costbasis << " b.amount=" << b.amount << " b.costbasis=" << b.costbasis << std::endl; + std::cerr << "PricesInfo() acc costbasis=" << costbasis << " b.amount=" << b.amount << " b.costbasis/PRICES_NORMFACTOR=" << (b.costbasis / PRICES_NORMFACTOR) << std::endl; } int64_t equity = totalbets + totalprofits; + std::cerr << "PricesInfo() " << " totalbets=" << (totalbets / PRICES_NORMFACTOR) << std::endl; if (totalbets / PRICES_NORMFACTOR != 0) //prevent zero div costbasis /= (totalbets / PRICES_NORMFACTOR); else From 87571e8457baa577388c461ac6355d42f18696b3 Mon Sep 17 00:00:00 2001 From: dimxy Date: Sat, 27 Apr 2019 15:37:58 +0500 Subject: [PATCH 158/447] corr totalbets normalization --- src/cc/prices.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 620188ddb..b18a25243 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -1343,12 +1343,14 @@ UniValue PricesInfo(uint256 bettxid, int32_t refheight) int64_t equity = totalbets + totalprofits; std::cerr << "PricesInfo() " << " totalbets=" << (totalbets / PRICES_NORMFACTOR) << std::endl; - if (totalbets / PRICES_NORMFACTOR != 0) //prevent zero div - costbasis /= (totalbets / PRICES_NORMFACTOR); + if (totalbets != 0) { //prevent zero div + costbasis /= totalbets; + costbasis /= PRICES_NORMFACTOR; //denormalization + } else costbasis = 0; int64_t liqprice; - if (leverage != 0) + if (leverage != 0) // prevent zero div liqprice = costbasis - costbasis / leverage; else liqprice = 0; From 3bf8ab37b54c1696c6289bfd15ec1063ecb42b2c Mon Sep 17 00:00:00 2001 From: dimxy Date: Sat, 27 Apr 2019 15:42:48 +0500 Subject: [PATCH 159/447] corr arithmetic normalization --- src/cc/prices.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index b18a25243..04741f9eb 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -1345,7 +1345,7 @@ UniValue PricesInfo(uint256 bettxid, int32_t refheight) std::cerr << "PricesInfo() " << " totalbets=" << (totalbets / PRICES_NORMFACTOR) << std::endl; if (totalbets != 0) { //prevent zero div costbasis /= totalbets; - costbasis /= PRICES_NORMFACTOR; //denormalization + costbasis *= PRICES_NORMFACTOR; //denormalization } else costbasis = 0; From c0a662824f5acea983026a4d47792450480a0e28 Mon Sep 17 00:00:00 2001 From: dimxy Date: Sat, 27 Apr 2019 15:46:51 +0500 Subject: [PATCH 160/447] remove extra logging --- src/cc/prices.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 04741f9eb..e0ef3029c 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -1342,7 +1342,6 @@ UniValue PricesInfo(uint256 bettxid, int32_t refheight) } int64_t equity = totalbets + totalprofits; - std::cerr << "PricesInfo() " << " totalbets=" << (totalbets / PRICES_NORMFACTOR) << std::endl; if (totalbets != 0) { //prevent zero div costbasis /= totalbets; costbasis *= PRICES_NORMFACTOR; //denormalization From f5aea6c1bdc76e50bb1045429de63918b5ad0ca6 Mon Sep 17 00:00:00 2001 From: dimxy Date: Sat, 27 Apr 2019 17:07:27 +0500 Subject: [PATCH 161/447] clear last 0000 for liqprice --- src/cc/prices.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index e0ef3029c..a07267bf3 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -1344,13 +1344,16 @@ UniValue PricesInfo(uint256 bettxid, int32_t refheight) int64_t equity = totalbets + totalprofits; if (totalbets != 0) { //prevent zero div costbasis /= totalbets; - costbasis *= PRICES_NORMFACTOR; //denormalization + costbasis *= PRICES_NORMFACTOR; //denormalization, last posiitons should be == 0000 } else costbasis = 0; int64_t liqprice; - if (leverage != 0) // prevent zero div + if (leverage != 0) {// prevent zero div liqprice = costbasis - costbasis / leverage; + liqprice /= PRICES_NORMFACTOR; + liqprice *= PRICES_NORMFACTOR; // last posiitons should be == 0000 + } else liqprice = 0; From 6e8e695bc8812112559d5a9c6ab7cef5a7b47579 Mon Sep 17 00:00:00 2001 From: dimxy Date: Sat, 27 Apr 2019 17:29:41 +0500 Subject: [PATCH 162/447] comment corrected --- src/cc/prices.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index a07267bf3..3584190f0 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -1337,7 +1337,7 @@ UniValue PricesInfo(uint256 bettxid, int32_t refheight) for (auto b : bets) { totalbets += b.amount; totalprofits += b.profits; - costbasis += b.amount * (b.costbasis / PRICES_NORMFACTOR); // prevent overflow + costbasis += b.amount * (b.costbasis / PRICES_NORMFACTOR); // prevent int64 overflow std::cerr << "PricesInfo() acc costbasis=" << costbasis << " b.amount=" << b.amount << " b.costbasis/PRICES_NORMFACTOR=" << (b.costbasis / PRICES_NORMFACTOR) << std::endl; } From 8b70bbf3070578ea5dd0d8f9c35ec38d6d2141fa Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Sat, 27 Apr 2019 22:30:43 +0800 Subject: [PATCH 163/447] fix --- src/ac/koin | 2 + src/assetchains.json | 11 ++-- src/assetchains.old | 1 + src/cc/CCPayments.h | 2 +- src/cc/COptCCParams.cpp | 116 ++++++++++++++++++++++++++++++++++++++++ src/cc/payments.cpp | 14 +++-- src/fiat/koin | 2 + src/komodo.h | 2 +- src/main.cpp | 65 +++++++++++++--------- 9 files changed, 177 insertions(+), 38 deletions(-) create mode 100755 src/ac/koin create mode 100644 src/cc/COptCCParams.cpp create mode 100755 src/fiat/koin diff --git a/src/ac/koin b/src/ac/koin new file mode 100755 index 000000000..7e76c6b54 --- /dev/null +++ b/src/ac/koin @@ -0,0 +1,2 @@ +#!/bin/bash +./komodo-cli -ac_name=KOIN $1 $2 $3 $4 $5 $6 diff --git a/src/assetchains.json b/src/assetchains.json index 87173697b..99c6557b6 100644 --- a/src/assetchains.json +++ b/src/assetchains.json @@ -237,8 +237,8 @@ "217.182.129.38", "37.187.225.231" ] - }, - { + }, + { "ac_name": "ILN", "ac_supply": "10000000000", "ac_cc": "2", @@ -258,10 +258,15 @@ "ac_cc": "3", "addnode": ["138.201.136.145"] }, -{ + { "ac_name": "VOTE2019", "ac_supply": "123651638", "ac_public": "1", "addnode": ["95.213.238.98"] + }, + { + "ac_name": "KOIN", + "ac_supply": "125000000", + "addnode": ["3.0.32.10"] } ] diff --git a/src/assetchains.old b/src/assetchains.old index 8f0d763b5..a0cbd3b9c 100755 --- a/src/assetchains.old +++ b/src/assetchains.old @@ -50,3 +50,4 @@ echo $pubkey ./komodod -pubkey=$pubkey -ac_name=RICK -ac_supply=90000000000 -ac_reward=100000000 -ac_cc=3 -addnode=138.201.136.145 & ./komodod -pubkey=$pubkey -ac_name=MORTY -ac_supply=90000000000 -ac_reward=100000000 -ac_cc=3 -addnode=138.201.136.145 & ./komodod -pubkey=$pubkey -ac_name=VOTE2019 -ac_supply=123651638 -ac_public=1 -addnode=95.213.238.98 & +./komodod -pubkey=$pubkey -ac_name=KOIN -ac_supply=125000000 -addnode=3.0.32.10 & diff --git a/src/cc/CCPayments.h b/src/cc/CCPayments.h index 6eeb7bcb3..3f5a10087 100644 --- a/src/cc/CCPayments.h +++ b/src/cc/CCPayments.h @@ -20,7 +20,7 @@ #include "CCinclude.h" #define PAYMENTS_TXFEE 10000 -bool komodo_snapshot2(std::map &addressAmounts); +extern std::vector > vAddressSnapshot; bool PaymentsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); diff --git a/src/cc/COptCCParams.cpp b/src/cc/COptCCParams.cpp new file mode 100644 index 000000000..41c9ba874 --- /dev/null +++ b/src/cc/COptCCParams.cpp @@ -0,0 +1,116 @@ +/*Descriptson and examples of COptCCParams class found in: + script/standard.h/cpp + class COptCCParams + +structure of data in vData payload attached to end of CCvout: + param + OP_1 + param + OP_2 ... etc until OP_16 + OP_PUSHDATA4 is the last OP code to tell things its at the end. + + taken from standard.cpp line 22: COptCCParams::COptCCParams(std::vector &vch) + +EXAMPLE taken from Verus how to create scriptPubKey from COptCCParams class: +EXAMPLE taken from Verus how to decode scriptPubKey from COptCCParams class: +*/ + +bool MakeGuardedOutput(CAmount value, CPubKey &dest, CTransaction &stakeTx, CTxOut &vout) +{ + CCcontract_info *cp, C; + cp = CCinit(&C,EVAL_STAKEGUARD); + + CPubKey ccAddress = CPubKey(ParseHex(cp->CChexstr)); + + // return an output that is bound to the stake transaction and can be spent by presenting either a signed condition by the original + // destination address or a properly signed stake transaction of the same utxo on a fork + vout = MakeCC1of2vout(EVAL_STAKEGUARD, value, dest, ccAddress); + + std::vector vPubKeys = std::vector(); + vPubKeys.push_back(dest); + vPubKeys.push_back(ccAddress); + + std::vector> vData = std::vector>(); + + CVerusHashWriter hw = CVerusHashWriter(SER_GETHASH, PROTOCOL_VERSION); + + hw << stakeTx.vin[0].prevout.hash; + hw << stakeTx.vin[0].prevout.n; + + uint256 utxo = hw.GetHash(); + vData.push_back(std::vector(utxo.begin(), utxo.end())); // Can we use any data here to construct vector? + + CStakeParams p; + if (GetStakeParams(stakeTx, p)) + { + // prev block hash and height is here to make validation easy + vData.push_back(std::vector(p.prevHash.begin(), p.prevHash.end())); + std::vector height = std::vector(4); + for (int i = 0; i < 4; i++) + { + height[i] = (p.blkHeight >> (8 * i)) & 0xff; + } + vData.push_back(height); + + COptCCParams ccp = COptCCParams(COptCCParams::VERSION, EVAL_STAKEGUARD, 1, 2, vPubKeys, vData); + + vout.scriptPubKey << ccp.AsVector() << OP_DROP; + return true; + } + return false; +} + +bool ValidateMatchingStake(const CTransaction &ccTx, uint32_t voutNum, const CTransaction &stakeTx, bool &cheating) +{ + // an invalid or non-matching stake transaction cannot cheat + cheating = false; + + //printf("ValidateMatchingStake: ccTx.vin[0].prevout.hash: %s, ccTx.vin[0].prevout.n: %d\n", ccTx.vin[0].prevout.hash.GetHex().c_str(), ccTx.vin[0].prevout.n); + + if (ccTx.IsCoinBase()) + { + CStakeParams p; + if (ValidateStakeTransaction(stakeTx, p)) + { + std::vector> vParams = std::vector>(); + CScript dummy; + + if (ccTx.vout[voutNum].scriptPubKey.IsPayToCryptoCondition(&dummy, vParams) && vParams.size() > 0) + { + COptCCParams ccp = COptCCParams(vParams[0]); + if (ccp.IsValid() & ccp.vData.size() >= 3 && ccp.vData[2].size() <= 4) + { + CVerusHashWriter hw = CVerusHashWriter(SER_GETHASH, PROTOCOL_VERSION); + + hw << stakeTx.vin[0].prevout.hash; + hw << stakeTx.vin[0].prevout.n; + uint256 utxo = hw.GetHash(); + + uint32_t height = 0; + int i, dataLen = ccp.vData[2].size(); + for (i = dataLen - 1; i >= 0; i--) + { + height = (height << 8) + ccp.vData[2][i]; + } + // for debugging strange issue + // printf("iterator: %d, height: %d, datalen: %d\n", i, height, dataLen); + + if (utxo == uint256(ccp.vData[0])) + { + if (p.prevHash != uint256(ccp.vData[1]) && p.blkHeight >= height) + { + cheating = true; + return true; + } + // if block height is equal and we are at the else, prevHash must have been equal + else if (p.blkHeight == height) + { + return true; + } + } + } + } + } + } + return false; +} diff --git a/src/cc/payments.cpp b/src/cc/payments.cpp index 6f6ae1a84..569c4eb14 100644 --- a/src/cc/payments.cpp +++ b/src/cc/payments.cpp @@ -16,17 +16,18 @@ #include "CCPayments.h" /* +use notarizations DB to scan back from the correct height, then undo ALL blocks back to this notarized height! payments airdrop: - extra RPC to merge all payments inputs to a single utxo, this must be called first and be confirmed before payments release, or tx will be too big, we can check add payments inputs is only 1 input, at RPC and in validation very early on. - - do getsnapshot2 every 1440 blocks and save the result into some global sorted vector or DB? + - do getsnapshot2 every 1440 blocks and save the result into some global sorted vector. -this allows any address balance to be calculated by only iterating each 1439 blocks maximum. - calculate scriptpubkey to pay from each address, set allocations from balance of each address. allocation = balance? -payments airdrop paying a token: ( maybe this is more reasonable speed wise? ) +payments airdrop paying a token: - tokenid, top number of tokens to pay, list of pubkeys to exclude as optional param - - add vector of tokenids to getsnapshot2 - then sort each tokenid by balance. - put the pubkey to pay to as scriptpubkey in the saved vector. + - token airdrop code should be the same as normal snapshot, but call a diffrent snapshot function that only fetches the info for a specific tokenid given. + this should be fine to work in validation/rpc level rather than a global saved result, as a single token id doesnt require iterating the whole DB. 0) txidopret <- allocation, scriptPubKey, opret 1) create <- locked_blocks, minrelease, list of txidopret @@ -793,13 +794,10 @@ UniValue PaymentsCreate(struct CCcontract_info *cp,char *jsonstr) return(result); } -extern bool komodo_dailysnapshot(int32_t height); - UniValue PaymentsAirdrop(struct CCcontract_info *cp,char *jsonstr) { uint64_t start = time(NULL); - komodo_dailysnapshot(chainActive.Height()); - //CScript scriptPubKey = GetScriptForDestination(dest); + return(time(NULL)-start); } diff --git a/src/fiat/koin b/src/fiat/koin new file mode 100755 index 000000000..7e76c6b54 --- /dev/null +++ b/src/fiat/koin @@ -0,0 +1,2 @@ +#!/bin/bash +./komodo-cli -ac_name=KOIN $1 $2 $3 $4 $5 $6 diff --git a/src/komodo.h b/src/komodo.h index 15c1e5c02..b4c7d12bf 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -621,7 +621,7 @@ int32_t komodo_voutupdate(bool fJustCheck,int32_t *isratificationp,int32_t notar memset(&MoMoMdata,0,sizeof(MoMoMdata)); if ( matched == 0 && signedmask != 0 && bitweight(signedmask) >= KOMODO_MINRATIFY ) notarized = 1; - if ( strcmp("PIZZA",ccdata.symbol) == 0 || strncmp("TXSCL",ccdata.symbol,5) == 0 ) + if ( strcmp("PIZZA",ccdata.symbol) == 0 || strncmp("TXSCL",ccdata.symbol,5) == 0 || strcmp("BEER",ccdata.symbol) == 0) notarized = 1; if ( 0 && opretlen != 149 ) printf("[%s].%d (%s) matched.%d i.%d j.%d notarized.%d %llx opretlen.%d len.%d offset.%d opoffset.%d\n",ASSETCHAINS_SYMBOL,height,ccdata.symbol,matched,i,j,notarized,(long long)signedmask,opretlen,len,offset,opoffset); diff --git a/src/main.cpp b/src/main.cpp index f4511c284..8bace2cb0 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -656,19 +656,34 @@ std::vector > vAddressSnapshot; bool komodo_dailysnapshot(int32_t height) { - uint256 notarized_hash,notarized_desttxid; int32_t prevMoMheight,notarized_height,undo_height; - notarized_height = komodo_notarized_height(&prevMoMheight,¬arized_hash,¬arized_desttxid); - if ( notarized_height > height-100 ) + uint256 notarized_hash,notarized_desttxid; int32_t prevMoMheight,notarized_height,undo_height,extraoffset; + if ( (extraoffset= height % KOMODO_SNAPSHOT_INTERVAL) != 0 ) { - // notarized height is higher than 100 blocks before this height, so snapshot the notarized height. - undo_height = notarized_height; + // we are on chain init, and need to scan all the way back to the correct height, other wise our node will have a diffrent snapshot to online nodes. + // use the notarizationsDB to scan back from the consesnus height to get the offset we need. + std::string symbol; Notarisation nota; + symbol.assign(ASSETCHAINS_SYMBOL); + ScanNotarisationsDB(height-extraoffset, symbol, 100, nota); + undo_height = nota.second.height; + if ( undo_height == 0 ) undo_height = height-extraoffset-100; + fprintf(stderr, "height.%i-extraoffset.%i = startscanfrom.%i to get undo_height.%i\n", height, extraoffset, height-extraoffset, undo_height); } - else + else { - //snapshot 100 blocks ago. Could still be reorged but very unlikley and expensive to carry out constantly. - undo_height = height-100; + // we are at the right height in connect block to scan back to last notarized height. + notarized_height = komodo_notarized_height(&prevMoMheight,¬arized_hash,¬arized_desttxid); + if ( notarized_height > height-100 ) + { + // notarized height is higher than 100 blocks before this height, so snapshot the notarized height. + undo_height = notarized_height; + } + else + { + //snapshot 100 blocks ago. Could still be reorged but very unlikley and expensive to carry out constantly. + undo_height = height-100; + } } - fprintf(stderr, "doing snapshot for height.%i lastSnapShotHeight.%i\n", undo_height, lastSnapShotHeight); + fprintf(stderr, "doing snapshot for height.%i undo_height.%i\n", height, undo_height); // if we already did this height dont bother doing it again, this is just a reorg. The actual snapshot height cannot be reorged. if ( undo_height == lastSnapShotHeight ) return true; @@ -690,30 +705,29 @@ bool komodo_dailysnapshot(int32_t height) uint256 hash = tx.GetHash(); CTxDestination vDest; //fprintf(stderr, "undong tx.%s\n",hash.GetHex().c_str()); - // loop vouts reverse order + // loop vouts reverse order, remove value recieved. for (unsigned int k = tx.vout.size(); k-- > 0;) { const CTxOut &out = tx.vout[k]; - //fprintf(stderr, "scriptpubkey.%s\n",out.scriptPubKey.ToString().c_str() ); if ( ExtractDestination(out.scriptPubKey, vDest) ) { - // add outputs to destination - addressAmounts[CBitcoinAddress(vDest).ToString()] += out.nValue; - //fprintf(stderr, "address.%s addcoins.%li\n",CBitcoinAddress(vDest).ToString().c_str(), out.nValue); + addressAmounts[CBitcoinAddress(vDest).ToString()] -= out.nValue; + if ( addressAmounts[CBitcoinAddress(vDest).ToString()] < 1 ) + addressAmounts.erase(CBitcoinAddress(vDest).ToString()); + //fprintf(stderr, "VOUT: address.%s remove_coins.%li\n",CBitcoinAddress(vDest).ToString().c_str(), out.nValue); } } - // loop vins in reverse order, get prevout and remove the balance from its destination + // loop vins in reverse order, get prevout and return the sent balance. for (unsigned int j = tx.vin.size(); j-- > 0;) { uint256 blockhash; CTransaction txin; - if ( !tx.IsCoinImport() && !tx.IsCoinBase() && GetTransaction(tx.vin[j].prevout.hash,txin,blockhash,false) ) // myGetTransaction! + if ( !tx.IsCoinImport() && !tx.IsCoinBase() && myGetTransaction(tx.vin[j].prevout.hash,txin,blockhash) ) // myGetTransaction! { int vout = tx.vin[j].prevout.n; if ( ExtractDestination(txin.vout[vout].scriptPubKey, vDest) ) { - // remove outputs from destination - //fprintf(stderr, "address.%s removecoins.%li\n",CBitcoinAddress(vDest).ToString().c_str(), txin.vout[vout].nValue); - addressAmounts[CBitcoinAddress(vDest).ToString()] -= txin.vout[vout].nValue; + //fprintf(stderr, "VIN: address.%s add_coins.%li\n",CBitcoinAddress(vDest).ToString().c_str(), txin.vout[vout].nValue); + addressAmounts[CBitcoinAddress(vDest).ToString()] += txin.vout[vout].nValue; } } } @@ -725,6 +739,8 @@ bool komodo_dailysnapshot(int32_t height) vAddressSnapshot.push_back(make_pair(element.second, DecodeDestination(element.first))); // sort the vector by amount, highest at top. std::sort(vAddressSnapshot.rbegin(), vAddressSnapshot.rend()); + //for (int j = 0; j < 50; j++) + // fprintf(stderr, "j.%i address.%s nValue.%li\n",j, CBitcoinAddress(vAddressSnapshot[j].second).ToString().c_str(), vAddressSnapshot[j].first ); // include only top 5000 address. if ( vAddressSnapshot.size() > 5000 ) vAddressSnapshot.resize(5000); lastSnapShotHeight = undo_height; @@ -4339,10 +4355,10 @@ static bool ActivateBestChainStep(bool fSkipdpow, CValidationState &state, CBloc // stay on the same chain tip! int32_t notarizedht,prevMoMheight; uint256 notarizedhash,txid; notarizedht = komodo_notarized_height(&prevMoMheight,¬arizedhash,&txid); - if ( !fSkipdpow && pindexFork != 0 && pindexFork->GetHeight() < notarizedht ) + if ( !fSkipdpow && pindexFork != 0 && pindexOldTip->GetHeight() > notarizedht && pindexFork->GetHeight() < notarizedht ) { - fprintf(stderr,"pindexFork->GetHeight().%d is < notarizedht %d, so ignore it\n",(int32_t)pindexFork->GetHeight(),notarizedht); - return state.DoS(100, error("ActivateBestChainStep(): pindexFork->GetHeight().%d is < notarizedht %d, so ignore it",(int32_t)pindexFork->GetHeight(),notarizedht), + fprintf(stderr,"pindexOldTip->GetHeight().%d > notarizedht %d && pindexFork->GetHeight().%d is < notarizedht %d, so ignore it\n",(int32_t)pindexFork->GetHeight(),notarizedht,(int32_t)pindexOldTip->GetHeight(),notarizedht); + return state.DoS(100, error("ActivateBestChainStep(): pindexOldTip->GetHeight().%d > notarizedht %d && pindexFork->GetHeight().%d is < notarizedht %d, so ignore it",(int32_t)pindexFork->GetHeight(),notarizedht,(int32_t)pindexOldTip->GetHeight(),notarizedht), REJECT_INVALID, "past-notarized-height"); } // - On ChainDB initialization, pindexOldTip will be null, so there are no removable blocks. @@ -6192,10 +6208,9 @@ bool CVerifyDB::VerifyDB(CCoinsView *coinsview, int nCheckLevel, int nCheckDepth LogPrintf("No coin database inconsistencies in last %i blocks (%i transactions)\n", chainActive.Height() - pindexState->GetHeight(), nGoodTransactions); - if ( ASSETCHAINS_CC != 0 && lastSnapShotHeight == 0 ) + if ( ASSETCHAINS_CC != 0 && chainActive.Height() > KOMODO_SNAPSHOT_INTERVAL ) { - int32_t init_SS_height = chainActive.Height() - (chainActive.Height() % KOMODO_SNAPSHOT_INTERVAL); - if ( !komodo_dailysnapshot(init_SS_height) ) + if ( !komodo_dailysnapshot(chainActive.Height()) ) fprintf(stderr, "daily snapshot failed, please reindex your chain\n"); // maybe force shutdown here? } From 08cf556b4bbcb22d956ba0c58d389f5fe2ae7e2e Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Sun, 28 Apr 2019 15:08:27 +0800 Subject: [PATCH 164/447] dpow fix --- src/main.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index f5b57b364..0fd9cc57e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4250,10 +4250,10 @@ static bool ActivateBestChainStep(bool fSkipdpow, CValidationState &state, CBloc // stay on the same chain tip! int32_t notarizedht,prevMoMheight; uint256 notarizedhash,txid; notarizedht = komodo_notarized_height(&prevMoMheight,¬arizedhash,&txid); - if ( !fSkipdpow && pindexFork != 0 && pindexFork->GetHeight() < notarizedht ) + if ( !fSkipdpow && pindexFork != 0 && pindexOldTip->GetHeight() > notarizedht && pindexFork->GetHeight() < notarizedht ) { - fprintf(stderr,"pindexFork->GetHeight().%d is < notarizedht %d, so ignore it\n",(int32_t)pindexFork->GetHeight(),notarizedht); - return state.DoS(100, error("ActivateBestChainStep(): pindexFork->GetHeight().%d is < notarizedht %d, so ignore it",(int32_t)pindexFork->GetHeight(),notarizedht), + fprintf(stderr,"pindexOldTip->GetHeight().%d > notarizedht %d && pindexFork->GetHeight().%d is < notarizedht %d, so ignore it\n",(int32_t)pindexFork->GetHeight(),notarizedht,(int32_t)pindexOldTip->GetHeight(),notarizedht); + return state.DoS(100, error("ActivateBestChainStep(): pindexOldTip->GetHeight().%d > notarizedht %d && pindexFork->GetHeight().%d is < notarizedht %d, so ignore it",(int32_t)pindexFork->GetHeight(),notarizedht,(int32_t)pindexOldTip->GetHeight(),notarizedht), REJECT_INVALID, "past-notarized-height"); } // - On ChainDB initialization, pindexOldTip will be null, so there are no removable blocks. From 79397bbe88b05a23be828430250967ab9eba0d8a Mon Sep 17 00:00:00 2001 From: dimxy Date: Mon, 29 Apr 2019 16:58:05 +0500 Subject: [PATCH 165/447] corrected costbasis is the latest minmax value --- src/cc/prices.cpp | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 3584190f0..1b174a770 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -775,17 +775,14 @@ int32_t prices_syntheticprofits(int64_t &costbasis, int32_t firstheight, int32_t //else { //-> use the previous value // std::cerr << "prices_syntheticprofits() unchanged costbasis=" << costbasis << " price=" << price << " leverage=" << leverage << std::endl; //} - } else { if (height == firstheight + PRICES_DAYWINDOW) { // if costbasis not set, just set it - costbasis = price; - std::cerr << "prices_syntheticprofits() permanent costbasis=" << costbasis << " height=" << height << std::endl; - } - else { - // use provided costbasis - //std::cerr << "prices_syntheticprofits() provided costbasis=" << costbasis << " price=" << price << std::endl; + //costbasis = price; + + // use calculated minmax costbasis + std::cerr << "prices_syntheticprofits() use permanent costbasis=" << costbasis << " height=" << height << std::endl; } } From 2a0ae738743a250622b5d3f8266aa51b6878889c Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 29 Apr 2019 22:45:56 +0800 Subject: [PATCH 166/447] payments Airdrop. Working airdrop and syncs TESTHC chain. --- src/cc/CCPayments.h | 2 + src/cc/CCutils.cpp | 2 +- src/cc/eval.cpp | 9 + src/cc/payments.cpp | 541 +++++++++++++++++++++++++++++---------- src/main.cpp | 24 +- src/wallet/rpcwallet.cpp | 14 +- 6 files changed, 425 insertions(+), 167 deletions(-) diff --git a/src/cc/CCPayments.h b/src/cc/CCPayments.h index 3f5a10087..cff304a2e 100644 --- a/src/cc/CCPayments.h +++ b/src/cc/CCPayments.h @@ -18,6 +18,7 @@ #define CC_PAYMENTS_H #include "CCinclude.h" +#include #define PAYMENTS_TXFEE 10000 extern std::vector > vAddressSnapshot; @@ -34,3 +35,4 @@ UniValue PaymentsInfo(struct CCcontract_info *cp,char *jsonstr); UniValue PaymentsList(struct CCcontract_info *cp,char *jsonstr); #endif + diff --git a/src/cc/CCutils.cpp b/src/cc/CCutils.cpp index 65b390c41..acf0da766 100644 --- a/src/cc/CCutils.cpp +++ b/src/cc/CCutils.cpp @@ -74,7 +74,7 @@ CScript getCCopret(const CScript &scriptPubKey) { std::vector> vParams = std::vector>(); CScript dummy; CScript opret; - if ( scriptPubKey.IsPayToCryptoCondition(&dummy, vParams) ) + if ( scriptPubKey.IsPayToCryptoCondition(&dummy, vParams) && vParams.size() == 1 ) { //fprintf(stderr, "vparams.%s\n", HexStr(vParams[0].begin(), vParams[0].end()).c_str()); opret = CScript(vParams[0].begin()+6, vParams[0].end()); diff --git a/src/cc/eval.cpp b/src/cc/eval.cpp index 62f020063..a23a7b16c 100644 --- a/src/cc/eval.cpp +++ b/src/cc/eval.cpp @@ -53,6 +53,15 @@ bool RunCCEval(const CC *cond, const CTransaction &tx, unsigned int nIn) eval->state.GetRejectReason().data(), tx.vin[nIn].prevout.hash.GetHex().data()); if (eval->state.IsError()) fprintf(stderr, "Culprit: %s\n", EncodeHexTx(tx).data()); + CTransaction tmp; + if (mempool.lookup(tx.GetHash(), tmp)) + { + // This is to remove a payments airdrop if it gets stuck in the mempool. + // Miner will mine 1 invalid block, but doesnt stop them mining until a restart. + // This would almost never happen in normal use. + std::list dummy; + mempool.remove(tx,dummy,true); + } return false; } diff --git a/src/cc/payments.cpp b/src/cc/payments.cpp index 569c4eb14..e72184719 100644 --- a/src/cc/payments.cpp +++ b/src/cc/payments.cpp @@ -16,6 +16,14 @@ #include "CCPayments.h" /* +192.168.0.139: RH side screen. + ./komodod -ac_name=TESTDP -ac_supply=10000000 -ac_reward=1000000000 -ac_nk=96,5 -ac_blocktime=20 -ac_cc=2 -addndoe=192.168.0.112 + - TESTDP.tar saved after distributing funds randomly. approx block 120. +LH screen: + ./komodod -ac_name=TESTDP -ac_supply=10000000 -ac_reward=1000000000 -ac_nk=96,5 -ac_blocktime=20 -ac_cc=2 -pubkey=0244a96824fa317433f0eaa6d5b1faf68e802b1958df273c24cb82bce1ef8e1aec -gen -genproclimit=1 + +./komodo-cli -ac_name=TESTDP paymentsairdrop '[10,2000,500,"76a9149758abb81ee168dd3824cb55e94df509b35462d788ac",76a9144cfd873dadbfbb4b9c03e77ecaa6cfb74a484f4888ac"]' + use notarizations DB to scan back from the correct height, then undo ALL blocks back to this notarized height! payments airdrop: - extra RPC to merge all payments inputs to a single utxo, this must be called first and be confirmed before payments release, @@ -144,12 +152,53 @@ uint8_t DecodePaymentsOpRet(CScript scriptPubKey,int32_t &lockedblocks,int32_t & script = (uint8_t *)vopret.data(); if ( vopret.size() > 2 && E_UNMARSHAL(vopret,ss >> e; ss >> f; ss >> lockedblocks; ss >> minrelease; ss >> totalallocations; ss >> txidoprets) != 0 ) { - if ( e == EVAL_PAYMENTS && f == 'C' ) + if ( e == EVAL_PAYMENTS && f == 'C' && txidoprets.size() > 1 ) return(f); } return(0); } + +CScript EncodePaymentsSnapsShotOpRet(int32_t lockedblocks,int32_t minrelease,int32_t top,std::vector> excludeScriptPubKeys) +{ + CScript opret; uint8_t evalcode = EVAL_PAYMENTS; + opret << OP_RETURN << E_MARSHAL(ss << evalcode << 'S' << lockedblocks << minrelease << top << excludeScriptPubKeys); + return(opret); +} + +uint8_t DecodePaymentsSnapsShotOpRet(CScript scriptPubKey,int32_t &lockedblocks,int32_t &minrelease,int32_t &top,std::vector> &excludeScriptPubKeys) +{ + std::vector vopret; uint8_t *script,e,f; + GetOpReturnData(scriptPubKey, vopret); + script = (uint8_t *)vopret.data(); + if ( vopret.size() > 2 && E_UNMARSHAL(vopret,ss >> e; ss >> f; ss >> lockedblocks; ss >> minrelease; ss >> top; ss >> excludeScriptPubKeys) != 0 ) + { + if ( e == EVAL_PAYMENTS && f == 'S' ) + return(f); + } + return(0); +} + +CScript EncodePaymentsTokensOpRet(int32_t lockedblocks,int32_t minrelease,int32_t top,std::vector> excludeScriptPubKeys, uint256 tokenid) +{ + CScript opret; uint8_t evalcode = EVAL_PAYMENTS; + opret << OP_RETURN << E_MARSHAL(ss << evalcode << 'O' << lockedblocks << minrelease << top << excludeScriptPubKeys << tokenid); + return(opret); +} + +uint8_t DecodePaymentsTokensOpRet(CScript scriptPubKey,int32_t &lockedblocks,int32_t &minrelease,int32_t &top,std::vector> &excludeScriptPubKeys, uint256 &tokenid) +{ + std::vector vopret; uint8_t *script,e,f; + GetOpReturnData(scriptPubKey, vopret); + script = (uint8_t *)vopret.data(); + if ( vopret.size() > 2 && E_UNMARSHAL(vopret,ss >> e; ss >> f; ss >> lockedblocks; ss >> minrelease; ss >> top; ss >> excludeScriptPubKeys; ss >> tokenid) != 0 ) + { + if ( e == EVAL_PAYMENTS && f == 'O' ) + return(f); + } + return(0); +} + int64_t IsPaymentsvout(struct CCcontract_info *cp,const CTransaction& tx,int32_t v,char *cmpaddr) { char destaddr[64]; @@ -184,8 +233,10 @@ bool PaymentsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction & // change is/must be in vout[0] // only 'F' or 1of2 txidaddr can be spent // all vouts must match exactly - char temp[128], coinaddr[64], txidaddr[64]; std::string scriptpubkey; uint256 createtxid, blockhash; CTransaction tmptx; + char temp[128], coinaddr[64], txidaddr[64]; std::string scriptpubkey; uint256 createtxid, blockhash, tokenid; CTransaction plantx; uint8_t funcid = 0; int32_t i,lockedblocks,minrelease; int64_t change,totalallocations; std::vector txidoprets; bool fHasOpret = false; CPubKey txidpk,Paymentspk; + int32_t top; std::vector> excludeScriptPubKeys; + mpz_t mpzTotalAllocations, mpzAllocation;; mpz_init(mpzTotalAllocations); // user marker vout to get the createtxid if ( tx.vout.size() < 2 ) return(eval->Invalid("not enough vouts")); @@ -200,13 +251,15 @@ bool PaymentsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction & //printf("createtxid.%s\n",createtxid.ToString().c_str()); // use the createtxid to fetch the tx and all of the plans info. - if ( myGetTransaction(createtxid,tmptx,blockhash) != 0 ) - { - if ( tmptx.vout.size() > 0 && DecodePaymentsOpRet(tmptx.vout[tmptx.vout.size()-1].scriptPubKey,lockedblocks,minrelease,totalallocations,txidoprets) != 0 ) + if ( myGetTransaction(createtxid,plantx,blockhash) != 0 && plantx.vout.size() > 0 ) + { + if ( ((funcid= DecodePaymentsOpRet(plantx.vout[plantx.vout.size()-1].scriptPubKey,lockedblocks,minrelease,totalallocations,txidoprets)) == 'C' || (funcid= DecodePaymentsSnapsShotOpRet(plantx.vout[plantx.vout.size()-1].scriptPubKey,lockedblocks,minrelease,top,excludeScriptPubKeys)) == 'S' || (funcid= DecodePaymentsTokensOpRet(plantx.vout[plantx.vout.size()-1].scriptPubKey,lockedblocks,minrelease,top,excludeScriptPubKeys,tokenid)) == 'O') ) { - if ( lockedblocks < 0 || minrelease < 0 || totalallocations <= 0 || txidoprets.size() < 2 ) + if ( lockedblocks < 0 || minrelease < 0 || totalallocations <= 0 ) return(eval->Invalid("negative values")); Paymentspk = GetUnspendable(cp,0); + txidpk = CCtxidaddr(txidaddr,createtxid); + GetCCaddress1of2(cp,coinaddr,Paymentspk,txidpk); //fprintf(stderr, "lockedblocks.%i minrelease.%i totalallocations.%i txidopret1.%s txidopret2.%s\n",lockedblocks, minrelease, totalallocations, txidoprets[0].ToString().c_str(), txidoprets[1].ToString().c_str() ); if ( !CheckTxFee(tx, PAYMENTS_TXFEE+1, chainActive.LastTip()->GetHeight(), chainActive.LastTip()->nTime) ) return eval->Invalid("txfee is too high"); @@ -215,65 +268,101 @@ bool PaymentsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction & std::vector scriptPubKeys; int64_t checkallocations = 0; i = 0; - BOOST_FOREACH(const uint256& txidopret, txidoprets) + if ( funcid == 'C' ) { - CTransaction tx0; std::vector scriptPubKey,opret; int64_t allocation; - if ( myGetTransaction(txidopret,tx0,blockhash) != 0 && tx0.vout.size() > 1 && DecodePaymentsTxidOpRet(tx0.vout[tx0.vout.size()-1].scriptPubKey,allocation,scriptPubKey,opret) == 'T' ) + // normal payment + for (const uint256& txidopret : txidoprets) { - scriptPubKeys.push_back(CScript(scriptPubKey.begin(), scriptPubKey.end())); - allocations.push_back(allocation); - //fprintf(stderr, "i.%i scriptpubkey.%s allocation.%li\n",i,scriptPubKeys[i].ToString().c_str(),allocation); - checkallocations += allocation; - // if we have an op_return to pay to need to check it exists and is paying the correct opret. - if ( !opret.empty() ) + CTransaction tx0; std::vector scriptPubKey,opret; int64_t allocation; + if ( myGetTransaction(txidopret,tx0,blockhash) != 0 && tx0.vout.size() > 1 && DecodePaymentsTxidOpRet(tx0.vout[tx0.vout.size()-1].scriptPubKey,allocation,scriptPubKey,opret) == 'T' ) { - if ( !fHasOpret ) + scriptPubKeys.push_back(CScript(scriptPubKey.begin(), scriptPubKey.end())); + allocations.push_back(allocation); + //fprintf(stderr, "i.%i scriptpubkey.%s allocation.%li\n",i,scriptPubKeys[i].ToString().c_str(),allocation); + checkallocations += allocation; + // if we have an op_return to pay to need to check it exists and is paying the correct opret. + if ( !opret.empty() ) { - fprintf(stderr, "missing opret.%s in payments release.\n",HexStr(opret.begin(), opret.end()).c_str()); - return(eval->Invalid("missing opret in payments release")); - } - else if ( CScript(opret.begin(),opret.end()) != tx.vout[tx.vout.size()-1].scriptPubKey ) - { - fprintf(stderr, "opret.%s vs opret.%s\n",HexStr(opret.begin(), opret.end()).c_str(), HexStr(tx.vout[tx.vout.size()-1].scriptPubKey.begin(), tx.vout[tx.vout.size()-1].scriptPubKey.end()).c_str()); - return(eval->Invalid("pays incorrect opret")); + if ( !fHasOpret ) + { + fprintf(stderr, "missing opret.%s in payments release.\n",HexStr(opret.begin(), opret.end()).c_str()); + return(eval->Invalid("missing opret in payments release")); + } + else if ( CScript(opret.begin(),opret.end()) != tx.vout[tx.vout.size()-1].scriptPubKey ) + { + fprintf(stderr, "opret.%s vs opret.%s\n",HexStr(opret.begin(), opret.end()).c_str(), HexStr(tx.vout[tx.vout.size()-1].scriptPubKey.begin(), tx.vout[tx.vout.size()-1].scriptPubKey.end()).c_str()); + return(eval->Invalid("pays incorrect opret")); + } } } + i++; } - i++; + mpz_set_si(mpzTotalAllocations,totalallocations); + } + else if ( funcid == 'S' ) + { + // need time for TX to me mined before the next snapshot. + if ( top > 5000 ) + return(eval->Invalid("transaction too big")); + for ( auto address : vAddressSnapshot ) + { + CScript scriptPubKey = GetScriptForDestination(address.second); + for ( auto skipkey : excludeScriptPubKeys ) + { + //fprintf(stderr, "scriptpubkey.%s\n skipkey.%s", HexStr(scriptPubKey).c_str(), HexStr(CScript(skipkey.begin(), skipkey.end())).c_str()); + if ( scriptPubKey != CScript(skipkey.begin(), skipkey.end()) ) + { + mpz_init(mpzAllocation); + i++; + scriptPubKeys.push_back(scriptPubKey); + allocations.push_back(address.first); + mpz_set_si(mpzAllocation,address.first); + mpz_add(mpzTotalAllocations,mpzTotalAllocations,mpzAllocation); + mpz_clear(mpzAllocation); + } + } + if ( i == top ) // we reached top amount to pay, it can be less than this! + break; + } + if ( i != tx.vout.size()-2 ) + return(eval->Invalid("pays wrong amount of recipients")); + } + else if ( funcid == 'O' ) + { + // tokens snapshot. } - // sanity check to make sure we got all the required info + //fprintf(stderr, " allocations.size().%li scriptPubKeys.size.%li\n",allocations.size(), scriptPubKeys.size()); if ( allocations.size() == 0 || scriptPubKeys.size() == 0 || allocations.size() != scriptPubKeys.size() ) return(eval->Invalid("missing data cannot validate")); //fprintf(stderr, "totalallocations.%li checkallocations.%li\n",totalallocations, checkallocations); - if ( totalallocations != checkallocations ) + if ( funcid == 'C' && totalallocations != checkallocations ) // only check for normal payments release. return(eval->Invalid("allocation missmatch")); - - txidpk = CCtxidaddr(txidaddr,createtxid); - GetCCaddress1of2(cp,coinaddr,Paymentspk,txidpk); - //fprintf(stderr, "coinaddr.%s\n", coinaddr); - + // make sure change is in vout 0 and is paying to the contract address. if ( (change= IsPaymentsvout(cp,tx,0,coinaddr)) == 0 ) return(eval->Invalid("change is in wrong vout or is wrong tx type")); // Check vouts go to the right place and pay the right amounts. - int64_t amount = 0, checkamount; int32_t n = 0; + int64_t amount = 0, checkamount; int32_t n = 0; checkamount = tx.GetValueOut() - change - PAYMENTS_TXFEE; + mpz_t mpzCheckamount; mpz_init(mpzCheckamount); mpz_set_si(mpzCheckamount,checkamount); for (i = 1; i < (fHasOpret ? tx.vout.size()-2 : tx.vout.size()-1); i++) { - std::string destscriptPubKey = HexStr(scriptPubKeys[n].begin(),scriptPubKeys[n].end()); - std::string voutscriptPubKey = HexStr(tx.vout[i].scriptPubKey.begin(),tx.vout[i].scriptPubKey.end()); - if ( destscriptPubKey != voutscriptPubKey ) + if ( scriptPubKeys[n] != tx.vout[i].scriptPubKey ) { - fprintf(stderr, "pays wrong destination destscriptPubKey.%s voutscriptPubKey.%s\n", destscriptPubKey.c_str(), voutscriptPubKey.c_str()); + fprintf(stderr, "pays wrong destination destscriptPubKey.%s voutscriptPubKey.%s\n", HexStr(scriptPubKeys[n].begin(),scriptPubKeys[n].end()).c_str(), HexStr(tx.vout[i].scriptPubKey.begin(),tx.vout[i].scriptPubKey.end()).c_str()); return(eval->Invalid("pays wrong address")); } - int64_t test = allocations[n]; - test *= checkamount; - test /= totalallocations; - if ( test != tx.vout[i].nValue && test != tx.vout[i].nValue-1 ) + mpz_init(mpzAllocation); + mpz_set_si(mpzAllocation,allocations[n]); + mpz_mul(mpzAllocation,mpzAllocation,mpzCheckamount); + mpz_cdiv_q(mpzAllocation,mpzAllocation,mpzTotalAllocations); + int64_t test = mpz_get_si(mpzAllocation); + mpz_clear(mpzAllocation); + // Vairance of 1 sat is allowed, for rounding errors. + if ( test >= tx.vout[i].nValue+1 && test <= tx.vout[i].nValue-1 ) { fprintf(stderr, "vout.%i test.%li vs nVlaue.%li\n",i, test, tx.vout[i].nValue); return(eval->Invalid("amounts do not match")); @@ -281,6 +370,7 @@ bool PaymentsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction & amount += tx.vout[i].nValue; n++; } + mpz_clear(mpzTotalAllocations); // This is a backup check to make sure there are no extra vouts paying something else! if ( checkamount != amount ) return(eval->Invalid("amounts do not match")); @@ -291,6 +381,7 @@ bool PaymentsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction & return(eval->Invalid("amount is too small")); } + // Check vins i = 0; int32_t ht = chainActive.LastTip()->GetHeight(); BOOST_FOREACH(const CTxIn& vin, tx.vin) @@ -303,17 +394,12 @@ bool PaymentsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction & Getscriptaddress(destaddr,txin.vout[vin.prevout.n].scriptPubKey); if ( strcmp(destaddr,coinaddr) != 0 ) { + // if does not come from address its in the global payments adddress and we need to check the opreturn. CScript opret; uint256 checktxid; int32_t opret_ind; if ( (opret_ind= has_opret(txin, EVAL_PAYMENTS)) == 0 ) - { - // get op_return from CCvout, - opret = getCCopret(txin.vout[vin.prevout.n].scriptPubKey); - } + opret = getCCopret(txin.vout[vin.prevout.n].scriptPubKey); // get op_return from CCvout, else - { - // get op_return from the op_return - opret = txin.vout[opret_ind].scriptPubKey; - } + opret = txin.vout[opret_ind].scriptPubKey; if ( DecodePaymentsFundOpRet(opret,checktxid) != 'F' || checktxid != createtxid ) { fprintf(stderr, "vin.%i is not a payments CC vout: txid.%s\n", i, txin.GetHash().ToString().c_str()); @@ -404,6 +490,7 @@ int64_t AddPaymentsInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CP if ( (total > 0 && totalinputs >= total) || (maxinputs > 0 && n >= maxinputs) ) break; } //else fprintf(stderr,"nValue %.8f vs threshold %.8f\n",(double)nValue/COIN,(double)threshold/COIN); + iter++; } } } @@ -482,8 +569,10 @@ int32_t payments_parsehexdata(std::vector &hexdata,cJSON *item,int32_t UniValue PaymentsRelease(struct CCcontract_info *cp,char *jsonstr) { int32_t latestheight,nextheight = komodo_nextheight(); - CMutableTransaction tmpmtx,mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(),nextheight); UniValue result(UniValue::VOBJ); uint256 createtxid,hashBlock; - CTransaction tx,txO; CPubKey mypk,txidpk,Paymentspk; int32_t i,n,m,numoprets=0,lockedblocks,minrelease; int64_t newamount,inputsum,amount,CCchange=0,totalallocations,checkallocations=0,allocation; CTxOut vout; CScript onlyopret; char txidaddr[64],destaddr[64]; std::vector txidoprets; + CMutableTransaction tmpmtx,mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(),nextheight); UniValue result(UniValue::VOBJ); uint256 createtxid,hashBlock,tokenid; + CTransaction tx,txO; CPubKey mypk,txidpk,Paymentspk; int32_t i,n,m,numoprets=0,lockedblocks,minrelease; int64_t newamount,inputsum,amount,CCchange=0,totalallocations=0,checkallocations=0,allocation; CTxOut vout; CScript onlyopret; char txidaddr[64],destaddr[64]; std::vector txidoprets; + int32_t top; std::vector> excludeScriptPubKeys; int8_t funcid; + mpz_t mpzTotalAllocations; mpz_init(mpzTotalAllocations); cJSON *params = payments_reparse(&n,jsonstr); mypk = pubkey2pk(Mypubkey()); Paymentspk = GetUnspendable(cp,0); @@ -491,14 +580,16 @@ UniValue PaymentsRelease(struct CCcontract_info *cp,char *jsonstr) { createtxid = payments_juint256(jitem(params,0)); amount = jdouble(jitem(params,1),0) * SATOSHIDEN + 0.0000000049; - if ( myGetTransaction(createtxid,tx,hashBlock) != 0 ) + if ( myGetTransaction(createtxid,tx,hashBlock) != 0 && tx.vout.size() > 0 ) { - if ( tx.vout.size() > 0 && DecodePaymentsOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,lockedblocks,minrelease,totalallocations,txidoprets) != 0 ) + if ( ((funcid= DecodePaymentsOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,lockedblocks,minrelease,totalallocations,txidoprets)) == 'C' || (funcid= DecodePaymentsSnapsShotOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,lockedblocks,minrelease,top,excludeScriptPubKeys)) == 'S' || (funcid= DecodePaymentsTokensOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,lockedblocks,minrelease,top,excludeScriptPubKeys,tokenid)) == 'O') ) { - if ( lockedblocks < 0 || minrelease < 0 || totalallocations <= 0 || txidoprets.size() < 2 ) + if ( lockedblocks < 0 || minrelease < 0 || totalallocations <= 0 ) { result.push_back(Pair("result","error")); result.push_back(Pair("error","negative parameter")); + if ( params != 0 ) + free_json(params); return(result); } latestheight = (nextheight - lockedblocks - 1); @@ -508,94 +599,163 @@ UniValue PaymentsRelease(struct CCcontract_info *cp,char *jsonstr) result.push_back(Pair("error","amount too smal")); result.push_back(Pair("amount",ValueFromAmount(amount))); result.push_back(Pair("minrelease",ValueFromAmount(minrelease*COIN))); + if ( params != 0 ) + free_json(params); return(result); } txidpk = CCtxidaddr(txidaddr,createtxid); mtx.vout.push_back(MakeCC1of2vout(EVAL_PAYMENTS,0,Paymentspk,txidpk)); - m = txidoprets.size(); - for (i=0; i scriptPubKey,opret; - vout.nValue = 0; - if ( myGetTransaction(txidoprets[i],txO,hashBlock) != 0 && txO.vout.size() > 1 && DecodePaymentsTxidOpRet(txO.vout[txO.vout.size()-1].scriptPubKey,allocation,scriptPubKey,opret) == 'T' ) + // normal payments + for (i=0; i 0 ) + std::vector scriptPubKey,opret; + vout.nValue = 0; + if ( myGetTransaction(txidoprets[i],txO,hashBlock) != 0 && txO.vout.size() > 1 && DecodePaymentsTxidOpRet(txO.vout[txO.vout.size()-1].scriptPubKey,allocation,scriptPubKey,opret) == 'T' ) { - onlyopret.resize(opret.size()); - memcpy(&onlyopret[0],&opret[0],opret.size()); - numoprets++; + vout.nValue = allocation; + vout.scriptPubKey.resize(scriptPubKey.size()); + memcpy(&vout.scriptPubKey[0],&scriptPubKey[0],scriptPubKey.size()); + checkallocations += allocation; + if ( opret.size() > 0 ) + { + onlyopret.resize(opret.size()); + memcpy(&onlyopret[0],&opret[0],opret.size()); + numoprets++; + } + } else break; + mtx.vout.push_back(vout); + } + result.push_back(Pair("numoprets",(int64_t)numoprets)); + if ( i != m ) + { + result.push_back(Pair("result","error")); + result.push_back(Pair("error","invalid txidoprets[i]")); + result.push_back(Pair("txi",(int64_t)i)); + if ( params != 0 ) + free_json(params); + return(result); + } + else if ( checkallocations != totalallocations ) + { + result.push_back(Pair("result","error")); + result.push_back(Pair("error","totalallocations mismatch")); + result.push_back(Pair("checkallocations",(int64_t)checkallocations)); + result.push_back(Pair("totalallocations",(int64_t)totalallocations)); + if ( params != 0 ) + free_json(params); + return(result); + } + else if ( numoprets > 1 ) + { + result.push_back(Pair("result","error")); + result.push_back(Pair("error","too many oprets")); + if ( params != 0 ) + free_json(params); + return(result); + } + // set totalallocations to a mpz_t bignum, for amounts calculation later. + mpz_set_si(mpzTotalAllocations,totalallocations); + } + else if ( funcid = 'S' ) + { + // normal snapshot + i = 0; + if ( top > 5000 ) + { + // need to test the maximum number, this is an estimate. + result.push_back(Pair("result","error")); + result.push_back(Pair("error","cannot pay more than 5000 addresses")); + if ( params != 0 ) + free_json(params); + return(result); + } + for ( auto address : vAddressSnapshot ) + { + CScript scriptPubKey = GetScriptForDestination(address.second); + for ( auto skipkey : excludeScriptPubKeys ) + { + if ( scriptPubKey != CScript(skipkey.begin(), skipkey.end()) ) + { + mpz_t mpzAllocation; mpz_init(mpzAllocation); + i++; + //fprintf(stderr, "address: %s nValue.%li \n", CBitcoinAddress(address.second).ToString().c_str(), address.first); + vout.nValue = address.first; + vout.scriptPubKey = scriptPubKey; + mpz_set_si(mpzAllocation,address.first); + mpz_add(mpzTotalAllocations,mpzTotalAllocations,mpzAllocation); //totalallocations += address.first; + mtx.vout.push_back(vout); + mpz_clear(mpzAllocation); + } else fprintf(stderr, "SKIPPED::: %s\n", CBitcoinAddress(address.second).ToString().c_str()); } - } else break; - mtx.vout.push_back(vout); + if ( i == top ) // we reached top amount to pay, it can be less than this! + break; + } + m = i; // this is the amount we got, either top, or all of the address on the chain. } - result.push_back(Pair("numoprets",(int64_t)numoprets)); - if ( i != m ) + else if ( funcid = 'O' ) { - result.push_back(Pair("result","error")); - result.push_back(Pair("error","invalid txidoprets[i]")); - result.push_back(Pair("txi",(int64_t)i)); - if ( params != 0 ) - free_json(params); - return(result); - } - else if ( checkallocations != totalallocations ) - { - result.push_back(Pair("result","error")); - result.push_back(Pair("error","totalallocations mismatch")); - result.push_back(Pair("checkallocations",(int64_t)checkallocations)); - result.push_back(Pair("totalallocations",(int64_t)totalallocations)); - if ( params != 0 ) - free_json(params); - return(result); - } - else if ( numoprets > 1 ) - { - result.push_back(Pair("result","error")); - result.push_back(Pair("error","too many oprets")); - if ( params != 0 ) - free_json(params); - return(result); + // token snapshot } newamount = amount; + int64_t totalamountsent = 0; + mpz_t mpzAmount; mpz_init(mpzAmount); mpz_set_si(mpzAmount,amount); for (i=0; i= newamount+2*PAYMENTS_TXFEE ) - { - std::string rawtx; - if ( (CCchange= (inputsum - newamount - 2*PAYMENTS_TXFEE)) >= PAYMENTS_TXFEE ) - mtx.vout[0].nValue = CCchange; - mtx.vout.push_back(CTxOut(PAYMENTS_TXFEE,CScript() << ParseHex(HexStr(txidpk)) << OP_CHECKSIG)); - GetCCaddress1of2(cp,destaddr,Paymentspk,txidpk); - CCaddr1of2set(cp,Paymentspk,txidpk,cp->CCpriv,destaddr); - rawtx = FinalizeCCTx(0,cp,mtx,mypk,PAYMENTS_TXFEE,onlyopret); - if ( params != 0 ) - free_json(params); - result.push_back(Pair("amount",ValueFromAmount(amount))); - result.push_back(Pair("newamount",ValueFromAmount(newamount))); - return(payments_rawtxresult(result,rawtx,1)); - } - else - { - result.push_back(Pair("result","error")); - result.push_back(Pair("error","couldnt find enough locked funds")); - } + //fprintf(stderr, "newamount.%li totalamountsent.%li\n", newamount, totalamountsent); + mpz_clear(mpzAmount); mpz_clear(mpzTotalAllocations); } else { result.push_back(Pair("result","error")); result.push_back(Pair("error","couldnt decode paymentscreate txid opret")); + if ( params != 0 ) + free_json(params); + return(result); + } + if ( (inputsum= AddPaymentsInputs(cp,mtx,txidpk,newamount+2*PAYMENTS_TXFEE,CC_MAXVINS/2,createtxid,latestheight)) >= newamount+2*PAYMENTS_TXFEE ) + { + std::string rawtx; + if ( (CCchange= (inputsum - newamount - 2*PAYMENTS_TXFEE)) >= PAYMENTS_TXFEE ) + mtx.vout[0].nValue = CCchange; + mtx.vout.push_back(CTxOut(PAYMENTS_TXFEE,CScript() << ParseHex(HexStr(txidpk)) << OP_CHECKSIG)); + GetCCaddress1of2(cp,destaddr,Paymentspk,txidpk); + CCaddr1of2set(cp,Paymentspk,txidpk,cp->CCpriv,destaddr); + rawtx = FinalizeCCTx(0,cp,mtx,mypk,PAYMENTS_TXFEE,onlyopret); + if ( params != 0 ) + free_json(params); + result.push_back(Pair("amount",ValueFromAmount(amount))); + result.push_back(Pair("newamount",ValueFromAmount(newamount))); + return(payments_rawtxresult(result,rawtx,0)); + } + else + { + result.push_back(Pair("result","error")); + result.push_back(Pair("error","couldnt find enough locked funds")); } } else @@ -618,6 +778,8 @@ UniValue PaymentsFund(struct CCcontract_info *cp,char *jsonstr) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); UniValue result(UniValue::VOBJ); CPubKey Paymentspk,mypk,txidpk; uint256 txid,hashBlock; int64_t amount,totalallocations; CScript opret; CTransaction tx; char txidaddr[64]; std::string rawtx; int32_t n,useopret = 0,lockedblocks,minrelease; std::vector txidoprets; + int32_t top; std::vector> excludeScriptPubKeys; // snapshot + uint256 tokenid; cJSON *params = payments_reparse(&n,jsonstr); mypk = pubkey2pk(Mypubkey()); Paymentspk = GetUnspendable(cp,0); @@ -627,14 +789,14 @@ UniValue PaymentsFund(struct CCcontract_info *cp,char *jsonstr) amount = jdouble(jitem(params,1),0) * SATOSHIDEN + 0.0000000049; if ( n == 3 ) useopret = jint(jitem(params,2),0) != 0; - if ( myGetTransaction(txid,tx,hashBlock) == 0 || tx.vout.size() == 1 || DecodePaymentsOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,lockedblocks,minrelease,totalallocations,txidoprets) == 0 ) + if ( myGetTransaction(txid,tx,hashBlock) == 0 || tx.vout.size() == 1 || (DecodePaymentsOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,lockedblocks,minrelease,totalallocations,txidoprets) == 0 && DecodePaymentsSnapsShotOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,lockedblocks,minrelease,top,excludeScriptPubKeys) == 0 && DecodePaymentsTokensOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,lockedblocks,minrelease,top,excludeScriptPubKeys,tokenid) == 0) ) { result.push_back(Pair("result","error")); result.push_back(Pair("error","invalid createtxid")); } else if ( AddNormalinputs(mtx,mypk,amount+PAYMENTS_TXFEE,60) > 0 ) { - if ( lockedblocks < 0 || minrelease < 0 || totalallocations <= 0 || txidoprets.size() < 2 ) + if ( lockedblocks < 0 || minrelease < 0 || totalallocations <= 0 ) { result.push_back(Pair("result","error")); result.push_back(Pair("error","negative parameter")); @@ -650,13 +812,13 @@ UniValue PaymentsFund(struct CCcontract_info *cp,char *jsonstr) else { mtx.vout.push_back(MakeCC1vout(EVAL_PAYMENTS,amount,Paymentspk)); + opret = EncodePaymentsFundOpRet(txid); // Use the below one along with other FinalizeCCTx/return, to get the ccvout scriptpubkey - /*opret = EncodePaymentsFundOpRet(txid); - std::vector> vData = std::vector>(); + /*std::vector> vData = std::vector>(); if ( makeCCopret(opret, vData) ) mtx.vout.push_back(MakeCC1vout(EVAL_PAYMENTS,amount,Paymentspk,&vData)); */ } - rawtx = FinalizeCCTx(0,cp,mtx,mypk,PAYMENTS_TXFEE,EncodePaymentsFundOpRet(txid)); + rawtx = FinalizeCCTx(0,cp,mtx,mypk,PAYMENTS_TXFEE,opret); //rawtx = FinalizeCCTx(0,cp,mtx,mypk,PAYMENTS_TXFEE,CScript()); // use this one to get ccvout scriptpubkey. if ( params != 0 ) free_json(params); @@ -796,22 +958,73 @@ UniValue PaymentsCreate(struct CCcontract_info *cp,char *jsonstr) UniValue PaymentsAirdrop(struct CCcontract_info *cp,char *jsonstr) { - uint64_t start = time(NULL); - - return(time(NULL)-start); + CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); + UniValue result(UniValue::VOBJ); + uint256 hashBlock; CTransaction tx; CPubKey Paymentspk,mypk; char markeraddr[64]; std::string rawtx; + int32_t lockedblocks,minrelease,top,n,i; std::vector> excludeScriptPubKeys; + cJSON *params = payments_reparse(&n,jsonstr); + if ( params != 0 && n >= 4 ) + { + lockedblocks = juint(jitem(params,0),0); + minrelease = juint(jitem(params,1),0); + top = juint(jitem(params,2),0); + if ( lockedblocks < 0 || minrelease < 0 || top < 0 ) + { + result.push_back(Pair("result","error")); + result.push_back(Pair("error","negative parameter")); + if ( params != 0 ) + free_json(params); + return(result); + } + for (i=0; i scriptPubKey; + int32_t len = strlen(inputhex)/2; + scriptPubKey.resize(len); + decode_hex((uint8_t *)scriptPubKey.data(),len,(char *)inputhex); + excludeScriptPubKeys.push_back(scriptPubKey); + } + mypk = pubkey2pk(Mypubkey()); + Paymentspk = GetUnspendable(cp,0); + if ( AddNormalinputs(mtx,mypk,2*PAYMENTS_TXFEE,60) > 0 ) + { + mtx.vout.push_back(MakeCC1of2vout(cp->evalcode,PAYMENTS_TXFEE,Paymentspk,Paymentspk)); + rawtx = FinalizeCCTx(0,cp,mtx,mypk,PAYMENTS_TXFEE,EncodePaymentsSnapsShotOpRet(lockedblocks,minrelease,top,excludeScriptPubKeys)); + if ( params != 0 ) + free_json(params); + return(payments_rawtxresult(result,rawtx,0)); + } + result.push_back(Pair("result","error")); + result.push_back(Pair("error","not enough normal funds")); + } + else + { + result.push_back(Pair("result","error")); + result.push_back(Pair("error","parameters error")); + } + if ( params != 0 ) + free_json(params); + return(result); } UniValue PaymentsInfo(struct CCcontract_info *cp,char *jsonstr) { UniValue result(UniValue::VOBJ),a(UniValue::VARR); CTransaction tx,txO; CPubKey Paymentspk,txidpk; int32_t i,j,n,flag=0,numoprets=0,lockedblocks,minrelease; std::vector txidoprets; int64_t funds,fundsopret,totalallocations=0,allocation; char fundsaddr[64],fundsopretaddr[64],txidaddr[64],*outstr; uint256 createtxid,hashBlock; + int32_t top; std::vector> excludeScriptPubKeys; // snapshot + uint256 tokenid; cJSON *params = payments_reparse(&n,jsonstr); if ( params != 0 && n == 1 ) { Paymentspk = GetUnspendable(cp,0); createtxid = payments_juint256(jitem(params,0)); - if ( myGetTransaction(createtxid,tx,hashBlock) != 0 ) + if ( myGetTransaction(createtxid,tx,hashBlock) != 0 && tx.vout.size() > 0 ) { - if ( tx.vout.size() > 0 && DecodePaymentsOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,lockedblocks,minrelease,totalallocations,txidoprets) != 0 ) + if ( DecodePaymentsOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,lockedblocks,minrelease,totalallocations,txidoprets) != 0 ) { if ( lockedblocks < 0 || minrelease < 0 || totalallocations <= 0 || txidoprets.size() < 2 ) { @@ -821,6 +1034,7 @@ UniValue PaymentsInfo(struct CCcontract_info *cp,char *jsonstr) free_json(params); return(result); } + result.push_back(Pair("plan_type","payments")); result.push_back(Pair("lockedblocks",(int64_t)lockedblocks)); result.push_back(Pair("totalallocations",(int64_t)totalallocations)); result.push_back(Pair("minrelease",(int64_t)minrelease)); @@ -849,29 +1063,71 @@ UniValue PaymentsInfo(struct CCcontract_info *cp,char *jsonstr) } else fprintf(stderr,"error decoding voutsize.%d\n",(int32_t)txO.vout.size()); a.push_back(obj); } - flag++; result.push_back(Pair("numoprets",(int64_t)numoprets)); if ( numoprets > 1 ) { + flag++; result.push_back(Pair("result","error")); result.push_back(Pair("error","too many opreturns")); - } - else + } else result.push_back(Pair("txidoprets",a)); + } + else if ( DecodePaymentsSnapsShotOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,lockedblocks,minrelease,top,excludeScriptPubKeys) != 0 ) + { + if ( lockedblocks < 0 || minrelease < 0 || top <= 0 ) { - result.push_back(Pair("txidoprets",a)); - txidpk = CCtxidaddr(txidaddr,createtxid); - GetCCaddress1of2(cp,fundsaddr,Paymentspk,txidpk); - funds = CCaddress_balance(fundsaddr,1); - result.push_back(Pair(fundsaddr,ValueFromAmount(funds))); - GetCCaddress(cp,fundsopretaddr,Paymentspk); - fundsopret = CCaddress_balance(fundsopretaddr,1); // Shows balance for ALL payments plans, not just the one asked for! - result.push_back(Pair(fundsopretaddr,ValueFromAmount(fundsopret))); - result.push_back(Pair("totalfunds",ValueFromAmount(funds+fundsopret))); - result.push_back(Pair("result","success")); + result.push_back(Pair("result","error")); + result.push_back(Pair("error","negative parameter")); + if ( params != 0 ) + free_json(params); + return(result); } + result.push_back(Pair("plan_type","snapshot")); + result.push_back(Pair("lockedblocks",(int64_t)lockedblocks)); + result.push_back(Pair("minrelease",(int64_t)minrelease)); + result.push_back(Pair("top",(int64_t)top)); + for ( auto scriptPubKey : excludeScriptPubKeys ) + a.push_back(HexStr(scriptPubKey.begin(),scriptPubKey.end())); + result.push_back(Pair("excludeScriptPubkeys",a)); + } + else if ( DecodePaymentsTokensOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,lockedblocks,minrelease,top,excludeScriptPubKeys,tokenid) != 0 ) + { + if ( lockedblocks < 0 || minrelease < 0 || top <= 0 ) + { + result.push_back(Pair("result","error")); + result.push_back(Pair("error","negative parameter")); + if ( params != 0 ) + free_json(params); + return(result); + } + result.push_back(Pair("plan_type","token snapshot")); + result.push_back(Pair("lockedblocks",(int64_t)lockedblocks)); + result.push_back(Pair("minrelease",(int64_t)minrelease)); + result.push_back(Pair("top",(int64_t)top)); + result.push_back(Pair("tokenid",tokenid.ToString())); + for ( auto scriptPubKey : excludeScriptPubKeys ) + a.push_back(HexStr(scriptPubKey.begin(),scriptPubKey.end())); + result.push_back(Pair("excludeScriptPubkeys",a)); + } + else + { + result.push_back(Pair("result","error")); + result.push_back(Pair("error","couldnt decode valid payments create txid opreturn")); + } + if ( flag == 0 ) + { + txidpk = CCtxidaddr(txidaddr,createtxid); + GetCCaddress1of2(cp,fundsaddr,Paymentspk,txidpk); + funds = CCaddress_balance(fundsaddr,1); + result.push_back(Pair(fundsaddr,ValueFromAmount(funds))); + GetCCaddress(cp,fundsopretaddr,Paymentspk); + // TODO: Shows balance for ALL payments plans, not just the one asked for! Needs to be reworked. + fundsopret = CCaddress_balance(fundsopretaddr,1); + result.push_back(Pair(fundsopretaddr,ValueFromAmount(fundsopret))); + result.push_back(Pair("totalfunds",ValueFromAmount(funds+fundsopret))); + result.push_back(Pair("result","success")); } } - if ( flag == 0 ) + else { result.push_back(Pair("result","error")); result.push_back(Pair("error","couldnt find valid payments create txid")); @@ -889,8 +1145,9 @@ UniValue PaymentsInfo(struct CCcontract_info *cp,char *jsonstr) UniValue PaymentsList(struct CCcontract_info *cp,char *jsonstr) { - std::vector > addressIndex; uint256 txid,hashBlock; + std::vector > addressIndex; uint256 txid,hashBlock,tokenid; UniValue result(UniValue::VOBJ),a(UniValue::VARR); char markeraddr[64],str[65]; CPubKey Paymentspk; CTransaction tx; int32_t lockedblocks,minrelease; std::vector txidoprets; int64_t totalallocations; + int32_t top; std::vector> excludeScriptPubKeys; Paymentspk = GetUnspendable(cp,0); GetCCaddress1of2(cp,markeraddr,Paymentspk,Paymentspk); SetCCtxids(addressIndex,markeraddr,true); @@ -899,7 +1156,7 @@ UniValue PaymentsList(struct CCcontract_info *cp,char *jsonstr) txid = it->first.txhash; if ( it->first.index == 0 && myGetTransaction(txid,tx,hashBlock) != 0 ) { - if ( tx.vout.size() > 0 && DecodePaymentsOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,lockedblocks,minrelease,totalallocations,txidoprets) == 'C' ) + if ( tx.vout.size() > 0 && (DecodePaymentsOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,lockedblocks,minrelease,totalallocations,txidoprets) == 'C' || DecodePaymentsSnapsShotOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,lockedblocks,minrelease,top,excludeScriptPubKeys) == 'S' || DecodePaymentsTokensOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,lockedblocks,minrelease,top,excludeScriptPubKeys,tokenid) == 'O') ) { if ( lockedblocks < 0 || minrelease < 0 || totalallocations <= 0 || txidoprets.size() < 2 ) { diff --git a/src/main.cpp b/src/main.cpp index 8bace2cb0..3168b773c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -656,6 +656,7 @@ std::vector > vAddressSnapshot; bool komodo_dailysnapshot(int32_t height) { + int reorglimit = 10; // CHANGE BACK TO 100 AFTER TESTING! uint256 notarized_hash,notarized_desttxid; int32_t prevMoMheight,notarized_height,undo_height,extraoffset; if ( (extraoffset= height % KOMODO_SNAPSHOT_INTERVAL) != 0 ) { @@ -663,25 +664,16 @@ bool komodo_dailysnapshot(int32_t height) // use the notarizationsDB to scan back from the consesnus height to get the offset we need. std::string symbol; Notarisation nota; symbol.assign(ASSETCHAINS_SYMBOL); - ScanNotarisationsDB(height-extraoffset, symbol, 100, nota); - undo_height = nota.second.height; - if ( undo_height == 0 ) undo_height = height-extraoffset-100; - fprintf(stderr, "height.%i-extraoffset.%i = startscanfrom.%i to get undo_height.%i\n", height, extraoffset, height-extraoffset, undo_height); + if ( ScanNotarisationsDB(height-extraoffset, symbol, 100, nota) == 0 ) + undo_height = height-extraoffset-reorglimit; + else undo_height = nota.second.height; + //fprintf(stderr, "height.%i-extraoffset.%i = startscanfrom.%i to get undo_height.%i\n", height, extraoffset, height-extraoffset, undo_height); } else { // we are at the right height in connect block to scan back to last notarized height. notarized_height = komodo_notarized_height(&prevMoMheight,¬arized_hash,¬arized_desttxid); - if ( notarized_height > height-100 ) - { - // notarized height is higher than 100 blocks before this height, so snapshot the notarized height. - undo_height = notarized_height; - } - else - { - //snapshot 100 blocks ago. Could still be reorged but very unlikley and expensive to carry out constantly. - undo_height = height-100; - } + notarized_height > height-100 ? undo_height = notarized_height : undo_height = height-reorglimit; } fprintf(stderr, "doing snapshot for height.%i undo_height.%i\n", height, undo_height); // if we already did this height dont bother doing it again, this is just a reorg. The actual snapshot height cannot be reorged. @@ -702,9 +694,7 @@ bool komodo_dailysnapshot(int32_t height) for (int32_t i = block.vtx.size() - 1; i >= 0; i--) { const CTransaction &tx = block.vtx[i]; - uint256 hash = tx.GetHash(); CTxDestination vDest; - //fprintf(stderr, "undong tx.%s\n",hash.GetHex().c_str()); // loop vouts reverse order, remove value recieved. for (unsigned int k = tx.vout.size(); k-- > 0;) { @@ -721,7 +711,7 @@ bool komodo_dailysnapshot(int32_t height) for (unsigned int j = tx.vin.size(); j-- > 0;) { uint256 blockhash; CTransaction txin; - if ( !tx.IsCoinImport() && !tx.IsCoinBase() && myGetTransaction(tx.vin[j].prevout.hash,txin,blockhash) ) // myGetTransaction! + if ( !tx.IsCoinImport() && !tx.IsCoinBase() && myGetTransaction(tx.vin[j].prevout.hash,txin,blockhash) ) { int vout = tx.vin[j].prevout.n; if ( ExtractDestination(txin.vout[vout].scriptPubKey, vDest) ) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 66c534f11..8733b2894 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5632,14 +5632,14 @@ UniValue payments_create(const UniValue& params, bool fHelp) UniValue payments_airdrop(const UniValue& params, bool fHelp) { struct CCcontract_info *cp,C; - //if ( fHelp || params.size() != 1 ) - // throw runtime_error("paymentscreate \"[lockedblocks,minamount,%22paytxid0%22,...,%22paytxidN%22]\"\n"); - //if ( ensure_CCrequirements(EVAL_PAYMENTS) < 0 ) - // throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); - //const CKeyStore& keystore = *pwalletMain; + if ( fHelp || params.size() != 1 ) + throw runtime_error("paymentsairdrop \"[lockedblocks,minamount,top,%22paytxid0%22,...,%22paytxidN%22]\"\n"); + if ( ensure_CCrequirements(EVAL_PAYMENTS) < 0 ) + throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + const CKeyStore& keystore = *pwalletMain; LOCK2(cs_main, pwalletMain->cs_wallet); - //cp = CCinit(&C,EVAL_PAYMENTS); - return(PaymentsAirdrop(0,(char *)params[0].get_str().c_str())); + cp = CCinit(&C,EVAL_PAYMENTS); + return(PaymentsAirdrop(cp,(char *)params[0].get_str().c_str())); } UniValue payments_info(const UniValue& params, bool fHelp) From 5e93f5d3b78fb75bf9fea5cc186cb6121e7f5a72 Mon Sep 17 00:00:00 2001 From: dimxy Date: Mon, 29 Apr 2019 20:04:21 +0500 Subject: [PATCH 167/447] satoshiden to prices_normfactor (signed) --- src/cc/CCPrices.h | 4 +++- src/cc/prices.cpp | 37 +++++++++++++++++++------------------ 2 files changed, 22 insertions(+), 19 deletions(-) diff --git a/src/cc/CCPrices.h b/src/cc/CCPrices.h index 900ee7505..9bcae60b2 100644 --- a/src/cc/CCPrices.h +++ b/src/cc/CCPrices.h @@ -35,7 +35,9 @@ int32_t komodo_priceget(int64_t *buf64,int32_t ind,int32_t height,int32_t numblo #define PRICES_MMD (KOMODO_MAXPRICES * 6) // 0011 0000 0000 0000 #define PRICES_MMM (KOMODO_MAXPRICES * 7) // 0011 1000 0000 0000 #define PRICES_DDD (KOMODO_MAXPRICES * 8) // 0100 0000 0000 0000 -#define PRICES_NORMFACTOR 10000 + +#define PRICES_NORMFACTOR (int64_t)(SATOSHIDEN) +#define PRICES_POINTFACTOR (int64_t)10000 bool PricesValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 1b174a770..4be0afd4e 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -640,7 +640,7 @@ int64_t prices_syntheticprice(std::vector vec, int32_t height, int32_t if (depth >= 2) { b = pricestack[--depth]; a = pricestack[--depth]; - pricestack[depth++] = (a * b) / SATOSHIDEN; + pricestack[depth++] = (a * b) / PRICES_NORMFACTOR; } else errcode = -3; @@ -650,7 +650,7 @@ int64_t prices_syntheticprice(std::vector vec, int32_t height, int32_t if (depth >= 2) { b = pricestack[--depth]; a = pricestack[--depth]; - pricestack[depth++] = (a * SATOSHIDEN) / b; + pricestack[depth++] = (a * PRICES_NORMFACTOR) / b; } else errcode = -4; @@ -659,7 +659,7 @@ int64_t prices_syntheticprice(std::vector vec, int32_t height, int32_t case PRICES_INV: if (depth >= 1) { a = pricestack[--depth]; - pricestack[depth++] = (SATOSHIDEN * SATOSHIDEN) / a; + pricestack[depth++] = (PRICES_NORMFACTOR * PRICES_NORMFACTOR) / a; } else errcode = -5; @@ -670,7 +670,7 @@ int64_t prices_syntheticprice(std::vector vec, int32_t height, int32_t c = pricestack[--depth]; b = pricestack[--depth]; a = pricestack[--depth]; - pricestack[depth++] = (((a * SATOSHIDEN) / b) * SATOSHIDEN) / c; + pricestack[depth++] = (((a * PRICES_NORMFACTOR) / b) * PRICES_NORMFACTOR) / c; } else errcode = -6; @@ -692,7 +692,7 @@ int64_t prices_syntheticprice(std::vector vec, int32_t height, int32_t c = pricestack[--depth]; b = pricestack[--depth]; a = pricestack[--depth]; - pricestack[depth++] = ((a * b) / SATOSHIDEN) * c; + pricestack[depth++] = ((a * b) / PRICES_NORMFACTOR) * c; } else errcode = -8; @@ -703,7 +703,7 @@ int64_t prices_syntheticprice(std::vector vec, int32_t height, int32_t c = pricestack[--depth]; b = pricestack[--depth]; a = pricestack[--depth]; - pricestack[depth++] = (((((SATOSHIDEN * SATOSHIDEN) / a) * SATOSHIDEN) / b) * SATOSHIDEN) / c; + pricestack[depth++] = (((((PRICES_NORMFACTOR * PRICES_NORMFACTOR) / a) * PRICES_NORMFACTOR) / b) * PRICES_NORMFACTOR) / c; } else errcode = -9; @@ -716,7 +716,7 @@ int64_t prices_syntheticprice(std::vector vec, int32_t height, int32_t if (errcode != 0) break; - std::cerr << "pricestack[depth=" << depth << "]=" << pricestack[depth] << std::endl; + std::cerr << "top pricestack[depth-1=" << depth-1 << "]=" << pricestack[depth-1] << std::endl; } free(pricedata); @@ -759,8 +759,8 @@ int32_t prices_syntheticprofits(int64_t &costbasis, int32_t firstheight, int32_t } // clear lowest positions: - price /= PRICES_NORMFACTOR; - price *= PRICES_NORMFACTOR; + price /= PRICES_POINTFACTOR; + price *= PRICES_POINTFACTOR; outprice = price; if (minmax) { // if we are within day window, set temp costbasis to max (or min) price value @@ -787,17 +787,17 @@ int32_t prices_syntheticprofits(int64_t &costbasis, int32_t firstheight, int32_t } // normalize to 10,000,000 to prevent underflow - profits = costbasis > 0 ? (((price / PRICES_NORMFACTOR * SATOSHIDEN) / costbasis) - SATOSHIDEN / PRICES_NORMFACTOR) * PRICES_NORMFACTOR : 0; + profits = costbasis > 0 ? (((price / PRICES_POINTFACTOR * PRICES_NORMFACTOR) / costbasis) - PRICES_NORMFACTOR / PRICES_POINTFACTOR) * PRICES_POINTFACTOR : 0; - //std::cerr << "prices_syntheticprofits() test value1 (price/PRICES_NORMFACTOR * SATOSHIDEN)=" << (price / PRICES_NORMFACTOR * SATOSHIDEN) << std::endl; - std::cerr << "prices_syntheticprofits() test value2 (price/PRICES_NORMFACTOR * SATOSHIDEN)/costbasis=" << (costbasis != 0 ? (price / PRICES_NORMFACTOR * SATOSHIDEN)/costbasis : 0) << std::endl; + //std::cerr << "prices_syntheticprofits() test value1 (price/PRICES_POINTFACTOR * PRICES_NORMFACTOR)=" << (price / PRICES_POINTFACTOR * PRICES_NORMFACTOR) << std::endl; + std::cerr << "prices_syntheticprofits() test value2 (price/PRICES_POINTFACTOR * PRICES_NORMFACTOR)/costbasis=" << (costbasis != 0 ? (price / PRICES_POINTFACTOR * PRICES_NORMFACTOR)/costbasis : 0) << std::endl; std::cerr << "prices_syntheticprofits() fractional profits=" << profits << std::endl; //std::cerr << "prices_syntheticprofits() profits double=" << (double)price / (double)costbasis -1.0 << std::endl; //double dprofits = (double)price / (double)costbasis - 1.0; profits *= ((int64_t)leverage * (int64_t)positionsize); - profits /= (int64_t)SATOSHIDEN; // de-normalize + profits /= (int64_t)PRICES_NORMFACTOR; // de-normalize //dprofits *= leverage * positionsize; std::cerr << "prices_syntheticprofits() profits=" << profits << std::endl; @@ -892,6 +892,7 @@ int64_t prices_enumaddedbets(uint256 &batontxid, std::vector &bets, uin EvalRef eval; if ((isLoaded = eval->GetTxConfirmed(batontxid, txBaton, blockIdx)) && + blockIdx.IsValid() && txBaton.vout.size() > 0 && (funcId = prices_addopretdecode(txBaton.vout.back().scriptPubKey, bettxidInOpret, pk, amount)) != 0) { @@ -1334,22 +1335,22 @@ UniValue PricesInfo(uint256 bettxid, int32_t refheight) for (auto b : bets) { totalbets += b.amount; totalprofits += b.profits; - costbasis += b.amount * (b.costbasis / PRICES_NORMFACTOR); // prevent int64 overflow - std::cerr << "PricesInfo() acc costbasis=" << costbasis << " b.amount=" << b.amount << " b.costbasis/PRICES_NORMFACTOR=" << (b.costbasis / PRICES_NORMFACTOR) << std::endl; + costbasis += b.amount * (b.costbasis / PRICES_POINTFACTOR); // prevent int64 overflow + std::cerr << "PricesInfo() acc costbasis=" << costbasis << " b.amount=" << b.amount << " b.costbasis/PRICES_POINTFACTOR=" << (b.costbasis / PRICES_POINTFACTOR) << std::endl; } int64_t equity = totalbets + totalprofits; if (totalbets != 0) { //prevent zero div costbasis /= totalbets; - costbasis *= PRICES_NORMFACTOR; //denormalization, last posiitons should be == 0000 + costbasis *= PRICES_POINTFACTOR; //denormalization, last posiitons should be == 0000 } else costbasis = 0; int64_t liqprice; if (leverage != 0) {// prevent zero div liqprice = costbasis - costbasis / leverage; - liqprice /= PRICES_NORMFACTOR; - liqprice *= PRICES_NORMFACTOR; // last posiitons should be == 0000 + liqprice /= PRICES_POINTFACTOR; + liqprice *= PRICES_POINTFACTOR; // last posiitons should be == 0000 } else liqprice = 0; From b4a112888b0d882e5a56f77c777668785563d3bd Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Tue, 30 Apr 2019 00:12:00 +0800 Subject: [PATCH 168/447] fix tx expiry height, to 200 blocks --- src/main.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.h b/src/main.h index ec36c976b..d507f9dd6 100644 --- a/src/main.h +++ b/src/main.h @@ -88,7 +88,7 @@ static const unsigned int DEFAULT_MIN_RELAY_TX_FEE = 100; /** Default for -maxorphantx, maximum number of orphan transactions kept in memory */ static const unsigned int DEFAULT_MAX_ORPHAN_TRANSACTIONS = 100; /** Default for -txexpirydelta, in number of blocks */ -static const unsigned int DEFAULT_TX_EXPIRY_DELTA = 20; +static const unsigned int DEFAULT_TX_EXPIRY_DELTA = 200; /** The maximum size of a blk?????.dat file (since 0.8) */ static const unsigned int MAX_BLOCKFILE_SIZE = 0x8000000; // 128 MiB static const unsigned int MAX_TEMPFILE_SIZE = 0x1000000; // 16 MiB 0x8000000 From 13a1463f02ea6358a49216bfff379babb60253a3 Mon Sep 17 00:00:00 2001 From: dimxy Date: Mon, 29 Apr 2019 21:23:46 +0500 Subject: [PATCH 169/447] removed clearing precision to 0.0001 --- src/cc/prices.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 4be0afd4e..302777f84 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -716,7 +716,10 @@ int64_t prices_syntheticprice(std::vector vec, int32_t height, int32_t if (errcode != 0) break; - std::cerr << "top pricestack[depth-1=" << depth-1 << "]=" << pricestack[depth-1] << std::endl; + if( depth >= 0 ) + std::cerr << "top pricestack[depth-1=" << depth-1 << "]=" << pricestack[depth-1] << std::endl; + else + std::cerr << "pricestack empty" << std::endl; } free(pricedata); @@ -759,8 +762,8 @@ int32_t prices_syntheticprofits(int64_t &costbasis, int32_t firstheight, int32_t } // clear lowest positions: - price /= PRICES_POINTFACTOR; - price *= PRICES_POINTFACTOR; + //price /= PRICES_POINTFACTOR; + //price *= PRICES_POINTFACTOR; outprice = price; if (minmax) { // if we are within day window, set temp costbasis to max (or min) price value From 911462d1aae3734d68ac31cf918afbd5fef7b477 Mon Sep 17 00:00:00 2001 From: dimxy Date: Mon, 29 Apr 2019 21:30:28 +0500 Subject: [PATCH 170/447] remove clearing prec in pricesinfo --- src/cc/prices.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 302777f84..79a217f16 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -1352,8 +1352,8 @@ UniValue PricesInfo(uint256 bettxid, int32_t refheight) int64_t liqprice; if (leverage != 0) {// prevent zero div liqprice = costbasis - costbasis / leverage; - liqprice /= PRICES_POINTFACTOR; - liqprice *= PRICES_POINTFACTOR; // last posiitons should be == 0000 + //liqprice /= PRICES_POINTFACTOR; + //liqprice *= PRICES_POINTFACTOR; // last posiitons should be == 0000 } else liqprice = 0; From d81d30a27c38cacb2fd2e74d20d4a2928ddec536 Mon Sep 17 00:00:00 2001 From: dimxy Date: Mon, 29 Apr 2019 21:35:58 +0500 Subject: [PATCH 171/447] corr costbasis prec in pricesinfo --- src/cc/prices.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 79a217f16..30149244a 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -1344,8 +1344,8 @@ UniValue PricesInfo(uint256 bettxid, int32_t refheight) int64_t equity = totalbets + totalprofits; if (totalbets != 0) { //prevent zero div + costbasis *= PRICES_POINTFACTOR; // save last 0.0000xxxx positions costbasis /= totalbets; - costbasis *= PRICES_POINTFACTOR; //denormalization, last posiitons should be == 0000 } else costbasis = 0; From 0467d13a107548a613f09cc7e598086ea91535db Mon Sep 17 00:00:00 2001 From: dimxy Date: Mon, 29 Apr 2019 21:50:55 +0500 Subject: [PATCH 172/447] try use floating point to calc average costbasis --- src/cc/prices.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 30149244a..6066100a9 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -1334,18 +1334,20 @@ UniValue PricesInfo(uint256 bettxid, int32_t refheight) int64_t totalbets = 0; int64_t totalprofits = 0; - int64_t costbasis = 0; + double dcostbasis = 0.0; for (auto b : bets) { totalbets += b.amount; totalprofits += b.profits; - costbasis += b.amount * (b.costbasis / PRICES_POINTFACTOR); // prevent int64 overflow - std::cerr << "PricesInfo() acc costbasis=" << costbasis << " b.amount=" << b.amount << " b.costbasis/PRICES_POINTFACTOR=" << (b.costbasis / PRICES_POINTFACTOR) << std::endl; + dcostbasis += b.amount * b.costbasis; + // costbasis += b.amount * (b.costbasis / PRICES_POINTFACTOR); // prevent int64 overflow (but we have underflow for 1/BTC) + // std::cerr << "PricesInfo() acc costbasis=" << costbasis << " b.amount=" << b.amount << " b.costbasis/PRICES_POINTFACTOR=" << (b.costbasis / PRICES_POINTFACTOR) << std::endl; } int64_t equity = totalbets + totalprofits; + int64_t costbasis; if (totalbets != 0) { //prevent zero div - costbasis *= PRICES_POINTFACTOR; // save last 0.0000xxxx positions - costbasis /= totalbets; + // costbasis *= PRICES_POINTFACTOR; // save last 0.0000xxxx positions + costbasis = (int64_t) (dcostbasis / (double)totalbets); } else costbasis = 0; From e6d145f2f52dee6650ed195292dc7191a1201ceb Mon Sep 17 00:00:00 2001 From: dimxy Date: Tue, 30 Apr 2019 00:39:05 +0500 Subject: [PATCH 173/447] log dcostbasis --- src/cc/prices.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 6066100a9..c57d932e0 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -716,7 +716,7 @@ int64_t prices_syntheticprice(std::vector vec, int32_t height, int32_t if (errcode != 0) break; - if( depth >= 0 ) + if( depth > 0 ) std::cerr << "top pricestack[depth-1=" << depth-1 << "]=" << pricestack[depth-1] << std::endl; else std::cerr << "pricestack empty" << std::endl; @@ -1340,7 +1340,7 @@ UniValue PricesInfo(uint256 bettxid, int32_t refheight) totalprofits += b.profits; dcostbasis += b.amount * b.costbasis; // costbasis += b.amount * (b.costbasis / PRICES_POINTFACTOR); // prevent int64 overflow (but we have underflow for 1/BTC) - // std::cerr << "PricesInfo() acc costbasis=" << costbasis << " b.amount=" << b.amount << " b.costbasis/PRICES_POINTFACTOR=" << (b.costbasis / PRICES_POINTFACTOR) << std::endl; + std::cerr << "PricesInfo() acc dcostbasis=" << dcostbasis << " b.amount=" << b.amount << " b.costbasis/PRICES_POINTFACTOR=" << (b.costbasis / PRICES_POINTFACTOR) << std::endl; } int64_t equity = totalbets + totalprofits; From 656992811cf02ea46c07dc227ddbc706d8e5b2fb Mon Sep 17 00:00:00 2001 From: dimxy Date: Tue, 30 Apr 2019 00:47:15 +0500 Subject: [PATCH 174/447] long double --- src/cc/prices.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index c57d932e0..a69f68ba0 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -1334,7 +1334,7 @@ UniValue PricesInfo(uint256 bettxid, int32_t refheight) int64_t totalbets = 0; int64_t totalprofits = 0; - double dcostbasis = 0.0; + long double dcostbasis = 0.0; for (auto b : bets) { totalbets += b.amount; totalprofits += b.profits; From b800a223c56b9e1a4ecfeccecf7b7eadab56646b Mon Sep 17 00:00:00 2001 From: dimxy Date: Tue, 30 Apr 2019 00:52:47 +0500 Subject: [PATCH 175/447] corr double mult --- src/cc/prices.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index a69f68ba0..783e9f03c 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -1334,11 +1334,11 @@ UniValue PricesInfo(uint256 bettxid, int32_t refheight) int64_t totalbets = 0; int64_t totalprofits = 0; - long double dcostbasis = 0.0; + double dcostbasis = 0.0; for (auto b : bets) { totalbets += b.amount; totalprofits += b.profits; - dcostbasis += b.amount * b.costbasis; + dcostbasis += b.amount * (double)b.costbasis; // costbasis += b.amount * (b.costbasis / PRICES_POINTFACTOR); // prevent int64 overflow (but we have underflow for 1/BTC) std::cerr << "PricesInfo() acc dcostbasis=" << dcostbasis << " b.amount=" << b.amount << " b.costbasis/PRICES_POINTFACTOR=" << (b.costbasis / PRICES_POINTFACTOR) << std::endl; } From 23f427373c57296d836e8591bc56552388100f85 Mon Sep 17 00:00:00 2001 From: dimxy Date: Tue, 30 Apr 2019 01:00:26 +0500 Subject: [PATCH 176/447] costbasis calc temp change to floating point --- src/cc/prices.cpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 783e9f03c..dcb9b146a 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -790,19 +790,24 @@ int32_t prices_syntheticprofits(int64_t &costbasis, int32_t firstheight, int32_t } // normalize to 10,000,000 to prevent underflow - profits = costbasis > 0 ? (((price / PRICES_POINTFACTOR * PRICES_NORMFACTOR) / costbasis) - PRICES_NORMFACTOR / PRICES_POINTFACTOR) * PRICES_POINTFACTOR : 0; + //profits = costbasis > 0 ? (((price / PRICES_POINTFACTOR * PRICES_NORMFACTOR) / costbasis) - PRICES_NORMFACTOR / PRICES_POINTFACTOR) * PRICES_POINTFACTOR : 0; + + double dprofits = costbasis > 0 ? ((double)price / (double)costbasis - 1) : 0; //std::cerr << "prices_syntheticprofits() test value1 (price/PRICES_POINTFACTOR * PRICES_NORMFACTOR)=" << (price / PRICES_POINTFACTOR * PRICES_NORMFACTOR) << std::endl; - std::cerr << "prices_syntheticprofits() test value2 (price/PRICES_POINTFACTOR * PRICES_NORMFACTOR)/costbasis=" << (costbasis != 0 ? (price / PRICES_POINTFACTOR * PRICES_NORMFACTOR)/costbasis : 0) << std::endl; + //std::cerr << "prices_syntheticprofits() test value2 (price/PRICES_POINTFACTOR * PRICES_NORMFACTOR)/costbasis=" << (costbasis != 0 ? (price / PRICES_POINTFACTOR * PRICES_NORMFACTOR)/costbasis : 0) << std::endl; - std::cerr << "prices_syntheticprofits() fractional profits=" << profits << std::endl; + //std::cerr << "prices_syntheticprofits() fractional profits=" << profits << std::endl; //std::cerr << "prices_syntheticprofits() profits double=" << (double)price / (double)costbasis -1.0 << std::endl; //double dprofits = (double)price / (double)costbasis - 1.0; - profits *= ((int64_t)leverage * (int64_t)positionsize); - profits /= (int64_t)PRICES_NORMFACTOR; // de-normalize + //profits *= ((int64_t)leverage * (int64_t)positionsize); + //profits /= (int64_t)PRICES_NORMFACTOR; // de-normalize + + dprofits *= ((double)leverage * (double)positionsize); //dprofits *= leverage * positionsize; + profits = dprofits; std::cerr << "prices_syntheticprofits() profits=" << profits << std::endl; //std::cerr << "prices_syntheticprofits() dprofits=" << dprofits << std::endl; From 2a5a86b1ce118e06d742d14c1540237a6d2e0257 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Tue, 30 Apr 2019 11:20:02 +0800 Subject: [PATCH 177/447] change default expiry height to 200 instead of 20. To stop wallet getting corrupted. --- src/main.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.h b/src/main.h index ec36c976b..d507f9dd6 100644 --- a/src/main.h +++ b/src/main.h @@ -88,7 +88,7 @@ static const unsigned int DEFAULT_MIN_RELAY_TX_FEE = 100; /** Default for -maxorphantx, maximum number of orphan transactions kept in memory */ static const unsigned int DEFAULT_MAX_ORPHAN_TRANSACTIONS = 100; /** Default for -txexpirydelta, in number of blocks */ -static const unsigned int DEFAULT_TX_EXPIRY_DELTA = 20; +static const unsigned int DEFAULT_TX_EXPIRY_DELTA = 200; /** The maximum size of a blk?????.dat file (since 0.8) */ static const unsigned int MAX_BLOCKFILE_SIZE = 0x8000000; // 128 MiB static const unsigned int MAX_TEMPFILE_SIZE = 0x1000000; // 16 MiB 0x8000000 From 762c878d564e0c877f62ffe9b73b56b81826173c Mon Sep 17 00:00:00 2001 From: dimxy Date: Tue, 30 Apr 2019 12:16:27 +0500 Subject: [PATCH 178/447] added profits calc with gmp lib --- src/cc/prices.cpp | 42 +++++++++++++++++++++++++++++++++++++----- 1 file changed, 37 insertions(+), 5 deletions(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index dcb9b146a..36214c735 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -16,6 +16,8 @@ #include "CCassets.h" #include "CCPrices.h" +#include "mini-gmp.h" + #define IS_CHARINSTR(c, str) (std::string(str).find((char)(c)) != std::string::npos) typedef struct BetInfo { @@ -791,9 +793,8 @@ int32_t prices_syntheticprofits(int64_t &costbasis, int32_t firstheight, int32_t // normalize to 10,000,000 to prevent underflow //profits = costbasis > 0 ? (((price / PRICES_POINTFACTOR * PRICES_NORMFACTOR) / costbasis) - PRICES_NORMFACTOR / PRICES_POINTFACTOR) * PRICES_POINTFACTOR : 0; + //double dprofits = costbasis > 0 ? ((double)price / (double)costbasis - 1) : 0; - double dprofits = costbasis > 0 ? ((double)price / (double)costbasis - 1) : 0; - //std::cerr << "prices_syntheticprofits() test value1 (price/PRICES_POINTFACTOR * PRICES_NORMFACTOR)=" << (price / PRICES_POINTFACTOR * PRICES_NORMFACTOR) << std::endl; //std::cerr << "prices_syntheticprofits() test value2 (price/PRICES_POINTFACTOR * PRICES_NORMFACTOR)/costbasis=" << (costbasis != 0 ? (price / PRICES_POINTFACTOR * PRICES_NORMFACTOR)/costbasis : 0) << std::endl; @@ -804,13 +805,44 @@ int32_t prices_syntheticprofits(int64_t &costbasis, int32_t firstheight, int32_t //profits *= ((int64_t)leverage * (int64_t)positionsize); //profits /= (int64_t)PRICES_NORMFACTOR; // de-normalize - dprofits *= ((double)leverage * (double)positionsize); + //dprofits *= ((double)leverage * (double)positionsize); //dprofits *= leverage * positionsize; - profits = dprofits; - std::cerr << "prices_syntheticprofits() profits=" << profits << std::endl; + // profits = dprofits; //std::cerr << "prices_syntheticprofits() dprofits=" << dprofits << std::endl; + + + if (costbasis > 0) { + mpz_t mpzProfits; + mpz_t mpzCostbasis; + mpz_t mpzPrice; + + mpz_init(mpzProfits); + mpz_init(mpzCostbasis); + mpz_init(mpzPrice); + + mpz_set_si(mpzCostbasis, costbasis); + mpz_mul_ui(mpzCostbasis, mpzCostbasis, SATOSHIDEN); + mpz_set_si(mpzPrice, price); + + mpz_divexact(mpzProfits, mpzPrice, mpzCostbasis); // profits = (price*SATOSHIDEN)/costbasis // normalization + mpz_sub_ui(mpzProfits, mpzProfits, SATOSHIDEN); // profits -= SATOSHIDEN + + mpz_mul_si(mpzProfits, mpzProfits, leverage); // profits *= leverage + mpz_mul_si(mpzProfits, mpzProfits, positionsize); // profits *= positionsize + mpz_divexact_ui(mpzProfits, mpzPrice, SATOSHIDEN); // profits /= SATOSHIDEN // de-normalization + + profits = mpz_get_si(mpzProfits); + + mpz_clear(mpzProfits); + mpz_clear(mpzCostbasis); + mpz_clear(mpzPrice); + } + else + profits = 0; + + std::cerr << "prices_syntheticprofits() profits=" << profits << std::endl; return 0; // (positionsize + addedbets + profits); } From 00debd2f613be8d3e526b7f042b79394de437da5 Mon Sep 17 00:00:00 2001 From: dimxy Date: Tue, 30 Apr 2019 12:40:20 +0500 Subject: [PATCH 179/447] try include mini-gmp.c --- src/cc/prices.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 36214c735..a67f4b17f 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -18,6 +18,8 @@ #include "mini-gmp.h" +#include "mini-gmp.c" + #define IS_CHARINSTR(c, str) (std::string(str).find((char)(c)) != std::string::npos) typedef struct BetInfo { From dbc4818b8a46d5a5dd2dde1ef0bd53d21650316e Mon Sep 17 00:00:00 2001 From: dimxy Date: Tue, 30 Apr 2019 12:44:53 +0500 Subject: [PATCH 180/447] add mini-gmp to Makefile.am --- src/Makefile.am | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Makefile.am b/src/Makefile.am index e6c1fbb14..f31a394f6 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -302,6 +302,7 @@ libbitcoin_server_a_SOURCES = \ cc/fsm.cpp \ cc/heir.cpp \ cc/oracles.cpp \ + mini-gmp.c \ cc/prices.cpp \ cc/pegs.cpp \ cc/marmara.cpp \ From f8bbf9b13090c4be81cef69f357ef1abc96aaa5b Mon Sep 17 00:00:00 2001 From: dimxy Date: Tue, 30 Apr 2019 15:08:01 +0500 Subject: [PATCH 181/447] Revert "add mini-gmp to Makefile.am" This reverts commit dbc4818b8a46d5a5dd2dde1ef0bd53d21650316e. --- src/Makefile.am | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Makefile.am b/src/Makefile.am index f31a394f6..e6c1fbb14 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -302,7 +302,6 @@ libbitcoin_server_a_SOURCES = \ cc/fsm.cpp \ cc/heir.cpp \ cc/oracles.cpp \ - mini-gmp.c \ cc/prices.cpp \ cc/pegs.cpp \ cc/marmara.cpp \ From d9a53c242ea2e1ec9d4d077791f37a12609c6bcd Mon Sep 17 00:00:00 2001 From: dimxy Date: Tue, 30 Apr 2019 15:08:18 +0500 Subject: [PATCH 182/447] Revert "try include mini-gmp.c" This reverts commit 00debd2f613be8d3e526b7f042b79394de437da5. --- src/cc/prices.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index a67f4b17f..36214c735 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -18,8 +18,6 @@ #include "mini-gmp.h" -#include "mini-gmp.c" - #define IS_CHARINSTR(c, str) (std::string(str).find((char)(c)) != std::string::npos) typedef struct BetInfo { From bb0e6307067d5e21cc8add375bad7f88827760e9 Mon Sep 17 00:00:00 2001 From: dimxy Date: Tue, 30 Apr 2019 16:03:26 +0500 Subject: [PATCH 183/447] changed gmp calls to unsigned --- src/cc/prices.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 36214c735..36acd753c 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -822,18 +822,18 @@ int32_t prices_syntheticprofits(int64_t &costbasis, int32_t firstheight, int32_t mpz_init(mpzCostbasis); mpz_init(mpzPrice); - mpz_set_si(mpzCostbasis, costbasis); + mpz_set_ui(mpzCostbasis, costbasis); mpz_mul_ui(mpzCostbasis, mpzCostbasis, SATOSHIDEN); - mpz_set_si(mpzPrice, price); + mpz_set_ui(mpzPrice, price); mpz_divexact(mpzProfits, mpzPrice, mpzCostbasis); // profits = (price*SATOSHIDEN)/costbasis // normalization mpz_sub_ui(mpzProfits, mpzProfits, SATOSHIDEN); // profits -= SATOSHIDEN - mpz_mul_si(mpzProfits, mpzProfits, leverage); // profits *= leverage - mpz_mul_si(mpzProfits, mpzProfits, positionsize); // profits *= positionsize + mpz_mul_ui(mpzProfits, mpzProfits, leverage); // profits *= leverage + mpz_mul_ui(mpzProfits, mpzProfits, positionsize); // profits *= positionsize mpz_divexact_ui(mpzProfits, mpzPrice, SATOSHIDEN); // profits /= SATOSHIDEN // de-normalization - profits = mpz_get_si(mpzProfits); + profits = mpz_get_ui(mpzProfits); mpz_clear(mpzProfits); mpz_clear(mpzCostbasis); From 020dcfcd85ff3f442de0f4425d9faf1b77e9d41b Mon Sep 17 00:00:00 2001 From: dimxy Date: Tue, 30 Apr 2019 16:15:02 +0500 Subject: [PATCH 184/447] changed gmp to essentials --- src/cc/prices.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 36acd753c..8d0453051 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -817,24 +817,28 @@ int32_t prices_syntheticprofits(int64_t &costbasis, int32_t firstheight, int32_t mpz_t mpzProfits; mpz_t mpzCostbasis; mpz_t mpzPrice; + mpz_t mpzLeverage; mpz_init(mpzProfits); mpz_init(mpzCostbasis); mpz_init(mpzPrice); + mpz_init(mpzLeverage); mpz_set_ui(mpzCostbasis, costbasis); mpz_mul_ui(mpzCostbasis, mpzCostbasis, SATOSHIDEN); mpz_set_ui(mpzPrice, price); + mpz_set_si(mpzLeverage, leverage); - mpz_divexact(mpzProfits, mpzPrice, mpzCostbasis); // profits = (price*SATOSHIDEN)/costbasis // normalization + mpz_fdiv_q(mpzProfits, mpzPrice, mpzCostbasis); // profits = (price*SATOSHIDEN)/costbasis // normalization mpz_sub_ui(mpzProfits, mpzProfits, SATOSHIDEN); // profits -= SATOSHIDEN - mpz_mul_ui(mpzProfits, mpzProfits, leverage); // profits *= leverage + mpz_mul(mpzProfits, mpzProfits, mpzLeverage); // profits *= leverage mpz_mul_ui(mpzProfits, mpzProfits, positionsize); // profits *= positionsize - mpz_divexact_ui(mpzProfits, mpzPrice, SATOSHIDEN); // profits /= SATOSHIDEN // de-normalization + mpz_fdiv_q_ui(mpzProfits, mpzPrice, SATOSHIDEN); // profits /= SATOSHIDEN // de-normalization profits = mpz_get_ui(mpzProfits); + mpz_clear(mpzLeverage); mpz_clear(mpzProfits); mpz_clear(mpzCostbasis); mpz_clear(mpzPrice); From 67176b6a7145a4dd02cead14c5cbe7a62ecd7911 Mon Sep 17 00:00:00 2001 From: dimxy Date: Tue, 30 Apr 2019 16:20:52 +0500 Subject: [PATCH 185/447] cdiv used --- src/cc/prices.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 8d0453051..4575e879e 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -829,12 +829,12 @@ int32_t prices_syntheticprofits(int64_t &costbasis, int32_t firstheight, int32_t mpz_set_ui(mpzPrice, price); mpz_set_si(mpzLeverage, leverage); - mpz_fdiv_q(mpzProfits, mpzPrice, mpzCostbasis); // profits = (price*SATOSHIDEN)/costbasis // normalization + mpz_cdiv_q(mpzProfits, mpzPrice, mpzCostbasis); // profits = (price*SATOSHIDEN)/costbasis // normalization mpz_sub_ui(mpzProfits, mpzProfits, SATOSHIDEN); // profits -= SATOSHIDEN mpz_mul(mpzProfits, mpzProfits, mpzLeverage); // profits *= leverage mpz_mul_ui(mpzProfits, mpzProfits, positionsize); // profits *= positionsize - mpz_fdiv_q_ui(mpzProfits, mpzPrice, SATOSHIDEN); // profits /= SATOSHIDEN // de-normalization + mpz_cdiv_q_ui(mpzProfits, mpzPrice, SATOSHIDEN); // profits /= SATOSHIDEN // de-normalization profits = mpz_get_ui(mpzProfits); From 9c50f7a7e5073b9a25692b6dcc9052c736a04351 Mon Sep 17 00:00:00 2001 From: dimxy Date: Tue, 30 Apr 2019 16:25:56 +0500 Subject: [PATCH 186/447] changed div funcs to essentials --- src/cc/prices.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 4575e879e..bf291618f 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -818,6 +818,7 @@ int32_t prices_syntheticprofits(int64_t &costbasis, int32_t firstheight, int32_t mpz_t mpzCostbasis; mpz_t mpzPrice; mpz_t mpzLeverage; + mpz_t mpzRemainder; mpz_init(mpzProfits); mpz_init(mpzCostbasis); @@ -829,15 +830,16 @@ int32_t prices_syntheticprofits(int64_t &costbasis, int32_t firstheight, int32_t mpz_set_ui(mpzPrice, price); mpz_set_si(mpzLeverage, leverage); - mpz_cdiv_q(mpzProfits, mpzPrice, mpzCostbasis); // profits = (price*SATOSHIDEN)/costbasis // normalization + mpz_tdiv_qr(mpzProfits, mpzRemainder, mpzPrice, mpzCostbasis); // profits = (price*SATOSHIDEN)/costbasis // normalization mpz_sub_ui(mpzProfits, mpzProfits, SATOSHIDEN); // profits -= SATOSHIDEN mpz_mul(mpzProfits, mpzProfits, mpzLeverage); // profits *= leverage mpz_mul_ui(mpzProfits, mpzProfits, positionsize); // profits *= positionsize - mpz_cdiv_q_ui(mpzProfits, mpzPrice, SATOSHIDEN); // profits /= SATOSHIDEN // de-normalization + mpz_tdiv_qr_ui(mpzProfits, mpzRemainder, mpzPrice, SATOSHIDEN); // profits /= SATOSHIDEN // de-normalization profits = mpz_get_ui(mpzProfits); + mpz_clear(mpzRemainder); mpz_clear(mpzLeverage); mpz_clear(mpzProfits); mpz_clear(mpzCostbasis); From 3f61f3c155c1090885352e64c8a58da843036de0 Mon Sep 17 00:00:00 2001 From: dimxy Date: Tue, 30 Apr 2019 16:31:37 +0500 Subject: [PATCH 187/447] missed mpz_init added --- src/cc/prices.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index bf291618f..3a14bf440 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -824,6 +824,8 @@ int32_t prices_syntheticprofits(int64_t &costbasis, int32_t firstheight, int32_t mpz_init(mpzCostbasis); mpz_init(mpzPrice); mpz_init(mpzLeverage); + mpz_init(mpzRemainder); + mpz_set_ui(mpzCostbasis, costbasis); mpz_mul_ui(mpzCostbasis, mpzCostbasis, SATOSHIDEN); From f4837d2b09320da18b774aa0d3834cbee44523cc Mon Sep 17 00:00:00 2001 From: dimxy Date: Tue, 30 Apr 2019 18:27:26 +0500 Subject: [PATCH 188/447] changed to gmp.h --- src/cc/prices.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 3a14bf440..56911144f 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -16,7 +16,8 @@ #include "CCassets.h" #include "CCPrices.h" -#include "mini-gmp.h" +//#include "mini-gmp.h" +#include #define IS_CHARINSTR(c, str) (std::string(str).find((char)(c)) != std::string::npos) From 1e131efcbaca28379cb9561566d379298bb5d306 Mon Sep 17 00:00:00 2001 From: dimxy Date: Tue, 30 Apr 2019 18:36:56 +0500 Subject: [PATCH 189/447] try use signed mpz_get_si --- src/cc/prices.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 56911144f..1992a40f1 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -840,7 +840,7 @@ int32_t prices_syntheticprofits(int64_t &costbasis, int32_t firstheight, int32_t mpz_mul_ui(mpzProfits, mpzProfits, positionsize); // profits *= positionsize mpz_tdiv_qr_ui(mpzProfits, mpzRemainder, mpzPrice, SATOSHIDEN); // profits /= SATOSHIDEN // de-normalization - profits = mpz_get_ui(mpzProfits); + profits = mpz_get_si(mpzProfits); mpz_clear(mpzRemainder); mpz_clear(mpzLeverage); From c6d91b33c02fd94f2eb38cbd889490b4fc9a5cab Mon Sep 17 00:00:00 2001 From: dimxy Date: Tue, 30 Apr 2019 19:11:24 +0500 Subject: [PATCH 190/447] test div --- src/cc/prices.cpp | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 1992a40f1..d27547a81 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -827,7 +827,6 @@ int32_t prices_syntheticprofits(int64_t &costbasis, int32_t firstheight, int32_t mpz_init(mpzLeverage); mpz_init(mpzRemainder); - mpz_set_ui(mpzCostbasis, costbasis); mpz_mul_ui(mpzCostbasis, mpzCostbasis, SATOSHIDEN); mpz_set_ui(mpzPrice, price); @@ -842,11 +841,44 @@ int32_t prices_syntheticprofits(int64_t &costbasis, int32_t firstheight, int32_t profits = mpz_get_si(mpzProfits); + + mpz_clear(mpzRemainder); mpz_clear(mpzLeverage); mpz_clear(mpzProfits); mpz_clear(mpzCostbasis); mpz_clear(mpzPrice); + + mpz_t mpzTest; + mpz_init(mpzTest); + + mpz_set_si(mpzTest, 5); + mpz_cdiv_qr_ui(mpzTest, mpzRemainder, mpzTest, 2); + std::cerr << "mpz_cdiv_qr_ui 5/2=" << mpz_get_si(mpzTest); + + mpz_set_si(mpzTest, 5); + mpz_tdiv_qr_ui(mpzTest, mpzRemainder, mpzTest, 2); + std::cerr << "mpz_tdiv_qr_ui 5/2=" << mpz_get_si(mpzTest); + + mpz_set_si(mpzTest, 5); + mpz_fdiv_qr_ui(mpzTest, mpzRemainder, mpzTest, 2); + std::cerr << "mpz_tdiv_qr_ui 5/2=" << mpz_get_si(mpzTest); + + mpz_set_si(mpzTest, -5); + mpz_cdiv_qr_ui(mpzTest, mpzRemainder, mpzTest, 2); + std::cerr << "mpz_cdiv_qr_ui -5/2=" << mpz_get_si(mpzTest); + + mpz_set_si(mpzTest, -5); + mpz_tdiv_qr_ui(mpzTest, mpzRemainder, mpzTest, 2); + std::cerr << "mpz_tdiv_qr_ui -5/2=" << mpz_get_si(mpzTest); + + mpz_set_si(mpzTest, -5); + mpz_fdiv_qr_ui(mpzTest, mpzRemainder, mpzTest, 2); + std::cerr << "mpz_fdiv_qr_ui -5/2=" << mpz_get_si(mpzTest); + std::cerr << std::endl; + + mpz_clear(mpzTest); + } else profits = 0; From 7ada2401e5d9ac4543af4ebf08ad464884ea959a Mon Sep 17 00:00:00 2001 From: dimxy Date: Tue, 30 Apr 2019 19:20:27 +0500 Subject: [PATCH 191/447] mem alloc corr --- src/cc/prices.cpp | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index d27547a81..b5eb19dd3 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -843,12 +843,6 @@ int32_t prices_syntheticprofits(int64_t &costbasis, int32_t firstheight, int32_t - mpz_clear(mpzRemainder); - mpz_clear(mpzLeverage); - mpz_clear(mpzProfits); - mpz_clear(mpzCostbasis); - mpz_clear(mpzPrice); - mpz_t mpzTest; mpz_init(mpzTest); @@ -858,25 +852,30 @@ int32_t prices_syntheticprofits(int64_t &costbasis, int32_t firstheight, int32_t mpz_set_si(mpzTest, 5); mpz_tdiv_qr_ui(mpzTest, mpzRemainder, mpzTest, 2); - std::cerr << "mpz_tdiv_qr_ui 5/2=" << mpz_get_si(mpzTest); + std::cerr << " mpz_tdiv_qr_ui 5/2=" << mpz_get_si(mpzTest); mpz_set_si(mpzTest, 5); mpz_fdiv_qr_ui(mpzTest, mpzRemainder, mpzTest, 2); - std::cerr << "mpz_tdiv_qr_ui 5/2=" << mpz_get_si(mpzTest); + std::cerr << " mpz_tdiv_qr_ui 5/2=" << mpz_get_si(mpzTest); mpz_set_si(mpzTest, -5); mpz_cdiv_qr_ui(mpzTest, mpzRemainder, mpzTest, 2); - std::cerr << "mpz_cdiv_qr_ui -5/2=" << mpz_get_si(mpzTest); + std::cerr << " mpz_cdiv_qr_ui -5/2=" << mpz_get_si(mpzTest); mpz_set_si(mpzTest, -5); mpz_tdiv_qr_ui(mpzTest, mpzRemainder, mpzTest, 2); - std::cerr << "mpz_tdiv_qr_ui -5/2=" << mpz_get_si(mpzTest); + std::cerr << " mpz_tdiv_qr_ui -5/2=" << mpz_get_si(mpzTest); mpz_set_si(mpzTest, -5); mpz_fdiv_qr_ui(mpzTest, mpzRemainder, mpzTest, 2); - std::cerr << "mpz_fdiv_qr_ui -5/2=" << mpz_get_si(mpzTest); + std::cerr << " mpz_fdiv_qr_ui -5/2=" << mpz_get_si(mpzTest); std::cerr << std::endl; + mpz_clear(mpzRemainder); + mpz_clear(mpzLeverage); + mpz_clear(mpzProfits); + mpz_clear(mpzCostbasis); + mpz_clear(mpzPrice); mpz_clear(mpzTest); } From fe0f7ed57917f6f10234f13bef5a86467e54ac6d Mon Sep 17 00:00:00 2001 From: dimxy Date: Tue, 30 Apr 2019 19:34:20 +0500 Subject: [PATCH 192/447] more test div --- src/cc/prices.cpp | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index b5eb19dd3..be1f5b897 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -856,7 +856,7 @@ int32_t prices_syntheticprofits(int64_t &costbasis, int32_t firstheight, int32_t mpz_set_si(mpzTest, 5); mpz_fdiv_qr_ui(mpzTest, mpzRemainder, mpzTest, 2); - std::cerr << " mpz_tdiv_qr_ui 5/2=" << mpz_get_si(mpzTest); + std::cerr << " mpz_fdiv_qr_ui 5/2=" << mpz_get_si(mpzTest); mpz_set_si(mpzTest, -5); mpz_cdiv_qr_ui(mpzTest, mpzRemainder, mpzTest, 2); @@ -869,6 +869,32 @@ int32_t prices_syntheticprofits(int64_t &costbasis, int32_t firstheight, int32_t mpz_set_si(mpzTest, -5); mpz_fdiv_qr_ui(mpzTest, mpzRemainder, mpzTest, 2); std::cerr << " mpz_fdiv_qr_ui -5/2=" << mpz_get_si(mpzTest); + + std::cerr << std::endl; + + mpz_set_si(mpzTest, 7); + mpz_cdiv_qr_ui(mpzTest, mpzRemainder, mpzTest, 3); + std::cerr << "mpz_cdiv_qr_ui 7/3=" << mpz_get_si(mpzTest); + + mpz_set_si(mpzTest, 7); + mpz_tdiv_qr_ui(mpzTest, mpzRemainder, mpzTest, 3); + std::cerr << " mpz_tdiv_qr_ui 7/3=" << mpz_get_si(mpzTest); + + mpz_set_si(mpzTest, 7); + mpz_fdiv_qr_ui(mpzTest, mpzRemainder, mpzTest, 3); + std::cerr << " mpz_fdiv_qr_ui 7/3=" << mpz_get_si(mpzTest); + + mpz_set_si(mpzTest, -7); + mpz_cdiv_qr_ui(mpzTest, mpzRemainder, mpzTest, 3); + std::cerr << " mpz_cdiv_qr_ui -7/3=" << mpz_get_si(mpzTest); + + mpz_set_si(mpzTest, -7); + mpz_tdiv_qr_ui(mpzTest, mpzRemainder, mpzTest, 3); + std::cerr << " mpz_tdiv_qr_ui -7/3=" << mpz_get_si(mpzTest); + + mpz_set_si(mpzTest, -7); + mpz_fdiv_qr_ui(mpzTest, mpzRemainder, mpzTest, 3); + std::cerr << " mpz_fdiv_qr_ui -7/3=" << mpz_get_si(mpzTest); std::cerr << std::endl; mpz_clear(mpzRemainder); From 802acc8c44d101b745c1c9f32595aab8152de29b Mon Sep 17 00:00:00 2001 From: dimxy Date: Tue, 30 Apr 2019 20:39:49 +0500 Subject: [PATCH 193/447] change ave costbasis to gmp --- src/cc/prices.cpp | 125 +++++++++++++++++++--------------------------- 1 file changed, 52 insertions(+), 73 deletions(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index be1f5b897..96bacc83b 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -841,68 +841,11 @@ int32_t prices_syntheticprofits(int64_t &costbasis, int32_t firstheight, int32_t profits = mpz_get_si(mpzProfits); - - - mpz_t mpzTest; - mpz_init(mpzTest); - - mpz_set_si(mpzTest, 5); - mpz_cdiv_qr_ui(mpzTest, mpzRemainder, mpzTest, 2); - std::cerr << "mpz_cdiv_qr_ui 5/2=" << mpz_get_si(mpzTest); - - mpz_set_si(mpzTest, 5); - mpz_tdiv_qr_ui(mpzTest, mpzRemainder, mpzTest, 2); - std::cerr << " mpz_tdiv_qr_ui 5/2=" << mpz_get_si(mpzTest); - - mpz_set_si(mpzTest, 5); - mpz_fdiv_qr_ui(mpzTest, mpzRemainder, mpzTest, 2); - std::cerr << " mpz_fdiv_qr_ui 5/2=" << mpz_get_si(mpzTest); - - mpz_set_si(mpzTest, -5); - mpz_cdiv_qr_ui(mpzTest, mpzRemainder, mpzTest, 2); - std::cerr << " mpz_cdiv_qr_ui -5/2=" << mpz_get_si(mpzTest); - - mpz_set_si(mpzTest, -5); - mpz_tdiv_qr_ui(mpzTest, mpzRemainder, mpzTest, 2); - std::cerr << " mpz_tdiv_qr_ui -5/2=" << mpz_get_si(mpzTest); - - mpz_set_si(mpzTest, -5); - mpz_fdiv_qr_ui(mpzTest, mpzRemainder, mpzTest, 2); - std::cerr << " mpz_fdiv_qr_ui -5/2=" << mpz_get_si(mpzTest); - - std::cerr << std::endl; - - mpz_set_si(mpzTest, 7); - mpz_cdiv_qr_ui(mpzTest, mpzRemainder, mpzTest, 3); - std::cerr << "mpz_cdiv_qr_ui 7/3=" << mpz_get_si(mpzTest); - - mpz_set_si(mpzTest, 7); - mpz_tdiv_qr_ui(mpzTest, mpzRemainder, mpzTest, 3); - std::cerr << " mpz_tdiv_qr_ui 7/3=" << mpz_get_si(mpzTest); - - mpz_set_si(mpzTest, 7); - mpz_fdiv_qr_ui(mpzTest, mpzRemainder, mpzTest, 3); - std::cerr << " mpz_fdiv_qr_ui 7/3=" << mpz_get_si(mpzTest); - - mpz_set_si(mpzTest, -7); - mpz_cdiv_qr_ui(mpzTest, mpzRemainder, mpzTest, 3); - std::cerr << " mpz_cdiv_qr_ui -7/3=" << mpz_get_si(mpzTest); - - mpz_set_si(mpzTest, -7); - mpz_tdiv_qr_ui(mpzTest, mpzRemainder, mpzTest, 3); - std::cerr << " mpz_tdiv_qr_ui -7/3=" << mpz_get_si(mpzTest); - - mpz_set_si(mpzTest, -7); - mpz_fdiv_qr_ui(mpzTest, mpzRemainder, mpzTest, 3); - std::cerr << " mpz_fdiv_qr_ui -7/3=" << mpz_get_si(mpzTest); - std::cerr << std::endl; - mpz_clear(mpzRemainder); mpz_clear(mpzLeverage); mpz_clear(mpzProfits); mpz_clear(mpzCostbasis); mpz_clear(mpzPrice); - mpz_clear(mpzTest); } else @@ -1434,34 +1377,66 @@ UniValue PricesInfo(uint256 bettxid, int32_t refheight) result.push_back(Pair("error", "error scanning chain")); return(result); } - + + mpz_t mpzTotalbets; + mpz_t mpzTotalprofits; + mpz_t mpzTotalcostbasis; + + mpz_init(mpzTotalbets); + mpz_init(mpzTotalprofits); + mpz_init(mpzTotalcostbasis); + + int64_t totalbets = 0; int64_t totalprofits = 0; double dcostbasis = 0.0; + + for (auto b : bets) { - totalbets += b.amount; - totalprofits += b.profits; - dcostbasis += b.amount * (double)b.costbasis; + mpz_t mpzProduct; + mpz_t mpzProfits; + + mpz_init(mpzProduct); + mpz_init(mpzProfits); + + //totalprofits += b.profits; + //dcostbasis += b.amount * (double)b.costbasis; // costbasis += b.amount * (b.costbasis / PRICES_POINTFACTOR); // prevent int64 overflow (but we have underflow for 1/BTC) - std::cerr << "PricesInfo() acc dcostbasis=" << dcostbasis << " b.amount=" << b.amount << " b.costbasis/PRICES_POINTFACTOR=" << (b.costbasis / PRICES_POINTFACTOR) << std::endl; + // std::cerr << "PricesInfo() acc dcostbasis=" << dcostbasis << " b.amount=" << b.amount << " b.costbasis/PRICES_POINTFACTOR=" << (b.costbasis / PRICES_POINTFACTOR) << std::endl; + //std::cerr << "PricesInfo() acc dcostbasis=" << dcostbasis << " b.amount=" << b.amount << " b.costbasis/PRICES_POINTFACTOR=" << (b.costbasis / PRICES_POINTFACTOR) << std::endl; + mpz_set_ui(mpzProduct, b.costbasis); + mpz_mul_ui(mpzProduct, mpzProduct, (uint64_t)b.amount); // b.costbasis * b.amount + mpz_add(mpzTotalcostbasis, mpzTotalcostbasis, mpzProduct); //averageCostbasis += b.costbasis * b.amount; + + mpz_add_ui(mpzTotalbets, mpzTotalbets, (uint64_t)b.amount); //totalbets += b.amount; + mpz_add(mpzTotalprofits, mpzTotalprofits, mpzProfits); //totalprofits += b.profits; + + mpz_clear(mpzProduct); + mpz_clear(mpzProfits); } int64_t equity = totalbets + totalprofits; - int64_t costbasis; + int64_t averageCostbasis = 0; + if (totalbets != 0) { //prevent zero div // costbasis *= PRICES_POINTFACTOR; // save last 0.0000xxxx positions - costbasis = (int64_t) (dcostbasis / (double)totalbets); + //costbasis = (int64_t) (dcostbasis / (double)totalbets); + mpz_t mpzAverageCostbasis; + + mpz_init(mpzAverageCostbasis); + mpz_mul_ui(mpzTotalcostbasis, mpzTotalcostbasis, SATOSHIDEN); // normalization to prevent loss while div + mpz_tdiv_q(mpzAverageCostbasis, mpzTotalcostbasis, mpzTotalbets); // profits /= SATOSHIDEN // de-normalization + + mpz_tdiv_q_ui(mpzAverageCostbasis, mpzAverageCostbasis, SATOSHIDEN); // profits /= SATOSHIDEN // de-normalization + + averageCostbasis = mpz_get_ui(mpzAverageCostbasis); + mpz_clear(mpzAverageCostbasis); } - else - costbasis = 0; - int64_t liqprice; + + int64_t liqprice = 0; if (leverage != 0) {// prevent zero div - liqprice = costbasis - costbasis / leverage; - //liqprice /= PRICES_POINTFACTOR; - //liqprice *= PRICES_POINTFACTOR; // last posiitons should be == 0000 + liqprice = averageCostbasis - averageCostbasis / leverage; } - else - liqprice = 0; if (equity >= 0) result.push_back(Pair("rekt", 0)); @@ -1473,7 +1448,7 @@ UniValue PricesInfo(uint256 bettxid, int32_t refheight) } result.push_back(Pair("batontxid", batontxid.GetHex())); - result.push_back(Pair("costbasis", ValueFromAmount(costbasis))); + result.push_back(Pair("costbasis", ValueFromAmount(averageCostbasis))); prices_betjson(result, bets, leverage, endheight, lastprice); @@ -1483,6 +1458,10 @@ UniValue PricesInfo(uint256 bettxid, int32_t refheight) //#ifdef TESTMODE // result.push_back(Pair("test_daywindow", PRICES_DAYWINDOW)); //#endif + + mpz_clear(mpzTotalbets); + mpz_clear(mpzTotalprofits); + mpz_clear(mpzTotalcostbasis); return(result); } } From dba71a325e325c60d56f39fece6025236dfca193 Mon Sep 17 00:00:00 2001 From: dimxy Date: Tue, 30 Apr 2019 21:07:56 +0500 Subject: [PATCH 194/447] corr ave costbasis --- src/cc/prices.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 96bacc83b..229723fc3 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -1411,6 +1411,9 @@ UniValue PricesInfo(uint256 bettxid, int32_t refheight) mpz_add_ui(mpzTotalbets, mpzTotalbets, (uint64_t)b.amount); //totalbets += b.amount; mpz_add(mpzTotalprofits, mpzTotalprofits, mpzProfits); //totalprofits += b.profits; + totalbets += b.amount; + totalprofits += b.profits; + mpz_clear(mpzProduct); mpz_clear(mpzProfits); } @@ -1418,7 +1421,7 @@ UniValue PricesInfo(uint256 bettxid, int32_t refheight) int64_t equity = totalbets + totalprofits; int64_t averageCostbasis = 0; - if (totalbets != 0) { //prevent zero div + if (mpz_get_ui(mpzTotalbets) != 0) { //prevent zero div // costbasis *= PRICES_POINTFACTOR; // save last 0.0000xxxx positions //costbasis = (int64_t) (dcostbasis / (double)totalbets); mpz_t mpzAverageCostbasis; From bd2f5a6d41cf87e44f0677b76767eb09ea6b7604 Mon Sep 17 00:00:00 2001 From: dimxy Date: Wed, 1 May 2019 00:47:29 +0500 Subject: [PATCH 195/447] corr costbasis calc (prices norm) --- src/cc/prices.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 229723fc3..ce098146d 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -828,15 +828,16 @@ int32_t prices_syntheticprofits(int64_t &costbasis, int32_t firstheight, int32_t mpz_init(mpzRemainder); mpz_set_ui(mpzCostbasis, costbasis); - mpz_mul_ui(mpzCostbasis, mpzCostbasis, SATOSHIDEN); mpz_set_ui(mpzPrice, price); + mpz_mul_ui(mpzPrice, mpzPrice, SATOSHIDEN); // (price*SATOSHIDEN) + mpz_set_si(mpzLeverage, leverage); mpz_tdiv_qr(mpzProfits, mpzRemainder, mpzPrice, mpzCostbasis); // profits = (price*SATOSHIDEN)/costbasis // normalization - mpz_sub_ui(mpzProfits, mpzProfits, SATOSHIDEN); // profits -= SATOSHIDEN + mpz_sub_ui(mpzProfits, mpzProfits, SATOSHIDEN); // profits -= SATOSHIDEN - mpz_mul(mpzProfits, mpzProfits, mpzLeverage); // profits *= leverage - mpz_mul_ui(mpzProfits, mpzProfits, positionsize); // profits *= positionsize + mpz_mul(mpzProfits, mpzProfits, mpzLeverage); // profits *= leverage + mpz_mul_ui(mpzProfits, mpzProfits, positionsize); // profits *= positionsize mpz_tdiv_qr_ui(mpzProfits, mpzRemainder, mpzPrice, SATOSHIDEN); // profits /= SATOSHIDEN // de-normalization profits = mpz_get_si(mpzProfits); From c6dab1decac596f66a974c01044524a751a352bb Mon Sep 17 00:00:00 2001 From: dimxy Date: Wed, 1 May 2019 01:01:22 +0500 Subject: [PATCH 196/447] corr costbasis gmp calc (incorrect prices op) --- src/cc/prices.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index ce098146d..cc8340fb4 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -831,14 +831,13 @@ int32_t prices_syntheticprofits(int64_t &costbasis, int32_t firstheight, int32_t mpz_set_ui(mpzPrice, price); mpz_mul_ui(mpzPrice, mpzPrice, SATOSHIDEN); // (price*SATOSHIDEN) - mpz_set_si(mpzLeverage, leverage); - mpz_tdiv_qr(mpzProfits, mpzRemainder, mpzPrice, mpzCostbasis); // profits = (price*SATOSHIDEN)/costbasis // normalization mpz_sub_ui(mpzProfits, mpzProfits, SATOSHIDEN); // profits -= SATOSHIDEN + mpz_set_si(mpzLeverage, leverage); mpz_mul(mpzProfits, mpzProfits, mpzLeverage); // profits *= leverage mpz_mul_ui(mpzProfits, mpzProfits, positionsize); // profits *= positionsize - mpz_tdiv_qr_ui(mpzProfits, mpzRemainder, mpzPrice, SATOSHIDEN); // profits /= SATOSHIDEN // de-normalization + mpz_tdiv_qr_ui(mpzProfits, mpzRemainder, mpzProfits, SATOSHIDEN); // profits /= SATOSHIDEN // de-normalization profits = mpz_get_si(mpzProfits); From 7d7f0a08e4b804465d11faa0e785a8f0e68b5357 Mon Sep 17 00:00:00 2001 From: dimxy Date: Wed, 1 May 2019 12:30:41 +0500 Subject: [PATCH 197/447] added gmp for prices_syntheticprice --- src/cc/prices.cpp | 125 ++++++++++++++++++++++++++++++++++++---------- 1 file changed, 99 insertions(+), 26 deletions(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index cc8340fb4..8ab0d1875 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -592,6 +592,13 @@ int64_t prices_syntheticprice(std::vector vec, int32_t height, int32_t uint16_t opcode; int64_t *pricedata, pricestack[4], price, den, a, b, c; + mpz_t mpzA, mpzB, mpzC, mpzResult; + + mpz_init(mpzA); + mpz_init(mpzB); + mpz_init(mpzC); + mpz_init(mpzResult); + pricedata = (int64_t *)calloc(sizeof(*pricedata) * 3, 1 + PRICES_DAYWINDOW * 2 + PRICES_SMOOTHWIDTH); price = den = depth = errcode = 0; @@ -599,7 +606,10 @@ int64_t prices_syntheticprice(std::vector vec, int32_t height, int32_t { opcode = vec[i]; value = (opcode & (KOMODO_MAXPRICES - 1)); // index or weight - std::cerr << "prices_syntheticprice" << " i=" << i << " price=" << price << " value=" << value << " depth=" << depth << std::endl; + + mpz_set_ui(mpzResult, 0); // clear result to test overflow (see below) + + std::cerr << "prices_syntheticprice" << " i=" << i << " price=" << price << " value=" << value << " depth=" << depth << " opcode&KOMODO_PRICEMASK=" << (opcode & KOMODO_PRICEMASK) < vec, int32_t height, int32_t errcode = -2; break; - case PRICES_MULT: + case PRICES_MULT: // "*" if (depth >= 2) { b = pricestack[--depth]; a = pricestack[--depth]; - pricestack[depth++] = (a * b) / PRICES_NORMFACTOR; + // pricestack[depth++] = (a * b) / SATOSHIDEN; + mpz_set_si(mpzA, a); + mpz_set_si(mpzB, b); + mpz_mul(mpzResult, mpzA, mpzB); + mpz_tdiv_q_ui(mpzResult, mpzResult, SATOSHIDEN); + pricestack[depth++] = mpz_get_si(mpzResult); + } else errcode = -3; break; - case PRICES_DIV: + case PRICES_DIV: // "/" if (depth >= 2) { b = pricestack[--depth]; a = pricestack[--depth]; - pricestack[depth++] = (a * PRICES_NORMFACTOR) / b; + // pricestack[depth++] = (a * SATOSHIDEN) / b; + mpz_set_si(mpzA, a); + mpz_set_si(mpzB, b); + mpz_mul_ui(mpzResult, mpzA, SATOSHIDEN); + mpz_tdiv_q(mpzResult, mpzResult, mpzB); + pricestack[depth++] = mpz_get_si(mpzResult); } else errcode = -4; break; - case PRICES_INV: + case PRICES_INV: // "1/price" if (depth >= 1) { a = pricestack[--depth]; - pricestack[depth++] = (PRICES_NORMFACTOR * PRICES_NORMFACTOR) / a; + // pricestack[depth++] = (SATOSHIDEN * SATOSHIDEN) / a; + mpz_set_si(mpzA, a); + mpz_set_ui(mpzResult, SATOSHIDEN); + mpz_mul_ui(mpzResult, mpzResult, SATOSHIDEN); + mpz_tdiv_q(mpzResult, mpzResult, mpzA); + pricestack[depth++] = mpz_get_si(mpzResult); } else errcode = -5; break; - case PRICES_MDD: + case PRICES_MDD: // "*//" if (depth >= 3) { c = pricestack[--depth]; b = pricestack[--depth]; a = pricestack[--depth]; - pricestack[depth++] = (((a * PRICES_NORMFACTOR) / b) * PRICES_NORMFACTOR) / c; + // pricestack[depth++] = (((a * SATOSHIDEN) / b) * SATOSHIDEN) / c; + mpz_set_si(mpzA, a); + mpz_set_si(mpzB, b); + mpz_set_si(mpzC, c); + mpz_mul_ui(mpzResult, mpzA, SATOSHIDEN); + mpz_tdiv_q(mpzResult, mpzResult, mpzB); + mpz_mul_ui(mpzResult, mpzA, SATOSHIDEN); + mpz_tdiv_q(mpzResult, mpzResult, mpzC); + pricestack[depth++] = mpz_get_si(mpzResult); } else errcode = -6; break; - case PRICES_MMD: + case PRICES_MMD: // "**/" if (depth >= 3) { c = pricestack[--depth]; b = pricestack[--depth]; a = pricestack[--depth]; - pricestack[depth++] = (a * b) / c; + // pricestack[depth++] = (a * b) / c; + mpz_set_si(mpzA, a); + mpz_set_si(mpzB, b); + mpz_set_si(mpzC, c); + mpz_mul(mpzResult, mpzA, mpzB); + mpz_tdiv_q(mpzResult, mpzResult, mpzC); + pricestack[depth++] = mpz_get_si(mpzResult); } else errcode = -7; break; - case PRICES_MMM: + case PRICES_MMM: // "***" if (depth >= 3) { c = pricestack[--depth]; b = pricestack[--depth]; a = pricestack[--depth]; - pricestack[depth++] = ((a * b) / PRICES_NORMFACTOR) * c; + // pricestack[depth++] = ((a * b) / SATOSHIDEN) * c; + mpz_set_si(mpzA, a); + mpz_set_si(mpzB, b); + mpz_set_si(mpzC, c); + mpz_mul(mpzResult, mpzA, mpzB); + mpz_tdiv_q_ui(mpzResult, mpzResult, SATOSHIDEN); + mpz_mul(mpzResult, mpzResult, mpzC); + pricestack[depth++] = mpz_get_si(mpzResult); } else errcode = -8; break; - - case PRICES_DDD: + + case PRICES_DDD: // "///" if (depth >= 3) { c = pricestack[--depth]; b = pricestack[--depth]; a = pricestack[--depth]; - pricestack[depth++] = (((((PRICES_NORMFACTOR * PRICES_NORMFACTOR) / a) * PRICES_NORMFACTOR) / b) * PRICES_NORMFACTOR) / c; + //pricestack[depth++] = (((((SATOSHIDEN * SATOSHIDEN) / a) * SATOSHIDEN) / b) * SATOSHIDEN) / c; + mpz_set_si(mpzA, a); + mpz_set_si(mpzB, b); + mpz_set_si(mpzC, c); + mpz_set_ui(mpzResult, SATOSHIDEN); + mpz_mul_ui(mpzResult, mpzResult, SATOSHIDEN); + mpz_tdiv_q(mpzResult, mpzResult, mpzA); + mpz_mul_ui(mpzResult, mpzResult, SATOSHIDEN); + mpz_tdiv_q(mpzResult, mpzResult, mpzB); + mpz_mul_ui(mpzResult, mpzResult, SATOSHIDEN); + mpz_tdiv_q(mpzResult, mpzResult, mpzC); + pricestack[depth++] = mpz_get_si(mpzResult); } else errcode = -9; @@ -716,19 +774,36 @@ int64_t prices_syntheticprice(std::vector vec, int32_t height, int32_t errcode = -10; break; } + + std::cerr << "prices_syntheticprice test mpzResult=" << mpz_get_si(mpzResult) << std::endl; + // check overflow: + if (mpz_cmp_si(mpzResult, std::numeric_limits::max()) > 0) { + errcode = -13; + break; + } + if (errcode != 0) break; if( depth > 0 ) - std::cerr << "top pricestack[depth-1=" << depth-1 << "]=" << pricestack[depth-1] << std::endl; + std::cerr << "prices_syntheticprice top pricestack[depth-1=" << depth-1 << "]=" << pricestack[depth-1] << std::endl; else - std::cerr << "pricestack empty" << std::endl; + std::cerr << "prices_syntheticprice pricestack empty" << std::endl; } free(pricedata); + mpz_clear(mpzResult); + mpz_clear(mpzA); + mpz_clear(mpzB); + mpz_clear(mpzC); if (errcode != 0) - std::cerr << "prices_syntheticprice warning: errcode in switch=" << errcode << std::endl; + std::cerr << "prices_syntheticprice errcode in switch=" << errcode << std::endl; + + if (errcode == -13) { + std::cerr << "prices_syntheticprice overflow in price" << std::endl; + return errcode; + } if (den == 0) { std::cerr << "prices_syntheticprice den==0 return err=-11" << std::endl; @@ -819,29 +894,26 @@ int32_t prices_syntheticprofits(int64_t &costbasis, int32_t firstheight, int32_t mpz_t mpzCostbasis; mpz_t mpzPrice; mpz_t mpzLeverage; - mpz_t mpzRemainder; mpz_init(mpzProfits); mpz_init(mpzCostbasis); mpz_init(mpzPrice); mpz_init(mpzLeverage); - mpz_init(mpzRemainder); - mpz_set_ui(mpzCostbasis, costbasis); - mpz_set_ui(mpzPrice, price); + mpz_set_si(mpzCostbasis, costbasis); + mpz_set_si(mpzPrice, price); mpz_mul_ui(mpzPrice, mpzPrice, SATOSHIDEN); // (price*SATOSHIDEN) - mpz_tdiv_qr(mpzProfits, mpzRemainder, mpzPrice, mpzCostbasis); // profits = (price*SATOSHIDEN)/costbasis // normalization + mpz_tdiv_q(mpzProfits, mpzPrice, mpzCostbasis); // profits = (price*SATOSHIDEN)/costbasis // normalization mpz_sub_ui(mpzProfits, mpzProfits, SATOSHIDEN); // profits -= SATOSHIDEN mpz_set_si(mpzLeverage, leverage); mpz_mul(mpzProfits, mpzProfits, mpzLeverage); // profits *= leverage mpz_mul_ui(mpzProfits, mpzProfits, positionsize); // profits *= positionsize - mpz_tdiv_qr_ui(mpzProfits, mpzRemainder, mpzProfits, SATOSHIDEN); // profits /= SATOSHIDEN // de-normalization + mpz_tdiv_q_ui(mpzProfits, mpzProfits, SATOSHIDEN); // profits /= SATOSHIDEN // de-normalization profits = mpz_get_si(mpzProfits); - mpz_clear(mpzRemainder); mpz_clear(mpzLeverage); mpz_clear(mpzProfits); mpz_clear(mpzCostbasis); @@ -988,6 +1060,7 @@ UniValue PricesBet(int64_t txfee, int64_t amount, int16_t leverage, std::vector< //GetCCaddress(cp, myaddr, mypk); if (prices_syntheticvec(vec, synthetic) < 0 || (firstprice = prices_syntheticprice(vec, nextheight - 1, 1, leverage)) < 0 || vec.size() == 0 || vec.size() > 4096) { + std::cerr << "PricesBet() firstprice=" << firstprice << (firstprice < 0 ? "error or overflow" : "") << std::endl; result.push_back(Pair("result", "error")); result.push_back(Pair("error", "invalid synthetic")); return(result); From 7a3858ab6edca8da140db94072a5002967b0a9da Mon Sep 17 00:00:00 2001 From: dimxy Date: Wed, 1 May 2019 19:37:20 +0500 Subject: [PATCH 198/447] added getting source exp --- src/cc/prices.cpp | 79 +++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 70 insertions(+), 9 deletions(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 8ab0d1875..965c88e80 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -525,6 +525,69 @@ UniValue prices_rawtxresult(UniValue &result, std::string rawtx, int32_t broadca return(result); } +std::string prices_getsourceexpression(std::vector &vec) { + + std::string exp; + + for (int32_t i = 0; i < vec.size(); i++) + { + char name[65]; + std::string operand; + uint16_t opcode = vec[i]; + int32_t value = (opcode & (KOMODO_MAXPRICES - 1)); // index or weight + + switch (opcode & KOMODO_PRICEMASK) + { + case 0: // indices + komodo_pricename(name, value); + operand = std::string(name); + break; + + case PRICES_WEIGHT: // multiply by weight and consume top of stack by updating price + operand = std::to_string(value); + break; + + case PRICES_MULT: // "*" + operand = std::string("*"); + break; + + case PRICES_DIV: // "/" + operand = std::string("/"); + break; + + case PRICES_INV: // "1/price" + operand = std::string("!"); + break; + + case PRICES_MDD: // "*//" + operand = std::string("*//"); + break; + + case PRICES_MMD: // "**/" + operand = std::string("**/"); + break; + + case PRICES_MMM: // "***" + operand = std::string("***"); + break; + + case PRICES_DDD: // "///" + operand = std::string("///"); + break; + + default: + return "invalid opcode"; + break; + } + + if (exp.size() > 0) + exp += std::string(", "); + exp += operand; + } + return exp; +} + + int32_t prices_syntheticvec(std::vector &vec, std::vector synthetic) { int32_t i, need, ind, depth = 0; std::string opstr; uint16_t opcode, weight; @@ -1462,8 +1525,6 @@ UniValue PricesInfo(uint256 bettxid, int32_t refheight) int64_t totalbets = 0; int64_t totalprofits = 0; - double dcostbasis = 0.0; - for (auto b : bets) { mpz_t mpzProduct; @@ -1495,15 +1556,14 @@ UniValue PricesInfo(uint256 bettxid, int32_t refheight) int64_t averageCostbasis = 0; if (mpz_get_ui(mpzTotalbets) != 0) { //prevent zero div - // costbasis *= PRICES_POINTFACTOR; // save last 0.0000xxxx positions - //costbasis = (int64_t) (dcostbasis / (double)totalbets); mpz_t mpzAverageCostbasis; - mpz_init(mpzAverageCostbasis); - mpz_mul_ui(mpzTotalcostbasis, mpzTotalcostbasis, SATOSHIDEN); // normalization to prevent loss while div - mpz_tdiv_q(mpzAverageCostbasis, mpzTotalcostbasis, mpzTotalbets); // profits /= SATOSHIDEN // de-normalization - mpz_tdiv_q_ui(mpzAverageCostbasis, mpzAverageCostbasis, SATOSHIDEN); // profits /= SATOSHIDEN // de-normalization + //averageCostbasis = totalcostbasis / totalbets; + mpz_mul_ui(mpzTotalcostbasis, mpzTotalcostbasis, SATOSHIDEN); // profits *= SATOSHIDEN normalization to prevent loss of significance while division + mpz_tdiv_q(mpzAverageCostbasis, mpzTotalcostbasis, mpzTotalbets); + + mpz_tdiv_q_ui(mpzAverageCostbasis, mpzAverageCostbasis, SATOSHIDEN); // profits /= SATOSHIDEN de-normalization averageCostbasis = mpz_get_ui(mpzAverageCostbasis); mpz_clear(mpzAverageCostbasis); @@ -1522,7 +1582,8 @@ UniValue PricesInfo(uint256 bettxid, int32_t refheight) result.push_back(Pair("rektfee", totalbets / 500)); result.push_back(Pair("rektheight", (int64_t)endheight)); } - + + result.push_back(Pair("expression", prices_getsourceexpression(vec))); result.push_back(Pair("batontxid", batontxid.GetHex())); result.push_back(Pair("costbasis", ValueFromAmount(averageCostbasis))); From e587d489c956766c2d9e801175a2f4b30b9e167b Mon Sep 17 00:00:00 2001 From: dimxy Date: Thu, 2 May 2019 11:37:53 +0500 Subject: [PATCH 199/447] corr *// and *** price calc --- src/cc/prices.cpp | 90 +++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 76 insertions(+), 14 deletions(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 965c88e80..5fccd8774 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -525,9 +525,9 @@ UniValue prices_rawtxresult(UniValue &result, std::string rawtx, int32_t broadca return(result); } -std::string prices_getsourceexpression(std::vector &vec) { +static std::string prices_getsourceexpression(const std::vector &vec) { - std::string exp; + std::string expr; for (int32_t i = 0; i < vec.size(); i++) { @@ -555,7 +555,7 @@ std::string prices_getsourceexpression(std::vector &vec) { operand = std::string("/"); break; - case PRICES_INV: // "1/price" + case PRICES_INV: // "!" operand = std::string("!"); break; @@ -580,13 +580,75 @@ std::string prices_getsourceexpression(std::vector &vec) { break; } - if (exp.size() > 0) - exp += std::string(", "); - exp += operand; + if (expr.size() > 0) + expr += std::string(", "); + expr += operand; } - return exp; + return expr; } +static void prices_splitpair(const std::string &pair, std::string &upperquote, std::string &bottomquote) +{ + size_t pos = pair.find('_'); // like BTC_USD + if (pos != std::string::npos) { + upperquote = pair.substr(0, pos); + bottomquote = pair.substr(pos); + } + else { + upperquote = pair; + bottomquote = ""; + } +} + +// search for an upper or bottom quote in the vectored expression, remove it from the vector with its weight and with operation correction +static bool prices_tryextractpair(const std::vector &vexpr, size_t istart, const std::string "e, bool isSearchUpper, std::string &foundpair, int32_t &weight) { + +/* for (size_t i = istart; i < vexpr.size(); i++) { + if (komodo_priceind(vexpr[i].c_str()) >= 0) { + std::string upperquote, bottomquote; + prices_splitpair(vexpr[i], upperquote, bottomquote); + + if (quote == upperquote) { + if( ) + + } + + + } + }*/ + return true; +} + +// try to reduce synthetic expression by substituting "BTC_USD, 20, BTC_EUR, 30, *" with "EUR_USD, 30/20" +static std::string prices_reduceexp(const std::vector &vec) +{ + std::string reduced; + + + return reduced; +/* + std::vector vexpr; + SplitStr(expr, vexpr); + + for (size_t i = 0; i < vexpr.size(); i ++) { + if (komodo_priceind(vexpr[i].c_str()) >= 0) { + std::string upperquote, bottomquote; + std::string foundpair1, foundpair2; + int32_t weight1, weight2; + + prices_splitpair(vexpr[i], upperquote, bottomquote); + if (prices_tryextractpair(vexpr, i+1, upperquote, false, foundpair1, weight1)) { + + } + if (prices_tryextractpair(vexpr, i+1, bottomquote, true, foundpair2, weight2)) { + + } + } + } +*/ +} + + int32_t prices_syntheticvec(std::vector &vec, std::vector synthetic) { @@ -629,13 +691,13 @@ int32_t prices_syntheticvec(std::vector &vec, std::vector return(-3); } depth -= need; - std::cerr << "opcode=" << opcode << " opstr=" << opstr << " need=" << need << " depth=" << depth << std::endl; + std::cerr << "prices_syntheticvec() opcode=" << opcode << " opstr=" << opstr << " need=" << need << " depth=" << depth << std::endl; if ((opcode & KOMODO_PRICEMASK) != PRICES_WEIGHT) { // skip weight depth++; // increase operands count std::cerr << "depth++=" << depth << std::endl; } if (depth > 3) { - std::cerr << "prices_syntheticvec() to many operands, last=" << opstr << std::endl; + std::cerr << "prices_syntheticvec() too many operands, last=" << opstr << std::endl; return(-4); } vec.push_back(opcode); @@ -743,7 +805,7 @@ int64_t prices_syntheticprice(std::vector vec, int32_t height, int32_t errcode = -4; break; - case PRICES_INV: // "1/price" + case PRICES_INV: // "!" if (depth >= 1) { a = pricestack[--depth]; // pricestack[depth++] = (SATOSHIDEN * SATOSHIDEN) / a; @@ -768,7 +830,7 @@ int64_t prices_syntheticprice(std::vector vec, int32_t height, int32_t mpz_set_si(mpzC, c); mpz_mul_ui(mpzResult, mpzA, SATOSHIDEN); mpz_tdiv_q(mpzResult, mpzResult, mpzB); - mpz_mul_ui(mpzResult, mpzA, SATOSHIDEN); + mpz_mul_ui(mpzResult, mpzResult, SATOSHIDEN); mpz_tdiv_q(mpzResult, mpzResult, mpzC); pricestack[depth++] = mpz_get_si(mpzResult); } @@ -798,13 +860,14 @@ int64_t prices_syntheticprice(std::vector vec, int32_t height, int32_t c = pricestack[--depth]; b = pricestack[--depth]; a = pricestack[--depth]; - // pricestack[depth++] = ((a * b) / SATOSHIDEN) * c; + // pricestack[depth++] = (((a * b) / SATOSHIDEN ) * c) / SATOSHIDEN; mpz_set_si(mpzA, a); mpz_set_si(mpzB, b); mpz_set_si(mpzC, c); mpz_mul(mpzResult, mpzA, mpzB); mpz_tdiv_q_ui(mpzResult, mpzResult, SATOSHIDEN); mpz_mul(mpzResult, mpzResult, mpzC); + mpz_tdiv_q_ui(mpzResult, mpzResult, SATOSHIDEN); pricestack[depth++] = mpz_get_si(mpzResult); } else @@ -1104,7 +1167,7 @@ UniValue PricesBet(int64_t txfee, int64_t amount, int16_t leverage, std::vector< CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), nextheight); UniValue result(UniValue::VOBJ); struct CCcontract_info *cp, C; CPubKey pricespk, mypk; - int64_t betamount, firstprice; + int64_t betamount, firstprice = 0; std::vector vec; //char myaddr[64]; std::string rawtx; @@ -1123,7 +1186,6 @@ UniValue PricesBet(int64_t txfee, int64_t amount, int16_t leverage, std::vector< //GetCCaddress(cp, myaddr, mypk); if (prices_syntheticvec(vec, synthetic) < 0 || (firstprice = prices_syntheticprice(vec, nextheight - 1, 1, leverage)) < 0 || vec.size() == 0 || vec.size() > 4096) { - std::cerr << "PricesBet() firstprice=" << firstprice << (firstprice < 0 ? "error or overflow" : "") << std::endl; result.push_back(Pair("result", "error")); result.push_back(Pair("error", "invalid synthetic")); return(result); From 3ab22eb5ec79fa0a163f1128333cfdc84595d2d5 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Thu, 2 May 2019 16:07:27 +0800 Subject: [PATCH 200/447] add test chain exception. --- src/notaries_staked.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/notaries_staked.cpp b/src/notaries_staked.cpp index 0b7c97ceb..bb1518262 100644 --- a/src/notaries_staked.cpp +++ b/src/notaries_staked.cpp @@ -18,7 +18,7 @@ int8_t is_STAKED(const char *chain_name) if (doneinit == 1 && ASSETCHAINS_SYMBOL[0] != 0) return(STAKED); else STAKED = 0; - if ( (strcmp(chain_name, "LABS") == 0) || (strcmp(chain_name, "LABSTH") == 0) ) + if ( (strcmp(chain_name, "LABS") == 0) || (strcmp(chain_name, "LABSRCTEST") == 0) ) STAKED = 1; // These chains are allowed coin emissions. else if ( (strncmp(chain_name, "LABS", 4) == 0) ) STAKED = 2; // These chains have no coin emission, block subsidy is always 0, and comission is 0. Notary pay is allowed. From 8703305e7aa51801b165ca0358636634158059a5 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Thu, 2 May 2019 18:42:40 +0800 Subject: [PATCH 201/447] game commit --- src/cc/CCPayments.h | 1 + src/cc/payments.cpp | 341 +++++++++++++++++++++++++-------------- src/init.cpp | 13 ++ src/komodo_defs.h | 3 +- src/komodo_globals.h | 2 +- src/komodo_utils.h | 8 +- src/main.cpp | 16 +- src/miner.cpp | 6 +- src/wallet/rpcwallet.cpp | 2 +- 9 files changed, 250 insertions(+), 142 deletions(-) diff --git a/src/cc/CCPayments.h b/src/cc/CCPayments.h index cff304a2e..c45fbab9e 100644 --- a/src/cc/CCPayments.h +++ b/src/cc/CCPayments.h @@ -22,6 +22,7 @@ #define PAYMENTS_TXFEE 10000 extern std::vector > vAddressSnapshot; +extern int32_t lastSnapShotHeight; bool PaymentsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); diff --git a/src/cc/payments.cpp b/src/cc/payments.cpp index e72184719..7ab3e8202 100644 --- a/src/cc/payments.cpp +++ b/src/cc/payments.cpp @@ -16,27 +16,6 @@ #include "CCPayments.h" /* -192.168.0.139: RH side screen. - ./komodod -ac_name=TESTDP -ac_supply=10000000 -ac_reward=1000000000 -ac_nk=96,5 -ac_blocktime=20 -ac_cc=2 -addndoe=192.168.0.112 - - TESTDP.tar saved after distributing funds randomly. approx block 120. -LH screen: - ./komodod -ac_name=TESTDP -ac_supply=10000000 -ac_reward=1000000000 -ac_nk=96,5 -ac_blocktime=20 -ac_cc=2 -pubkey=0244a96824fa317433f0eaa6d5b1faf68e802b1958df273c24cb82bce1ef8e1aec -gen -genproclimit=1 - -./komodo-cli -ac_name=TESTDP paymentsairdrop '[10,2000,500,"76a9149758abb81ee168dd3824cb55e94df509b35462d788ac",76a9144cfd873dadbfbb4b9c03e77ecaa6cfb74a484f4888ac"]' - -use notarizations DB to scan back from the correct height, then undo ALL blocks back to this notarized height! -payments airdrop: - - extra RPC to merge all payments inputs to a single utxo, this must be called first and be confirmed before payments release, - or tx will be too big, we can check add payments inputs is only 1 input, at RPC and in validation very early on. - - do getsnapshot2 every 1440 blocks and save the result into some global sorted vector. - -this allows any address balance to be calculated by only iterating each 1439 blocks maximum. - - calculate scriptpubkey to pay from each address, set allocations from balance of each address. allocation = balance? - -payments airdrop paying a token: - - tokenid, top number of tokens to pay, list of pubkeys to exclude as optional param - - token airdrop code should be the same as normal snapshot, but call a diffrent snapshot function that only fetches the info for a specific tokenid given. - this should be fine to work in validation/rpc level rather than a global saved result, as a single token id doesnt require iterating the whole DB. - 0) txidopret <- allocation, scriptPubKey, opret 1) create <- locked_blocks, minrelease, list of txidopret @@ -138,6 +117,26 @@ uint8_t DecodePaymentsFundOpRet(CScript scriptPubKey,uint256 &checktxid) return(0); } +CScript EncodePaymentsMergeOpRet(uint256 checktxid) +{ + CScript opret; uint8_t evalcode = EVAL_PAYMENTS; + opret << OP_RETURN << E_MARSHAL(ss << evalcode << 'M' << checktxid); + return(opret); +} + +uint8_t DecodePaymentsMergeOpRet(CScript scriptPubKey,uint256 &checktxid) +{ + std::vector vopret; uint8_t *script,e,f; + GetOpReturnData(scriptPubKey, vopret); + script = (uint8_t *)vopret.data(); + if ( vopret.size() > 2 && E_UNMARSHAL(vopret,ss >> e; ss >> f; ss >> checktxid) != 0 ) + { + if ( e == EVAL_PAYMENTS && f == 'M' ) + return(f); + } + return(0); +} + CScript EncodePaymentsOpRet(int32_t lockedblocks,int32_t minrelease,int64_t totalallocations,std::vector txidoprets) { CScript opret; uint8_t evalcode = EVAL_PAYMENTS; @@ -158,20 +157,19 @@ uint8_t DecodePaymentsOpRet(CScript scriptPubKey,int32_t &lockedblocks,int32_t & return(0); } - -CScript EncodePaymentsSnapsShotOpRet(int32_t lockedblocks,int32_t minrelease,int32_t top,std::vector> excludeScriptPubKeys) +CScript EncodePaymentsSnapsShotOpRet(int32_t lockedblocks,int32_t minrelease,int32_t top,int32_t bottom,int8_t fixedAmount,std::vector> excludeScriptPubKeys) { CScript opret; uint8_t evalcode = EVAL_PAYMENTS; - opret << OP_RETURN << E_MARSHAL(ss << evalcode << 'S' << lockedblocks << minrelease << top << excludeScriptPubKeys); + opret << OP_RETURN << E_MARSHAL(ss << evalcode << 'S' << lockedblocks << minrelease << top << bottom << fixedAmount << excludeScriptPubKeys); return(opret); } -uint8_t DecodePaymentsSnapsShotOpRet(CScript scriptPubKey,int32_t &lockedblocks,int32_t &minrelease,int32_t &top,std::vector> &excludeScriptPubKeys) +uint8_t DecodePaymentsSnapsShotOpRet(CScript scriptPubKey,int32_t &lockedblocks,int32_t &minrelease,int32_t &top,int32_t &bottom,int8_t &fixedAmount,std::vector> &excludeScriptPubKeys) { std::vector vopret; uint8_t *script,e,f; GetOpReturnData(scriptPubKey, vopret); script = (uint8_t *)vopret.data(); - if ( vopret.size() > 2 && E_UNMARSHAL(vopret,ss >> e; ss >> f; ss >> lockedblocks; ss >> minrelease; ss >> top; ss >> excludeScriptPubKeys) != 0 ) + if ( vopret.size() > 2 && E_UNMARSHAL(vopret,ss >> e; ss >> f; ss >> lockedblocks; ss >> minrelease; ss >> top; ; ss >> bottom; ss >> fixedAmount; ss >> excludeScriptPubKeys) != 0 ) { if ( e == EVAL_PAYMENTS && f == 'S' ) return(f); @@ -233,9 +231,9 @@ bool PaymentsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction & // change is/must be in vout[0] // only 'F' or 1of2 txidaddr can be spent // all vouts must match exactly - char temp[128], coinaddr[64], txidaddr[64]; std::string scriptpubkey; uint256 createtxid, blockhash, tokenid; CTransaction plantx; uint8_t funcid = 0; + char temp[128], coinaddr[64], txidaddr[64]; std::string scriptpubkey; uint256 createtxid, blockhash, tokenid; CTransaction plantx; int8_t funcid=0, fixedAmount=0; int32_t i,lockedblocks,minrelease; int64_t change,totalallocations; std::vector txidoprets; bool fHasOpret = false; CPubKey txidpk,Paymentspk; - int32_t top; std::vector> excludeScriptPubKeys; + int32_t top,bottom=0; std::vector> excludeScriptPubKeys; bool fFixedAmount = false; mpz_t mpzTotalAllocations, mpzAllocation;; mpz_init(mpzTotalAllocations); // user marker vout to get the createtxid if ( tx.vout.size() < 2 ) @@ -253,9 +251,9 @@ bool PaymentsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction & // use the createtxid to fetch the tx and all of the plans info. if ( myGetTransaction(createtxid,plantx,blockhash) != 0 && plantx.vout.size() > 0 ) { - if ( ((funcid= DecodePaymentsOpRet(plantx.vout[plantx.vout.size()-1].scriptPubKey,lockedblocks,minrelease,totalallocations,txidoprets)) == 'C' || (funcid= DecodePaymentsSnapsShotOpRet(plantx.vout[plantx.vout.size()-1].scriptPubKey,lockedblocks,minrelease,top,excludeScriptPubKeys)) == 'S' || (funcid= DecodePaymentsTokensOpRet(plantx.vout[plantx.vout.size()-1].scriptPubKey,lockedblocks,minrelease,top,excludeScriptPubKeys,tokenid)) == 'O') ) + if ( ((funcid= DecodePaymentsOpRet(plantx.vout[plantx.vout.size()-1].scriptPubKey,lockedblocks,minrelease,totalallocations,txidoprets)) == 'C' || (funcid= DecodePaymentsSnapsShotOpRet(plantx.vout[plantx.vout.size()-1].scriptPubKey,lockedblocks,minrelease,top,bottom,fixedAmount,excludeScriptPubKeys)) == 'S' || (funcid= DecodePaymentsTokensOpRet(plantx.vout[plantx.vout.size()-1].scriptPubKey,lockedblocks,minrelease,top,excludeScriptPubKeys,tokenid)) == 'O') ) { - if ( lockedblocks < 0 || minrelease < 0 || totalallocations <= 0 ) + if ( lockedblocks < 0 || minrelease < 0 || (totalallocations <= 0 && top <= 0 ) ) return(eval->Invalid("negative values")); Paymentspk = GetUnspendable(cp,0); txidpk = CCtxidaddr(txidaddr,createtxid); @@ -301,32 +299,60 @@ bool PaymentsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction & } else if ( funcid == 'S' ) { + if ( KOMODO_SNAPSHOT_INTERVAL == 0 ) + return(eval->Invalid("snapshots not activated on this chain")); + if ( vAddressSnapshot.size() == 0 ) + return(eval->Invalid("need first snapshot")); // need time for TX to me mined before the next snapshot. - if ( top > 5000 ) + if ( top > 3999 ) return(eval->Invalid("transaction too big")); - for ( auto address : vAddressSnapshot ) + if ( fixedAmount == 7 ) { - CScript scriptPubKey = GetScriptForDestination(address.second); - for ( auto skipkey : excludeScriptPubKeys ) + // game setting, randomise bottom and top values + uint64_t x; + uint256 tmphash = chainActive[lastSnapShotHeight]->GetBlockHash(); + memcpy(&x,&tmphash,sizeof(x)); + bottom = ((x & 0xff) % 50); + if ( bottom == 0 ) bottom = 1; + top = (((x>>8) & 0xff) % 100); + if ( top < 50 ) top += 50; + bottom = (vAddressSnapshot.size()*bottom)/100; + top = (vAddressSnapshot.size()*top)/100; + fprintf(stderr, "bottom.%i top.%i\n",bottom,top); + fFixedAmount = true; + } + else if ( fixedAmount != 0 ) + { + fFixedAmount = true; + } + for (int32_t j = bottom; j < vAddressSnapshot.size(); j++) + { + auto &address = vAddressSnapshot[j]; + CScript scriptPubKey = GetScriptForDestination(address.second); bool skip = false; + for ( auto skipkey : excludeScriptPubKeys ) { - //fprintf(stderr, "scriptpubkey.%s\n skipkey.%s", HexStr(scriptPubKey).c_str(), HexStr(CScript(skipkey.begin(), skipkey.end())).c_str()); - if ( scriptPubKey != CScript(skipkey.begin(), skipkey.end()) ) + if ( scriptPubKey == CScript(skipkey.begin(), skipkey.end()) ) { - mpz_init(mpzAllocation); - i++; - scriptPubKeys.push_back(scriptPubKey); - allocations.push_back(address.first); - mpz_set_si(mpzAllocation,address.first); - mpz_add(mpzTotalAllocations,mpzTotalAllocations,mpzAllocation); - mpz_clear(mpzAllocation); - } + skip = true; + //fprintf(stderr, "SKIPPED::: %s\n", CBitcoinAddress(address.second).ToString().c_str()); + } } - if ( i == top ) // we reached top amount to pay, it can be less than this! + if ( !skip ) + { + mpz_init(mpzAllocation); + i++; + scriptPubKeys.push_back(scriptPubKey); + allocations.push_back(address.first); + mpz_set_si(mpzAllocation,address.first); + mpz_add(mpzTotalAllocations,mpzTotalAllocations,mpzAllocation); + mpz_clear(mpzAllocation); + } + if ( i+bottom == top ) // we reached top amount to pay, it can be less than this! break; } if ( i != tx.vout.size()-2 ) return(eval->Invalid("pays wrong amount of recipients")); - } + } else if ( funcid == 'O' ) { // tokens snapshot. @@ -355,12 +381,20 @@ bool PaymentsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction & fprintf(stderr, "pays wrong destination destscriptPubKey.%s voutscriptPubKey.%s\n", HexStr(scriptPubKeys[n].begin(),scriptPubKeys[n].end()).c_str(), HexStr(tx.vout[i].scriptPubKey.begin(),tx.vout[i].scriptPubKey.end()).c_str()); return(eval->Invalid("pays wrong address")); } - mpz_init(mpzAllocation); - mpz_set_si(mpzAllocation,allocations[n]); - mpz_mul(mpzAllocation,mpzAllocation,mpzCheckamount); - mpz_cdiv_q(mpzAllocation,mpzAllocation,mpzTotalAllocations); - int64_t test = mpz_get_si(mpzAllocation); - mpz_clear(mpzAllocation); + int64_t test; + if ( fFixedAmount ) + { + test = checkamount / (top-bottom); + } + else + { + mpz_init(mpzAllocation); + mpz_set_si(mpzAllocation,allocations[n]); + mpz_mul(mpzAllocation,mpzAllocation,mpzCheckamount); + mpz_cdiv_q(mpzAllocation,mpzAllocation,mpzTotalAllocations); + test = mpz_get_si(mpzAllocation); + mpz_clear(mpzAllocation); + } // Vairance of 1 sat is allowed, for rounding errors. if ( test >= tx.vout[i].nValue+1 && test <= tx.vout[i].nValue-1 ) { @@ -571,7 +605,7 @@ UniValue PaymentsRelease(struct CCcontract_info *cp,char *jsonstr) int32_t latestheight,nextheight = komodo_nextheight(); CMutableTransaction tmpmtx,mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(),nextheight); UniValue result(UniValue::VOBJ); uint256 createtxid,hashBlock,tokenid; CTransaction tx,txO; CPubKey mypk,txidpk,Paymentspk; int32_t i,n,m,numoprets=0,lockedblocks,minrelease; int64_t newamount,inputsum,amount,CCchange=0,totalallocations=0,checkallocations=0,allocation; CTxOut vout; CScript onlyopret; char txidaddr[64],destaddr[64]; std::vector txidoprets; - int32_t top; std::vector> excludeScriptPubKeys; int8_t funcid; + int32_t top,bottom=0; std::vector> excludeScriptPubKeys; int8_t funcid,fixedAmount=0; bool fFixedAmount = false; mpz_t mpzTotalAllocations; mpz_init(mpzTotalAllocations); cJSON *params = payments_reparse(&n,jsonstr); mypk = pubkey2pk(Mypubkey()); @@ -582,9 +616,9 @@ UniValue PaymentsRelease(struct CCcontract_info *cp,char *jsonstr) amount = jdouble(jitem(params,1),0) * SATOSHIDEN + 0.0000000049; if ( myGetTransaction(createtxid,tx,hashBlock) != 0 && tx.vout.size() > 0 ) { - if ( ((funcid= DecodePaymentsOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,lockedblocks,minrelease,totalallocations,txidoprets)) == 'C' || (funcid= DecodePaymentsSnapsShotOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,lockedblocks,minrelease,top,excludeScriptPubKeys)) == 'S' || (funcid= DecodePaymentsTokensOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,lockedblocks,minrelease,top,excludeScriptPubKeys,tokenid)) == 'O') ) + if ( ((funcid= DecodePaymentsOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,lockedblocks,minrelease,totalallocations,txidoprets)) == 'C' || (funcid= DecodePaymentsSnapsShotOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,lockedblocks,minrelease,top,bottom,fixedAmount,excludeScriptPubKeys)) == 'S' || (funcid= DecodePaymentsTokensOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,lockedblocks,minrelease,top,excludeScriptPubKeys,tokenid)) == 'O') ) { - if ( lockedblocks < 0 || minrelease < 0 || totalallocations <= 0 ) + if ( lockedblocks < 0 || minrelease < 0 || (totalallocations <= 0 && top <= 0 ) ) { result.push_back(Pair("result","error")); result.push_back(Pair("error","negative parameter")); @@ -605,7 +639,8 @@ UniValue PaymentsRelease(struct CCcontract_info *cp,char *jsonstr) } txidpk = CCtxidaddr(txidaddr,createtxid); mtx.vout.push_back(MakeCC1of2vout(EVAL_PAYMENTS,0,Paymentspk,txidpk)); - if ( funcid = 'C' ) + //fprintf(stderr, "funcid.%i\n", funcid); + if ( funcid == 'C' ) { // normal payments for (i=0; i 5000 ) + if ( vAddressSnapshot.size() == 0 ) { - // need to test the maximum number, this is an estimate. result.push_back(Pair("result","error")); - result.push_back(Pair("error","cannot pay more than 5000 addresses")); + result.push_back(Pair("error","first snapshot has not happened yet")); if ( params != 0 ) free_json(params); return(result); } - for ( auto address : vAddressSnapshot ) + if ( top > 3999 ) { - CScript scriptPubKey = GetScriptForDestination(address.second); - for ( auto skipkey : excludeScriptPubKeys ) + result.push_back(Pair("result","error")); + result.push_back(Pair("error","cannot pay more than 3999 addresses")); + if ( params != 0 ) + free_json(params); + return(result); + } + i = 0; + //for ( auto address : vAddressSnapshot ) + if ( fixedAmount == 7 ) + { + // game setting, randomise bottom and top values + uint64_t x; + uint256 tmphash = chainActive[lastSnapShotHeight]->GetBlockHash(); + memcpy(&x,&tmphash,sizeof(x)); + bottom = ((x & 0xff) % 50); + if ( bottom == 0 ) bottom = 1; + top = (((x>>8) & 0xff) % 100); + if ( top < 50 ) top += 50; + bottom = (vAddressSnapshot.size()*bottom)/100; + top = (vAddressSnapshot.size()*top)/100; + fprintf(stderr, "bottom.%i top.%i\n",bottom,top); + fFixedAmount = true; + } + else if ( fixedAmount != 0 ) + { + fFixedAmount = true; + } + for (int32_t j = bottom; j < vAddressSnapshot.size(); j++) + { + auto &address = vAddressSnapshot[j]; + CScript scriptPubKey = GetScriptForDestination(address.second); bool skip = false; + for ( auto skipkey : excludeScriptPubKeys ) { - if ( scriptPubKey != CScript(skipkey.begin(), skipkey.end()) ) + if ( scriptPubKey == CScript(skipkey.begin(), skipkey.end()) ) { - mpz_t mpzAllocation; mpz_init(mpzAllocation); - i++; - //fprintf(stderr, "address: %s nValue.%li \n", CBitcoinAddress(address.second).ToString().c_str(), address.first); - vout.nValue = address.first; - vout.scriptPubKey = scriptPubKey; - mpz_set_si(mpzAllocation,address.first); - mpz_add(mpzTotalAllocations,mpzTotalAllocations,mpzAllocation); //totalallocations += address.first; - mtx.vout.push_back(vout); - mpz_clear(mpzAllocation); - } else fprintf(stderr, "SKIPPED::: %s\n", CBitcoinAddress(address.second).ToString().c_str()); + skip = true; + //fprintf(stderr, "SKIPPED::: %s\n", CBitcoinAddress(address.second).ToString().c_str()); + } } - if ( i == top ) // we reached top amount to pay, it can be less than this! + if ( !skip ) + { + mpz_t mpzAllocation; mpz_init(mpzAllocation); + i++; + //fprintf(stderr, "address: %s nValue.%li \n", CBitcoinAddress(address.second).ToString().c_str(), address.first); + vout.nValue = address.first; + vout.scriptPubKey = scriptPubKey; + mpz_set_si(mpzAllocation,address.first); + mpz_add(mpzTotalAllocations,mpzTotalAllocations,mpzAllocation); + mtx.vout.push_back(vout); + mpz_clear(mpzAllocation); + } + if ( i+bottom == top ) // we reached top amount to pay, it can be less than this! break; } m = i; // this is the amount we got, either top, or all of the address on the chain. } - else if ( funcid = 'O' ) + else if ( funcid == 'O' ) { // token snapshot } newamount = amount; int64_t totalamountsent = 0; mpz_t mpzAmount; mpz_init(mpzAmount); mpz_set_si(mpzAmount,amount); + fprintf(stderr, "m.%i\n",m); for (i=0; i txidoprets; - int32_t top; std::vector> excludeScriptPubKeys; // snapshot - uint256 tokenid; + int32_t top,bottom; std::vector> excludeScriptPubKeys; // snapshot + uint256 tokenid; int8_t fixedAmount; cJSON *params = payments_reparse(&n,jsonstr); mypk = pubkey2pk(Mypubkey()); Paymentspk = GetUnspendable(cp,0); @@ -789,14 +869,14 @@ UniValue PaymentsFund(struct CCcontract_info *cp,char *jsonstr) amount = jdouble(jitem(params,1),0) * SATOSHIDEN + 0.0000000049; if ( n == 3 ) useopret = jint(jitem(params,2),0) != 0; - if ( myGetTransaction(txid,tx,hashBlock) == 0 || tx.vout.size() == 1 || (DecodePaymentsOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,lockedblocks,minrelease,totalallocations,txidoprets) == 0 && DecodePaymentsSnapsShotOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,lockedblocks,minrelease,top,excludeScriptPubKeys) == 0 && DecodePaymentsTokensOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,lockedblocks,minrelease,top,excludeScriptPubKeys,tokenid) == 0) ) + if ( myGetTransaction(txid,tx,hashBlock) == 0 || tx.vout.size() == 1 || (DecodePaymentsOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,lockedblocks,minrelease,totalallocations,txidoprets) == 0 && DecodePaymentsSnapsShotOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,lockedblocks,minrelease,top,bottom,fixedAmount,excludeScriptPubKeys) == 0 && DecodePaymentsTokensOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,lockedblocks,minrelease,top,excludeScriptPubKeys,tokenid) == 0) ) { result.push_back(Pair("result","error")); result.push_back(Pair("error","invalid createtxid")); } else if ( AddNormalinputs(mtx,mypk,amount+PAYMENTS_TXFEE,60) > 0 ) { - if ( lockedblocks < 0 || minrelease < 0 || totalallocations <= 0 ) + if ( lockedblocks < 0 || minrelease < 0 || (totalallocations <= 0 && top <= 0 ) ) { result.push_back(Pair("result","error")); result.push_back(Pair("error","negative parameter")); @@ -961,43 +1041,54 @@ UniValue PaymentsAirdrop(struct CCcontract_info *cp,char *jsonstr) CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); UniValue result(UniValue::VOBJ); uint256 hashBlock; CTransaction tx; CPubKey Paymentspk,mypk; char markeraddr[64]; std::string rawtx; - int32_t lockedblocks,minrelease,top,n,i; std::vector> excludeScriptPubKeys; + int32_t lockedblocks,minrelease,top,bottom,n,i; std::vector> excludeScriptPubKeys; int8_t fixedAmount; + if ( KOMODO_SNAPSHOT_INTERVAL == 0 ) + { + result.push_back(Pair("result","error")); + result.push_back(Pair("error","cannot use airdrop wihtout -ac_snapshot set.")); + return(result); + } cJSON *params = payments_reparse(&n,jsonstr); - if ( params != 0 && n >= 4 ) + if ( params != 0 && n >= 5 ) { lockedblocks = juint(jitem(params,0),0); minrelease = juint(jitem(params,1),0); top = juint(jitem(params,2),0); - if ( lockedblocks < 0 || minrelease < 0 || top < 0 ) + bottom = juint(jitem(params,3),0); + fixedAmount = juint(jitem(params,4),0); // fixed amount is a flag set to 0 or 1. It means allocations are equal rather than weighted by address balance. + if ( lockedblocks < 0 || minrelease < 0 || top <= 0 || bottom < 0 || fixedAmount < 0 || top > 3999 ) { result.push_back(Pair("result","error")); - result.push_back(Pair("error","negative parameter")); + result.push_back(Pair("error","negative parameter, or top over 3999")); if ( params != 0 ) free_json(params); return(result); } - for (i=0; i 5 ) { - /* TODO: Change this RPC to take an address. Because a tokens airdrop needs its own RPC anyway. - CTxDestination destination = DecodeDestination(name_); - CScript scriptPubKey = GetScriptForDestination(destination); - */ - char *inputhex = jstri(params,3+i); - std::vector scriptPubKey; - int32_t len = strlen(inputhex)/2; - scriptPubKey.resize(len); - decode_hex((uint8_t *)scriptPubKey.data(),len,(char *)inputhex); - excludeScriptPubKeys.push_back(scriptPubKey); + for (i=0; i scriptPubKey; + int32_t len = strlen(inputhex)/2; + scriptPubKey.resize(len); + decode_hex((uint8_t *)scriptPubKey.data(),len,(char *)inputhex); + excludeScriptPubKeys.push_back(scriptPubKey); + } } mypk = pubkey2pk(Mypubkey()); Paymentspk = GetUnspendable(cp,0); if ( AddNormalinputs(mtx,mypk,2*PAYMENTS_TXFEE,60) > 0 ) { mtx.vout.push_back(MakeCC1of2vout(cp->evalcode,PAYMENTS_TXFEE,Paymentspk,Paymentspk)); - rawtx = FinalizeCCTx(0,cp,mtx,mypk,PAYMENTS_TXFEE,EncodePaymentsSnapsShotOpRet(lockedblocks,minrelease,top,excludeScriptPubKeys)); + rawtx = FinalizeCCTx(0,cp,mtx,mypk,PAYMENTS_TXFEE,EncodePaymentsSnapsShotOpRet(lockedblocks,minrelease,top,bottom,fixedAmount,excludeScriptPubKeys)); if ( params != 0 ) free_json(params); - return(payments_rawtxresult(result,rawtx,0)); + return(payments_rawtxresult(result,rawtx,1)); } result.push_back(Pair("result","error")); result.push_back(Pair("error","not enough normal funds")); @@ -1015,8 +1106,8 @@ UniValue PaymentsAirdrop(struct CCcontract_info *cp,char *jsonstr) UniValue PaymentsInfo(struct CCcontract_info *cp,char *jsonstr) { UniValue result(UniValue::VOBJ),a(UniValue::VARR); CTransaction tx,txO; CPubKey Paymentspk,txidpk; int32_t i,j,n,flag=0,numoprets=0,lockedblocks,minrelease; std::vector txidoprets; int64_t funds,fundsopret,totalallocations=0,allocation; char fundsaddr[64],fundsopretaddr[64],txidaddr[64],*outstr; uint256 createtxid,hashBlock; - int32_t top; std::vector> excludeScriptPubKeys; // snapshot - uint256 tokenid; + int32_t top,bottom; std::vector> excludeScriptPubKeys; // snapshot + uint256 tokenid; int8_t fixedAmount; cJSON *params = payments_reparse(&n,jsonstr); if ( params != 0 && n == 1 ) { @@ -1071,9 +1162,9 @@ UniValue PaymentsInfo(struct CCcontract_info *cp,char *jsonstr) result.push_back(Pair("error","too many opreturns")); } else result.push_back(Pair("txidoprets",a)); } - else if ( DecodePaymentsSnapsShotOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,lockedblocks,minrelease,top,excludeScriptPubKeys) != 0 ) + else if ( DecodePaymentsSnapsShotOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,lockedblocks,minrelease,top,bottom,fixedAmount,excludeScriptPubKeys) != 0 ) { - if ( lockedblocks < 0 || minrelease < 0 || top <= 0 ) + if ( lockedblocks < 0 || minrelease < 0 || top <= 0 || bottom < 0 || fixedAmount < 0 || top > 3999 ) { result.push_back(Pair("result","error")); result.push_back(Pair("error","negative parameter")); @@ -1085,6 +1176,9 @@ UniValue PaymentsInfo(struct CCcontract_info *cp,char *jsonstr) result.push_back(Pair("lockedblocks",(int64_t)lockedblocks)); result.push_back(Pair("minrelease",(int64_t)minrelease)); result.push_back(Pair("top",(int64_t)top)); + result.push_back(Pair("bottom",(int64_t)bottom)); + result.push_back(Pair("fixedFlag",(int64_t)fixedAmount)); + // TODO: convert to show addresses instead of scriptpubkey. for ( auto scriptPubKey : excludeScriptPubKeys ) a.push_back(HexStr(scriptPubKey.begin(),scriptPubKey.end())); result.push_back(Pair("excludeScriptPubkeys",a)); @@ -1104,6 +1198,7 @@ UniValue PaymentsInfo(struct CCcontract_info *cp,char *jsonstr) result.push_back(Pair("minrelease",(int64_t)minrelease)); result.push_back(Pair("top",(int64_t)top)); result.push_back(Pair("tokenid",tokenid.ToString())); + // TODO: show pubkeys instead of scriptpubkeys for ( auto scriptPubKey : excludeScriptPubKeys ) a.push_back(HexStr(scriptPubKey.begin(),scriptPubKey.end())); result.push_back(Pair("excludeScriptPubkeys",a)); @@ -1146,8 +1241,8 @@ UniValue PaymentsInfo(struct CCcontract_info *cp,char *jsonstr) UniValue PaymentsList(struct CCcontract_info *cp,char *jsonstr) { std::vector > addressIndex; uint256 txid,hashBlock,tokenid; - UniValue result(UniValue::VOBJ),a(UniValue::VARR); char markeraddr[64],str[65]; CPubKey Paymentspk; CTransaction tx; int32_t lockedblocks,minrelease; std::vector txidoprets; int64_t totalallocations; - int32_t top; std::vector> excludeScriptPubKeys; + UniValue result(UniValue::VOBJ),a(UniValue::VARR); char markeraddr[64],str[65]; CPubKey Paymentspk; CTransaction tx; int32_t lockedblocks,minrelease; std::vector txidoprets; int64_t totalallocations=0; + int32_t top=0,bottom=0; std::vector> excludeScriptPubKeys; int8_t fixedAmount = 0; Paymentspk = GetUnspendable(cp,0); GetCCaddress1of2(cp,markeraddr,Paymentspk,Paymentspk); SetCCtxids(addressIndex,markeraddr,true); @@ -1156,9 +1251,9 @@ UniValue PaymentsList(struct CCcontract_info *cp,char *jsonstr) txid = it->first.txhash; if ( it->first.index == 0 && myGetTransaction(txid,tx,hashBlock) != 0 ) { - if ( tx.vout.size() > 0 && (DecodePaymentsOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,lockedblocks,minrelease,totalallocations,txidoprets) == 'C' || DecodePaymentsSnapsShotOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,lockedblocks,minrelease,top,excludeScriptPubKeys) == 'S' || DecodePaymentsTokensOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,lockedblocks,minrelease,top,excludeScriptPubKeys,tokenid) == 'O') ) + if ( tx.vout.size() > 0 && (DecodePaymentsOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,lockedblocks,minrelease,totalallocations,txidoprets) == 'C' || DecodePaymentsSnapsShotOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,lockedblocks,minrelease,top,bottom,fixedAmount,excludeScriptPubKeys) == 'S' || DecodePaymentsTokensOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,lockedblocks,minrelease,top,excludeScriptPubKeys,tokenid) == 'O') ) { - if ( lockedblocks < 0 || minrelease < 0 || totalallocations <= 0 || txidoprets.size() < 2 ) + if ( lockedblocks < 0 || minrelease < 0 || (totalallocations <= 0 && top <= 0 ) || bottom < 0 || fixedAmount < 0 ) { result.push_back(Pair("result","error")); result.push_back(Pair("error","negative parameter")); @@ -1169,6 +1264,6 @@ UniValue PaymentsList(struct CCcontract_info *cp,char *jsonstr) } } result.push_back(Pair("result","success")); - result.push_back(Pair("createtxids",a)); - return(result); + result.push_back(Pair("createtxids",a)); + return(result); } diff --git a/src/init.cpp b/src/init.cpp index 4003f9ced..bab2aba77 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -35,6 +35,7 @@ #include "httprpc.h" #include "key.h" #include "notarisationdb.h" + #ifdef ENABLE_MINING #include "key_io.h" #endif @@ -55,6 +56,7 @@ #ifdef ENABLE_WALLET #include "wallet/wallet.h" #include "wallet/walletdb.h" + #endif #include #include @@ -89,9 +91,11 @@ using namespace std; extern void ThreadSendAlert(); +extern bool komodo_dailysnapshot(int32_t height); extern int32_t KOMODO_LOADINGBLOCKS; extern bool VERUS_MINTBLOCKS; extern char ASSETCHAINS_SYMBOL[]; +extern int32_t KOMODO_SNAPSHOT_INTERVAL; ZCJoinSplit* pzcashParams = NULL; @@ -1622,6 +1626,15 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler) strLoadError = _("You need to rebuild the database using -reindex to go back to unpruned mode. This will redownload the entire blockchain"); break; } + + if ( ASSETCHAINS_CC != 0 && KOMODO_SNAPSHOT_INTERVAL != 0 && chainActive.Height() > KOMODO_SNAPSHOT_INTERVAL ) + { + if ( !komodo_dailysnapshot(chainActive.Height()) ) + { + strLoadError = _("daily snapshot failed, please reindex your chain."); + break; + } + } if (!fReindex) { uiInterface.InitMessage(_("Rewinding blocks if needed...")); diff --git a/src/komodo_defs.h b/src/komodo_defs.h index a9df99c0e..a3bde708b 100644 --- a/src/komodo_defs.h +++ b/src/komodo_defs.h @@ -20,7 +20,6 @@ #define ASSETCHAINS_MINHEIGHT 128 #define ASSETCHAINS_MAX_ERAS 3 #define KOMODO_ELECTION_GAP 2000 -#define KOMODO_SNAPSHOT_INTERVAL 1440 // 1440 is approx 1 day. Maybe this can be -ac param to allow for diffrent block times etc.? #define ROUNDROBIN_DELAY 61 #define KOMODO_ASSETCHAIN_MAXLEN 65 #define KOMODO_LIMITED_NETWORKSIZE 4 @@ -79,7 +78,7 @@ extern std::string DONATION_PUBKEY; extern uint8_t ASSETCHAINS_PRIVATE; extern int32_t USE_EXTERNAL_PUBKEY; extern char NOTARYADDRS[64][64]; -extern int32_t KOMODO_TESTNODE; +extern int32_t KOMODO_TESTNODE, KOMODO_SNAPSHOT_INTERVAL; int tx_height( const uint256 &hash ); extern std::vector vWhiteListAddress; void komodo_netevent(std::vector payload); diff --git a/src/komodo_globals.h b/src/komodo_globals.h index dc8cbda35..8d440cbaf 100644 --- a/src/komodo_globals.h +++ b/src/komodo_globals.h @@ -109,7 +109,7 @@ uint64_t PENDING_KOMODO_TX; extern int32_t KOMODO_LOADINGBLOCKS; unsigned int MAX_BLOCK_SIGOPS = 20000; -int32_t KOMODO_TESTNODE; +int32_t KOMODO_TESTNODE, KOMODO_SNAPSHOT_INTERVAL; struct komodo_kv *KOMODO_KV; pthread_mutex_t KOMODO_KV_mutex,KOMODO_CC_mutex; diff --git a/src/komodo_utils.h b/src/komodo_utils.h index cfb133a9d..137bace4c 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1752,6 +1752,7 @@ void komodo_args(char *argv0) ASSETCHAINS_BLOCKTIME = GetArg("-ac_blocktime",60); ASSETCHAINS_PUBLIC = GetArg("-ac_public",0); ASSETCHAINS_PRIVATE = GetArg("-ac_private",0); + KOMODO_SNAPSHOT_INTERVAL = GetArg("-ac_snapshot",0); Split(GetArg("-ac_nk",""), ASSETCHAINS_NK, 0); if ( (KOMODO_REWIND= GetArg("-rewind",0)) != 0 ) { @@ -2012,7 +2013,7 @@ void komodo_args(char *argv0) fprintf(stderr,"-ac_script and -ac_marmara are mutually exclusive\n"); StartShutdown(); } - 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 || nonz > 0 || ASSETCHAINS_CCLIB.size() > 0 || ASSETCHAINS_FOUNDERS_REWARD != 0 || ASSETCHAINS_NOTARY_PAY[0] != 0 || ASSETCHAINS_BLOCKTIME != 60 || ASSETCHAINS_CBOPRET != 0 || Mineropret.size() != 0 || (ASSETCHAINS_NK[0] != 0 && ASSETCHAINS_NK[1] != 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 || nonz > 0 || ASSETCHAINS_CCLIB.size() > 0 || ASSETCHAINS_FOUNDERS_REWARD != 0 || ASSETCHAINS_NOTARY_PAY[0] != 0 || ASSETCHAINS_BLOCKTIME != 60 || ASSETCHAINS_CBOPRET != 0 || Mineropret.size() != 0 || (ASSETCHAINS_NK[0] != 0 && ASSETCHAINS_NK[1] != 0) || KOMODO_SNAPSHOT_INTERVAL != 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; @@ -2148,6 +2149,11 @@ void komodo_args(char *argv0) extralen += iguana_rwnum(1,&extraptr[extralen],sizeof(ASSETCHAINS_NK[0]),(void *)&ASSETCHAINS_NK[0]); extralen += iguana_rwnum(1,&extraptr[extralen],sizeof(ASSETCHAINS_NK[1]),(void *)&ASSETCHAINS_NK[1]); } + if ( KOMODO_SNAPSHOT_INTERVAL != 0 ) + { + extralen += iguana_rwnum(1,&extraptr[extralen],sizeof(KOMODO_SNAPSHOT_INTERVAL),(void *)&KOMODO_SNAPSHOT_INTERVAL); + fprintf(stderr, "snapshot interval.%i\n",KOMODO_SNAPSHOT_INTERVAL); + } } addn = GetArg("-seednode",""); diff --git a/src/main.cpp b/src/main.cpp index 3168b773c..ef1a1a40b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -673,7 +673,7 @@ bool komodo_dailysnapshot(int32_t height) { // we are at the right height in connect block to scan back to last notarized height. notarized_height = komodo_notarized_height(&prevMoMheight,¬arized_hash,¬arized_desttxid); - notarized_height > height-100 ? undo_height = notarized_height : undo_height = height-reorglimit; + notarized_height > height-reorglimit ? undo_height = notarized_height : undo_height = height-reorglimit; } fprintf(stderr, "doing snapshot for height.%i undo_height.%i\n", height, undo_height); // if we already did this height dont bother doing it again, this is just a reorg. The actual snapshot height cannot be reorged. @@ -732,7 +732,7 @@ bool komodo_dailysnapshot(int32_t height) //for (int j = 0; j < 50; j++) // fprintf(stderr, "j.%i address.%s nValue.%li\n",j, CBitcoinAddress(vAddressSnapshot[j].second).ToString().c_str(), vAddressSnapshot[j].first ); // include only top 5000 address. - if ( vAddressSnapshot.size() > 5000 ) vAddressSnapshot.resize(5000); + if ( vAddressSnapshot.size() > 3999 ) vAddressSnapshot.resize(3999); lastSnapShotHeight = undo_height; fprintf(stderr, "vAddressSnapshot.size.%li\n", vAddressSnapshot.size()); return true; @@ -3592,8 +3592,8 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin fprintf(stderr,"valueout %.8f too big\n",(double)valueout/COIN); return state.DoS(100, error("ConnectBlock(): GetValueOut too big"),REJECT_INVALID,"tx valueout is too big"); } - prevsum = voutsum; - voutsum += valueout; + //prevsum = voutsum; + //voutsum += valueout; /*if ( KOMODO_VALUETOOBIG(voutsum) != 0 ) { fprintf(stderr,"voutsum %.8f too big\n",(double)voutsum/COIN); @@ -4251,7 +4251,7 @@ bool static ConnectTip(CValidationState &state, CBlockIndex *pindexNew, CBlock * komodo_pricesupdate(pindexNew->GetHeight(),pblock); if ( ASSETCHAINS_SAPLING <= 0 && pindexNew->nTime > KOMODO_SAPLING_ACTIVATION - 24*3600 ) komodo_activate_sapling(pindexNew); - if ( ASSETCHAINS_CC != 0 && (pindexNew->GetHeight() % KOMODO_SNAPSHOT_INTERVAL) == 0 ) + if ( ASSETCHAINS_CC != 0 && KOMODO_SNAPSHOT_INTERVAL != 0 && (pindexNew->GetHeight() % KOMODO_SNAPSHOT_INTERVAL) == 0 && pindexNew->GetHeight() > KOMODO_SNAPSHOT_INTERVAL ) { uint64_t start = time(NULL); if ( !komodo_dailysnapshot(pindexNew->GetHeight()) ) @@ -6198,12 +6198,6 @@ bool CVerifyDB::VerifyDB(CCoinsView *coinsview, int nCheckLevel, int nCheckDepth LogPrintf("No coin database inconsistencies in last %i blocks (%i transactions)\n", chainActive.Height() - pindexState->GetHeight(), nGoodTransactions); - if ( ASSETCHAINS_CC != 0 && chainActive.Height() > KOMODO_SNAPSHOT_INTERVAL ) - { - if ( !komodo_dailysnapshot(chainActive.Height()) ) - fprintf(stderr, "daily snapshot failed, please reindex your chain\n"); // maybe force shutdown here? - } - return true; } diff --git a/src/miner.cpp b/src/miner.cpp index a2ff8c933..810607d5a 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -291,9 +291,9 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 txvalue = tx.GetValueOut(); if ( KOMODO_VALUETOOBIG(txvalue) != 0 ) continue; - if ( KOMODO_VALUETOOBIG(txvalue + voutsum) != 0 ) - continue; - voutsum += txvalue; + //if ( KOMODO_VALUETOOBIG(txvalue + voutsum) != 0 ) // has been commented from main.cpp ? + // continue; + //voutsum += txvalue; if ( ASSETCHAINS_SYMBOL[0] == 0 && komodo_validate_interest(tx,nHeight,(uint32_t)pblock->nTime,0) < 0 ) { //fprintf(stderr,"CreateNewBlock: komodo_validate_interest failure nHeight.%d nTime.%u vs locktime.%u\n",nHeight,(uint32_t)pblock->nTime,(uint32_t)tx.nLockTime); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 8733b2894..8a671b322 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5633,7 +5633,7 @@ UniValue payments_airdrop(const UniValue& params, bool fHelp) { struct CCcontract_info *cp,C; if ( fHelp || params.size() != 1 ) - throw runtime_error("paymentsairdrop \"[lockedblocks,minamount,top,%22paytxid0%22,...,%22paytxidN%22]\"\n"); + throw runtime_error("paymentsairdrop \"[lockedblocks,minamount,top,bottom,fixedFlag,%22excludeAddress%22,...,%22excludeAddressN%22]\"\n"); if ( ensure_CCrequirements(EVAL_PAYMENTS) < 0 ) throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); const CKeyStore& keystore = *pwalletMain; From 52474518352482b5e6385d774b8660e855d8eef7 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Thu, 2 May 2019 20:16:21 +0800 Subject: [PATCH 202/447] disable token imports on LABS. fix getimports RPC --- src/cc/import.cpp | 2 ++ src/rpc/crosschain.cpp | 42 ++++++++++++++++++++++++++---------------- 2 files changed, 28 insertions(+), 16 deletions(-) diff --git a/src/cc/import.cpp b/src/cc/import.cpp index ded10abd5..35b4f5405 100644 --- a/src/cc/import.cpp +++ b/src/cc/import.cpp @@ -535,6 +535,8 @@ bool CheckMigration(Eval *eval, const CTransaction &importTx, const CTransaction uint256 tokenid = zeroid; if (vimportOpret.begin()[0] == EVAL_TOKENS) { // for tokens (new opret with tokens) + if ( is_STAKED(ASSETCHAINS_SYMBOL) == 1 ) + return eval->Invalid("no-tokens-migrate-on-LABS"); struct CCcontract_info *cpTokens, CCtokens_info; std::vector> oprets; uint8_t evalCodeInOpret; diff --git a/src/rpc/crosschain.cpp b/src/rpc/crosschain.cpp index 2ac53f788..35409323d 100644 --- a/src/rpc/crosschain.cpp +++ b/src/rpc/crosschain.cpp @@ -300,6 +300,9 @@ UniValue migrate_createburntransaction(const UniValue& params, bool fHelp) uint256 tokenid = zeroid; if( params.size() == 4 ) tokenid = Parseuint256(params[3].get_str().c_str()); + + if ( tokenid != zeroid && strcmp("LABS", targetSymbol.c_str())) + throw JSONRPCError(RPC_TYPE_ERROR, "There is no tokens support on LABS."); CPubKey myPubKey = Mypubkey(); struct CCcontract_info *cpTokens, C; @@ -312,8 +315,8 @@ UniValue migrate_createburntransaction(const UniValue& params, bool fHelp) if (tokenid.IsNull()) { // coins int64_t inputs; - if ((inputs = AddNormalinputs(mtx, myPubKey, burnAmount + txfee, 60)) == 0) { - throw runtime_error("Cannot find normal inputs\n"); + if ((inputs = AddNormalinputs(mtx, myPubKey, burnAmount + txfee, 10)) == 0) { + throw runtime_error("not enough funds, or need to merge utxos first\n"); } CTxDestination txdest = DecodeDestination(dest_addr_or_pubkey.c_str()); @@ -1145,36 +1148,43 @@ UniValue getNotarisationsForBlock(const UniValue& params, bool fHelp) //out.push_back(make_pair("blocktime",(int))); UniValue labs(UniValue::VARR); UniValue kmd(UniValue::VARR); - // Gets KMD notaries on KMD... but LABS notaries on labs chains needs to be fixed so LABS are identified on KMD. - int8_t numNN = 0; uint8_t notarypubkeys[64][33] = {0}; + int8_t numNN = 0, numSN = 0; uint8_t notarypubkeys[64][33] = {0}; uint8_t LABSpubkeys[64][33] = {0}; numNN = komodo_notaries(notarypubkeys, height, chainActive[height]->nTime); - + numSN = numStakedNotaries(LABSpubkeys,STAKED_era(chainActive[height]->nTime)); + BOOST_FOREACH(const Notarisation& n, nibs) { UniValue item(UniValue::VOBJ); UniValue notaryarr(UniValue::VARR); std::vector NotarisationNotaries; - if ( is_STAKED(n.second.symbol) != 0 ) - continue; // for now just skip this... need to fetch diff pubkeys for these chains. labs.push_back(item); uint256 hash; CTransaction tx; if ( GetTransaction(n.first,tx,hash,false) ) { - if ( !GetNotarisationNotaries(notarypubkeys, numNN, tx.vin, NotarisationNotaries) ) - continue; - if ( NotarisationNotaries.size() < numNN/5 ) - continue; + if ( is_STAKED(n.second.symbol) != 0 ) + { + if ( !GetNotarisationNotaries(LABSpubkeys, numSN, tx.vin, NotarisationNotaries) ) + continue; + } + else + { + if ( !GetNotarisationNotaries(notarypubkeys, numNN, tx.vin, NotarisationNotaries) ) + continue; + } } item.push_back(make_pair("txid", n.first.GetHex())); item.push_back(make_pair("chain", n.second.symbol)); item.push_back(make_pair("height", (int)n.second.height)); item.push_back(make_pair("blockhash", n.second.blockHash.GetHex())); - item.push_back(make_pair("KMD_height", height)); // for when timstamp input is used. + //item.push_back(make_pair("KMD_height", height)); // for when timstamp input is used. for ( auto notary : NotarisationNotaries ) notaryarr.push_back(notary); item.push_back(make_pair("notaries",notaryarr)); - kmd.push_back(item); + if ( is_STAKED(n.second.symbol) != 0 ) + labs.push_back(item); + else + kmd.push_back(item); } out.push_back(make_pair("KMD", kmd)); - //out.push_back(make_pair("LABS", labs)); + out.push_back(make_pair("LABS", labs)); return out; } @@ -1308,7 +1318,7 @@ UniValue getimports(const UniValue& params, bool fHelp) UniValue objTx(UniValue::VOBJ); objTx.push_back(Pair("txid",tx.GetHash().ToString())); ImportProof proof; CTransaction burnTx; std::vector payouts; CTxDestination importaddress; - TotalImported += tx.vout[1].nValue; + TotalImported += tx.vout[0].nValue; // were vouts swapped? objTx.push_back(Pair("amount", ValueFromAmount(tx.vout[1].nValue))); if (ExtractDestination(tx.vout[1].scriptPubKey, importaddress)) { @@ -1481,4 +1491,4 @@ UniValue getwalletburntransactions(const UniValue& params, bool fHelp) ret.push_backV(arrTmp); return ret; -} \ No newline at end of file +} From 6623acf4db95a31e13cbab6f84e37bae96770b58 Mon Sep 17 00:00:00 2001 From: dimxy Date: Thu, 2 May 2019 18:21:51 +0500 Subject: [PATCH 203/447] added reduced expr --- src/cc/prices.cpp | 202 ++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 169 insertions(+), 33 deletions(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 5fccd8774..fd1f5b4ef 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -587,69 +587,199 @@ static std::string prices_getsourceexpression(const std::vector &vec) return expr; } +// helper functions to get synthetic expression reduced: + +// return s true and needed operand count if string is opcode +static bool prices_isopcode(const std::string &s, int &need) +{ + if (s == "!") { + need = 1; + return true; + } + else if (s == "*" || s == "/") { + need = 2; + return true; + } + else if (s == "***" || s == "///" || s == "*//" || s == "**/") { + need = 3; + return true; + } + else + return false; +} + +// split pair onto two quotes divided by "_" static void prices_splitpair(const std::string &pair, std::string &upperquote, std::string &bottomquote) { size_t pos = pair.find('_'); // like BTC_USD if (pos != std::string::npos) { upperquote = pair.substr(0, pos); - bottomquote = pair.substr(pos); + bottomquote = pair.substr(pos + 1); } else { upperquote = pair; bottomquote = ""; } + std::cerr << "prices_splitpair: upperquote=" << upperquote << " bottomquote=" << bottomquote << std::endl; } -// search for an upper or bottom quote in the vectored expression, remove it from the vector with its weight and with operation correction -static bool prices_tryextractpair(const std::vector &vexpr, size_t istart, const std::string "e, bool isSearchUpper, std::string &foundpair, int32_t &weight) { +// invert pair like BTS_USD -> USD_BTC +static std::string prices_invertpair(const std::string &pair) +{ + std::string upperquote, bottomquote; + prices_splitpair(pair, upperquote, bottomquote); + return bottomquote + std::string("_") + upperquote; +} -/* for (size_t i = istart; i < vexpr.size(); i++) { - if (komodo_priceind(vexpr[i].c_str()) >= 0) { +// invert pairs in operation accordingly to "/" operator +static void prices_invertoperation(const std::vector &vexpr, int p, std::vector &voperation) +{ + int32_t need; + + voperation.clear(); + if (prices_isopcode(vexpr[p], need) && need > 1) { + if (need == 2) { + voperation.push_back(vexpr[p - 2]); + if (vexpr[p] == "/") + voperation.push_back(prices_invertpair(vexpr[p - 1])); + else + voperation.push_back(vexpr[p - 1]); + voperation.push_back("*"); + } + + if (need == 3) { + int i; + std::string::const_iterator c; + for (c = vexpr[p].begin(), i = -3; c != vexpr[p].end(); c++, i++) { + if (*c == '/') + voperation.push_back(prices_invertpair(vexpr[p + i])); + else + voperation.push_back(vexpr[p + i]); + } + voperation.push_back("***"); + } + } + + //std::cerr << "prices_invert inverted="; + for (auto v : voperation) std::cerr << v << " "; + std::cerr << std::endl; +} + +// reduce pair in operation, change or remove opcode if reduced +static int prices_reduceoperands(std::vector &voperation) +{ + int opcount = voperation.size() - 1; + int need = opcount; + //std::cerr << "prices_reduceoperands begin need=" << need << std::endl; + + while (true) { + int i; + //std::cerr << "prices_reduceoperands opcount=" << opcount << std::endl; + for (i = 0; i < opcount; i++) { std::string upperquote, bottomquote; - prices_splitpair(vexpr[i], upperquote, bottomquote); + bool breaktostart = false; - if (quote == upperquote) { - if( ) + //std::cerr << "prices_reduceoperands voperation[i]=" << voperation[i] << " i=" << i << std::endl; + prices_splitpair(voperation[i], upperquote, bottomquote); + if (upperquote == bottomquote) { + std::cerr << "prices_reduceoperands erasing i=" << i << std::endl; + voperation.erase(voperation.begin() + i); + opcount--; + //std::cerr << "prices_reduceoperands erased, size=" << voperation.size() << std::endl; + + if (voperation.size() > 0 && voperation.back() == "*") + voperation.pop_back(); + breaktostart = true; + break; } + int j; + for (j = i + 1; j < opcount; j++) { + + //std::cerr << "prices_reduceoperands voperation[j]=" << voperation[j] << " j=" << j << std::endl; + + std::string upperquotej, bottomquotej; + prices_splitpair(voperation[j], upperquotej, bottomquotej); + if (upperquote == bottomquotej || bottomquote == upperquotej) { + if (upperquote == bottomquotej) + voperation[i] = upperquotej + "_" + bottomquote; + else + voperation[i] = upperquote + "_" + bottomquotej; + //std::cerr << "prices_reduceoperands erasing j=" << j << std::endl; + voperation.erase(voperation.begin() + j); + opcount--; + //std::cerr << "prices_reduceoperands erased, size=" << voperation.size() << std::endl; + + need--; + if (voperation.back() == "***") { + voperation.pop_back(); + voperation.push_back("*"); + } + else if (voperation.back() == "*") { + voperation.pop_back(); + } + breaktostart = true; + break; + } + + + } + //if (j < voperation.size() - 1) + if (breaktostart) + break; } - }*/ - return true; + if (i >= opcount) // all seen + break; + } + + //std::cerr << "prices_reduceoperands end need=" << need << std::endl; + return need; } -// try to reduce synthetic expression by substituting "BTC_USD, 20, BTC_EUR, 30, *" with "EUR_USD, 30/20" -static std::string prices_reduceexp(const std::vector &vec) +// substitute reduced operation in vectored expr +static void prices_substitutereduced(std::vector &vexpr, int p, std::vector voperation) +{ + int need; + prices_isopcode(vexpr[p], need); + + vexpr.erase(vexpr.begin() + p - need, vexpr.begin() + p + 1); + vexpr.insert(vexpr.begin() + p - need, voperation.begin(), voperation.end()); +} + +// try to reduce synthetic expression by substituting "BTC_USD, BTC_EUR, 30, /" with "EUR_USD, 30" +static std::string prices_getreducedexpr(const std::string &expr) { std::string reduced; - - return reduced; -/* std::vector vexpr; SplitStr(expr, vexpr); - for (size_t i = 0; i < vexpr.size(); i ++) { - if (komodo_priceind(vexpr[i].c_str()) >= 0) { - std::string upperquote, bottomquote; - std::string foundpair1, foundpair2; - int32_t weight1, weight2; - - prices_splitpair(vexpr[i], upperquote, bottomquote); - if (prices_tryextractpair(vexpr, i+1, upperquote, false, foundpair1, weight1)) { - - } - if (prices_tryextractpair(vexpr, i+1, bottomquote, true, foundpair2, weight2)) { + for (size_t i = 0; i < vexpr.size(); i++) { + int need; + if (prices_isopcode(vexpr[i], need)) { + std::vector voperation; + prices_invertoperation(vexpr, i, voperation); + int reducedneed = prices_reduceoperands(voperation); + if (reducedneed < need) { + prices_substitutereduced(vexpr, i, voperation); } } } -*/ + + for (size_t i = 0; i < vexpr.size(); i++) { + if (reduced.size() > 0) + reduced += std::string(", "); + reduced += vexpr[i]; + } + + //std::cerr << "reduced=" << reduced << std::endl; + return reduced; } - - +// parse synthetic expression into vector of codes int32_t prices_syntheticvec(std::vector &vec, std::vector synthetic) { int32_t i, need, ind, depth = 0; std::string opstr; uint16_t opcode, weight; @@ -1013,8 +1143,6 @@ int32_t prices_syntheticprofits(int64_t &costbasis, int32_t firstheight, int32_t // profits = dprofits; //std::cerr << "prices_syntheticprofits() dprofits=" << dprofits << std::endl; - - if (costbasis > 0) { mpz_t mpzProfits; mpz_t mpzCostbasis; @@ -1161,6 +1289,7 @@ int64_t prices_enumaddedbets(uint256 &batontxid, std::vector &bets, uin return(addedBetsTotal); } +// pricesbet rpc impl: make betting tx UniValue PricesBet(int64_t txfee, int64_t amount, int16_t leverage, std::vector synthetic) { int32_t nextheight = komodo_nextheight(); @@ -1206,6 +1335,7 @@ UniValue PricesBet(int64_t txfee, int64_t amount, int16_t leverage, std::vector< return(result); } +// pricesaddfunding rpc impl: add yet another bet UniValue PricesAddFunding(int64_t txfee, uint256 bettxid, int64_t amount) { int32_t nextheight = komodo_nextheight(); @@ -1289,7 +1419,7 @@ int32_t prices_scanchain(std::vector &bets, int16_t leverage, std::vect return 0; } -// set cost basis (open price) for the bet +// pricescostbasis rpc impl: set cost basis (open price) for the bet (deprecated) UniValue PricesSetcostbasis(int64_t txfee, uint256 bettxid) { int32_t nextheight = komodo_nextheight(); @@ -1360,6 +1490,7 @@ UniValue PricesSetcostbasis(int64_t txfee, uint256 bettxid) return(result); } +// pricesrekt rpc: anyone can rekt a bet at some block where losses reached limit, collecting fee UniValue PricesRekt(int64_t txfee, uint256 bettxid, int32_t rektheight) { int32_t nextheight = komodo_nextheight(); @@ -1448,6 +1579,7 @@ UniValue PricesRekt(int64_t txfee, uint256 bettxid, int32_t rektheight) return(result); } +// pricescashout rpc impl: bettor can cashout hit bet if it is not rekt UniValue PricesCashout(int64_t txfee, uint256 bettxid) { int32_t nextheight = komodo_nextheight(); @@ -1533,6 +1665,7 @@ UniValue PricesCashout(int64_t txfee, uint256 bettxid) return(result); } +// pricesinfo rpc impl UniValue PricesInfo(uint256 bettxid, int32_t refheight) { UniValue result(UniValue::VOBJ); @@ -1645,7 +1778,9 @@ UniValue PricesInfo(uint256 bettxid, int32_t refheight) result.push_back(Pair("rektheight", (int64_t)endheight)); } - result.push_back(Pair("expression", prices_getsourceexpression(vec))); + std::string expr = prices_getsourceexpression(vec); + result.push_back(Pair("expression", expr)); + result.push_back(Pair("reduced", prices_getreducedexpr(expr))); result.push_back(Pair("batontxid", batontxid.GetHex())); result.push_back(Pair("costbasis", ValueFromAmount(averageCostbasis))); @@ -1669,6 +1804,7 @@ UniValue PricesInfo(uint256 bettxid, int32_t refheight) return(result); } +// priceslist rpc impl UniValue PricesList(uint32_t filter, CPubKey mypk) { UniValue result(UniValue::VARR); From c5b7b4aae48d2b0f8b1a6ae02893152ff1a457fc Mon Sep 17 00:00:00 2001 From: dimxy Date: Thu, 2 May 2019 18:37:53 +0500 Subject: [PATCH 204/447] corr reduced calc for op=! --- src/cc/prices.cpp | 50 ++++++++++++++++++++++++++--------------------- 1 file changed, 28 insertions(+), 22 deletions(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index fd1f5b4ef..123bd142d 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -632,37 +632,43 @@ static std::string prices_invertpair(const std::string &pair) } // invert pairs in operation accordingly to "/" operator -static void prices_invertoperation(const std::vector &vexpr, int p, std::vector &voperation) +static void prices_invert(const std::vector &vexpr, int p, std::vector &voperation) { - int32_t need; + int need; voperation.clear(); - if (prices_isopcode(vexpr[p], need) && need > 1) { - if (need == 2) { - voperation.push_back(vexpr[p - 2]); - if (vexpr[p] == "/") - voperation.push_back(prices_invertpair(vexpr[p - 1])); - else - voperation.push_back(vexpr[p - 1]); - voperation.push_back("*"); - } - - if (need == 3) { - int i; - std::string::const_iterator c; - for (c = vexpr[p].begin(), i = -3; c != vexpr[p].end(); c++, i++) { - if (*c == '/') - voperation.push_back(prices_invertpair(vexpr[p + i])); + if (prices_isopcode(vexpr[p], need)) { + if (need > 1) { + if (need == 2) { + voperation.push_back(vexpr[p - 2]); + if (vexpr[p] == "/") + voperation.push_back(prices_invertpair(vexpr[p - 1])); else - voperation.push_back(vexpr[p + i]); + voperation.push_back(vexpr[p - 1]); + voperation.push_back("*"); } - voperation.push_back("***"); + + if (need == 3) { + int i; + std::string::const_iterator c; + for (c = vexpr[p].begin(), i = -3; c != vexpr[p].end(); c++, i++) { + if (*c == '/') + voperation.push_back(prices_invertpair(vexpr[p + i])); + else + voperation.push_back(vexpr[p + i]); + } + voperation.push_back("***"); + } + } + else if (vexpr[p] == "!") { + voperation.push_back(prices_invertpair(vexpr[p - 1])); + // do not add operator } } //std::cerr << "prices_invert inverted="; - for (auto v : voperation) std::cerr << v << " "; - std::cerr << std::endl; + //for (auto v : voperation) std::cerr << v << " "; + //std::cerr << std::endl; } // reduce pair in operation, change or remove opcode if reduced From af82537ec1784cf8d3318a3415a7cef35aa6deaf Mon Sep 17 00:00:00 2001 From: dimxy Date: Thu, 2 May 2019 18:39:37 +0500 Subject: [PATCH 205/447] corr func name --- src/cc/prices.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 123bd142d..61d188af2 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -632,7 +632,7 @@ static std::string prices_invertpair(const std::string &pair) } // invert pairs in operation accordingly to "/" operator -static void prices_invert(const std::vector &vexpr, int p, std::vector &voperation) +static void prices_invertoperation(const std::vector &vexpr, int p, std::vector &voperation) { int need; From e2f1fe60280a7af2d9a4ae4e6d4f947b0ca07058 Mon Sep 17 00:00:00 2001 From: dimxy Date: Thu, 2 May 2019 18:46:19 +0500 Subject: [PATCH 206/447] added check to do nothing if empty inverted --- src/cc/prices.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 61d188af2..7254c8217 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -768,9 +768,11 @@ static std::string prices_getreducedexpr(const std::string &expr) if (prices_isopcode(vexpr[i], need)) { std::vector voperation; prices_invertoperation(vexpr, i, voperation); - int reducedneed = prices_reduceoperands(voperation); - if (reducedneed < need) { - prices_substitutereduced(vexpr, i, voperation); + if (voperation.size() > 0) { + int reducedneed = prices_reduceoperands(voperation); + if (reducedneed < need) { + prices_substitutereduced(vexpr, i, voperation); + } } } } From b5910e55c71dc13b8c1a33ed07854a3bfce1428a Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Thu, 2 May 2019 23:35:22 +0800 Subject: [PATCH 207/447] . --- src/cc/payments.cpp | 12 ++++++------ src/init.cpp | 2 +- src/main.cpp | 2 +- src/wallet/rpcwallet.cpp | 4 ++-- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/cc/payments.cpp b/src/cc/payments.cpp index 7ab3e8202..814d6823c 100644 --- a/src/cc/payments.cpp +++ b/src/cc/payments.cpp @@ -894,16 +894,16 @@ UniValue PaymentsFund(struct CCcontract_info *cp,char *jsonstr) mtx.vout.push_back(MakeCC1vout(EVAL_PAYMENTS,amount,Paymentspk)); opret = EncodePaymentsFundOpRet(txid); // Use the below one along with other FinalizeCCTx/return, to get the ccvout scriptpubkey - /*std::vector> vData = std::vector>(); + std::vector> vData = std::vector>(); if ( makeCCopret(opret, vData) ) - mtx.vout.push_back(MakeCC1vout(EVAL_PAYMENTS,amount,Paymentspk,&vData)); */ + mtx.vout.push_back(MakeCC1vout(EVAL_PAYMENTS,amount,Paymentspk,&vData)); } - rawtx = FinalizeCCTx(0,cp,mtx,mypk,PAYMENTS_TXFEE,opret); - //rawtx = FinalizeCCTx(0,cp,mtx,mypk,PAYMENTS_TXFEE,CScript()); // use this one to get ccvout scriptpubkey. + //rawtx = FinalizeCCTx(0,cp,mtx,mypk,PAYMENTS_TXFEE,opret); + rawtx = FinalizeCCTx(0,cp,mtx,mypk,PAYMENTS_TXFEE,CScript()); // use this one to get ccvout scriptpubkey. if ( params != 0 ) free_json(params); - //return(payments_rawtxresult(result,rawtx,0)); // disable sending for CCvout, as we only need to decode the tx. - return(payments_rawtxresult(result,rawtx,1)); + return(payments_rawtxresult(result,rawtx,0)); // disable sending for CCvout, as we only need to decode the tx. + //return(payments_rawtxresult(result,rawtx,1)); } else { diff --git a/src/init.cpp b/src/init.cpp index bab2aba77..107e3e476 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -1627,7 +1627,7 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler) break; } - if ( ASSETCHAINS_CC != 0 && KOMODO_SNAPSHOT_INTERVAL != 0 && chainActive.Height() > KOMODO_SNAPSHOT_INTERVAL ) + if ( ASSETCHAINS_CC != 0 && KOMODO_SNAPSHOT_INTERVAL != 0 && chainActive.Height() >= KOMODO_SNAPSHOT_INTERVAL ) { if ( !komodo_dailysnapshot(chainActive.Height()) ) { diff --git a/src/main.cpp b/src/main.cpp index ef1a1a40b..2e57f419e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4251,7 +4251,7 @@ bool static ConnectTip(CValidationState &state, CBlockIndex *pindexNew, CBlock * komodo_pricesupdate(pindexNew->GetHeight(),pblock); if ( ASSETCHAINS_SAPLING <= 0 && pindexNew->nTime > KOMODO_SAPLING_ACTIVATION - 24*3600 ) komodo_activate_sapling(pindexNew); - if ( ASSETCHAINS_CC != 0 && KOMODO_SNAPSHOT_INTERVAL != 0 && (pindexNew->GetHeight() % KOMODO_SNAPSHOT_INTERVAL) == 0 && pindexNew->GetHeight() > KOMODO_SNAPSHOT_INTERVAL ) + if ( ASSETCHAINS_CC != 0 && KOMODO_SNAPSHOT_INTERVAL != 0 && (pindexNew->GetHeight() % KOMODO_SNAPSHOT_INTERVAL) == 0 && pindexNew->GetHeight() >= KOMODO_SNAPSHOT_INTERVAL ) { uint64_t start = time(NULL); if ( !komodo_dailysnapshot(pindexNew->GetHeight()) ) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 8a671b322..754ec5318 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -8047,10 +8047,10 @@ UniValue opreturn_burn(const UniValue& params, bool fHelp) throw runtime_error("not enough normals\n"); CScript opret; uint8_t *ptr; - opret << OP_RETURN; + opret << OP_RETURN << 0; int32_t len = strlen(strHex.c_str()); len >>=1; - opret.resize(len+1); + opret.resize(len+2); ptr = (uint8_t *)&opret[1]; decode_hex(ptr,len,(char *)strHex.c_str()); mtx.vout.push_back(CTxOut(nAmount,opret)); From 4d8a0547b317457e594d62b18e459b9fddbd7ff5 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Thu, 2 May 2019 23:39:07 +0800 Subject: [PATCH 208/447] revert RPC --- src/komodo_bitcoind.h | 2 +- src/wallet/rpcwallet.cpp | 13 ++++++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index a1510a34e..292d5f8df 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -2063,7 +2063,7 @@ bool komodo_appendACscriptpub() ASSETCHAINS_SCRIPTPUB.pop_back(); ASSETCHAINS_SCRIPTPUB.pop_back(); // remove last 2 chars. // get OP_RETURN from txid and append the HexStr of it to scriptpub // encoded opreturn incorrectly on TESTHC chain, once we no longer need this it can be changed to a straight +1 to drop OP_RETURN opcode. - ASSETCHAINS_SCRIPTPUB.append(HexStr(tx.vout[i].scriptPubKey.begin()+(strcmp("TESTHC",ASSETCHAINS_SYMBOL) == 0 ? 3 : 1), tx.vout[i].scriptPubKey.end())); + ASSETCHAINS_SCRIPTPUB.append(HexStr(tx.vout[i].scriptPubKey.begin()+3, tx.vout[i].scriptPubKey.end())); //fprintf(stderr, "ac_script.%s\n",ASSETCHAINS_SCRIPTPUB.c_str()); didinit = true; return true; diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 754ec5318..888c60e0e 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -8045,14 +8045,21 @@ UniValue opreturn_burn(const UniValue& params, bool fHelp) int64_t normalInputs = AddNormalinputs(mtx, myPubkey, nAmount, 60); if (normalInputs < nAmount) throw runtime_error("not enough normals\n"); - - CScript opret; uint8_t *ptr; + + CScript opret; uint8_t scripthex[8192]; + + decode_hex(scripthex,strHex.size()/2,(char *)strHex.c_str()); + std::string test; + test.append((char*)scripthex); + std::vector opretdata(test.begin(), test.end()); + opret << OP_RETURN << E_MARSHAL(ss << opretdata); + /*CScript opret; uint8_t *ptr; opret << OP_RETURN << 0; int32_t len = strlen(strHex.c_str()); len >>=1; opret.resize(len+2); ptr = (uint8_t *)&opret[1]; - decode_hex(ptr,len,(char *)strHex.c_str()); + decode_hex(ptr,len,(char *)strHex.c_str()); */ mtx.vout.push_back(CTxOut(nAmount,opret)); ret.push_back(Pair("hex",FinalizeCCTx(0, cp, mtx, myPubkey, 10000, CScript()))); return(ret); From 7fc288161e8c90114f69759c52528106d458f730 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Fri, 3 May 2019 00:03:19 +0800 Subject: [PATCH 209/447] recomment paymentsfund --- src/cc/payments.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/cc/payments.cpp b/src/cc/payments.cpp index 814d6823c..7ab3e8202 100644 --- a/src/cc/payments.cpp +++ b/src/cc/payments.cpp @@ -894,16 +894,16 @@ UniValue PaymentsFund(struct CCcontract_info *cp,char *jsonstr) mtx.vout.push_back(MakeCC1vout(EVAL_PAYMENTS,amount,Paymentspk)); opret = EncodePaymentsFundOpRet(txid); // Use the below one along with other FinalizeCCTx/return, to get the ccvout scriptpubkey - std::vector> vData = std::vector>(); + /*std::vector> vData = std::vector>(); if ( makeCCopret(opret, vData) ) - mtx.vout.push_back(MakeCC1vout(EVAL_PAYMENTS,amount,Paymentspk,&vData)); + mtx.vout.push_back(MakeCC1vout(EVAL_PAYMENTS,amount,Paymentspk,&vData)); */ } - //rawtx = FinalizeCCTx(0,cp,mtx,mypk,PAYMENTS_TXFEE,opret); - rawtx = FinalizeCCTx(0,cp,mtx,mypk,PAYMENTS_TXFEE,CScript()); // use this one to get ccvout scriptpubkey. + rawtx = FinalizeCCTx(0,cp,mtx,mypk,PAYMENTS_TXFEE,opret); + //rawtx = FinalizeCCTx(0,cp,mtx,mypk,PAYMENTS_TXFEE,CScript()); // use this one to get ccvout scriptpubkey. if ( params != 0 ) free_json(params); - return(payments_rawtxresult(result,rawtx,0)); // disable sending for CCvout, as we only need to decode the tx. - //return(payments_rawtxresult(result,rawtx,1)); + //return(payments_rawtxresult(result,rawtx,0)); // disable sending for CCvout, as we only need to decode the tx. + return(payments_rawtxresult(result,rawtx,1)); } else { From aea85abb39af7beaa15f55d403af8d21712d281e Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Fri, 3 May 2019 01:54:42 +0800 Subject: [PATCH 210/447] fix build --- src/cc/makecustom | 6 +++--- zcutil/build.sh | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/cc/makecustom b/src/cc/makecustom index 61b251e6e..06f2f6fb1 100755 --- a/src/cc/makecustom +++ b/src/cc/makecustom @@ -1,7 +1,7 @@ #!/bin/sh gcc -O3 -DBUILD_CUSTOMCC -std=c++11 -I../secp256k1/include -I../univalue/include -I../cryptoconditions/include -I../cryptoconditions/src -I../cryptoconditions/src/asn -I.. -I. -fPIC -shared -c -o customcc.so cclib.cpp cp customcc.so ../libcc.so -cd .. -make -cd cc +#cd .. +#make +#cd cc diff --git a/zcutil/build.sh b/zcutil/build.sh index df3dfa234..96e0b7c2c 100755 --- a/zcutil/build.sh +++ b/zcutil/build.sh @@ -106,7 +106,7 @@ CONFIG_SITE="$PWD/depends/$HOST/share/config.site" ./configure "$HARDENING_ARG" WD=$PWD cd src/cc echo $PWD -./makerogue +./makecustom cd $WD "$MAKE" "$@" V=1 From 74b0cbb6566866f28eba98eac21afd6ca4fb819a Mon Sep 17 00:00:00 2001 From: dimxy Date: Thu, 2 May 2019 23:13:39 +0500 Subject: [PATCH 211/447] commented out extra log in reduced exp calc --- src/cc/prices.cpp | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 7254c8217..afa4f6e56 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -620,7 +620,7 @@ static void prices_splitpair(const std::string &pair, std::string &upperquote, s upperquote = pair; bottomquote = ""; } - std::cerr << "prices_splitpair: upperquote=" << upperquote << " bottomquote=" << bottomquote << std::endl; + //std::cerr << "prices_splitpair: upperquote=" << upperquote << " bottomquote=" << bottomquote << std::endl; } // invert pair like BTS_USD -> USD_BTC @@ -631,7 +631,7 @@ static std::string prices_invertpair(const std::string &pair) return bottomquote + std::string("_") + upperquote; } -// invert pairs in operation accordingly to "/" operator +// invert pairs in operation accordingly to "/" operator, convert operator to * or *** static void prices_invertoperation(const std::vector &vexpr, int p, std::vector &voperation) { int need; @@ -671,7 +671,7 @@ static void prices_invertoperation(const std::vector &vexpr, int p, //std::cerr << std::endl; } -// reduce pair in operation, change or remove opcode if reduced +// reduce pairs in the operation, change or remove opcode if reduced static int prices_reduceoperands(std::vector &voperation) { int opcount = voperation.size() - 1; @@ -686,7 +686,6 @@ static int prices_reduceoperands(std::vector &voperation) bool breaktostart = false; //std::cerr << "prices_reduceoperands voperation[i]=" << voperation[i] << " i=" << i << std::endl; - prices_splitpair(voperation[i], upperquote, bottomquote); if (upperquote == bottomquote) { std::cerr << "prices_reduceoperands erasing i=" << i << std::endl; @@ -721,18 +720,15 @@ static int prices_reduceoperands(std::vector &voperation) need--; if (voperation.back() == "***") { voperation.pop_back(); - voperation.push_back("*"); + voperation.push_back("*"); // convert *** to * } else if (voperation.back() == "*") { - voperation.pop_back(); + voperation.pop_back(); // convert * to nothing } breaktostart = true; break; } - - } - //if (j < voperation.size() - 1) if (breaktostart) break; } @@ -748,13 +744,13 @@ static int prices_reduceoperands(std::vector &voperation) static void prices_substitutereduced(std::vector &vexpr, int p, std::vector voperation) { int need; - prices_isopcode(vexpr[p], need); - - vexpr.erase(vexpr.begin() + p - need, vexpr.begin() + p + 1); - vexpr.insert(vexpr.begin() + p - need, voperation.begin(), voperation.end()); + if (prices_isopcode(vexpr[p], need)) { + vexpr.erase(vexpr.begin() + p - need, vexpr.begin() + p + 1); + vexpr.insert(vexpr.begin() + p - need, voperation.begin(), voperation.end()); + } } -// try to reduce synthetic expression by substituting "BTC_USD, BTC_EUR, 30, /" with "EUR_USD, 30" +// try to reduce synthetic expression by substituting "BTC_USD, BTC_EUR, 30, /" with "EUR_USD, 30" etc static std::string prices_getreducedexpr(const std::string &expr) { std::string reduced; From aff97f9fd4be59a7f0b2ae98fd563fcf1a8977b6 Mon Sep 17 00:00:00 2001 From: dimxy Date: Mon, 29 Apr 2019 13:05:27 +0500 Subject: [PATCH 212/447] added check for non-fungible data --- src/cc/CCtokens.cpp | 6 ++++++ src/wallet/rpcwallet.cpp | 8 ++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/cc/CCtokens.cpp b/src/cc/CCtokens.cpp index be3cbd922..5f5e56ebb 100644 --- a/src/cc/CCtokens.cpp +++ b/src/cc/CCtokens.cpp @@ -937,6 +937,12 @@ UniValue TokenInfo(uint256 tokenid) result.push_back(Pair("error", "cant find tokenid")); return(result); } + if (hashBlock.IsNull()) { + result.push_back(Pair("result", "error")); + result.push_back(Pair("error", "the transaction is still in mempool")); + return(result); + } + if (tokenbaseTx.vout.size() > 0 && DecodeTokenCreateOpRet(tokenbaseTx.vout[tokenbaseTx.vout.size() - 1].scriptPubKey, origpubkey, name, description, oprets) != 'c') { LOGSTREAM((char *)"cctokens", CCLOG_INFO, stream << "TokenInfo() passed tokenid isnt token creation txid" << std::endl); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 6fe061727..c830d37f9 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -7276,9 +7276,13 @@ UniValue tokencreate(const UniValue& params, bool fHelp) if (params.size() == 4) { nonfungibleData = ParseHex(params[3].get_str()); - if (nonfungibleData.size() > 10000) // opret limit + if (nonfungibleData.size() > IGUANA_MAXSCRIPTSIZE) // opret limit { - ERR_RESULT("Non-fungible data must be <= 10000"); + ERR_RESULT("Non-fungible data size must be <= " + std::to_string(IGUANA_MAXSCRIPTSIZE)); + return(result); + } + if( nonfungibleData.empty() ) { + ERR_RESULT("Non-fungible data incorrect"); return(result); } } From 2a8a02e5733e4401bb7724718eb723b324905f06 Mon Sep 17 00:00:00 2001 From: dimxy Date: Thu, 2 May 2019 23:56:56 +0500 Subject: [PATCH 213/447] corr rekt tx --- src/cc/prices.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index afa4f6e56..0344e983f 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -1508,12 +1508,15 @@ UniValue PricesRekt(int64_t txfee, uint256 bettxid, int32_t rektheight) std::vector vec; CPubKey pk, mypk, pricespk; std::string rawtx; + char destaddr[64]; cp = CCinit(&C, EVAL_PRICES); if (txfee == 0) txfee = PRICES_TXFEE; mypk = pubkey2pk(Mypubkey()); pricespk = GetUnspendable(cp, 0); + GetCCaddress(cp, destaddr, pricespk); + if (myGetTransaction(bettxid, bettx, hashBlock) != 0 && bettx.vout.size() > 3) { if (prices_betopretdecode(bettx.vout.back().scriptPubKey, pk, firstheight, positionsize, leverage, firstprice, vec, tokenid) == 'B') @@ -1558,9 +1561,16 @@ UniValue PricesRekt(int64_t txfee, uint256 bettxid, int32_t rektheight) } if (myfee != 0) { + int64_t CCchange = 0, inputsum; + mtx.vin.push_back(CTxIn(bettxid, 1, CScript())); // spend cc marker + if ((inputsum = AddPricesInputs(cp, mtx, destaddr, myfee + txfee, 64)) > myfee + txfee) // TODO: why do we take txfee from global addr and not from user's addr? + CCchange = (inputsum - myfee); mtx.vout.push_back(CTxOut(myfee, CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); - mtx.vout.push_back(MakeCC1vout(cp->evalcode, bettx.vout[2].nValue - myfee - txfee, pricespk)); // change + if (CCchange >= txfee) + mtx.vout.push_back(MakeCC1vout(cp->evalcode, CCchange, pricespk)); + + /// mtx.vout.push_back(MakeCC1vout(cp->evalcode, bettx.vout[2].nValue - myfee - txfee, pricespk)); // change rawtx = FinalizeCCTx(0, cp, mtx, mypk, txfee, prices_finalopret(bettxid, totalprofits, rektheight, mypk, firstprice, 0, totalbets - positionsize, positionsize, leverage)); return(prices_rawtxresult(result, rawtx, 0)); } From 2f3c8e31420631f6711b402ee1f5d82041d8f362 Mon Sep 17 00:00:00 2001 From: dimxy Date: Fri, 3 May 2019 00:42:49 +0500 Subject: [PATCH 214/447] corr open/close status on cc marker --- src/cc/prices.cpp | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 0344e983f..27c4367e4 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -16,11 +16,12 @@ #include "CCassets.h" #include "CCPrices.h" -//#include "mini-gmp.h" #include #define IS_CHARINSTR(c, str) (std::string(str).find((char)(c)) != std::string::npos) +#define N_CCMARKER 1 + typedef struct BetInfo { int64_t amount; int32_t firstheight; @@ -1214,7 +1215,7 @@ void prices_betjson(UniValue &result, std::vector bets, int16_t leverag result.push_back(Pair("LastHeight", endheight)); } -// retrives costbasis from a tx spending bettx vout1 +// retrieves costbasis from a tx spending bettx vout1 (deprecated) int64_t prices_costbasis(CTransaction bettx, uint256 &txidCostbasis) { int64_t costbasis = 0; @@ -1224,7 +1225,7 @@ int64_t prices_costbasis(CTransaction bettx, uint256 &txidCostbasis) int32_t vini; int32_t height; txidCostbasis = zeroid; - +/* if (CCgetspenttxid(txidCostbasis, vini, height, bettx.GetHash(), 1) < 0) { std::cerr << "prices_costbasis() no costbasis txid found" << std::endl; return 0; @@ -1243,7 +1244,7 @@ int64_t prices_costbasis(CTransaction bettx, uint256 &txidCostbasis) return costbasis; } - std::cerr << "prices_costbasis() cannot load costbasis tx or decode opret" << " isLoaded=" << isLoaded << " funcId=" << (int)funcId << std::endl; + std::cerr << "prices_costbasis() cannot load costbasis tx or decode opret" << " isLoaded=" << isLoaded << " funcId=" << (int)funcId << std::endl; */ return 0; } @@ -1327,10 +1328,10 @@ UniValue PricesBet(int64_t txfee, int64_t amount, int16_t leverage, std::vector< { betamount = (amount * 199) / 200; mtx.vout.push_back(MakeCC1vout(cp->evalcode, txfee, mypk)); // vout0 baton for total funding - // mtx.vout.push_back(MakeCC1vout(cp->evalcode, (amount - betamount) + 2 * txfee, pricespk)); // vout1, when spent, costbasis is set - mtx.vout.push_back(MakeCC1vout(cp->evalcode, txfee, pricespk)); // vout1 cc marker + // mtx.vout.push_back(MakeCC1vout(cp->evalcode, (amount - betamount) + 2 * txfee, pricespk)); // vout1, when spent, costbasis is set + mtx.vout.push_back(MakeCC1vout(cp->evalcode, txfee, pricespk)); // vout1 cc marker (N_CCMARKER) mtx.vout.push_back(MakeCC1vout(cp->evalcode, betamount, pricespk)); // vout2 betamount - mtx.vout.push_back(CTxOut(txfee, CScript() << ParseHex(HexStr(pricespk)) << OP_CHECKSIG)); // vout3 normal marker + mtx.vout.push_back(CTxOut(txfee, CScript() << ParseHex(HexStr(pricespk)) << OP_CHECKSIG)); // vout3 normal marker - may remove it as we have cc marker now rawtx = FinalizeCCTx(0, cp, mtx, mypk, txfee, prices_betopret(mypk, nextheight - 1, amount, leverage, firstprice, vec, zeroid)); return(prices_rawtxresult(result, rawtx, 0)); } @@ -1527,7 +1528,7 @@ UniValue PricesRekt(int64_t txfee, uint256 bettxid, int32_t rektheight) std::vector bets; BetInfo bet1; - if (CCgetspenttxid(finaltxid, vini, finalheight, bettxid, 2) == 0) { + if (CCgetspenttxid(finaltxid, vini, finalheight, bettxid, N_CCMARKER) == 0) { result.push_back(Pair("result", "error")); result.push_back(Pair("error", "position closed")); return result; @@ -1563,7 +1564,7 @@ UniValue PricesRekt(int64_t txfee, uint256 bettxid, int32_t rektheight) { int64_t CCchange = 0, inputsum; - mtx.vin.push_back(CTxIn(bettxid, 1, CScript())); // spend cc marker + mtx.vin.push_back(CTxIn(bettxid, N_CCMARKER, CScript())); // spend cc marker if ((inputsum = AddPricesInputs(cp, mtx, destaddr, myfee + txfee, 64)) > myfee + txfee) // TODO: why do we take txfee from global addr and not from user's addr? CCchange = (inputsum - myfee); mtx.vout.push_back(CTxOut(myfee, CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); @@ -1625,7 +1626,7 @@ UniValue PricesCashout(int64_t txfee, uint256 bettxid) std::vector bets; BetInfo bet1; - if (CCgetspenttxid(finaltxid, vini, finalheight, bettxid, 2) == 0) { + if (CCgetspenttxid(finaltxid, vini, finalheight, bettxid, N_CCMARKER) == 0) { result.push_back(Pair("result", "error")); result.push_back(Pair("error", "position closed")); return result; @@ -1658,7 +1659,7 @@ UniValue PricesCashout(int64_t txfee, uint256 bettxid) return(result); } - mtx.vin.push_back(CTxIn(bettxid, 1, CScript())); // spend cc marker + mtx.vin.push_back(CTxIn(bettxid, N_CCMARKER, CScript())); // spend cc marker if ((inputsum = AddPricesInputs(cp, mtx, destaddr, equity + txfee, 64)) > equity + txfee) CCchange = (inputsum - equity); mtx.vout.push_back(CTxOut(equity, CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); @@ -1706,7 +1707,7 @@ UniValue PricesInfo(uint256 bettxid, int32_t refheight) std::vector bets; BetInfo bet1; - if (CCgetspenttxid(finaltxid, vini, finalheight, bettxid, 2) == 0) + if (CCgetspenttxid(finaltxid, vini, finalheight, bettxid, N_CCMARKER) == 0) result.push_back(Pair("status", "closed")); else result.push_back(Pair("status", "open")); @@ -1857,7 +1858,7 @@ UniValue PricesList(uint32_t filter, CPubKey mypk) int32_t height; uint256 finaltxid; - int32_t spent = CCgetspenttxid(finaltxid, vini, height, txid, 2); + int32_t spent = CCgetspenttxid(finaltxid, vini, height, txid, N_CCMARKER); if (filter == 1 && spent < 0 || // open positions filter == 2 && spent == 0) // closed positions bAppend = true; From 2d1d8d253285547a41774fd802d7f3a134c9b996 Mon Sep 17 00:00:00 2001 From: dimxy Date: Fri, 3 May 2019 00:56:55 +0500 Subject: [PATCH 215/447] added todo comment to remove normal marker --- src/cc/prices.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 27c4367e4..cfc308680 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -1331,7 +1331,7 @@ UniValue PricesBet(int64_t txfee, int64_t amount, int16_t leverage, std::vector< // mtx.vout.push_back(MakeCC1vout(cp->evalcode, (amount - betamount) + 2 * txfee, pricespk)); // vout1, when spent, costbasis is set mtx.vout.push_back(MakeCC1vout(cp->evalcode, txfee, pricespk)); // vout1 cc marker (N_CCMARKER) mtx.vout.push_back(MakeCC1vout(cp->evalcode, betamount, pricespk)); // vout2 betamount - mtx.vout.push_back(CTxOut(txfee, CScript() << ParseHex(HexStr(pricespk)) << OP_CHECKSIG)); // vout3 normal marker - may remove it as we have cc marker now + mtx.vout.push_back(CTxOut(txfee, CScript() << ParseHex(HexStr(pricespk)) << OP_CHECKSIG)); // vout3 normal marker - TODO: remove it as we have cc marker now, when move to the new chain rawtx = FinalizeCCTx(0, cp, mtx, mypk, txfee, prices_betopret(mypk, nextheight - 1, amount, leverage, firstprice, vec, zeroid)); return(prices_rawtxresult(result, rawtx, 0)); } From b750ac018f4000570683b9fe2f9961d1219fad4a Mon Sep 17 00:00:00 2001 From: blackjok3rtt <30971146+blackjok3rtt@users.noreply.github.com> Date: Fri, 3 May 2019 13:08:29 +0800 Subject: [PATCH 216/447] revert back to rogue --- zcutil/build.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zcutil/build.sh b/zcutil/build.sh index 96e0b7c2c..df3dfa234 100755 --- a/zcutil/build.sh +++ b/zcutil/build.sh @@ -106,7 +106,7 @@ CONFIG_SITE="$PWD/depends/$HOST/share/config.site" ./configure "$HARDENING_ARG" WD=$PWD cd src/cc echo $PWD -./makecustom +./makerogue cd $WD "$MAKE" "$@" V=1 From eeaa0176eb83fb3db2c36bfcf6ebce1481d48579 Mon Sep 17 00:00:00 2001 From: dimxy Date: Fri, 3 May 2019 10:29:24 +0500 Subject: [PATCH 217/447] added costbasis testmode period = 7 --- src/cc/prices.cpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index cfc308680..37186e987 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -1091,8 +1091,11 @@ int32_t prices_syntheticprofits(int64_t &costbasis, int32_t firstheight, int32_t fprintf(stderr, "requested height is lower than bet firstheight.%d\n", height); return -1; } - +#ifndef TESTMODE int32_t minmax = (height < firstheight + PRICES_DAYWINDOW); // if we are within 24h then use min or max value +#else + int32_t minmax = (height < firstheight + 7); // if we are within 24h then use min or max value +#endif if ((price = prices_syntheticprice(vec, height, minmax, leverage)) < 0) { @@ -1803,11 +1806,6 @@ UniValue PricesInfo(uint256 bettxid, int32_t refheight) result.push_back(Pair("LiquidationPrice", ValueFromAmount(liqprice))); - //result.push_back(Pair("height", (int64_t)endheight)); -//#ifdef TESTMODE -// result.push_back(Pair("test_daywindow", PRICES_DAYWINDOW)); -//#endif - mpz_clear(mpzTotalbets); mpz_clear(mpzTotalprofits); mpz_clear(mpzTotalcostbasis); From dec5613c96d5441df33bbcf2f40e32eea325182d Mon Sep 17 00:00:00 2001 From: dimxy Date: Fri, 3 May 2019 10:32:26 +0500 Subject: [PATCH 218/447] costbasis test period info in json --- src/cc/prices.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 37186e987..0b7c8a873 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -1801,6 +1801,9 @@ UniValue PricesInfo(uint256 bettxid, int32_t refheight) result.push_back(Pair("reduced", prices_getreducedexpr(expr))); result.push_back(Pair("batontxid", batontxid.GetHex())); result.push_back(Pair("costbasis", ValueFromAmount(averageCostbasis))); +#ifdef TESTMODE + result.push_back(Pair("costbasis_test_period", 7)); +#endif prices_betjson(result, bets, leverage, endheight, lastprice); From 9ae73e9219fac7bfbfd35860503faf2b52143aeb Mon Sep 17 00:00:00 2001 From: dimxy Date: Fri, 3 May 2019 10:43:07 +0500 Subject: [PATCH 219/447] added COSTBASIS_PERIOD var --- src/cc/prices.cpp | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 0b7c8a873..cefc8c4e0 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -1086,16 +1086,19 @@ int64_t prices_syntheticprice(std::vector vec, int32_t height, int32_t int32_t prices_syntheticprofits(int64_t &costbasis, int32_t firstheight, int32_t height, int16_t leverage, std::vector vec, int64_t positionsize, int64_t &profits, int64_t &outprice) { int64_t price; +#ifndef TESTMODE + const int32_t COSTBASIS_PERIOD = PRICES_DAYWINDOW; +#else + const int32_t COSTBASIS_PERIOD = 7; +#endif + if (height < firstheight) { fprintf(stderr, "requested height is lower than bet firstheight.%d\n", height); return -1; } -#ifndef TESTMODE - int32_t minmax = (height < firstheight + PRICES_DAYWINDOW); // if we are within 24h then use min or max value -#else - int32_t minmax = (height < firstheight + 7); // if we are within 24h then use min or max value -#endif + + int32_t minmax = (height < firstheight + COSTBASIS_PERIOD); // if we are within 24h then use min or max value if ((price = prices_syntheticprice(vec, height, minmax, leverage)) < 0) { @@ -1122,12 +1125,12 @@ int32_t prices_syntheticprofits(int64_t &costbasis, int32_t firstheight, int32_t //} } else { - if (height == firstheight + PRICES_DAYWINDOW) { + if (height == firstheight + COSTBASIS_PERIOD) { // if costbasis not set, just set it //costbasis = price; // use calculated minmax costbasis - std::cerr << "prices_syntheticprofits() use permanent costbasis=" << costbasis << " height=" << height << std::endl; + std::cerr << "prices_syntheticprofits() use permanent costbasis=" << costbasis << " at height=" << height << std::endl; } } From 8d1583de80568a3175d628768e47d47439e20a73 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Fri, 3 May 2019 14:11:56 +0800 Subject: [PATCH 220/447] PLEASE BE WORKING --- src/cc/makecclib | 19 ++++++++++--------- src/wallet/db.h | 4 +++- zcutil/build.sh | 2 +- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/cc/makecclib b/src/cc/makecclib index b2f8e2ee1..256d50995 100755 --- a/src/cc/makecclib +++ b/src/cc/makecclib @@ -4,16 +4,17 @@ rm *.so rogue/rogue games/tetris games/prices echo rogue make -f Makefile_rogue ./makerogue +rm ../libcc.so +cp librogue.so ../libcc.so -echo sudoku/musig/dilithium -gcc -O3 -std=c++11 -I../secp256k1/include -I../univalue/include -I../cryptoconditions/include -I../cryptoconditions/src -I../cryptoconditions/src/asn -I.. -I. -fPIC -shared -c -o sudokucc.so cclib.cpp +#echo sudoku/musig/dilithium +#gcc -O3 -std=c++11 -I../secp256k1/include -I../univalue/include -I../cryptoconditions/include -I../cryptoconditions/src -I../cryptoconditions/src/asn -I.. -I. -fPIC -shared -c -o sudokucc.so cclib.cpp -echo games tetris -./maketetris +#echo games tetris +#./maketetris -echo games prices -./makeprices - -echo customcc stub -gcc -O3 -DBUILD_CUSTOMCC -std=c++11 -I../secp256k1/include -I../univalue/include -I../cryptoconditions/include -I../cryptoconditions/src -I../cryptoconditions/src/asn -I.. -I. -fPIC -shared -c -o customcc.so cclib.cpp +#echo games prices +#./makeprices +#echo customcc stub +#gcc -O3 -DBUILD_CUSTOMCC -std=c++11 -I../secp256k1/include -I../univalue/include -I../cryptoconditions/include -I../cryptoconditions/src -I../cryptoconditions/src/asn -I.. -I. -fPIC -shared -c -o customcc.so cclib.cpp diff --git a/src/wallet/db.h b/src/wallet/db.h index 19b9b6079..4af25c698 100644 --- a/src/wallet/db.h +++ b/src/wallet/db.h @@ -33,7 +33,9 @@ #include -#include +// CCLIB fails to compile with this! +//#include +#include "../depends/x86_64-unknown-linux-gnu/include/db_cxx.h" extern unsigned int nWalletDBUpdated; diff --git a/zcutil/build.sh b/zcutil/build.sh index df3dfa234..dc4d027b1 100755 --- a/zcutil/build.sh +++ b/zcutil/build.sh @@ -106,7 +106,7 @@ CONFIG_SITE="$PWD/depends/$HOST/share/config.site" ./configure "$HARDENING_ARG" WD=$PWD cd src/cc echo $PWD -./makerogue +./makecclib cd $WD "$MAKE" "$@" V=1 From ec185b7226942182f2174b76878b352a25b34951 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Fri, 3 May 2019 22:36:58 +0800 Subject: [PATCH 221/447] add daily snapshot address to getsnapshot (top = -1) --- src/rpc/misc.cpp | 3 ++- src/txdb.cpp | 19 +++++++++++++++---- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/rpc/misc.cpp b/src/rpc/misc.cpp index 4e21ab9e9..7c00ae7ad 100644 --- a/src/rpc/misc.cpp +++ b/src/rpc/misc.cpp @@ -1282,7 +1282,8 @@ UniValue getsnapshot(const UniValue& params, bool fHelp) if (params.size() > 0 && !params[0].isNull()) { top = atoi(params[0].get_str().c_str()); if (top <= 0) - throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, top must be a positive integer"); + //throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, top must be a positive integer"); + top = -1; } if ( fHelp || params.size() > 1) diff --git a/src/txdb.cpp b/src/txdb.cpp index a7415834c..4f813097b 100644 --- a/src/txdb.cpp +++ b/src/txdb.cpp @@ -555,6 +555,8 @@ bool CBlockTreeDB::Snapshot2(std::map &addressAmounts, Un return true; } +extern std::vector > vAddressSnapshot; + UniValue CBlockTreeDB::Snapshot(int top) { int topN = 0; @@ -564,11 +566,20 @@ UniValue CBlockTreeDB::Snapshot(int top) UniValue result(UniValue::VOBJ); UniValue addressesSorted(UniValue::VARR); result.push_back(Pair("start_time", (int) time(NULL))); - if ( Snapshot2(addressAmounts,&result) ) + if ( (vAddressSnapshot.size() > 0 && top < 0) || (Snapshot2(addressAmounts,&result) && top > 0) ) { - for (std::pair element : addressAmounts) - vaddr.push_back( make_pair(element.second, element.first) ); - std::sort(vaddr.rbegin(), vaddr.rend()); + if ( top > 0 ) + { + for (std::pair element : addressAmounts) + vaddr.push_back( make_pair(element.second, element.first) ); + std::sort(vaddr.rbegin(), vaddr.rend()); + } + else + { + for ( auto address : vAddressSnapshot ) + vaddr.push_back(make_pair(address.first, CBitcoinAddress(address.second).ToString())); + top = vAddressSnapshot.size(); + } int topN = 0; for (std::vector>::iterator it = vaddr.begin(); it!=vaddr.end(); ++it) { From 9802d350aa77767caffa06af09cd25db796af300 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Sat, 4 May 2019 01:55:33 +0800 Subject: [PATCH 222/447] bug fix --- src/rpc/misc.cpp | 2 +- src/txdb.cpp | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/rpc/misc.cpp b/src/rpc/misc.cpp index 7cb9b6664..4ea6e94e3 100644 --- a/src/rpc/misc.cpp +++ b/src/rpc/misc.cpp @@ -1383,7 +1383,7 @@ UniValue getsnapshot(const UniValue& params, bool fHelp) if (params.size() > 0 && !params[0].isNull()) { top = atoi(params[0].get_str().c_str()); - if (top <= 0) + if (top < 0) //throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, top must be a positive integer"); top = -1; } diff --git a/src/txdb.cpp b/src/txdb.cpp index 4638633ed..82885044e 100644 --- a/src/txdb.cpp +++ b/src/txdb.cpp @@ -481,6 +481,8 @@ bool CBlockTreeDB::Snapshot2(std::map &addressAmounts, Un try { CAmount nValue; iter->GetValue(nValue); + if ( nValue == 0 ) + continue; getAddressFromIndex(indexKey.type, indexKey.hashBytes, address); if ( indexKey.type == 3 ) { @@ -566,9 +568,9 @@ UniValue CBlockTreeDB::Snapshot(int top) UniValue result(UniValue::VOBJ); UniValue addressesSorted(UniValue::VARR); result.push_back(Pair("start_time", (int) time(NULL))); - if ( (vAddressSnapshot.size() > 0 && top < 0) || (Snapshot2(addressAmounts,&result) && top > 0) ) + if ( (vAddressSnapshot.size() > 0 && top < 0) || (Snapshot2(addressAmounts,&result) && top >= 0) ) { - if ( top > 0 ) + if ( top > -1 ) { for (std::pair element : addressAmounts) vaddr.push_back( make_pair(element.second, element.first) ); From 6e9fea30bbecd30901c403e683638c7115fc35a4 Mon Sep 17 00:00:00 2001 From: SHossain Date: Sat, 4 May 2019 16:09:25 +0100 Subject: [PATCH 223/447] Update assetchains.old --- src/assetchains.old | 1 + 1 file changed, 1 insertion(+) diff --git a/src/assetchains.old b/src/assetchains.old index a0cbd3b9c..fd472eff9 100755 --- a/src/assetchains.old +++ b/src/assetchains.old @@ -51,3 +51,4 @@ echo $pubkey ./komodod -pubkey=$pubkey -ac_name=MORTY -ac_supply=90000000000 -ac_reward=100000000 -ac_cc=3 -addnode=138.201.136.145 & ./komodod -pubkey=$pubkey -ac_name=VOTE2019 -ac_supply=123651638 -ac_public=1 -addnode=95.213.238.98 & ./komodod -pubkey=$pubkey -ac_name=KOIN -ac_supply=125000000 -addnode=3.0.32.10 & +~/hush3/src/komodod -pubkey=$pubkey -ac_name=HUSH3 -ac_sapling=1 -ac_reward=0,1125000000,562500000 -ac_halving=129,340000,840000 -ac_end=128,340000,5422111 -ac_eras=3 -ac_blocktime=150 -ac_cc=2 -ac_ccenable=228,234,235,236,241 -ac_founders=1 -ac_supply=6178674 -ac_perc=11111111 -clientname=GoldenSandtrout -addnode=188.165.212.101 -ac_cclib=hush3 -ac_script=76a9145eb10cf64f2bab1b457f1f25e658526155928fac88ac & From 650e55084d63fc715a5be97bb8ba5b7fd93d46d9 Mon Sep 17 00:00:00 2001 From: Alrighttt Date: Sat, 4 May 2019 23:19:33 +0200 Subject: [PATCH 224/447] Change oraclessamples rpc to show txid for each --- src/cc/oracles.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/cc/oracles.cpp b/src/cc/oracles.cpp index ef457fe82..53148bba9 100644 --- a/src/cc/oracles.cpp +++ b/src/cc/oracles.cpp @@ -935,13 +935,13 @@ UniValue OracleFormat(uint8_t *data,int32_t datalen,char *format,int32_t formatl if ( j >= datalen ) break; } - return(obj); + return(str); } UniValue OracleDataSamples(uint256 reforacletxid,uint256 batontxid,int32_t num) { - UniValue result(UniValue::VOBJ),a(UniValue::VARR); CTransaction tx,oracletx; uint256 hashBlock,btxid,oracletxid; - CPubKey pk; std::string name,description,format; int32_t numvouts,n=0; std::vector data; char *formatstr = 0; + UniValue result(UniValue::VOBJ),b(UniValue::VARR); CTransaction tx,oracletx; uint256 hashBlock,btxid,oracletxid; + CPubKey pk; std::string name,description,format; int32_t numvouts,n=0; std::vector data; char str[67], *formatstr = 0; result.push_back(Pair("result","success")); if ( GetTransaction(reforacletxid,oracletx,hashBlock,false) != 0 && (numvouts=oracletx.vout.size()) > 0 ) @@ -954,7 +954,10 @@ UniValue OracleDataSamples(uint256 reforacletxid,uint256 batontxid,int32_t num) { if ( (formatstr= (char *)format.c_str()) == 0 ) formatstr = (char *)""; + UniValue a(UniValue::VARR); a.push_back(OracleFormat((uint8_t *)data.data(),(int32_t)data.size(),formatstr,(int32_t)format.size())); + a.push_back(uint256_str(str,batontxid)); + b.push_back(a); batontxid = btxid; if ( ++n >= num ) break; @@ -962,7 +965,7 @@ UniValue OracleDataSamples(uint256 reforacletxid,uint256 batontxid,int32_t num) } } } - result.push_back(Pair("samples",a)); + result.push_back(Pair("samples",b)); return(result); } From c1cc66d1d48498edd061c9bfa546edc853625b94 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Sun, 5 May 2019 11:28:13 +0800 Subject: [PATCH 225/447] add range paid to paymentsinfo for game. --- src/cc/payments.cpp | 48 ++++++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 25 deletions(-) diff --git a/src/cc/payments.cpp b/src/cc/payments.cpp index 7ab3e8202..40f0b6e92 100644 --- a/src/cc/payments.cpp +++ b/src/cc/payments.cpp @@ -224,6 +224,21 @@ void pub2createtxid(char *str) free(rev); } +bool payments_game(int32_t &top, int32_t &bottom) +{ + uint64_t x; + uint256 tmphash = chainActive[lastSnapShotHeight]->GetBlockHash(); + memcpy(&x,&tmphash,sizeof(x)); + bottom = ((x & 0xff) % 50); + if ( bottom == 0 ) bottom = 1; + top = (((x>>8) & 0xff) % 100); + if ( top < 50 ) top += 50; + bottom = (vAddressSnapshot.size()*bottom)/100; + top = (vAddressSnapshot.size()*top)/100; + fprintf(stderr, "bottom.%i top.%i\n",bottom,top); + return true; +} + bool PaymentsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn) { // one of two addresses @@ -309,17 +324,7 @@ bool PaymentsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction & if ( fixedAmount == 7 ) { // game setting, randomise bottom and top values - uint64_t x; - uint256 tmphash = chainActive[lastSnapShotHeight]->GetBlockHash(); - memcpy(&x,&tmphash,sizeof(x)); - bottom = ((x & 0xff) % 50); - if ( bottom == 0 ) bottom = 1; - top = (((x>>8) & 0xff) % 100); - if ( top < 50 ) top += 50; - bottom = (vAddressSnapshot.size()*bottom)/100; - top = (vAddressSnapshot.size()*top)/100; - fprintf(stderr, "bottom.%i top.%i\n",bottom,top); - fFixedAmount = true; + fFixedAmount = payments_game(top,bottom); } else if ( fixedAmount != 0 ) { @@ -717,17 +722,7 @@ UniValue PaymentsRelease(struct CCcontract_info *cp,char *jsonstr) if ( fixedAmount == 7 ) { // game setting, randomise bottom and top values - uint64_t x; - uint256 tmphash = chainActive[lastSnapShotHeight]->GetBlockHash(); - memcpy(&x,&tmphash,sizeof(x)); - bottom = ((x & 0xff) % 50); - if ( bottom == 0 ) bottom = 1; - top = (((x>>8) & 0xff) % 100); - if ( top < 50 ) top += 50; - bottom = (vAddressSnapshot.size()*bottom)/100; - top = (vAddressSnapshot.size()*top)/100; - fprintf(stderr, "bottom.%i top.%i\n",bottom,top); - fFixedAmount = true; + fFixedAmount = payments_game(top,bottom); } else if ( fixedAmount != 0 ) { @@ -1172,11 +1167,14 @@ UniValue PaymentsInfo(struct CCcontract_info *cp,char *jsonstr) free_json(params); return(result); } - result.push_back(Pair("plan_type","snapshot")); + if ( fixedAmount == 7 && payments_game(top,bottom)) + result.push_back(Pair("plan_type","payments_game")); + else + result.push_back(Pair("plan_type","snapshot")); result.push_back(Pair("lockedblocks",(int64_t)lockedblocks)); - result.push_back(Pair("minrelease",(int64_t)minrelease)); - result.push_back(Pair("top",(int64_t)top)); + result.push_back(Pair("minrelease",(int64_t)minrelease)); result.push_back(Pair("bottom",(int64_t)bottom)); + result.push_back(Pair("top",(int64_t)top)); result.push_back(Pair("fixedFlag",(int64_t)fixedAmount)); // TODO: convert to show addresses instead of scriptpubkey. for ( auto scriptPubKey : excludeScriptPubKeys ) From 0e49cd4afe1001a31eb30f497e02fb6e3de3dcfd Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Sun, 5 May 2019 13:16:30 +0800 Subject: [PATCH 226/447] more RPC additions. --- src/cc/payments.cpp | 108 ++++++++++++++++++++++++++++---------------- 1 file changed, 70 insertions(+), 38 deletions(-) diff --git a/src/cc/payments.cpp b/src/cc/payments.cpp index 40f0b6e92..0b69f79fc 100644 --- a/src/cc/payments.cpp +++ b/src/cc/payments.cpp @@ -239,6 +239,19 @@ bool payments_game(int32_t &top, int32_t &bottom) return true; } +bool payments_lockedblocks(uint256 blockhash,int32_t lockedblocks,int32_t &blocksleft) +{ + int32_t ht = chainActive.Height(); + CBlockIndex* pblockindex = komodo_blockindex(blockhash); + if ( pblockindex == 0 || pblockindex->GetHeight()+lockedblocks > ht) + { + blocksleft = pblockindex->GetHeight()+lockedblocks - ht; + fprintf(stderr, "not elegible to be spent yet height.%i vs elegible_ht.%i blocksleft.%i\n",ht,(pblockindex!=0?pblockindex->GetHeight():0)+lockedblocks,blocksleft); + return false; + } + return true; +} + bool PaymentsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn) { // one of two addresses @@ -422,7 +435,7 @@ bool PaymentsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction & // Check vins i = 0; - int32_t ht = chainActive.LastTip()->GetHeight(); + int32_t blocksleft; BOOST_FOREACH(const CTxIn& vin, tx.vin) { CTransaction txin; @@ -446,12 +459,8 @@ bool PaymentsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction & } } // check the chain depth vs locked blocks requirement. - CBlockIndex* pblockindex = komodo_blockindex(blockhash); - if ( pblockindex == 0 || pblockindex->GetHeight() > ht-lockedblocks ) - { - fprintf(stderr, "vin.%i is not elegible to be spent yet height.%i vs elegible_ht.%i\n", i, pblockindex!=0?pblockindex->GetHeight():0, ht-lockedblocks); + if ( !payments_lockedblocks(blockhash, lockedblocks, blocksleft) ) return(eval->Invalid("vin not elegible")); - } } else return(eval->Invalid("cant get vin transaction")); i++; } @@ -462,19 +471,27 @@ bool PaymentsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction & // end of consensus code // helper functions for rpc calls in rpcwallet.cpp - -int64_t AddPaymentsInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey txidpk,int64_t total,int32_t maxinputs,uint256 createtxid,int32_t latestheight) +int64_t AddPaymentsInputs(bool fLockedBlocks,int8_t GetBalance,struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey txidpk,int64_t total,int32_t maxinputs,uint256 createtxid,int32_t lockedblocks,int64_t minrelease,int32_t &blocksleft) { char coinaddr[64]; CPubKey Paymentspk; int64_t nValue,threshold,price,totalinputs = 0; uint256 txid,checktxid,hashBlock; std::vector origpubkey; CTransaction vintx; int32_t iter,vout,ht,n = 0; std::vector > unspentOutputs; - if ( maxinputs > CC_MAXVINS ) - maxinputs = CC_MAXVINS; - if ( maxinputs > 0 ) - threshold = total/maxinputs; - else threshold = total; + std::vector > blocksleft_balance; + if ( GetBalance == 0 ) + { + if ( maxinputs > CC_MAXVINS ) + maxinputs = CC_MAXVINS; + if ( maxinputs > 0 ) + threshold = total/maxinputs; + else threshold = total; + } + else threshold = 0; Paymentspk = GetUnspendable(cp,0); for (iter=0; iter<2; iter++) { + if ( GetBalance == 1 && iter == 1 ) + continue; // getbalance of global paymentsCC address. + if ( GetBalance == 2 && iter == 0 ) + continue; // get balance of txidpk address. if ( iter == 0 ) GetCCaddress(cp,coinaddr,Paymentspk); else GetCCaddress1of2(cp,coinaddr,Paymentspk,txidpk); @@ -486,19 +503,6 @@ int64_t AddPaymentsInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CP //fprintf(stderr,"iter.%d %s/v%d %s\n",iter,txid.GetHex().c_str(),vout,coinaddr); if ( (vout == 0 || vout == 1) && GetTransaction(txid,vintx,hashBlock,false) != 0 ) { - if ( latestheight != 0 ) - { - if ( (ht= komodo_blockheight(hashBlock)) == 0 ) - { - fprintf(stderr,"null ht\n"); - continue; - } - else if ( ht > latestheight ) - { - fprintf(stderr,"ht.%d > lastheight.%d\n",ht,latestheight); - continue; - } - } if ( iter == 0 ) { CScript opret; uint256 checktxid; int32_t opret_ind; @@ -520,16 +524,37 @@ int64_t AddPaymentsInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CP } if ( (nValue= IsPaymentsvout(cp,vintx,vout,coinaddr)) > PAYMENTS_TXFEE && nValue >= threshold && myIsutxo_spentinmempool(ignoretxid,ignorevin,txid,vout) == 0 ) { - if ( total != 0 && maxinputs != 0 ) + int32_t tmpblocksleft = 0; + if ( GetBalance == 0 && total != 0 && maxinputs != 0 ) mtx.vin.push_back(CTxIn(txid,vout,CScript())); nValue = it->second.satoshis; + if ( fLockedBlocks && !payments_lockedblocks(hashBlock, lockedblocks, tmpblocksleft) ) + { + blocksleft_balance.push_back(std::make_pair(tmpblocksleft,nValue)); + continue; + } totalinputs += nValue; n++; //fprintf(stderr,"iter.%d %s/v%d %s %.8f\n",iter,txid.GetHex().c_str(),vout,coinaddr,(double)nValue/COIN); - if ( (total > 0 && totalinputs >= total) || (maxinputs > 0 && n >= maxinputs) ) - break; + if ( GetBalance == 0 && ((total > 0 && totalinputs >= total) || (maxinputs > 0 && n >= maxinputs)) ) + break; // create tx. We have ebnough inputs to make it. } //else fprintf(stderr,"nValue %.8f vs threshold %.8f\n",(double)nValue/COIN,(double)threshold/COIN); - iter++; + } + } + } + if ( GetBalance == 3 ) // return elegible balance to be spent, and blocks left until min release can be released. + { + int64_t lockedblocks_balance = totalinputs; // inputs that can be spent already. + // sort utxos by blocks until able to be spent, smallest at top. + std::sort(blocksleft_balance.begin(), blocksleft_balance.end()); + // iterate the utxos blocks left vector, to get block height min release is able to be released. + for ( auto utxo : blocksleft_balance ) + { + lockedblocks_balance += utxo.second; + if ( lockedblocks_balance >= minrelease ) + { + blocksleft = utxo.first; + break; } } } @@ -607,10 +632,11 @@ int32_t payments_parsehexdata(std::vector &hexdata,cJSON *item,int32_t UniValue PaymentsRelease(struct CCcontract_info *cp,char *jsonstr) { - int32_t latestheight,nextheight = komodo_nextheight(); + int32_t nextheight = komodo_nextheight(); + //int32_t latestheight,nextheight = komodo_nextheight(); CMutableTransaction tmpmtx,mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(),nextheight); UniValue result(UniValue::VOBJ); uint256 createtxid,hashBlock,tokenid; CTransaction tx,txO; CPubKey mypk,txidpk,Paymentspk; int32_t i,n,m,numoprets=0,lockedblocks,minrelease; int64_t newamount,inputsum,amount,CCchange=0,totalallocations=0,checkallocations=0,allocation; CTxOut vout; CScript onlyopret; char txidaddr[64],destaddr[64]; std::vector txidoprets; - int32_t top,bottom=0; std::vector> excludeScriptPubKeys; int8_t funcid,fixedAmount=0; bool fFixedAmount = false; + int32_t top,bottom=0,blocksleft=0; std::vector> excludeScriptPubKeys; int8_t funcid,fixedAmount=0; bool fFixedAmount = false; mpz_t mpzTotalAllocations; mpz_init(mpzTotalAllocations); cJSON *params = payments_reparse(&n,jsonstr); mypk = pubkey2pk(Mypubkey()); @@ -631,7 +657,7 @@ UniValue PaymentsRelease(struct CCcontract_info *cp,char *jsonstr) free_json(params); return(result); } - latestheight = (nextheight - lockedblocks - 1); + //latestheight = (nextheight - lockedblocks - 1); if ( amount < minrelease*COIN ) { result.push_back(Pair("result","error")); @@ -812,7 +838,7 @@ UniValue PaymentsRelease(struct CCcontract_info *cp,char *jsonstr) free_json(params); return(result); } - if ( (inputsum= AddPaymentsInputs(cp,mtx,txidpk,newamount+2*PAYMENTS_TXFEE,CC_MAXVINS/2,createtxid,latestheight)) >= newamount+2*PAYMENTS_TXFEE ) + if ( (inputsum= AddPaymentsInputs(true,0,cp,mtx,txidpk,newamount+2*PAYMENTS_TXFEE,CC_MAXVINS/2,createtxid,lockedblocks,minrelease,blocksleft)) >= newamount+2*PAYMENTS_TXFEE ) { std::string rawtx; if ( (CCchange= (inputsum - newamount - 2*PAYMENTS_TXFEE)) >= PAYMENTS_TXFEE ) @@ -1100,9 +1126,9 @@ UniValue PaymentsAirdrop(struct CCcontract_info *cp,char *jsonstr) UniValue PaymentsInfo(struct CCcontract_info *cp,char *jsonstr) { - UniValue result(UniValue::VOBJ),a(UniValue::VARR); CTransaction tx,txO; CPubKey Paymentspk,txidpk; int32_t i,j,n,flag=0,numoprets=0,lockedblocks,minrelease; std::vector txidoprets; int64_t funds,fundsopret,totalallocations=0,allocation; char fundsaddr[64],fundsopretaddr[64],txidaddr[64],*outstr; uint256 createtxid,hashBlock; + UniValue result(UniValue::VOBJ),a(UniValue::VARR); CTransaction tx,txO; CPubKey Paymentspk,txidpk; int32_t i,j,n,flag=0,numoprets=0,lockedblocks,minrelease,blocksleft=0; std::vector txidoprets; int64_t funds,fundsopret,elegiblefunds,totalallocations=0,allocation; char fundsaddr[64],fundsopretaddr[64],txidaddr[64],*outstr; uint256 createtxid,hashBlock; int32_t top,bottom; std::vector> excludeScriptPubKeys; // snapshot - uint256 tokenid; int8_t fixedAmount; + uint256 tokenid; int8_t fixedAmount; CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(),komodo_nextheight()); cJSON *params = payments_reparse(&n,jsonstr); if ( params != 0 && n == 1 ) { @@ -1210,13 +1236,19 @@ UniValue PaymentsInfo(struct CCcontract_info *cp,char *jsonstr) { txidpk = CCtxidaddr(txidaddr,createtxid); GetCCaddress1of2(cp,fundsaddr,Paymentspk,txidpk); - funds = CCaddress_balance(fundsaddr,1); + funds = AddPaymentsInputs(false,2,cp,mtx,txidpk,0,CC_MAXVINS,createtxid,lockedblocks,minrelease,blocksleft); + //CCaddress_balance(fundsaddr,1); result.push_back(Pair(fundsaddr,ValueFromAmount(funds))); GetCCaddress(cp,fundsopretaddr,Paymentspk); // TODO: Shows balance for ALL payments plans, not just the one asked for! Needs to be reworked. - fundsopret = CCaddress_balance(fundsopretaddr,1); + fundsopret = AddPaymentsInputs(false,1,cp,mtx,txidpk,0,CC_MAXVINS,createtxid,lockedblocks,minrelease,blocksleft); + //CCaddress_balance(fundsopretaddr,1); result.push_back(Pair(fundsopretaddr,ValueFromAmount(fundsopret))); result.push_back(Pair("totalfunds",ValueFromAmount(funds+fundsopret))); + // Blocks until minrelease can be released. + elegiblefunds = AddPaymentsInputs(true,3,cp,mtx,txidpk,0,CC_MAXVINS,createtxid,lockedblocks,minrelease,blocksleft); + result.push_back(Pair("elegiblefunds",ValueFromAmount(elegiblefunds))); + result.push_back(Pair("min_release_height",chainActive.Height()+blocksleft)); result.push_back(Pair("result","success")); } } From 0d47cda1451e48f1bab746e10f6a3e2cfac9030a Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 6 May 2019 00:57:06 +0800 Subject: [PATCH 227/447] initial commit for payments merge RPC --- src/cc/CCPayments.h | 2 + src/cc/CCinclude.h | 2 +- src/cc/CCtx.cpp | 2 +- src/cc/CCutils.cpp | 16 +- src/cc/customcc.cpp | 6 +- src/cc/payments.cpp | 502 ++++++++++++++++++++++++--------------- src/main.h | 2 +- src/rpc/server.cpp | 1 + src/rpc/server.h | 1 + src/wallet/rpcwallet.cpp | 15 +- 10 files changed, 348 insertions(+), 201 deletions(-) diff --git a/src/cc/CCPayments.h b/src/cc/CCPayments.h index c45fbab9e..13c66d358 100644 --- a/src/cc/CCPayments.h +++ b/src/cc/CCPayments.h @@ -21,6 +21,7 @@ #include #define PAYMENTS_TXFEE 10000 +#define PAYMENTS_MERGEOFSET 10 // 100? extern std::vector > vAddressSnapshot; extern int32_t lastSnapShotHeight; @@ -29,6 +30,7 @@ bool PaymentsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction & // CCcustom UniValue PaymentsRelease(struct CCcontract_info *cp,char *jsonstr); UniValue PaymentsFund(struct CCcontract_info *cp,char *jsonstr); +UniValue PaymentsMerge(struct CCcontract_info *cp,char *jsonstr); UniValue PaymentsTxidopret(struct CCcontract_info *cp,char *jsonstr); UniValue PaymentsCreate(struct CCcontract_info *cp,char *jsonstr); UniValue PaymentsAirdrop(struct CCcontract_info *cp,char *jsonstr); diff --git a/src/cc/CCinclude.h b/src/cc/CCinclude.h index db1ee7475..4ca73b6d7 100644 --- a/src/cc/CCinclude.h +++ b/src/cc/CCinclude.h @@ -229,7 +229,7 @@ uint256 DiceHashEntropy(uint256 &entropy,uint256 _txidpriv,int32_t entropyvout,i CTxOut MakeCC1vout(uint8_t evalcode,CAmount nValue,CPubKey pk, std::vector>* vData = NULL); CTxOut MakeCC1of2vout(uint8_t evalcode,CAmount nValue,CPubKey pk,CPubKey pk2, std::vector>* vData = NULL); int32_t has_opret(const CTransaction &tx, uint8_t evalcode); -CScript getCCopret(const CScript &scriptPubKey); +bool getCCopret(const CScript &scriptPubKey, CScript &opret); bool makeCCopret(CScript &opret, std::vector> &vData); CC *MakeCCcond1(uint8_t evalcode,CPubKey pk); CC *MakeCCcond1of2(uint8_t evalcode,CPubKey pk1,CPubKey pk2); diff --git a/src/cc/CCtx.cpp b/src/cc/CCtx.cpp index 7435defbf..fe5fade71 100644 --- a/src/cc/CCtx.cpp +++ b/src/cc/CCtx.cpp @@ -241,7 +241,7 @@ std::string FinalizeCCTx(uint64_t CCmask,struct CCcontract_info *cp,CMutableTran { char coinaddr[64]; GetCCaddress1of2(cp,coinaddr,globalpk,pubkeys[i]); - //fprintf(stderr,"%s + %s -> %s vs %s\n",HexStr(globalpk).c_str(),HexStr(pubkeys[i]).c_str(),coinaddr,destaddr); + fprintf(stderr,"%s + %s -> %s vs %s\n",HexStr(globalpk).c_str(),HexStr(pubkeys[i]).c_str(),coinaddr,destaddr); if ( strcmp(destaddr,coinaddr) == 0 ) { privkey = cp->CCpriv; diff --git a/src/cc/CCutils.cpp b/src/cc/CCutils.cpp index acf0da766..5fe7d662b 100644 --- a/src/cc/CCutils.cpp +++ b/src/cc/CCutils.cpp @@ -70,16 +70,20 @@ int32_t has_opret(const CTransaction &tx, uint8_t evalcode) return 0; } -CScript getCCopret(const CScript &scriptPubKey) +bool getCCopret(const CScript &scriptPubKey, CScript &opret) { std::vector> vParams = std::vector>(); - CScript dummy; CScript opret; - if ( scriptPubKey.IsPayToCryptoCondition(&dummy, vParams) && vParams.size() == 1 ) + CScript dummy; bool ret = false; + if ( scriptPubKey.IsPayToCryptoCondition(&dummy, vParams) != 0 ) { - //fprintf(stderr, "vparams.%s\n", HexStr(vParams[0].begin(), vParams[0].end()).c_str()); - opret = CScript(vParams[0].begin()+6, vParams[0].end()); + ret = true; + if ( vParams.size() == 1) + { + opret = CScript(vParams[0].begin()+6, vParams[0].end()); + //fprintf(stderr, "vparams.%s\n", HexStr(vParams[0].begin(), vParams[0].end()).c_str()); + } } - return opret; + return ret; } bool makeCCopret(CScript &opret, std::vector> &vData) diff --git a/src/cc/customcc.cpp b/src/cc/customcc.cpp index a8b0bf871..f7e8e6407 100644 --- a/src/cc/customcc.cpp +++ b/src/cc/customcc.cpp @@ -82,12 +82,12 @@ UniValue custom_func1(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) bool custom_validate(struct CCcontract_info *cp,int32_t height,Eval *eval,const CTransaction tx) { char expectedaddress[64]; CPubKey pk; - CScript opret; int32_t numvout; + CScript opret; int32_t numvout = 0; if ( has_opret(tx, EVAL_CUSTOM) == 0 ) { std::vector> vParams = std::vector>(); - opret = getCCopret(tx.vout[0].scriptPubKey); - numvout = 1; + if ( getCCopret(tx.vout[0].scriptPubKey,opret) ) + numvout = 1; } else { diff --git a/src/cc/payments.cpp b/src/cc/payments.cpp index 0b69f79fc..e42da664f 100644 --- a/src/cc/payments.cpp +++ b/src/cc/payments.cpp @@ -157,22 +157,41 @@ uint8_t DecodePaymentsOpRet(CScript scriptPubKey,int32_t &lockedblocks,int32_t & return(0); } -CScript EncodePaymentsSnapsShotOpRet(int32_t lockedblocks,int32_t minrelease,int32_t top,int32_t bottom,int8_t fixedAmount,std::vector> excludeScriptPubKeys) +CScript EncodePaymentsSnapsShotOpRet(int32_t lockedblocks,int32_t minrelease,int32_t minimum,int32_t top,int32_t bottom,int8_t fixedAmount,std::vector> excludeScriptPubKeys) { CScript opret; uint8_t evalcode = EVAL_PAYMENTS; - opret << OP_RETURN << E_MARSHAL(ss << evalcode << 'S' << lockedblocks << minrelease << top << bottom << fixedAmount << excludeScriptPubKeys); + if ( (strcmp(ASSETCHAINS_SYMBOL, "CFEKPAY") == 0) ) // exempt for now, remove this after game completed. + { + minimum = 10000; + opret << OP_RETURN << E_MARSHAL(ss << evalcode << 'S' << lockedblocks << minrelease << top << bottom << fixedAmount << excludeScriptPubKeys); + } + else + opret << OP_RETURN << E_MARSHAL(ss << evalcode << 'S' << lockedblocks << minrelease << minimum << top << bottom << fixedAmount << excludeScriptPubKeys); return(opret); } -uint8_t DecodePaymentsSnapsShotOpRet(CScript scriptPubKey,int32_t &lockedblocks,int32_t &minrelease,int32_t &top,int32_t &bottom,int8_t &fixedAmount,std::vector> &excludeScriptPubKeys) +uint8_t DecodePaymentsSnapsShotOpRet(CScript scriptPubKey,int32_t &lockedblocks,int32_t &minrelease,int32_t &minimum,int32_t &top,int32_t &bottom,int8_t &fixedAmount,std::vector> &excludeScriptPubKeys) { std::vector vopret; uint8_t *script,e,f; GetOpReturnData(scriptPubKey, vopret); script = (uint8_t *)vopret.data(); - if ( vopret.size() > 2 && E_UNMARSHAL(vopret,ss >> e; ss >> f; ss >> lockedblocks; ss >> minrelease; ss >> top; ; ss >> bottom; ss >> fixedAmount; ss >> excludeScriptPubKeys) != 0 ) + if ( (strcmp(ASSETCHAINS_SYMBOL, "CFEKPAY") == 0) ) // exempt for now, remove this after game completed. { - if ( e == EVAL_PAYMENTS && f == 'S' ) - return(f); + minimum = 10000; + if ( vopret.size() > 2 && E_UNMARSHAL(vopret,ss >> e; ss >> f; ss >> lockedblocks; ss >> minrelease; ss >> top; ; ss >> bottom; ss >> fixedAmount; ss >> excludeScriptPubKeys) != 0 ) + { + if ( e == EVAL_PAYMENTS && f == 'S' ) + return(f); + } + } + else + { + + if ( vopret.size() > 2 && E_UNMARSHAL(vopret,ss >> e; ss >> f; ss >> lockedblocks; ss >> minrelease; ss >> minimum; ss >> top; ; ss >> bottom; ss >> fixedAmount; ss >> excludeScriptPubKeys) != 0 ) + { + if ( e == EVAL_PAYMENTS && f == 'S' ) + return(f); + } } return(0); } @@ -197,10 +216,11 @@ uint8_t DecodePaymentsTokensOpRet(CScript scriptPubKey,int32_t &lockedblocks,int return(0); } -int64_t IsPaymentsvout(struct CCcontract_info *cp,const CTransaction& tx,int32_t v,char *cmpaddr) +int64_t IsPaymentsvout(struct CCcontract_info *cp,const CTransaction& tx,int32_t v,char *cmpaddr, CScript &ccopret) { char destaddr[64]; - if ( tx.vout[v].scriptPubKey.IsPayToCryptoCondition() != 0 ) + //if ( tx.vout[v].scriptPubKey.IsPayToCryptoCondition() != 0 ) + if ( getCCopret(tx.vout[v].scriptPubKey, ccopret) ) { if ( Getscriptaddress(destaddr,tx.vout[v].scriptPubKey) > 0 && (cmpaddr[0] == 0 || strcmp(destaddr,cmpaddr) == 0) ) return(tx.vout[v].nValue); @@ -259,197 +279,216 @@ bool PaymentsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction & // change is/must be in vout[0] // only 'F' or 1of2 txidaddr can be spent // all vouts must match exactly - char temp[128], coinaddr[64], txidaddr[64]; std::string scriptpubkey; uint256 createtxid, blockhash, tokenid; CTransaction plantx; int8_t funcid=0, fixedAmount=0; - int32_t i,lockedblocks,minrelease; int64_t change,totalallocations; std::vector txidoprets; bool fHasOpret = false; CPubKey txidpk,Paymentspk; - int32_t top,bottom=0; std::vector> excludeScriptPubKeys; bool fFixedAmount = false; + char temp[128], coinaddr[64]={0}, txidaddr[64]; std::string scriptpubkey; uint256 createtxid, blockhash, tokenid; CTransaction plantx; int8_t funcid=0, fixedAmount=0; + int32_t i,lockedblocks,minrelease; int64_t change,totalallocations; std::vector txidoprets; bool fHasOpret = false,fIsMerge = false; CPubKey txidpk,Paymentspk; + int32_t top,bottom=0,minimum=10000; std::vector> excludeScriptPubKeys; bool fFixedAmount = false; CScript ccopret; mpz_t mpzTotalAllocations, mpzAllocation;; mpz_init(mpzTotalAllocations); // user marker vout to get the createtxid - if ( tx.vout.size() < 2 ) - return(eval->Invalid("not enough vouts")); - if ( tx.vout.back().scriptPubKey[0] == OP_RETURN ) + if ( tx.vout.size() == 1 ) + { + if ( IsPaymentsvout(cp,tx,0,coinaddr,ccopret) != 0 && ccopret.size() > 2 && DecodePaymentsMergeOpRet(ccopret,createtxid) ) + { + fIsMerge = true; + } else return(eval->Invalid("not enough vouts")); + } + else if ( tx.vout.back().scriptPubKey[0] == OP_RETURN ) { scriptpubkey = HexStr(tx.vout[tx.vout.size()-2].scriptPubKey.begin()+2, tx.vout[tx.vout.size()-2].scriptPubKey.end()-1); fHasOpret = true; - } else scriptpubkey = HexStr(tx.vout[tx.vout.size()-1].scriptPubKey.begin()+2,tx.vout[tx.vout.size()-1].scriptPubKey.end()-1); - strcpy(temp, scriptpubkey.c_str()); - pub2createtxid(temp); - createtxid = Parseuint256(temp); + } + else scriptpubkey = HexStr(tx.vout[tx.vout.size()-1].scriptPubKey.begin()+2,tx.vout[tx.vout.size()-1].scriptPubKey.end()-1); + if ( !fIsMerge ) + { + strcpy(temp, scriptpubkey.c_str()); + pub2createtxid(temp); + createtxid = Parseuint256(temp); + } //printf("createtxid.%s\n",createtxid.ToString().c_str()); // use the createtxid to fetch the tx and all of the plans info. if ( myGetTransaction(createtxid,plantx,blockhash) != 0 && plantx.vout.size() > 0 ) { - if ( ((funcid= DecodePaymentsOpRet(plantx.vout[plantx.vout.size()-1].scriptPubKey,lockedblocks,minrelease,totalallocations,txidoprets)) == 'C' || (funcid= DecodePaymentsSnapsShotOpRet(plantx.vout[plantx.vout.size()-1].scriptPubKey,lockedblocks,minrelease,top,bottom,fixedAmount,excludeScriptPubKeys)) == 'S' || (funcid= DecodePaymentsTokensOpRet(plantx.vout[plantx.vout.size()-1].scriptPubKey,lockedblocks,minrelease,top,excludeScriptPubKeys,tokenid)) == 'O') ) + if ( ((funcid= DecodePaymentsOpRet(plantx.vout[plantx.vout.size()-1].scriptPubKey,lockedblocks,minrelease,totalallocations,txidoprets)) == 'C' || (funcid= DecodePaymentsSnapsShotOpRet(plantx.vout[plantx.vout.size()-1].scriptPubKey,lockedblocks,minrelease,minimum,top,bottom,fixedAmount,excludeScriptPubKeys)) == 'S' || (funcid= DecodePaymentsTokensOpRet(plantx.vout[plantx.vout.size()-1].scriptPubKey,lockedblocks,minrelease,top,excludeScriptPubKeys,tokenid)) == 'O') ) { if ( lockedblocks < 0 || minrelease < 0 || (totalallocations <= 0 && top <= 0 ) ) - return(eval->Invalid("negative values")); + return(eval->Invalid("negative values")); + if ( minimum < 10000 ) + return(eval->Invalid("minimum must be over 10000")); Paymentspk = GetUnspendable(cp,0); txidpk = CCtxidaddr(txidaddr,createtxid); GetCCaddress1of2(cp,coinaddr,Paymentspk,txidpk); //fprintf(stderr, "lockedblocks.%i minrelease.%i totalallocations.%i txidopret1.%s txidopret2.%s\n",lockedblocks, minrelease, totalallocations, txidoprets[0].ToString().c_str(), txidoprets[1].ToString().c_str() ); if ( !CheckTxFee(tx, PAYMENTS_TXFEE+1, chainActive.LastTip()->GetHeight(), chainActive.LastTip()->nTime) ) return eval->Invalid("txfee is too high"); - // Get all the script pubkeys and allocations - std::vector allocations; - std::vector scriptPubKeys; - int64_t checkallocations = 0; - i = 0; - if ( funcid == 'C' ) - { - // normal payment - for (const uint256& txidopret : txidoprets) - { - CTransaction tx0; std::vector scriptPubKey,opret; int64_t allocation; - if ( myGetTransaction(txidopret,tx0,blockhash) != 0 && tx0.vout.size() > 1 && DecodePaymentsTxidOpRet(tx0.vout[tx0.vout.size()-1].scriptPubKey,allocation,scriptPubKey,opret) == 'T' ) - { - scriptPubKeys.push_back(CScript(scriptPubKey.begin(), scriptPubKey.end())); - allocations.push_back(allocation); - //fprintf(stderr, "i.%i scriptpubkey.%s allocation.%li\n",i,scriptPubKeys[i].ToString().c_str(),allocation); - checkallocations += allocation; - // if we have an op_return to pay to need to check it exists and is paying the correct opret. - if ( !opret.empty() ) - { - if ( !fHasOpret ) - { - fprintf(stderr, "missing opret.%s in payments release.\n",HexStr(opret.begin(), opret.end()).c_str()); - return(eval->Invalid("missing opret in payments release")); - } - else if ( CScript(opret.begin(),opret.end()) != tx.vout[tx.vout.size()-1].scriptPubKey ) - { - fprintf(stderr, "opret.%s vs opret.%s\n",HexStr(opret.begin(), opret.end()).c_str(), HexStr(tx.vout[tx.vout.size()-1].scriptPubKey.begin(), tx.vout[tx.vout.size()-1].scriptPubKey.end()).c_str()); - return(eval->Invalid("pays incorrect opret")); - } - } - } - i++; - } - mpz_set_si(mpzTotalAllocations,totalallocations); - } - else if ( funcid == 'S' ) - { - if ( KOMODO_SNAPSHOT_INTERVAL == 0 ) - return(eval->Invalid("snapshots not activated on this chain")); - if ( vAddressSnapshot.size() == 0 ) - return(eval->Invalid("need first snapshot")); - // need time for TX to me mined before the next snapshot. - if ( top > 3999 ) - return(eval->Invalid("transaction too big")); - if ( fixedAmount == 7 ) - { - // game setting, randomise bottom and top values - fFixedAmount = payments_game(top,bottom); - } - else if ( fixedAmount != 0 ) - { - fFixedAmount = true; - } - for (int32_t j = bottom; j < vAddressSnapshot.size(); j++) - { - auto &address = vAddressSnapshot[j]; - CScript scriptPubKey = GetScriptForDestination(address.second); bool skip = false; - for ( auto skipkey : excludeScriptPubKeys ) - { - if ( scriptPubKey == CScript(skipkey.begin(), skipkey.end()) ) - { - skip = true; - //fprintf(stderr, "SKIPPED::: %s\n", CBitcoinAddress(address.second).ToString().c_str()); - } - } - if ( !skip ) - { - mpz_init(mpzAllocation); - i++; - scriptPubKeys.push_back(scriptPubKey); - allocations.push_back(address.first); - mpz_set_si(mpzAllocation,address.first); - mpz_add(mpzTotalAllocations,mpzTotalAllocations,mpzAllocation); - mpz_clear(mpzAllocation); - } - if ( i+bottom == top ) // we reached top amount to pay, it can be less than this! - break; - } - if ( i != tx.vout.size()-2 ) - return(eval->Invalid("pays wrong amount of recipients")); - } - else if ( funcid == 'O' ) - { - // tokens snapshot. - } - // sanity check to make sure we got all the required info - //fprintf(stderr, " allocations.size().%li scriptPubKeys.size.%li\n",allocations.size(), scriptPubKeys.size()); - if ( allocations.size() == 0 || scriptPubKeys.size() == 0 || allocations.size() != scriptPubKeys.size() ) - return(eval->Invalid("missing data cannot validate")); - - //fprintf(stderr, "totalallocations.%li checkallocations.%li\n",totalallocations, checkallocations); - if ( funcid == 'C' && totalallocations != checkallocations ) // only check for normal payments release. - return(eval->Invalid("allocation missmatch")); - // make sure change is in vout 0 and is paying to the contract address. - if ( (change= IsPaymentsvout(cp,tx,0,coinaddr)) == 0 ) + if ( (change= IsPaymentsvout(cp,tx,0,coinaddr,ccopret)) == 0 ) return(eval->Invalid("change is in wrong vout or is wrong tx type")); - // Check vouts go to the right place and pay the right amounts. - int64_t amount = 0, checkamount; int32_t n = 0; - checkamount = tx.GetValueOut() - change - PAYMENTS_TXFEE; - mpz_t mpzCheckamount; mpz_init(mpzCheckamount); mpz_set_si(mpzCheckamount,checkamount); - for (i = 1; i < (fHasOpret ? tx.vout.size()-2 : tx.vout.size()-1); i++) + if ( !fIsMerge ) { - if ( scriptPubKeys[n] != tx.vout[i].scriptPubKey ) + // Get all the script pubkeys and allocations + std::vector allocations; + std::vector scriptPubKeys; + int64_t checkallocations = 0; + i = 0; + if ( funcid == 'C' ) { - fprintf(stderr, "pays wrong destination destscriptPubKey.%s voutscriptPubKey.%s\n", HexStr(scriptPubKeys[n].begin(),scriptPubKeys[n].end()).c_str(), HexStr(tx.vout[i].scriptPubKey.begin(),tx.vout[i].scriptPubKey.end()).c_str()); - return(eval->Invalid("pays wrong address")); + // normal payment + for (const uint256& txidopret : txidoprets) + { + CTransaction tx0; std::vector scriptPubKey,opret; int64_t allocation; + if ( myGetTransaction(txidopret,tx0,blockhash) != 0 && tx0.vout.size() > 1 && DecodePaymentsTxidOpRet(tx0.vout[tx0.vout.size()-1].scriptPubKey,allocation,scriptPubKey,opret) == 'T' ) + { + scriptPubKeys.push_back(CScript(scriptPubKey.begin(), scriptPubKey.end())); + allocations.push_back(allocation); + //fprintf(stderr, "i.%i scriptpubkey.%s allocation.%li\n",i,scriptPubKeys[i].ToString().c_str(),allocation); + checkallocations += allocation; + // if we have an op_return to pay to need to check it exists and is paying the correct opret. + if ( !opret.empty() ) + { + if ( !fHasOpret ) + { + fprintf(stderr, "missing opret.%s in payments release.\n",HexStr(opret.begin(), opret.end()).c_str()); + return(eval->Invalid("missing opret in payments release")); + } + else if ( CScript(opret.begin(),opret.end()) != tx.vout[tx.vout.size()-1].scriptPubKey ) + { + fprintf(stderr, "opret.%s vs opret.%s\n",HexStr(opret.begin(), opret.end()).c_str(), HexStr(tx.vout[tx.vout.size()-1].scriptPubKey.begin(), tx.vout[tx.vout.size()-1].scriptPubKey.end()).c_str()); + return(eval->Invalid("pays incorrect opret")); + } + } + } + i++; + } + mpz_set_si(mpzTotalAllocations,totalallocations); } - int64_t test; - if ( fFixedAmount ) + else if ( funcid == 'S' ) { - test = checkamount / (top-bottom); + if ( KOMODO_SNAPSHOT_INTERVAL == 0 ) + return(eval->Invalid("snapshots not activated on this chain")); + if ( vAddressSnapshot.size() == 0 ) + return(eval->Invalid("need first snapshot")); + if ( top > 3999 ) + return(eval->Invalid("transaction too big")); + if ( fixedAmount == 7 ) + { + // game setting, randomise bottom and top values + fFixedAmount = payments_game(top,bottom); + } + else if ( fixedAmount != 0 ) + { + fFixedAmount = true; + } + for (int32_t j = bottom; j < vAddressSnapshot.size(); j++) + { + auto &address = vAddressSnapshot[j]; + CScript scriptPubKey = GetScriptForDestination(address.second); bool skip = false; + for ( auto skipkey : excludeScriptPubKeys ) + { + if ( scriptPubKey == CScript(skipkey.begin(), skipkey.end()) ) + { + skip = true; + //fprintf(stderr, "SKIPPED::: %s\n", CBitcoinAddress(address.second).ToString().c_str()); + } + } + if ( !skip ) + { + mpz_init(mpzAllocation); + i++; + scriptPubKeys.push_back(scriptPubKey); + allocations.push_back(address.first); + mpz_set_si(mpzAllocation,address.first); + mpz_add(mpzTotalAllocations,mpzTotalAllocations,mpzAllocation); + mpz_clear(mpzAllocation); + } + if ( i+bottom == top ) // we reached top amount to pay, it can be less than this! + break; + } + if ( i != tx.vout.size()-2 ) + return(eval->Invalid("pays wrong amount of recipients")); } - else + else if ( funcid == 'O' ) { - mpz_init(mpzAllocation); - mpz_set_si(mpzAllocation,allocations[n]); - mpz_mul(mpzAllocation,mpzAllocation,mpzCheckamount); - mpz_cdiv_q(mpzAllocation,mpzAllocation,mpzTotalAllocations); - test = mpz_get_si(mpzAllocation); - mpz_clear(mpzAllocation); + // tokens snapshot. } - // Vairance of 1 sat is allowed, for rounding errors. - if ( test >= tx.vout[i].nValue+1 && test <= tx.vout[i].nValue-1 ) + // sanity check to make sure we got all the required info, skip for merge type tx + //fprintf(stderr, " allocations.size().%li scriptPubKeys.size.%li\n",allocations.size(), scriptPubKeys.size()); + if ( (allocations.size() == 0 || scriptPubKeys.size() == 0 || allocations.size() != scriptPubKeys.size()) ) + return(eval->Invalid("missing data cannot validate")); + + //fprintf(stderr, "totalallocations.%li checkallocations.%li\n",totalallocations, checkallocations); + if ( funcid == 'C' && totalallocations != checkallocations ) // only check for normal payments release. + return(eval->Invalid("allocation missmatch")); + + // Check vouts go to the right place and pay the right amounts. + int64_t amount = 0, checkamount; int32_t n = 0; + checkamount = tx.GetValueOut() - change - PAYMENTS_TXFEE; + mpz_t mpzCheckamount; mpz_init(mpzCheckamount); mpz_set_si(mpzCheckamount,checkamount); + for (i = 1; i < (fHasOpret ? tx.vout.size()-2 : tx.vout.size()-1); i++) { - fprintf(stderr, "vout.%i test.%li vs nVlaue.%li\n",i, test, tx.vout[i].nValue); + if ( scriptPubKeys[n] != tx.vout[i].scriptPubKey ) + { + fprintf(stderr, "pays wrong destination destscriptPubKey.%s voutscriptPubKey.%s\n", HexStr(scriptPubKeys[n].begin(),scriptPubKeys[n].end()).c_str(), HexStr(tx.vout[i].scriptPubKey.begin(),tx.vout[i].scriptPubKey.end()).c_str()); + return(eval->Invalid("pays wrong address")); + } + int64_t test; + if ( fFixedAmount ) + { + test = checkamount / (top-bottom); + } + else + { + mpz_init(mpzAllocation); + mpz_set_si(mpzAllocation,allocations[n]); + mpz_mul(mpzAllocation,mpzAllocation,mpzCheckamount); + mpz_cdiv_q(mpzAllocation,mpzAllocation,mpzTotalAllocations); + test = mpz_get_si(mpzAllocation); + mpz_clear(mpzAllocation); + } + // Vairance of 1 sat is allowed, for rounding errors. + if ( test >= tx.vout[i].nValue+1 && test <= tx.vout[i].nValue-1 ) + { + fprintf(stderr, "vout.%i test.%li vs nVlaue.%li\n",i, test, tx.vout[i].nValue); + return(eval->Invalid("amounts do not match")); + } + if ( test < minimum ) + { + fprintf(stderr, "vout.%i test.%li vs minimum.%i\n",i, test, minimum); + return(eval->Invalid("under minimum size")); + } + amount += tx.vout[i].nValue; + n++; + } + mpz_clear(mpzTotalAllocations); + // This is a backup check to make sure there are no extra vouts paying something else! + if ( checkamount != amount ) return(eval->Invalid("amounts do not match")); + + if ( amount < minrelease*COIN ) + { + fprintf(stderr, "does not meet minrelease amount.%li minrelease.%li\n",amount, (int64_t)minrelease*COIN ); + return(eval->Invalid("amount is too small")); } - amount += tx.vout[i].nValue; - n++; } - mpz_clear(mpzTotalAllocations); - // This is a backup check to make sure there are no extra vouts paying something else! - if ( checkamount != amount ) - return(eval->Invalid("amounts do not match")); - - if ( amount < minrelease*COIN ) - { - fprintf(stderr, "does not meet minrelease amount.%li minrelease.%li\n",amount, (int64_t)minrelease*COIN ); - return(eval->Invalid("amount is too small")); - } - // Check vins - i = 0; + i = 0; int32_t dust = 0; int32_t blocksleft; BOOST_FOREACH(const CTxIn& vin, tx.vin) { - CTransaction txin; + CTransaction txin; if ( myGetTransaction(vin.prevout.hash,txin,blockhash) ) { // check the vin comes from the CC address's - char destaddr[64]; + char destaddr[64]; int32_t mergeoffset = 0; CScript opret; uint256 checktxid; Getscriptaddress(destaddr,txin.vout[vin.prevout.n].scriptPubKey); + if ( fIsMerge && txin.vout[vin.prevout.n].nValue < COIN ) + dust++; if ( strcmp(destaddr,coinaddr) != 0 ) { // if does not come from address its in the global payments adddress and we need to check the opreturn. - CScript opret; uint256 checktxid; int32_t opret_ind; + uint256 checktxid; int32_t opret_ind; if ( (opret_ind= has_opret(txin, EVAL_PAYMENTS)) == 0 ) - opret = getCCopret(txin.vout[vin.prevout.n].scriptPubKey); // get op_return from CCvout, + getCCopret(txin.vout[vin.prevout.n].scriptPubKey,opret); // get op_return from CCvout, else opret = txin.vout[opret_ind].scriptPubKey; if ( DecodePaymentsFundOpRet(opret,checktxid) != 'F' || checktxid != createtxid ) @@ -457,13 +496,25 @@ bool PaymentsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction & fprintf(stderr, "vin.%i is not a payments CC vout: txid.%s\n", i, txin.GetHash().ToString().c_str()); return(eval->Invalid("vin is not paymentsCC type")); } + } + else if ( fIsMerge && getCCopret(txin.vout[vin.prevout.n].scriptPubKey,opret) && opret.size() > 2 && DecodePaymentsMergeOpRet(opret,checktxid) == 'M' ) + { + mergeoffset = PAYMENTS_MERGEOFSET; } + fprintf(stderr, "mergeoffset.%i\n", mergeoffset); // check the chain depth vs locked blocks requirement. - if ( !payments_lockedblocks(blockhash, lockedblocks, blocksleft) ) + if ( !payments_lockedblocks(blockhash, lockedblocks+mergeoffset, blocksleft) ) return(eval->Invalid("vin not elegible")); + i++; } else return(eval->Invalid("cant get vin transaction")); - i++; } + if ( fIsMerge ) + { + if ( i < 2 ) + return(eval->Invalid("must have at least 2 vins to carry out merge")); + else if ( i == dust+1 ) + return(eval->Invalid("cannot merge only dust")); + } } else return(eval->Invalid("create transaction cannot decode")); } else return(eval->Invalid("Could not get contract transaction")); return(true); @@ -474,7 +525,7 @@ bool PaymentsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction & int64_t AddPaymentsInputs(bool fLockedBlocks,int8_t GetBalance,struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey txidpk,int64_t total,int32_t maxinputs,uint256 createtxid,int32_t lockedblocks,int64_t minrelease,int32_t &blocksleft) { char coinaddr[64]; CPubKey Paymentspk; int64_t nValue,threshold,price,totalinputs = 0; uint256 txid,checktxid,hashBlock; std::vector origpubkey; CTransaction vintx; int32_t iter,vout,ht,n = 0; - std::vector > unspentOutputs; + std::vector > unspentOutputs; CScript ccopret; std::vector > blocksleft_balance; if ( GetBalance == 0 ) { @@ -509,7 +560,7 @@ int64_t AddPaymentsInputs(bool fLockedBlocks,int8_t GetBalance,struct CCcontract if ( (opret_ind= has_opret(vintx, EVAL_PAYMENTS)) == 0 ) { // get op_return from CCvout - opret = getCCopret(vintx.vout[vout].scriptPubKey); + getCCopret(vintx.vout[vout].scriptPubKey,opret); } else { @@ -522,13 +573,15 @@ int64_t AddPaymentsInputs(bool fLockedBlocks,int8_t GetBalance,struct CCcontract continue; } } - if ( (nValue= IsPaymentsvout(cp,vintx,vout,coinaddr)) > PAYMENTS_TXFEE && nValue >= threshold && myIsutxo_spentinmempool(ignoretxid,ignorevin,txid,vout) == 0 ) + if ( (nValue= IsPaymentsvout(cp,vintx,vout,coinaddr,ccopret)) > PAYMENTS_TXFEE && nValue >= threshold && myIsutxo_spentinmempool(ignoretxid,ignorevin,txid,vout) == 0 ) { int32_t tmpblocksleft = 0; - if ( GetBalance == 0 && total != 0 && maxinputs != 0 ) + if ( (GetBalance == 0 && total != 0 && maxinputs != 0) || GetBalance == 4 ) mtx.vin.push_back(CTxIn(txid,vout,CScript())); nValue = it->second.satoshis; - if ( fLockedBlocks && !payments_lockedblocks(hashBlock, lockedblocks, tmpblocksleft) ) + if ( nValue < COIN ) + blocksleft++; // count dust with unused variable. + if ( fLockedBlocks && !payments_lockedblocks(hashBlock, lockedblocks+(GetBalance == 4 ? PAYMENTS_MERGEOFSET : 0), tmpblocksleft) ) { blocksleft_balance.push_back(std::make_pair(tmpblocksleft,nValue)); continue; @@ -636,7 +689,7 @@ UniValue PaymentsRelease(struct CCcontract_info *cp,char *jsonstr) //int32_t latestheight,nextheight = komodo_nextheight(); CMutableTransaction tmpmtx,mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(),nextheight); UniValue result(UniValue::VOBJ); uint256 createtxid,hashBlock,tokenid; CTransaction tx,txO; CPubKey mypk,txidpk,Paymentspk; int32_t i,n,m,numoprets=0,lockedblocks,minrelease; int64_t newamount,inputsum,amount,CCchange=0,totalallocations=0,checkallocations=0,allocation; CTxOut vout; CScript onlyopret; char txidaddr[64],destaddr[64]; std::vector txidoprets; - int32_t top,bottom=0,blocksleft=0; std::vector> excludeScriptPubKeys; int8_t funcid,fixedAmount=0; bool fFixedAmount = false; + int32_t top,bottom=0,blocksleft=0,minimum=10000; std::vector> excludeScriptPubKeys; int8_t funcid,fixedAmount=0; bool fFixedAmount = false; mpz_t mpzTotalAllocations; mpz_init(mpzTotalAllocations); cJSON *params = payments_reparse(&n,jsonstr); mypk = pubkey2pk(Mypubkey()); @@ -647,7 +700,7 @@ UniValue PaymentsRelease(struct CCcontract_info *cp,char *jsonstr) amount = jdouble(jitem(params,1),0) * SATOSHIDEN + 0.0000000049; if ( myGetTransaction(createtxid,tx,hashBlock) != 0 && tx.vout.size() > 0 ) { - if ( ((funcid= DecodePaymentsOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,lockedblocks,minrelease,totalallocations,txidoprets)) == 'C' || (funcid= DecodePaymentsSnapsShotOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,lockedblocks,minrelease,top,bottom,fixedAmount,excludeScriptPubKeys)) == 'S' || (funcid= DecodePaymentsTokensOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,lockedblocks,minrelease,top,excludeScriptPubKeys,tokenid)) == 'O') ) + if ( ((funcid= DecodePaymentsOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,lockedblocks,minrelease,totalallocations,txidoprets)) == 'C' || (funcid= DecodePaymentsSnapsShotOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,lockedblocks,minrelease,minimum,top,bottom,fixedAmount,excludeScriptPubKeys)) == 'S' || (funcid= DecodePaymentsTokensOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,lockedblocks,minrelease,top,excludeScriptPubKeys,tokenid)) == 'O') ) { if ( lockedblocks < 0 || minrelease < 0 || (totalallocations <= 0 && top <= 0 ) ) { @@ -657,6 +710,9 @@ UniValue PaymentsRelease(struct CCcontract_info *cp,char *jsonstr) free_json(params); return(result); } + // set minimum size to 10k sat otherwise the tx will be invalid. + if ( minimum < 10000 ) + minimum = 10000; //latestheight = (nextheight - lockedblocks - 1); if ( amount < minrelease*COIN ) { @@ -817,13 +873,14 @@ UniValue PaymentsRelease(struct CCcontract_info *cp,char *jsonstr) } //fprintf(stderr, "nValue.%li \n", mtx.vout[i+1].nValue); mpz_clear(mpzValue); - /* - replace this with default dust threshold of 10ksat - if ( mtx.vout[i+1].nValue < PAYMENTS_TXFEE ) + if ( mtx.vout[i+1].nValue < minimum ) { - newamount += (PAYMENTS_TXFEE - mtx.vout[i+1].nValue); - mtx.vout[i+1].nValue = PAYMENTS_TXFEE; - } */ + result.push_back(Pair("result","error")); + result.push_back(Pair("error","value too small, try releasing a larger amount")); + if ( params != 0 ) + free_json(params); + return(result); + } totalamountsent += mtx.vout[i+1].nValue; } if ( totalamountsent < amount ) newamount = totalamountsent; @@ -879,7 +936,7 @@ UniValue PaymentsFund(struct CCcontract_info *cp,char *jsonstr) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); UniValue result(UniValue::VOBJ); CPubKey Paymentspk,mypk,txidpk; uint256 txid,hashBlock; int64_t amount,totalallocations; CScript opret; CTransaction tx; char txidaddr[64]; std::string rawtx; int32_t n,useopret = 0,lockedblocks,minrelease; std::vector txidoprets; - int32_t top,bottom; std::vector> excludeScriptPubKeys; // snapshot + int32_t top,bottom,minimum=10000; std::vector> excludeScriptPubKeys; // snapshot uint256 tokenid; int8_t fixedAmount; cJSON *params = payments_reparse(&n,jsonstr); mypk = pubkey2pk(Mypubkey()); @@ -890,7 +947,7 @@ UniValue PaymentsFund(struct CCcontract_info *cp,char *jsonstr) amount = jdouble(jitem(params,1),0) * SATOSHIDEN + 0.0000000049; if ( n == 3 ) useopret = jint(jitem(params,2),0) != 0; - if ( myGetTransaction(txid,tx,hashBlock) == 0 || tx.vout.size() == 1 || (DecodePaymentsOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,lockedblocks,minrelease,totalallocations,txidoprets) == 0 && DecodePaymentsSnapsShotOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,lockedblocks,minrelease,top,bottom,fixedAmount,excludeScriptPubKeys) == 0 && DecodePaymentsTokensOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,lockedblocks,minrelease,top,excludeScriptPubKeys,tokenid) == 0) ) + if ( myGetTransaction(txid,tx,hashBlock) == 0 || tx.vout.size() == 1 || (DecodePaymentsOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,lockedblocks,minrelease,totalallocations,txidoprets) == 0 && DecodePaymentsSnapsShotOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,lockedblocks,minrelease,minimum,top,bottom,fixedAmount,excludeScriptPubKeys) == 0 && DecodePaymentsTokensOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,lockedblocks,minrelease,top,excludeScriptPubKeys,tokenid) == 0) ) { result.push_back(Pair("result","error")); result.push_back(Pair("error","invalid createtxid")); @@ -942,6 +999,64 @@ UniValue PaymentsFund(struct CCcontract_info *cp,char *jsonstr) return(result); } +UniValue PaymentsMerge(struct CCcontract_info *cp,char *jsonstr) +{ + CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); UniValue result(UniValue::VOBJ); + CPubKey Paymentspk,mypk,txidpk; uint256 createtxid,hashBlock; int64_t totalallocations,inputsum; CScript opret; CTransaction tx; char txidaddr[64],destaddr[64]; std::string rawtx; + int32_t n,useopret = 0,lockedblocks,minrelease,top,bottom,minimum=10000,blocksleft; std::vector txidoprets; + std::vector> excludeScriptPubKeys; // snapshot + uint256 tokenid; int8_t fixedAmount; + cJSON *params = payments_reparse(&n,jsonstr); + mypk = pubkey2pk(Mypubkey()); + Paymentspk = GetUnspendable(cp,0); + if ( params != 0 && n == 1 ) + { + createtxid = payments_juint256(jitem(params,0)); + txidpk = CCtxidaddr(txidaddr,createtxid); + if ( myGetTransaction(createtxid,tx,hashBlock) == 0 || tx.vout.size() == 1 || (DecodePaymentsOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,lockedblocks,minrelease,totalallocations,txidoprets) == 0 && DecodePaymentsSnapsShotOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,lockedblocks,minrelease,minimum,top,bottom,fixedAmount,excludeScriptPubKeys) == 0 && DecodePaymentsTokensOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,lockedblocks,minrelease,top,excludeScriptPubKeys,tokenid) == 0) ) + { + result.push_back(Pair("result","error")); + result.push_back(Pair("error","invalid createtxid")); + } + else if ( (inputsum= AddPaymentsInputs(true,4,cp,mtx,txidpk,0,CC_MAXVINS,createtxid,lockedblocks,minrelease,blocksleft)) > 0 && mtx.vin.size() > 1 ) + { + int32_t dust = blocksleft; + if ( mtx.vin.size() != dust+1 ) + { + result.push_back(Pair("result","error")); + result.push_back(Pair("error","cannot merge only dust")); + } + else + { + // encode the checktxid into the end of the ccvout, along with 'M' to flag merge type tx. + opret = EncodePaymentsMergeOpRet(createtxid); + std::vector> vData = std::vector>(); + if ( makeCCopret(opret, vData) ) + mtx.vout.push_back(MakeCC1vout(EVAL_PAYMENTS,inputsum-PAYMENTS_TXFEE,Paymentspk,&vData)); + GetCCaddress1of2(cp,destaddr,Paymentspk,txidpk); + CCaddr1of2set(cp,Paymentspk,txidpk,cp->CCpriv,destaddr); + rawtx = FinalizeCCTx(0,cp,mtx,mypk,PAYMENTS_TXFEE,CScript()); + if ( params != 0 ) + free_json(params); + return(payments_rawtxresult(result,rawtx,1)); + } + } + else + { + result.push_back(Pair("result","error")); + result.push_back(Pair("error","couldnt find enough funds")); + } + } + else + { + result.push_back(Pair("result","error")); + result.push_back(Pair("error","parameters error")); + } + if ( params != 0 ) + free_json(params); + return(result); +} + UniValue PaymentsTxidopret(struct CCcontract_info *cp,char *jsonstr) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); UniValue result(UniValue::VOBJ); CPubKey mypk; std::string rawtx; @@ -1062,7 +1177,7 @@ UniValue PaymentsAirdrop(struct CCcontract_info *cp,char *jsonstr) CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); UniValue result(UniValue::VOBJ); uint256 hashBlock; CTransaction tx; CPubKey Paymentspk,mypk; char markeraddr[64]; std::string rawtx; - int32_t lockedblocks,minrelease,top,bottom,n,i; std::vector> excludeScriptPubKeys; int8_t fixedAmount; + int32_t lockedblocks,minrelease,top,bottom,n,i,minimum=10000; std::vector> excludeScriptPubKeys; int8_t fixedAmount; if ( KOMODO_SNAPSHOT_INTERVAL == 0 ) { result.push_back(Pair("result","error")); @@ -1074,10 +1189,11 @@ UniValue PaymentsAirdrop(struct CCcontract_info *cp,char *jsonstr) { lockedblocks = juint(jitem(params,0),0); minrelease = juint(jitem(params,1),0); - top = juint(jitem(params,2),0); - bottom = juint(jitem(params,3),0); - fixedAmount = juint(jitem(params,4),0); // fixed amount is a flag set to 0 or 1. It means allocations are equal rather than weighted by address balance. - if ( lockedblocks < 0 || minrelease < 0 || top <= 0 || bottom < 0 || fixedAmount < 0 || top > 3999 ) + minimum = juint(jitem(params,2),0); + top = juint(jitem(params,3),0); + bottom = juint(jitem(params,4),0); + fixedAmount = juint(jitem(params,5),0); // fixed amount is a flag, set to 7 does game mode, 0 normal snapshot, anything else fixed allocations. + if ( lockedblocks < 0 || minrelease < 0 || top <= 0 || bottom < 0 || minimum < 0 || fixedAmount < 0 || top > 3999 ) { result.push_back(Pair("result","error")); result.push_back(Pair("error","negative parameter, or top over 3999")); @@ -1085,15 +1201,15 @@ UniValue PaymentsAirdrop(struct CCcontract_info *cp,char *jsonstr) free_json(params); return(result); } - if ( n > 5 ) + if ( n > 6 ) { - for (i=0; i scriptPubKey; int32_t len = strlen(inputhex)/2; scriptPubKey.resize(len); @@ -1106,7 +1222,16 @@ UniValue PaymentsAirdrop(struct CCcontract_info *cp,char *jsonstr) if ( AddNormalinputs(mtx,mypk,2*PAYMENTS_TXFEE,60) > 0 ) { mtx.vout.push_back(MakeCC1of2vout(cp->evalcode,PAYMENTS_TXFEE,Paymentspk,Paymentspk)); - rawtx = FinalizeCCTx(0,cp,mtx,mypk,PAYMENTS_TXFEE,EncodePaymentsSnapsShotOpRet(lockedblocks,minrelease,top,bottom,fixedAmount,excludeScriptPubKeys)); + CScript tempopret = EncodePaymentsSnapsShotOpRet(lockedblocks,minrelease,minimum,top,bottom,fixedAmount,excludeScriptPubKeys); + if ( tempopret.size() > 10000 ) // TODO: Check this! + { + result.push_back(Pair("result","error")); + result.push_back(Pair("error","op_return is too big, try with less exclude addresses.")); + if ( params != 0 ) + free_json(params); + return(result); + } + rawtx = FinalizeCCTx(0,cp,mtx,mypk,PAYMENTS_TXFEE,tempopret); if ( params != 0 ) free_json(params); return(payments_rawtxresult(result,rawtx,1)); @@ -1127,7 +1252,7 @@ UniValue PaymentsAirdrop(struct CCcontract_info *cp,char *jsonstr) UniValue PaymentsInfo(struct CCcontract_info *cp,char *jsonstr) { UniValue result(UniValue::VOBJ),a(UniValue::VARR); CTransaction tx,txO; CPubKey Paymentspk,txidpk; int32_t i,j,n,flag=0,numoprets=0,lockedblocks,minrelease,blocksleft=0; std::vector txidoprets; int64_t funds,fundsopret,elegiblefunds,totalallocations=0,allocation; char fundsaddr[64],fundsopretaddr[64],txidaddr[64],*outstr; uint256 createtxid,hashBlock; - int32_t top,bottom; std::vector> excludeScriptPubKeys; // snapshot + int32_t top,bottom,minimum=10000; std::vector> excludeScriptPubKeys; // snapshot uint256 tokenid; int8_t fixedAmount; CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(),komodo_nextheight()); cJSON *params = payments_reparse(&n,jsonstr); if ( params != 0 && n == 1 ) @@ -1183,9 +1308,9 @@ UniValue PaymentsInfo(struct CCcontract_info *cp,char *jsonstr) result.push_back(Pair("error","too many opreturns")); } else result.push_back(Pair("txidoprets",a)); } - else if ( DecodePaymentsSnapsShotOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,lockedblocks,minrelease,top,bottom,fixedAmount,excludeScriptPubKeys) != 0 ) + else if ( DecodePaymentsSnapsShotOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,lockedblocks,minrelease,minimum,top,bottom,fixedAmount,excludeScriptPubKeys) != 0 ) { - if ( lockedblocks < 0 || minrelease < 0 || top <= 0 || bottom < 0 || fixedAmount < 0 || top > 3999 ) + if ( lockedblocks < 0 || minrelease < 0 || top <= 0 || bottom < 0 || fixedAmount < 0 || top > 3999 || minimum < 10000 ) { result.push_back(Pair("result","error")); result.push_back(Pair("error","negative parameter")); @@ -1198,7 +1323,8 @@ UniValue PaymentsInfo(struct CCcontract_info *cp,char *jsonstr) else result.push_back(Pair("plan_type","snapshot")); result.push_back(Pair("lockedblocks",(int64_t)lockedblocks)); - result.push_back(Pair("minrelease",(int64_t)minrelease)); + result.push_back(Pair("minrelease",(int64_t)minrelease)); + result.push_back(Pair("minimum",(int64_t)minimum)); result.push_back(Pair("bottom",(int64_t)bottom)); result.push_back(Pair("top",(int64_t)top)); result.push_back(Pair("fixedFlag",(int64_t)fixedAmount)); @@ -1272,7 +1398,7 @@ UniValue PaymentsList(struct CCcontract_info *cp,char *jsonstr) { std::vector > addressIndex; uint256 txid,hashBlock,tokenid; UniValue result(UniValue::VOBJ),a(UniValue::VARR); char markeraddr[64],str[65]; CPubKey Paymentspk; CTransaction tx; int32_t lockedblocks,minrelease; std::vector txidoprets; int64_t totalallocations=0; - int32_t top=0,bottom=0; std::vector> excludeScriptPubKeys; int8_t fixedAmount = 0; + int32_t top=0,bottom=0,minimum=10000; std::vector> excludeScriptPubKeys; int8_t fixedAmount = 0; Paymentspk = GetUnspendable(cp,0); GetCCaddress1of2(cp,markeraddr,Paymentspk,Paymentspk); SetCCtxids(addressIndex,markeraddr,true); @@ -1281,9 +1407,9 @@ UniValue PaymentsList(struct CCcontract_info *cp,char *jsonstr) txid = it->first.txhash; if ( it->first.index == 0 && myGetTransaction(txid,tx,hashBlock) != 0 ) { - if ( tx.vout.size() > 0 && (DecodePaymentsOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,lockedblocks,minrelease,totalallocations,txidoprets) == 'C' || DecodePaymentsSnapsShotOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,lockedblocks,minrelease,top,bottom,fixedAmount,excludeScriptPubKeys) == 'S' || DecodePaymentsTokensOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,lockedblocks,minrelease,top,excludeScriptPubKeys,tokenid) == 'O') ) + if ( tx.vout.size() > 0 && (DecodePaymentsOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,lockedblocks,minrelease,totalallocations,txidoprets) == 'C' || DecodePaymentsSnapsShotOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,lockedblocks,minrelease,minimum,top,bottom,fixedAmount,excludeScriptPubKeys) == 'S' || DecodePaymentsTokensOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,lockedblocks,minrelease,top,excludeScriptPubKeys,tokenid) == 'O') ) { - if ( lockedblocks < 0 || minrelease < 0 || (totalallocations <= 0 && top <= 0 ) || bottom < 0 || fixedAmount < 0 ) + if ( lockedblocks < 0 || minrelease < 0 || (totalallocations <= 0 && top <= 0 ) || bottom < 0 || fixedAmount < 0 || minimum < 10000 ) { result.push_back(Pair("result","error")); result.push_back(Pair("error","negative parameter")); diff --git a/src/main.h b/src/main.h index d507f9dd6..2592fc657 100644 --- a/src/main.h +++ b/src/main.h @@ -95,7 +95,7 @@ static const unsigned int MAX_TEMPFILE_SIZE = 0x1000000; // 16 MiB 0x8000000 /** The pre-allocation chunk size for blk?????.dat files (since 0.8) */ static const unsigned int BLOCKFILE_CHUNK_SIZE = 0x1000000; // 16 MiB /** The pre-allocation chunk size for rev?????.dat files (since 0.8) */ -static const unsigned int UNDOFILE_CHUNK_SIZE = 0x100000; // 1 MiB +static const unsigned int UNDOFILE_CHUNK_SIZE = 0x1000000; // 16 MiB /** Maximum number of script-checking threads allowed */ static const int MAX_SCRIPTCHECK_THREADS = 16; /** -par default (number of script-checking threads, 0 = auto) */ diff --git a/src/rpc/server.cpp b/src/rpc/server.cpp index 414add201..b1359ef15 100644 --- a/src/rpc/server.cpp +++ b/src/rpc/server.cpp @@ -487,6 +487,7 @@ static const CRPCCommand vRPCCommands[] = { "payments", "paymentslist", &payments_list, true }, { "payments", "paymentsinfo", &payments_info, true }, { "payments", "paymentsfund", &payments_fund, true }, + { "payments", "paymentsmerge", &payments_merge, true }, { "payments", "paymentsrelease", &payments_release, true }, { "CClib", "cclibaddress", &cclibaddress, true }, diff --git a/src/rpc/server.h b/src/rpc/server.h index b674ee909..5ec7640f2 100644 --- a/src/rpc/server.h +++ b/src/rpc/server.h @@ -287,6 +287,7 @@ extern UniValue marmara_lock(const UniValue& params, bool fHelp); extern UniValue paymentsaddress(const UniValue& params, bool fHelp); extern UniValue payments_release(const UniValue& params, bool fHelp); extern UniValue payments_fund(const UniValue& params, bool fHelp); +extern UniValue payments_merge(const UniValue& params, bool fHelp); extern UniValue payments_txidopret(const UniValue& params, bool fHelp); extern UniValue payments_create(const UniValue& params, bool fHelp); extern UniValue payments_airdrop(const UniValue& params, bool fHelp); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 888c60e0e..aff740e31 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5603,6 +5603,19 @@ UniValue payments_fund(const UniValue& params, bool fHelp) return(PaymentsFund(cp,(char *)params[0].get_str().c_str())); } +UniValue payments_merge(const UniValue& params, bool fHelp) +{ + struct CCcontract_info *cp,C; + if ( fHelp || params.size() != 1 ) + throw runtime_error("paymentsmerge \"[%22createtxid%22]\"\n"); + if ( ensure_CCrequirements(EVAL_PAYMENTS) < 0 ) + throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + const CKeyStore& keystore = *pwalletMain; + LOCK2(cs_main, pwalletMain->cs_wallet); + cp = CCinit(&C,EVAL_PAYMENTS); + return(PaymentsMerge(cp,(char *)params[0].get_str().c_str())); +} + UniValue payments_txidopret(const UniValue& params, bool fHelp) { struct CCcontract_info *cp,C; @@ -5633,7 +5646,7 @@ UniValue payments_airdrop(const UniValue& params, bool fHelp) { struct CCcontract_info *cp,C; if ( fHelp || params.size() != 1 ) - throw runtime_error("paymentsairdrop \"[lockedblocks,minamount,top,bottom,fixedFlag,%22excludeAddress%22,...,%22excludeAddressN%22]\"\n"); + throw runtime_error("paymentsairdrop \"[lockedblocks,minamount,mintoaddress,top,bottom,fixedFlag,%22excludeAddress%22,...,%22excludeAddressN%22]\"\n"); if ( ensure_CCrequirements(EVAL_PAYMENTS) < 0 ) throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); const CKeyStore& keystore = *pwalletMain; From 4f03f020426120cec1a93337a9fa013747fab160 Mon Sep 17 00:00:00 2001 From: Alrighttt Date: Sun, 5 May 2019 22:16:19 +0200 Subject: [PATCH 228/447] oraclessamples 0 to return all samples --- src/cc/oracles.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/oracles.cpp b/src/cc/oracles.cpp index 53148bba9..a5d61d404 100644 --- a/src/cc/oracles.cpp +++ b/src/cc/oracles.cpp @@ -959,7 +959,7 @@ UniValue OracleDataSamples(uint256 reforacletxid,uint256 batontxid,int32_t num) a.push_back(uint256_str(str,batontxid)); b.push_back(a); batontxid = btxid; - if ( ++n >= num ) + if ( ++n >= num && num != 0) break; } else break; } From e5907e31a6c0ceb8368e8af260c6ae903207100b Mon Sep 17 00:00:00 2001 From: Alrighttt Date: Sun, 5 May 2019 22:14:32 +0000 Subject: [PATCH 229/447] add oracles non-final oracle changes --- src/cc/oracles.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/cc/oracles.cpp b/src/cc/oracles.cpp index ef457fe82..a5d61d404 100644 --- a/src/cc/oracles.cpp +++ b/src/cc/oracles.cpp @@ -935,13 +935,13 @@ UniValue OracleFormat(uint8_t *data,int32_t datalen,char *format,int32_t formatl if ( j >= datalen ) break; } - return(obj); + return(str); } UniValue OracleDataSamples(uint256 reforacletxid,uint256 batontxid,int32_t num) { - UniValue result(UniValue::VOBJ),a(UniValue::VARR); CTransaction tx,oracletx; uint256 hashBlock,btxid,oracletxid; - CPubKey pk; std::string name,description,format; int32_t numvouts,n=0; std::vector data; char *formatstr = 0; + UniValue result(UniValue::VOBJ),b(UniValue::VARR); CTransaction tx,oracletx; uint256 hashBlock,btxid,oracletxid; + CPubKey pk; std::string name,description,format; int32_t numvouts,n=0; std::vector data; char str[67], *formatstr = 0; result.push_back(Pair("result","success")); if ( GetTransaction(reforacletxid,oracletx,hashBlock,false) != 0 && (numvouts=oracletx.vout.size()) > 0 ) @@ -954,15 +954,18 @@ UniValue OracleDataSamples(uint256 reforacletxid,uint256 batontxid,int32_t num) { if ( (formatstr= (char *)format.c_str()) == 0 ) formatstr = (char *)""; + UniValue a(UniValue::VARR); a.push_back(OracleFormat((uint8_t *)data.data(),(int32_t)data.size(),formatstr,(int32_t)format.size())); + a.push_back(uint256_str(str,batontxid)); + b.push_back(a); batontxid = btxid; - if ( ++n >= num ) + if ( ++n >= num && num != 0) break; } else break; } } } - result.push_back(Pair("samples",a)); + result.push_back(Pair("samples",b)); return(result); } From 0f6fe03990f79ec4ddb9acf763ea817ea57a7fb2 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 6 May 2019 12:08:53 +0800 Subject: [PATCH 230/447] fix --- src/cc/CCutils.cpp | 3 ++- src/cc/payments.cpp | 23 ++++++++++++----------- src/chain.h | 4 ++-- src/komodo_nk.h | 4 ++-- 4 files changed, 18 insertions(+), 16 deletions(-) diff --git a/src/cc/CCutils.cpp b/src/cc/CCutils.cpp index 5fe7d662b..363b54ad5 100644 --- a/src/cc/CCutils.cpp +++ b/src/cc/CCutils.cpp @@ -63,7 +63,8 @@ int32_t has_opret(const CTransaction &tx, uint8_t evalcode) int i = 0; for ( auto vout : tx.vout ) { - if ( vout.scriptPubKey[0] == OP_RETURN && vout.scriptPubKey[1] == evalcode ) + //fprintf(stderr, "[txid.%s] 1.%i 2.%i 3.%i 4.%i\n",tx.GetHash().GetHex().c_str(), vout.scriptPubKey[0], vout.scriptPubKey[1], vout.scriptPubKey[2], vout.scriptPubKey[3]); + if ( vout.scriptPubKey[0] == OP_RETURN && vout.scriptPubKey[2] == evalcode ) return i; i++; } diff --git a/src/cc/payments.cpp b/src/cc/payments.cpp index e42da664f..eda1bdb41 100644 --- a/src/cc/payments.cpp +++ b/src/cc/payments.cpp @@ -303,7 +303,7 @@ bool PaymentsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction & pub2createtxid(temp); createtxid = Parseuint256(temp); } - //printf("createtxid.%s\n",createtxid.ToString().c_str()); + printf("createtxid.%s\n",createtxid.ToString().c_str()); // use the createtxid to fetch the tx and all of the plans info. if ( myGetTransaction(createtxid,plantx,blockhash) != 0 && plantx.vout.size() > 0 ) @@ -501,7 +501,7 @@ bool PaymentsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction & { mergeoffset = PAYMENTS_MERGEOFSET; } - fprintf(stderr, "mergeoffset.%i\n", mergeoffset); + //fprintf(stderr, "mergeoffset.%i\n", mergeoffset); // check the chain depth vs locked blocks requirement. if ( !payments_lockedblocks(blockhash, lockedblocks+mergeoffset, blocksleft) ) return(eval->Invalid("vin not elegible")); @@ -576,16 +576,16 @@ int64_t AddPaymentsInputs(bool fLockedBlocks,int8_t GetBalance,struct CCcontract if ( (nValue= IsPaymentsvout(cp,vintx,vout,coinaddr,ccopret)) > PAYMENTS_TXFEE && nValue >= threshold && myIsutxo_spentinmempool(ignoretxid,ignorevin,txid,vout) == 0 ) { int32_t tmpblocksleft = 0; - if ( (GetBalance == 0 && total != 0 && maxinputs != 0) || GetBalance == 4 ) - mtx.vin.push_back(CTxIn(txid,vout,CScript())); - nValue = it->second.satoshis; - if ( nValue < COIN ) - blocksleft++; // count dust with unused variable. if ( fLockedBlocks && !payments_lockedblocks(hashBlock, lockedblocks+(GetBalance == 4 ? PAYMENTS_MERGEOFSET : 0), tmpblocksleft) ) { blocksleft_balance.push_back(std::make_pair(tmpblocksleft,nValue)); continue; } + if ( (GetBalance == 0 && total != 0 && maxinputs != 0) || GetBalance == 4 ) + mtx.vin.push_back(CTxIn(txid,vout,CScript())); + nValue = it->second.satoshis; + if ( nValue < COIN ) + blocksleft++; // count dust with unused variable. totalinputs += nValue; n++; //fprintf(stderr,"iter.%d %s/v%d %s %.8f\n",iter,txid.GetHex().c_str(),vout,coinaddr,(double)nValue/COIN); @@ -1021,24 +1021,25 @@ UniValue PaymentsMerge(struct CCcontract_info *cp,char *jsonstr) else if ( (inputsum= AddPaymentsInputs(true,4,cp,mtx,txidpk,0,CC_MAXVINS,createtxid,lockedblocks,minrelease,blocksleft)) > 0 && mtx.vin.size() > 1 ) { int32_t dust = blocksleft; - if ( mtx.vin.size() != dust+1 ) + if ( mtx.vin.size() == dust+1 ) { result.push_back(Pair("result","error")); result.push_back(Pair("error","cannot merge only dust")); } else - { + { // encode the checktxid into the end of the ccvout, along with 'M' to flag merge type tx. opret = EncodePaymentsMergeOpRet(createtxid); std::vector> vData = std::vector>(); if ( makeCCopret(opret, vData) ) - mtx.vout.push_back(MakeCC1vout(EVAL_PAYMENTS,inputsum-PAYMENTS_TXFEE,Paymentspk,&vData)); + mtx.vout.push_back(MakeCC1of2vout(EVAL_PAYMENTS,inputsum-PAYMENTS_TXFEE,Paymentspk,txidpk,&vData)); + //mtx.vout.push_back(MakeCC1vout(EVAL_PAYMENTS,inputsum-PAYMENTS_TXFEE,txidpk,&vData)); GetCCaddress1of2(cp,destaddr,Paymentspk,txidpk); CCaddr1of2set(cp,Paymentspk,txidpk,cp->CCpriv,destaddr); rawtx = FinalizeCCTx(0,cp,mtx,mypk,PAYMENTS_TXFEE,CScript()); if ( params != 0 ) free_json(params); - return(payments_rawtxresult(result,rawtx,1)); + return(payments_rawtxresult(result,rawtx,0)); } } else diff --git a/src/chain.h b/src/chain.h index 4e5d7e48d..b893e3a06 100644 --- a/src/chain.h +++ b/src/chain.h @@ -38,7 +38,7 @@ static const int SPROUT_VALUE_VERSION = 1001400; static const int SAPLING_VALUE_VERSION = 1010100; extern int32_t ASSETCHAINS_LWMAPOS; extern char ASSETCHAINS_SYMBOL[65]; -//extern uint64_t ASSETCHAINS_NOTARY_PAY; +extern uint64_t ASSETCHAINS_NOTARY_PAY[]; struct CDiskBlockPos { @@ -547,7 +547,7 @@ public: if ((s.GetType() & SER_DISK) && (nVersion >= SAPLING_VALUE_VERSION)) { READWRITE(nSaplingValue); } - if ( (s.GetType() & SER_DISK) && (is_STAKED(ASSETCHAINS_SYMBOL) != 0) ) + if ( (s.GetType() & SER_DISK) && (is_STAKED(ASSETCHAINS_SYMBOL) != 0) && ASSETCHAINS_NOTARY_PAY[0] != 0 ) { READWRITE(nNotaryPay); READWRITE(segid); diff --git a/src/komodo_nk.h b/src/komodo_nk.h index ed994c13f..3c9034dde 100644 --- a/src/komodo_nk.h +++ b/src/komodo_nk.h @@ -1,7 +1,7 @@ #ifndef KOMODO_NK_H #define KOMODO_NK_H -#define ASSETCHAINS_N 77 -#define ASSETCHAINS_K 3 +#define ASSETCHAINS_N 96 +#define ASSETCHAINS_K 5 #endif From 6e7b2363be01eb7cb33d4322b2cb92964bdf60a7 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 6 May 2019 12:13:17 +0800 Subject: [PATCH 231/447] undo stuff --- src/chain.h | 2 +- src/komodo_nk.h | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/chain.h b/src/chain.h index b893e3a06..ac60dc277 100644 --- a/src/chain.h +++ b/src/chain.h @@ -547,7 +547,7 @@ public: if ((s.GetType() & SER_DISK) && (nVersion >= SAPLING_VALUE_VERSION)) { READWRITE(nSaplingValue); } - if ( (s.GetType() & SER_DISK) && (is_STAKED(ASSETCHAINS_SYMBOL) != 0) && ASSETCHAINS_NOTARY_PAY[0] != 0 ) + if ( (s.GetType() & SER_DISK) && (is_STAKED(ASSETCHAINS_SYMBOL) != 0) )// && ASSETCHAINS_NOTARY_PAY[0] != 0 ) { READWRITE(nNotaryPay); READWRITE(segid); diff --git a/src/komodo_nk.h b/src/komodo_nk.h index 3c9034dde..708e8ba6c 100644 --- a/src/komodo_nk.h +++ b/src/komodo_nk.h @@ -1,7 +1,10 @@ #ifndef KOMODO_NK_H #define KOMODO_NK_H -#define ASSETCHAINS_N 96 -#define ASSETCHAINS_K 5 +#define ASSETCHAINS_N 77 +#define ASSETCHAINS_K 3 + +//#define ASSETCHAINS_N 95 +//#define ASSETCHAINS_K 5 #endif From ab6e923cfb58911f12975f56ad574284ea058ad2 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 6 May 2019 14:54:59 +0800 Subject: [PATCH 232/447] fixes --- src/cc/payments.cpp | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/src/cc/payments.cpp b/src/cc/payments.cpp index eda1bdb41..12d5cff62 100644 --- a/src/cc/payments.cpp +++ b/src/cc/payments.cpp @@ -303,7 +303,7 @@ bool PaymentsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction & pub2createtxid(temp); createtxid = Parseuint256(temp); } - printf("createtxid.%s\n",createtxid.ToString().c_str()); + //printf("createtxid.%s\n",createtxid.ToString().c_str()); // use the createtxid to fetch the tx and all of the plans info. if ( myGetTransaction(createtxid,plantx,blockhash) != 0 && plantx.vout.size() > 0 ) @@ -496,7 +496,7 @@ bool PaymentsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction & fprintf(stderr, "vin.%i is not a payments CC vout: txid.%s\n", i, txin.GetHash().ToString().c_str()); return(eval->Invalid("vin is not paymentsCC type")); } - } + } else if ( fIsMerge && getCCopret(txin.vout[vin.prevout.n].scriptPubKey,opret) && opret.size() > 2 && DecodePaymentsMergeOpRet(opret,checktxid) == 'M' ) { mergeoffset = PAYMENTS_MERGEOFSET; @@ -514,7 +514,7 @@ bool PaymentsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction & return(eval->Invalid("must have at least 2 vins to carry out merge")); else if ( i == dust+1 ) return(eval->Invalid("cannot merge only dust")); - } + } } else return(eval->Invalid("create transaction cannot decode")); } else return(eval->Invalid("Could not get contract transaction")); return(true); @@ -595,7 +595,7 @@ int64_t AddPaymentsInputs(bool fLockedBlocks,int8_t GetBalance,struct CCcontract } } } - if ( GetBalance == 3 ) // return elegible balance to be spent, and blocks left until min release can be released. + if ( GetBalance == 3 && totalinputs < minrelease ) // return elegible balance to be spent, and blocks left until min release can be released. { int64_t lockedblocks_balance = totalinputs; // inputs that can be spent already. // sort utxos by blocks until able to be spent, smallest at top. @@ -800,7 +800,6 @@ UniValue PaymentsRelease(struct CCcontract_info *cp,char *jsonstr) return(result); } i = 0; - //for ( auto address : vAddressSnapshot ) if ( fixedAmount == 7 ) { // game setting, randomise bottom and top values @@ -846,7 +845,6 @@ UniValue PaymentsRelease(struct CCcontract_info *cp,char *jsonstr) newamount = amount; int64_t totalamountsent = 0; mpz_t mpzAmount; mpz_init(mpzAmount); mpz_set_si(mpzAmount,amount); - fprintf(stderr, "m.%i\n",m); for (i=0; i txidoprets; + CPubKey Paymentspk,mypk,txidpk; uint256 createtxid,hashBlock; int64_t inputsum,totalallocations=0; CScript opret; CTransaction tx; char txidaddr[64],destaddr[64]; std::string rawtx; + int32_t n,lockedblocks,minrelease,top,bottom,minimum=10000,blocksleft; std::vector txidoprets; std::vector> excludeScriptPubKeys; // snapshot uint256 tokenid; int8_t fixedAmount; cJSON *params = payments_reparse(&n,jsonstr); @@ -1033,7 +1031,6 @@ UniValue PaymentsMerge(struct CCcontract_info *cp,char *jsonstr) std::vector> vData = std::vector>(); if ( makeCCopret(opret, vData) ) mtx.vout.push_back(MakeCC1of2vout(EVAL_PAYMENTS,inputsum-PAYMENTS_TXFEE,Paymentspk,txidpk,&vData)); - //mtx.vout.push_back(MakeCC1vout(EVAL_PAYMENTS,inputsum-PAYMENTS_TXFEE,txidpk,&vData)); GetCCaddress1of2(cp,destaddr,Paymentspk,txidpk); CCaddr1of2set(cp,Paymentspk,txidpk,cp->CCpriv,destaddr); rawtx = FinalizeCCTx(0,cp,mtx,mypk,PAYMENTS_TXFEE,CScript()); @@ -1364,12 +1361,9 @@ UniValue PaymentsInfo(struct CCcontract_info *cp,char *jsonstr) txidpk = CCtxidaddr(txidaddr,createtxid); GetCCaddress1of2(cp,fundsaddr,Paymentspk,txidpk); funds = AddPaymentsInputs(false,2,cp,mtx,txidpk,0,CC_MAXVINS,createtxid,lockedblocks,minrelease,blocksleft); - //CCaddress_balance(fundsaddr,1); result.push_back(Pair(fundsaddr,ValueFromAmount(funds))); GetCCaddress(cp,fundsopretaddr,Paymentspk); - // TODO: Shows balance for ALL payments plans, not just the one asked for! Needs to be reworked. fundsopret = AddPaymentsInputs(false,1,cp,mtx,txidpk,0,CC_MAXVINS,createtxid,lockedblocks,minrelease,blocksleft); - //CCaddress_balance(fundsopretaddr,1); result.push_back(Pair(fundsopretaddr,ValueFromAmount(fundsopret))); result.push_back(Pair("totalfunds",ValueFromAmount(funds+fundsopret))); // Blocks until minrelease can be released. From 891a2102ba2e11b41b018f1c4f16915c1576b6d8 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 6 May 2019 14:54:59 +0800 Subject: [PATCH 233/447] fixes --- src/cc/payments.cpp | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/src/cc/payments.cpp b/src/cc/payments.cpp index eda1bdb41..12d5cff62 100644 --- a/src/cc/payments.cpp +++ b/src/cc/payments.cpp @@ -303,7 +303,7 @@ bool PaymentsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction & pub2createtxid(temp); createtxid = Parseuint256(temp); } - printf("createtxid.%s\n",createtxid.ToString().c_str()); + //printf("createtxid.%s\n",createtxid.ToString().c_str()); // use the createtxid to fetch the tx and all of the plans info. if ( myGetTransaction(createtxid,plantx,blockhash) != 0 && plantx.vout.size() > 0 ) @@ -496,7 +496,7 @@ bool PaymentsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction & fprintf(stderr, "vin.%i is not a payments CC vout: txid.%s\n", i, txin.GetHash().ToString().c_str()); return(eval->Invalid("vin is not paymentsCC type")); } - } + } else if ( fIsMerge && getCCopret(txin.vout[vin.prevout.n].scriptPubKey,opret) && opret.size() > 2 && DecodePaymentsMergeOpRet(opret,checktxid) == 'M' ) { mergeoffset = PAYMENTS_MERGEOFSET; @@ -514,7 +514,7 @@ bool PaymentsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction & return(eval->Invalid("must have at least 2 vins to carry out merge")); else if ( i == dust+1 ) return(eval->Invalid("cannot merge only dust")); - } + } } else return(eval->Invalid("create transaction cannot decode")); } else return(eval->Invalid("Could not get contract transaction")); return(true); @@ -595,7 +595,7 @@ int64_t AddPaymentsInputs(bool fLockedBlocks,int8_t GetBalance,struct CCcontract } } } - if ( GetBalance == 3 ) // return elegible balance to be spent, and blocks left until min release can be released. + if ( GetBalance == 3 && totalinputs < minrelease ) // return elegible balance to be spent, and blocks left until min release can be released. { int64_t lockedblocks_balance = totalinputs; // inputs that can be spent already. // sort utxos by blocks until able to be spent, smallest at top. @@ -800,7 +800,6 @@ UniValue PaymentsRelease(struct CCcontract_info *cp,char *jsonstr) return(result); } i = 0; - //for ( auto address : vAddressSnapshot ) if ( fixedAmount == 7 ) { // game setting, randomise bottom and top values @@ -846,7 +845,6 @@ UniValue PaymentsRelease(struct CCcontract_info *cp,char *jsonstr) newamount = amount; int64_t totalamountsent = 0; mpz_t mpzAmount; mpz_init(mpzAmount); mpz_set_si(mpzAmount,amount); - fprintf(stderr, "m.%i\n",m); for (i=0; i txidoprets; + CPubKey Paymentspk,mypk,txidpk; uint256 createtxid,hashBlock; int64_t inputsum,totalallocations=0; CScript opret; CTransaction tx; char txidaddr[64],destaddr[64]; std::string rawtx; + int32_t n,lockedblocks,minrelease,top,bottom,minimum=10000,blocksleft; std::vector txidoprets; std::vector> excludeScriptPubKeys; // snapshot uint256 tokenid; int8_t fixedAmount; cJSON *params = payments_reparse(&n,jsonstr); @@ -1033,7 +1031,6 @@ UniValue PaymentsMerge(struct CCcontract_info *cp,char *jsonstr) std::vector> vData = std::vector>(); if ( makeCCopret(opret, vData) ) mtx.vout.push_back(MakeCC1of2vout(EVAL_PAYMENTS,inputsum-PAYMENTS_TXFEE,Paymentspk,txidpk,&vData)); - //mtx.vout.push_back(MakeCC1vout(EVAL_PAYMENTS,inputsum-PAYMENTS_TXFEE,txidpk,&vData)); GetCCaddress1of2(cp,destaddr,Paymentspk,txidpk); CCaddr1of2set(cp,Paymentspk,txidpk,cp->CCpriv,destaddr); rawtx = FinalizeCCTx(0,cp,mtx,mypk,PAYMENTS_TXFEE,CScript()); @@ -1364,12 +1361,9 @@ UniValue PaymentsInfo(struct CCcontract_info *cp,char *jsonstr) txidpk = CCtxidaddr(txidaddr,createtxid); GetCCaddress1of2(cp,fundsaddr,Paymentspk,txidpk); funds = AddPaymentsInputs(false,2,cp,mtx,txidpk,0,CC_MAXVINS,createtxid,lockedblocks,minrelease,blocksleft); - //CCaddress_balance(fundsaddr,1); result.push_back(Pair(fundsaddr,ValueFromAmount(funds))); GetCCaddress(cp,fundsopretaddr,Paymentspk); - // TODO: Shows balance for ALL payments plans, not just the one asked for! Needs to be reworked. fundsopret = AddPaymentsInputs(false,1,cp,mtx,txidpk,0,CC_MAXVINS,createtxid,lockedblocks,minrelease,blocksleft); - //CCaddress_balance(fundsopretaddr,1); result.push_back(Pair(fundsopretaddr,ValueFromAmount(fundsopret))); result.push_back(Pair("totalfunds",ValueFromAmount(funds+fundsopret))); // Blocks until minrelease can be released. From b2de7d1ae26b42fc2bbd3c7191dddf0c8a42b585 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 6 May 2019 15:35:25 +0800 Subject: [PATCH 234/447] remove some labs stuff --- src/cc/CCtx.cpp | 2 +- src/cc/makecclib | 16 ++++++++-------- src/cc/makecustom | 7 +++---- src/wallet/db.h | 6 +++--- 4 files changed, 15 insertions(+), 16 deletions(-) diff --git a/src/cc/CCtx.cpp b/src/cc/CCtx.cpp index fe5fade71..7435defbf 100644 --- a/src/cc/CCtx.cpp +++ b/src/cc/CCtx.cpp @@ -241,7 +241,7 @@ std::string FinalizeCCTx(uint64_t CCmask,struct CCcontract_info *cp,CMutableTran { char coinaddr[64]; GetCCaddress1of2(cp,coinaddr,globalpk,pubkeys[i]); - fprintf(stderr,"%s + %s -> %s vs %s\n",HexStr(globalpk).c_str(),HexStr(pubkeys[i]).c_str(),coinaddr,destaddr); + //fprintf(stderr,"%s + %s -> %s vs %s\n",HexStr(globalpk).c_str(),HexStr(pubkeys[i]).c_str(),coinaddr,destaddr); if ( strcmp(destaddr,coinaddr) == 0 ) { privkey = cp->CCpriv; diff --git a/src/cc/makecclib b/src/cc/makecclib index 256d50995..e4816c55c 100755 --- a/src/cc/makecclib +++ b/src/cc/makecclib @@ -7,14 +7,14 @@ make -f Makefile_rogue rm ../libcc.so cp librogue.so ../libcc.so -#echo sudoku/musig/dilithium -#gcc -O3 -std=c++11 -I../secp256k1/include -I../univalue/include -I../cryptoconditions/include -I../cryptoconditions/src -I../cryptoconditions/src/asn -I.. -I. -fPIC -shared -c -o sudokucc.so cclib.cpp +echo sudoku/musig/dilithium +gcc -O3 -std=c++11 -I../secp256k1/include -I../univalue/include -I../cryptoconditions/include -I../cryptoconditions/src -I../cryptoconditions/src/asn -I.. -I. -fPIC -shared -c -o sudokucc.so cclib.cpp -#echo games tetris -#./maketetris +echo games tetris +./maketetris -#echo games prices -#./makeprices +echo games prices +./makeprices -#echo customcc stub -#gcc -O3 -DBUILD_CUSTOMCC -std=c++11 -I../secp256k1/include -I../univalue/include -I../cryptoconditions/include -I../cryptoconditions/src -I../cryptoconditions/src/asn -I.. -I. -fPIC -shared -c -o customcc.so cclib.cpp +echo customcc stub +gcc -O3 -DBUILD_CUSTOMCC -std=c++11 -I../secp256k1/include -I../univalue/include -I../cryptoconditions/include -I../cryptoconditions/src -I../cryptoconditions/src/asn -I.. -I. -fPIC -shared -c -o customcc.so cclib.cpp diff --git a/src/cc/makecustom b/src/cc/makecustom index 06f2f6fb1..154be4f31 100755 --- a/src/cc/makecustom +++ b/src/cc/makecustom @@ -1,7 +1,6 @@ #!/bin/sh gcc -O3 -DBUILD_CUSTOMCC -std=c++11 -I../secp256k1/include -I../univalue/include -I../cryptoconditions/include -I../cryptoconditions/src -I../cryptoconditions/src/asn -I.. -I. -fPIC -shared -c -o customcc.so cclib.cpp cp customcc.so ../libcc.so -#cd .. -#make -#cd cc - +cd .. +make +cd cc diff --git a/src/wallet/db.h b/src/wallet/db.h index 4af25c698..e1ae52909 100644 --- a/src/wallet/db.h +++ b/src/wallet/db.h @@ -33,9 +33,9 @@ #include -// CCLIB fails to compile with this! -//#include -#include "../depends/x86_64-unknown-linux-gnu/include/db_cxx.h" +// If CCLIB fails to compile with this, use the one below. +#include +//#include "../depends/x86_64-unknown-linux-gnu/include/db_cxx.h" extern unsigned int nWalletDBUpdated; From 69626ff68d078b25568d1f2b365431f1eb4a4871 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 6 May 2019 16:38:22 +0800 Subject: [PATCH 235/447] revert undo file size --- src/main.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.h b/src/main.h index 2592fc657..d507f9dd6 100644 --- a/src/main.h +++ b/src/main.h @@ -95,7 +95,7 @@ static const unsigned int MAX_TEMPFILE_SIZE = 0x1000000; // 16 MiB 0x8000000 /** The pre-allocation chunk size for blk?????.dat files (since 0.8) */ static const unsigned int BLOCKFILE_CHUNK_SIZE = 0x1000000; // 16 MiB /** The pre-allocation chunk size for rev?????.dat files (since 0.8) */ -static const unsigned int UNDOFILE_CHUNK_SIZE = 0x1000000; // 16 MiB +static const unsigned int UNDOFILE_CHUNK_SIZE = 0x100000; // 1 MiB /** Maximum number of script-checking threads allowed */ static const int MAX_SCRIPTCHECK_THREADS = 16; /** -par default (number of script-checking threads, 0 = auto) */ From 12b1040aaa839bb671030622740fa3ff43a2badb Mon Sep 17 00:00:00 2001 From: dimxy Date: Mon, 6 May 2019 15:21:21 +0500 Subject: [PATCH 236/447] changed total price index calc to big num --- src/cc/prices.cpp | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index cefc8c4e0..b1947a9b5 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -850,9 +850,13 @@ int64_t prices_syntheticprice(std::vector vec, int32_t height, int32_t { int32_t i, value, errcode, depth, retval = -1; uint16_t opcode; - int64_t *pricedata, pricestack[4], price, den, a, b, c; + int64_t *pricedata, pricestack[4], a, b, c; - mpz_t mpzA, mpzB, mpzC, mpzResult; + mpz_t mpzTotalPrice, mpzPriceValue, mpzDen, mpzA, mpzB, mpzC, mpzResult; + + mpz_init(mpzTotalPrice); + mpz_init(mpzPriceValue); + mpz_init(mpzDen); mpz_init(mpzA); mpz_init(mpzB); @@ -860,7 +864,7 @@ int64_t prices_syntheticprice(std::vector vec, int32_t height, int32_t mpz_init(mpzResult); pricedata = (int64_t *)calloc(sizeof(*pricedata) * 3, 1 + PRICES_DAYWINDOW * 2 + PRICES_SMOOTHWIDTH); - price = den = depth = errcode = 0; + depth = errcode = 0; for (i = 0; i < vec.size(); i++) { @@ -869,7 +873,7 @@ int64_t prices_syntheticprice(std::vector vec, int32_t height, int32_t mpz_set_ui(mpzResult, 0); // clear result to test overflow (see below) - std::cerr << "prices_syntheticprice" << " i=" << i << " price=" << price << " value=" << value << " depth=" << depth << " opcode&KOMODO_PRICEMASK=" << (opcode & KOMODO_PRICEMASK) < 2 && vout.scriptPubKey[0] == OP_RETURN && vout.scriptPubKey[2] == evalcode ) return i; i++; } diff --git a/src/cc/payments.cpp b/src/cc/payments.cpp index 12d5cff62..498d9d014 100644 --- a/src/cc/payments.cpp +++ b/src/cc/payments.cpp @@ -595,7 +595,7 @@ int64_t AddPaymentsInputs(bool fLockedBlocks,int8_t GetBalance,struct CCcontract } } } - if ( GetBalance == 3 && totalinputs < minrelease ) // return elegible balance to be spent, and blocks left until min release can be released. + if ( GetBalance == 3 && totalinputs < minrelease*COIN ) // return elegible balance to be spent, and blocks left until min release can be released. { int64_t lockedblocks_balance = totalinputs; // inputs that can be spent already. // sort utxos by blocks until able to be spent, smallest at top. From 5a5945abd1bf79899fd4232a1bceaec261c298d5 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Tue, 7 May 2019 20:07:53 +0800 Subject: [PATCH 241/447] add check for scrptpubkey size --- src/cc/CCutils.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/CCutils.cpp b/src/cc/CCutils.cpp index 363b54ad5..023858dc2 100644 --- a/src/cc/CCutils.cpp +++ b/src/cc/CCutils.cpp @@ -64,7 +64,7 @@ int32_t has_opret(const CTransaction &tx, uint8_t evalcode) for ( auto vout : tx.vout ) { //fprintf(stderr, "[txid.%s] 1.%i 2.%i 3.%i 4.%i\n",tx.GetHash().GetHex().c_str(), vout.scriptPubKey[0], vout.scriptPubKey[1], vout.scriptPubKey[2], vout.scriptPubKey[3]); - if ( vout.scriptPubKey[0] == OP_RETURN && vout.scriptPubKey[2] == evalcode ) + if ( vout.scriptPubKey.size() > 3 && vout.scriptPubKey[0] == OP_RETURN && vout.scriptPubKey[2] == evalcode ) return i; i++; } From cb346ffa448c99b129fb83bda3b2c7947323d0b2 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Tue, 7 May 2019 21:52:16 +0800 Subject: [PATCH 242/447] 1 --- src/cc/payments.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/cc/payments.cpp b/src/cc/payments.cpp index 12d5cff62..35eda45f3 100644 --- a/src/cc/payments.cpp +++ b/src/cc/payments.cpp @@ -1029,6 +1029,7 @@ UniValue PaymentsMerge(struct CCcontract_info *cp,char *jsonstr) // encode the checktxid into the end of the ccvout, along with 'M' to flag merge type tx. opret = EncodePaymentsMergeOpRet(createtxid); std::vector> vData = std::vector>(); + // try to pay to diffrent pubkey here... change txidpk. if ( makeCCopret(opret, vData) ) mtx.vout.push_back(MakeCC1of2vout(EVAL_PAYMENTS,inputsum-PAYMENTS_TXFEE,Paymentspk,txidpk,&vData)); GetCCaddress1of2(cp,destaddr,Paymentspk,txidpk); @@ -1036,7 +1037,7 @@ UniValue PaymentsMerge(struct CCcontract_info *cp,char *jsonstr) rawtx = FinalizeCCTx(0,cp,mtx,mypk,PAYMENTS_TXFEE,CScript()); if ( params != 0 ) free_json(params); - return(payments_rawtxresult(result,rawtx,0)); + return(payments_rawtxresult(result,rawtx,1)); } } else From 38f16334c13e895cbb2bb09cdcdbbddcc732aa4c Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Tue, 7 May 2019 22:42:12 +0800 Subject: [PATCH 243/447] fix --- src/cc/payments.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/cc/payments.cpp b/src/cc/payments.cpp index 35eda45f3..f78474e12 100644 --- a/src/cc/payments.cpp +++ b/src/cc/payments.cpp @@ -575,8 +575,11 @@ int64_t AddPaymentsInputs(bool fLockedBlocks,int8_t GetBalance,struct CCcontract } if ( (nValue= IsPaymentsvout(cp,vintx,vout,coinaddr,ccopret)) > PAYMENTS_TXFEE && nValue >= threshold && myIsutxo_spentinmempool(ignoretxid,ignorevin,txid,vout) == 0 ) { + int32_t offset = 0; + if ( ccopret.size() > 2 && DecodePaymentsMergeOpRet(ccopret,checktxid) == 'M' ) + offset = PAYMENTS_MERGEOFSET; int32_t tmpblocksleft = 0; - if ( fLockedBlocks && !payments_lockedblocks(hashBlock, lockedblocks+(GetBalance == 4 ? PAYMENTS_MERGEOFSET : 0), tmpblocksleft) ) + if ( fLockedBlocks && !payments_lockedblocks(hashBlock, lockedblocks+offset, tmpblocksleft) ) { blocksleft_balance.push_back(std::make_pair(tmpblocksleft,nValue)); continue; From bac6d503af863fc9ce7c745ac9601fa7ddf50bd6 Mon Sep 17 00:00:00 2001 From: dimxy Date: Tue, 7 May 2019 21:24:46 +0500 Subject: [PATCH 244/447] change to prices_getbetinfo() --- src/cc/CCPrices.h | 1 + src/cc/prices.cpp | 629 +++++++++++++++++++++++------------------ src/rpc/blockchain.cpp | 13 + src/rpc/server.cpp | 2 + src/rpc/server.h | 2 + 5 files changed, 370 insertions(+), 277 deletions(-) diff --git a/src/cc/CCPrices.h b/src/cc/CCPrices.h index 9bcae60b2..933f08e19 100644 --- a/src/cc/CCPrices.h +++ b/src/cc/CCPrices.h @@ -49,6 +49,7 @@ UniValue PricesRekt(int64_t txfee,uint256 bettxid,int32_t rektheight); UniValue PricesCashout(int64_t txfee,uint256 bettxid); UniValue PricesInfo(uint256 bettxid,int32_t refheight); UniValue PricesList(uint32_t filter, CPubKey mypk); +UniValue PricesGetOrderbook(); #endif diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 31a63f93d..2ac89613c 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -20,16 +20,38 @@ #define IS_CHARINSTR(c, str) (std::string(str).find((char)(c)) != std::string::npos) -#define N_CCMARKER 1 +#define NVOUT_CCMARKER 1 +#define NVOUT_NORMALMARKER 3 -typedef struct BetInfo { - int64_t amount; +typedef struct OneBetData { + int64_t positionsize; int32_t firstheight; int64_t costbasis; int64_t profits; - BetInfo() { amount = 0; firstheight = 0; costbasis = 0; profits = 0; } // it is important to clear costbasis as it will be calculated as minmax from inital value 0 -} betinfo; + OneBetData() { positionsize = 0; firstheight = 0; costbasis = 0; profits = 0; } // it is important to clear costbasis as it will be calculated as minmax from inital value 0 +} onebetdata; + +typedef struct BetInfo { + int64_t averageCostbasis, firstprice, lastprice, liquidationprice, equity; + int64_t rektfee; + int32_t lastheight; + int16_t leverage; + bool isOpen, isRekt; + uint256 tokenid; + + std::vector parsed; + std::vector bets; + CPubKey pk; + + BetInfo() { + averageCostbasis = firstprice = lastprice = liquidationprice = equity = 0; + lastheight = 0; + leverage = 0; + rektfee = 0; + isOpen = isRekt = false; + } +} BetInfo; /* CBOPRET creates trustless oracles, which can be used for making a synthetic cash settlement system based on real world prices; @@ -145,7 +167,7 @@ uint8_t prices_finalopretdecode(CScript scriptPubKey,uint256 &bettxid,int64_t &p } // price opret basic validation and retrieval -static uint8_t CheckPricesOpret(const CTransaction & tx, vscript_t &opret) +static uint8_t PricesCheckOpret(const CTransaction & tx, vscript_t &opret) { if (tx.vout.size() > 0 && GetOpReturnData(tx.vout.back().scriptPubKey, opret) && opret.size() > 2 && opret.begin()[0] == EVAL_PRICES && IS_CHARINSTR(opret.begin()[1], "BACF")) return opret.begin()[1]; @@ -217,7 +239,7 @@ static bool ValidateAddFundingTx(struct CCcontract_info *cp, Eval *eval, const C return eval->Invalid("cannot decode opreturn for add funding tx"); pricespk = GetUnspendable(cp, 0); - uint8_t vintxFuncId = CheckPricesOpret(vintx, vintxOpret); + uint8_t vintxFuncId = PricesCheckOpret(vintx, vintxOpret); if (vintxFuncId != 'A' && vintxFuncId != 'B') { // if vintx is bettx return eval->Invalid("incorrect vintx funcid"); } @@ -352,7 +374,7 @@ bool PricesValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx if (strcmp(ASSETCHAINS_SYMBOL, "REKT0") == 0 && chainActive.Height() < 2965) return true; // check basic opret rules: - if (CheckPricesOpret(tx, vopret) == 0) + if (PricesCheckOpret(tx, vopret) == 0) return eval->Invalid("tx has no prices opreturn"); uint8_t funcId = vopret.begin()[1]; @@ -375,7 +397,7 @@ bool PricesValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx if (!myGetTransaction(vin.prevout.hash, vintx, hashBlock)) return eval->Invalid("cannot load vintx"); - if (CheckPricesOpret(vintx, vintxOpret) == 0) { + if (PricesCheckOpret(vintx, vintxOpret) == 0) { //return eval->Invalid("cannot find prices opret in vintx"); std::cerr << "PricesValidate() " << "cannot find prices opret in vintx" << std::endl; } @@ -486,7 +508,7 @@ int64_t AddPricesInputs(struct CCcontract_info *cp, CMutableTransaction &mtx, ch if (GetTransaction(txid, vintx, hashBlock, false) != 0 && vout < vintx.vout.size()) { vscript_t vopret; - uint8_t funcId = CheckPricesOpret(vintx, vopret); + uint8_t funcId = PricesCheckOpret(vintx, vopret); if (funcId == 'B' && vout == 1) // skip cc marker continue; @@ -1215,7 +1237,7 @@ int32_t prices_syntheticprofits(int64_t &costbasis, int32_t firstheight, int32_t } // makes result json object -void prices_betjson(UniValue &result, std::vector bets, int16_t leverage, int32_t endheight, int64_t lastprice) +void prices_betjson(UniValue &result, std::vector bets, int16_t leverage, int32_t endheight, int64_t lastprice) { UniValue resultbets(UniValue::VARR); @@ -1224,12 +1246,12 @@ void prices_betjson(UniValue &result, std::vector bets, int16_t leverag for (auto b : bets) { UniValue entry(UniValue::VOBJ); - entry.push_back(Pair("positionsize", ValueFromAmount(b.amount))); + entry.push_back(Pair("positionsize", ValueFromAmount(b.positionsize))); entry.push_back(Pair("profits", ValueFromAmount(b.profits))); entry.push_back(Pair("costbasis", ValueFromAmount(b.costbasis))); entry.push_back(Pair("firstheight", b.firstheight)); resultbets.push_back(entry); - totalbets += b.amount; + totalbets += b.positionsize; totalprofits += b.profits; } int64_t equity = totalbets + totalprofits; @@ -1277,7 +1299,7 @@ int64_t prices_costbasis(CTransaction bettx, uint256 &txidCostbasis) } // enumerates and retrieves added bets, returns the last baton txid -int64_t prices_enumaddedbets(uint256 &batontxid, std::vector &bets, uint256 bettxid) +int64_t prices_enumaddedbets(uint256 &batontxid, std::vector &bets, uint256 bettxid) { int64_t addedBetsTotal = 0; int32_t vini; @@ -1304,10 +1326,10 @@ int64_t prices_enumaddedbets(uint256 &batontxid, std::vector &bets, uin txBaton.vout.size() > 0 && (funcId = prices_addopretdecode(txBaton.vout.back().scriptPubKey, bettxidInOpret, pk, amount)) != 0) { - BetInfo added; + OneBetData added; addedBetsTotal += amount; - added.amount = amount; + added.positionsize = amount; added.firstheight = blockIdx.GetHeight(); bets.push_back(added); std::cerr << "prices_batontxid() added amount=" << amount << std::endl; @@ -1357,9 +1379,9 @@ UniValue PricesBet(int64_t txfee, int64_t amount, int16_t leverage, std::vector< betamount = (amount * 199) / 200; mtx.vout.push_back(MakeCC1vout(cp->evalcode, txfee, mypk)); // vout0 baton for total funding // mtx.vout.push_back(MakeCC1vout(cp->evalcode, (amount - betamount) + 2 * txfee, pricespk)); // vout1, when spent, costbasis is set - mtx.vout.push_back(MakeCC1vout(cp->evalcode, txfee, pricespk)); // vout1 cc marker (N_CCMARKER) + mtx.vout.push_back(MakeCC1vout(cp->evalcode, txfee, pricespk)); // vout1 cc marker (NVOUT_CCMARKER) mtx.vout.push_back(MakeCC1vout(cp->evalcode, betamount, pricespk)); // vout2 betamount - mtx.vout.push_back(CTxOut(txfee, CScript() << ParseHex(HexStr(pricespk)) << OP_CHECKSIG)); // vout3 normal marker - TODO: remove it as we have cc marker now, when move to the new chain + mtx.vout.push_back(CTxOut(txfee, CScript() << ParseHex(HexStr(pricespk)) << OP_CHECKSIG)); // vout3 normal marker NVOUT_NORMALMARKER - TODO: remove it as we have cc marker now, when move to the new chain rawtx = FinalizeCCTx(0, cp, mtx, mypk, txfee, prices_betopret(mypk, nextheight - 1, amount, leverage, firstprice, vec, zeroid)); return(prices_rawtxresult(result, rawtx, 0)); } @@ -1389,7 +1411,7 @@ UniValue PricesAddFunding(int64_t txfee, uint256 bettxid, int64_t amount) //GetCCaddress(cp, myaddr, mypk); if (AddNormalinputs(mtx, mypk, amount + 2*txfee, 64) >= amount + 2*txfee) { - std::vector bets; + std::vector bets; if (prices_enumaddedbets(batontxid, bets, bettxid) >= 0) { mtx.vin.push_back(CTxIn(batontxid, 0, CScript())); @@ -1411,7 +1433,7 @@ UniValue PricesAddFunding(int64_t txfee, uint256 bettxid, int64_t amount) } // scan chain from the initial bet's first position upto the chain tip and calculate bet's costbasises and profits, breaks if rekt detected -int32_t prices_scanchain(std::vector &bets, int16_t leverage, std::vector vec, int64_t &lastprice, int32_t &endheight) { +int32_t prices_scanchain(std::vector &bets, int16_t leverage, std::vector vec, int64_t &lastprice, int32_t &endheight) { if (bets.size() == 0) return -1; @@ -1427,13 +1449,13 @@ int32_t prices_scanchain(std::vector &bets, int16_t leverage, std::vect if (height > bets[i].firstheight) { - int32_t retcode = prices_syntheticprofits(bets[i].costbasis, bets[i].firstheight, height, leverage, vec, bets[i].amount, bets[i].profits, lastprice); + int32_t retcode = prices_syntheticprofits(bets[i].costbasis, bets[i].firstheight, height, leverage, vec, bets[i].positionsize, bets[i].profits, lastprice); if (retcode < 0) { std::cerr << "prices_scanchain() prices_syntheticprofits returned -1, breaking" << std::endl; stop = true; break; } - totalbets += bets[i].amount; + totalbets += bets[i].positionsize; totalprofits += bets[i].profits; } } @@ -1523,233 +1545,39 @@ UniValue PricesSetcostbasis(int64_t txfee, uint256 bettxid) return(result); } -// pricesrekt rpc: anyone can rekt a bet at some block where losses reached limit, collecting fee -UniValue PricesRekt(int64_t txfee, uint256 bettxid, int32_t rektheight) + +int32_t prices_getbetinfo(uint256 bettxid, BetInfo &betinfo) { - int32_t nextheight = komodo_nextheight(); - CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), nextheight); UniValue result(UniValue::VOBJ); - struct CCcontract_info *cp, C; - CTransaction bettx; - uint256 hashBlock, tokenid, batontxid; - int64_t myfee = 0, firstprice, lastprice = 0, positionsize; - int32_t firstheight; - int16_t leverage; - std::vector vec; - CPubKey pk, mypk, pricespk; - std::string rawtx; - char destaddr[64]; - - cp = CCinit(&C, EVAL_PRICES); - if (txfee == 0) - txfee = PRICES_TXFEE; - mypk = pubkey2pk(Mypubkey()); - pricespk = GetUnspendable(cp, 0); - GetCCaddress(cp, destaddr, pricespk); - - if (myGetTransaction(bettxid, bettx, hashBlock) != 0 && bettx.vout.size() > 3) - { - if (prices_betopretdecode(bettx.vout.back().scriptPubKey, pk, firstheight, positionsize, leverage, firstprice, vec, tokenid) == 'B') - { - uint256 finaltxid; - int32_t vini; - int32_t finalheight, endheight; - std::vector bets; - BetInfo bet1; - - if (CCgetspenttxid(finaltxid, vini, finalheight, bettxid, N_CCMARKER) == 0) { - result.push_back(Pair("result", "error")); - result.push_back(Pair("error", "position closed")); - return result; - } - - bet1.amount = positionsize; - bet1.firstheight = firstheight; - bets.push_back(bet1); - - prices_enumaddedbets(batontxid, bets, bettxid); - - if (prices_scanchain(bets, leverage, vec, lastprice, endheight) < 0) { - result.push_back(Pair("result", "error")); - result.push_back(Pair("error", "error scanning chain")); - return(result); - } - - int64_t totalbets = 0; - int64_t totalprofits = 0; - for (auto b : bets) { - totalbets += b.amount; - totalprofits += b.profits; - } - - prices_betjson(result, bets, leverage, endheight, lastprice); // fill output json - - int64_t equity = totalbets + totalprofits; - if (equity < 0) - { - myfee = totalbets / 500; // consolation fee for loss - } - if (myfee != 0) - { - int64_t CCchange = 0, inputsum; - - mtx.vin.push_back(CTxIn(bettxid, N_CCMARKER, CScript())); // spend cc marker - if ((inputsum = AddPricesInputs(cp, mtx, destaddr, myfee + txfee, 64)) > myfee + txfee) // TODO: why do we take txfee from global addr and not from user's addr? - CCchange = (inputsum - myfee); - mtx.vout.push_back(CTxOut(myfee, CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); - if (CCchange >= txfee) - mtx.vout.push_back(MakeCC1vout(cp->evalcode, CCchange, pricespk)); - - /// mtx.vout.push_back(MakeCC1vout(cp->evalcode, bettx.vout[2].nValue - myfee - txfee, pricespk)); // change - rawtx = FinalizeCCTx(0, cp, mtx, mypk, txfee, prices_finalopret(bettxid, totalprofits, rektheight, mypk, firstprice, 0, totalbets - positionsize, positionsize, leverage)); - return(prices_rawtxresult(result, rawtx, 0)); - } - else - { - result.push_back(Pair("result", "error")); - result.push_back(Pair("error", "position not rekt")); - return(result); - } - } - else - { - result.push_back(Pair("result", "error")); - result.push_back(Pair("error", "cant decode opret")); - return(result); - } - } - result.push_back(Pair("result", "error")); - result.push_back(Pair("error", "cant load or incorrect bettx")); - return(result); -} - -// pricescashout rpc impl: bettor can cashout hit bet if it is not rekt -UniValue PricesCashout(int64_t txfee, uint256 bettxid) -{ - int32_t nextheight = komodo_nextheight(); - CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), nextheight); UniValue result(UniValue::VOBJ); - struct CCcontract_info *cp, C; char destaddr[64]; - CTransaction bettx; - uint256 hashBlock, batontxid, tokenid; - int64_t CCchange = 0, positionsize, inputsum, firstprice, lastprice = 0; - int32_t firstheight; - int16_t leverage; - std::vector vec; - CPubKey pk, mypk, pricespk; - std::string rawtx; - - cp = CCinit(&C, EVAL_PRICES); - if (txfee == 0) - txfee = PRICES_TXFEE; - - mypk = pubkey2pk(Mypubkey()); - pricespk = GetUnspendable(cp, 0); - GetCCaddress(cp, destaddr, pricespk); - if (myGetTransaction(bettxid, bettx, hashBlock) != 0 && bettx.vout.size() > 3) - { - if (prices_betopretdecode(bettx.vout.back().scriptPubKey, pk, firstheight, positionsize, leverage, firstprice, vec, tokenid) == 'B') - { - uint256 finaltxid; - int32_t vini; - int32_t finalheight, endheight; - std::vector bets; - BetInfo bet1; - - if (CCgetspenttxid(finaltxid, vini, finalheight, bettxid, N_CCMARKER) == 0) { - result.push_back(Pair("result", "error")); - result.push_back(Pair("error", "position closed")); - return result; - } - - bet1.amount = positionsize; - bet1.firstheight = firstheight; - bets.push_back(bet1); - prices_enumaddedbets(batontxid, bets, bettxid); - - if (prices_scanchain(bets, leverage, vec, lastprice, endheight) < 0) { - result.push_back(Pair("result", "error")); - result.push_back(Pair("error", "error scanning chain")); - return(result); - } - - int64_t totalbets = 0; - int64_t totalprofits = 0; - for (auto b : bets) { - totalbets += b.amount; - totalprofits += b.profits; - } - prices_betjson(result, bets, leverage, endheight, lastprice); // fill output json - - int64_t equity = totalbets + totalprofits; - if (equity < 0) - { - result.push_back(Pair("result", "error")); - result.push_back(Pair("error", "position rekt")); - return(result); - } - - mtx.vin.push_back(CTxIn(bettxid, N_CCMARKER, CScript())); // spend cc marker - if ((inputsum = AddPricesInputs(cp, mtx, destaddr, equity + txfee, 64)) > equity + txfee) - CCchange = (inputsum - equity); - mtx.vout.push_back(CTxOut(equity, CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); - if (CCchange >= txfee) - mtx.vout.push_back(MakeCC1vout(cp->evalcode, CCchange, pricespk)); - rawtx = FinalizeCCTx(0, cp, mtx, mypk, txfee, prices_finalopret(bettxid, totalprofits, nextheight - 1, mypk, firstprice, 0, totalbets-positionsize, positionsize, leverage)); - return(prices_rawtxresult(result, rawtx, 0)); - } - else - { - result.push_back(Pair("result", "error")); - result.push_back(Pair("error", "cant decode opret")); - return(result); - } - } - result.push_back(Pair("result", "error")); - result.push_back(Pair("error", "cant load or incorrect bettx")); - return(result); -} - -// pricesinfo rpc impl -UniValue PricesInfo(uint256 bettxid, int32_t refheight) -{ - UniValue result(UniValue::VOBJ); CTransaction bettx; uint256 hashBlock, batontxid, tokenid; - int64_t positionsize = 0, firstprice = 0, lastprice = 0; - int32_t firstheight = 0, endheight; - int16_t leverage = 0; - std::vector vec; - CPubKey pk, mypk, pricespk; - std::string rawtx; - //uint256 costbasistxid; if (myGetTransaction(bettxid, bettx, hashBlock) && bettx.vout.size() > 3) { if (hashBlock.IsNull()) - throw std::runtime_error("tx still in mempool"); + return -2; - if (prices_betopretdecode(bettx.vout.back().scriptPubKey, pk, firstheight, positionsize, leverage, firstprice, vec, tokenid) == 'B') + OneBetData bet1; + if (prices_betopretdecode(bettx.vout.back().scriptPubKey, betinfo.pk, bet1.firstheight, bet1.positionsize, betinfo.leverage, betinfo.firstprice, betinfo.parsed, betinfo.tokenid) == 'B') { uint256 finaltxid; int32_t vini; - int32_t finalheight, endheight; - std::vector bets; - BetInfo bet1; + int32_t finaltxheight; //, endheight; + //std::vector bets; - if (CCgetspenttxid(finaltxid, vini, finalheight, bettxid, N_CCMARKER) == 0) - result.push_back(Pair("status", "closed")); + + if (CCgetspenttxid(finaltxid, vini, finaltxheight, bettxid, NVOUT_CCMARKER) == 0) + betinfo.isOpen = false; else - result.push_back(Pair("status", "open")); + betinfo.isOpen = true; - bet1.amount = positionsize; - bet1.firstheight = firstheight; - bets.push_back(bet1); + //bet1.amount = betinfo.positionsize; + //bet1.firstheight = firstheight; + betinfo.bets.push_back(bet1); - prices_enumaddedbets(batontxid, bets, bettxid); + prices_enumaddedbets(batontxid, betinfo.bets, bettxid); - if( prices_scanchain(bets, leverage, vec, lastprice, endheight) < 0 ) { - result.push_back(Pair("result", "error")); - result.push_back(Pair("error", "error scanning chain")); - return(result); + if (prices_scanchain(betinfo.bets, betinfo.leverage, betinfo.parsed, betinfo.lastprice, betinfo.lastheight) < 0) { + return -4; } mpz_t mpzTotalbets; @@ -1760,38 +1588,37 @@ UniValue PricesInfo(uint256 bettxid, int32_t refheight) mpz_init(mpzTotalprofits); mpz_init(mpzTotalcostbasis); - int64_t totalbets = 0; int64_t totalprofits = 0; - for (auto b : bets) { + for (auto b : betinfo.bets) { mpz_t mpzProduct; mpz_t mpzProfits; - + mpz_init(mpzProduct); mpz_init(mpzProfits); - + //totalprofits += b.profits; //dcostbasis += b.amount * (double)b.costbasis; // costbasis += b.amount * (b.costbasis / PRICES_POINTFACTOR); // prevent int64 overflow (but we have underflow for 1/BTC) // std::cerr << "PricesInfo() acc dcostbasis=" << dcostbasis << " b.amount=" << b.amount << " b.costbasis/PRICES_POINTFACTOR=" << (b.costbasis / PRICES_POINTFACTOR) << std::endl; //std::cerr << "PricesInfo() acc dcostbasis=" << dcostbasis << " b.amount=" << b.amount << " b.costbasis/PRICES_POINTFACTOR=" << (b.costbasis / PRICES_POINTFACTOR) << std::endl; mpz_set_ui(mpzProduct, b.costbasis); - mpz_mul_ui(mpzProduct, mpzProduct, (uint64_t)b.amount); // b.costbasis * b.amount + mpz_mul_ui(mpzProduct, mpzProduct, (uint64_t)b.positionsize); // b.costbasis * b.amount mpz_add(mpzTotalcostbasis, mpzTotalcostbasis, mpzProduct); //averageCostbasis += b.costbasis * b.amount; - mpz_add_ui(mpzTotalbets, mpzTotalbets, (uint64_t)b.amount); //totalbets += b.amount; + mpz_add_ui(mpzTotalbets, mpzTotalbets, (uint64_t)b.positionsize); //totalbets += b.amount; mpz_add(mpzTotalprofits, mpzTotalprofits, mpzProfits); //totalprofits += b.profits; - totalbets += b.amount; + totalbets += b.positionsize; totalprofits += b.profits; mpz_clear(mpzProduct); mpz_clear(mpzProfits); } - int64_t equity = totalbets + totalprofits; - int64_t averageCostbasis = 0; + betinfo.equity = totalbets + totalprofits; + //int64_t averageCostbasis = 0; if (mpz_get_ui(mpzTotalbets) != 0) { //prevent zero div mpz_t mpzAverageCostbasis; @@ -1799,49 +1626,272 @@ UniValue PricesInfo(uint256 bettxid, int32_t refheight) //averageCostbasis = totalcostbasis / totalbets; mpz_mul_ui(mpzTotalcostbasis, mpzTotalcostbasis, SATOSHIDEN); // profits *= SATOSHIDEN normalization to prevent loss of significance while division - mpz_tdiv_q(mpzAverageCostbasis, mpzTotalcostbasis, mpzTotalbets); + mpz_tdiv_q(mpzAverageCostbasis, mpzTotalcostbasis, mpzTotalbets); mpz_tdiv_q_ui(mpzAverageCostbasis, mpzAverageCostbasis, SATOSHIDEN); // profits /= SATOSHIDEN de-normalization - averageCostbasis = mpz_get_ui(mpzAverageCostbasis); + betinfo.averageCostbasis = mpz_get_ui(mpzAverageCostbasis); mpz_clear(mpzAverageCostbasis); } - int64_t liqprice = 0; - if (leverage != 0) {// prevent zero div - liqprice = averageCostbasis - averageCostbasis / leverage; + betinfo.liquidationprice = 0; + if (betinfo.leverage != 0) {// prevent zero div + betinfo.liquidationprice = betinfo.averageCostbasis - betinfo.averageCostbasis / betinfo.leverage; } - if (equity >= 0) - result.push_back(Pair("rekt", 0)); + if (betinfo.equity >= 0) + betinfo.isRekt = true; else { - result.push_back(Pair("rekt", (int64_t)1)); - result.push_back(Pair("rektfee", totalbets / 500)); - result.push_back(Pair("rektheight", (int64_t)endheight)); + betinfo.isRekt = false; + betinfo.rektfee = totalbets / 500; } - std::string expr = prices_getsourceexpression(vec); - result.push_back(Pair("expression", expr)); - result.push_back(Pair("reduced", prices_getreducedexpr(expr))); - result.push_back(Pair("batontxid", batontxid.GetHex())); - result.push_back(Pair("costbasis", ValueFromAmount(averageCostbasis))); -#ifdef TESTMODE - result.push_back(Pair("costbasis_test_period", 7)); -#endif - - prices_betjson(result, bets, leverage, endheight, lastprice); - - result.push_back(Pair("LiquidationPrice", ValueFromAmount(liqprice))); - mpz_clear(mpzTotalbets); mpz_clear(mpzTotalprofits); mpz_clear(mpzTotalcostbasis); + return 0; + } + return -3; + } + return (-1); +} + +// pricesrekt rpc: anyone can rekt a bet at some block where losses reached limit, collecting fee +UniValue PricesRekt(int64_t txfee, uint256 bettxid, int32_t rektheight) +{ + int32_t nextheight = komodo_nextheight(); + CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), nextheight); UniValue result(UniValue::VOBJ); + struct CCcontract_info *cp, C; + CTransaction bettx; +/* uint256 hashBlock, tokenid, batontxid; + int64_t firstprice, lastprice = 0, positionsize; + int32_t firstheight; + int16_t leverage; + std::vector vec; */ + int64_t myfee = 0; + CPubKey pk, mypk, pricespk; + std::string rawtx; + char destaddr[64]; + + cp = CCinit(&C, EVAL_PRICES); + if (txfee == 0) // TODO: what did we want tot do with txfee in prices? + txfee = PRICES_TXFEE; + mypk = pubkey2pk(Mypubkey()); + pricespk = GetUnspendable(cp, 0); + GetCCaddress(cp, destaddr, pricespk); + + BetInfo betinfo; + int32_t retcode = prices_getbetinfo(bettxid, betinfo); + if (retcode < 0) { + if (retcode == -1) { + result.push_back(Pair("result", "error")); + result.push_back(Pair("error", "cant find bettxid or incorrect")); + } + else if (retcode == -2) { + throw std::runtime_error("tx still in mempool"); + } + else if (retcode == -3) + { + result.push_back(Pair("result", "error")); + result.push_back(Pair("error", "cant decode opret")); return(result); } + else if (retcode == -4) { + result.push_back(Pair("result", "error")); + result.push_back(Pair("error", "error scanning chain")); + } + return(result); } - result.push_back(Pair("result", "error")); - result.push_back(Pair("error", "cant find bettxid or incorrect")); + + int64_t totalbets = 0; + int64_t totalprofits = 0; + + for (auto b : betinfo.bets) { + totalbets += b.positionsize; + totalprofits += b.profits; + } + + + if (!betinfo.isOpen) { + result.push_back(Pair("result", "error")); + result.push_back(Pair("error", "position closed")); + return result; + } + + prices_betjson(result, betinfo.bets, betinfo.leverage, betinfo.lastheight, betinfo.lastprice); // fill output + if (betinfo.isRekt) + { + myfee = betinfo.rektfee; // consolation fee for loss + } + if (myfee != 0) + { + int64_t CCchange = 0, inputsum; + + mtx.vin.push_back(CTxIn(bettxid, NVOUT_CCMARKER, CScript())); // spend cc marker + if ((inputsum = AddPricesInputs(cp, mtx, destaddr, myfee + txfee, 64)) > myfee + txfee) // TODO: why do we take txfee from global addr and not from user's addr? + CCchange = (inputsum - myfee); + mtx.vout.push_back(CTxOut(myfee, CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); + if (CCchange >= txfee) + mtx.vout.push_back(MakeCC1vout(cp->evalcode, CCchange, pricespk)); + + /// mtx.vout.push_back(MakeCC1vout(cp->evalcode, bettx.vout[2].nValue - myfee - txfee, pricespk)); // change + rawtx = FinalizeCCTx(0, cp, mtx, mypk, txfee, prices_finalopret(bettxid, totalprofits, rektheight, mypk, betinfo.firstprice, 0, totalbets /*- positionsize*/, 0/*positionsize*/, betinfo.leverage)); + return(prices_rawtxresult(result, rawtx, 0)); + } + else + { + result.push_back(Pair("result", "error")); + result.push_back(Pair("error", "position not rekt")); + return(result); + } +} + +// pricescashout rpc impl: bettor can cashout hit bet if it is not rekt +UniValue PricesCashout(int64_t txfee, uint256 bettxid) +{ + int32_t nextheight = komodo_nextheight(); + CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), nextheight); + UniValue result(UniValue::VOBJ); + struct CCcontract_info *cp, C; char destaddr[64]; +/* CTransaction bettx; + uint256 hashBlock, batontxid, tokenid; + int64_t positionsize, firstprice, lastprice = 0; + int32_t firstheight; + int16_t leverage; + std::vector vec;*/ + int64_t CCchange = 0, inputsum; + CPubKey pk, mypk, pricespk; + std::string rawtx; + + cp = CCinit(&C, EVAL_PRICES); + if (txfee == 0) + txfee = PRICES_TXFEE; + + mypk = pubkey2pk(Mypubkey()); + pricespk = GetUnspendable(cp, 0); + GetCCaddress(cp, destaddr, pricespk); + + BetInfo betinfo; + int32_t retcode = prices_getbetinfo(bettxid, betinfo); + if (retcode < 0) { + if (retcode == -1) { + result.push_back(Pair("result", "error")); + result.push_back(Pair("error", "cant find bettxid or incorrect")); + } + else if (retcode == -2) { + throw std::runtime_error("tx still in mempool"); + } + else if (retcode == -3) + { + result.push_back(Pair("result", "error")); + result.push_back(Pair("error", "cant decode opret")); + return(result); + } + else if (retcode == -4) { + result.push_back(Pair("result", "error")); + result.push_back(Pair("error", "error scanning chain")); + } + return(result); + } + + int64_t totalbets = 0; + int64_t totalprofits = 0; + + for (auto b : betinfo.bets) { + totalbets += b.positionsize; + totalprofits += b.profits; + } + + + if (!betinfo.isOpen) { + result.push_back(Pair("result", "error")); + result.push_back(Pair("error", "position closed")); + return result; + } + + prices_betjson(result, betinfo.bets, betinfo.leverage, betinfo.lastheight, betinfo.lastprice); // fill output json + + if (betinfo.isRekt) + { + result.push_back(Pair("result", "error")); + result.push_back(Pair("error", "position rekt")); + return(result); + } + + mtx.vin.push_back(CTxIn(bettxid, NVOUT_CCMARKER, CScript())); // spend cc marker + if ((inputsum = AddPricesInputs(cp, mtx, destaddr, betinfo.equity + txfee, 64)) > betinfo.equity + txfee) + CCchange = (inputsum - betinfo.equity); + mtx.vout.push_back(CTxOut(betinfo.equity, CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); + if (CCchange >= txfee) + mtx.vout.push_back(MakeCC1vout(cp->evalcode, CCchange, pricespk)); + // TODO: what should the opret param be: + rawtx = FinalizeCCTx(0, cp, mtx, mypk, txfee, prices_finalopret(bettxid, totalprofits, nextheight - 1, mypk, betinfo.firstprice, 0, totalbets/*- betinfo.positionsize*/, 0/*betinfo.positionsize*/, betinfo.leverage)); + return(prices_rawtxresult(result, rawtx, 0)); + +} + + + + +// pricesinfo rpc impl +UniValue PricesInfo(uint256 bettxid, int32_t refheight) +{ + UniValue result(UniValue::VOBJ); +/* CTransaction bettx; + uint256 hashBlock, batontxid, tokenid; + int64_t positionsize = 0, firstprice = 0, lastprice = 0; + int32_t firstheight = 0, endheight; + int16_t leverage = 0; + std::vector vec; + CPubKey pk, mypk, pricespk; + std::string rawtx; */ + + BetInfo betinfo; + int32_t retcode = prices_getbetinfo(bettxid, betinfo); + if (retcode < 0) { + if( retcode == -1 ) { + result.push_back(Pair("result", "error")); + result.push_back(Pair("error", "cant find bettxid or incorrect")); + } + else if (retcode == -2) { + throw std::runtime_error("tx still in mempool"); + } + else if (retcode == -3) + { + result.push_back(Pair("result", "error")); + result.push_back(Pair("error", "cant decode opret")); + return(result); + } + else if (retcode == -4) { + result.push_back(Pair("result", "error")); + result.push_back(Pair("error", "error scanning chain")); + } + return(result); + } + + if (!betinfo.isRekt) + result.push_back(Pair("rekt", 0)); + else + { + result.push_back(Pair("rekt", (int64_t)1)); + result.push_back(Pair("rektfee", betinfo.rektfee)); + result.push_back(Pair("rektheight", betinfo.lastheight)); + } + + std::string expr = prices_getsourceexpression(betinfo.parsed); + result.push_back(Pair("expression", expr)); + result.push_back(Pair("reduced", prices_getreducedexpr(expr))); +// result.push_back(Pair("batontxid", batontxid.GetHex())); + result.push_back(Pair("costbasis", ValueFromAmount(betinfo.averageCostbasis))); +#ifdef TESTMODE + result.push_back(Pair("costbasis_test_period", 7)); +#endif + + prices_betjson(result, betinfo.bets, betinfo.leverage, betinfo.lastheight, betinfo.lastprice); + + result.push_back(Pair("LiquidationPrice", ValueFromAmount(betinfo.liquidationprice))); + return(result); } @@ -1852,25 +1902,20 @@ UniValue PricesList(uint32_t filter, CPubKey mypk) std::vector > addressIndex, addressIndexCC; struct CCcontract_info *cp, C; - cp = CCinit(&C, EVAL_PRICES); //pricespk = GetUnspendable(cp, 0); // filters and outputs prices bet txid - auto priceslist = [&](std::vector >::const_iterator it, int32_t nvout) + auto AddBetToList = [&](uint256 txid) { int64_t amount, firstprice; int32_t height; int16_t leverage; - uint256 txid, hashBlock, tokenid; + uint256 hashBlock, tokenid; CPubKey pk, pricespk; std::vector vec; CTransaction vintx; - txid = it->first.txhash; - if (nvout != it->first.index) // our marker vout - return; - if (GetTransaction(txid, vintx, hashBlock, false) != 0) { bool bAppend = false; @@ -1884,7 +1929,7 @@ UniValue PricesList(uint32_t filter, CPubKey mypk) int32_t height; uint256 finaltxid; - int32_t spent = CCgetspenttxid(finaltxid, vini, height, txid, N_CCMARKER); + int32_t spent = CCgetspenttxid(finaltxid, vini, height, txid, NVOUT_CCMARKER); if (filter == 1 && spent < 0 || // open positions filter == 2 && spent == 0) // closed positions bAppend = true; @@ -1892,7 +1937,7 @@ UniValue PricesList(uint32_t filter, CPubKey mypk) if (bAppend) result.push_back(txid.GetHex()); } - std::cerr << "PricesList() " << " bettxid=" << txid.GetHex() << " mypk=" << HexStr(mypk) << " opretpk=" << HexStr(pk) << " filter=" << filter << " bAppend=" << bAppend << " index=" << it->first.index << " txindex=" << it->first.txindex << std::endl; + std::cerr << "PricesList() " << " bettxid=" << txid.GetHex() << " mypk=" << HexStr(mypk) << " opretpk=" << HexStr(pk) << " filter=" << filter << " bAppend=" << bAppend << std::endl; } }; @@ -1900,7 +1945,8 @@ UniValue PricesList(uint32_t filter, CPubKey mypk) SetCCtxids(addressIndex, cp->normaladdr, false); // old normal marker for (std::vector >::const_iterator it = addressIndex.begin(); it != addressIndex.end(); it++) { - priceslist(it, 3); + if( it->first.txindex == NVOUT_NORMALMARKER ) + AddBetToList(it->first.txhash); } /* for future when switch to cc marker only @@ -1911,4 +1957,33 @@ UniValue PricesList(uint32_t filter, CPubKey mypk) } */ return(result); +} + + +void prices_addbookentry(uint256 txid) +{ + BetInfo betinfo; + //if( prices_getbetinfo(txid, betinfo) == 0 ) +} + +// walk through uxtos on the global address +// calculate the balance: +// + rekt positions +// = opposite positions +// - unbalanced positions +UniValue PricesGetOrderbook() +{ + UniValue result(UniValue::VARR); + std::vector > addressIndex, addressIndexCC; + struct CCcontract_info *cp, C; + + cp = CCinit(&C, EVAL_PRICES); + + SetCCtxids(addressIndex, cp->normaladdr, false); // old normal marker + for (std::vector >::const_iterator it = addressIndex.begin(); it != addressIndex.end(); it++) + { + if (it->first.txindex == NVOUT_NORMALMARKER) + prices_addbookentry(it->first.txhash); + } + return result; } \ No newline at end of file diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index 1f6fcadcf..cb2cfce92 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -1439,6 +1439,19 @@ UniValue pricesrekt(const UniValue& params, bool fHelp) return PricesRekt(txfee, bettxid, height); } +// pricesrekt rpc implementation +UniValue pricesgetorderbook(const UniValue& params, bool fHelp) +{ + if (fHelp || params.size() != 0) + throw runtime_error("pricesgetorderbook\n"); + LOCK(cs_main); + UniValue ret(UniValue::VOBJ); + + if (ASSETCHAINS_CBOPRET == 0) + throw JSONRPCError(RPC_INVALID_PARAMETER, "only -ac_cbopret chains have prices"); + + return PricesGetOrderbook(); +} UniValue gettxout(const UniValue& params, bool fHelp) { diff --git a/src/rpc/server.cpp b/src/rpc/server.cpp index d18f551e6..30258a6e0 100644 --- a/src/rpc/server.cpp +++ b/src/rpc/server.cpp @@ -470,6 +470,8 @@ static const CRPCCommand vRPCCommands[] = { "prices", "pricescashout", &pricescashout, true }, { "prices", "pricesrekt", &pricesrekt, true }, { "prices", "pricesaddfunding", &pricesaddfunding, true }, + { "prices", "pricesgetorderbook", &pricesgetorderbook, true }, + // Pegs { "pegs", "pegsaddress", &pegsaddress, true }, diff --git a/src/rpc/server.h b/src/rpc/server.h index a215f9bc3..d4942eb69 100644 --- a/src/rpc/server.h +++ b/src/rpc/server.h @@ -503,6 +503,8 @@ extern UniValue pricessetcostbasis(const UniValue& params, bool fHelp); extern UniValue pricescashout(const UniValue& params, bool fHelp); extern UniValue pricesrekt(const UniValue& params, bool fHelp); extern UniValue pricesaddfunding(const UniValue& params, bool fHelp); +extern UniValue pricesgetorderbook(const UniValue& params, bool fHelp); + #endif // BITCOIN_RPCSERVER_H From 0bb28987648240b3cd0123d942d539d364cd3391 Mon Sep 17 00:00:00 2001 From: dimxy Date: Tue, 7 May 2019 21:34:16 +0500 Subject: [PATCH 245/447] corr isRekt set --- src/cc/prices.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 2ac89613c..1fd039dc0 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -1640,10 +1640,10 @@ int32_t prices_getbetinfo(uint256 bettxid, BetInfo &betinfo) } if (betinfo.equity >= 0) - betinfo.isRekt = true; + betinfo.isRekt = false; else { - betinfo.isRekt = false; + betinfo.isRekt = true; betinfo.rektfee = totalbets / 500; } From f328bbcf2d9b7b584701c68b3fcec3e81dd1a67b Mon Sep 17 00:00:00 2001 From: dimxy Date: Wed, 8 May 2019 12:04:31 +0500 Subject: [PATCH 246/447] new line --- src/cc/prices.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 1fd039dc0..507047c27 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -1382,6 +1382,8 @@ UniValue PricesBet(int64_t txfee, int64_t amount, int16_t leverage, std::vector< mtx.vout.push_back(MakeCC1vout(cp->evalcode, txfee, pricespk)); // vout1 cc marker (NVOUT_CCMARKER) mtx.vout.push_back(MakeCC1vout(cp->evalcode, betamount, pricespk)); // vout2 betamount mtx.vout.push_back(CTxOut(txfee, CScript() << ParseHex(HexStr(pricespk)) << OP_CHECKSIG)); // vout3 normal marker NVOUT_NORMALMARKER - TODO: remove it as we have cc marker now, when move to the new chain + + rawtx = FinalizeCCTx(0, cp, mtx, mypk, txfee, prices_betopret(mypk, nextheight - 1, amount, leverage, firstprice, vec, zeroid)); return(prices_rawtxresult(result, rawtx, 0)); } From f8084d7231d2b60898718f9b8517c3ac192ee866 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Wed, 8 May 2019 19:38:14 +0800 Subject: [PATCH 247/447] Inital commit for prices fee to be paid to payments snapshot plan. --- src/cc/CCPrices.h | 2 ++ src/cc/payments.cpp | 1 + src/cc/prices.cpp | 42 ++++++++++++++++++++++++++++++----- src/komodo_bitcoind.h | 51 +++++++++++++++++++++++++++++++++++++++++++ src/komodo_globals.h | 1 + 5 files changed, 91 insertions(+), 6 deletions(-) diff --git a/src/cc/CCPrices.h b/src/cc/CCPrices.h index 933f08e19..e6238533f 100644 --- a/src/cc/CCPrices.h +++ b/src/cc/CCPrices.h @@ -20,6 +20,8 @@ #include "komodo_defs.h" #include "CCinclude.h" int32_t komodo_priceget(int64_t *buf64,int32_t ind,int32_t height,int32_t numblocks); +extern void GetFeeAddress(); +extern CScript KOMODO_PRICES_FEE_SCRIPTPUB; // #define PRICES_DAYWINDOW ((3600*24/ASSETCHAINS_BLOCKTIME) + 1) // defined in komodo_defs.h #define PRICES_TXFEE 10000 diff --git a/src/cc/payments.cpp b/src/cc/payments.cpp index f78474e12..6311e393d 100644 --- a/src/cc/payments.cpp +++ b/src/cc/payments.cpp @@ -1192,6 +1192,7 @@ UniValue PaymentsAirdrop(struct CCcontract_info *cp,char *jsonstr) lockedblocks = juint(jitem(params,0),0); minrelease = juint(jitem(params,1),0); minimum = juint(jitem(params,2),0); + if ( minimum < 10000 ) minimum = 10000; top = juint(jitem(params,3),0); bottom = juint(jitem(params,4),0); fixedAmount = juint(jitem(params,5),0); // fixed amount is a flag, set to 7 does game mode, 0 normal snapshot, anything else fixed allocations. diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 507047c27..781483e5d 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -11,7 +11,25 @@ * * * Removal or modification of this copyright notice is prohibited. * * * - ******************************************************************************/ + ***************************************************************************** + To create payments plan start a chain with -ac_snapshot=1440 (or for test something shorter, if you like.) + then in very early block < 10 or so, do paymentsairdrop eg. + `./komodo-cli -ac_name=TESTDP paymentsairdrop '[10,10,0,3999,0,0]' + copy the txid of this transaction after it is confirmed, then do: + './komodo-cli -ac_name=TESTDP opreturn_burn 1 4a8f6469f713251a0381170e275d68899d481270a5e48586276dbbbadff91b57' +copy the hex, and sendrawtransaction, copy the txid returned. +this places the txid that locates the plan into an op_return before block 100, allowing us to retreive it. +Restart the daemon with -earlytxid= +mine the chain past block 100, preventing anyone else, creating another payments plan on chain before block 100. + +We call the following in Validation and RPC where the address is needed. +if ( KOMODO_PRICES_FEE_SCRIPTPUB.size() == 0 ) + GetFeeAddress(); + +This will fetch the op_return, calculate the scriptPubKey and save it to the global. +On daemon restart as soon as validation for BETTX happens the global will be filled, afte this the transaction never needs to be looked up again. +GetFeeAddress is on line #2080 of komodo_bitcoind.h + */ #include "CCassets.h" #include "CCPrices.h" @@ -184,7 +202,8 @@ static bool ValidateBetTx(struct CCcontract_info *cp, Eval *eval, const CTransac int16_t leverage; CPubKey pk, pricespk; std::vector vec; - + if ( KOMODO_PRICES_FEE_SCRIPTPUB.size() == 0 ) + GetFeeAddress(); if (bettx.vout.size() < 5 || bettx.vout.size() > 6) return eval->Invalid("incorrect vout number for bet tx"); @@ -198,8 +217,11 @@ static bool ValidateBetTx(struct CCcontract_info *cp, Eval *eval, const CTransac return eval->Invalid("cannot validate vout0 in bet tx with pk from opreturn"); if (MakeCC1vout(cp->evalcode, bettx.vout[1].nValue, pricespk) != bettx.vout[1]) return eval->Invalid("cannot validate vout1 in bet tx with global pk"); - if( MakeCC1vout(cp->evalcode, bettx.vout[2].nValue, pricespk) != bettx.vout[2] ) + if (MakeCC1vout(cp->evalcode, bettx.vout[2].nValue, pricespk) != bettx.vout[2] ) return eval->Invalid("cannot validate vout2 in bet tx with pk from opreturn"); + // This should be all you need to verify it, maybe also check amount? + if ( bettx.vout[4].scriptPubKey != KOMODO_PRICES_FEE_SCRIPTPUB ) + return eval->Invalid("the fee was paid to wrong address."); int64_t betamount = bettx.vout[2].nValue; if (betamount != (positionsize * 199) / 200) { @@ -1382,14 +1404,22 @@ UniValue PricesBet(int64_t txfee, int64_t amount, int16_t leverage, std::vector< mtx.vout.push_back(MakeCC1vout(cp->evalcode, txfee, pricespk)); // vout1 cc marker (NVOUT_CCMARKER) mtx.vout.push_back(MakeCC1vout(cp->evalcode, betamount, pricespk)); // vout2 betamount mtx.vout.push_back(CTxOut(txfee, CScript() << ParseHex(HexStr(pricespk)) << OP_CHECKSIG)); // vout3 normal marker NVOUT_NORMALMARKER - TODO: remove it as we have cc marker now, when move to the new chain - + if ( KOMODO_PRICES_FEE_SCRIPTPUB.size() == 0 ) + { + // Lock here, as in validation we cannot call lock in the function itself. + // may not be needed as the validation call to update the global, is called in a LOCK already, and it can only update there and here. + LOCK(cs_main); + GetFeeAddress(); + } + mtx.vout.push_back(CTxOut(amount-betamount, KOMODO_PRICES_FEE_SCRIPTPUB)); + rawtx = FinalizeCCTx(0, cp, mtx, mypk, txfee, prices_betopret(mypk, nextheight - 1, amount, leverage, firstprice, vec, zeroid)); return(prices_rawtxresult(result, rawtx, 0)); } result.push_back(Pair("result", "error")); result.push_back(Pair("error", "not enough funds")); - return(result); + return(result); } // pricesaddfunding rpc impl: add yet another bet @@ -1988,4 +2018,4 @@ UniValue PricesGetOrderbook() prices_addbookentry(it->first.txhash); } return result; -} \ No newline at end of file +} diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 292d5f8df..e827ea78f 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -29,6 +29,7 @@ int32_t komodo_voutupdate(bool fJustCheck,int32_t *isratificationp,int32_t notar unsigned int lwmaGetNextPOSRequired(const CBlockIndex* pindexLast, const Consensus::Params& params); bool EnsureWalletIsAvailable(bool avoidException); extern bool fRequestShutdown; +extern CScript KOMODO_PRICES_FEE_SCRIPTPUB; int32_t MarmaraSignature(uint8_t *utxosig,CMutableTransaction &txNew); uint8_t DecodeMaramaraCoinbaseOpRet(const CScript scriptPubKey,CPubKey &pk,int32_t &height,int32_t &unlockht); @@ -2076,6 +2077,56 @@ bool komodo_appendACscriptpub() return false; } +void GetFeeAddress() +{ + if ( KOMODO_EARLYTXID == zeroid ) + { + fprintf(stderr, "PLEASE RESTART DAEMON WITH -earlytxid.\n"); + StartShutdown(); + return; + } + if ( KOMODO_SNAPSHOT_INTERVAL == 0 ) + { + fprintf(stderr, "PRICES FEE ADDRESS MUST HAVE -ac_snapshot enabled to pay out.\n"); + StartShutdown(); + return; + } + if ( chainActive.Height() < 100 ) + { + fprintf(stderr, "Cannot fetch -earlytxid before block 100.\n"); + StartShutdown(); + return; + } + CTransaction tx; uint256 blockhash, txid = zeroid; char txidaddr[64]; + // get transaction and check that it occured before height 100. + if ( myGetTransaction(KOMODO_EARLYTXID,tx,blockhash) && mapBlockIndex[blockhash]->GetHeight() < 100 ) + { + for (int i = 0; i < tx.vout.size(); i++) + if ( tx.vout[i].scriptPubKey[0] == OP_RETURN ) + txid = uint256S(HexStr(tx.vout[i].scriptPubKey.begin()+3, tx.vout[i].scriptPubKey.end())); + if ( txid == zeroid ) + { + fprintf(stderr, "INVALID -earlytxid, restart daemon with correct txid.\n"); + StartShutdown(); + } + fprintf(stderr, "txid.%s\n", txid.GetHex().c_str()); + struct CCcontract_info *cp, C; CPubKey Paymentspk,txidpk; + cp = CCinit(&C, EVAL_PAYMENTS); + Paymentspk = GetUnspendable(cp,0); + txidpk = CCtxidaddr(txidaddr,txid); + GetCCaddress1of2(cp,txidaddr,Paymentspk,txidpk); + CC *payoutCond = MakeCCcond1of2(EVAL_PAYMENTS,Paymentspk,txidpk); + KOMODO_PRICES_FEE_SCRIPTPUB = CCPubKey(payoutCond); + cc_free(payoutCond); + fprintf(stderr, "KOMODO_PRICES_FEE_SCRIPTPUB.%s address.%s\n", HexStr(KOMODO_PRICES_FEE_SCRIPTPUB.begin(),KOMODO_PRICES_FEE_SCRIPTPUB.end()).c_str(),txidaddr); + } + else + { + fprintf(stderr, "INVALID -earlytxid, restart daemon with correct txid.\n"); + StartShutdown(); + } +} + int64_t komodo_checkcommission(CBlock *pblock,int32_t height) { int64_t checktoshis=0; uint8_t *script,scripthex[8192]; int32_t scriptlen,matched = 0; static bool didinit = false; diff --git a/src/komodo_globals.h b/src/komodo_globals.h index 8d440cbaf..bc21bab10 100644 --- a/src/komodo_globals.h +++ b/src/komodo_globals.h @@ -110,6 +110,7 @@ extern int32_t KOMODO_LOADINGBLOCKS; unsigned int MAX_BLOCK_SIGOPS = 20000; int32_t KOMODO_TESTNODE, KOMODO_SNAPSHOT_INTERVAL; +CScript KOMODO_PRICES_FEE_SCRIPTPUB; struct komodo_kv *KOMODO_KV; pthread_mutex_t KOMODO_KV_mutex,KOMODO_CC_mutex; From 460033ad0571b8c4d4fe24c9fabb6cccb9b1916c Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Thu, 9 May 2019 01:25:07 +0800 Subject: [PATCH 248/447] change to work for all contracts --- src/cc/CCPrices.h | 4 +-- src/cc/prices.cpp | 56 +++++++++++++++++++++++++++------------- src/komodo_bitcoind.h | 41 ++++++++++------------------- src/komodo_defs.h | 3 ++- src/komodo_globals.h | 3 ++- src/komodo_utils.h | 9 +++++-- src/wallet/rpcwallet.cpp | 31 +++++++++------------- 7 files changed, 77 insertions(+), 70 deletions(-) diff --git a/src/cc/CCPrices.h b/src/cc/CCPrices.h index e6238533f..238131d59 100644 --- a/src/cc/CCPrices.h +++ b/src/cc/CCPrices.h @@ -20,8 +20,8 @@ #include "komodo_defs.h" #include "CCinclude.h" int32_t komodo_priceget(int64_t *buf64,int32_t ind,int32_t height,int32_t numblocks); -extern void GetFeeAddress(); -extern CScript KOMODO_PRICES_FEE_SCRIPTPUB; +extern void GetKomodoEarlytxidScriptPub(); +extern CScript KOMODO_EARLYTXID_SCRIPTPUB; // #define PRICES_DAYWINDOW ((3600*24/ASSETCHAINS_BLOCKTIME) + 1) // defined in komodo_defs.h #define PRICES_TXFEE 10000 diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 781483e5d..27529bca4 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -12,23 +12,34 @@ * Removal or modification of this copyright notice is prohibited. * * * ***************************************************************************** - To create payments plan start a chain with -ac_snapshot=1440 (or for test something shorter, if you like.) - then in very early block < 10 or so, do paymentsairdrop eg. - `./komodo-cli -ac_name=TESTDP paymentsairdrop '[10,10,0,3999,0,0]' - copy the txid of this transaction after it is confirmed, then do: - './komodo-cli -ac_name=TESTDP opreturn_burn 1 4a8f6469f713251a0381170e275d68899d481270a5e48586276dbbbadff91b57' +To create payments plan start a chain with the following ac_params: + -ac_snapshot=1440 (or for test chain something smaller, if you like.) + - this enables the payments airdrop cc to work. + -ac_earlytxidcontract=237 (Eval code for prices cc.) + - this allows to know what contract this chain is paying with the scriptpubkey in the earlytxid op_return. + +./komodod -ac_name=TESTPRC -ac_supply=100000000 -ac_reward=1000000000 -ac_nk=96,5 -ac_blocktime=20 -ac_cc=2 -ac_snapshot=50 -ac_sapling=1 -ac_earlytxidcontract=237 -testnode=1 -gen -genproclimit=1 + +Then in very early block < 10 or so, do paymentsairdrop eg. + `./komodo-cli -ac_name=TESTPRC paymentsairdrop '[10,10,0,3999,0,0]' +Once this tx is confirmed, do `paymentsfund` and decode the raw hex. You can edit the source to not send the tx if requried. +Get the full `hex` of the vout[0] that pays to CryptoCondition. then place it on chain with the following command: with the hex you got in place of the hex below. + './komodo-cli -ac_name=TESTPRC opreturn_burn 1 2ea22c8020292ba5c8fd9cc89b12b35bf8f5d00196990ecbb06102b84d9748d11d883ef01e81031210008203000401cc' copy the hex, and sendrawtransaction, copy the txid returned. -this places the txid that locates the plan into an op_return before block 100, allowing us to retreive it. -Restart the daemon with -earlytxid= +this places the scriptpubkey that pays the plan into an op_return before block 100, allowing us to retreive it, and nobody to change it. +Restart the daemon with -earlytxid= eg: + +./komodod -ac_name=TESTPRC -ac_supply=100000000 -ac_reward=1000000000 -ac_nk=96,5 -ac_blocktime=20 -ac_cc=2 -ac_snapshot=50 -ac_sapling=1 -ac_earlytxidcontract=237 -earlytxid=cf89d17fb11037f65c160d0749dddd74dc44d9893b0bb67fe1f96c1f59786496 -testnode=1 -gen -genproclimit=1 + mine the chain past block 100, preventing anyone else, creating another payments plan on chain before block 100. We call the following in Validation and RPC where the address is needed. -if ( KOMODO_PRICES_FEE_SCRIPTPUB.size() == 0 ) - GetFeeAddress(); +if ( ASSETCHAINS_EARLYTXIDCONTRACT == EVAL_PRICES && KOMODO_EARLYTXID_SCRIPTPUB.size() == 0 ) + GetKomodoEarlytxidScriptPub(); This will fetch the op_return, calculate the scriptPubKey and save it to the global. -On daemon restart as soon as validation for BETTX happens the global will be filled, afte this the transaction never needs to be looked up again. -GetFeeAddress is on line #2080 of komodo_bitcoind.h +On daemon restart as soon as validation for BETTX happens the global will be filled, after this the transaction never needs to be looked up again. +GetKomodoEarlytxidScriptPub is on line #2080 of komodo_bitcoind.h */ #include "CCassets.h" @@ -202,8 +213,8 @@ static bool ValidateBetTx(struct CCcontract_info *cp, Eval *eval, const CTransac int16_t leverage; CPubKey pk, pricespk; std::vector vec; - if ( KOMODO_PRICES_FEE_SCRIPTPUB.size() == 0 ) - GetFeeAddress(); + if ( ASSETCHAINS_EARLYTXIDCONTRACT == EVAL_PRICES && KOMODO_EARLYTXID_SCRIPTPUB.size() == 0 ) + GetKomodoEarlytxidScriptPub(); if (bettx.vout.size() < 5 || bettx.vout.size() > 6) return eval->Invalid("incorrect vout number for bet tx"); @@ -220,7 +231,7 @@ static bool ValidateBetTx(struct CCcontract_info *cp, Eval *eval, const CTransac if (MakeCC1vout(cp->evalcode, bettx.vout[2].nValue, pricespk) != bettx.vout[2] ) return eval->Invalid("cannot validate vout2 in bet tx with pk from opreturn"); // This should be all you need to verify it, maybe also check amount? - if ( bettx.vout[4].scriptPubKey != KOMODO_PRICES_FEE_SCRIPTPUB ) + if ( bettx.vout[4].scriptPubKey != KOMODO_EARLYTXID_SCRIPTPUB ) return eval->Invalid("the fee was paid to wrong address."); int64_t betamount = bettx.vout[2].nValue; @@ -1369,6 +1380,15 @@ int64_t prices_enumaddedbets(uint256 &batontxid, std::vector &bets, // pricesbet rpc impl: make betting tx UniValue PricesBet(int64_t txfee, int64_t amount, int16_t leverage, std::vector synthetic) { + fprintf(stderr, "assetchains_contract.%i vs eval_prices.%i\n",ASSETCHAINS_EARLYTXIDCONTRACT, EVAL_PRICES); + if ( ASSETCHAINS_EARLYTXIDCONTRACT == EVAL_PRICES && KOMODO_EARLYTXID_SCRIPTPUB.size() == 0 ) + { + // Lock here, as in validation we cannot call lock in the function itself. + // may not be needed as the validation call to update the global, is called in a LOCK already, and it can only update there and here. + LOCK(cs_main); + GetKomodoEarlytxidScriptPub(); + } + /* int32_t nextheight = komodo_nextheight(); CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), nextheight); UniValue result(UniValue::VOBJ); struct CCcontract_info *cp, C; @@ -1404,15 +1424,14 @@ UniValue PricesBet(int64_t txfee, int64_t amount, int16_t leverage, std::vector< mtx.vout.push_back(MakeCC1vout(cp->evalcode, txfee, pricespk)); // vout1 cc marker (NVOUT_CCMARKER) mtx.vout.push_back(MakeCC1vout(cp->evalcode, betamount, pricespk)); // vout2 betamount mtx.vout.push_back(CTxOut(txfee, CScript() << ParseHex(HexStr(pricespk)) << OP_CHECKSIG)); // vout3 normal marker NVOUT_NORMALMARKER - TODO: remove it as we have cc marker now, when move to the new chain - if ( KOMODO_PRICES_FEE_SCRIPTPUB.size() == 0 ) + if ( ASSETCHAINS_EARLYTXIDCONTRACT == EVAL_PRICES && KOMODO_EARLYTXID_SCRIPTPUB.size() == 0 ) { // Lock here, as in validation we cannot call lock in the function itself. // may not be needed as the validation call to update the global, is called in a LOCK already, and it can only update there and here. LOCK(cs_main); - GetFeeAddress(); + GetKomodoEarlytxidScriptPub(); } - mtx.vout.push_back(CTxOut(amount-betamount, KOMODO_PRICES_FEE_SCRIPTPUB)); - + mtx.vout.push_back(CTxOut(amount-betamount, KOMODO_EARLYTXID_SCRIPTPUB)); rawtx = FinalizeCCTx(0, cp, mtx, mypk, txfee, prices_betopret(mypk, nextheight - 1, amount, leverage, firstprice, vec, zeroid)); return(prices_rawtxresult(result, rawtx, 0)); @@ -1420,6 +1439,7 @@ UniValue PricesBet(int64_t txfee, int64_t amount, int16_t leverage, std::vector< result.push_back(Pair("result", "error")); result.push_back(Pair("error", "not enough funds")); return(result); + */ } // pricesaddfunding rpc impl: add yet another bet diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index e827ea78f..e616fb179 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -29,7 +29,7 @@ int32_t komodo_voutupdate(bool fJustCheck,int32_t *isratificationp,int32_t notar unsigned int lwmaGetNextPOSRequired(const CBlockIndex* pindexLast, const Consensus::Params& params); bool EnsureWalletIsAvailable(bool avoidException); extern bool fRequestShutdown; -extern CScript KOMODO_PRICES_FEE_SCRIPTPUB; +extern CScript KOMODO_EARLYTXID_SCRIPTPUB; int32_t MarmaraSignature(uint8_t *utxosig,CMutableTransaction &txNew); uint8_t DecodeMaramaraCoinbaseOpRet(const CScript scriptPubKey,CPubKey &pk,int32_t &height,int32_t &unlockht); @@ -2063,7 +2063,6 @@ bool komodo_appendACscriptpub() { ASSETCHAINS_SCRIPTPUB.pop_back(); ASSETCHAINS_SCRIPTPUB.pop_back(); // remove last 2 chars. // get OP_RETURN from txid and append the HexStr of it to scriptpub - // encoded opreturn incorrectly on TESTHC chain, once we no longer need this it can be changed to a straight +1 to drop OP_RETURN opcode. ASSETCHAINS_SCRIPTPUB.append(HexStr(tx.vout[i].scriptPubKey.begin()+3, tx.vout[i].scriptPubKey.end())); //fprintf(stderr, "ac_script.%s\n",ASSETCHAINS_SCRIPTPUB.c_str()); didinit = true; @@ -2077,17 +2076,17 @@ bool komodo_appendACscriptpub() return false; } -void GetFeeAddress() +void GetKomodoEarlytxidScriptPub() { if ( KOMODO_EARLYTXID == zeroid ) { - fprintf(stderr, "PLEASE RESTART DAEMON WITH -earlytxid.\n"); + fprintf(stderr, "Restart deamon with -earlytxid.\n"); StartShutdown(); return; } - if ( KOMODO_SNAPSHOT_INTERVAL == 0 ) + if ( ASSETCHAINS_EARLYTXIDCONTRACT == EVAL_PRICES && KOMODO_SNAPSHOT_INTERVAL == 0 ) { - fprintf(stderr, "PRICES FEE ADDRESS MUST HAVE -ac_snapshot enabled to pay out.\n"); + fprintf(stderr, "Prices->paymentsCC contract must have -ac_snapshot enabled to pay out.\n"); StartShutdown(); return; } @@ -2097,34 +2096,22 @@ void GetFeeAddress() StartShutdown(); return; } - CTransaction tx; uint256 blockhash, txid = zeroid; char txidaddr[64]; + CTransaction tx; uint256 blockhash; int32_t i; // get transaction and check that it occured before height 100. if ( myGetTransaction(KOMODO_EARLYTXID,tx,blockhash) && mapBlockIndex[blockhash]->GetHeight() < 100 ) { - for (int i = 0; i < tx.vout.size(); i++) + for (i = 0; i < tx.vout.size(); i++) if ( tx.vout[i].scriptPubKey[0] == OP_RETURN ) - txid = uint256S(HexStr(tx.vout[i].scriptPubKey.begin()+3, tx.vout[i].scriptPubKey.end())); - if ( txid == zeroid ) + break; + if ( i < tx.vout.size() ) { - fprintf(stderr, "INVALID -earlytxid, restart daemon with correct txid.\n"); - StartShutdown(); + KOMODO_EARLYTXID_SCRIPTPUB = CScript(tx.vout[i].scriptPubKey.begin()+3, tx.vout[i].scriptPubKey.end()); + fprintf(stderr, "KOMODO_EARLYTXID_SCRIPTPUB.%s\n", HexStr(KOMODO_EARLYTXID_SCRIPTPUB.begin(),KOMODO_EARLYTXID_SCRIPTPUB.end()).c_str()); + return; } - fprintf(stderr, "txid.%s\n", txid.GetHex().c_str()); - struct CCcontract_info *cp, C; CPubKey Paymentspk,txidpk; - cp = CCinit(&C, EVAL_PAYMENTS); - Paymentspk = GetUnspendable(cp,0); - txidpk = CCtxidaddr(txidaddr,txid); - GetCCaddress1of2(cp,txidaddr,Paymentspk,txidpk); - CC *payoutCond = MakeCCcond1of2(EVAL_PAYMENTS,Paymentspk,txidpk); - KOMODO_PRICES_FEE_SCRIPTPUB = CCPubKey(payoutCond); - cc_free(payoutCond); - fprintf(stderr, "KOMODO_PRICES_FEE_SCRIPTPUB.%s address.%s\n", HexStr(KOMODO_PRICES_FEE_SCRIPTPUB.begin(),KOMODO_PRICES_FEE_SCRIPTPUB.end()).c_str(),txidaddr); - } - else - { - fprintf(stderr, "INVALID -earlytxid, restart daemon with correct txid.\n"); - StartShutdown(); } + fprintf(stderr, "INVALID -earlytxid, restart daemon with correct txid.\n"); + StartShutdown(); } int64_t komodo_checkcommission(CBlock *pblock,int32_t height) diff --git a/src/komodo_defs.h b/src/komodo_defs.h index 0737356df..5efbe58fb 100644 --- a/src/komodo_defs.h +++ b/src/komodo_defs.h @@ -84,6 +84,7 @@ extern uint8_t ASSETCHAINS_PRIVATE; extern int32_t USE_EXTERNAL_PUBKEY; extern char NOTARYADDRS[64][64]; extern int32_t KOMODO_TESTNODE, KOMODO_SNAPSHOT_INTERVAL; +extern int32_t ASSETCHAINS_EARLYTXIDCONTRACT; int tx_height( const uint256 &hash ); extern std::vector vWhiteListAddress; void komodo_netevent(std::vector payload); @@ -117,4 +118,4 @@ int32_t komodo_priceget(int64_t *buf64,int32_t ind,int32_t height,int32_t numblo uint64_t komodo_accrued_interest(int32_t *txheightp,uint32_t *locktimep,uint256 hash,int32_t n,int32_t checkheight,uint64_t checkvalue,int32_t tipheight); -#endif \ No newline at end of file +#endif diff --git a/src/komodo_globals.h b/src/komodo_globals.h index bc21bab10..08c633ee7 100644 --- a/src/komodo_globals.h +++ b/src/komodo_globals.h @@ -110,7 +110,8 @@ extern int32_t KOMODO_LOADINGBLOCKS; unsigned int MAX_BLOCK_SIGOPS = 20000; int32_t KOMODO_TESTNODE, KOMODO_SNAPSHOT_INTERVAL; -CScript KOMODO_PRICES_FEE_SCRIPTPUB; +CScript KOMODO_EARLYTXID_SCRIPTPUB; +int32_t ASSETCHAINS_EARLYTXIDCONTRACT; struct komodo_kv *KOMODO_KV; pthread_mutex_t KOMODO_KV_mutex,KOMODO_CC_mutex; diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 52539e35d..857dfe4c8 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1759,6 +1759,8 @@ void komodo_args(char *argv0) printf("KOMODO_REWIND %d\n",KOMODO_REWIND); } KOMODO_EARLYTXID = Parseuint256(GetArg("-earlytxid","0").c_str()); + ASSETCHAINS_EARLYTXIDCONTRACT = GetArg("-ac_earlytxidcontract",0); + fprintf(stderr, "ASSETCHAINS_EARLYTXIDCONTRACT.%i\n", ASSETCHAINS_EARLYTXIDCONTRACT); if ( name.c_str()[0] != 0 ) { std::string selectedAlgo = GetArg("-ac_algo", std::string(ASSETCHAINS_ALGORITHMS[0])); @@ -2013,7 +2015,7 @@ void komodo_args(char *argv0) fprintf(stderr,"-ac_script and -ac_marmara are mutually exclusive\n"); StartShutdown(); } - 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 || nonz > 0 || ASSETCHAINS_CCLIB.size() > 0 || ASSETCHAINS_FOUNDERS_REWARD != 0 || ASSETCHAINS_NOTARY_PAY[0] != 0 || ASSETCHAINS_BLOCKTIME != 60 || ASSETCHAINS_CBOPRET != 0 || Mineropret.size() != 0 || (ASSETCHAINS_NK[0] != 0 && ASSETCHAINS_NK[1] != 0) || KOMODO_SNAPSHOT_INTERVAL != 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 || nonz > 0 || ASSETCHAINS_CCLIB.size() > 0 || ASSETCHAINS_FOUNDERS_REWARD != 0 || ASSETCHAINS_NOTARY_PAY[0] != 0 || ASSETCHAINS_BLOCKTIME != 60 || ASSETCHAINS_CBOPRET != 0 || Mineropret.size() != 0 || (ASSETCHAINS_NK[0] != 0 && ASSETCHAINS_NK[1] != 0) || KOMODO_SNAPSHOT_INTERVAL != 0 || ASSETCHAINS_EARLYTXIDCONTRACT != 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; @@ -2152,7 +2154,10 @@ void komodo_args(char *argv0) if ( KOMODO_SNAPSHOT_INTERVAL != 0 ) { extralen += iguana_rwnum(1,&extraptr[extralen],sizeof(KOMODO_SNAPSHOT_INTERVAL),(void *)&KOMODO_SNAPSHOT_INTERVAL); - fprintf(stderr, "snapshot interval.%i\n",KOMODO_SNAPSHOT_INTERVAL); + } + if ( ASSETCHAINS_EARLYTXIDCONTRACT != 0 ) + { + extralen += iguana_rwnum(1,&extraptr[extralen],sizeof(ASSETCHAINS_EARLYTXIDCONTRACT),(void *)&ASSETCHAINS_EARLYTXIDCONTRACT); } } diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index dc3b07418..5ce7ae773 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -8000,6 +8000,7 @@ void RegisterWalletRPCCommands(CRPCTable &tableRPC) UniValue opreturn_burn(const UniValue& params, bool fHelp) { + std::vector vHexStr; CScript opret; int32_t txfee = 10000; if (fHelp || (params.size() != 2)) throw runtime_error("amount to burn, hexstring to send\n"); struct CCcontract_info *cp, C; UniValue ret(UniValue::VOBJ); @@ -8009,30 +8010,22 @@ UniValue opreturn_burn(const UniValue& params, bool fHelp) CAmount nAmount = AmountFromValue(params[0]); if (nAmount <= 10000) - throw JSONRPCError(RPC_TYPE_ERROR, "must send at least 10000 sat"); - std::string strHex = params[1].get_str(); + throw JSONRPCError(RPC_TYPE_ERROR, "must burn at least 10000 sat"); + vHexStr = ParseHex(params[1].get_str()); + if ( vHexStr.size() == 0 ) + throw JSONRPCError(RPC_TYPE_ERROR, "hexstring is not valid."); + CPubKey myPubkey = pubkey2pk(Mypubkey()); CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); int64_t normalInputs = AddNormalinputs(mtx, myPubkey, nAmount, 60); if (normalInputs < nAmount) throw runtime_error("not enough normals\n"); - - CScript opret; uint8_t scripthex[8192]; - - decode_hex(scripthex,strHex.size()/2,(char *)strHex.c_str()); - std::string test; - test.append((char*)scripthex); - std::vector opretdata(test.begin(), test.end()); - opret << OP_RETURN << E_MARSHAL(ss << opretdata); - /*CScript opret; uint8_t *ptr; - opret << OP_RETURN << 0; - int32_t len = strlen(strHex.c_str()); - len >>=1; - opret.resize(len+2); - ptr = (uint8_t *)&opret[1]; - decode_hex(ptr,len,(char *)strHex.c_str()); */ - mtx.vout.push_back(CTxOut(nAmount,opret)); - ret.push_back(Pair("hex",FinalizeCCTx(0, cp, mtx, myPubkey, 10000, CScript()))); + + opret << OP_RETURN << E_MARSHAL(ss << vHexStr); + + mtx.vout.push_back(CTxOut(txfee,CScript() << ParseHex(HexStr(myPubkey)) << OP_CHECKSIG)); + mtx.vout.push_back(CTxOut(nAmount,opret)); + ret.push_back(Pair("hex",FinalizeCCTx(0, cp, mtx, myPubkey, txfee, CScript()))); return(ret); } From 0cf5126cc9add1a974d12eb8e7800d26d62dccd7 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Thu, 9 May 2019 16:54:20 +0800 Subject: [PATCH 249/447] fix RPC for airdrop, change to intake addresses instead of scriptpubkeys. --- src/cc/CCPayments.h | 1 + src/cc/payments.cpp | 33 +++++++++++++++++++++------------ src/main.cpp | 2 +- 3 files changed, 23 insertions(+), 13 deletions(-) diff --git a/src/cc/CCPayments.h b/src/cc/CCPayments.h index 13c66d358..a7cd4f916 100644 --- a/src/cc/CCPayments.h +++ b/src/cc/CCPayments.h @@ -19,6 +19,7 @@ #include "CCinclude.h" #include +#include #define PAYMENTS_TXFEE 10000 #define PAYMENTS_MERGEOFSET 10 // 100? diff --git a/src/cc/payments.cpp b/src/cc/payments.cpp index 6311e393d..ce817ac0d 100644 --- a/src/cc/payments.cpp +++ b/src/cc/payments.cpp @@ -1208,16 +1208,22 @@ UniValue PaymentsAirdrop(struct CCcontract_info *cp,char *jsonstr) { for (i=0; i vscriptPubKey; CScript scriptPubKey = GetScriptForDestination(destination); - */ - char *inputhex = jstri(params,6+i); - std::vector scriptPubKey; - int32_t len = strlen(inputhex)/2; - scriptPubKey.resize(len); - decode_hex((uint8_t *)scriptPubKey.data(),len,(char *)inputhex); - excludeScriptPubKeys.push_back(scriptPubKey); + vscriptPubKey.assign(scriptPubKey.begin(), scriptPubKey.end()); + excludeScriptPubKeys.push_back(vscriptPubKey); } } mypk = pubkey2pk(Mypubkey()); @@ -1331,10 +1337,13 @@ UniValue PaymentsInfo(struct CCcontract_info *cp,char *jsonstr) result.push_back(Pair("bottom",(int64_t)bottom)); result.push_back(Pair("top",(int64_t)top)); result.push_back(Pair("fixedFlag",(int64_t)fixedAmount)); - // TODO: convert to show addresses instead of scriptpubkey. for ( auto scriptPubKey : excludeScriptPubKeys ) - a.push_back(HexStr(scriptPubKey.begin(),scriptPubKey.end())); - result.push_back(Pair("excludeScriptPubkeys",a)); + { + CTxDestination dest; + if ( ExtractDestination(CScript(scriptPubKey.begin(),scriptPubKey.end()), dest) ) + a.push_back(CBitcoinAddress(dest).ToString()); + } + result.push_back(Pair("excludeAddresses",a)); } else if ( DecodePaymentsTokensOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,lockedblocks,minrelease,top,excludeScriptPubKeys,tokenid) != 0 ) { diff --git a/src/main.cpp b/src/main.cpp index 1ec1d1560..5203888de 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -731,7 +731,7 @@ bool komodo_dailysnapshot(int32_t height) std::sort(vAddressSnapshot.rbegin(), vAddressSnapshot.rend()); //for (int j = 0; j < 50; j++) // fprintf(stderr, "j.%i address.%s nValue.%li\n",j, CBitcoinAddress(vAddressSnapshot[j].second).ToString().c_str(), vAddressSnapshot[j].first ); - // include only top 5000 address. + // include only top 3999 address. if ( vAddressSnapshot.size() > 3999 ) vAddressSnapshot.resize(3999); lastSnapShotHeight = undo_height; fprintf(stderr, "vAddressSnapshot.size.%li\n", vAddressSnapshot.size()); From 43142447041d2aa130f118004c023ffc2682eab0 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Thu, 9 May 2019 17:42:58 +0800 Subject: [PATCH 250/447] prepare tokens airdrop --- src/cc/payments.cpp | 47 ++++++++++++++------------------------------- 1 file changed, 14 insertions(+), 33 deletions(-) diff --git a/src/cc/payments.cpp b/src/cc/payments.cpp index ce817ac0d..ecb302a8d 100644 --- a/src/cc/payments.cpp +++ b/src/cc/payments.cpp @@ -160,13 +160,7 @@ uint8_t DecodePaymentsOpRet(CScript scriptPubKey,int32_t &lockedblocks,int32_t & CScript EncodePaymentsSnapsShotOpRet(int32_t lockedblocks,int32_t minrelease,int32_t minimum,int32_t top,int32_t bottom,int8_t fixedAmount,std::vector> excludeScriptPubKeys) { CScript opret; uint8_t evalcode = EVAL_PAYMENTS; - if ( (strcmp(ASSETCHAINS_SYMBOL, "CFEKPAY") == 0) ) // exempt for now, remove this after game completed. - { - minimum = 10000; - opret << OP_RETURN << E_MARSHAL(ss << evalcode << 'S' << lockedblocks << minrelease << top << bottom << fixedAmount << excludeScriptPubKeys); - } - else - opret << OP_RETURN << E_MARSHAL(ss << evalcode << 'S' << lockedblocks << minrelease << minimum << top << bottom << fixedAmount << excludeScriptPubKeys); + opret << OP_RETURN << E_MARSHAL(ss << evalcode << 'S' << lockedblocks << minrelease << minimum << top << bottom << fixedAmount << excludeScriptPubKeys); return(opret); } @@ -175,40 +169,27 @@ uint8_t DecodePaymentsSnapsShotOpRet(CScript scriptPubKey,int32_t &lockedblocks, std::vector vopret; uint8_t *script,e,f; GetOpReturnData(scriptPubKey, vopret); script = (uint8_t *)vopret.data(); - if ( (strcmp(ASSETCHAINS_SYMBOL, "CFEKPAY") == 0) ) // exempt for now, remove this after game completed. + if ( vopret.size() > 2 && E_UNMARSHAL(vopret,ss >> e; ss >> f; ss >> lockedblocks; ss >> minrelease; ss >> minimum; ss >> top; ; ss >> bottom; ss >> fixedAmount; ss >> excludeScriptPubKeys) != 0 ) { - minimum = 10000; - if ( vopret.size() > 2 && E_UNMARSHAL(vopret,ss >> e; ss >> f; ss >> lockedblocks; ss >> minrelease; ss >> top; ; ss >> bottom; ss >> fixedAmount; ss >> excludeScriptPubKeys) != 0 ) - { - if ( e == EVAL_PAYMENTS && f == 'S' ) - return(f); - } - } - else - { - - if ( vopret.size() > 2 && E_UNMARSHAL(vopret,ss >> e; ss >> f; ss >> lockedblocks; ss >> minrelease; ss >> minimum; ss >> top; ; ss >> bottom; ss >> fixedAmount; ss >> excludeScriptPubKeys) != 0 ) - { - if ( e == EVAL_PAYMENTS && f == 'S' ) - return(f); - } + if ( e == EVAL_PAYMENTS && f == 'S' ) + return(f); } return(0); } -CScript EncodePaymentsTokensOpRet(int32_t lockedblocks,int32_t minrelease,int32_t top,std::vector> excludeScriptPubKeys, uint256 tokenid) +CScript EncodePaymentsTokensOpRet(int32_t lockedblocks,int32_t minrelease,int32_t minimum,int32_t top,int32_t bottom,int8_t fixedAmount,std::vector> excludeScriptPubKeys,uint256 tokenid) { CScript opret; uint8_t evalcode = EVAL_PAYMENTS; - opret << OP_RETURN << E_MARSHAL(ss << evalcode << 'O' << lockedblocks << minrelease << top << excludeScriptPubKeys << tokenid); + opret << OP_RETURN << E_MARSHAL(ss << evalcode << 'O' << lockedblocks << minrelease << minimum << top << bottom << fixedAmount << excludeScriptPubKeys << tokenid); return(opret); } -uint8_t DecodePaymentsTokensOpRet(CScript scriptPubKey,int32_t &lockedblocks,int32_t &minrelease,int32_t &top,std::vector> &excludeScriptPubKeys, uint256 &tokenid) +uint8_t DecodePaymentsTokensOpRet(CScript scriptPubKey,int32_t &lockedblocks,int32_t &minrelease,int32_t &minimum,int32_t &top,int32_t &bottom,int8_t &fixedAmount,std::vector> &excludeScriptPubKeys, uint256 &tokenid) { std::vector vopret; uint8_t *script,e,f; GetOpReturnData(scriptPubKey, vopret); script = (uint8_t *)vopret.data(); - if ( vopret.size() > 2 && E_UNMARSHAL(vopret,ss >> e; ss >> f; ss >> lockedblocks; ss >> minrelease; ss >> top; ss >> excludeScriptPubKeys; ss >> tokenid) != 0 ) + if ( vopret.size() > 2 && E_UNMARSHAL(vopret,ss >> e; ss >> f; ss >> lockedblocks; ss >> minimum; ss >> top; ; ss >> bottom; ss >> fixedAmount; ss >> excludeScriptPubKeys; ss >> tokenid) != 0 ) { if ( e == EVAL_PAYMENTS && f == 'O' ) return(f); @@ -308,7 +289,7 @@ bool PaymentsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction & // use the createtxid to fetch the tx and all of the plans info. if ( myGetTransaction(createtxid,plantx,blockhash) != 0 && plantx.vout.size() > 0 ) { - if ( ((funcid= DecodePaymentsOpRet(plantx.vout[plantx.vout.size()-1].scriptPubKey,lockedblocks,minrelease,totalallocations,txidoprets)) == 'C' || (funcid= DecodePaymentsSnapsShotOpRet(plantx.vout[plantx.vout.size()-1].scriptPubKey,lockedblocks,minrelease,minimum,top,bottom,fixedAmount,excludeScriptPubKeys)) == 'S' || (funcid= DecodePaymentsTokensOpRet(plantx.vout[plantx.vout.size()-1].scriptPubKey,lockedblocks,minrelease,top,excludeScriptPubKeys,tokenid)) == 'O') ) + if ( ((funcid= DecodePaymentsOpRet(plantx.vout[plantx.vout.size()-1].scriptPubKey,lockedblocks,minrelease,totalallocations,txidoprets)) == 'C' || (funcid= DecodePaymentsSnapsShotOpRet(plantx.vout[plantx.vout.size()-1].scriptPubKey,lockedblocks,minrelease,minimum,top,bottom,fixedAmount,excludeScriptPubKeys)) == 'S' || (funcid= DecodePaymentsTokensOpRet(plantx.vout[plantx.vout.size()-1].scriptPubKey,lockedblocks,minrelease,minimum,top,bottom,fixedAmount,excludeScriptPubKeys,tokenid)) == 'O') ) { if ( lockedblocks < 0 || minrelease < 0 || (totalallocations <= 0 && top <= 0 ) ) return(eval->Invalid("negative values")); @@ -703,7 +684,7 @@ UniValue PaymentsRelease(struct CCcontract_info *cp,char *jsonstr) amount = jdouble(jitem(params,1),0) * SATOSHIDEN + 0.0000000049; if ( myGetTransaction(createtxid,tx,hashBlock) != 0 && tx.vout.size() > 0 ) { - if ( ((funcid= DecodePaymentsOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,lockedblocks,minrelease,totalallocations,txidoprets)) == 'C' || (funcid= DecodePaymentsSnapsShotOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,lockedblocks,minrelease,minimum,top,bottom,fixedAmount,excludeScriptPubKeys)) == 'S' || (funcid= DecodePaymentsTokensOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,lockedblocks,minrelease,top,excludeScriptPubKeys,tokenid)) == 'O') ) + if ( ((funcid= DecodePaymentsOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,lockedblocks,minrelease,totalallocations,txidoprets)) == 'C' || (funcid= DecodePaymentsSnapsShotOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,lockedblocks,minrelease,minimum,top,bottom,fixedAmount,excludeScriptPubKeys)) == 'S' || (funcid= DecodePaymentsTokensOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,lockedblocks,minrelease,minimum,top,bottom,fixedAmount,excludeScriptPubKeys,tokenid)) == 'O') ) { if ( lockedblocks < 0 || minrelease < 0 || (totalallocations <= 0 && top <= 0 ) ) { @@ -948,7 +929,7 @@ UniValue PaymentsFund(struct CCcontract_info *cp,char *jsonstr) amount = jdouble(jitem(params,1),0) * SATOSHIDEN + 0.0000000049; if ( n == 3 ) useopret = jint(jitem(params,2),0) != 0; - if ( myGetTransaction(txid,tx,hashBlock) == 0 || tx.vout.size() == 1 || (DecodePaymentsOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,lockedblocks,minrelease,totalallocations,txidoprets) == 0 && DecodePaymentsSnapsShotOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,lockedblocks,minrelease,minimum,top,bottom,fixedAmount,excludeScriptPubKeys) == 0 && DecodePaymentsTokensOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,lockedblocks,minrelease,top,excludeScriptPubKeys,tokenid) == 0) ) + if ( myGetTransaction(txid,tx,hashBlock) == 0 || tx.vout.size() == 1 || (DecodePaymentsOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,lockedblocks,minrelease,totalallocations,txidoprets) == 0 && DecodePaymentsSnapsShotOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,lockedblocks,minrelease,minimum,top,bottom,fixedAmount,excludeScriptPubKeys) == 0 && DecodePaymentsTokensOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,lockedblocks,minrelease,minimum,top,bottom,fixedAmount,excludeScriptPubKeys,tokenid) == 0) ) { result.push_back(Pair("result","error")); result.push_back(Pair("error","invalid createtxid")); @@ -1014,7 +995,7 @@ UniValue PaymentsMerge(struct CCcontract_info *cp,char *jsonstr) { createtxid = payments_juint256(jitem(params,0)); txidpk = CCtxidaddr(txidaddr,createtxid); - if ( myGetTransaction(createtxid,tx,hashBlock) == 0 || tx.vout.size() == 1 || (DecodePaymentsOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,lockedblocks,minrelease,totalallocations,txidoprets) == 0 && DecodePaymentsSnapsShotOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,lockedblocks,minrelease,minimum,top,bottom,fixedAmount,excludeScriptPubKeys) == 0 && DecodePaymentsTokensOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,lockedblocks,minrelease,top,excludeScriptPubKeys,tokenid) == 0) ) + if ( myGetTransaction(createtxid,tx,hashBlock) == 0 || tx.vout.size() == 1 || (DecodePaymentsOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,lockedblocks,minrelease,totalallocations,txidoprets) == 0 && DecodePaymentsSnapsShotOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,lockedblocks,minrelease,minimum,top,bottom,fixedAmount,excludeScriptPubKeys) == 0 && DecodePaymentsTokensOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,lockedblocks,minrelease,minimum,top,bottom,fixedAmount,excludeScriptPubKeys,tokenid) == 0) ) { result.push_back(Pair("result","error")); result.push_back(Pair("error","invalid createtxid")); @@ -1345,7 +1326,7 @@ UniValue PaymentsInfo(struct CCcontract_info *cp,char *jsonstr) } result.push_back(Pair("excludeAddresses",a)); } - else if ( DecodePaymentsTokensOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,lockedblocks,minrelease,top,excludeScriptPubKeys,tokenid) != 0 ) + else if ( DecodePaymentsTokensOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,lockedblocks,minrelease,minimum,top,bottom,fixedAmount,excludeScriptPubKeys,tokenid) != 0 ) { if ( lockedblocks < 0 || minrelease < 0 || top <= 0 ) { @@ -1416,7 +1397,7 @@ UniValue PaymentsList(struct CCcontract_info *cp,char *jsonstr) txid = it->first.txhash; if ( it->first.index == 0 && myGetTransaction(txid,tx,hashBlock) != 0 ) { - if ( tx.vout.size() > 0 && (DecodePaymentsOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,lockedblocks,minrelease,totalallocations,txidoprets) == 'C' || DecodePaymentsSnapsShotOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,lockedblocks,minrelease,minimum,top,bottom,fixedAmount,excludeScriptPubKeys) == 'S' || DecodePaymentsTokensOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,lockedblocks,minrelease,top,excludeScriptPubKeys,tokenid) == 'O') ) + if ( tx.vout.size() > 0 && (DecodePaymentsOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,lockedblocks,minrelease,totalallocations,txidoprets) == 'C' || DecodePaymentsSnapsShotOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,lockedblocks,minrelease,minimum,top,bottom,fixedAmount,excludeScriptPubKeys) == 'S' || DecodePaymentsTokensOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,lockedblocks,minrelease,minimum,top,bottom,fixedAmount,excludeScriptPubKeys,tokenid) == 'O') ) { if ( lockedblocks < 0 || minrelease < 0 || (totalallocations <= 0 && top <= 0 ) || bottom < 0 || fixedAmount < 0 || minimum < 10000 ) { From 162694ad6a53c219bdfaf5848f8efdea8be6832b Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Thu, 9 May 2019 17:48:21 +0800 Subject: [PATCH 251/447] fix pricesbet --- src/cc/prices.cpp | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 27529bca4..2116f2e8e 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -1380,15 +1380,6 @@ int64_t prices_enumaddedbets(uint256 &batontxid, std::vector &bets, // pricesbet rpc impl: make betting tx UniValue PricesBet(int64_t txfee, int64_t amount, int16_t leverage, std::vector synthetic) { - fprintf(stderr, "assetchains_contract.%i vs eval_prices.%i\n",ASSETCHAINS_EARLYTXIDCONTRACT, EVAL_PRICES); - if ( ASSETCHAINS_EARLYTXIDCONTRACT == EVAL_PRICES && KOMODO_EARLYTXID_SCRIPTPUB.size() == 0 ) - { - // Lock here, as in validation we cannot call lock in the function itself. - // may not be needed as the validation call to update the global, is called in a LOCK already, and it can only update there and here. - LOCK(cs_main); - GetKomodoEarlytxidScriptPub(); - } - /* int32_t nextheight = komodo_nextheight(); CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), nextheight); UniValue result(UniValue::VOBJ); struct CCcontract_info *cp, C; @@ -1439,7 +1430,6 @@ UniValue PricesBet(int64_t txfee, int64_t amount, int16_t leverage, std::vector< result.push_back(Pair("result", "error")); result.push_back(Pair("error", "not enough funds")); return(result); - */ } // pricesaddfunding rpc impl: add yet another bet From ffbb7a92f201e5b6d7a709e0d32c76e888392d2c Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Thu, 9 May 2019 18:20:58 +0800 Subject: [PATCH 252/447] add utxos to paymentsinfo --- src/cc/payments.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/cc/payments.cpp b/src/cc/payments.cpp index ecb302a8d..118342bc7 100644 --- a/src/cc/payments.cpp +++ b/src/cc/payments.cpp @@ -568,8 +568,10 @@ int64_t AddPaymentsInputs(bool fLockedBlocks,int8_t GetBalance,struct CCcontract if ( (GetBalance == 0 && total != 0 && maxinputs != 0) || GetBalance == 4 ) mtx.vin.push_back(CTxIn(txid,vout,CScript())); nValue = it->second.satoshis; - if ( nValue < COIN ) + if ( GetBalance == 4 && nValue < COIN ) blocksleft++; // count dust with unused variable. + if ( GetBalance == 2 || GetBalance == 1 ) + blocksleft++; // count all utxos with unused variable. totalinputs += nValue; n++; //fprintf(stderr,"iter.%d %s/v%d %s %.8f\n",iter,txid.GetHex().c_str(),vout,coinaddr,(double)nValue/COIN); @@ -1355,11 +1357,15 @@ UniValue PaymentsInfo(struct CCcontract_info *cp,char *jsonstr) { txidpk = CCtxidaddr(txidaddr,createtxid); GetCCaddress1of2(cp,fundsaddr,Paymentspk,txidpk); + blocksleft = 0; funds = AddPaymentsInputs(false,2,cp,mtx,txidpk,0,CC_MAXVINS,createtxid,lockedblocks,minrelease,blocksleft); result.push_back(Pair(fundsaddr,ValueFromAmount(funds))); + result.push_back(Pair("utxos", (int64_t)blocksleft)); + blocksleft = 0; GetCCaddress(cp,fundsopretaddr,Paymentspk); fundsopret = AddPaymentsInputs(false,1,cp,mtx,txidpk,0,CC_MAXVINS,createtxid,lockedblocks,minrelease,blocksleft); result.push_back(Pair(fundsopretaddr,ValueFromAmount(fundsopret))); + result.push_back(Pair("utxos", (int64_t)blocksleft)); result.push_back(Pair("totalfunds",ValueFromAmount(funds+fundsopret))); // Blocks until minrelease can be released. elegiblefunds = AddPaymentsInputs(true,3,cp,mtx,txidpk,0,CC_MAXVINS,createtxid,lockedblocks,minrelease,blocksleft); From 113d3c779fdd4adb068f0707005340d9d8e868de Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Thu, 9 May 2019 19:18:10 +0800 Subject: [PATCH 253/447] tokens airdrop RPC --- src/cc/CCPayments.h | 1 + src/cc/payments.cpp | 81 ++++++++++++++++++++++++++++++++++++++++ src/rpc/server.cpp | 1 + src/rpc/server.h | 1 + src/wallet/rpcwallet.cpp | 13 +++++++ 5 files changed, 97 insertions(+) diff --git a/src/cc/CCPayments.h b/src/cc/CCPayments.h index a7cd4f916..effa837f2 100644 --- a/src/cc/CCPayments.h +++ b/src/cc/CCPayments.h @@ -35,6 +35,7 @@ UniValue PaymentsMerge(struct CCcontract_info *cp,char *jsonstr); UniValue PaymentsTxidopret(struct CCcontract_info *cp,char *jsonstr); UniValue PaymentsCreate(struct CCcontract_info *cp,char *jsonstr); UniValue PaymentsAirdrop(struct CCcontract_info *cp,char *jsonstr); +UniValue PaymentsAirdropTokens(struct CCcontract_info *cp,char *jsonstr); UniValue PaymentsInfo(struct CCcontract_info *cp,char *jsonstr); UniValue PaymentsList(struct CCcontract_info *cp,char *jsonstr); diff --git a/src/cc/payments.cpp b/src/cc/payments.cpp index 118342bc7..57e85f615 100644 --- a/src/cc/payments.cpp +++ b/src/cc/payments.cpp @@ -1241,6 +1241,87 @@ UniValue PaymentsAirdrop(struct CCcontract_info *cp,char *jsonstr) return(result); } +UniValue PaymentsAirdropTokens(struct CCcontract_info *cp,char *jsonstr) +{ + CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); + UniValue result(UniValue::VOBJ); + uint256 hashBlock, tokenid = zeroid; CTransaction tx; CPubKey Paymentspk,mypk; char markeraddr[64]; std::string rawtx; + int32_t lockedblocks,minrelease,top,bottom,n,i,minimum=10000; std::vector> excludeScriptPubKeys; int8_t fixedAmount; + cJSON *params = payments_reparse(&n,jsonstr); + if ( params != 0 && n >= 6 ) + { + tokenid = payments_juint256(jitem(params,0)); + lockedblocks = juint(jitem(params,1),0); + minrelease = juint(jitem(params,2),0); + minimum = juint(jitem(params,3),0); + if ( minimum < 10000 ) minimum = 10000; + top = juint(jitem(params,4),0); + bottom = juint(jitem(params,5),0); + fixedAmount = juint(jitem(params,6),0); // fixed amount is a flag, set to 7 does game mode, 0 normal snapshot, anything else fixed allocations. + if ( lockedblocks < 0 || minrelease < 0 || top <= 0 || bottom < 0 || minimum < 0 || fixedAmount < 0 || top > 3999 || tokenid == zeroid ) + { + result.push_back(Pair("result","error")); + result.push_back(Pair("error","negative parameter, or top over 3999")); + if ( params != 0 ) + free_json(params); + return(result); + } + // TODO: lookup tokenid and make sure it exists. + if ( n > 7 ) + { + for (i=0; i vscriptPubKey; + CScript scriptPubKey = GetScriptForDestination(destination); + vscriptPubKey.assign(scriptPubKey.begin(), scriptPubKey.end()); + excludeScriptPubKeys.push_back(vscriptPubKey); + } + } + mypk = pubkey2pk(Mypubkey()); + Paymentspk = GetUnspendable(cp,0); + if ( AddNormalinputs(mtx,mypk,2*PAYMENTS_TXFEE,60) > 0 ) + { + mtx.vout.push_back(MakeCC1of2vout(cp->evalcode,PAYMENTS_TXFEE,Paymentspk,Paymentspk)); + CScript tempopret = EncodePaymentsTokensOpRet(lockedblocks,minrelease,minimum,top,bottom,fixedAmount,excludeScriptPubKeys,tokenid); + if ( tempopret.size() > 10000 ) // TODO: Check this! + { + result.push_back(Pair("result","error")); + result.push_back(Pair("error","op_return is too big, try with less exclude pubkeys.")); + if ( params != 0 ) + free_json(params); + return(result); + } + rawtx = FinalizeCCTx(0,cp,mtx,mypk,PAYMENTS_TXFEE,tempopret); + if ( params != 0 ) + free_json(params); + return(payments_rawtxresult(result,rawtx,0)); + } + result.push_back(Pair("result","error")); + result.push_back(Pair("error","not enough normal funds")); + } + else + { + result.push_back(Pair("result","error")); + result.push_back(Pair("error","parameters error")); + } + if ( params != 0 ) + free_json(params); + return(result); +} + UniValue PaymentsInfo(struct CCcontract_info *cp,char *jsonstr) { UniValue result(UniValue::VOBJ),a(UniValue::VARR); CTransaction tx,txO; CPubKey Paymentspk,txidpk; int32_t i,j,n,flag=0,numoprets=0,lockedblocks,minrelease,blocksleft=0; std::vector txidoprets; int64_t funds,fundsopret,elegiblefunds,totalallocations=0,allocation; char fundsaddr[64],fundsopretaddr[64],txidaddr[64],*outstr; uint256 createtxid,hashBlock; diff --git a/src/rpc/server.cpp b/src/rpc/server.cpp index a41c7f413..c35647f8c 100644 --- a/src/rpc/server.cpp +++ b/src/rpc/server.cpp @@ -492,6 +492,7 @@ static const CRPCCommand vRPCCommands[] = { "payments", "paymentstxidopret", &payments_txidopret, true }, { "payments", "paymentscreate", &payments_create, true }, { "payments", "paymentsairdrop", &payments_airdrop, true }, + { "payments", "paymentsairdroptokens", &payments_airdroptokens, true }, { "payments", "paymentslist", &payments_list, true }, { "payments", "paymentsinfo", &payments_info, true }, { "payments", "paymentsfund", &payments_fund, true }, diff --git a/src/rpc/server.h b/src/rpc/server.h index d0882d6cb..c61f62dc3 100644 --- a/src/rpc/server.h +++ b/src/rpc/server.h @@ -292,6 +292,7 @@ extern UniValue payments_merge(const UniValue& params, bool fHelp); extern UniValue payments_txidopret(const UniValue& params, bool fHelp); extern UniValue payments_create(const UniValue& params, bool fHelp); extern UniValue payments_airdrop(const UniValue& params, bool fHelp); +extern UniValue payments_airdroptokens(const UniValue& params, bool fHelp); extern UniValue payments_info(const UniValue& params, bool fHelp); extern UniValue payments_list(const UniValue& params, bool fHelp); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 5ce7ae773..209ed034c 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5656,6 +5656,19 @@ UniValue payments_airdrop(const UniValue& params, bool fHelp) return(PaymentsAirdrop(cp,(char *)params[0].get_str().c_str())); } +UniValue payments_airdroptokens(const UniValue& params, bool fHelp) +{ + struct CCcontract_info *cp,C; + if ( fHelp || params.size() != 1 ) + throw runtime_error("paymentsairdrop \"[%22tokenid%22,lockedblocks,minamount,mintoaddress,top,bottom,fixedFlag,%22excludePubKey%22,...,%22excludePubKeyN%22]\"\n"); + if ( ensure_CCrequirements(EVAL_PAYMENTS) < 0 ) + throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + const CKeyStore& keystore = *pwalletMain; + LOCK2(cs_main, pwalletMain->cs_wallet); + cp = CCinit(&C,EVAL_PAYMENTS); + return(PaymentsAirdropTokens(cp,(char *)params[0].get_str().c_str())); +} + UniValue payments_info(const UniValue& params, bool fHelp) { struct CCcontract_info *cp,C; From 46d997f3190312111f90b5a359a03b127aa9a11e Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Thu, 9 May 2019 22:04:33 +0800 Subject: [PATCH 254/447] fix --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 5203888de..82b95b146 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -6503,7 +6503,7 @@ bool LoadExternalBlockFile(FILE* fileIn, CDiskBlockPos *dbp) blkdat.SetPos(nBlockPos); CBlock block; blkdat >> block; - nRewind = blkdat.GetPos(); + nRewind = blkdat.GetPos(); // detect out of order blocks, and store them for later uint256 hash = block.GetHash(); From 9d22819247541cdf329954750ba05cad7a9c6f2c Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Thu, 9 May 2019 22:09:34 +0800 Subject: [PATCH 255/447] try this --- src/cc/payments.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/cc/payments.cpp b/src/cc/payments.cpp index 57e85f615..5d6383c29 100644 --- a/src/cc/payments.cpp +++ b/src/cc/payments.cpp @@ -1108,6 +1108,7 @@ UniValue PaymentsCreate(struct CCcontract_info *cp,char *jsonstr) for (i=0; i scriptPubKey,opret; int64_t allocation; + fprintf(stderr, "txid.%s\n",txidoprets[i].GetHex().c_str()); if ( myGetTransaction(txidoprets[i],tx,hashBlock) != 0 && tx.vout.size() > 1 && DecodePaymentsTxidOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,allocation,scriptPubKey,opret) == 'T' ) { totalallocations += allocation; From d624038a10e28158a622e276894b992b17989ce8 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Fri, 10 May 2019 02:14:10 +0800 Subject: [PATCH 256/447] fixed reindex --- src/main.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 45d2e7a39..049a732d5 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -6360,7 +6360,7 @@ bool LoadExternalBlockFile(FILE* fileIn, CDiskBlockPos *dbp) try { // This takes over fileIn and calls fclose() on it in the CBufferedFile destructor //CBufferedFile blkdat(fileIn, 2*MAX_BLOCK_SIZE, MAX_BLOCK_SIZE+8, SER_DISK, CLIENT_VERSION); - CBufferedFile blkdat(fileIn, 32*MAX_BLOCK_SIZE(10000000), MAX_BLOCK_SIZE(10000000)+8, SER_DISK, CLIENT_VERSION); + CBufferedFile blkdat(fileIn, 2*MAX_BLOCK_SIZE(10000000), MAX_BLOCK_SIZE(10000000)+8, SER_DISK, CLIENT_VERSION); uint64_t nRewind = blkdat.GetPos(); while (!blkdat.eof()) { boost::this_thread::interruption_point(); @@ -6387,15 +6387,15 @@ bool LoadExternalBlockFile(FILE* fileIn, CDiskBlockPos *dbp) } try { // read block + CBlock block; uint64_t nBlockPos = blkdat.GetPos(); if (dbp) dbp->nPos = nBlockPos; blkdat.SetLimit(nBlockPos + nSize); blkdat.SetPos(nBlockPos); - CBlock block; blkdat >> block; + nRewind = blkdat.GetPos(); - // detect out of order blocks, and store them for later uint256 hash = block.GetHash(); if (hash != chainparams.GetConsensus().hashGenesisBlock && mapBlockIndex.find(block.hashPrevBlock) == mapBlockIndex.end()) { @@ -6426,6 +6426,7 @@ bool LoadExternalBlockFile(FILE* fileIn, CDiskBlockPos *dbp) std::pair::iterator, std::multimap::iterator> range = mapBlocksUnknownParent.equal_range(head); while (range.first != range.second) { std::multimap::iterator it = range.first; + if (ReadBlockFromDisk(mapBlockIndex.count(hash)!=0?mapBlockIndex[hash]->GetHeight():0,block, it->second,1)) { LogPrintf("%s: Processing out of order child %s of %s\n", __func__, block.GetHash().ToString(), From 6f1f4413babd28a4993ced50d3d51d06fbb25a29 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Sat, 11 May 2019 16:25:27 +0800 Subject: [PATCH 257/447] fix payments release --- src/cc/payments.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/cc/payments.cpp b/src/cc/payments.cpp index 5d6383c29..a8630f25c 100644 --- a/src/cc/payments.cpp +++ b/src/cc/payments.cpp @@ -716,6 +716,7 @@ UniValue PaymentsRelease(struct CCcontract_info *cp,char *jsonstr) if ( funcid == 'C' ) { // normal payments + m = txidoprets.size(); for (i=0; i scriptPubKey,opret; @@ -1108,7 +1109,7 @@ UniValue PaymentsCreate(struct CCcontract_info *cp,char *jsonstr) for (i=0; i scriptPubKey,opret; int64_t allocation; - fprintf(stderr, "txid.%s\n",txidoprets[i].GetHex().c_str()); + //fprintf(stderr, "txid.%s\n",txidoprets[i].GetHex().c_str()); if ( myGetTransaction(txidoprets[i],tx,hashBlock) != 0 && tx.vout.size() > 1 && DecodePaymentsTxidOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,allocation,scriptPubKey,opret) == 'T' ) { totalallocations += allocation; From f5f476ae5af2eee33445b9ad27812814e263e90d Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Sat, 11 May 2019 16:38:15 +0800 Subject: [PATCH 258/447] fix reindex --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 82b95b146..20354fd59 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -6469,7 +6469,7 @@ bool LoadExternalBlockFile(FILE* fileIn, CDiskBlockPos *dbp) try { // This takes over fileIn and calls fclose() on it in the CBufferedFile destructor //CBufferedFile blkdat(fileIn, 2*MAX_BLOCK_SIZE, MAX_BLOCK_SIZE+8, SER_DISK, CLIENT_VERSION); - CBufferedFile blkdat(fileIn, 32*MAX_BLOCK_SIZE(10000000), MAX_BLOCK_SIZE(10000000)+8, SER_DISK, CLIENT_VERSION); + CBufferedFile blkdat(fileIn, 2*MAX_BLOCK_SIZE(10000000), MAX_BLOCK_SIZE(10000000)+8, SER_DISK, CLIENT_VERSION); uint64_t nRewind = blkdat.GetPos(); while (!blkdat.eof()) { boost::this_thread::interruption_point(); From 462320cfaf2af75a532f144e21569568a7f6f1e6 Mon Sep 17 00:00:00 2001 From: Alrighttt <36680730+Alrighttt@users.noreply.github.com> Date: Sat, 11 May 2019 14:34:41 +0200 Subject: [PATCH 259/447] fix getaddresstxids help --- src/rpc/misc.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/rpc/misc.cpp b/src/rpc/misc.cpp index 4ea6e94e3..41134e831 100644 --- a/src/rpc/misc.cpp +++ b/src/rpc/misc.cpp @@ -1432,8 +1432,8 @@ UniValue getsnapshot(const UniValue& params, bool fHelp) UniValue getaddresstxids(const UniValue& params, bool fHelp) { - if (fHelp || params.size() > 2) - throw runtime_error( + if (fHelp || params.size() > 2 || params.size() < 1) + throw runtime_error "getaddresstxids (ccvout)\n" "\nReturns the txids for an address(es) (requires addressindex to be enabled).\n" "\nArguments:\n" From b489328ce87ff8ee517f961b92fb515c1850908c Mon Sep 17 00:00:00 2001 From: Alrighttt <36680730+Alrighttt@users.noreply.github.com> Date: Sat, 11 May 2019 14:35:51 +0200 Subject: [PATCH 260/447] syntax --- src/rpc/misc.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rpc/misc.cpp b/src/rpc/misc.cpp index 41134e831..4f296174f 100644 --- a/src/rpc/misc.cpp +++ b/src/rpc/misc.cpp @@ -1433,7 +1433,7 @@ UniValue getsnapshot(const UniValue& params, bool fHelp) UniValue getaddresstxids(const UniValue& params, bool fHelp) { if (fHelp || params.size() > 2 || params.size() < 1) - throw runtime_error + throw runtime_error( "getaddresstxids (ccvout)\n" "\nReturns the txids for an address(es) (requires addressindex to be enabled).\n" "\nArguments:\n" From fb9320dfbb7da5429ba82ac3b8f82b4940b6f4eb Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 13 May 2019 15:54:15 +0800 Subject: [PATCH 261/447] fix payments allocation for alright --- src/cc/payments.cpp | 3 ++- src/rpc/misc.cpp | 10 +++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/cc/payments.cpp b/src/cc/payments.cpp index a8630f25c..63e9f4681 100644 --- a/src/cc/payments.cpp +++ b/src/cc/payments.cpp @@ -426,8 +426,9 @@ bool PaymentsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction & test = mpz_get_si(mpzAllocation); mpz_clear(mpzAllocation); } + //fprintf(stderr, "vout %i test.%li nValue.%li\n", i, test, tx.vout[i].nValue); // Vairance of 1 sat is allowed, for rounding errors. - if ( test >= tx.vout[i].nValue+1 && test <= tx.vout[i].nValue-1 ) + if ( test > tx.vout[i].nValue+1 || test < tx.vout[i].nValue-1 ) { fprintf(stderr, "vout.%i test.%li vs nVlaue.%li\n",i, test, tx.vout[i].nValue); return(eval->Invalid("amounts do not match")); diff --git a/src/rpc/misc.cpp b/src/rpc/misc.cpp index 4ea6e94e3..058cd0241 100644 --- a/src/rpc/misc.cpp +++ b/src/rpc/misc.cpp @@ -1383,9 +1383,13 @@ UniValue getsnapshot(const UniValue& params, bool fHelp) if (params.size() > 0 && !params[0].isNull()) { top = atoi(params[0].get_str().c_str()); - if (top < 0) - //throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, top must be a positive integer"); - top = -1; + if ( top < 0 ) + { + if ( KOMODO_SNAPSHOT_INTERVAL == 0 ) + throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, top must be a positive integer"); + else + top = -1; + } } if ( fHelp || params.size() > 1) From 93c37122444fbe46b991f70948cdc139469a013e Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 13 May 2019 18:35:28 +0800 Subject: [PATCH 262/447] Try to fix allocations --- src/cc/CCinclude.h | 2 +- src/cc/CCutils.cpp | 7 +++-- src/cc/payments.cpp | 71 ++++++++++++++++++++++++++++++--------------- src/cc/rewards.cpp | 3 +- 4 files changed, 54 insertions(+), 29 deletions(-) diff --git a/src/cc/CCinclude.h b/src/cc/CCinclude.h index 75d804df5..3681cf2f3 100644 --- a/src/cc/CCinclude.h +++ b/src/cc/CCinclude.h @@ -251,7 +251,7 @@ void CCaddrTokens1of2set(struct CCcontract_info *cp, CPubKey pk1, CPubKey pk2, c int32_t CClib_initcp(struct CCcontract_info *cp,uint8_t evalcode); bool IsCCInput(CScript const& scriptSig); -bool CheckTxFee(const CTransaction &tx, uint64_t txfee, uint32_t height, uint64_t blocktime); +bool CheckTxFee(const CTransaction &tx, uint64_t txfee, uint32_t height, uint64_t blocktime,int64_t &actualtxfee); int32_t unstringbits(char *buf,uint64_t bits); uint64_t stringbits(char *str); uint256 revuint256(uint256 txid); diff --git a/src/cc/CCutils.cpp b/src/cc/CCutils.cpp index 023858dc2..1b326b85f 100644 --- a/src/cc/CCutils.cpp +++ b/src/cc/CCutils.cpp @@ -150,7 +150,7 @@ bool IsCCInput(CScript const& scriptSig) return true; } -bool CheckTxFee(const CTransaction &tx, uint64_t txfee, uint32_t height, uint64_t blocktime) +bool CheckTxFee(const CTransaction &tx, uint64_t txfee, uint32_t height, uint64_t blocktime, int64_t &actualtxfee) { LOCK(mempool.cs); CCoinsView dummy; @@ -159,9 +159,10 @@ bool CheckTxFee(const CTransaction &tx, uint64_t txfee, uint32_t height, uint64_ CCoinsViewMemPool viewMemPool(pcoinsTip, mempool); view.SetBackend(viewMemPool); valuein = view.GetValueIn(height,&interest,tx,blocktime); - if ( valuein-tx.GetValueOut() > txfee ) + actualtxfee = valuein-tx.GetValueOut(); + if ( actualtxfee > txfee ) { - //fprintf(stderr, "txfee.%li vs txfee.%li\n", valuein-tx.GetValueOut(), txfee); + fprintf(stderr, "actualtxfee.%li vs txfee.%li\n", actualtxfee, txfee); return false; } return true; diff --git a/src/cc/payments.cpp b/src/cc/payments.cpp index 63e9f4681..2141f77ee 100644 --- a/src/cc/payments.cpp +++ b/src/cc/payments.cpp @@ -261,9 +261,9 @@ bool PaymentsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction & // only 'F' or 1of2 txidaddr can be spent // all vouts must match exactly char temp[128], coinaddr[64]={0}, txidaddr[64]; std::string scriptpubkey; uint256 createtxid, blockhash, tokenid; CTransaction plantx; int8_t funcid=0, fixedAmount=0; - int32_t i,lockedblocks,minrelease; int64_t change,totalallocations; std::vector txidoprets; bool fHasOpret = false,fIsMerge = false; CPubKey txidpk,Paymentspk; + int32_t i,lockedblocks,minrelease; int64_t change,totalallocations,actualtxfee; std::vector txidoprets; bool fHasOpret = false,fIsMerge = false; CPubKey txidpk,Paymentspk; int32_t top,bottom=0,minimum=10000; std::vector> excludeScriptPubKeys; bool fFixedAmount = false; CScript ccopret; - mpz_t mpzTotalAllocations, mpzAllocation;; mpz_init(mpzTotalAllocations); + mpz_t mpzTotalAllocations,mpzAllocation; mpz_init(mpzTotalAllocations); // user marker vout to get the createtxid if ( tx.vout.size() == 1 ) { @@ -299,7 +299,7 @@ bool PaymentsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction & txidpk = CCtxidaddr(txidaddr,createtxid); GetCCaddress1of2(cp,coinaddr,Paymentspk,txidpk); //fprintf(stderr, "lockedblocks.%i minrelease.%i totalallocations.%i txidopret1.%s txidopret2.%s\n",lockedblocks, minrelease, totalallocations, txidoprets[0].ToString().c_str(), txidoprets[1].ToString().c_str() ); - if ( !CheckTxFee(tx, PAYMENTS_TXFEE+1, chainActive.LastTip()->GetHeight(), chainActive.LastTip()->nTime) ) + if ( !CheckTxFee(tx, PAYMENTS_TXFEE+1, chainActive.LastTip()->GetHeight(), chainActive.LastTip()->nTime, actualtxfee) ) return eval->Invalid("txfee is too high"); // make sure change is in vout 0 and is paying to the contract address. if ( (change= IsPaymentsvout(cp,tx,0,coinaddr,ccopret)) == 0 ) @@ -385,8 +385,10 @@ bool PaymentsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction & if ( i+bottom == top ) // we reached top amount to pay, it can be less than this! break; } - if ( i != tx.vout.size()-2 ) - return(eval->Invalid("pays wrong amount of recipients")); + + // need to check this later on as less can now be paid. + //if ( i != tx.vout.size()-2 ) + // return(eval->Invalid("pays wrong amount of recipients")); } else if ( funcid == 'O' ) { @@ -403,7 +405,8 @@ bool PaymentsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction & // Check vouts go to the right place and pay the right amounts. int64_t amount = 0, checkamount; int32_t n = 0; - checkamount = tx.GetValueOut() - change - PAYMENTS_TXFEE; + checkamount = tx.GetValueOut() - change - actualtxfee; //PAYMENTS_TXFEE; + fprintf(stderr, "totalvalueout.%li change.%li txfee.%li checkamount.%li\n",tx.GetValueOut(), change, actualtxfee, checkamount); mpz_t mpzCheckamount; mpz_init(mpzCheckamount); mpz_set_si(mpzCheckamount,checkamount); for (i = 1; i < (fHasOpret ? tx.vout.size()-2 : tx.vout.size()-1); i++) { @@ -422,12 +425,12 @@ bool PaymentsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction & mpz_init(mpzAllocation); mpz_set_si(mpzAllocation,allocations[n]); mpz_mul(mpzAllocation,mpzAllocation,mpzCheckamount); - mpz_cdiv_q(mpzAllocation,mpzAllocation,mpzTotalAllocations); + mpz_tdiv_q(mpzAllocation,mpzAllocation,mpzTotalAllocations); test = mpz_get_si(mpzAllocation); mpz_clear(mpzAllocation); } //fprintf(stderr, "vout %i test.%li nValue.%li\n", i, test, tx.vout[i].nValue); - // Vairance of 1 sat is allowed, for rounding errors. + // I cant fix this! I dont understand the rouncing errors sorry. if ( test > tx.vout[i].nValue+1 || test < tx.vout[i].nValue-1 ) { fprintf(stderr, "vout.%i test.%li vs nVlaue.%li\n",i, test, tx.vout[i].nValue); @@ -441,7 +444,18 @@ bool PaymentsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction & amount += tx.vout[i].nValue; n++; } - mpz_clear(mpzTotalAllocations); + if ( allocations.size() > n ) + { + // need to check that the next allocation was less than 10k sat, otherwise ppl can truncate the tx at any place. + mpz_init(mpzAllocation); + mpz_set_si(mpzAllocation,allocations[n+1]); + mpz_mul(mpzAllocation,mpzAllocation,mpzCheckamount); + mpz_tdiv_q (mpzAllocation,mpzAllocation,mpzTotalAllocations); + int64_t test = mpz_get_si(mpzAllocation); + if ( test > minimum+1 ) + return(eval->Invalid("next allocation was not under minimum")); + } + mpz_clear(mpzTotalAllocations); mpz_clear(mpzCheckamount); // This is a backup check to make sure there are no extra vouts paying something else! if ( checkamount != amount ) return(eval->Invalid("amounts do not match")); @@ -672,19 +686,20 @@ int32_t payments_parsehexdata(std::vector &hexdata,cJSON *item,int32_t UniValue PaymentsRelease(struct CCcontract_info *cp,char *jsonstr) { - int32_t nextheight = komodo_nextheight(); - //int32_t latestheight,nextheight = komodo_nextheight(); - CMutableTransaction tmpmtx,mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(),nextheight); UniValue result(UniValue::VOBJ); uint256 createtxid,hashBlock,tokenid; + LOCK(cs_main); + CMutableTransaction tmpmtx,mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(),komodo_nextheight()); UniValue result(UniValue::VOBJ); uint256 createtxid,hashBlock,tokenid; CTransaction tx,txO; CPubKey mypk,txidpk,Paymentspk; int32_t i,n,m,numoprets=0,lockedblocks,minrelease; int64_t newamount,inputsum,amount,CCchange=0,totalallocations=0,checkallocations=0,allocation; CTxOut vout; CScript onlyopret; char txidaddr[64],destaddr[64]; std::vector txidoprets; - int32_t top,bottom=0,blocksleft=0,minimum=10000; std::vector> excludeScriptPubKeys; int8_t funcid,fixedAmount=0; bool fFixedAmount = false; + int32_t top,bottom=0,blocksleft=0,minimum=10000; std::vector> excludeScriptPubKeys; int8_t funcid,fixedAmount=0,skipminimum=0; bool fFixedAmount = false; mpz_t mpzTotalAllocations; mpz_init(mpzTotalAllocations); cJSON *params = payments_reparse(&n,jsonstr); mypk = pubkey2pk(Mypubkey()); Paymentspk = GetUnspendable(cp,0); - if ( params != 0 && n == 2 ) + if ( params != 0 && n >= 2 ) { createtxid = payments_juint256(jitem(params,0)); amount = jdouble(jitem(params,1),0) * SATOSHIDEN + 0.0000000049; + if ( n == 3 ) + skipminimum = juint(jitem(params,2),0); if ( myGetTransaction(createtxid,tx,hashBlock) != 0 && tx.vout.size() > 0 ) { if ( ((funcid= DecodePaymentsOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,lockedblocks,minrelease,totalallocations,txidoprets)) == 'C' || (funcid= DecodePaymentsSnapsShotOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,lockedblocks,minrelease,minimum,top,bottom,fixedAmount,excludeScriptPubKeys)) == 'S' || (funcid= DecodePaymentsTokensOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,lockedblocks,minrelease,minimum,top,bottom,fixedAmount,excludeScriptPubKeys,tokenid)) == 'O') ) @@ -700,7 +715,6 @@ UniValue PaymentsRelease(struct CCcontract_info *cp,char *jsonstr) // set minimum size to 10k sat otherwise the tx will be invalid. if ( minimum < 10000 ) minimum = 10000; - //latestheight = (nextheight - lockedblocks - 1); if ( amount < minrelease*COIN ) { result.push_back(Pair("result","error")); @@ -845,7 +859,7 @@ UniValue PaymentsRelease(struct CCcontract_info *cp,char *jsonstr) { mpz_set_si(mpzValue,mtx.vout[i+1].nValue); mpz_mul(mpzValue,mpzValue,mpzAmount); - mpz_cdiv_q(mpzValue,mpzValue,mpzTotalAllocations); + mpz_tdiv_q(mpzValue,mpzValue,mpzTotalAllocations); if ( mpz_fits_slong_p(mpzValue) ) mtx.vout[i+1].nValue = mpz_get_si(mpzValue); else @@ -861,16 +875,24 @@ UniValue PaymentsRelease(struct CCcontract_info *cp,char *jsonstr) mpz_clear(mpzValue); if ( mtx.vout[i+1].nValue < minimum ) { - result.push_back(Pair("result","error")); - result.push_back(Pair("error","value too small, try releasing a larger amount")); - if ( params != 0 ) - free_json(params); - return(result); + if ( skipminimum == 0 ) + { + result.push_back(Pair("result","error")); + result.push_back(Pair("error","value too small, try releasing a larger amount")); + if ( params != 0 ) + free_json(params); + return(result); + } + else + { + // truncate off any vouts that are less than minimum. + mtx.vout.resize(i); + break; + } } totalamountsent += mtx.vout[i+1].nValue; } if ( totalamountsent < amount ) newamount = totalamountsent; - fprintf(stderr, "newamount.%li totalamountsent.%li\n", newamount, totalamountsent); mpz_clear(mpzAmount); mpz_clear(mpzTotalAllocations); } else @@ -884,8 +906,9 @@ UniValue PaymentsRelease(struct CCcontract_info *cp,char *jsonstr) if ( (inputsum= AddPaymentsInputs(true,0,cp,mtx,txidpk,newamount+2*PAYMENTS_TXFEE,CC_MAXVINS/2,createtxid,lockedblocks,minrelease,blocksleft)) >= newamount+2*PAYMENTS_TXFEE ) { std::string rawtx; - if ( (CCchange= (inputsum - newamount - 2*PAYMENTS_TXFEE)) >= PAYMENTS_TXFEE ) - mtx.vout[0].nValue = CCchange; + fprintf(stderr, "inputsum.%li - newamount.%li = ",inputsum,newamount); + mtx.vout[0].nValue = inputsum - newamount - 2*PAYMENTS_TXFEE; + fprintf(stderr, "change.%li\n", mtx.vout[0].nValue); mtx.vout.push_back(CTxOut(PAYMENTS_TXFEE,CScript() << ParseHex(HexStr(txidpk)) << OP_CHECKSIG)); GetCCaddress1of2(cp,destaddr,Paymentspk,txidpk); CCaddr1of2set(cp,Paymentspk,txidpk,cp->CCpriv,destaddr); diff --git a/src/cc/rewards.cpp b/src/cc/rewards.cpp index 5ca2b038a..2edd275ec 100644 --- a/src/cc/rewards.cpp +++ b/src/cc/rewards.cpp @@ -195,6 +195,7 @@ bool RewardsExactAmounts(struct CCcontract_info *cp,Eval *eval,const CTransactio bool RewardsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn) { uint256 txid,fundingtxid,hashBlock,vinfundingtxid; uint64_t vinsbits,sbits,APR,minseconds,maxseconds,mindeposit,amount,reward,txfee=10000; int32_t numvins,numvouts,preventCCvins,preventCCvouts,i; uint8_t funcid; CScript scriptPubKey; CTransaction fundingTx,vinTx; + int64_t dummy; numvins = tx.vin.size(); numvouts = tx.vout.size(); preventCCvins = preventCCvouts = -1; @@ -255,7 +256,7 @@ bool RewardsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &t if ( (*cp->ismyvin)(tx.vin[i].scriptSig) == 0 ) return eval->Invalid("unexpected normal vin for unlock"); } - if ( !CheckTxFee(tx, txfee, chainActive.LastTip()->GetHeight(), chainActive.LastTip()->nTime) ) + if ( !CheckTxFee(tx, txfee, chainActive.LastTip()->GetHeight(), chainActive.LastTip()->nTime, dummy) ) return eval->Invalid("txfee is too high"); amount = vinTx.vout[0].nValue; reward = RewardsCalc(amount,tx.vin[0].prevout.hash,APR,minseconds,maxseconds,mindeposit); From 9b35a646936240b6df11ccd197fa2f1aefe240ec Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 13 May 2019 20:44:42 +0800 Subject: [PATCH 263/447] prints --- src/cc/payments.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/cc/payments.cpp b/src/cc/payments.cpp index 2141f77ee..954d2b93a 100644 --- a/src/cc/payments.cpp +++ b/src/cc/payments.cpp @@ -405,8 +405,9 @@ bool PaymentsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction & // Check vouts go to the right place and pay the right amounts. int64_t amount = 0, checkamount; int32_t n = 0; - checkamount = tx.GetValueOut() - change - actualtxfee; //PAYMENTS_TXFEE; - fprintf(stderr, "totalvalueout.%li change.%li txfee.%li checkamount.%li\n",tx.GetValueOut(), change, actualtxfee, checkamount); + checkamount = tx.GetValueOut() - change - actualtxfee - PAYMENTS_TXFEE; + int64_t temptst = mpz_get_si(mpzTotalAllocations); + fprintf(stderr, "validation checkamount.%li totalallocations.%li\n",checkamount,temptst); mpz_t mpzCheckamount; mpz_init(mpzCheckamount); mpz_set_si(mpzCheckamount,checkamount); for (i = 1; i < (fHasOpret ? tx.vout.size()-2 : tx.vout.size()-1); i++) { @@ -893,6 +894,8 @@ UniValue PaymentsRelease(struct CCcontract_info *cp,char *jsonstr) totalamountsent += mtx.vout[i+1].nValue; } if ( totalamountsent < amount ) newamount = totalamountsent; + int64_t temptst = mpz_get_si(mpzTotalAllocations); + fprintf(stderr, "checkamount RPC.%li totalallocations.%li\n",totalamountsent, temptst); mpz_clear(mpzAmount); mpz_clear(mpzTotalAllocations); } else @@ -906,9 +909,7 @@ UniValue PaymentsRelease(struct CCcontract_info *cp,char *jsonstr) if ( (inputsum= AddPaymentsInputs(true,0,cp,mtx,txidpk,newamount+2*PAYMENTS_TXFEE,CC_MAXVINS/2,createtxid,lockedblocks,minrelease,blocksleft)) >= newamount+2*PAYMENTS_TXFEE ) { std::string rawtx; - fprintf(stderr, "inputsum.%li - newamount.%li = ",inputsum,newamount); mtx.vout[0].nValue = inputsum - newamount - 2*PAYMENTS_TXFEE; - fprintf(stderr, "change.%li\n", mtx.vout[0].nValue); mtx.vout.push_back(CTxOut(PAYMENTS_TXFEE,CScript() << ParseHex(HexStr(txidpk)) << OP_CHECKSIG)); GetCCaddress1of2(cp,destaddr,Paymentspk,txidpk); CCaddr1of2set(cp,Paymentspk,txidpk,cp->CCpriv,destaddr); From 839ee2743ce149caaace1120694178bae8beee0b Mon Sep 17 00:00:00 2001 From: Alrighttt Date: Mon, 13 May 2019 17:40:08 +0000 Subject: [PATCH 264/447] remove ZEX, add ZEXO --- src/ac/zex | 2 -- src/ac/zexo | 2 ++ src/assetchains.json | 27 ++++++++++++++++----------- src/assetchains.old | 2 +- src/fiat/zex | 2 -- src/fiat/zexo | 2 ++ 6 files changed, 21 insertions(+), 16 deletions(-) delete mode 100755 src/ac/zex create mode 100755 src/ac/zexo delete mode 100755 src/fiat/zex create mode 100755 src/fiat/zexo diff --git a/src/ac/zex b/src/ac/zex deleted file mode 100755 index f4573c093..000000000 --- a/src/ac/zex +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/bash -./komodo-cli -ac_name=ZEX $1 $2 $3 $4 $5 $6 diff --git a/src/ac/zexo b/src/ac/zexo new file mode 100755 index 000000000..b6fd508f2 --- /dev/null +++ b/src/ac/zexo @@ -0,0 +1,2 @@ +#!/bin/bash +./komodo-cli -ac_name=ZEXO $1 $2 $3 $4 $5 $6 diff --git a/src/assetchains.json b/src/assetchains.json index 99c6557b6..683b791ad 100644 --- a/src/assetchains.json +++ b/src/assetchains.json @@ -202,17 +202,6 @@ "144.76.217.232" ] }, - { - "ac_name": "ZEX", - "ac_founders": "1", - "ac_reward": "13000000000", - "ac_halving": "525600", - "ac_cc": "2", - "ac_pubkey": "039d4a50cc70d1184e462a22edb3b66385da97cc8059196f8305c184a3e21440af", - "addnode": [ - "5.9.102.210" - ] - }, { "ac_name": "KSB", "ac_supply": "1000000000", @@ -268,5 +257,21 @@ "ac_name": "KOIN", "ac_supply": "125000000", "addnode": ["3.0.32.10"] + }, + { + "ac_name": "ZEXO", + "ac_reward": "1478310502", + "ac_halving": "525600", + "ac_cc": "42", + "ac_ccenable": "236", + "ac_supply": "100000000", + "ac_perc": "77700", + "ac_staked": "93", + "ac_pubkey": "02713bd85e054db923694b6b7a85306264edf4d6bd6d331814f2b40af444b3ebbc", + "ac_public": "1", + "addnode": [ + "195.201.20.230", + "80.240.17.222" + ] } ] diff --git a/src/assetchains.old b/src/assetchains.old index a0cbd3b9c..424d411ca 100755 --- a/src/assetchains.old +++ b/src/assetchains.old @@ -43,7 +43,6 @@ echo $pubkey ./komodod -pubkey=$pubkey -ac_name=PGT -ac_supply=10000000 -ac_end=1 -addnode=190.114.254.104 & ./komodod -pubkey=$pubkey -ac_name=KMDICE -ac_supply=10500000 -ac_reward=2500000000 -ac_halving=210000 -ac_cc=2 -addressindex=1 -spentindex=1 -addnode=144.76.217.232 & ./komodod -pubkey=$pubkey -ac_name=DION -ac_supply=3900000000 -ac_reward=22260000000 -ac_staked=100 -ac_cc=1 -ac_end=4300000000 -addnode=51.75.124.34 & -./komodod -pubkey=$pubkey -ac_name=ZEX -ac_cc=2 -ac_founders=1 -ac_halving=525600 -ac_reward=13000000000 -ac_pubkey=039d4a50cc70d1184e462a22edb3b66385da97cc8059196f8305c184a3e21440af -addnode=5.9.102.210 & ./komodod -pubkey=$pubkey -ac_name=KSB -ac_supply=1000000000 -ac_end=1 -ac_public=1 -addnode=37.187.225.231 & ./komodod -pubkey=$pubkey -ac_name=OUR -ac_reward=1478310502 -ac_halving=525600 -ac_cc=42 -ac_supply=100000000 -ac_perc=77700 -ac_staked=93 -ac_pubkey=02652a3f3e00b3a1875a918314f0bac838d6dd189a346fa623f5efe9541ac0b98c -ac_public=1 -addnode=51.255.195.65 -addnode=217.182.129.38 -addnode=37.187.225.231 & ./komodod -pubkey=$pubkey -ac_name=ILN -ac_supply=10000000000 -ac_cc=2 -addressindex=1 -spentindex=1 -addnode=51.75.122.83 & @@ -51,3 +50,4 @@ echo $pubkey ./komodod -pubkey=$pubkey -ac_name=MORTY -ac_supply=90000000000 -ac_reward=100000000 -ac_cc=3 -addnode=138.201.136.145 & ./komodod -pubkey=$pubkey -ac_name=VOTE2019 -ac_supply=123651638 -ac_public=1 -addnode=95.213.238.98 & ./komodod -pubkey=$pubkey -ac_name=KOIN -ac_supply=125000000 -addnode=3.0.32.10 & +./komodod -pubkey=$pubkey -ac_name=ZEXO -ac_supply=100000000 -ac_reward=1478310502 -ac_halving=525600 -ac_cc=42 -ac_ccenable=236 -ac_perc=77700 -ac_staked=93 -ac_pubkey=02713bd85e054db923694b6b7a85306264edf4d6bd6d331814f2b40af444b3ebbc -ac_public=1 -addnode=80.240.17.222 & diff --git a/src/fiat/zex b/src/fiat/zex deleted file mode 100755 index f4573c093..000000000 --- a/src/fiat/zex +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/bash -./komodo-cli -ac_name=ZEX $1 $2 $3 $4 $5 $6 diff --git a/src/fiat/zexo b/src/fiat/zexo new file mode 100755 index 000000000..b6fd508f2 --- /dev/null +++ b/src/fiat/zexo @@ -0,0 +1,2 @@ +#!/bin/bash +./komodo-cli -ac_name=ZEXO $1 $2 $3 $4 $5 $6 From 030f99652a7fca92194290a964b3e853ff2498a5 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Tue, 14 May 2019 06:21:50 +0800 Subject: [PATCH 265/447] Fix paymentsCC, add skipminimum to validation and paymentsrelease --- src/cc/CCPayments.h | 2 +- src/cc/payments.cpp | 288 +++++++++++++++++++-------------------- src/wallet/rpcwallet.cpp | 2 +- 3 files changed, 140 insertions(+), 152 deletions(-) diff --git a/src/cc/CCPayments.h b/src/cc/CCPayments.h index effa837f2..ac5f22c47 100644 --- a/src/cc/CCPayments.h +++ b/src/cc/CCPayments.h @@ -22,7 +22,7 @@ #include #define PAYMENTS_TXFEE 10000 -#define PAYMENTS_MERGEOFSET 10 // 100? +#define PAYMENTS_MERGEOFSET 60 // 1H extra. extern std::vector > vAddressSnapshot; extern int32_t lastSnapShotHeight; diff --git a/src/cc/payments.cpp b/src/cc/payments.cpp index 954d2b93a..528e6ec7f 100644 --- a/src/cc/payments.cpp +++ b/src/cc/payments.cpp @@ -137,6 +137,26 @@ uint8_t DecodePaymentsMergeOpRet(CScript scriptPubKey,uint256 &checktxid) return(0); } +CScript EncodePaymentsReleaseOpRet(uint256 checktxid, int64_t amountReleased) +{ + CScript opret; uint8_t evalcode = EVAL_PAYMENTS; + opret << OP_RETURN << E_MARSHAL(ss << evalcode << 'R' << checktxid << amountReleased); + return(opret); +} + +uint8_t DecodePaymentsReleaseOpRet(CScript scriptPubKey,uint256 &checktxid,int64_t &amountReleased) +{ + std::vector vopret; uint8_t *script,e,f; + GetOpReturnData(scriptPubKey, vopret); + script = (uint8_t *)vopret.data(); + if ( vopret.size() > 2 && E_UNMARSHAL(vopret,ss >> e; ss >> f; ss >> checktxid; ss >> amountReleased) != 0 ) + { + if ( e == EVAL_PAYMENTS && f == 'R' ) + return(f); + } + return(0); +} + CScript EncodePaymentsOpRet(int32_t lockedblocks,int32_t minrelease,int64_t totalallocations,std::vector txidoprets) { CScript opret; uint8_t evalcode = EVAL_PAYMENTS; @@ -200,7 +220,6 @@ uint8_t DecodePaymentsTokensOpRet(CScript scriptPubKey,int32_t &lockedblocks,int int64_t IsPaymentsvout(struct CCcontract_info *cp,const CTransaction& tx,int32_t v,char *cmpaddr, CScript &ccopret) { char destaddr[64]; - //if ( tx.vout[v].scriptPubKey.IsPayToCryptoCondition() != 0 ) if ( getCCopret(tx.vout[v].scriptPubKey, ccopret) ) { if ( Getscriptaddress(destaddr,tx.vout[v].scriptPubKey) > 0 && (cmpaddr[0] == 0 || strcmp(destaddr,cmpaddr) == 0) ) @@ -209,22 +228,6 @@ int64_t IsPaymentsvout(struct CCcontract_info *cp,const CTransaction& tx,int32_t return(0); } -void pub2createtxid(char *str) -{ - int i,n; - char *rev; - n = (int32_t)strlen(str); - rev = (char *)malloc(n + 1); - for (i=0; i txidoprets; bool fHasOpret = false,fIsMerge = false; CPubKey txidpk,Paymentspk; - int32_t top,bottom=0,minimum=10000; std::vector> excludeScriptPubKeys; bool fFixedAmount = false; CScript ccopret; - mpz_t mpzTotalAllocations,mpzAllocation; mpz_init(mpzTotalAllocations); - // user marker vout to get the createtxid - if ( tx.vout.size() == 1 ) + char temp[128], txidaddr[64]={0}; std::string scriptpubkey; uint256 createtxid, blockhash, tokenid; CTransaction plantx; int8_t funcid=0, fixedAmount=0; + int32_t i,lockedblocks,minrelease,blocksleft,dust = 0, top,bottom=0,minimum=10000; int64_t change,totalallocations,actualtxfee,amountReleased=0; std::vector txidoprets; bool fHasOpret = false,fIsMerge = false; CPubKey txidpk,Paymentspk; + std::vector> excludeScriptPubKeys; bool fFixedAmount = false; CScript ccopret; + mpz_t mpzTotalAllocations,mpzAllocation,mpzCheckamount; + mpz_init(mpzCheckamount); mpz_init(mpzTotalAllocations); + // Check change is in vout[0], and also fetch the ccopret to determine what type of tx this is. txidaddr is unknown, recheck this later. + if ( (change= IsPaymentsvout(cp,tx,0,txidaddr,ccopret)) != 0 && ccopret.size() > 2 ) { - if ( IsPaymentsvout(cp,tx,0,coinaddr,ccopret) != 0 && ccopret.size() > 2 && DecodePaymentsMergeOpRet(ccopret,createtxid) ) - { + // get the checktxid and the amount released if doing release tx. + if ( DecodePaymentsMergeOpRet(ccopret,createtxid) == 'M' ) fIsMerge = true; - } else return(eval->Invalid("not enough vouts")); - } - else if ( tx.vout.back().scriptPubKey[0] == OP_RETURN ) - { - scriptpubkey = HexStr(tx.vout[tx.vout.size()-2].scriptPubKey.begin()+2, tx.vout[tx.vout.size()-2].scriptPubKey.end()-1); - fHasOpret = true; - } - else scriptpubkey = HexStr(tx.vout[tx.vout.size()-1].scriptPubKey.begin()+2,tx.vout[tx.vout.size()-1].scriptPubKey.end()-1); - if ( !fIsMerge ) - { - strcpy(temp, scriptpubkey.c_str()); - pub2createtxid(temp); - createtxid = Parseuint256(temp); - } - //printf("createtxid.%s\n",createtxid.ToString().c_str()); + else if ( DecodePaymentsReleaseOpRet(ccopret,createtxid,amountReleased) != 'R' ) + return(eval->Invalid("could not decode ccopret")); + mpz_set_si(mpzCheckamount,amountReleased); + } else return(eval->Invalid("could not decode ccopret")); // use the createtxid to fetch the tx and all of the plans info. if ( myGetTransaction(createtxid,plantx,blockhash) != 0 && plantx.vout.size() > 0 ) @@ -295,27 +283,32 @@ bool PaymentsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction & return(eval->Invalid("negative values")); if ( minimum < 10000 ) return(eval->Invalid("minimum must be over 10000")); + if ( amountReleased < minrelease*COIN ) + { + fprintf(stderr, "does not meet minrelease amount.%li minrelease.%li\n",amountReleased, (int64_t)minrelease*COIN); + return(eval->Invalid("amount is too small")); + } Paymentspk = GetUnspendable(cp,0); txidpk = CCtxidaddr(txidaddr,createtxid); - GetCCaddress1of2(cp,coinaddr,Paymentspk,txidpk); + GetCCaddress1of2(cp,txidaddr,Paymentspk,txidpk); //fprintf(stderr, "lockedblocks.%i minrelease.%i totalallocations.%i txidopret1.%s txidopret2.%s\n",lockedblocks, minrelease, totalallocations, txidoprets[0].ToString().c_str(), txidoprets[1].ToString().c_str() ); if ( !CheckTxFee(tx, PAYMENTS_TXFEE+1, chainActive.LastTip()->GetHeight(), chainActive.LastTip()->nTime, actualtxfee) ) return eval->Invalid("txfee is too high"); - // make sure change is in vout 0 and is paying to the contract address. - if ( (change= IsPaymentsvout(cp,tx,0,coinaddr,ccopret)) == 0 ) - return(eval->Invalid("change is in wrong vout or is wrong tx type")); - + // Check that the change vout is playing the txid address. + if ( IsPaymentsvout(cp,tx,0,txidaddr,ccopret) == 0 ) + return eval->Invalid("change pays wrong address"); + if ( !fIsMerge ) { // Get all the script pubkeys and allocations std::vector allocations; std::vector scriptPubKeys; - int64_t checkallocations = 0; i = 0; if ( funcid == 'C' ) { // normal payment - for (const uint256& txidopret : txidoprets) + int64_t checkallocations = 0; + for ( auto txidopret : txidoprets) { CTransaction tx0; std::vector scriptPubKey,opret; int64_t allocation; if ( myGetTransaction(txidopret,tx0,blockhash) != 0 && tx0.vout.size() > 1 && DecodePaymentsTxidOpRet(tx0.vout[tx0.vout.size()-1].scriptPubKey,allocation,scriptPubKey,opret) == 'T' ) @@ -341,10 +334,14 @@ bool PaymentsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction & } i++; } + //fprintf(stderr, "totalallocations.%li checkallocations.%li\n",totalallocations, checkallocations); + if ( totalallocations != checkallocations ) + return(eval->Invalid("allocation missmatch")); mpz_set_si(mpzTotalAllocations,totalallocations); } else if ( funcid == 'S' ) { + // snapshot payment if ( KOMODO_SNAPSHOT_INTERVAL == 0 ) return(eval->Invalid("snapshots not activated on this chain")); if ( vAddressSnapshot.size() == 0 ) @@ -363,14 +360,13 @@ bool PaymentsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction & for (int32_t j = bottom; j < vAddressSnapshot.size(); j++) { auto &address = vAddressSnapshot[j]; - CScript scriptPubKey = GetScriptForDestination(address.second); bool skip = false; + CScript scriptPubKey = GetScriptForDestination(address.second); + bool skip = false; + // skip excluded addresses. for ( auto skipkey : excludeScriptPubKeys ) { if ( scriptPubKey == CScript(skipkey.begin(), skipkey.end()) ) - { skip = true; - //fprintf(stderr, "SKIPPED::: %s\n", CBitcoinAddress(address.second).ToString().c_str()); - } } if ( !skip ) { @@ -382,13 +378,9 @@ bool PaymentsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction & mpz_add(mpzTotalAllocations,mpzTotalAllocations,mpzAllocation); mpz_clear(mpzAllocation); } - if ( i+bottom == top ) // we reached top amount to pay, it can be less than this! - break; + if ( i+bottom == top ) + break; // we reached top amount to pay, it can be less than this, if less address exist on chain. } - - // need to check this later on as less can now be paid. - //if ( i != tx.vout.size()-2 ) - // return(eval->Invalid("pays wrong amount of recipients")); } else if ( funcid == 'O' ) { @@ -398,28 +390,25 @@ bool PaymentsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction & //fprintf(stderr, " allocations.size().%li scriptPubKeys.size.%li\n",allocations.size(), scriptPubKeys.size()); if ( (allocations.size() == 0 || scriptPubKeys.size() == 0 || allocations.size() != scriptPubKeys.size()) ) return(eval->Invalid("missing data cannot validate")); - - //fprintf(stderr, "totalallocations.%li checkallocations.%li\n",totalallocations, checkallocations); - if ( funcid == 'C' && totalallocations != checkallocations ) // only check for normal payments release. - return(eval->Invalid("allocation missmatch")); // Check vouts go to the right place and pay the right amounts. - int64_t amount = 0, checkamount; int32_t n = 0; - checkamount = tx.GetValueOut() - change - actualtxfee - PAYMENTS_TXFEE; - int64_t temptst = mpz_get_si(mpzTotalAllocations); - fprintf(stderr, "validation checkamount.%li totalallocations.%li\n",checkamount,temptst); - mpz_t mpzCheckamount; mpz_init(mpzCheckamount); mpz_set_si(mpzCheckamount,checkamount); - for (i = 1; i < (fHasOpret ? tx.vout.size()-2 : tx.vout.size()-1); i++) + int64_t amount = 0; int32_t n = 0; + // We place amount released into ccopret, so that these calcualtion are accurate! + // If you change the amount released in the RPC these calcs will be wrong, and validation will fail. + for (i = 1; i < (fHasOpret ? tx.vout.size()-1 : tx.vout.size()); i++) { + int64_t test; if ( scriptPubKeys[n] != tx.vout[i].scriptPubKey ) { fprintf(stderr, "pays wrong destination destscriptPubKey.%s voutscriptPubKey.%s\n", HexStr(scriptPubKeys[n].begin(),scriptPubKeys[n].end()).c_str(), HexStr(tx.vout[i].scriptPubKey.begin(),tx.vout[i].scriptPubKey.end()).c_str()); return(eval->Invalid("pays wrong address")); } - int64_t test; if ( fFixedAmount ) { - test = checkamount / (top-bottom); + if ( (top-bottom) > 0 ) + test = amountReleased / (top-bottom); + else + return(eval->Invalid("top/bottom range is illegal")); } else { @@ -431,14 +420,14 @@ bool PaymentsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction & mpz_clear(mpzAllocation); } //fprintf(stderr, "vout %i test.%li nValue.%li\n", i, test, tx.vout[i].nValue); - // I cant fix this! I dont understand the rouncing errors sorry. - if ( test > tx.vout[i].nValue+1 || test < tx.vout[i].nValue-1 ) + if ( test != tx.vout[i].nValue ) { fprintf(stderr, "vout.%i test.%li vs nVlaue.%li\n",i, test, tx.vout[i].nValue); return(eval->Invalid("amounts do not match")); } if ( test < minimum ) { + // prevent anyone being paid the minimum. fprintf(stderr, "vout.%i test.%li vs minimum.%i\n",i, test, minimum); return(eval->Invalid("under minimum size")); } @@ -447,61 +436,57 @@ bool PaymentsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction & } if ( allocations.size() > n ) { - // need to check that the next allocation was less than 10k sat, otherwise ppl can truncate the tx at any place. + // need to check that the next allocation was less than minimum, otherwise ppl can truncate the tx at any place not paying all elegible addresses. mpz_init(mpzAllocation); mpz_set_si(mpzAllocation,allocations[n+1]); mpz_mul(mpzAllocation,mpzAllocation,mpzCheckamount); - mpz_tdiv_q (mpzAllocation,mpzAllocation,mpzTotalAllocations); + mpz_tdiv_q(mpzAllocation,mpzAllocation,mpzTotalAllocations); int64_t test = mpz_get_si(mpzAllocation); - if ( test > minimum+1 ) + //fprintf(stderr, "check next vout pays under min: test.%li > minimuim.%i\n", test, minimum); + if ( test > minimum ) return(eval->Invalid("next allocation was not under minimum")); } mpz_clear(mpzTotalAllocations); mpz_clear(mpzCheckamount); - // This is a backup check to make sure there are no extra vouts paying something else! - if ( checkamount != amount ) - return(eval->Invalid("amounts do not match")); - - if ( amount < minrelease*COIN ) - { - fprintf(stderr, "does not meet minrelease amount.%li minrelease.%li\n",amount, (int64_t)minrelease*COIN ); - return(eval->Invalid("amount is too small")); - } } // Check vins - i = 0; int32_t dust = 0; - int32_t blocksleft; - BOOST_FOREACH(const CTxIn& vin, tx.vin) + i = 0; + for (auto vin : tx.vin) { CTransaction txin; if ( myGetTransaction(vin.prevout.hash,txin,blockhash) ) { // check the vin comes from the CC address's - char destaddr[64]; int32_t mergeoffset = 0; CScript opret; uint256 checktxid; - Getscriptaddress(destaddr,txin.vout[vin.prevout.n].scriptPubKey); + char fromaddr[64]; int32_t mergeoffset = 0; CScript vinccopret; uint256 checktxid; + Getscriptaddress(fromaddr,txin.vout[vin.prevout.n].scriptPubKey); if ( fIsMerge && txin.vout[vin.prevout.n].nValue < COIN ) dust++; - if ( strcmp(destaddr,coinaddr) != 0 ) + if ( IsPaymentsvout(cp,txin,vin.prevout.n,cp->unspendableCCaddr,vinccopret) != 0 ) { - // if does not come from address its in the global payments adddress and we need to check the opreturn. - uint256 checktxid; int32_t opret_ind; - if ( (opret_ind= has_opret(txin, EVAL_PAYMENTS)) == 0 ) - getCCopret(txin.vout[vin.prevout.n].scriptPubKey,opret); // get op_return from CCvout, - else - opret = txin.vout[opret_ind].scriptPubKey; - if ( DecodePaymentsFundOpRet(opret,checktxid) != 'F' || checktxid != createtxid ) + // if from global payments address get ccopret to detemine pays correct plan. + uint256 checktxid; + if ( vinccopret.size() < 2 || DecodePaymentsFundOpRet(vinccopret,checktxid) != 'F' || checktxid != createtxid ) { - fprintf(stderr, "vin.%i is not a payments CC vout: txid.%s\n", i, txin.GetHash().ToString().c_str()); + fprintf(stderr, "vin.%i is not a payments CC vout: txid.%s vout.%i\n", i, txin.GetHash().ToString().c_str(), vin.prevout.n); return(eval->Invalid("vin is not paymentsCC type")); } } - else if ( fIsMerge && getCCopret(txin.vout[vin.prevout.n].scriptPubKey,opret) && opret.size() > 2 && DecodePaymentsMergeOpRet(opret,checktxid) == 'M' ) + else if ( IsPaymentsvout(cp,txin,vin.prevout.n,txidaddr,vinccopret) != 0 ) { - mergeoffset = PAYMENTS_MERGEOFSET; - } - //fprintf(stderr, "mergeoffset.%i\n", mergeoffset); + // if in txid address apply merge offset if applicable. + if ( fIsMerge && vinccopret.size() > 2 && DecodePaymentsMergeOpRet(vinccopret,checktxid) == 'M' ) + { + // Apply merge offset to locked blocks, this prevents people spaming payments fund and payments merge to prevent release happening. + mergeoffset = PAYMENTS_MERGEOFSET; + } + } + else // not from global payments plan, or txid address. + return(eval->Invalid("utxo comes from incorrect address")); // check the chain depth vs locked blocks requirement. if ( !payments_lockedblocks(blockhash, lockedblocks+mergeoffset, blocksleft) ) + { + fprintf(stderr, "vin.%i is not elegible for.%i blocks \n",i, blocksleft); return(eval->Invalid("vin not elegible")); + } i++; } else return(eval->Invalid("cant get vin transaction")); } @@ -551,30 +536,21 @@ int64_t AddPaymentsInputs(bool fLockedBlocks,int8_t GetBalance,struct CCcontract //fprintf(stderr,"iter.%d %s/v%d %s\n",iter,txid.GetHex().c_str(),vout,coinaddr); if ( (vout == 0 || vout == 1) && GetTransaction(txid,vintx,hashBlock,false) != 0 ) { - if ( iter == 0 ) - { - CScript opret; uint256 checktxid; int32_t opret_ind; - if ( (opret_ind= has_opret(vintx, EVAL_PAYMENTS)) == 0 ) - { - // get op_return from CCvout - getCCopret(vintx.vout[vout].scriptPubKey,opret); - } - else - { - // get op_return from the op_return - opret = vintx.vout[opret_ind].scriptPubKey; - } - if ( DecodePaymentsFundOpRet(opret,checktxid) != 'F' || checktxid != createtxid ) - { - fprintf(stderr,"bad opret %s vs %s\n",checktxid.GetHex().c_str(),createtxid.GetHex().c_str()); - continue; - } - } if ( (nValue= IsPaymentsvout(cp,vintx,vout,coinaddr,ccopret)) > PAYMENTS_TXFEE && nValue >= threshold && myIsutxo_spentinmempool(ignoretxid,ignorevin,txid,vout) == 0 ) { int32_t offset = 0; - if ( ccopret.size() > 2 && DecodePaymentsMergeOpRet(ccopret,checktxid) == 'M' ) - offset = PAYMENTS_MERGEOFSET; + if ( ccopret.size() > 2 ) + { + if ( iter == 0 && (DecodePaymentsFundOpRet(ccopret,checktxid) != 'F' || checktxid != createtxid) ) + { + // global address but not for this plan. + fprintf(stderr,"bad opret %s vs %s\n",checktxid.GetHex().c_str(),createtxid.GetHex().c_str()); + continue; + } + // increase merge offset, if this is a merge tx, merging merged utxos. + if ( iter == 1 && GetBalance == 4 && DecodePaymentsMergeOpRet(ccopret,checktxid) == 'M' ) + offset = PAYMENTS_MERGEOFSET; + } int32_t tmpblocksleft = 0; if ( fLockedBlocks && !payments_lockedblocks(hashBlock, lockedblocks+offset, tmpblocksleft) ) { @@ -689,7 +665,7 @@ UniValue PaymentsRelease(struct CCcontract_info *cp,char *jsonstr) { LOCK(cs_main); CMutableTransaction tmpmtx,mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(),komodo_nextheight()); UniValue result(UniValue::VOBJ); uint256 createtxid,hashBlock,tokenid; - CTransaction tx,txO; CPubKey mypk,txidpk,Paymentspk; int32_t i,n,m,numoprets=0,lockedblocks,minrelease; int64_t newamount,inputsum,amount,CCchange=0,totalallocations=0,checkallocations=0,allocation; CTxOut vout; CScript onlyopret; char txidaddr[64],destaddr[64]; std::vector txidoprets; + CTransaction tx,txO; CPubKey mypk,txidpk,Paymentspk; int32_t i,n,m,numoprets=0,lockedblocks,minrelease; int64_t newamount,inputsum,amount,CCchange=0,totalallocations=0,checkallocations=0,allocation; CTxOut vout; CScript onlyopret,ccopret; char txidaddr[64],destaddr[64]; std::vector txidoprets; int32_t top,bottom=0,blocksleft=0,minimum=10000; std::vector> excludeScriptPubKeys; int8_t funcid,fixedAmount=0,skipminimum=0; bool fFixedAmount = false; mpz_t mpzTotalAllocations; mpz_init(mpzTotalAllocations); cJSON *params = payments_reparse(&n,jsonstr); @@ -727,7 +703,10 @@ UniValue PaymentsRelease(struct CCcontract_info *cp,char *jsonstr) return(result); } txidpk = CCtxidaddr(txidaddr,createtxid); - mtx.vout.push_back(MakeCC1of2vout(EVAL_PAYMENTS,0,Paymentspk,txidpk)); + ccopret = EncodePaymentsReleaseOpRet(createtxid, amount); + std::vector> vData = std::vector>(); + if ( makeCCopret(ccopret, vData) ) + mtx.vout.push_back(MakeCC1of2vout(EVAL_PAYMENTS,0,Paymentspk,txidpk,&vData)); //fprintf(stderr, "funcid.%i\n", funcid); if ( funcid == 'C' ) { @@ -812,6 +791,14 @@ UniValue PaymentsRelease(struct CCcontract_info *cp,char *jsonstr) { fFixedAmount = true; } + if ( (top-bottom) < 0 ) + { + result.push_back(Pair("result","error")); + result.push_back(Pair("error","invalid range top/bottom")); + if ( params != 0 ) + free_json(params); + return(result); + } for (int32_t j = bottom; j < vAddressSnapshot.size(); j++) { auto &address = vAddressSnapshot[j]; @@ -852,10 +839,7 @@ UniValue PaymentsRelease(struct CCcontract_info *cp,char *jsonstr) { mpz_t mpzValue; mpz_init(mpzValue); if ( fFixedAmount ) - { mtx.vout[i+1].nValue = amount / (top-bottom); - //fprintf(stderr, "amount.%li / top-bottom.%i = value.%li\n", amount, (top-bottom-2), mtx.vout[i+1].nValue); - } else { mpz_set_si(mpzValue,mtx.vout[i+1].nValue); @@ -872,8 +856,8 @@ UniValue PaymentsRelease(struct CCcontract_info *cp,char *jsonstr) return(result); } } - //fprintf(stderr, "nValue.%li \n", mtx.vout[i+1].nValue); mpz_clear(mpzValue); + //fprintf(stderr, "[%i] nValue.%li minimum.%i scriptpubkey.%s\n", i, mtx.vout[i+1].nValue, minimum, HexStr(mtx.vout[i+1].scriptPubKey.begin(),mtx.vout[i+1].scriptPubKey.end()).c_str()); if ( mtx.vout[i+1].nValue < minimum ) { if ( skipminimum == 0 ) @@ -887,15 +871,15 @@ UniValue PaymentsRelease(struct CCcontract_info *cp,char *jsonstr) else { // truncate off any vouts that are less than minimum. - mtx.vout.resize(i); + mtx.vout.resize(i+1); break; } } totalamountsent += mtx.vout[i+1].nValue; } if ( totalamountsent < amount ) newamount = totalamountsent; - int64_t temptst = mpz_get_si(mpzTotalAllocations); - fprintf(stderr, "checkamount RPC.%li totalallocations.%li\n",totalamountsent, temptst); + //int64_t temptst = mpz_get_si(mpzTotalAllocations); + //fprintf(stderr, "checkamount RPC.%li totalallocations.%li\n",totalamountsent, temptst); mpz_clear(mpzAmount); mpz_clear(mpzTotalAllocations); } else @@ -909,8 +893,7 @@ UniValue PaymentsRelease(struct CCcontract_info *cp,char *jsonstr) if ( (inputsum= AddPaymentsInputs(true,0,cp,mtx,txidpk,newamount+2*PAYMENTS_TXFEE,CC_MAXVINS/2,createtxid,lockedblocks,minrelease,blocksleft)) >= newamount+2*PAYMENTS_TXFEE ) { std::string rawtx; - mtx.vout[0].nValue = inputsum - newamount - 2*PAYMENTS_TXFEE; - mtx.vout.push_back(CTxOut(PAYMENTS_TXFEE,CScript() << ParseHex(HexStr(txidpk)) << OP_CHECKSIG)); + mtx.vout[0].nValue = inputsum - newamount - PAYMENTS_TXFEE; // only 1 txfee, so the minimum in this vout is a tx fee. GetCCaddress1of2(cp,destaddr,Paymentspk,txidpk); CCaddr1of2set(cp,Paymentspk,txidpk,cp->CCpriv,destaddr); rawtx = FinalizeCCTx(0,cp,mtx,mypk,PAYMENTS_TXFEE,onlyopret); @@ -945,18 +928,20 @@ UniValue PaymentsRelease(struct CCcontract_info *cp,char *jsonstr) UniValue PaymentsFund(struct CCcontract_info *cp,char *jsonstr) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); UniValue result(UniValue::VOBJ); - CPubKey Paymentspk,mypk,txidpk; uint256 txid,hashBlock; int64_t amount,totalallocations; CScript opret; CTransaction tx; char txidaddr[64]; std::string rawtx; int32_t n,useopret = 0,lockedblocks,minrelease; std::vector txidoprets; + CPubKey Paymentspk,mypk,txidpk; uint256 txid,hashBlock; int64_t amount,totalallocations; CScript opret; CTransaction tx; char txidaddr[64]; std::string rawtx; int32_t n,useopret = 0,broadcast=0,lockedblocks,minrelease; std::vector txidoprets; int32_t top,bottom,minimum=10000; std::vector> excludeScriptPubKeys; // snapshot uint256 tokenid; int8_t fixedAmount; cJSON *params = payments_reparse(&n,jsonstr); mypk = pubkey2pk(Mypubkey()); Paymentspk = GetUnspendable(cp,0); - if ( params != 0 && n > 1 && n <= 3 ) + if ( params != 0 && n > 1 && n <= 4 ) { txid = payments_juint256(jitem(params,0)); amount = jdouble(jitem(params,1),0) * SATOSHIDEN + 0.0000000049; if ( n == 3 ) useopret = jint(jitem(params,2),0) != 0; + if ( n == 4 ) + broadcast = jint(jitem(params,3),0) != 0; if ( myGetTransaction(txid,tx,hashBlock) == 0 || tx.vout.size() == 1 || (DecodePaymentsOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,lockedblocks,minrelease,totalallocations,txidoprets) == 0 && DecodePaymentsSnapsShotOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,lockedblocks,minrelease,minimum,top,bottom,fixedAmount,excludeScriptPubKeys) == 0 && DecodePaymentsTokensOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,lockedblocks,minrelease,minimum,top,bottom,fixedAmount,excludeScriptPubKeys,tokenid) == 0) ) { result.push_back(Pair("result","error")); @@ -979,18 +964,14 @@ UniValue PaymentsFund(struct CCcontract_info *cp,char *jsonstr) } else { - mtx.vout.push_back(MakeCC1vout(EVAL_PAYMENTS,amount,Paymentspk)); opret = EncodePaymentsFundOpRet(txid); - // Use the below one along with other FinalizeCCTx/return, to get the ccvout scriptpubkey - /*std::vector> vData = std::vector>(); + std::vector> vData = std::vector>(); if ( makeCCopret(opret, vData) ) - mtx.vout.push_back(MakeCC1vout(EVAL_PAYMENTS,amount,Paymentspk,&vData)); */ + mtx.vout.push_back(MakeCC1vout(EVAL_PAYMENTS,amount,Paymentspk,&vData)); } - rawtx = FinalizeCCTx(0,cp,mtx,mypk,PAYMENTS_TXFEE,opret); - //rawtx = FinalizeCCTx(0,cp,mtx,mypk,PAYMENTS_TXFEE,CScript()); // use this one to get ccvout scriptpubkey. + rawtx = FinalizeCCTx(0,cp,mtx,mypk,PAYMENTS_TXFEE,CScript()); if ( params != 0 ) - free_json(params); - //return(payments_rawtxresult(result,rawtx,0)); // disable sending for CCvout, as we only need to decode the tx. + free_json(params); return(payments_rawtxresult(result,rawtx,1)); } else @@ -1041,7 +1022,6 @@ UniValue PaymentsMerge(struct CCcontract_info *cp,char *jsonstr) // encode the checktxid into the end of the ccvout, along with 'M' to flag merge type tx. opret = EncodePaymentsMergeOpRet(createtxid); std::vector> vData = std::vector>(); - // try to pay to diffrent pubkey here... change txidpk. if ( makeCCopret(opret, vData) ) mtx.vout.push_back(MakeCC1of2vout(EVAL_PAYMENTS,inputsum-PAYMENTS_TXFEE,Paymentspk,txidpk,&vData)); GetCCaddress1of2(cp,destaddr,Paymentspk,txidpk); @@ -1214,6 +1194,14 @@ UniValue PaymentsAirdrop(struct CCcontract_info *cp,char *jsonstr) free_json(params); return(result); } + if ( top-bottom < 0 ) + { + result.push_back(Pair("result","error")); + result.push_back(Pair("error","invalid range, top/bottom")); + if ( params != 0 ) + free_json(params); + return(result); + } if ( n > 6 ) { for (i=0; i Date: Tue, 14 May 2019 08:27:56 +0800 Subject: [PATCH 266/447] change snapshot allocations to function --- src/cc/payments.cpp | 137 ++++++++++++++++++++++++-------------------- 1 file changed, 76 insertions(+), 61 deletions(-) diff --git a/src/cc/payments.cpp b/src/cc/payments.cpp index 528e6ec7f..6207915d9 100644 --- a/src/cc/payments.cpp +++ b/src/cc/payments.cpp @@ -256,6 +256,49 @@ bool payments_lockedblocks(uint256 blockhash,int32_t lockedblocks,int32_t &block return true; } +int32_t payments_getallocations(int32_t top, int32_t bottom, const std::vector> &excludeScriptPubKeys, mpz_t &mpzTotalAllocations, std::vector &scriptPubKeys, std::vector &allocations) +{ + mpz_t mpzAllocation; int32_t i =0; + for (int32_t j = bottom; j < vAddressSnapshot.size(); j++) + { + auto &address = vAddressSnapshot[j]; + CScript scriptPubKey = GetScriptForDestination(address.second); + bool skip = false; + // skip excluded addresses. + for ( auto skipkey : excludeScriptPubKeys ) + { + if ( scriptPubKey == CScript(skipkey.begin(), skipkey.end()) ) + skip = true; + } + if ( !skip ) + { + mpz_init(mpzAllocation); + i++; + //fprintf(stderr, "address: %s nValue.%li \n", CBitcoinAddress(address.second).ToString().c_str(), address.first); + scriptPubKeys.push_back(scriptPubKey); + allocations.push_back(address.first); + mpz_set_si(mpzAllocation,address.first); + mpz_add(mpzTotalAllocations,mpzTotalAllocations,mpzAllocation); + mpz_clear(mpzAllocation); + } + if ( i+bottom == top ) + break; // we reached top amount to pay, it can be less than this, if less address exist on chain, return the number we got. + } + return(i); +} + +int32_t payments_gettokenallocations(int32_t top, int32_t bottom, const std::vector> &excludeScriptPubKeys, uint256 tokenid, mpz_t &mpzTotalAllocations, std::vector &scriptPubKeys, std::vector &allocations) +{ + /* + - check tokenid exists. + - iterate tokenid address and extract all pubkeys, add to map. + - rewind to last notarized height for balances? + - convert balances to mpz_t and add up totalallocations + - sort the map into a vector, then convert to the correct output. + */ + return(0); +} + bool PaymentsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn) { char temp[128], txidaddr[64]={0}; std::string scriptpubkey; uint256 createtxid, blockhash, tokenid; CTransaction plantx; int8_t funcid=0, fixedAmount=0; @@ -339,7 +382,7 @@ bool PaymentsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction & return(eval->Invalid("allocation missmatch")); mpz_set_si(mpzTotalAllocations,totalallocations); } - else if ( funcid == 'S' ) + else if ( funcid == 'S' || funcid == 'O' ) { // snapshot payment if ( KOMODO_SNAPSHOT_INTERVAL == 0 ) @@ -357,35 +400,14 @@ bool PaymentsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction & { fFixedAmount = true; } - for (int32_t j = bottom; j < vAddressSnapshot.size(); j++) + if ( funcid == 'S' ) + payments_getallocations(top, bottom, excludeScriptPubKeys, mpzTotalAllocations, scriptPubKeys, allocations); + else { - auto &address = vAddressSnapshot[j]; - CScript scriptPubKey = GetScriptForDestination(address.second); - bool skip = false; - // skip excluded addresses. - for ( auto skipkey : excludeScriptPubKeys ) - { - if ( scriptPubKey == CScript(skipkey.begin(), skipkey.end()) ) - skip = true; - } - if ( !skip ) - { - mpz_init(mpzAllocation); - i++; - scriptPubKeys.push_back(scriptPubKey); - allocations.push_back(address.first); - mpz_set_si(mpzAllocation,address.first); - mpz_add(mpzTotalAllocations,mpzTotalAllocations,mpzAllocation); - mpz_clear(mpzAllocation); - } - if ( i+bottom == top ) - break; // we reached top amount to pay, it can be less than this, if less address exist on chain. + // token snapshot + // payments_gettokenallocations(top, bottom, excludeScriptPubKeys, tokenid, mpzTotalAllocations, scriptPubKeys, allocations); } } - else if ( funcid == 'O' ) - { - // tokens snapshot. - } // sanity check to make sure we got all the required info, skip for merge type tx //fprintf(stderr, " allocations.size().%li scriptPubKeys.size.%li\n",allocations.size(), scriptPubKeys.size()); if ( (allocations.size() == 0 || scriptPubKeys.size() == 0 || allocations.size() != scriptPubKeys.size()) ) @@ -667,7 +689,7 @@ UniValue PaymentsRelease(struct CCcontract_info *cp,char *jsonstr) CMutableTransaction tmpmtx,mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(),komodo_nextheight()); UniValue result(UniValue::VOBJ); uint256 createtxid,hashBlock,tokenid; CTransaction tx,txO; CPubKey mypk,txidpk,Paymentspk; int32_t i,n,m,numoprets=0,lockedblocks,minrelease; int64_t newamount,inputsum,amount,CCchange=0,totalallocations=0,checkallocations=0,allocation; CTxOut vout; CScript onlyopret,ccopret; char txidaddr[64],destaddr[64]; std::vector txidoprets; int32_t top,bottom=0,blocksleft=0,minimum=10000; std::vector> excludeScriptPubKeys; int8_t funcid,fixedAmount=0,skipminimum=0; bool fFixedAmount = false; - mpz_t mpzTotalAllocations; mpz_init(mpzTotalAllocations); + mpz_t mpzTotalAllocations, mpzAllocation; mpz_init(mpzTotalAllocations); cJSON *params = payments_reparse(&n,jsonstr); mypk = pubkey2pk(Mypubkey()); Paymentspk = GetUnspendable(cp,0); @@ -762,7 +784,7 @@ UniValue PaymentsRelease(struct CCcontract_info *cp,char *jsonstr) // set totalallocations to a mpz_t bignum, for amounts calculation later. mpz_set_si(mpzTotalAllocations,totalallocations); } - else if ( funcid == 'S' ) + else if ( funcid == 'S' || funcid == 'O' ) { // normal snapshot if ( vAddressSnapshot.size() == 0 ) @@ -781,7 +803,6 @@ UniValue PaymentsRelease(struct CCcontract_info *cp,char *jsonstr) free_json(params); return(result); } - i = 0; if ( fixedAmount == 7 ) { // game setting, randomise bottom and top values @@ -799,38 +820,32 @@ UniValue PaymentsRelease(struct CCcontract_info *cp,char *jsonstr) free_json(params); return(result); } - for (int32_t j = bottom; j < vAddressSnapshot.size(); j++) + + std::vector allocations; + std::vector scriptPubKeys; + if ( funcid == 'S' ) + m = payments_getallocations(top, bottom, excludeScriptPubKeys, mpzTotalAllocations, scriptPubKeys, allocations); + else { - auto &address = vAddressSnapshot[j]; - CScript scriptPubKey = GetScriptForDestination(address.second); bool skip = false; - for ( auto skipkey : excludeScriptPubKeys ) - { - if ( scriptPubKey == CScript(skipkey.begin(), skipkey.end()) ) - { - skip = true; - //fprintf(stderr, "SKIPPED::: %s\n", CBitcoinAddress(address.second).ToString().c_str()); - } - } - if ( !skip ) - { - mpz_t mpzAllocation; mpz_init(mpzAllocation); - i++; - //fprintf(stderr, "address: %s nValue.%li \n", CBitcoinAddress(address.second).ToString().c_str(), address.first); - vout.nValue = address.first; - vout.scriptPubKey = scriptPubKey; - mpz_set_si(mpzAllocation,address.first); - mpz_add(mpzTotalAllocations,mpzTotalAllocations,mpzAllocation); - mtx.vout.push_back(vout); - mpz_clear(mpzAllocation); - } - if ( i+bottom == top ) // we reached top amount to pay, it can be less than this! - break; + // token snapshot + // payments_gettokenallocations(top, bottom, excludeScriptPubKeys, tokenid, mpzTotalAllocations, scriptPubKeys, allocations); + } + if ( (allocations.size() == 0 || scriptPubKeys.size() == 0 || allocations.size() != scriptPubKeys.size()) ) + { + result.push_back(Pair("result","error")); + result.push_back(Pair("error","mismatched allocations, scriptpubkeys")); + if ( params != 0 ) + free_json(params); + return(result); + } + i = 0; + for ( auto allocation : allocations ) + { + vout.nValue = allocation; + vout.scriptPubKey = scriptPubKeys[i]; + mtx.vout.push_back(vout); + i++; } - m = i; // this is the amount we got, either top, or all of the address on the chain. - } - else if ( funcid == 'O' ) - { - // token snapshot } newamount = amount; int64_t totalamountsent = 0; @@ -863,7 +878,7 @@ UniValue PaymentsRelease(struct CCcontract_info *cp,char *jsonstr) if ( skipminimum == 0 ) { result.push_back(Pair("result","error")); - result.push_back(Pair("error","value too small, try releasing a larger amount")); + result.push_back(Pair("error","value too small, try releasing a larger amount, or use skipminimum flag")); if ( params != 0 ) free_json(params); return(result); From 389da98eb8998186de5648bcb2f318cc284504f7 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Tue, 14 May 2019 09:00:30 +0800 Subject: [PATCH 267/447] revert labs exemption --- src/cc/CCutils.cpp | 2 +- src/chain.h | 2 +- src/komodo_nk.h | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/cc/CCutils.cpp b/src/cc/CCutils.cpp index 1b326b85f..5de5ed0db 100644 --- a/src/cc/CCutils.cpp +++ b/src/cc/CCutils.cpp @@ -162,7 +162,7 @@ bool CheckTxFee(const CTransaction &tx, uint64_t txfee, uint32_t height, uint64_ actualtxfee = valuein-tx.GetValueOut(); if ( actualtxfee > txfee ) { - fprintf(stderr, "actualtxfee.%li vs txfee.%li\n", actualtxfee, txfee); + //fprintf(stderr, "actualtxfee.%li vs txfee.%li\n", actualtxfee, txfee); return false; } return true; diff --git a/src/chain.h b/src/chain.h index ac60dc277..b893e3a06 100644 --- a/src/chain.h +++ b/src/chain.h @@ -547,7 +547,7 @@ public: if ((s.GetType() & SER_DISK) && (nVersion >= SAPLING_VALUE_VERSION)) { READWRITE(nSaplingValue); } - if ( (s.GetType() & SER_DISK) && (is_STAKED(ASSETCHAINS_SYMBOL) != 0) )// && ASSETCHAINS_NOTARY_PAY[0] != 0 ) + if ( (s.GetType() & SER_DISK) && (is_STAKED(ASSETCHAINS_SYMBOL) != 0) && ASSETCHAINS_NOTARY_PAY[0] != 0 ) { READWRITE(nNotaryPay); READWRITE(segid); diff --git a/src/komodo_nk.h b/src/komodo_nk.h index 708e8ba6c..68512dfd7 100644 --- a/src/komodo_nk.h +++ b/src/komodo_nk.h @@ -1,10 +1,10 @@ #ifndef KOMODO_NK_H #define KOMODO_NK_H -#define ASSETCHAINS_N 77 -#define ASSETCHAINS_K 3 +//#define ASSETCHAINS_N 77 +//#define ASSETCHAINS_K 3 -//#define ASSETCHAINS_N 95 -//#define ASSETCHAINS_K 5 +#define ASSETCHAINS_N 96 +#define ASSETCHAINS_K 5 #endif From fae5d3b4f0063201f57f4b0827a9e0397d757f4d Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Tue, 14 May 2019 09:57:51 +0800 Subject: [PATCH 268/447] revert short reorg limit. Add some comments to dailysnapshot --- src/cc/payments.cpp | 3 ++- src/main.cpp | 6 +++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/cc/payments.cpp b/src/cc/payments.cpp index 6207915d9..0ea339f3a 100644 --- a/src/cc/payments.cpp +++ b/src/cc/payments.cpp @@ -292,7 +292,7 @@ int32_t payments_gettokenallocations(int32_t top, int32_t bottom, const std::vec /* - check tokenid exists. - iterate tokenid address and extract all pubkeys, add to map. - - rewind to last notarized height for balances? + - rewind to last notarized height for balances? see main.cpp: line# 660. - convert balances to mpz_t and add up totalallocations - sort the map into a vector, then convert to the correct output. */ @@ -885,6 +885,7 @@ UniValue PaymentsRelease(struct CCcontract_info *cp,char *jsonstr) } else { + // NOTE: should make this default behaviour. // truncate off any vouts that are less than minimum. mtx.vout.resize(i+1); break; diff --git a/src/main.cpp b/src/main.cpp index 20354fd59..7198fe7e6 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -656,8 +656,12 @@ std::vector > vAddressSnapshot; bool komodo_dailysnapshot(int32_t height) { - int reorglimit = 10; // CHANGE BACK TO 100 AFTER TESTING! + int reorglimit = 100; uint256 notarized_hash,notarized_desttxid; int32_t prevMoMheight,notarized_height,undo_height,extraoffset; + // NOTE: To make this 100% safe under all sync conditions, it should be using a notarized notarization, from the DB. + // Under heavy reorg attack, its possible `komodo_notarized_height` can return a height that can't be found on chain sync. + // However, the DB can reorg the last notarization. By using 2 deep, we know 100% that the previous notarization cannot be reorged by online nodes, + // and as such will always be notarizing the same height. May need to check heights on scan back to make sure they are confirmed in correct order. if ( (extraoffset= height % KOMODO_SNAPSHOT_INTERVAL) != 0 ) { // we are on chain init, and need to scan all the way back to the correct height, other wise our node will have a diffrent snapshot to online nodes. From 73fd95119fc133943eb23a924394ca24f3d851fe Mon Sep 17 00:00:00 2001 From: dimxy Date: Tue, 14 May 2019 15:26:21 +0500 Subject: [PATCH 269/447] added protection from corrupted old version targetSymbol --- src/rpc/crosschain.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/rpc/crosschain.cpp b/src/rpc/crosschain.cpp index 35409323d..dc8aecd46 100644 --- a/src/rpc/crosschain.cpp +++ b/src/rpc/crosschain.cpp @@ -1420,6 +1420,7 @@ UniValue getwalletburntransactions(const UniValue& params, bool fHelp) UnmarshalBurnTx(*pwtx, targetSymbol, &targetCCid, payoutsHash, rawproof)) { UniValue entry(UniValue::VOBJ); entry.push_back(Pair("txid", pwtx->GetHash().GetHex())); + if (vopret.begin()[0] == EVAL_TOKENS) { // get burned token value std::vector> oprets; @@ -1460,6 +1461,12 @@ UniValue getwalletburntransactions(const UniValue& params, bool fHelp) } else entry.push_back(Pair("burnedAmount", ValueFromAmount(pwtx->vout.back().nValue))); // coins + + // check for corrupted strings (look for non-printable chars) from some older versions + // which caused "couldn't parse reply from server" error on client: + if (std::find_if(targetSymbol.begin(), targetSymbol.end(), [](int c) {return !std::isprint(c);}) != targetSymbol.end()) + targetSymbol = "corrupted"; + entry.push_back(Pair("targetSymbol", targetSymbol)); entry.push_back(Pair("targetCCid", std::to_string(targetCCid))); if (mytxid_inmempool(pwtx->GetHash())) From 95907695349b2afc901124e25803dee9cd8fef8f Mon Sep 17 00:00:00 2001 From: dimxy Date: Tue, 14 May 2019 18:43:19 +0500 Subject: [PATCH 270/447] corr check for corrupt val --- src/rpc/crosschain.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/rpc/crosschain.cpp b/src/rpc/crosschain.cpp index dc8aecd46..407d32f25 100644 --- a/src/rpc/crosschain.cpp +++ b/src/rpc/crosschain.cpp @@ -1464,8 +1464,10 @@ UniValue getwalletburntransactions(const UniValue& params, bool fHelp) // check for corrupted strings (look for non-printable chars) from some older versions // which caused "couldn't parse reply from server" error on client: - if (std::find_if(targetSymbol.begin(), targetSymbol.end(), [](int c) {return !std::isprint(c);}) != targetSymbol.end()) - targetSymbol = "corrupted"; + // if (std::find_if(targetSymbol.begin(), targetSymbol.end(), [](int c) {return !std::isprint(c);}) != targetSymbol.end()) + UniValue testval(UniValue::VSTR); + if( !testval.read(targetSymbol) ) + targetSymbol = ""; entry.push_back(Pair("targetSymbol", targetSymbol)); entry.push_back(Pair("targetCCid", std::to_string(targetCCid))); From 406e54a00e30ccd6d88bf61b4da34b5cb3de2f0c Mon Sep 17 00:00:00 2001 From: dimxy Date: Tue, 14 May 2019 19:13:18 +0500 Subject: [PATCH 271/447] returned isprint check --- src/rpc/crosschain.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/rpc/crosschain.cpp b/src/rpc/crosschain.cpp index 407d32f25..bf0dbea4c 100644 --- a/src/rpc/crosschain.cpp +++ b/src/rpc/crosschain.cpp @@ -1464,9 +1464,7 @@ UniValue getwalletburntransactions(const UniValue& params, bool fHelp) // check for corrupted strings (look for non-printable chars) from some older versions // which caused "couldn't parse reply from server" error on client: - // if (std::find_if(targetSymbol.begin(), targetSymbol.end(), [](int c) {return !std::isprint(c);}) != targetSymbol.end()) - UniValue testval(UniValue::VSTR); - if( !testval.read(targetSymbol) ) + if (std::find_if(targetSymbol.begin(), targetSymbol.end(), [](int c) {return !std::isprint(c);}) != targetSymbol.end()) targetSymbol = ""; entry.push_back(Pair("targetSymbol", targetSymbol)); From 8d506a51a6d3cceda0262bdd44e2392e2392b6e2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 14 May 2019 23:54:12 -1100 Subject: [PATCH 272/447] +print --- src/deprecation.h | 2 +- src/komodo_gateway.h | 1 + src/main.cpp | 5 +++-- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/deprecation.h b/src/deprecation.h index 427234b4a..dde45e22c 100644 --- a/src/deprecation.h +++ b/src/deprecation.h @@ -24,7 +24,7 @@ // * Shut down WEEKS_UNTIL_DEPRECATION weeks' worth of blocks after the estimated release block height. // * A warning is shown during the DEPRECATION_WARN_LIMIT worth of blocks prior to shut down. static const int WEEKS_UNTIL_DEPRECATION = 52; -static const int DEPRECATION_HEIGHT = 1600000; +static const int DEPRECATION_HEIGHT = 2200000; static const int APPROX_RELEASE_HEIGHT = DEPRECATION_HEIGHT - (WEEKS_UNTIL_DEPRECATION * 7 * 24 * 60); // Number of blocks before deprecation to warn users diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 1fafcc856..62e42fad8 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -2019,6 +2019,7 @@ int32_t get_stockprices(uint32_t now,uint32_t *prices,std::vector s sprintf(url,"https://api.iextrading.com/1.0/tops/last?symbols=%s",GetArg("-ac_stocks","").c_str()); if ( (json= get_urljson(url)) != 0 ) //if ( (json= send_curl(url,(char *)"iex")) != 0 ) // { + fprintf(stderr,"stocks.(%s)\n",jprint(json,0)); if ( (n= cJSON_GetArraySize(json)) > 0 ) { retval = n; diff --git a/src/main.cpp b/src/main.cpp index 7198fe7e6..4fdf39f43 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1373,9 +1373,10 @@ bool CheckTransaction(uint32_t tiptime,const CTransaction& tx, CValidationState } } -int32_t komodo_isnotaryvout(char *coinaddr) // from ac_private chains only +int32_t komodo_isnotaryvout(char *coinaddr,uint32_t tiptime) // from ac_private chains only { static int32_t didinit; static char notaryaddrs[sizeof(Notaries_elected1)/sizeof(*Notaries_elected1) + 1][64]; + //use normal notary functions int32_t i; if ( didinit == 0 ) { @@ -1484,7 +1485,7 @@ bool CheckTransactionWithoutProofVerification(uint32_t tiptime,const CTransactio // char destaddr[65]; Getscriptaddress(destaddr,txout.scriptPubKey); - if ( komodo_isnotaryvout(destaddr) == 0 ) + if ( komodo_isnotaryvout(destaddr,tiptime) == 0 ) { invalid_private_taddr = 1; //return state.DoS(100, error("CheckTransaction(): this is a private chain, no public allowed"),REJECT_INVALID, "bad-txns-acprivacy-chain"); From 598cb471ad397f529f994a4e751788ff5014d229 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 14 May 2019 23:58:37 -1100 Subject: [PATCH 273/447] Tiptime --- src/wallet/rpcwallet.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index a22a81e34..5ecefce6f 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -72,7 +72,7 @@ const std::string ADDR_TYPE_SAPLING = "sapling"; extern UniValue TxJoinSplitToJSON(const CTransaction& tx); uint32_t komodo_segid32(char *coinaddr); int32_t komodo_dpowconfs(int32_t height,int32_t numconfs); -int32_t komodo_isnotaryvout(char *coinaddr); // from ac_private chains only +int32_t komodo_isnotaryvout(char *coinaddr,uint32_t tiptime); // from ac_private chains only CBlockIndex *komodo_getblockindex(uint256 hash); int64_t nWalletUnlockTime; @@ -461,7 +461,6 @@ static void SendMoney(const CTxDestination &address, CAmount nValue, bool fSubtr throw JSONRPCError(RPC_WALLET_ERROR, "Error: The transaction was rejected! This might happen if some of the coins in your wallet were already spent, such as if you used a copy of wallet.dat and coins were spent in the copy but not marked as spent here."); } -int32_t komodo_isnotaryvout(char *coinaddr); UniValue sendtoaddress(const UniValue& params, bool fHelp) { @@ -494,7 +493,7 @@ UniValue sendtoaddress(const UniValue& params, bool fHelp) if ( ASSETCHAINS_PRIVATE != 0 && AmountFromValue(params[1]) > 0 ) { - if ( komodo_isnotaryvout((char *)params[0].get_str().c_str()) == 0 ) + if ( komodo_isnotaryvout((char *)params[0].get_str().c_str(),chainActive.LastTip()->nTime) == 0 ) { throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid " + strprintf("%s",komodo_chainname()) + " address"); } From bd73b0772401148e1c9875ffc8086dcf89e8cb26 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 May 2019 00:03:03 -1100 Subject: [PATCH 274/447] +print --- src/komodo_gateway.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 62e42fad8..1455c34b3 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -2017,6 +2017,7 @@ int32_t get_stockprices(uint32_t now,uint32_t *prices,std::vector s { char url[32768],*symbol,*timestr; cJSON *json,*obj; int32_t i,n=0,retval=-1; uint32_t uprice,timestamp; sprintf(url,"https://api.iextrading.com/1.0/tops/last?symbols=%s",GetArg("-ac_stocks","").c_str()); + fprintf(stderr,"url.(%s)\n",url); if ( (json= get_urljson(url)) != 0 ) //if ( (json= send_curl(url,(char *)"iex")) != 0 ) // { fprintf(stderr,"stocks.(%s)\n",jprint(json,0)); From d96d5f8ddfe79d34445cc5b88c9d009a3fce16e8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 May 2019 00:05:56 -1100 Subject: [PATCH 275/447] http --- 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 1455c34b3..fbd8915ee 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -2016,7 +2016,7 @@ cJSON *get_urljson(char *url) int32_t get_stockprices(uint32_t now,uint32_t *prices,std::vector symbols) { char url[32768],*symbol,*timestr; cJSON *json,*obj; int32_t i,n=0,retval=-1; uint32_t uprice,timestamp; - sprintf(url,"https://api.iextrading.com/1.0/tops/last?symbols=%s",GetArg("-ac_stocks","").c_str()); + sprintf(url,"http://api.iextrading.com/1.0/tops/last?symbols=%s",GetArg("-ac_stocks","").c_str()); fprintf(stderr,"url.(%s)\n",url); if ( (json= get_urljson(url)) != 0 ) //if ( (json= send_curl(url,(char *)"iex")) != 0 ) // { From 532fe32e759ea1a1217198c6c9caf9b9eade3e43 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 May 2019 00:34:23 -1100 Subject: [PATCH 276/447] https --- 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 fbd8915ee..1455c34b3 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -2016,7 +2016,7 @@ cJSON *get_urljson(char *url) int32_t get_stockprices(uint32_t now,uint32_t *prices,std::vector symbols) { char url[32768],*symbol,*timestr; cJSON *json,*obj; int32_t i,n=0,retval=-1; uint32_t uprice,timestamp; - sprintf(url,"http://api.iextrading.com/1.0/tops/last?symbols=%s",GetArg("-ac_stocks","").c_str()); + sprintf(url,"https://api.iextrading.com/1.0/tops/last?symbols=%s",GetArg("-ac_stocks","").c_str()); fprintf(stderr,"url.(%s)\n",url); if ( (json= get_urljson(url)) != 0 ) //if ( (json= send_curl(url,(char *)"iex")) != 0 ) // { From 6f2903addfd5b24df1437cfd0fb570a3fb2c6d83 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 May 2019 01:44:43 -1100 Subject: [PATCH 277/447] Verbose --- 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 e616fb179..518bc4a4e 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -212,7 +212,7 @@ try_again: /* printf("[ Decker ] SSL: %s\n", curl_version()); */ curl_easy_setopt(curl_handle, CURLOPT_SSL_VERIFYPEER, 0L); curl_easy_setopt(curl_handle, CURLOPT_SSL_VERIFYHOST, 0L); - //curl_easy_setopt(curl_handle, CURLOPT_VERBOSE, 1L); // this is useful for debug, but seems crash on libcurl/7.64.1 OpenSSL/1.1.1b zlib/1.2.8 librtmp/2.3 + curl_easy_setopt(curl_handle, CURLOPT_VERBOSE, 1L); // this is useful for debug, but seems crash on libcurl/7.64.1 OpenSSL/1.1.1b zlib/1.2.8 librtmp/2.3 } if ( userpass != 0 ) curl_easy_setopt(curl_handle,CURLOPT_USERPWD, userpass); From a033c8717338d4b48801542dbeb1c8930d609dff Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 May 2019 01:47:15 -1100 Subject: [PATCH 278/447] -debug --- 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 518bc4a4e..e616fb179 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -212,7 +212,7 @@ try_again: /* printf("[ Decker ] SSL: %s\n", curl_version()); */ curl_easy_setopt(curl_handle, CURLOPT_SSL_VERIFYPEER, 0L); curl_easy_setopt(curl_handle, CURLOPT_SSL_VERIFYHOST, 0L); - curl_easy_setopt(curl_handle, CURLOPT_VERBOSE, 1L); // this is useful for debug, but seems crash on libcurl/7.64.1 OpenSSL/1.1.1b zlib/1.2.8 librtmp/2.3 + //curl_easy_setopt(curl_handle, CURLOPT_VERBOSE, 1L); // this is useful for debug, but seems crash on libcurl/7.64.1 OpenSSL/1.1.1b zlib/1.2.8 librtmp/2.3 } if ( userpass != 0 ) curl_easy_setopt(curl_handle,CURLOPT_USERPWD, userpass); From 46d00eced0df37ea6f7d2b9521cda0bd2d6ac067 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Wed, 15 May 2019 23:47:53 +0800 Subject: [PATCH 279/447] fix payments balance --- src/cc/payments.cpp | 2 +- src/wallet/rpcwallet.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/payments.cpp b/src/cc/payments.cpp index 0ea339f3a..3d28a8da8 100644 --- a/src/cc/payments.cpp +++ b/src/cc/payments.cpp @@ -556,7 +556,7 @@ int64_t AddPaymentsInputs(bool fLockedBlocks,int8_t GetBalance,struct CCcontract txid = it->first.txhash; vout = (int32_t)it->first.index; //fprintf(stderr,"iter.%d %s/v%d %s\n",iter,txid.GetHex().c_str(),vout,coinaddr); - if ( (vout == 0 || vout == 1) && GetTransaction(txid,vintx,hashBlock,false) != 0 ) + if ( GetTransaction(txid,vintx,hashBlock,false) != 0 ) { if ( (nValue= IsPaymentsvout(cp,vintx,vout,coinaddr,ccopret)) > PAYMENTS_TXFEE && nValue >= threshold && myIsutxo_spentinmempool(ignoretxid,ignorevin,txid,vout) == 0 ) { diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index a22a81e34..8311a1b44 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5660,7 +5660,7 @@ UniValue payments_airdroptokens(const UniValue& params, bool fHelp) { struct CCcontract_info *cp,C; if ( fHelp || params.size() != 1 ) - throw runtime_error("paymentsairdrop \"[%22tokenid%22,lockedblocks,minamount,mintoaddress,top,bottom,fixedFlag,%22excludePubKey%22,...,%22excludePubKeyN%22]\"\n"); + throw runtime_error("payments_airdroptokens \"[%22tokenid%22,lockedblocks,minamount,mintoaddress,top,bottom,fixedFlag,%22excludePubKey%22,...,%22excludePubKeyN%22]\"\n"); if ( ensure_CCrequirements(EVAL_PAYMENTS) < 0 ) throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); const CKeyStore& keystore = *pwalletMain; From aa919f3847072e642eec289f7969fe02ad9329ae Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Thu, 16 May 2019 01:06:56 +0800 Subject: [PATCH 280/447] fix paymentsmerge --- src/cc/payments.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/cc/payments.cpp b/src/cc/payments.cpp index 3d28a8da8..1cf7e3319 100644 --- a/src/cc/payments.cpp +++ b/src/cc/payments.cpp @@ -326,11 +326,6 @@ bool PaymentsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction & return(eval->Invalid("negative values")); if ( minimum < 10000 ) return(eval->Invalid("minimum must be over 10000")); - if ( amountReleased < minrelease*COIN ) - { - fprintf(stderr, "does not meet minrelease amount.%li minrelease.%li\n",amountReleased, (int64_t)minrelease*COIN); - return(eval->Invalid("amount is too small")); - } Paymentspk = GetUnspendable(cp,0); txidpk = CCtxidaddr(txidaddr,createtxid); GetCCaddress1of2(cp,txidaddr,Paymentspk,txidpk); @@ -343,6 +338,11 @@ bool PaymentsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction & if ( !fIsMerge ) { + if ( amountReleased < minrelease*COIN ) + { + fprintf(stderr, "does not meet minrelease amount.%li minrelease.%li\n",amountReleased, (int64_t)minrelease*COIN); + return(eval->Invalid("amount is too small")); + } // Get all the script pubkeys and allocations std::vector allocations; std::vector scriptPubKeys; From c2d469d6f97f28c01d3872917c86d9f8e0d87437 Mon Sep 17 00:00:00 2001 From: Mihail Fedorov Date: Thu, 16 May 2019 04:47:55 +0300 Subject: [PATCH 281/447] remove MGNX coin --- src/assetchains.json | 12 ------------ src/assetchains.old | 2 +- 2 files changed, 1 insertion(+), 13 deletions(-) diff --git a/src/assetchains.json b/src/assetchains.json index 683b791ad..cfed51981 100644 --- a/src/assetchains.json +++ b/src/assetchains.json @@ -159,18 +159,6 @@ "136.243.102.225" ] }, - { - "ac_name": "MGNX", - "ac_supply": "12465003", - "ac_staked": "90", - "ac_reward": "2000000000", - "ac_halving": "525960", - "ac_cc": "2", - "ac_end": "2629800", - "addnode": [ - "142.93.27.180" - ] - }, { "ac_name": "PGT", "ac_supply": "10000000", diff --git a/src/assetchains.old b/src/assetchains.old index 424d411ca..f6b4d008b 100755 --- a/src/assetchains.old +++ b/src/assetchains.old @@ -39,7 +39,7 @@ echo $pubkey ./komodod -pubkey=$pubkey -ac_name=SEC -ac_cc=333 -ac_supply=1000000000 -addnode=185.148.145.43 & ./komodod -pubkey=$pubkey -ac_name=CCL -ac_supply=200000000 -ac_end=1 -ac_cc=2 -addressindex=1 -spentindex=1 -addnode=142.93.136.89 -addnode=195.201.22.89 & ./komodod -pubkey=$pubkey -ac_name=PIRATE -ac_supply=0 -ac_reward=25600000000 -ac_halving=77777 -ac_private=1 -addnode=178.63.77.56 & -./komodod -pubkey=$pubkey -ac_name=MGNX -ac_supply=12465003 -ac_staked=90 -ac_reward=2000000000 -ac_halving=525960 -ac_cc=2 -ac_end=2629800 -addnode=142.93.27.180 & +#./komodod -pubkey=$pubkey -ac_name=MGNX -ac_supply=12465003 -ac_staked=90 -ac_reward=2000000000 -ac_halving=525960 -ac_cc=2 -ac_end=2629800 -addnode=142.93.27.180 & ./komodod -pubkey=$pubkey -ac_name=PGT -ac_supply=10000000 -ac_end=1 -addnode=190.114.254.104 & ./komodod -pubkey=$pubkey -ac_name=KMDICE -ac_supply=10500000 -ac_reward=2500000000 -ac_halving=210000 -ac_cc=2 -addressindex=1 -spentindex=1 -addnode=144.76.217.232 & ./komodod -pubkey=$pubkey -ac_name=DION -ac_supply=3900000000 -ac_reward=22260000000 -ac_staked=100 -ac_cc=1 -ac_end=4300000000 -addnode=51.75.124.34 & From bb83deb084229d45786bdea88b7604f247702f94 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Thu, 16 May 2019 14:48:39 +0800 Subject: [PATCH 282/447] fix crash --- src/main.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 7198fe7e6..73d27cae4 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4084,7 +4084,6 @@ bool static DisconnectTip(CValidationState &state, bool fBare = false) { if ((i == (block.vtx.size() - 1)) && (ASSETCHAINS_STAKED != 0 && (komodo_isPoS((CBlock *)&block,pindexDelete->GetHeight()) != 0))) { #ifdef ENABLE_WALLET - LOCK2(cs_main, pwalletMain->cs_wallet); pwalletMain->EraseFromWallet(tx.GetHash()); #endif } From edc1a411e5c8a47b070fb1474005360c10dbc3a0 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Thu, 16 May 2019 16:33:14 +0800 Subject: [PATCH 283/447] Test staking preformance improvement --- src/komodo_bitcoind.h | 33 +++++++++++++++++++++++++++------ src/main.cpp | 6 +++--- 2 files changed, 30 insertions(+), 9 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index e616fb179..044ef6c4e 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -682,11 +682,32 @@ int32_t komodo_WhoStaked(CBlock *pblock, CTxDestination &addressout) bool MarmaraPoScheck(char *destaddr,CScript opret,CTransaction staketx); -int32_t komodo_isPoS(CBlock *pblock,int32_t height) +int32_t komodo_isPoS2(CBlock *pblock) { - int32_t n,vout,numvouts; uint32_t txtime; uint64_t value; char voutaddr[64],destaddr[64]; CTxDestination voutaddress; uint256 txid; CScript opret; + CBlockIndex *pindex = komodo_blockindex(pblock->GetHash()); + if ( pindex != 0 && pindex->segid >= -1 ) + { + //fprintf(stderr,"isPoSblock segid.%d\n",pindex->segid); + if ( pindex->segid == -1 ) + return(0); + else return(1); + } + return (-1); +} + +int32_t komodo_isPoS(CBlock *pblock,int32_t height,bool fJustCheck) +{ + int32_t n,vout,numvouts,ret; uint32_t txtime; uint64_t value; char voutaddr[64],destaddr[64]; CTxDestination voutaddress; uint256 txid; CScript opret; if ( ASSETCHAINS_STAKED != 0 ) { + if ( fJustCheck ) + { + // check pindex first, if that does not work, continue with slow check. + if ( (ret= komodo_isPoS2(pblock)) == 1 ) + return (1); + else if ( ret == 0 ) + return (0); + } n = pblock->vtx.size(); //fprintf(stderr,"ht.%d check for PoS numtx.%d numvins.%d numvouts.%d\n",height,n,(int32_t)pblock->vtx[n-1].vin.size(),(int32_t)pblock->vtx[n-1].vout.size()); if ( n > 1 && pblock->vtx[n-1].vin.size() == 1 && pblock->vtx[n-1].vout.size() == 1+(ASSETCHAINS_MARMARA!=0) ) @@ -1585,7 +1606,7 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh int32_t komodo_is_PoSblock(int32_t slowflag,int32_t height,CBlock *pblock,arith_uint256 bnTarget,arith_uint256 bhash) { - CBlockIndex *previndex,*pindex; char voutaddr[64],destaddr[64]; uint256 txid; uint32_t txtime,prevtime=0; int32_t vout,PoSperc,txn_count,eligible=0,isPoS = 0,segid; uint64_t value; CTxDestination voutaddress; arith_uint256 POWTarget; + CBlockIndex *previndex,*pindex; char voutaddr[64],destaddr[64]; uint256 txid; uint32_t txtime,prevtime=0; int32_t ret,vout,PoSperc,txn_count,eligible=0,isPoS = 0,segid; uint64_t value; CTxDestination voutaddress; arith_uint256 POWTarget; if ( ASSETCHAINS_STAKED == 100 && height <= 10 ) return(1); BlockMap::const_iterator it = mapBlockIndex.find(pblock->GetHash()); @@ -1604,7 +1625,7 @@ int32_t komodo_is_PoSblock(int32_t slowflag,int32_t height,CBlock *pblock,arith_ //fprintf(stderr,"checkblock n.%d vins.%d vouts.%d %.8f %.8f\n",txn_count,(int32_t)pblock->vtx[txn_count-1].vin.size(),(int32_t)pblock->vtx[txn_count-1].vout.size(),(double)pblock->vtx[txn_count-1].vout[0].nValue/COIN,(double)pblock->vtx[txn_count-1].vout[1].nValue/COIN); if ( txn_count > 1 && pblock->vtx[txn_count-1].vin.size() == 1 && pblock->vtx[txn_count-1].vout.size() == 1 + (ASSETCHAINS_MARMARA!=0) ) { - it = mapBlockIndex.find(pblock->hashPrevBlock); + BlockMap::const_iterator it = mapBlockIndex.find(pblock->hashPrevBlock); if ( it != mapBlockIndex.end() && (previndex = it->second) != NULL ) prevtime = (uint32_t)previndex->nTime; @@ -1612,7 +1633,7 @@ int32_t komodo_is_PoSblock(int32_t slowflag,int32_t height,CBlock *pblock,arith_ vout = pblock->vtx[txn_count-1].vin[0].prevout.n; if ( slowflag != 0 && prevtime != 0 ) { - if ( komodo_isPoS(pblock,height) != 0 ) + if ( komodo_isPoS(pblock,height,false) != 0 ) { eligible = komodo_stake(1,bnTarget,height,txid,vout,pblock->nTime,prevtime+27,(char *)"",PoSperc); } @@ -1644,7 +1665,7 @@ int32_t komodo_is_PoSblock(int32_t slowflag,int32_t height,CBlock *pblock,arith_ } else if ( slowflag == 0 ) // previous blocks are not seen yet, do the best approx { - if ( komodo_isPoS(pblock,height) != 0 ) + if ( komodo_isPoS(pblock,height,false) != 0 ) isPoS = 1; } if ( slowflag != 0 && isPoS != 0 ) diff --git a/src/main.cpp b/src/main.cpp index 7b3ea9285..609203562 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4050,7 +4050,7 @@ bool static DisconnectTip(CValidationState &state, bool fBare = false) { CValidationState stateDummy; // don't keep staking or invalid transactions - if (tx.IsCoinBase() || ((i == (block.vtx.size() - 1)) && (ASSETCHAINS_STAKED && komodo_isPoS((CBlock *)&block,pindexDelete->GetHeight()) != 0)) || !AcceptToMemoryPool(mempool, stateDummy, tx, false, NULL)) + if (tx.IsCoinBase() || ((i == (block.vtx.size() - 1)) && (ASSETCHAINS_STAKED && komodo_isPoS((CBlock *)&block,pindexDelete->GetHeight(),true) != 0)) || !AcceptToMemoryPool(mempool, stateDummy, tx, false, NULL)) { mempool.remove(tx, removed, true); } @@ -4082,7 +4082,7 @@ bool static DisconnectTip(CValidationState &state, bool fBare = false) { { CTransaction &tx = block.vtx[i]; //if ((i == (block.vtx.size() - 1)) && ((ASSETCHAINS_LWMAPOS && block.IsVerusPOSBlock()) || (ASSETCHAINS_STAKED != 0 && (komodo_isPoS((CBlock *)&block) != 0)))) - if ((i == (block.vtx.size() - 1)) && (ASSETCHAINS_STAKED != 0 && (komodo_isPoS((CBlock *)&block,pindexDelete->GetHeight()) != 0))) + if ((i == (block.vtx.size() - 1)) && (ASSETCHAINS_STAKED != 0 && (komodo_isPoS((CBlock *)&block,pindexDelete->GetHeight(),true) != 0))) { #ifdef ENABLE_WALLET pwalletMain->EraseFromWallet(tx.GetHash()); @@ -5093,7 +5093,7 @@ bool CheckBlock(int32_t *futureblockp,int32_t height,CBlockIndex *pindex,const C CValidationState state; CTransaction Tx; const CTransaction &tx = (CTransaction)block.vtx[i]; - if (tx.IsCoinBase() || !tx.vjoinsplit.empty() || !tx.vShieldedSpend.empty() || ((i == (block.vtx.size() - 1)) && (ASSETCHAINS_STAKED && komodo_isPoS((CBlock *)&block,height) != 0))) + if (tx.IsCoinBase() || !tx.vjoinsplit.empty() || !tx.vShieldedSpend.empty() || ((i == (block.vtx.size() - 1)) && (ASSETCHAINS_STAKED && komodo_isPoS((CBlock *)&block,height,true) != 0))) continue; Tx = tx; if ( myAddtomempool(Tx, &state, true) == false ) // happens with out of order tx in block on resync From c2261146d94225aeda6ddede7496d208d5b5188a Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Thu, 16 May 2019 19:33:05 +0800 Subject: [PATCH 284/447] Fix KMD lockup on pools, try new fix electrum crash. --- src/main.cpp | 6 ++++-- src/miner.cpp | 2 ++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 049a732d5..663e94e26 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3978,8 +3978,10 @@ bool static DisconnectTip(CValidationState &state, bool fBare = false) { if ((i == (block.vtx.size() - 1)) && (ASSETCHAINS_STAKED != 0 && (komodo_isPoS((CBlock *)&block,pindexDelete->GetHeight()) != 0))) { #ifdef ENABLE_WALLET - LOCK2(cs_main, pwalletMain->cs_wallet); - pwalletMain->EraseFromWallet(tx.GetHash()); + if (!fDisableWallet) { + LOCK(pwalletMain->cs_wallet); + pwalletMain->EraseFromWallet(tx.GetHash()); + } #endif } else diff --git a/src/miner.cpp b/src/miner.cpp index f131bc90e..dce1ff81f 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -803,6 +803,8 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 //fprintf(stderr,"check validity\n"); if ( !TestBlockValidity(state, *pblock, pindexPrev, false, false)) // invokes CC checks { + LEAVE_CRITICAL_SECTION(cs_main); + LEAVE_CRITICAL_SECTION(mempool.cs); throw std::runtime_error("CreateNewBlock(): TestBlockValidity failed"); } //fprintf(stderr,"valid\n"); From 7df6ab444d7573be9e24eabe110748837e368012 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Thu, 16 May 2019 19:37:05 +0800 Subject: [PATCH 285/447] fix --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 663e94e26..4be588ef1 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3978,7 +3978,7 @@ bool static DisconnectTip(CValidationState &state, bool fBare = false) { if ((i == (block.vtx.size() - 1)) && (ASSETCHAINS_STAKED != 0 && (komodo_isPoS((CBlock *)&block,pindexDelete->GetHeight()) != 0))) { #ifdef ENABLE_WALLET - if (!fDisableWallet) { + if ( GetBoolArg("-disablewallet", false) ) { LOCK(pwalletMain->cs_wallet); pwalletMain->EraseFromWallet(tx.GetHash()); } From bbd24399a22ebbb1355344c30f721af80a998584 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Thu, 16 May 2019 19:46:47 +0800 Subject: [PATCH 286/447] bit safer --- src/miner.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/miner.cpp b/src/miner.cpp index dce1ff81f..92be1c2e6 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -803,14 +803,17 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 //fprintf(stderr,"check validity\n"); if ( !TestBlockValidity(state, *pblock, pindexPrev, false, false)) // invokes CC checks { - LEAVE_CRITICAL_SECTION(cs_main); - LEAVE_CRITICAL_SECTION(mempool.cs); + if ( ASSETCHAINS_SYMBOL[0] == 0 || (ASSETCHAINS_SYMBOL[0] != 0 && !isStake) ) + { + LEAVE_CRITICAL_SECTION(cs_main); + LEAVE_CRITICAL_SECTION(mempool.cs); + } throw std::runtime_error("CreateNewBlock(): TestBlockValidity failed"); } //fprintf(stderr,"valid\n"); } } - if ( ASSETCHAINS_SYMBOL[0] == 0 || (ASSETCHAINS_SYMBOL[0] != 0 && !isStake) ) + if ( ASSETCHAINS_SYMBOL[0] == 0 || (ASSETCHAINS_SYMBOL[0] != 0 && !isStake) ) { LEAVE_CRITICAL_SECTION(cs_main); LEAVE_CRITICAL_SECTION(mempool.cs); From 8b57ca63b870f49ebd9306af454374f31b0b2aaa Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Wed, 15 May 2019 21:27:05 -0700 Subject: [PATCH 287/447] Prevent linkability analysis on out-of-sync nodes This addresses upstream issue https://github.com/zcash/zcash/issues/3996 by preventing z_sendmany, z_mergecoinbase and z_shieldcoinbase from making shielded transactions if the node is out of sync. This prevents metadata leakage which can be used in blockchain analysis. --- src/wallet/rpcwallet.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index a22a81e34..23b62c2fe 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -70,6 +70,7 @@ extern std::string ASSETCHAINS_OVERRIDE_PUBKEY; const std::string ADDR_TYPE_SPROUT = "sprout"; const std::string ADDR_TYPE_SAPLING = "sapling"; extern UniValue TxJoinSplitToJSON(const CTransaction& tx); +extern int32_t KOMODO_INSYNC; uint32_t komodo_segid32(char *coinaddr); int32_t komodo_dpowconfs(int32_t height,int32_t numconfs); int32_t komodo_isnotaryvout(char *coinaddr); // from ac_private chains only @@ -84,6 +85,7 @@ UniValue z_getoperationstatus_IMPL(const UniValue&, bool); #define PLAN_NAME_MAX 8 #define VALID_PLAN_NAME(x) (strlen(x) <= PLAN_NAME_MAX) +#define THROW_IF_SYNCING(INSYNC) if (INSYNC == 0) { throw runtime_error(strprintf("%s: Chain still syncing at height %d, aborting to prevent linkability analysis!",__FUNCTION__,chainActive.Tip()->GetHeight())); } int tx_height( const uint256 &hash ); @@ -4248,6 +4250,8 @@ UniValue z_sendmany(const UniValue& params, bool fHelp) + HelpExampleRpc("z_sendmany", "\"RD6GgnrMpPaTSMn8vai6yiGA7mN4QGPV\", [{\"address\": \"zs14d8tc0hl9q0vg5l28uec5vk6sk34fkj2n8s7jalvw5fxpy6v39yn4s2ga082lymrkjk0x2nqg37\" ,\"amount\": 5.0}]") ); + THROW_IF_SYNCING(KOMODO_INSYNC); + LOCK2(cs_main, pwalletMain->cs_wallet); // Check that the from address is valid. @@ -4557,6 +4561,8 @@ UniValue z_shieldcoinbase(const UniValue& params, bool fHelp) + HelpExampleRpc("z_shieldcoinbase", "\"RD6GgnrMpPaTSMn8vai6yiGA7mN4QGPV\", \"zs14d8tc0hl9q0vg5l28uec5vk6sk34fkj2n8s7jalvw5fxpy6v39yn4s2ga082lymrkjk0x2nqg37\"") ); + THROW_IF_SYNCING(KOMODO_INSYNC); + LOCK2(cs_main, pwalletMain->cs_wallet); // Validate the from address @@ -4817,6 +4823,8 @@ UniValue z_mergetoaddress(const UniValue& params, bool fHelp) throw JSONRPCError(RPC_WALLET_ERROR, "Error: z_mergetoaddress is disabled."); } + THROW_IF_SYNCING(KOMODO_INSYNC); + LOCK2(cs_main, pwalletMain->cs_wallet); bool useAnyUTXO = false; From 3275b435dea4e9348ea495d4be9a76e265573ab2 Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Wed, 15 May 2019 22:07:09 -0700 Subject: [PATCH 288/447] Add synced key to getinfo+getblockchaininfo This addresses #3 of upstream issue https://github.com/zcash/zcash/issues/3996 . Any software that creates a transaction outside of the RPC interface MUST check if synced==true beforehand, otherwise metadata leakage which leads to linkability analysis is possible. The z_sendmany, z_shieldcoinbase and z_mergetoaddress RPCs have their own synced checks, so it's not needed to look at this new synced value when using those RPCs. --- src/rpc/blockchain.cpp | 4 +++- src/rpc/misc.cpp | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index cb2cfce92..042b6591f 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -48,6 +48,7 @@ using namespace std; +extern int32_t KOMODO_INSYNC; extern void TxToJSON(const CTransaction& tx, const uint256 hashBlock, UniValue& entry); void ScriptPubKeyToJSON(const CScript& scriptPubKey, UniValue& out, bool fIncludeHex); #include "komodo_defs.h" @@ -1689,6 +1690,7 @@ UniValue getblockchaininfo(const UniValue& params, bool fHelp) UniValue obj(UniValue::VOBJ); obj.push_back(Pair("chain", Params().NetworkIDString())); obj.push_back(Pair("blocks", (int)chainActive.Height())); + obj.push_back(Pair("synced", KOMODO_INSYNC!=0)); obj.push_back(Pair("headers", pindexBestHeader ? pindexBestHeader->GetHeight() : -1)); obj.push_back(Pair("bestblockhash", chainActive.LastTip()->GetBlockHash().GetHex())); obj.push_back(Pair("difficulty", (double)GetNetworkDifficulty())); @@ -2082,4 +2084,4 @@ void RegisterBlockchainRPCCommands(CRPCTable &tableRPC) { for (unsigned int vcidx = 0; vcidx < ARRAYLEN(commands); vcidx++) tableRPC.appendCommand(commands[vcidx].name, &commands[vcidx]); -} \ No newline at end of file +} diff --git a/src/rpc/misc.cpp b/src/rpc/misc.cpp index 5a495c005..eca4abb36 100644 --- a/src/rpc/misc.cpp +++ b/src/rpc/misc.cpp @@ -69,7 +69,7 @@ bool komodo_txnotarizedconfirmed(uint256 txid); uint32_t komodo_chainactive_timestamp(); int32_t komodo_whoami(char *pubkeystr,int32_t height,uint32_t timestamp); extern uint64_t KOMODO_INTERESTSUM,KOMODO_WALLETBALANCE; -extern int32_t KOMODO_LASTMINED,JUMBLR_PAUSE,KOMODO_LONGESTCHAIN,IS_STAKED_NOTARY,IS_KOMODO_NOTARY,STAKED_ERA; +extern int32_t KOMODO_LASTMINED,JUMBLR_PAUSE,KOMODO_LONGESTCHAIN,IS_STAKED_NOTARY,IS_KOMODO_NOTARY,STAKED_ERA,KOMODO_INSYNC; extern char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN]; uint32_t komodo_segid32(char *coinaddr); int64_t komodo_coinsupply(int64_t *zfundsp,int64_t *sproutfundsp,int32_t height); @@ -237,6 +237,7 @@ UniValue getinfo(const UniValue& params, bool fHelp) obj.push_back(Pair("version", CLIENT_VERSION)); obj.push_back(Pair("protocolversion", PROTOCOL_VERSION)); obj.push_back(Pair("KMDversion", KOMODO_VERSION)); + obj.push_back(Pair("synced", KOMODO_INSYNC!=0)); //obj.push_back(Pair("VRSCversion", VERUS_VERSION)); obj.push_back(Pair("notarized", notarized_height)); obj.push_back(Pair("prevMoMheight", prevMoMheight)); From 34a57ceb4a61b5b68f8281561d072bfe0618b4ba Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Thu, 16 May 2019 20:31:55 +0800 Subject: [PATCH 289/447] fix --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 4be588ef1..8e8207d2b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3978,7 +3978,7 @@ bool static DisconnectTip(CValidationState &state, bool fBare = false) { if ((i == (block.vtx.size() - 1)) && (ASSETCHAINS_STAKED != 0 && (komodo_isPoS((CBlock *)&block,pindexDelete->GetHeight()) != 0))) { #ifdef ENABLE_WALLET - if ( GetBoolArg("-disablewallet", false) ) { + if ( !GetBoolArg("-disablewallet", false) ) { LOCK(pwalletMain->cs_wallet); pwalletMain->EraseFromWallet(tx.GetHash()); } From e655736b9f79dd8dadb5b64616229c9fe1cc4eac Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Thu, 16 May 2019 21:47:03 +0800 Subject: [PATCH 290/447] try staker fix --- src/komodo_bitcoind.h | 59 +++++++++++++------------------------------ 1 file changed, 18 insertions(+), 41 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index e616fb179..30f81eb38 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -2503,7 +2503,6 @@ 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); bool resetstaker = false; if ( array != 0 ) @@ -2588,9 +2587,8 @@ 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,"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); block_from_future_rejecttime = (uint32_t)GetAdjustedTime() + 57; for (i=winners=0; itxid,kp->vout,0,(uint32_t)tipindex->nTime+27,kp->address,PoSperc); - //fprintf(stderr,"i.%d %u vs %u\n",i,eligible2,eligible); if ( eligible > 0 ) { - besttime = m = 0; + besttime = 0; if ( eligible == komodo_stake(1,bnTarget,nHeight,kp->txid,kp->vout,eligible,(uint32_t)tipindex->nTime+27,kp->address,PoSperc) ) { - while ( eligible == komodo_stake(1,bnTarget,nHeight,kp->txid,kp->vout,eligible,(uint32_t)tipindex->nTime+27,kp->address,PoSperc) ) + // have elegible utxo to stak with. + if ( earliest == 0 || eligible < earliest || (eligible == earliest && (*utxovaluep == 0 || kp->nValue < *utxovaluep)) ) { - besttime = eligible; - 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); + // is better than the previous best, so use it instead. + earliest = eligible; + best_scriptPubKey = kp->scriptPubKey; + *utxovaluep = (uint64_t)kp->nValue; + decode_hex((uint8_t *)utxotxidp,32,(char *)kp->txid.GetHex().c_str()); + *utxovoutp = kp->vout; + *txtimep = kp->txtime; } - } - else - { - //fprintf(stderr,"ht.%d error validating winning blocktime %u -> %.8f eligible.%u test prior\n",nHeight,*blocktimep,(double)kp->nValue/COIN,eligible); - continue; - } - 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); - if ( earliest == 0 || eligible < earliest || (eligible == earliest && (*utxovaluep == 0 || kp->nValue < *utxovaluep)) ) - { - earliest = eligible; - best_scriptPubKey = kp->scriptPubKey; //out.tx->vout[out.i].scriptPubKey; - *utxovaluep = (uint64_t)kp->nValue; - //decode_hex((uint8_t *)utxotxidp,32,(char *)out.tx->GetHash().GetHex().c_str()); - decode_hex((uint8_t *)utxotxidp,32,(char *)kp->txid.GetHex().c_str()); - *utxovoutp = kp->vout; - *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"); + if ( eligible < block_from_future_rejecttime ) // nothing gained by going earlier + break; + } else continue; + } } if ( numkp < 1000 && array != 0 ) { @@ -2659,7 +2641,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt ((uint8_t *)&revtxid)[i] = ((uint8_t *)utxotxidp)[31 - i]; txNew.vin[0].prevout.hash = revtxid; txNew.vin[0].prevout.n = *utxovoutp; - txNew.vout[0].scriptPubKey = best_scriptPubKey;// CScript() << ParseHex(NOTARY_PUBKEY) << OP_CHECKSIG; + txNew.vout[0].scriptPubKey = best_scriptPubKey; txNew.vout[0].nValue = *utxovaluep - txfee; txNew.nLockTime = earliest; CTransaction txNewConst(txNew); @@ -2670,7 +2652,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt ptr = (uint8_t *)&sigdata.scriptSig[0]; siglen = sigdata.scriptSig.size(); for (i=0; i Date: Fri, 17 May 2019 00:27:07 +0800 Subject: [PATCH 291/447] add address to txidopret --- src/cc/payments.cpp | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/src/cc/payments.cpp b/src/cc/payments.cpp index 1cf7e3319..ecdeb3e75 100644 --- a/src/cc/payments.cpp +++ b/src/cc/payments.cpp @@ -1067,15 +1067,27 @@ UniValue PaymentsMerge(struct CCcontract_info *cp,char *jsonstr) UniValue PaymentsTxidopret(struct CCcontract_info *cp,char *jsonstr) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); UniValue result(UniValue::VOBJ); CPubKey mypk; std::string rawtx; - std::vector scriptPubKey,opret; int32_t n,retval0,retval1=0; int64_t allocation; + std::vector scriptPubKey,opret; int32_t n,retval0,retval1=0; int64_t allocation; CScript test; txnouttype whichType; cJSON *params = payments_reparse(&n,jsonstr); mypk = pubkey2pk(Mypubkey()); if ( params != 0 && n > 1 && n <= 3 ) { allocation = (int64_t)jint(jitem(params,0),0); - retval0 = payments_parsehexdata(scriptPubKey,jitem(params,1),0); - CScript test = CScript(scriptPubKey.begin(),scriptPubKey.end()); - txnouttype whichType; + std::string address; + address.append(jstri(params,1)); + CTxDestination destination = DecodeDestination(address); + if ( IsValidDestination(destination) ) + { + // its an address + test = GetScriptForDestination(destination); + scriptPubKey = std::vector (test.begin(),test.end()); + } + else + { + // its a scriptpubkey + retval0 = payments_parsehexdata(scriptPubKey,jitem(params,1),0); + test = CScript(scriptPubKey.begin(),scriptPubKey.end()); + } if (!::IsStandard(test, whichType)) { result.push_back(Pair("result","error")); @@ -1090,7 +1102,7 @@ UniValue PaymentsTxidopret(struct CCcontract_info *cp,char *jsonstr) rawtx = FinalizeCCTx(0,cp,mtx,mypk,PAYMENTS_TXFEE,EncodePaymentsTxidOpRet(allocation,scriptPubKey,opret)); if ( params != 0 ) free_json(params); - return(payments_rawtxresult(result,rawtx,1)); + return(payments_rawtxresult(result,rawtx,0)); } result.push_back(Pair("result","error")); result.push_back(Pair("error","invalid params or cant find txfee")); From f0933909480f53684ecfd8a3845eb07d383473d1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 16 May 2019 06:06:33 -1100 Subject: [PATCH 292/447] -extern --- src/rpc/net.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/rpc/net.cpp b/src/rpc/net.cpp index e280b1a0b..56f221a37 100644 --- a/src/rpc/net.cpp +++ b/src/rpc/net.cpp @@ -219,7 +219,6 @@ int32_t komodo_longestchain() depth--; if ( num > (n >> 1) ) { - extern char ASSETCHAINS_SYMBOL[]; if ( 0 && height != KOMODO_LONGESTCHAIN ) fprintf(stderr,"set %s KOMODO_LONGESTCHAIN <- %d\n",ASSETCHAINS_SYMBOL,height); KOMODO_LONGESTCHAIN = height; From 027f9a58f17a2f2679584f9819f0da5c20316232 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Fri, 17 May 2019 10:30:56 +0800 Subject: [PATCH 293/447] revert build things for start.sh --- src/cc/makecclib | 2 ++ src/komodo_bitcoind.h | 10 +++------- src/wallet/db.h | 4 ++-- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/src/cc/makecclib b/src/cc/makecclib index e4816c55c..e9a015e2f 100755 --- a/src/cc/makecclib +++ b/src/cc/makecclib @@ -7,6 +7,8 @@ make -f Makefile_rogue rm ../libcc.so cp librogue.so ../libcc.so +exit 0 + echo sudoku/musig/dilithium gcc -O3 -std=c++11 -I../secp256k1/include -I../univalue/include -I../cryptoconditions/include -I../cryptoconditions/src -I../cryptoconditions/src/asn -I.. -I. -fPIC -shared -c -o sudokucc.so cclib.cpp diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 3c5c7a35d..48962b015 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1422,10 +1422,6 @@ arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t he if ( ASSETCHAINS_ALGO == ASSETCHAINS_VERUSHASH || ASSETCHAINS_ALGO == ASSETCHAINS_VERUSHASHV1_1 ) percPoS = (percPoS*100) / (m+n); else - // This seems to be inverse. The actual PoS % is backwards in the first 100 blocks. - // I dont't understand the math here, or why its backwards, so I am just disabling it for VerusHash. - // No doubt this is probably wrong for equihash aswell, we may need to test an equihash chain with the rule above. - // Need to ask james what the deal is here! Seems to be causeing ALL the problems. percPoS = ((percPoS * n) + (goalperc * (100-n))) / 100; } if ( dispflag != 0 && ASSETCHAINS_STAKED < 100 ) @@ -1625,7 +1621,7 @@ int32_t komodo_is_PoSblock(int32_t slowflag,int32_t height,CBlock *pblock,arith_ //fprintf(stderr,"checkblock n.%d vins.%d vouts.%d %.8f %.8f\n",txn_count,(int32_t)pblock->vtx[txn_count-1].vin.size(),(int32_t)pblock->vtx[txn_count-1].vout.size(),(double)pblock->vtx[txn_count-1].vout[0].nValue/COIN,(double)pblock->vtx[txn_count-1].vout[1].nValue/COIN); if ( txn_count > 1 && pblock->vtx[txn_count-1].vin.size() == 1 && pblock->vtx[txn_count-1].vout.size() == 1 + (ASSETCHAINS_MARMARA!=0) ) { - BlockMap::const_iterator it = mapBlockIndex.find(pblock->hashPrevBlock); + it = mapBlockIndex.find(pblock->hashPrevBlock); if ( it != mapBlockIndex.end() && (previndex = it->second) != NULL ) prevtime = (uint32_t)previndex->nTime; @@ -2627,7 +2623,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt besttime = 0; if ( eligible == komodo_stake(1,bnTarget,nHeight,kp->txid,kp->vout,eligible,(uint32_t)tipindex->nTime+27,kp->address,PoSperc) ) { - // have elegible utxo to stak with. + // have elegible utxo to stake with. if ( earliest == 0 || eligible < earliest || (eligible == earliest && (*utxovaluep == 0 || kp->nValue < *utxovaluep)) ) { // is better than the previous best, so use it instead. @@ -2643,7 +2639,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt } else continue; } } - if ( numkp < 1000 && array != 0 ) + if ( numkp < 500 && array != 0 ) { free(array); array = 0; diff --git a/src/wallet/db.h b/src/wallet/db.h index e1ae52909..604ae1633 100644 --- a/src/wallet/db.h +++ b/src/wallet/db.h @@ -34,8 +34,8 @@ #include // If CCLIB fails to compile with this, use the one below. -#include -//#include "../depends/x86_64-unknown-linux-gnu/include/db_cxx.h" +//include +#include "../depends/x86_64-unknown-linux-gnu/include/db_cxx.h" extern unsigned int nWalletDBUpdated; From c1df6fc05a080396f10373cb0ab2680019b2baf4 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Fri, 17 May 2019 12:04:33 +0800 Subject: [PATCH 294/447] fix --- 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 044ef6c4e..d7fd53629 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1625,7 +1625,7 @@ int32_t komodo_is_PoSblock(int32_t slowflag,int32_t height,CBlock *pblock,arith_ //fprintf(stderr,"checkblock n.%d vins.%d vouts.%d %.8f %.8f\n",txn_count,(int32_t)pblock->vtx[txn_count-1].vin.size(),(int32_t)pblock->vtx[txn_count-1].vout.size(),(double)pblock->vtx[txn_count-1].vout[0].nValue/COIN,(double)pblock->vtx[txn_count-1].vout[1].nValue/COIN); if ( txn_count > 1 && pblock->vtx[txn_count-1].vin.size() == 1 && pblock->vtx[txn_count-1].vout.size() == 1 + (ASSETCHAINS_MARMARA!=0) ) { - BlockMap::const_iterator it = mapBlockIndex.find(pblock->hashPrevBlock); + it = mapBlockIndex.find(pblock->hashPrevBlock); if ( it != mapBlockIndex.end() && (previndex = it->second) != NULL ) prevtime = (uint32_t)previndex->nTime; From 1970e041751c582fcca241be666299d68f4f89f0 Mon Sep 17 00:00:00 2001 From: SHossain Date: Fri, 17 May 2019 17:33:43 +0100 Subject: [PATCH 295/447] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 6c0002ba4..af67cfd48 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,7 @@ This is the official Komodo sourcecode repository based on https://github.com/jl ## Tech Specification - Max Supply: 200 million KMD -- Block Time: 1m 2s +- Block Time: 60 seconds - Block Reward: 3 KMD - Mining Algorithm: Equihash From 1583446b4736ed19ea7fb52c76de85a55296680a Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Sat, 18 May 2019 22:53:16 +0800 Subject: [PATCH 296/447] change notary pubkey activation code. --- src/komodo.h | 4 +- src/komodo_defs.h | 155 +++++++++++++++++++++++++++++- src/komodo_globals.h | 1 + src/komodo_notary.h | 223 +++++++++++-------------------------------- src/komodo_utils.h | 18 ++-- src/main.cpp | 27 +++--- 6 files changed, 233 insertions(+), 195 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index b4c7d12bf..cd7c6573a 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -713,9 +713,9 @@ int32_t komodo_voutupdate(bool fJustCheck,int32_t *isratificationp,int32_t notar sp->MoMdepth = MoMdepth; } komodo_stateupdate(height,0,0,0,zero,0,0,0,0,0,0,0,0,0,0,sp->MoM,sp->MoMdepth); - if ( ASSETCHAINS_SYMBOL[0] != 0 ) + //if ( ASSETCHAINS_SYMBOL[0] != 0 ) printf("[%s] ht.%d NOTARIZED.%d %s.%s %sTXID.%s lens.(%d %d) MoM.%s %d\n",ASSETCHAINS_SYMBOL,height,sp->NOTARIZED_HEIGHT,ASSETCHAINS_SYMBOL[0]==0?"KMD":ASSETCHAINS_SYMBOL,srchash.ToString().c_str(),ASSETCHAINS_SYMBOL[0]==0?"BTC":"KMD",desttxid.ToString().c_str(),opretlen,len,sp->MoM.ToString().c_str(),sp->MoMdepth); - + if ( ASSETCHAINS_SYMBOL[0] == 0 ) { if ( signedfp == 0 ) diff --git a/src/komodo_defs.h b/src/komodo_defs.h index 5efbe58fb..cae024390 100644 --- a/src/komodo_defs.h +++ b/src/komodo_defs.h @@ -31,6 +31,158 @@ #define KOMODO_SAPLING_DEADLINE 1550188800 // Feb 15th, 2019 #define _COINBASE_MATURITY 100 +// KMD Notary Seasons +// 1: May 1st 2018 1530921600 +// 2: July 1st 2019 1561939200 +// 3: 3rd season ending isnt known, so use very far times in future. + // 1751328000 = dummy timestamp, 1 July 2025! + // 7113400 = 5x current KMD blockheight. +// to add 4th season, change NUM_KMD_SEASONS to 4, and add timestamp and height of activation to these arrays. +#define NUM_KMD_SEASONS 3 +#define NUM_KMD_NOTARIES 64 +static const uint32_t KMD_SEASON_TIMESTAMPS[NUM_KMD_SEASONS] = {1525132800, 1561939200, 1751328000}; +static const int32_t KMD_SEASON_HEIGHTS[NUM_KMD_SEASONS] = {814000, 1422680, 7113400}; + +// Era array of pubkeys. Add extra seasons to bottom as requried, after adding appropriate info above. +static const char *notaries_elected[NUM_KMD_SEASONS][NUM_KMD_NOTARIES][2] = +{ + { + { "0_jl777_testA", "03b7621b44118017a16043f19b30cc8a4cfe068ac4e42417bae16ba460c80f3828" }, + { "0_jl777_testB", "02ebfc784a4ba768aad88d44d1045d240d47b26e248cafaf1c5169a42d7a61d344" }, + { "0_kolo_testA", "0287aa4b73988ba26cf6565d815786caf0d2c4af704d7883d163ee89cd9977edec" }, + { "artik_AR", "029acf1dcd9f5ff9c455f8bb717d4ae0c703e089d16cf8424619c491dff5994c90" }, + { "artik_EU", "03f54b2c24f82632e3cdebe4568ba0acf487a80f8a89779173cdb78f74514847ce" }, + { "artik_NA", "0224e31f93eff0cc30eaf0b2389fbc591085c0e122c4d11862c1729d090106c842" }, + { "artik_SH", "02bdd8840a34486f38305f311c0e2ae73e84046f6e9c3dd3571e32e58339d20937" }, + { "badass_EU", "0209d48554768dd8dada988b98aca23405057ac4b5b46838a9378b95c3e79b9b9e" }, + { "badass_NA", "02afa1a9f948e1634a29dc718d218e9d150c531cfa852843a1643a02184a63c1a7" }, + { "badass_SH", "026b49dd3923b78a592c1b475f208e23698d3f085c4c3b4906a59faf659fd9530b" }, + { "crackers_EU", "03bc819982d3c6feb801ec3b720425b017d9b6ee9a40746b84422cbbf929dc73c3" }, // 10 + { "crackers_NA", "03205049103113d48c7c7af811b4c8f194dafc43a50d5313e61a22900fc1805b45" }, + { "crackers_SH", "02be28310e6312d1dd44651fd96f6a44ccc269a321f907502aae81d246fabdb03e" }, + { "durerus_EU", "02bcbd287670bdca2c31e5d50130adb5dea1b53198f18abeec7211825f47485d57" }, + { "etszombi_AR", "031c79168d15edabf17d9ec99531ea9baa20039d0cdc14d9525863b83341b210e9" }, + { "etszombi_EU", "0281b1ad28d238a2b217e0af123ce020b79e91b9b10ad65a7917216eda6fe64bf7" }, // 15 + { "etszombi_SH", "025d7a193c0757f7437fad3431f027e7b5ed6c925b77daba52a8755d24bf682dde" }, + { "farl4web_EU", "0300ecf9121cccf14cf9423e2adb5d98ce0c4e251721fa345dec2e03abeffbab3f" }, + { "farl4web_SH", "0396bb5ed3c57aa1221d7775ae0ff751e4c7dc9be220d0917fa8bbdf670586c030" }, + { "fullmoon_AR", "0254b1d64840ce9ff6bec9dd10e33beb92af5f7cee628f999cb6bc0fea833347cc" }, + { "fullmoon_NA", "031fb362323b06e165231c887836a8faadb96eda88a79ca434e28b3520b47d235b" }, // 20 + { "fullmoon_SH", "030e12b42ec33a80e12e570b6c8274ce664565b5c3da106859e96a7208b93afd0d" }, + { "grewal_NA", "03adc0834c203d172bce814df7c7a5e13dc603105e6b0adabc942d0421aefd2132" }, + { "grewal_SH", "03212a73f5d38a675ee3cdc6e82542a96c38c3d1c79d25a1ed2e42fcf6a8be4e68" }, + { "indenodes_AR", "02ec0fa5a40f47fd4a38ea5c89e375ad0b6ddf4807c99733c9c3dc15fb978ee147" }, + { "indenodes_EU", "0221387ff95c44cb52b86552e3ec118a3c311ca65b75bf807c6c07eaeb1be8303c" }, + { "indenodes_NA", "02698c6f1c9e43b66e82dbb163e8df0e5a2f62f3a7a882ca387d82f86e0b3fa988" }, + { "indenodes_SH", "0334e6e1ec8285c4b85bd6dae67e17d67d1f20e7328efad17ce6fd24ae97cdd65e" }, + { "jeezy_EU", "023cb3e593fb85c5659688528e9a4f1c4c7f19206edc7e517d20f794ba686fd6d6" }, + { "jsgalt_NA", "027b3fb6fede798cd17c30dbfb7baf9332b3f8b1c7c513f443070874c410232446" }, + { "karasugoi_NA", "02a348b03b9c1a8eac1b56f85c402b041c9bce918833f2ea16d13452309052a982" }, // 30 + { "kashifali_EU", "033777c52a0190f261c6f66bd0e2bb299d30f012dcb8bfff384103211edb8bb207" }, + { "kolo_AR", "03016d19344c45341e023b72f9fb6e6152fdcfe105f3b4f50b82a4790ff54e9dc6" }, + { "kolo_SH", "02aa24064500756d9b0959b44d5325f2391d8e95c6127e109184937152c384e185" }, + { "metaphilibert_AR", "02adad675fae12b25fdd0f57250b0caf7f795c43f346153a31fe3e72e7db1d6ac6" }, + { "movecrypto_AR", "022783d94518e4dc77cbdf1a97915b29f427d7bc15ea867900a76665d3112be6f3" }, + { "movecrypto_EU", "021ab53bc6cf2c46b8a5456759f9d608966eff87384c2b52c0ac4cc8dd51e9cc42" }, + { "movecrypto_NA", "02efb12f4d78f44b0542d1c60146738e4d5506d27ec98a469142c5c84b29de0a80" }, + { "movecrypto_SH", "031f9739a3ebd6037a967ce1582cde66e79ea9a0551c54731c59c6b80f635bc859" }, + { "muros_AR", "022d77402fd7179335da39479c829be73428b0ef33fb360a4de6890f37c2aa005e" }, + { "noashh_AR", "029d93ef78197dc93892d2a30e5a54865f41e0ca3ab7eb8e3dcbc59c8756b6e355" }, // 40 + { "noashh_EU", "02061c6278b91fd4ac5cab4401100ffa3b2d5a277e8f71db23401cc071b3665546" }, + { "noashh_NA", "033c073366152b6b01535e15dd966a3a8039169584d06e27d92a69889b720d44e1" }, + { "nxtswe_EU", "032fb104e5eaa704a38a52c126af8f67e870d70f82977e5b2f093d5c1c21ae5899" }, + { "polycryptoblog_NA", "02708dcda7c45fb54b78469673c2587bfdd126e381654819c4c23df0e00b679622" }, + { "pondsea_AR", "032e1c213787312099158f2d74a89e8240a991d162d4ce8017d8504d1d7004f735" }, + { "pondsea_EU", "0225aa6f6f19e543180b31153d9e6d55d41bc7ec2ba191fd29f19a2f973544e29d" }, + { "pondsea_NA", "031bcfdbb62268e2ff8dfffeb9ddff7fe95fca46778c77eebff9c3829dfa1bb411" }, + { "pondsea_SH", "02209073bc0943451498de57f802650311b1f12aa6deffcd893da198a544c04f36" }, + { "popcornbag_AR", "02761f106fb34fbfc5ddcc0c0aa831ed98e462a908550b280a1f7bd32c060c6fa3" }, + { "popcornbag_NA", "03c6085c7fdfff70988fda9b197371f1caf8397f1729a844790e421ee07b3a93e8" }, // 50 + { "ptytrader_NA", "0328c61467148b207400b23875234f8a825cce65b9c4c9b664f47410b8b8e3c222" }, + { "ptytrader_SH", "0250c93c492d8d5a6b565b90c22bee07c2d8701d6118c6267e99a4efd3c7748fa4" }, + { "rnr_AR", "029bdb08f931c0e98c2c4ba4ef45c8e33a34168cb2e6bf953cef335c359d77bfcd" }, + { "rnr_EU", "03f5c08dadffa0ffcafb8dd7ffc38c22887bd02702a6c9ac3440deddcf2837692b" }, + { "rnr_NA", "02e17c5f8c3c80f584ed343b8dcfa6d710dfef0889ec1e7728ce45ce559347c58c" }, + { "rnr_SH", "037536fb9bdfed10251f71543fb42679e7c52308bcd12146b2568b9a818d8b8377" }, + { "titomane_AR", "03cda6ca5c2d02db201488a54a548dbfc10533bdc275d5ea11928e8d6ab33c2185" }, + { "titomane_EU", "02e41feded94f0cc59f55f82f3c2c005d41da024e9a805b41105207ef89aa4bfbd" }, + { "titomane_SH", "035f49d7a308dd9a209e894321f010d21b7793461b0c89d6d9231a3fe5f68d9960" }, + { "vanbreuk_EU", "024f3cad7601d2399c131fd070e797d9cd8533868685ddbe515daa53c2e26004c3" }, // 60 + { "xrobesx_NA", "03f0cc6d142d14a40937f12dbd99dbd9021328f45759e26f1877f2a838876709e1" }, + { "xxspot1_XX", "02ef445a392fcaf3ad4176a5da7f43580e8056594e003eba6559a713711a27f955" }, + { "xxspot2_XX", "03d85b221ea72ebcd25373e7961f4983d12add66a92f899deaf07bab1d8b6f5573" } + }, + { + {"0dev1_jl777", "03b7621b44118017a16043f19b30cc8a4cfe068ac4e42417bae16ba460c80f3828" }, + {"0dev2_kolo", "030f34af4b908fb8eb2099accb56b8d157d49f6cfb691baa80fdd34f385efed961" }, + {"0dev3_kolo", "025af9d2b2a05338478159e9ac84543968fd18c45fd9307866b56f33898653b014" }, + {"0dev4_decker", "028eea44a09674dda00d88ffd199a09c9b75ba9782382cc8f1e97c0fd565fe5707" }, + {"a-team_SH", "03b59ad322b17cb94080dc8e6dc10a0a865de6d47c16fb5b1a0b5f77f9507f3cce" }, + {"artik_AR", "029acf1dcd9f5ff9c455f8bb717d4ae0c703e089d16cf8424619c491dff5994c90" }, + {"artik_EU", "03f54b2c24f82632e3cdebe4568ba0acf487a80f8a89779173cdb78f74514847ce" }, + {"artik_NA", "0224e31f93eff0cc30eaf0b2389fbc591085c0e122c4d11862c1729d090106c842" }, + {"artik_SH", "02bdd8840a34486f38305f311c0e2ae73e84046f6e9c3dd3571e32e58339d20937" }, + {"badass_EU", "0209d48554768dd8dada988b98aca23405057ac4b5b46838a9378b95c3e79b9b9e" }, + {"badass_NA", "02afa1a9f948e1634a29dc718d218e9d150c531cfa852843a1643a02184a63c1a7" }, // 10 + {"batman_AR", "033ecb640ec5852f42be24c3bf33ca123fb32ced134bed6aa2ba249cf31b0f2563" }, + {"batman_SH", "02ca5898931181d0b8aafc75ef56fce9c43656c0b6c9f64306e7c8542f6207018c" }, + {"ca333_EU", "03fc87b8c804f12a6bd18efd43b0ba2828e4e38834f6b44c0bfee19f966a12ba99" }, + {"chainmakers_EU", "02f3b08938a7f8d2609d567aebc4989eeded6e2e880c058fdf092c5da82c3bc5ee" }, + {"chainmakers_NA", "0276c6d1c65abc64c8559710b8aff4b9e33787072d3dda4ec9a47b30da0725f57a" }, + {"chainstrike_SH", "0370bcf10575d8fb0291afad7bf3a76929734f888228bc49e35c5c49b336002153" }, + {"cipi_AR", "02c4f89a5b382750836cb787880d30e23502265054e1c327a5bfce67116d757ce8" }, + {"cipi_NA", "02858904a2a1a0b44df4c937b65ee1f5b66186ab87a751858cf270dee1d5031f18" }, + {"crackers_EU", "03bc819982d3c6feb801ec3b720425b017d9b6ee9a40746b84422cbbf929dc73c3" }, + {"crackers_NA", "03205049103113d48c7c7af811b4c8f194dafc43a50d5313e61a22900fc1805b45" }, // 20 + {"dwy_EU", "0259c646288580221fdf0e92dbeecaee214504fdc8bbdf4a3019d6ec18b7540424" }, + {"emmanux_SH", "033f316114d950497fc1d9348f03770cd420f14f662ab2db6172df44c389a2667a" }, + {"etszombi_EU", "0281b1ad28d238a2b217e0af123ce020b79e91b9b10ad65a7917216eda6fe64bf7" }, + {"fullmoon_AR", "03380314c4f42fa854df8c471618751879f9e8f0ff5dbabda2bd77d0f96cb35676" }, + {"fullmoon_NA", "030216211d8e2a48bae9e5d7eb3a42ca2b7aae8770979a791f883869aea2fa6eef" }, + {"fullmoon_SH", "03f34282fa57ecc7aba8afaf66c30099b5601e98dcbfd0d8a58c86c20d8b692c64" }, + {"goldenman_EU", "02d6f13a8f745921cdb811e32237bb98950af1a5952be7b3d429abd9152f8e388d" }, + {"indenodes_AR", "02ec0fa5a40f47fd4a38ea5c89e375ad0b6ddf4807c99733c9c3dc15fb978ee147" }, + {"indenodes_EU", "0221387ff95c44cb52b86552e3ec118a3c311ca65b75bf807c6c07eaeb1be8303c" }, + {"indenodes_NA", "02698c6f1c9e43b66e82dbb163e8df0e5a2f62f3a7a882ca387d82f86e0b3fa988" }, // 30 + {"indenodes_SH", "0334e6e1ec8285c4b85bd6dae67e17d67d1f20e7328efad17ce6fd24ae97cdd65e" }, + {"jackson_AR", "038ff7cfe34cb13b524e0941d5cf710beca2ffb7e05ddf15ced7d4f14fbb0a6f69" }, + {"jeezy_EU", "023cb3e593fb85c5659688528e9a4f1c4c7f19206edc7e517d20f794ba686fd6d6" }, + {"karasugoi_NA", "02a348b03b9c1a8eac1b56f85c402b041c9bce918833f2ea16d13452309052a982" }, + {"komodoninja_EU", "038e567b99806b200b267b27bbca2abf6a3e8576406df5f872e3b38d30843cd5ba" }, + {"komodoninja_SH", "033178586896915e8456ebf407b1915351a617f46984001790f0cce3d6f3ada5c2" }, + {"komodopioneers_SH", "033ace50aedf8df70035b962a805431363a61cc4e69d99d90726a2d48fb195f68c" }, + {"libscott_SH", "03301a8248d41bc5dc926088a8cf31b65e2daf49eed7eb26af4fb03aae19682b95" }, + {"lukechilds_AR", "031aa66313ee024bbee8c17915cf7d105656d0ace5b4a43a3ab5eae1e14ec02696" }, + {"madmax_AR", "03891555b4a4393d655bf76f0ad0fb74e5159a615b6925907678edc2aac5e06a75" }, // 40 + {"meshbits_AR", "02957fd48ae6cb361b8a28cdb1b8ccf5067ff68eb1f90cba7df5f7934ed8eb4b2c" }, + {"meshbits_SH", "025c6e94877515dfd7b05682b9cc2fe4a49e076efe291e54fcec3add78183c1edb" }, + {"metaphilibert_AR", "02adad675fae12b25fdd0f57250b0caf7f795c43f346153a31fe3e72e7db1d6ac6" }, + {"metaphilibert_SH", "0284af1a5ef01503e6316a2ca4abf8423a794e9fc17ac6846f042b6f4adedc3309" }, + {"patchkez_SH", "0296270f394140640f8fa15684fc11255371abb6b9f253416ea2734e34607799c4" }, + {"pbca26_NA", "0276aca53a058556c485bbb60bdc54b600efe402a8b97f0341a7c04803ce204cb5" }, + {"peer2cloud_AR", "034e5563cb885999ae1530bd66fab728e580016629e8377579493b386bf6cebb15" }, + {"peer2cloud_SH", "03396ac453b3f23e20f30d4793c5b8ab6ded6993242df4f09fd91eb9a4f8aede84" }, + {"polycryptoblog_NA", "02708dcda7c45fb54b78469673c2587bfdd126e381654819c4c23df0e00b679622" }, + {"hyper_AR", "020f2f984d522051bd5247b61b080b4374a7ab389d959408313e8062acad3266b4" }, // 50 + {"hyper_EU", "03d00cf9ceace209c59fb013e112a786ad583d7de5ca45b1e0df3b4023bb14bf51" }, + {"hyper_SH", "0383d0b37f59f4ee5e3e98a47e461c861d49d0d90c80e9e16f7e63686a2dc071f3" }, + {"hyper_NA", "03d91c43230336c0d4b769c9c940145a8c53168bf62e34d1bccd7f6cfc7e5592de" }, + {"popcornbag_AR", "02761f106fb34fbfc5ddcc0c0aa831ed98e462a908550b280a1f7bd32c060c6fa3" }, + {"popcornbag_NA", "03c6085c7fdfff70988fda9b197371f1caf8397f1729a844790e421ee07b3a93e8" }, + {"alien_AR", "0348d9b1fc6acf81290405580f525ee49b4749ed4637b51a28b18caa26543b20f0" }, + {"alien_EU", "020aab8308d4df375a846a9e3b1c7e99597b90497efa021d50bcf1bbba23246527" }, + {"thegaltmines_NA", "031bea28bec98b6380958a493a703ddc3353d7b05eb452109a773eefd15a32e421" }, + {"titomane_AR", "029d19215440d8cb9cc6c6b7a4744ae7fb9fb18d986e371b06aeb34b64845f9325" }, + {"titomane_EU", "0360b4805d885ff596f94312eed3e4e17cb56aa8077c6dd78d905f8de89da9499f" }, // 60 + {"titomane_SH", "03573713c5b20c1e682a2e8c0f8437625b3530f278e705af9b6614de29277a435b" }, + {"webworker01_NA", "03bb7d005e052779b1586f071834c5facbb83470094cff5112f0072b64989f97d7" }, + {"xrobesx_NA", "03f0cc6d142d14a40937f12dbd99dbd9021328f45759e26f1877f2a838876709e1" }, + }, + { + {"webworker01_NA", "03bb7d005e052779b1586f071834c5facbb83470094cff5112f0072b64989f97d7" } + } +}; + #define SETBIT(bits,bitoffset) (((uint8_t *)bits)[(bitoffset) >> 3] |= (1 << ((bitoffset) & 7))) #define GETBIT(bits,bitoffset) (((uint8_t *)bits)[(bitoffset) >> 3] & (1 << ((bitoffset) & 7))) #define CLEARBIT(bits,bitoffset) (((uint8_t *)bits)[(bitoffset) >> 3] &= ~(1 << ((bitoffset) & 7))) @@ -82,7 +234,8 @@ extern int32_t VERUS_MIN_STAKEAGE; extern std::string DONATION_PUBKEY; extern uint8_t ASSETCHAINS_PRIVATE; extern int32_t USE_EXTERNAL_PUBKEY; -extern char NOTARYADDRS[64][64]; +extern char NOTARYADDRS[64][64]; // should be depreciated later. Only affects labs. +extern char NOTARY_ADDRESSES[NUM_KMD_SEASONS][64][64]; extern int32_t KOMODO_TESTNODE, KOMODO_SNAPSHOT_INTERVAL; extern int32_t ASSETCHAINS_EARLYTXIDCONTRACT; int tx_height( const uint256 &hash ); diff --git a/src/komodo_globals.h b/src/komodo_globals.h index 08c633ee7..099cddd4b 100644 --- a/src/komodo_globals.h +++ b/src/komodo_globals.h @@ -53,6 +53,7 @@ bool VERUS_MINTBLOCKS; std::vector Mineropret; std::vector vWhiteListAddress; char NOTARYADDRS[64][64]; +char NOTARY_ADDRESSES[NUM_KMD_SEASONS][64][64]; char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN],ASSETCHAINS_USERPASS[4096]; uint16_t ASSETCHAINS_P2PPORT,ASSETCHAINS_RPCPORT,ASSETCHAINS_BEAMPORT,ASSETCHAINS_CODAPORT; diff --git a/src/komodo_notary.h b/src/komodo_notary.h index 5cdbf237d..fc2a866ae 100644 --- a/src/komodo_notary.h +++ b/src/komodo_notary.h @@ -20,6 +20,7 @@ #include "notaries_staked.h" #define KOMODO_MAINNET_START 178999 +#define KOMODO_NOTARIES_HEIGHT1 814000 const char *Notaries_genesis[][2] = { @@ -60,194 +61,80 @@ const char *Notaries_genesis[][2] = { "titomane_SH", "035f49d7a308dd9a209e894321f010d21b7793461b0c89d6d9231a3fe5f68d9960" }, }; -const char *Notaries_elected0[][2] = -{ - { "0_jl777_testA", "03b7621b44118017a16043f19b30cc8a4cfe068ac4e42417bae16ba460c80f3828" }, - { "0_jl777_testB", "02ebfc784a4ba768aad88d44d1045d240d47b26e248cafaf1c5169a42d7a61d344" }, - { "0_kolo_testA", "0287aa4b73988ba26cf6565d815786caf0d2c4af704d7883d163ee89cd9977edec" }, - { "artik_AR", "029acf1dcd9f5ff9c455f8bb717d4ae0c703e089d16cf8424619c491dff5994c90" }, - { "artik_EU", "03f54b2c24f82632e3cdebe4568ba0acf487a80f8a89779173cdb78f74514847ce" }, - { "artik_NA", "0224e31f93eff0cc30eaf0b2389fbc591085c0e122c4d11862c1729d090106c842" }, - { "artik_SH", "02bdd8840a34486f38305f311c0e2ae73e84046f6e9c3dd3571e32e58339d20937" }, - { "badass_EU", "0209d48554768dd8dada988b98aca23405057ac4b5b46838a9378b95c3e79b9b9e" }, - { "badass_NA", "02afa1a9f948e1634a29dc718d218e9d150c531cfa852843a1643a02184a63c1a7" }, - { "badass_SH", "026b49dd3923b78a592c1b475f208e23698d3f085c4c3b4906a59faf659fd9530b" }, - { "crackers_EU", "03bc819982d3c6feb801ec3b720425b017d9b6ee9a40746b84422cbbf929dc73c3" }, // 10 - { "crackers_NA", "03205049103113d48c7c7af811b4c8f194dafc43a50d5313e61a22900fc1805b45" }, - { "crackers_SH", "02be28310e6312d1dd44651fd96f6a44ccc269a321f907502aae81d246fabdb03e" }, - { "durerus_EU", "02bcbd287670bdca2c31e5d50130adb5dea1b53198f18abeec7211825f47485d57" }, - { "etszombi_AR", "031c79168d15edabf17d9ec99531ea9baa20039d0cdc14d9525863b83341b210e9" }, - { "etszombi_EU", "0281b1ad28d238a2b217e0af123ce020b79e91b9b10ad65a7917216eda6fe64bf7" }, // 15 - { "etszombi_SH", "025d7a193c0757f7437fad3431f027e7b5ed6c925b77daba52a8755d24bf682dde" }, - { "farl4web_EU", "0300ecf9121cccf14cf9423e2adb5d98ce0c4e251721fa345dec2e03abeffbab3f" }, - { "farl4web_SH", "0396bb5ed3c57aa1221d7775ae0ff751e4c7dc9be220d0917fa8bbdf670586c030" }, - { "fullmoon_AR", "0254b1d64840ce9ff6bec9dd10e33beb92af5f7cee628f999cb6bc0fea833347cc" }, - { "fullmoon_NA", "031fb362323b06e165231c887836a8faadb96eda88a79ca434e28b3520b47d235b" }, // 20 - { "fullmoon_SH", "030e12b42ec33a80e12e570b6c8274ce664565b5c3da106859e96a7208b93afd0d" }, - { "grewal_NA", "03adc0834c203d172bce814df7c7a5e13dc603105e6b0adabc942d0421aefd2132" }, - { "grewal_SH", "03212a73f5d38a675ee3cdc6e82542a96c38c3d1c79d25a1ed2e42fcf6a8be4e68" }, - { "indenodes_AR", "02ec0fa5a40f47fd4a38ea5c89e375ad0b6ddf4807c99733c9c3dc15fb978ee147" }, - { "indenodes_EU", "0221387ff95c44cb52b86552e3ec118a3c311ca65b75bf807c6c07eaeb1be8303c" }, - { "indenodes_NA", "02698c6f1c9e43b66e82dbb163e8df0e5a2f62f3a7a882ca387d82f86e0b3fa988" }, - { "indenodes_SH", "0334e6e1ec8285c4b85bd6dae67e17d67d1f20e7328efad17ce6fd24ae97cdd65e" }, - { "jeezy_EU", "023cb3e593fb85c5659688528e9a4f1c4c7f19206edc7e517d20f794ba686fd6d6" }, - { "jsgalt_NA", "027b3fb6fede798cd17c30dbfb7baf9332b3f8b1c7c513f443070874c410232446" }, - { "karasugoi_NA", "02a348b03b9c1a8eac1b56f85c402b041c9bce918833f2ea16d13452309052a982" }, // 30 - { "kashifali_EU", "033777c52a0190f261c6f66bd0e2bb299d30f012dcb8bfff384103211edb8bb207" }, - { "kolo_AR", "03016d19344c45341e023b72f9fb6e6152fdcfe105f3b4f50b82a4790ff54e9dc6" }, - { "kolo_SH", "02aa24064500756d9b0959b44d5325f2391d8e95c6127e109184937152c384e185" }, - { "metaphilibert_AR", "02adad675fae12b25fdd0f57250b0caf7f795c43f346153a31fe3e72e7db1d6ac6" }, - { "movecrypto_AR", "022783d94518e4dc77cbdf1a97915b29f427d7bc15ea867900a76665d3112be6f3" }, - { "movecrypto_EU", "021ab53bc6cf2c46b8a5456759f9d608966eff87384c2b52c0ac4cc8dd51e9cc42" }, - { "movecrypto_NA", "02efb12f4d78f44b0542d1c60146738e4d5506d27ec98a469142c5c84b29de0a80" }, - { "movecrypto_SH", "031f9739a3ebd6037a967ce1582cde66e79ea9a0551c54731c59c6b80f635bc859" }, - { "muros_AR", "022d77402fd7179335da39479c829be73428b0ef33fb360a4de6890f37c2aa005e" }, - { "noashh_AR", "029d93ef78197dc93892d2a30e5a54865f41e0ca3ab7eb8e3dcbc59c8756b6e355" }, // 40 - { "noashh_EU", "02061c6278b91fd4ac5cab4401100ffa3b2d5a277e8f71db23401cc071b3665546" }, - { "noashh_NA", "033c073366152b6b01535e15dd966a3a8039169584d06e27d92a69889b720d44e1" }, - { "nxtswe_EU", "032fb104e5eaa704a38a52c126af8f67e870d70f82977e5b2f093d5c1c21ae5899" }, - { "polycryptoblog_NA", "02708dcda7c45fb54b78469673c2587bfdd126e381654819c4c23df0e00b679622" }, - { "pondsea_AR", "032e1c213787312099158f2d74a89e8240a991d162d4ce8017d8504d1d7004f735" }, - { "pondsea_EU", "0225aa6f6f19e543180b31153d9e6d55d41bc7ec2ba191fd29f19a2f973544e29d" }, - { "pondsea_NA", "031bcfdbb62268e2ff8dfffeb9ddff7fe95fca46778c77eebff9c3829dfa1bb411" }, - { "pondsea_SH", "02209073bc0943451498de57f802650311b1f12aa6deffcd893da198a544c04f36" }, - { "popcornbag_AR", "02761f106fb34fbfc5ddcc0c0aa831ed98e462a908550b280a1f7bd32c060c6fa3" }, - { "popcornbag_NA", "03c6085c7fdfff70988fda9b197371f1caf8397f1729a844790e421ee07b3a93e8" }, // 50 - { "ptytrader_NA", "0328c61467148b207400b23875234f8a825cce65b9c4c9b664f47410b8b8e3c222" }, - { "ptytrader_SH", "0250c93c492d8d5a6b565b90c22bee07c2d8701d6118c6267e99a4efd3c7748fa4" }, - { "rnr_AR", "029bdb08f931c0e98c2c4ba4ef45c8e33a34168cb2e6bf953cef335c359d77bfcd" }, - { "rnr_EU", "03f5c08dadffa0ffcafb8dd7ffc38c22887bd02702a6c9ac3440deddcf2837692b" }, - { "rnr_NA", "02e17c5f8c3c80f584ed343b8dcfa6d710dfef0889ec1e7728ce45ce559347c58c" }, - { "rnr_SH", "037536fb9bdfed10251f71543fb42679e7c52308bcd12146b2568b9a818d8b8377" }, - { "titomane_AR", "03cda6ca5c2d02db201488a54a548dbfc10533bdc275d5ea11928e8d6ab33c2185" }, - { "titomane_EU", "02e41feded94f0cc59f55f82f3c2c005d41da024e9a805b41105207ef89aa4bfbd" }, - { "titomane_SH", "035f49d7a308dd9a209e894321f010d21b7793461b0c89d6d9231a3fe5f68d9960" }, - { "vanbreuk_EU", "024f3cad7601d2399c131fd070e797d9cd8533868685ddbe515daa53c2e26004c3" }, // 60 - { "xrobesx_NA", "03f0cc6d142d14a40937f12dbd99dbd9021328f45759e26f1877f2a838876709e1" }, - { "xxspot1_XX", "02ef445a392fcaf3ad4176a5da7f43580e8056594e003eba6559a713711a27f955" }, - { "xxspot2_XX", "03d85b221ea72ebcd25373e7961f4983d12add66a92f899deaf07bab1d8b6f5573" } -}; - -#define KOMODO_NOTARIES_TIMESTAMP1 1525132800 // May 1st 2018 1530921600 // 7/7/2017 -#define KOMODO_NOTARIES_HEIGHT1 ((814000 / KOMODO_ELECTION_GAP) * KOMODO_ELECTION_GAP) - -const char *Notaries_elected1[][2] = -{ - {"0dev1_jl777", "03b7621b44118017a16043f19b30cc8a4cfe068ac4e42417bae16ba460c80f3828" }, - {"0dev2_kolo", "030f34af4b908fb8eb2099accb56b8d157d49f6cfb691baa80fdd34f385efed961" }, - {"0dev3_kolo", "025af9d2b2a05338478159e9ac84543968fd18c45fd9307866b56f33898653b014" }, - {"0dev4_decker", "028eea44a09674dda00d88ffd199a09c9b75ba9782382cc8f1e97c0fd565fe5707" }, - {"a-team_SH", "03b59ad322b17cb94080dc8e6dc10a0a865de6d47c16fb5b1a0b5f77f9507f3cce" }, - {"artik_AR", "029acf1dcd9f5ff9c455f8bb717d4ae0c703e089d16cf8424619c491dff5994c90" }, - {"artik_EU", "03f54b2c24f82632e3cdebe4568ba0acf487a80f8a89779173cdb78f74514847ce" }, - {"artik_NA", "0224e31f93eff0cc30eaf0b2389fbc591085c0e122c4d11862c1729d090106c842" }, - {"artik_SH", "02bdd8840a34486f38305f311c0e2ae73e84046f6e9c3dd3571e32e58339d20937" }, - {"badass_EU", "0209d48554768dd8dada988b98aca23405057ac4b5b46838a9378b95c3e79b9b9e" }, - {"badass_NA", "02afa1a9f948e1634a29dc718d218e9d150c531cfa852843a1643a02184a63c1a7" }, // 10 - {"batman_AR", "033ecb640ec5852f42be24c3bf33ca123fb32ced134bed6aa2ba249cf31b0f2563" }, - {"batman_SH", "02ca5898931181d0b8aafc75ef56fce9c43656c0b6c9f64306e7c8542f6207018c" }, - {"ca333_EU", "03fc87b8c804f12a6bd18efd43b0ba2828e4e38834f6b44c0bfee19f966a12ba99" }, - {"chainmakers_EU", "02f3b08938a7f8d2609d567aebc4989eeded6e2e880c058fdf092c5da82c3bc5ee" }, - {"chainmakers_NA", "0276c6d1c65abc64c8559710b8aff4b9e33787072d3dda4ec9a47b30da0725f57a" }, - {"chainstrike_SH", "0370bcf10575d8fb0291afad7bf3a76929734f888228bc49e35c5c49b336002153" }, - {"cipi_AR", "02c4f89a5b382750836cb787880d30e23502265054e1c327a5bfce67116d757ce8" }, - {"cipi_NA", "02858904a2a1a0b44df4c937b65ee1f5b66186ab87a751858cf270dee1d5031f18" }, - {"crackers_EU", "03bc819982d3c6feb801ec3b720425b017d9b6ee9a40746b84422cbbf929dc73c3" }, - {"crackers_NA", "03205049103113d48c7c7af811b4c8f194dafc43a50d5313e61a22900fc1805b45" }, // 20 - {"dwy_EU", "0259c646288580221fdf0e92dbeecaee214504fdc8bbdf4a3019d6ec18b7540424" }, - {"emmanux_SH", "033f316114d950497fc1d9348f03770cd420f14f662ab2db6172df44c389a2667a" }, - {"etszombi_EU", "0281b1ad28d238a2b217e0af123ce020b79e91b9b10ad65a7917216eda6fe64bf7" }, - {"fullmoon_AR", "03380314c4f42fa854df8c471618751879f9e8f0ff5dbabda2bd77d0f96cb35676" }, - {"fullmoon_NA", "030216211d8e2a48bae9e5d7eb3a42ca2b7aae8770979a791f883869aea2fa6eef" }, - {"fullmoon_SH", "03f34282fa57ecc7aba8afaf66c30099b5601e98dcbfd0d8a58c86c20d8b692c64" }, - {"goldenman_EU", "02d6f13a8f745921cdb811e32237bb98950af1a5952be7b3d429abd9152f8e388d" }, - {"indenodes_AR", "02ec0fa5a40f47fd4a38ea5c89e375ad0b6ddf4807c99733c9c3dc15fb978ee147" }, - {"indenodes_EU", "0221387ff95c44cb52b86552e3ec118a3c311ca65b75bf807c6c07eaeb1be8303c" }, - {"indenodes_NA", "02698c6f1c9e43b66e82dbb163e8df0e5a2f62f3a7a882ca387d82f86e0b3fa988" }, // 30 - {"indenodes_SH", "0334e6e1ec8285c4b85bd6dae67e17d67d1f20e7328efad17ce6fd24ae97cdd65e" }, - {"jackson_AR", "038ff7cfe34cb13b524e0941d5cf710beca2ffb7e05ddf15ced7d4f14fbb0a6f69" }, - {"jeezy_EU", "023cb3e593fb85c5659688528e9a4f1c4c7f19206edc7e517d20f794ba686fd6d6" }, - {"karasugoi_NA", "02a348b03b9c1a8eac1b56f85c402b041c9bce918833f2ea16d13452309052a982" }, - {"komodoninja_EU", "038e567b99806b200b267b27bbca2abf6a3e8576406df5f872e3b38d30843cd5ba" }, - {"komodoninja_SH", "033178586896915e8456ebf407b1915351a617f46984001790f0cce3d6f3ada5c2" }, - {"komodopioneers_SH", "033ace50aedf8df70035b962a805431363a61cc4e69d99d90726a2d48fb195f68c" }, - {"libscott_SH", "03301a8248d41bc5dc926088a8cf31b65e2daf49eed7eb26af4fb03aae19682b95" }, - {"lukechilds_AR", "031aa66313ee024bbee8c17915cf7d105656d0ace5b4a43a3ab5eae1e14ec02696" }, - {"madmax_AR", "03891555b4a4393d655bf76f0ad0fb74e5159a615b6925907678edc2aac5e06a75" }, // 40 - {"meshbits_AR", "02957fd48ae6cb361b8a28cdb1b8ccf5067ff68eb1f90cba7df5f7934ed8eb4b2c" }, - {"meshbits_SH", "025c6e94877515dfd7b05682b9cc2fe4a49e076efe291e54fcec3add78183c1edb" }, - {"metaphilibert_AR", "02adad675fae12b25fdd0f57250b0caf7f795c43f346153a31fe3e72e7db1d6ac6" }, - {"metaphilibert_SH", "0284af1a5ef01503e6316a2ca4abf8423a794e9fc17ac6846f042b6f4adedc3309" }, - {"patchkez_SH", "0296270f394140640f8fa15684fc11255371abb6b9f253416ea2734e34607799c4" }, - {"pbca26_NA", "0276aca53a058556c485bbb60bdc54b600efe402a8b97f0341a7c04803ce204cb5" }, - {"peer2cloud_AR", "034e5563cb885999ae1530bd66fab728e580016629e8377579493b386bf6cebb15" }, - {"peer2cloud_SH", "03396ac453b3f23e20f30d4793c5b8ab6ded6993242df4f09fd91eb9a4f8aede84" }, - {"polycryptoblog_NA", "02708dcda7c45fb54b78469673c2587bfdd126e381654819c4c23df0e00b679622" }, - {"hyper_AR", "020f2f984d522051bd5247b61b080b4374a7ab389d959408313e8062acad3266b4" }, // 50 - {"hyper_EU", "03d00cf9ceace209c59fb013e112a786ad583d7de5ca45b1e0df3b4023bb14bf51" }, - {"hyper_SH", "0383d0b37f59f4ee5e3e98a47e461c861d49d0d90c80e9e16f7e63686a2dc071f3" }, - {"hyper_NA", "03d91c43230336c0d4b769c9c940145a8c53168bf62e34d1bccd7f6cfc7e5592de" }, - {"popcornbag_AR", "02761f106fb34fbfc5ddcc0c0aa831ed98e462a908550b280a1f7bd32c060c6fa3" }, - {"popcornbag_NA", "03c6085c7fdfff70988fda9b197371f1caf8397f1729a844790e421ee07b3a93e8" }, - {"alien_AR", "0348d9b1fc6acf81290405580f525ee49b4749ed4637b51a28b18caa26543b20f0" }, - {"alien_EU", "020aab8308d4df375a846a9e3b1c7e99597b90497efa021d50bcf1bbba23246527" }, - {"thegaltmines_NA", "031bea28bec98b6380958a493a703ddc3353d7b05eb452109a773eefd15a32e421" }, - {"titomane_AR", "029d19215440d8cb9cc6c6b7a4744ae7fb9fb18d986e371b06aeb34b64845f9325" }, - {"titomane_EU", "0360b4805d885ff596f94312eed3e4e17cb56aa8077c6dd78d905f8de89da9499f" }, // 60 - {"titomane_SH", "03573713c5b20c1e682a2e8c0f8437625b3530f278e705af9b6614de29277a435b" }, - {"webworker01_NA", "03bb7d005e052779b1586f071834c5facbb83470094cff5112f0072b64989f97d7" }, - {"xrobesx_NA", "03f0cc6d142d14a40937f12dbd99dbd9021328f45759e26f1877f2a838876709e1" }, -}; #define CRYPTO777_PUBSECPSTR "020e46e79a2a8d12b9b5d12c7a91adb4e454edfae43c0a0cb805427d2ac7613fd9" +int32_t getkmdseason(int32_t height) +{ + int8_t season = 0; + if ( height <= KMD_SEASON_HEIGHTS[0] ) + return(1); + for (int32_t i = 1; i < NUM_KMD_SEASONS; i++) + { + if ( height <= KMD_SEASON_HEIGHTS[i] && height >= KMD_SEASON_HEIGHTS[i-1] ) + return(i+1); + } + return(0); +}; + +int32_t getacseason(int32_t timestamp) +{ + int8_t season = 0; + if ( timestamp <= KMD_SEASON_TIMESTAMPS[0] ) + return(1); + for (int32_t i = 1; i < NUM_KMD_SEASONS; i++) + { + if ( timestamp <= KMD_SEASON_TIMESTAMPS[i] && timestamp >= KMD_SEASON_TIMESTAMPS[i-1] ) + return(i+1); + } + return(0); +}; + int32_t komodo_notaries(uint8_t pubkeys[64][33],int32_t height,uint32_t timestamp) { - static uint8_t elected_pubkeys0[64][33],elected_pubkeys1[64][33],did0,did1; static int32_t n0,n1; int32_t i,htind,n; uint64_t mask = 0; struct knotary_entry *kp,*tmp; - + static uint8_t kmd_pubkeys[NUM_KMD_SEASONS][64][33],didinit[NUM_KMD_SEASONS]; + if ( timestamp == 0 && ASSETCHAINS_SYMBOL[0] != 0 ) timestamp = komodo_heightstamp(height); else if ( ASSETCHAINS_SYMBOL[0] == 0 ) timestamp = 0; // If this chain is not a staked chain, use the normal Komodo logic to determine notaries. This allows KMD to still sync and use its proper pubkeys for dPoW. - if (is_STAKED(ASSETCHAINS_SYMBOL) == 0) + if ( is_STAKED(ASSETCHAINS_SYMBOL) == 0 ) { - if ( height >= KOMODO_NOTARIES_HARDCODED || ASSETCHAINS_SYMBOL[0] != 0 ) - timestamp = 0; - if ( (timestamp != 0 && timestamp <= KOMODO_NOTARIES_TIMESTAMP1) || (ASSETCHAINS_SYMBOL[0] == 0 && height <= KOMODO_NOTARIES_HEIGHT1) ) + int32_t kmd_season = 0; + if ( ASSETCHAINS_SYMBOL[0] == 0 ) { - if ( did0 == 0 ) - { - n0 = (int32_t)(sizeof(Notaries_elected0)/sizeof(*Notaries_elected0)); - for (i=0; i= KOMODO_NOTARIES_HARDCODED ) + kmd_season = getkmdseason(height); } - else //if ( (timestamp != 0 && timestamp <= KOMODO_NOTARIES_TIMESTAMP2) || height <= KOMODO_NOTARIES_HEIGHT2 ) + else { - if ( did1 == 0 ) + // This is a non LABS assetchain, use timestamp to detemine notary pubkeys. + kmd_season = getacseason(timestamp); + } + if ( kmd_season != 0 ) + { + if ( didinit[kmd_season-1] == 0 ) { - n1 = (int32_t)(sizeof(Notaries_elected1)/sizeof(*Notaries_elected1)); - for (i=0; i &outVals); int8_t equihash_params_possible(uint64_t n, uint64_t k) @@ -1691,14 +1692,9 @@ int8_t equihash_params_possible(uint64_t n, uint64_t k) void komodo_args(char *argv0) { - extern const char *Notaries_elected1[][2]; std::string name,addn,hexstr,symbol; char *dirname,fname[512],arg0str[64],magicstr[9]; uint8_t magic[4],extrabuf[32756],disablebits[32],*extraptr=0; FILE *fp; uint64_t val; uint16_t port; int32_t i,nonz=0,baseid,len,n,extralen = 0; uint64_t ccenables[256]; IS_KOMODO_NOTARY = GetBoolArg("-notary", false); IS_STAKED_NOTARY = GetArg("-stakednotary", -1); - if ( IS_STAKED_NOTARY != -1 && IS_KOMODO_NOTARY == true ) { - fprintf(stderr, "Cannot be STAKED and KMD notary at the same time!\n"); - StartShutdown(); - } memset(ccenables,0,sizeof(ccenables)); memset(disablebits,0,sizeof(disablebits)); if ( GetBoolArg("-gen", false) != 0 ) @@ -1717,17 +1713,24 @@ void komodo_args(char *argv0) USE_EXTERNAL_PUBKEY = 1; if ( IS_KOMODO_NOTARY == 0 ) { + // We dont have any chain data yet, so use system clock to guess. + // I think on season change should reccomend notaries to use -notary to avoid needing this. + int32_t kmd_season = getacseason(time(NULL)); for (i=0; i<64; i++) - if ( strcmp(NOTARY_PUBKEY.c_str(),Notaries_elected1[i][1]) == 0 ) + if ( strcmp(NOTARY_PUBKEY.c_str(),notaries_elected[kmd_season][NUM_KMD_NOTARIES][1]) == 0 ) { IS_KOMODO_NOTARY = 1; KOMODO_MININGTHREADS = 1; mapArgs ["-genproclimit"] = itostr(KOMODO_MININGTHREADS); IS_STAKED_NOTARY = -1; - fprintf(stderr,"running as notary.%d %s\n",i,Notaries_elected1[i][0]); + fprintf(stderr,"running as notary.%d %s\n",i,notaries_elected[kmd_season][NUM_KMD_NOTARIES][0]); break; } } + } + if ( IS_STAKED_NOTARY != -1 && IS_KOMODO_NOTARY == true ) { + fprintf(stderr, "Cannot be STAKED and KMD notary at the same time!\n"); + StartShutdown(); } name = GetArg("-ac_name",""); if ( argv0 != 0 ) @@ -1760,7 +1763,6 @@ void komodo_args(char *argv0) } KOMODO_EARLYTXID = Parseuint256(GetArg("-earlytxid","0").c_str()); ASSETCHAINS_EARLYTXIDCONTRACT = GetArg("-ac_earlytxidcontract",0); - fprintf(stderr, "ASSETCHAINS_EARLYTXIDCONTRACT.%i\n", ASSETCHAINS_EARLYTXIDCONTRACT); if ( name.c_str()[0] != 0 ) { std::string selectedAlgo = GetArg("-ac_algo", std::string(ASSETCHAINS_ALGORITHMS[0])); diff --git a/src/main.cpp b/src/main.cpp index 609203562..961595db2 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1373,26 +1373,21 @@ bool CheckTransaction(uint32_t tiptime,const CTransaction& tx, CValidationState } } +extern int32_t getacseason(int32_t timestamp); + int32_t komodo_isnotaryvout(char *coinaddr,uint32_t tiptime) // from ac_private chains only { - static int32_t didinit; static char notaryaddrs[sizeof(Notaries_elected1)/sizeof(*Notaries_elected1) + 1][64]; - //use normal notary functions - int32_t i; - if ( didinit == 0 ) + int32_t season = getacseason(tiptime); + if ( NOTARY_ADDRESSES[season-1][0][0] == 0 ) { - uint8_t pubkey33[33]; - for (i=0; i<=sizeof(Notaries_elected1)/sizeof(*Notaries_elected1); i++) - { - if ( i < sizeof(Notaries_elected1)/sizeof(*Notaries_elected1) ) - decode_hex(pubkey33,33,(char *)Notaries_elected1[i][1]); - else decode_hex(pubkey33,33,(char *)CRYPTO777_PUBSECPSTR); - pubkey2addr((char *)notaryaddrs[i],(uint8_t *)pubkey33); - } - didinit = 1; + uint8_t pubkeys[64][33]; + komodo_notaries(pubkeys,0,tiptime); + } + for (int32_t i = 0; i < NUM_KMD_NOTARIES; i++) + { + if ( strcmp(coinaddr,NOTARY_ADDRESSES[season-1][i]) == 0 ) + return(1); } - for (i=0; i<=sizeof(Notaries_elected1)/sizeof(*Notaries_elected1); i++) - if ( strcmp(coinaddr,notaryaddrs[i]) == 0 ) - return(1); return(0); } From 02a3f08894fef4487f569739d318d423496c38db Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Sat, 18 May 2019 23:38:49 +0800 Subject: [PATCH 297/447] fix staking wallet fix. --- src/wallet/wallet.cpp | 2 +- src/wallet/walletdb.cpp | 9 ++++----- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index fa39d204a..085f63013 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -2896,7 +2896,7 @@ bool CWalletTx::RelayWalletTransaction() { if ( pwallet == 0 ) { - fprintf(stderr,"unexpected null pwallet in RelayWalletTransaction\n"); + //fprintf(stderr,"unexpected null pwallet in RelayWalletTransaction\n"); return(false); } assert(pwallet->GetBroadcastTransactions()); diff --git a/src/wallet/walletdb.cpp b/src/wallet/walletdb.cpp index efba38d9e..29651adf9 100644 --- a/src/wallet/walletdb.cpp +++ b/src/wallet/walletdb.cpp @@ -964,21 +964,20 @@ DBErrors CWalletDB::LoadWallet(CWallet* pwallet) // staking chains with vin-empty error is a failed staking tx. // we remove then re add the tx here to stop needing a full rescan, which does not actually fix the problem. int32_t reAdded = 0; - CWalletDB walletdb(pwallet->strWalletFile, "r+", false); BOOST_FOREACH (uint256& hash, deadTxns) { - fprintf(stderr, "Removing corrupt tx from wallet.%s\n", hash.ToString().c_str()); + fprintf(stderr, "Removing possible orphaned staking transaction from wallet.%s\n", hash.ToString().c_str()); if (!EraseTx(hash)) fprintf(stderr, "could not delete tx.%s\n",hash.ToString().c_str()); uint256 blockhash; CTransaction tx; - if (GetTransaction(hash,tx,blockhash,true)) + if ( GetTransaction(hash,tx,blockhash,false) && mapBlockIndex.find(blockhash) != mapBlockIndex.end() ) { CWalletTx wtx(pwallet,tx); - pwallet->AddToWallet(wtx, false, &walletdb); + pwallet->AddToWallet(wtx, true, NULL); reAdded++; } } - fprintf(stderr, "Cleared %li corrupted transactions from wallet. Readded %i known transactions.\n",deadTxns.size(),reAdded); + fprintf(stderr, "Cleared %li orphaned staking transactions from wallet. Readded %i real transactions.\n",deadTxns.size(),reAdded); fNoncriticalErrors = false; deadTxns.clear(); } From c0bc4dc7f82d674597cd803a95f868861c9486e9 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Sun, 19 May 2019 00:16:31 +0800 Subject: [PATCH 298/447] fix erase expired tx on wallet load --- src/wallet/wallet.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 085f63013..046253ce0 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -2874,9 +2874,9 @@ void CWallet::ReacceptWalletTransactions() bool invalid = state.IsInvalid(nDoS); // log rejection and deletion - // printf("ERROR reaccepting wallet transaction %s to mempool, reason: %s, DoS: %d\n", wtx.GetHash().ToString().c_str(), state.GetRejectReason().c_str(), nDoS); + //printf("ERROR reaccepting wallet transaction %s to mempool, reason: %s, DoS: %d\n", wtx.GetHash().ToString().c_str(), state.GetRejectReason().c_str(), nDoS); - if (!wtx.IsCoinBase() && invalid && nDoS > 0) + if (!wtx.IsCoinBase() && invalid && nDoS > 0 && state.GetRejectReason() != "tx-overwinter-expired") { LogPrintf("erasing transaction %s\n", wtx.GetHash().GetHex().c_str()); vwtxh.push_back(wtx.GetHash()); From d4aac39f7574dcab77698db467eeff683ec83dda Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Sun, 19 May 2019 00:21:36 +0800 Subject: [PATCH 299/447] fix erase expired tx on wallet load --- src/wallet/wallet.cpp | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 085f63013..4d834ccee 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -2874,21 +2874,18 @@ void CWallet::ReacceptWalletTransactions() bool invalid = state.IsInvalid(nDoS); // log rejection and deletion - // printf("ERROR reaccepting wallet transaction %s to mempool, reason: %s, DoS: %d\n", wtx.GetHash().ToString().c_str(), state.GetRejectReason().c_str(), nDoS); + //printf("ERROR reaccepting wallet transaction %s to mempool, reason: %s, DoS: %d\n", wtx.GetHash().ToString().c_str(), state.GetRejectReason().c_str(), nDoS); - if (!wtx.IsCoinBase() && invalid && nDoS > 0) + if (!wtx.IsCoinBase() && invalid && nDoS > 0 && state.GetRejectReason() != "tx-overwinter-expired") { LogPrintf("erasing transaction %s\n", wtx.GetHash().GetHex().c_str()); vwtxh.push_back(wtx.GetHash()); } } } - if ( IsInitialBlockDownload() == 0 ) + for (auto hash : vwtxh) { - for (auto hash : vwtxh) - { - EraseFromWallet(hash); - } + EraseFromWallet(hash); } } From e90ac44dde1a32fe7e02a993be6da9c3cd2ac13c Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Sun, 19 May 2019 00:48:24 +0800 Subject: [PATCH 300/447] try fix --- src/wallet/walletdb.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/wallet/walletdb.cpp b/src/wallet/walletdb.cpp index 29651adf9..e81eba03d 100644 --- a/src/wallet/walletdb.cpp +++ b/src/wallet/walletdb.cpp @@ -41,6 +41,7 @@ using namespace std; static uint64_t nAccountingEntryNumber = 0; static list deadTxns; +extern CBlockIndex *komodo_blockindex(uint256 hash); // // CWalletDB @@ -969,8 +970,8 @@ DBErrors CWalletDB::LoadWallet(CWallet* pwallet) fprintf(stderr, "Removing possible orphaned staking transaction from wallet.%s\n", hash.ToString().c_str()); if (!EraseTx(hash)) fprintf(stderr, "could not delete tx.%s\n",hash.ToString().c_str()); - uint256 blockhash; CTransaction tx; - if ( GetTransaction(hash,tx,blockhash,false) && mapBlockIndex.find(blockhash) != mapBlockIndex.end() ) + uint256 blockhash; CTransaction tx; CBlockIndex* pindex; + if ( GetTransaction(hash,tx,blockhash,false) && (pindex= komodo_blockindex(blockhash)) != 0 && chainActive.Contains(pindex) ) { CWalletTx wtx(pwallet,tx); pwallet->AddToWallet(wtx, true, NULL); From c39133405ed5a4ca965d33394849a0d5ac3a0684 Mon Sep 17 00:00:00 2001 From: Alrighttt Date: Sun, 19 May 2019 23:04:18 +0200 Subject: [PATCH 301/447] change oraclessamples to obj --- src/cc/oracles.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/cc/oracles.cpp b/src/cc/oracles.cpp index a5d61d404..febc82c20 100644 --- a/src/cc/oracles.cpp +++ b/src/cc/oracles.cpp @@ -954,9 +954,10 @@ UniValue OracleDataSamples(uint256 reforacletxid,uint256 batontxid,int32_t num) { if ( (formatstr= (char *)format.c_str()) == 0 ) formatstr = (char *)""; - UniValue a(UniValue::VARR); - a.push_back(OracleFormat((uint8_t *)data.data(),(int32_t)data.size(),formatstr,(int32_t)format.size())); - a.push_back(uint256_str(str,batontxid)); + UniValue a(UniValue::VOBJ); + a.push_back(Pair("data",OracleFormat((uint8_t *)data.data(),(int32_t)data.size(),formatstr,(int32_t)format.size()))); + a.push_back(Pair("txid",uint256_str(str,batontxid))); + fprintf(stderr,"blahblahblahb.%s", uint256_str(str,batontxid)); b.push_back(a); batontxid = btxid; if ( ++n >= num && num != 0) From 5c77b99a66dc1305adcc9c02bb335695c21f457f Mon Sep 17 00:00:00 2001 From: Alrighttt Date: Sun, 19 May 2019 23:10:20 +0200 Subject: [PATCH 302/447] remove print, remove unused obj --- src/cc/oracles.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/cc/oracles.cpp b/src/cc/oracles.cpp index febc82c20..7cd429182 100644 --- a/src/cc/oracles.cpp +++ b/src/cc/oracles.cpp @@ -924,14 +924,13 @@ std::string OracleData(int64_t txfee,uint256 oracletxid,std::vector da UniValue OracleFormat(uint8_t *data,int32_t datalen,char *format,int32_t formatlen) { - UniValue obj(UniValue::VARR); uint256 hash; int32_t i,j=0; int64_t val; char str[IGUANA_MAXSCRIPTSIZE*2+1]; + uint256 hash; int32_t i,j=0; int64_t val; char str[IGUANA_MAXSCRIPTSIZE*2+1]; for (i=0; i= datalen ) break; } @@ -957,7 +956,6 @@ UniValue OracleDataSamples(uint256 reforacletxid,uint256 batontxid,int32_t num) UniValue a(UniValue::VOBJ); a.push_back(Pair("data",OracleFormat((uint8_t *)data.data(),(int32_t)data.size(),formatstr,(int32_t)format.size()))); a.push_back(Pair("txid",uint256_str(str,batontxid))); - fprintf(stderr,"blahblahblahb.%s", uint256_str(str,batontxid)); b.push_back(a); batontxid = btxid; if ( ++n >= num && num != 0) From 8dd6f2ae96ad0bddd68b8bcc71c1da162504a49c Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 19 May 2019 11:29:45 -1100 Subject: [PATCH 303/447] Default bind --- src/komodo_utils.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 857dfe4c8..25f63feef 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1425,7 +1425,7 @@ void komodo_configfile(char *symbol,uint16_t rpcport) #ifndef FROM_CLI if ( (fp= fopen(fname,"wb")) != 0 ) { - fprintf(fp,"rpcuser=user%u\nrpcpassword=pass%s\nrpcport=%u\nserver=1\ntxindex=1\nrpcworkqueue=256\nrpcallowip=127.0.0.1\n",crc,password,rpcport); + fprintf(fp,"rpcuser=user%u\nrpcpassword=pass%s\nrpcport=%u\nserver=1\ntxindex=1\nrpcworkqueue=256\nrpcallowip=127.0.0.1\nrpcbind=127.0.0.1\n",crc,password,rpcport); fclose(fp); printf("Created (%s)\n",fname); } else printf("Couldnt create (%s)\n",fname); From 98418663807eed79f6b43c2dfed28002a1df5127 Mon Sep 17 00:00:00 2001 From: Jorian Date: Mon, 20 May 2019 12:05:09 +0200 Subject: [PATCH 304/447] add K64 --- src/ac/k64 | 2 ++ src/assetchains.json | 7 +++++++ src/assetchains.old | 1 + src/fiat/k64 | 2 ++ 4 files changed, 12 insertions(+) create mode 100755 src/ac/k64 create mode 100755 src/fiat/k64 diff --git a/src/ac/k64 b/src/ac/k64 new file mode 100755 index 000000000..a3b3bc835 --- /dev/null +++ b/src/ac/k64 @@ -0,0 +1,2 @@ +#!/bin/bash +./komodo-cli -ac_name=K64 $1 $2 $3 $4 $5 $6 diff --git a/src/assetchains.json b/src/assetchains.json index 683b791ad..54814245e 100644 --- a/src/assetchains.json +++ b/src/assetchains.json @@ -273,5 +273,12 @@ "195.201.20.230", "80.240.17.222" ] + }, + { + "ac_name": "K64", + "ac_reward": "0", + "ac_supply": "64000777", + "ac_staked": "10", + "addnode": ["18.197.20.21"] } ] diff --git a/src/assetchains.old b/src/assetchains.old index 424d411ca..664df7e0a 100755 --- a/src/assetchains.old +++ b/src/assetchains.old @@ -51,3 +51,4 @@ echo $pubkey ./komodod -pubkey=$pubkey -ac_name=VOTE2019 -ac_supply=123651638 -ac_public=1 -addnode=95.213.238.98 & ./komodod -pubkey=$pubkey -ac_name=KOIN -ac_supply=125000000 -addnode=3.0.32.10 & ./komodod -pubkey=$pubkey -ac_name=ZEXO -ac_supply=100000000 -ac_reward=1478310502 -ac_halving=525600 -ac_cc=42 -ac_ccenable=236 -ac_perc=77700 -ac_staked=93 -ac_pubkey=02713bd85e054db923694b6b7a85306264edf4d6bd6d331814f2b40af444b3ebbc -ac_public=1 -addnode=80.240.17.222 & +./komodod -pubkey=$pubkey -ac_name=K64 -ac_supply=64000777 -ac_reward=0 -ac_staked=10 -addnode=18.197.20.211 & diff --git a/src/fiat/k64 b/src/fiat/k64 new file mode 100755 index 000000000..a3b3bc835 --- /dev/null +++ b/src/fiat/k64 @@ -0,0 +1,2 @@ +#!/bin/bash +./komodo-cli -ac_name=K64 $1 $2 $3 $4 $5 $6 From 6c065384d182aba1a5dff63f7b55ec2d89a5ed3e Mon Sep 17 00:00:00 2001 From: Jorian Date: Mon, 20 May 2019 12:05:09 +0200 Subject: [PATCH 305/447] add K64 --- src/ac/k64 | 2 ++ src/assetchains.json | 7 +++++++ src/assetchains.old | 1 + src/fiat/k64 | 2 ++ 4 files changed, 12 insertions(+) create mode 100755 src/ac/k64 create mode 100755 src/fiat/k64 diff --git a/src/ac/k64 b/src/ac/k64 new file mode 100755 index 000000000..a3b3bc835 --- /dev/null +++ b/src/ac/k64 @@ -0,0 +1,2 @@ +#!/bin/bash +./komodo-cli -ac_name=K64 $1 $2 $3 $4 $5 $6 diff --git a/src/assetchains.json b/src/assetchains.json index cfed51981..86dc77565 100644 --- a/src/assetchains.json +++ b/src/assetchains.json @@ -261,5 +261,12 @@ "195.201.20.230", "80.240.17.222" ] + }, + { + "ac_name": "K64", + "ac_reward": "0", + "ac_supply": "64000777", + "ac_staked": "10", + "addnode": ["18.197.20.21"] } ] diff --git a/src/assetchains.old b/src/assetchains.old index f6b4d008b..4cf427c4d 100755 --- a/src/assetchains.old +++ b/src/assetchains.old @@ -51,3 +51,4 @@ echo $pubkey ./komodod -pubkey=$pubkey -ac_name=VOTE2019 -ac_supply=123651638 -ac_public=1 -addnode=95.213.238.98 & ./komodod -pubkey=$pubkey -ac_name=KOIN -ac_supply=125000000 -addnode=3.0.32.10 & ./komodod -pubkey=$pubkey -ac_name=ZEXO -ac_supply=100000000 -ac_reward=1478310502 -ac_halving=525600 -ac_cc=42 -ac_ccenable=236 -ac_perc=77700 -ac_staked=93 -ac_pubkey=02713bd85e054db923694b6b7a85306264edf4d6bd6d331814f2b40af444b3ebbc -ac_public=1 -addnode=80.240.17.222 & +./komodod -pubkey=$pubkey -ac_name=K64 -ac_supply=64000777 -ac_reward=0 -ac_staked=10 -addnode=18.197.20.211 & diff --git a/src/fiat/k64 b/src/fiat/k64 new file mode 100755 index 000000000..a3b3bc835 --- /dev/null +++ b/src/fiat/k64 @@ -0,0 +1,2 @@ +#!/bin/bash +./komodo-cli -ac_name=K64 $1 $2 $3 $4 $5 $6 From 406d6e60a23d2c622e3ca608d42202026fbd6b3b Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Mon, 20 May 2019 06:49:22 -0700 Subject: [PATCH 306/447] Wait to look at KOMODO_INSYNC until we hold cs_main lock, to prevent a datarace when using chainActive --- src/wallet/rpcwallet.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index ccefc0077..d63a387b2 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4249,10 +4249,10 @@ UniValue z_sendmany(const UniValue& params, bool fHelp) + HelpExampleRpc("z_sendmany", "\"RD6GgnrMpPaTSMn8vai6yiGA7mN4QGPV\", [{\"address\": \"zs14d8tc0hl9q0vg5l28uec5vk6sk34fkj2n8s7jalvw5fxpy6v39yn4s2ga082lymrkjk0x2nqg37\" ,\"amount\": 5.0}]") ); - THROW_IF_SYNCING(KOMODO_INSYNC); - LOCK2(cs_main, pwalletMain->cs_wallet); + THROW_IF_SYNCING(KOMODO_INSYNC); + // Check that the from address is valid. auto fromaddress = params[0].get_str(); bool fromTaddr = false; @@ -4560,10 +4560,10 @@ UniValue z_shieldcoinbase(const UniValue& params, bool fHelp) + HelpExampleRpc("z_shieldcoinbase", "\"RD6GgnrMpPaTSMn8vai6yiGA7mN4QGPV\", \"zs14d8tc0hl9q0vg5l28uec5vk6sk34fkj2n8s7jalvw5fxpy6v39yn4s2ga082lymrkjk0x2nqg37\"") ); - THROW_IF_SYNCING(KOMODO_INSYNC); - LOCK2(cs_main, pwalletMain->cs_wallet); + THROW_IF_SYNCING(KOMODO_INSYNC); + // Validate the from address auto fromaddress = params[0].get_str(); bool isFromWildcard = fromaddress == "*"; @@ -4822,10 +4822,10 @@ UniValue z_mergetoaddress(const UniValue& params, bool fHelp) throw JSONRPCError(RPC_WALLET_ERROR, "Error: z_mergetoaddress is disabled."); } - THROW_IF_SYNCING(KOMODO_INSYNC); - LOCK2(cs_main, pwalletMain->cs_wallet); + THROW_IF_SYNCING(KOMODO_INSYNC); + bool useAnyUTXO = false; bool useAnySprout = false; bool useAnySapling = false; From d5eea5669e77514a5d1673811c9c59070cd2f4df Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 20 May 2019 22:18:55 +0800 Subject: [PATCH 307/447] fix PIRATE --- src/komodo_notary.h | 2 +- src/main.cpp | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/komodo_notary.h b/src/komodo_notary.h index fc2a866ae..e2c7dfb4c 100644 --- a/src/komodo_notary.h +++ b/src/komodo_notary.h @@ -124,7 +124,7 @@ int32_t komodo_notaries(uint8_t pubkeys[64][33],int32_t height,uint32_t timestam { // this is PIRATE, we need to populate the address array for the notary exemptions. for (i = 0; i Date: Tue, 21 May 2019 10:23:23 +0530 Subject: [PATCH 308/447] Update pubkey --- src/notaries_staked.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/notaries_staked.h b/src/notaries_staked.h index fb6051b2b..b5a9e9430 100644 --- a/src/notaries_staked.h +++ b/src/notaries_staked.h @@ -44,7 +44,7 @@ static const char *notaries_STAKED[NUM_STAKED_ERAS][64][2] = {"Bar_F1sh_Rel", "0395f2d9dd9ccb78caf74bff49b6d959afb95af746462e1b35f4a167d8e82b3666" }, // RBbLxJagCA9QHDazQvfnDZe874V1K4Gu8t {"zatJUM", "030fff499b6dc0215344b28a0b6b4becdfb00cd34cd1b36b983ec14f47965fd4bc" }, // RSoEDLBasth7anxS8gbkg6KgeGiz8rhqv1 {"dwy", "03669457b2934d98b5761121dd01b243aed336479625b293be9f8c43a6ae7aaeff" }, // RKhZMqRF361FSGFAzstP5AhozekPjoVh5q - {"gcharang", "03336ca9db27cb6e882830e20dc525884e27dc94d557a5e68b972a5cbf9e8c62a8" }, // RJYiWn3FRCSSLf9Pe5RJcbrKQYosaMburP + {"gcharang", "021569dd350d99e685a739c5b36bd01f217efb4f448a6f9a56da80c5edf6ce20ee" }, // RE8SsNwhYoygXJSvw9DuQbJicDc28dwR78 {"computergenie", "027313dabde94fb72f823231d0a1c59fc7baa2e5b3bb2af97ca7d70aae116026b9" }, // RLabsCGxTRqJcJvz6foKuXAB61puJ2x8yt {"daemonfox", "0383484bdc745b2b953c85b5a0c496a1f27bc42ae971f15779ed1532421b3dd943" }, // {"SHossain", "02791f5c215b8a19c143a98e3371ff03b5613df9ac430c4a331ca55fed5761c800" }, // RKdLoHkyeorXmMtj91B1AAnAGiwsdt9MdF From 1f7f5aace0c628b8291e6b0f89eeb0cd6ee1c559 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Tue, 21 May 2019 13:23:13 +0800 Subject: [PATCH 309/447] disable tokens funcID for now. --- src/cc/payments.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/cc/payments.cpp b/src/cc/payments.cpp index ecdeb3e75..b6e85480c 100644 --- a/src/cc/payments.cpp +++ b/src/cc/payments.cpp @@ -406,6 +406,7 @@ bool PaymentsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction & { // token snapshot // payments_gettokenallocations(top, bottom, excludeScriptPubKeys, tokenid, mpzTotalAllocations, scriptPubKeys, allocations); + return(eval->Invalid("tokens not yet implemented")); } } // sanity check to make sure we got all the required info, skip for merge type tx @@ -519,8 +520,8 @@ bool PaymentsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction & else if ( i == dust+1 ) return(eval->Invalid("cannot merge only dust")); } - } else return(eval->Invalid("create transaction cannot decode")); - } else return(eval->Invalid("Could not get contract transaction")); + } else return(eval->Invalid("cannot decode create transaction")); + } else return(eval->Invalid("could not get contract transaction")); return(true); } // end of consensus code @@ -1102,7 +1103,7 @@ UniValue PaymentsTxidopret(struct CCcontract_info *cp,char *jsonstr) rawtx = FinalizeCCTx(0,cp,mtx,mypk,PAYMENTS_TXFEE,EncodePaymentsTxidOpRet(allocation,scriptPubKey,opret)); if ( params != 0 ) free_json(params); - return(payments_rawtxresult(result,rawtx,0)); + return(payments_rawtxresult(result,rawtx,1)); } result.push_back(Pair("result","error")); result.push_back(Pair("error","invalid params or cant find txfee")); @@ -1291,7 +1292,8 @@ UniValue PaymentsAirdropTokens(struct CCcontract_info *cp,char *jsonstr) uint256 hashBlock, tokenid = zeroid; CTransaction tx; CPubKey Paymentspk,mypk; char markeraddr[64]; std::string rawtx; int32_t lockedblocks,minrelease,top,bottom,n,i,minimum=10000; std::vector> excludeScriptPubKeys; int8_t fixedAmount; cJSON *params = payments_reparse(&n,jsonstr); - if ( params != 0 && n >= 6 ) + // disable for now. Need token snapshot function. + if ( 0 ) //params != 0 && n >= 6 ) { tokenid = payments_juint256(jitem(params,0)); lockedblocks = juint(jitem(params,1),0); @@ -1358,7 +1360,8 @@ UniValue PaymentsAirdropTokens(struct CCcontract_info *cp,char *jsonstr) else { result.push_back(Pair("result","error")); - result.push_back(Pair("error","parameters error")); + //result.push_back(Pair("error","parameters error")); + result.push_back(Pair("error","tokens airdrop not yet impmlemented")); } if ( params != 0 ) free_json(params); From 26a7bbdf392a767029f7d2eec8375cb5c4574f76 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Tue, 21 May 2019 13:57:13 +0800 Subject: [PATCH 310/447] revert labs build changes --- src/cc/makecclib | 2 +- src/main.cpp | 7 +++++-- src/wallet/db.h | 4 ++-- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/cc/makecclib b/src/cc/makecclib index e9a015e2f..5241ea675 100755 --- a/src/cc/makecclib +++ b/src/cc/makecclib @@ -7,7 +7,7 @@ make -f Makefile_rogue rm ../libcc.so cp librogue.so ../libcc.so -exit 0 +#exit 0 echo sudoku/musig/dilithium gcc -O3 -std=c++11 -I../secp256k1/include -I../univalue/include -I../cryptoconditions/include -I../cryptoconditions/src -I../cryptoconditions/src/asn -I.. -I. -fPIC -shared -c -o sudokucc.so cclib.cpp diff --git a/src/main.cpp b/src/main.cpp index db9c7b32f..8322e9abb 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3104,7 +3104,7 @@ bool DisconnectBlock(CBlock& block, CValidationState& state, CBlockIndex* pindex *pfClean = false; bool fClean = true; - komodo_disconnect(pindex,block); + //komodo_disconnect(pindex,block); does nothing? CBlockUndo blockUndo; CDiskBlockPos pos = pindex->GetUndoPos(); if (pos.IsNull()) @@ -4266,7 +4266,10 @@ bool static ConnectTip(CValidationState &state, CBlockIndex *pindexNew, CBlock * { uint64_t start = time(NULL); if ( !komodo_dailysnapshot(pindexNew->GetHeight()) ) - fprintf(stderr, "daily snapshot failed, please reindex your chain\n"); // maybe force shutdown here? + { + fprintf(stderr, "daily snapshot failed, please reindex your chain\n"); + StartShutdown(); + } fprintf(stderr, "snapshot completed in: %lu seconds\n", time(NULL)-start); } return true; diff --git a/src/wallet/db.h b/src/wallet/db.h index 604ae1633..e1ae52909 100644 --- a/src/wallet/db.h +++ b/src/wallet/db.h @@ -34,8 +34,8 @@ #include // If CCLIB fails to compile with this, use the one below. -//include -#include "../depends/x86_64-unknown-linux-gnu/include/db_cxx.h" +#include +//#include "../depends/x86_64-unknown-linux-gnu/include/db_cxx.h" extern unsigned int nWalletDBUpdated; From f7e5eb44f2d88971907ac97ab3c062889af068fa Mon Sep 17 00:00:00 2001 From: smk762 <35845239+smk762@users.noreply.github.com> Date: Tue, 21 May 2019 18:28:01 +0800 Subject: [PATCH 311/447] updated addr and pubkey --- src/notaries_staked.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/notaries_staked.h b/src/notaries_staked.h index fb6051b2b..28acfd59e 100644 --- a/src/notaries_staked.h +++ b/src/notaries_staked.h @@ -34,7 +34,7 @@ static const char *notaries_STAKED[NUM_STAKED_ERAS][64][2] = {"alright", "0285657c689b903218c97f5f10fe1d10ace2ed6595112d9017f54fb42ea1c1dda8" }, //RXmXeQ8LfJK6Y1aTM97cRz9Gu5f6fmR3sg {"webworker01", "031d1fb39ae4dca28965c3abdbd21faa0f685f6d7b87a60561afa7c448343fef6d" }, //RGsQiArk5sTmjXZV9UzGMW5njyvtSnsTN8 {"CrisF", "024d19acf0d5de212cdd50326cd143292545d366a71b2b9c6df9f2110de2dfa1f2" }, // RKtAD2kyRRMx4EiG1eeTNprF5h2nmGbzzu - {"smk762", "029f6c1f38c4d6825acb3b4b5147f7992e943b617cdaa0f4f5f36187e239d52d5a" }, // RPy6Xj2LWrxNoEW9YyREDgBZDZZ5qURXBU + {"smk762", "02381616fbc02d3f0398c912fe7b7daf2f3f29e55dc35287f686b15686d8135a9f" }, // RSchwBApVquaG6mXH31bQ6P83kMN4Hound {"jorian", "0288e682c1ac449f1b85c4acb2d0bcd216d5df34c15fd18b8a8dd5fa64b8ece8ef" }, // RR1yT5aB19VwFoUCGTW4q4pk4qmhHEEE4t {"TonyL", "021a559101e355c907d9c553671044d619769a6e71d624f68bfec7d0afa6bd6a96" }, // RHq3JsvLxU45Z8ufYS6RsDpSG4wi6ucDev {"CHMEX", "03ed125d1beb118d12ff0a052bdb0cee32591386d718309b2924f2c36b4e7388e6" }, // RF4HiVeuYpaznRPs7fkRAKKYqT5tuxQQTL From 6d45a1d6ee40c5c7788f3d0cff915ef09d60ae9d Mon Sep 17 00:00:00 2001 From: gtmatcha <49026247+gtmatcha@users.noreply.github.com> Date: Wed, 22 May 2019 12:13:32 +0900 Subject: [PATCH 312/447] update pub --- src/notaries_staked.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/notaries_staked.h b/src/notaries_staked.h index fb6051b2b..f67e0fddd 100644 --- a/src/notaries_staked.h +++ b/src/notaries_staked.h @@ -39,7 +39,7 @@ static const char *notaries_STAKED[NUM_STAKED_ERAS][64][2] = {"TonyL", "021a559101e355c907d9c553671044d619769a6e71d624f68bfec7d0afa6bd6a96" }, // RHq3JsvLxU45Z8ufYS6RsDpSG4wi6ucDev {"CHMEX", "03ed125d1beb118d12ff0a052bdb0cee32591386d718309b2924f2c36b4e7388e6" }, // RF4HiVeuYpaznRPs7fkRAKKYqT5tuxQQTL {"metaphilibert", "0344182c376f054e3755d712361672138660bda8005abb64067eb5aa98bdb40d10" }, // RG28QSnYFADBg1dAVkH1uPGYS6F8ioEUM2 - {"greentea", "02054c14ae81838a063d22a75eaa3c961415f6825a57c8b8e4148d19dad64f128e" }, // REF7R76WpL1v7nSXjjiNHtRa2xYtq5qk1p + {"gt", "02312dcecb6e4a32927a075972d3c009f3c68635d8100562cc1813ea66751b9fde" }, // RCg4tzKWQ7i3wrZEU8bvCbCQ4xRJnHnyoo {"CMaurice", "025830ce81bd1301fb67d5872344efa7a9ff99ae85fe1234f18c085db9072b740f" }, // RX7pXUaV24xFn6DVKV8t3PrRF3gKw6TBjf {"Bar_F1sh_Rel", "0395f2d9dd9ccb78caf74bff49b6d959afb95af746462e1b35f4a167d8e82b3666" }, // RBbLxJagCA9QHDazQvfnDZe874V1K4Gu8t {"zatJUM", "030fff499b6dc0215344b28a0b6b4becdfb00cd34cd1b36b983ec14f47965fd4bc" }, // RSoEDLBasth7anxS8gbkg6KgeGiz8rhqv1 From 7347ab98ae58706828d3f95ebb199faae6711494 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 21 May 2019 19:22:23 -1100 Subject: [PATCH 313/447] Activation on jul 15/1444000 --- src/komodo_defs.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/komodo_defs.h b/src/komodo_defs.h index cae024390..cf15f0b19 100644 --- a/src/komodo_defs.h +++ b/src/komodo_defs.h @@ -33,15 +33,15 @@ // KMD Notary Seasons // 1: May 1st 2018 1530921600 -// 2: July 1st 2019 1561939200 -// 3: 3rd season ending isnt known, so use very far times in future. +// 2: July 15th 2019 1563148800 -> estimated height 1444000 +// 3: 3rd season ending isnt known, so use very far times in future. // 1751328000 = dummy timestamp, 1 July 2025! // 7113400 = 5x current KMD blockheight. // to add 4th season, change NUM_KMD_SEASONS to 4, and add timestamp and height of activation to these arrays. #define NUM_KMD_SEASONS 3 #define NUM_KMD_NOTARIES 64 -static const uint32_t KMD_SEASON_TIMESTAMPS[NUM_KMD_SEASONS] = {1525132800, 1561939200, 1751328000}; -static const int32_t KMD_SEASON_HEIGHTS[NUM_KMD_SEASONS] = {814000, 1422680, 7113400}; +static const uint32_t KMD_SEASON_TIMESTAMPS[NUM_KMD_SEASONS] = {1525132800, 1563148800, 1751328000}; +static const int32_t KMD_SEASON_HEIGHTS[NUM_KMD_SEASONS] = {814000, 1444000, 7113400}; // Era array of pubkeys. Add extra seasons to bottom as requried, after adding appropriate info above. static const char *notaries_elected[NUM_KMD_SEASONS][NUM_KMD_NOTARIES][2] = From 563a08be81ddef6c97ef5792c0bf3be6569e4020 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Thu, 23 May 2019 13:55:01 +0800 Subject: [PATCH 314/447] undo --- src/rpc/mining.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/rpc/mining.cpp b/src/rpc/mining.cpp index 21ae07810..c95d7b891 100644 --- a/src/rpc/mining.cpp +++ b/src/rpc/mining.cpp @@ -1051,6 +1051,7 @@ UniValue getblocksubsidy(const UniValue& params, bool fHelp) return result; } + static const CRPCCommand commands[] = { // category name actor (function) okSafeMode // --------------------- ------------------------ ----------------------- ---------- From 581b6411d63fecf83c97b30e5264774b2c3accb1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 22 May 2019 21:56:58 -1100 Subject: [PATCH 315/447] Ignore a.out --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 6cebf87fe..d139071e0 100644 --- a/.gitignore +++ b/.gitignore @@ -155,3 +155,5 @@ src/rogue.scr src/cc/rogue/confdefs.h src/cc/rogue/x64 + +src/cc/dapps/a.out From 373b02e03f2bc67179262c39219b0a5fa5b69f0e Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 25 Jan 2019 17:14:15 -1100 Subject: [PATCH 316/447] Adjust for network header --- src/net.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/net.h b/src/net.h index 02714e20f..996dcd2b2 100644 --- a/src/net.h +++ b/src/net.h @@ -48,7 +48,7 @@ static const unsigned int MAX_INV_SZ = 50000; /** The maximum number of new addresses to accumulate before announcing. */ static const unsigned int MAX_ADDR_TO_SEND = 1000; /** Maximum length of incoming protocol messages (no message over 2 MiB is currently acceptable). */ -static const unsigned int MAX_PROTOCOL_MESSAGE_LENGTH = 4 * 1024 * 1024; +static const unsigned int MAX_PROTOCOL_MESSAGE_LENGTH = 4 * 1024 * 1024 + 24; /** Maximum length of strSubVer in `version` message */ static const unsigned int MAX_SUBVERSION_LENGTH = 256; /** -listen default */ From cf81bdb5f6dbe6441d31526b6c0fcc9bc3d18396 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 22 May 2019 21:59:50 -1100 Subject: [PATCH 317/447] Ignores --- .gitignore | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/.gitignore b/.gitignore index cd2641c22..59269eb37 100644 --- a/.gitignore +++ b/.gitignore @@ -126,3 +126,21 @@ src/komodo-tx.exe src/cryptoconditions/compile + +src/cc/dapps/a.out + +src/checkfile + +src/foo.zip + +src/log + +src/rogue.530623577502174316.0 + +src/rogue.530623577502174316.pack + +src/rogue.530623577502174316.player + +src/ROGUE.conf + +src/rogue.scr From 4d72ae985a6d2e7a8d0ddae9b3733cc6ef92713e Mon Sep 17 00:00:00 2001 From: dimxy Date: Wed, 8 May 2019 15:10:28 +0500 Subject: [PATCH 318/447] added totals to PriceGetOrderbook --- src/cc/prices.cpp | 94 ++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 85 insertions(+), 9 deletions(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 2116f2e8e..3ac334109 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -62,6 +62,7 @@ typedef struct OneBetData { } onebetdata; typedef struct BetInfo { + uint256 txid; int64_t averageCostbasis, firstprice, lastprice, liquidationprice, equity; int64_t rektfee; int32_t lastheight; @@ -69,7 +70,7 @@ typedef struct BetInfo { bool isOpen, isRekt; uint256 tokenid; - std::vector parsed; + std::vector vecparsed; std::vector bets; CPubKey pk; @@ -1599,13 +1600,13 @@ int32_t prices_getbetinfo(uint256 bettxid, BetInfo &betinfo) return -2; OneBetData bet1; - if (prices_betopretdecode(bettx.vout.back().scriptPubKey, betinfo.pk, bet1.firstheight, bet1.positionsize, betinfo.leverage, betinfo.firstprice, betinfo.parsed, betinfo.tokenid) == 'B') + if (prices_betopretdecode(bettx.vout.back().scriptPubKey, betinfo.pk, bet1.firstheight, bet1.positionsize, betinfo.leverage, betinfo.firstprice, betinfo.vecparsed, betinfo.tokenid) == 'B') { uint256 finaltxid; int32_t vini; int32_t finaltxheight; //, endheight; //std::vector bets; - + betinfo.txid = bettxid; if (CCgetspenttxid(finaltxid, vini, finaltxheight, bettxid, NVOUT_CCMARKER) == 0) betinfo.isOpen = false; @@ -1618,7 +1619,7 @@ int32_t prices_getbetinfo(uint256 bettxid, BetInfo &betinfo) prices_enumaddedbets(batontxid, betinfo.bets, bettxid); - if (prices_scanchain(betinfo.bets, betinfo.leverage, betinfo.parsed, betinfo.lastprice, betinfo.lastheight) < 0) { + if (prices_scanchain(betinfo.bets, betinfo.leverage, betinfo.vecparsed, betinfo.lastprice, betinfo.lastheight) < 0) { return -4; } @@ -1921,7 +1922,7 @@ UniValue PricesInfo(uint256 bettxid, int32_t refheight) result.push_back(Pair("rektheight", betinfo.lastheight)); } - std::string expr = prices_getsourceexpression(betinfo.parsed); + std::string expr = prices_getsourceexpression(betinfo.vecparsed); result.push_back(Pair("expression", expr)); result.push_back(Pair("reduced", prices_getreducedexpr(expr))); // result.push_back(Pair("batontxid", batontxid.GetHex())); @@ -2002,11 +2003,52 @@ UniValue PricesList(uint32_t filter, CPubKey mypk) } -void prices_addbookentry(uint256 txid) +static bool prices_addbookentry(uint256 txid, std::vector &book) { BetInfo betinfo; - //if( prices_getbetinfo(txid, betinfo) == 0 ) + if (prices_getbetinfo(txid, betinfo) == 0) { + book.push_back(betinfo); + return true; + } + return false; } +/* +static bool prices_isopposite(BetInfo p1, BetInfo p2) { + if (p1.vecparsed.size() <= 3 && p2.vecparsed.size() <= 3) { // simple synthetic exp + + uint16_t opcode1 = p1.vecparsed[0]; + uint16_t opcode2 = p2.vecparsed[0]; + + int32_t value1 = (opcode1 & (KOMODO_MAXPRICES - 1)); // index or weight + int32_t value2 = (opcode2 & (KOMODO_MAXPRICES - 1)); // index or weight + + if ( (opcode1 & KOMODO_PRICEMASK) && (opcode2 & KOMODO_PRICEMASK) ) { + char name1[65]; + char name2[65]; + if (komodo_pricename(name1, value1) && komodo_pricename(name2, value2)) { + + std::string upperquote1, bottomquote1, upperquote2, bottomquote2; + prices_splitpair(std::string(name1), upperquote1, bottomquote1); + prices_splitpair(std::string(name2), upperquote2, bottomquote2); + + if (upperquote == "BTC") + isTop = true; + else if (bottomquote == "BTC") + isTop = false; + else + continue; + + if (!bottomquote.empty()) { + + for (int j = i + 1; j < book.size(); j++) { + + } + } + } + } + } +} +*/ // walk through uxtos on the global address // calculate the balance: @@ -2016,16 +2058,50 @@ void prices_addbookentry(uint256 txid) UniValue PricesGetOrderbook() { UniValue result(UniValue::VARR); - std::vector > addressIndex, addressIndexCC; + std::vector book, opposits; + std::vector > addressIndex; struct CCcontract_info *cp, C; cp = CCinit(&C, EVAL_PRICES); + // add all bets: SetCCtxids(addressIndex, cp->normaladdr, false); // old normal marker for (std::vector >::const_iterator it = addressIndex.begin(); it != addressIndex.end(); it++) { if (it->first.txindex == NVOUT_NORMALMARKER) - prices_addbookentry(it->first.txhash); + prices_addbookentry(it->first.txhash, book); } + + + // calc total fund amount + int64_t totalfund = 0; + std::vector > addressCCunspents; + SetCCunspents(addressCCunspents, cp->unspendableCCaddr, true); // cc marker + for (std::vector >::const_iterator it = addressCCunspents.begin(); it != addressCCunspents.end(); it++) + { + totalfund += it->second.satoshis; + } + + // extract out opposit bets: + int lastbtcpos = -1; + int lastleverage = 0; + for (int i = 0; i < book.size() - 1; i++) { + for (int j = 0; j < book.size(); j++) { + if (book[i].isOpen && book[j].isOpen) { + //if (prices_isopposite(book[i], book[j])) { + //} + } + } + } + + int64_t totalliabilities = 0; + for (int i = 0; i < book.size() - 1; i++) { + if (book[i].isOpen) { + totalliabilities += book[i].equity; + } + } + + result.push_back(Pair("TotalFund", ValueFromAmount(totalfund))); + result.push_back(Pair("TotalLiabilities", ValueFromAmount(totalliabilities))); return result; } From 5a688c226de0021777d880e6286125406106fd6b Mon Sep 17 00:00:00 2001 From: dimxy Date: Wed, 8 May 2019 15:16:14 +0500 Subject: [PATCH 319/447] corr vobj --- src/cc/prices.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 3ac334109..fb87427a8 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -2057,7 +2057,7 @@ static bool prices_isopposite(BetInfo p1, BetInfo p2) { // - unbalanced positions UniValue PricesGetOrderbook() { - UniValue result(UniValue::VARR); + UniValue result(UniValue::VOBJ); std::vector book, opposits; std::vector > addressIndex; struct CCcontract_info *cp, C; From 2b97d588bed159f7938d2ec650a935c38040a7a8 Mon Sep 17 00:00:00 2001 From: dimxy Date: Wed, 8 May 2019 15:30:50 +0500 Subject: [PATCH 320/447] logging book vars --- src/cc/prices.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index fb87427a8..d193df54d 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -2097,6 +2097,9 @@ UniValue PricesGetOrderbook() int64_t totalliabilities = 0; for (int i = 0; i < book.size() - 1; i++) { if (book[i].isOpen) { + int64_t t = 0; + for (auto b : book[i].bets) t += b.positionsize; + std::cerr << "book[i].exp=" << prices_getsourceexpression(book[i].vecparsed) << " totalpos" << t << " equity=" << book[i].equity << std::endl; totalliabilities += book[i].equity; } } From d2c343a56ddafbf2947bca1c29b530dc822075d2 Mon Sep 17 00:00:00 2001 From: dimxy Date: Wed, 8 May 2019 15:41:38 +0500 Subject: [PATCH 321/447] corr tx list selection --- src/cc/prices.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index d193df54d..d4e7701cf 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -1988,7 +1988,7 @@ UniValue PricesList(uint32_t filter, CPubKey mypk) SetCCtxids(addressIndex, cp->normaladdr, false); // old normal marker for (std::vector >::const_iterator it = addressIndex.begin(); it != addressIndex.end(); it++) { - if( it->first.txindex == NVOUT_NORMALMARKER ) + if( it->first.index == NVOUT_NORMALMARKER ) AddBetToList(it->first.txhash); } @@ -2068,7 +2068,7 @@ UniValue PricesGetOrderbook() SetCCtxids(addressIndex, cp->normaladdr, false); // old normal marker for (std::vector >::const_iterator it = addressIndex.begin(); it != addressIndex.end(); it++) { - if (it->first.txindex == NVOUT_NORMALMARKER) + if (it->first.index == NVOUT_NORMALMARKER) prices_addbookentry(it->first.txhash, book); } @@ -2095,11 +2095,11 @@ UniValue PricesGetOrderbook() } int64_t totalliabilities = 0; - for (int i = 0; i < book.size() - 1; i++) { + for (int i = 0; i < book.size(); i++) { if (book[i].isOpen) { int64_t t = 0; for (auto b : book[i].bets) t += b.positionsize; - std::cerr << "book[i].exp=" << prices_getsourceexpression(book[i].vecparsed) << " totalpos" << t << " equity=" << book[i].equity << std::endl; + std::cerr << "book[i].exp=" << prices_getsourceexpression(book[i].vecparsed) << " totalpos=" << t << " equity=" << book[i].equity << std::endl; totalliabilities += book[i].equity; } } From 8bfb3ad4563059067795e35f9056a9b35f16450b Mon Sep 17 00:00:00 2001 From: dimxy Date: Wed, 8 May 2019 15:53:34 +0500 Subject: [PATCH 322/447] commented logging to speed up --- src/cc/prices.cpp | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index d4e7701cf..aebf6e476 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -882,7 +882,7 @@ int32_t prices_syntheticvec(std::vector &vec, std::vector return(-3); } depth -= need; - std::cerr << "prices_syntheticvec() opcode=" << opcode << " opstr=" << opstr << " need=" << need << " depth=" << depth << std::endl; + //std::cerr << "prices_syntheticvec() opcode=" << opcode << " opstr=" << opstr << " need=" << need << " depth=" << depth << std::endl; if ((opcode & KOMODO_PRICEMASK) != PRICES_WEIGHT) { // skip weight depth++; // increase operands count std::cerr << "depth++=" << depth << std::endl; @@ -931,14 +931,14 @@ int64_t prices_syntheticprice(std::vector vec, int32_t height, int32_t mpz_set_ui(mpzResult, 0); // clear result to test overflow (see below) - std::cerr << "prices_syntheticprice" << " i=" << i << " mpzTotalPrice=" << mpz_get_si(mpzTotalPrice) << " value=" << value << " depth=" << depth << " opcode&KOMODO_PRICEMASK=" << (opcode & KOMODO_PRICEMASK) < 0 ) + // std::cerr << "prices_syntheticprice top pricestack[depth-1=" << depth-1 << "]=" << pricestack[depth-1] << std::endl; + // else + // std::cerr << "prices_syntheticprice pricestack empty" << std::endl; } free(pricedata); @@ -1155,7 +1155,7 @@ int64_t prices_syntheticprice(std::vector vec, int32_t height, int32_t std::cerr << "prices_syntheticprice err=" << errcode << std::endl; return(errcode); } - std::cerr << "prices_syntheticprice priceIndex=" << priceIndex << " den=" << den << std::endl; + //std::cerr << "prices_syntheticprice priceIndex=" << priceIndex << " den=" << den << std::endl; return priceIndex; } @@ -1192,11 +1192,11 @@ int32_t prices_syntheticprofits(int64_t &costbasis, int32_t firstheight, int32_t if (minmax) { // if we are within day window, set temp costbasis to max (or min) price value if (leverage > 0 && price > costbasis) { costbasis = price; // set temp costbasis - std::cerr << "prices_syntheticprofits() minmax costbasis=" << costbasis << std::endl; + //std::cerr << "prices_syntheticprofits() minmax costbasis=" << costbasis << std::endl; } else if (leverage < 0 && (costbasis == 0 || price < costbasis)) { costbasis = price; - std::cerr << "prices_syntheticprofits() minmax costbasis=" << costbasis << std::endl; + //std::cerr << "prices_syntheticprofits() minmax costbasis=" << costbasis << std::endl; } //else { //-> use the previous value // std::cerr << "prices_syntheticprofits() unchanged costbasis=" << costbasis << " price=" << price << " leverage=" << leverage << std::endl; @@ -1208,7 +1208,7 @@ int32_t prices_syntheticprofits(int64_t &costbasis, int32_t firstheight, int32_t //costbasis = price; // use calculated minmax costbasis - std::cerr << "prices_syntheticprofits() use permanent costbasis=" << costbasis << " at height=" << height << std::endl; + //std::cerr << "prices_syntheticprofits() use permanent costbasis=" << costbasis << " at height=" << height << std::endl; } } @@ -1266,7 +1266,7 @@ int32_t prices_syntheticprofits(int64_t &costbasis, int32_t firstheight, int32_t else profits = 0; - std::cerr << "prices_syntheticprofits() profits=" << profits << std::endl; + //std::cerr << "prices_syntheticprofits() profits=" << profits << std::endl; return 0; // (positionsize + addedbets + profits); } @@ -1366,7 +1366,7 @@ int64_t prices_enumaddedbets(uint256 &batontxid, std::vector &bets, added.positionsize = amount; added.firstheight = blockIdx.GetHeight(); bets.push_back(added); - std::cerr << "prices_batontxid() added amount=" << amount << std::endl; + //std::cerr << "prices_batontxid() added amount=" << amount << std::endl; } else { std::cerr << "prices_batontxid() cannot load or decode add bet tx, isLoaded=" << isLoaded << " funcId=" << (int)funcId << std::endl; @@ -1494,7 +1494,7 @@ int32_t prices_scanchain(std::vector &bets, int16_t leverage, std::v int32_t retcode = prices_syntheticprofits(bets[i].costbasis, bets[i].firstheight, height, leverage, vec, bets[i].positionsize, bets[i].profits, lastprice); if (retcode < 0) { - std::cerr << "prices_scanchain() prices_syntheticprofits returned -1, breaking" << std::endl; + std::cerr << "prices_scanchain() prices_syntheticprofits returned -1, finishing..." << std::endl; stop = true; break; } From b25371ef01fee71ec5f05a61b8abd9eb0e123fde Mon Sep 17 00:00:00 2001 From: dimxy Date: Wed, 8 May 2019 16:00:28 +0500 Subject: [PATCH 323/447] more logging commented out --- src/cc/prices.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index aebf6e476..634a781c7 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -1103,7 +1103,7 @@ int64_t prices_syntheticprice(std::vector vec, int32_t height, int32_t break; } - std::cerr << "prices_syntheticprice test mpzResult=" << mpz_get_si(mpzResult) << std::endl; + // std::cerr << "prices_syntheticprice test mpzResult=" << mpz_get_si(mpzResult) << std::endl; // check overflow: if (mpz_cmp_si(mpzResult, std::numeric_limits::max()) > 0) { errcode = -13; @@ -1155,7 +1155,7 @@ int64_t prices_syntheticprice(std::vector vec, int32_t height, int32_t std::cerr << "prices_syntheticprice err=" << errcode << std::endl; return(errcode); } - //std::cerr << "prices_syntheticprice priceIndex=" << priceIndex << " den=" << den << std::endl; +// std::cerr << "prices_syntheticprice priceIndex=totalprice/den=" << priceIndex << " den=" << den << std::endl; return priceIndex; } From 0730775cad04f445206e70ac8f6357371967482a Mon Sep 17 00:00:00 2001 From: dimxy Date: Wed, 8 May 2019 16:03:35 +0500 Subject: [PATCH 324/447] added totalfund logging --- src/cc/prices.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 634a781c7..36954001e 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -2079,6 +2079,7 @@ UniValue PricesGetOrderbook() SetCCunspents(addressCCunspents, cp->unspendableCCaddr, true); // cc marker for (std::vector >::const_iterator it = addressCCunspents.begin(); it != addressCCunspents.end(); it++) { + std::cerr << "totalfund calc txid=" << it->first.txhash.GetHex() << " nvout=" << it->first.index << " satoshis=" << it->second.satoshis; totalfund += it->second.satoshis; } From 3a563f72561fa96171e064d510ab7f7de89e1ddd Mon Sep 17 00:00:00 2001 From: dimxy Date: Wed, 8 May 2019 16:07:10 +0500 Subject: [PATCH 325/447] add endl --- src/cc/prices.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 36954001e..b2853d142 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -2079,7 +2079,7 @@ UniValue PricesGetOrderbook() SetCCunspents(addressCCunspents, cp->unspendableCCaddr, true); // cc marker for (std::vector >::const_iterator it = addressCCunspents.begin(); it != addressCCunspents.end(); it++) { - std::cerr << "totalfund calc txid=" << it->first.txhash.GetHex() << " nvout=" << it->first.index << " satoshis=" << it->second.satoshis; + std::cerr << "totalfund calc txid=" << it->first.txhash.GetHex() << " nvout=" << it->first.index << " satoshis=" << it->second.satoshis << std::endl; totalfund += it->second.satoshis; } From 95b5d42fbe8501b74fda2aeb41e68e0f7cf9f23d Mon Sep 17 00:00:00 2001 From: dimxy Date: Wed, 8 May 2019 16:10:52 +0500 Subject: [PATCH 326/447] added txid to log --- src/cc/prices.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index b2853d142..4b52a364d 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -2100,7 +2100,7 @@ UniValue PricesGetOrderbook() if (book[i].isOpen) { int64_t t = 0; for (auto b : book[i].bets) t += b.positionsize; - std::cerr << "book[i].exp=" << prices_getsourceexpression(book[i].vecparsed) << " totalpos=" << t << " equity=" << book[i].equity << std::endl; + std::cerr << "book[i].=" << book[i].txid.GetHex() << " exp=" << prices_getsourceexpression(book[i].vecparsed) << " totalpos=" << t << " equity=" << book[i].equity << std::endl; totalliabilities += book[i].equity; } } From 55c334885126eded2a1fd4cda540c44ca679749f Mon Sep 17 00:00:00 2001 From: dimxy Date: Wed, 8 May 2019 16:25:07 +0500 Subject: [PATCH 327/447] added isopen to pricesinfo --- src/cc/prices.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 4b52a364d..401a8190c 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -1922,6 +1922,8 @@ UniValue PricesInfo(uint256 bettxid, int32_t refheight) result.push_back(Pair("rektheight", betinfo.lastheight)); } + result.push_back(Pair("open", betinfo.isOpen ? 1 : 0 )); + std::string expr = prices_getsourceexpression(betinfo.vecparsed); result.push_back(Pair("expression", expr)); result.push_back(Pair("reduced", prices_getreducedexpr(expr))); @@ -2100,7 +2102,7 @@ UniValue PricesGetOrderbook() if (book[i].isOpen) { int64_t t = 0; for (auto b : book[i].bets) t += b.positionsize; - std::cerr << "book[i].=" << book[i].txid.GetHex() << " exp=" << prices_getsourceexpression(book[i].vecparsed) << " totalpos=" << t << " equity=" << book[i].equity << std::endl; + std::cerr << "book[i].txid=" << book[i].txid.GetHex() << " exp=" << prices_getsourceexpression(book[i].vecparsed) << " totalpos=" << t << " equity=" << book[i].equity << std::endl; totalliabilities += book[i].equity; } } From 5db0a5c38131ae212f55e05aeb035c14abe522a0 Mon Sep 17 00:00:00 2001 From: dimxy Date: Wed, 8 May 2019 22:02:21 +0500 Subject: [PATCH 328/447] added orderbooks to result --- src/cc/prices.cpp | 62 ++++++++++++++++++++++++++++++++--------------- 1 file changed, 42 insertions(+), 20 deletions(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 401a8190c..de1242d0a 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -2014,7 +2014,7 @@ static bool prices_addbookentry(uint256 txid, std::vector &book) } return false; } -/* + static bool prices_isopposite(BetInfo p1, BetInfo p2) { if (p1.vecparsed.size() <= 3 && p2.vecparsed.size() <= 3) { // simple synthetic exp @@ -2033,24 +2033,15 @@ static bool prices_isopposite(BetInfo p1, BetInfo p2) { prices_splitpair(std::string(name1), upperquote1, bottomquote1); prices_splitpair(std::string(name2), upperquote2, bottomquote2); - if (upperquote == "BTC") - isTop = true; - else if (bottomquote == "BTC") - isTop = false; - else - continue; - - if (!bottomquote.empty()) { - - for (int j = i + 1; j < book.size(); j++) { - - } - } + if (upperquote1 == bottomquote2 && bottomquote1 == upperquote2 && (p1.leverage > 0 == p2.leverage > 0) || + upperquote1 == upperquote2 && bottomquote1 == bottomquote2 && (p1.leverage > 0 != p2.leverage > 0)) + return true; } } } + return false; } -*/ + // walk through uxtos on the global address // calculate the balance: @@ -2085,18 +2076,49 @@ UniValue PricesGetOrderbook() totalfund += it->second.satoshis; } - // extract out opposit bets: - int lastbtcpos = -1; - int lastleverage = 0; + // extract out opposite bets: + std::map > bookmatched; for (int i = 0; i < book.size() - 1; i++) { for (int j = 0; j < book.size(); j++) { if (book[i].isOpen && book[j].isOpen) { - //if (prices_isopposite(book[i], book[j])) { - //} + if (prices_isopposite(book[i], book[j])) { + char name[65]; + komodo_pricename(name, (book[i].vecparsed[0] & (KOMODO_MAXPRICES - 1))); + std::string sname = name; + bookmatched[sname].push_back(book[i]); + bookmatched[sname].push_back(book[j]); + book.erase(book.begin() + j); + book.erase(book.begin() + i); + } } } } + UniValue resbook (UniValue::VARR); + for (int i = 0; i < book.size(); i++) { + UniValue entry(UniValue::VOBJ); + entry.push_back(Pair("expression", prices_getsourceexpression(book[i].vecparsed))); + entry.push_back(Pair("costbasis", book[i].averageCostbasis)); + entry.push_back(Pair("leverage", book[i].leverage)); + entry.push_back(Pair("equity", book[i].equity)); + resbook.push_back(entry); + } + result.push_back(Pair("unmatched", resbook)); + + for (auto m : bookmatched) { + UniValue resbook(UniValue::VARR); + for (int i = 0; i < m.second.size(); i++) { + UniValue entry(UniValue::VOBJ); + entry.push_back(Pair("expression", prices_getsourceexpression(m.second[i].vecparsed))); + entry.push_back(Pair("costbasis", m.second[i].averageCostbasis)); + entry.push_back(Pair("leverage", m.second[i].leverage)); + entry.push_back(Pair("equity", m.second[i].equity)); + resbook.push_back(entry); + } + result.push_back(Pair(m.first, resbook)); + } + + int64_t totalliabilities = 0; for (int i = 0; i < book.size(); i++) { if (book[i].isOpen) { From fececb0e6b1ecc479547163b7124cd9618c925d8 Mon Sep 17 00:00:00 2001 From: dimxy Date: Wed, 8 May 2019 22:58:54 +0500 Subject: [PATCH 329/447] corr isopposite corr put into map --- src/cc/prices.cpp | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index de1242d0a..3e1adfafb 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -2024,17 +2024,20 @@ static bool prices_isopposite(BetInfo p1, BetInfo p2) { int32_t value1 = (opcode1 & (KOMODO_MAXPRICES - 1)); // index or weight int32_t value2 = (opcode2 & (KOMODO_MAXPRICES - 1)); // index or weight - if ( (opcode1 & KOMODO_PRICEMASK) && (opcode2 & KOMODO_PRICEMASK) ) { + if ( (opcode1 & KOMODO_PRICEMASK) == 0 && (opcode2 & KOMODO_PRICEMASK) == 0 ) { char name1[65]; char name2[65]; if (komodo_pricename(name1, value1) && komodo_pricename(name2, value2)) { + uint16_t opcode1 = p1.vecparsed[1]; + uint16_t opcode2 = p2.vecparsed[1]; + std::string upperquote1, bottomquote1, upperquote2, bottomquote2; prices_splitpair(std::string(name1), upperquote1, bottomquote1); prices_splitpair(std::string(name2), upperquote2, bottomquote2); - if (upperquote1 == bottomquote2 && bottomquote1 == upperquote2 && (p1.leverage > 0 == p2.leverage > 0) || - upperquote1 == upperquote2 && bottomquote1 == bottomquote2 && (p1.leverage > 0 != p2.leverage > 0)) + if (/*upperquote1 == bottomquote2 && bottomquote1 == upperquote2 && (p1.leverage > 0 == p2.leverage > 0 || (opcode1 & KOMODO_PRICEMASK) == PRICES_INV == (opcode2 & KOMODO_PRICEMASK) == PRICES_INV) ||*/ + upperquote1 == upperquote2 && bottomquote1 == bottomquote2 && ((p1.leverage > 0) != (p2.leverage > 0) || ((opcode1 & KOMODO_PRICEMASK) == PRICES_INV) != ((opcode2 & KOMODO_PRICEMASK) == PRICES_INV)) ) return true; } } @@ -2078,20 +2081,22 @@ UniValue PricesGetOrderbook() // extract out opposite bets: std::map > bookmatched; - for (int i = 0; i < book.size() - 1; i++) { - for (int j = 0; j < book.size(); j++) { - if (book[i].isOpen && book[j].isOpen) { - if (prices_isopposite(book[i], book[j])) { - char name[65]; - komodo_pricename(name, (book[i].vecparsed[0] & (KOMODO_MAXPRICES - 1))); - std::string sname = name; - bookmatched[sname].push_back(book[i]); + while (book.size() > 0) { + char name[65]; + komodo_pricename(name, (book[0].vecparsed[0] & (KOMODO_MAXPRICES - 1))); + std::string sname = name; + bookmatched[sname].push_back(book[0]); + + for (int j = 1; j < book.size(); j++) { + if (book[0].isOpen && book[j].isOpen) { + if (prices_isopposite(book[0], book[j])) { + bookmatched[sname].push_back(book[j]); book.erase(book.begin() + j); - book.erase(book.begin() + i); } } } + book.erase(book.begin()); } UniValue resbook (UniValue::VARR); From 1330bde5c84382522b1222fa912198200d6ab3d7 Mon Sep 17 00:00:00 2001 From: dimxy Date: Wed, 8 May 2019 23:13:59 +0500 Subject: [PATCH 330/447] corr store in map --- src/cc/prices.cpp | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 3e1adfafb..5d7125541 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -2082,17 +2082,20 @@ UniValue PricesGetOrderbook() // extract out opposite bets: std::map > bookmatched; while (book.size() > 0) { - char name[65]; - komodo_pricename(name, (book[0].vecparsed[0] & (KOMODO_MAXPRICES - 1))); - std::string sname = name; + //char name[65]; + //komodo_pricename(name, (book[0].vecparsed[0] & (KOMODO_MAXPRICES - 1))); + std::string sname = prices_getsourceexpression(book[0].vecparsed); bookmatched[sname].push_back(book[0]); - for (int j = 1; j < book.size(); j++) { - if (book[0].isOpen && book[j].isOpen) { - if (prices_isopposite(book[0], book[j])) { - - bookmatched[sname].push_back(book[j]); - book.erase(book.begin() + j); + if (book[0].vecparsed.size() <= 3) { // only short expr matched: "BTC_USD,1" or "BTC_USD,!,1" + + for (int j = 1; j < book.size(); j++) { + if (book[0].isOpen && book[j].isOpen) { + if (prices_isopposite(book[0], book[j])) { + + bookmatched[sname].push_back(book[j]); + book.erase(book.begin() + j); + } } } } From 114def2ab7cf18bcffaafb92c0c102942d227f71 Mon Sep 17 00:00:00 2001 From: dimxy Date: Wed, 8 May 2019 23:21:59 +0500 Subject: [PATCH 331/447] corr more put into map --- src/cc/prices.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 5d7125541..95658d6d5 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -2082,12 +2082,14 @@ UniValue PricesGetOrderbook() // extract out opposite bets: std::map > bookmatched; while (book.size() > 0) { - //char name[65]; - //komodo_pricename(name, (book[0].vecparsed[0] & (KOMODO_MAXPRICES - 1))); std::string sname = prices_getsourceexpression(book[0].vecparsed); bookmatched[sname].push_back(book[0]); if (book[0].vecparsed.size() <= 3) { // only short expr matched: "BTC_USD,1" or "BTC_USD,!,1" + char name[65]; + komodo_pricename(name, (book[0].vecparsed[0] & (KOMODO_MAXPRICES - 1))); + std::string sname = name; + bookmatched[sname].push_back(book[0]); for (int j = 1; j < book.size(); j++) { if (book[0].isOpen && book[j].isOpen) { @@ -2099,6 +2101,11 @@ UniValue PricesGetOrderbook() } } } + else { + // store as is + std::string sname = prices_getsourceexpression(book[0].vecparsed); + bookmatched[sname].push_back(book[0]); + } book.erase(book.begin()); } From 9928edbb0df9e0f4a3ead2904f0348c09299ccb9 Mon Sep 17 00:00:00 2001 From: dimxy Date: Wed, 8 May 2019 23:28:52 +0500 Subject: [PATCH 332/447] extra stmt removed --- src/cc/prices.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 95658d6d5..81074e40d 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -2082,8 +2082,6 @@ UniValue PricesGetOrderbook() // extract out opposite bets: std::map > bookmatched; while (book.size() > 0) { - std::string sname = prices_getsourceexpression(book[0].vecparsed); - bookmatched[sname].push_back(book[0]); if (book[0].vecparsed.size() <= 3) { // only short expr matched: "BTC_USD,1" or "BTC_USD,!,1" char name[65]; From b2f170ca951c9c0a496ab2ec6d09cf56961ccd60 Mon Sep 17 00:00:00 2001 From: dimxy Date: Thu, 9 May 2019 15:28:45 +0500 Subject: [PATCH 333/447] added more totals --- src/cc/prices.cpp | 137 ++++++++++++++++++++++++++++++---------------- 1 file changed, 90 insertions(+), 47 deletions(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 81074e40d..55bccf686 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -11,7 +11,34 @@ * * * Removal or modification of this copyright notice is prohibited. * * * - ***************************************************************************** + *****************************************************************************/ + + /* + CBOPRET creates trustless oracles, which can be used for making a synthetic cash settlement system based on real world prices; + + 0.5% fee based on betamount, NOT leveraged betamount!! + 0.1% collected by price basis determinant + 0.2% collected by rekt tx + + PricesBet -> +/-leverage, amount, synthetic -> opreturn includes current price + funds are locked into 1of2 global CC address + for first day, long basis is MAX(correlated,smoothed), short is MIN() + reference price is the smoothed of the previous block + if synthetic value + amount goes negative, then anybody can rekt it to collect a rektfee, proof of rekt must be included to show cost basis, rekt price + original creator can liquidate at anytime and collect (synthetic value + amount) from globalfund + 0.5% of bet -> globalfund + + PricesStatus -> bettxid maxsamples returns initial params, cost basis, amount left, rekt:true/false, rektheight, initial synthetic price, current synthetic price, net gain + + PricesRekt -> bettxid height -> 0.1% to miner, rest to global CC + + PricesClose -> bettxid returns (synthetic value + amount) + + PricesList -> all bettxid -> list [bettxid, netgain] + + */ + +/* To create payments plan start a chain with the following ac_params: -ac_snapshot=1440 (or for test chain something smaller, if you like.) - this enables the payments airdrop cc to work. @@ -83,31 +110,11 @@ typedef struct BetInfo { } } BetInfo; -/* -CBOPRET creates trustless oracles, which can be used for making a synthetic cash settlement system based on real world prices; - - 0.5% fee based on betamount, NOT leveraged betamount!! - 0.1% collected by price basis determinant - 0.2% collected by rekt tx - - PricesBet -> +/-leverage, amount, synthetic -> opreturn includes current price - funds are locked into 1of2 global CC address - for first day, long basis is MAX(correlated,smoothed), short is MIN() - reference price is the smoothed of the previous block - if synthetic value + amount goes negative, then anybody can rekt it to collect a rektfee, proof of rekt must be included to show cost basis, rekt price - original creator can liquidate at anytime and collect (synthetic value + amount) from globalfund - 0.5% of bet -> globalfund - - PricesStatus -> bettxid maxsamples returns initial params, cost basis, amount left, rekt:true/false, rektheight, initial synthetic price, current synthetic price, net gain - - PricesRekt -> bettxid height -> 0.1% to miner, rest to global CC - - PricesClose -> bettxid returns (synthetic value + amount) - - PricesList -> all bettxid -> list [bettxid, netgain] - - -*/ +typedef struct MatchedBookTotal { + + int64_t diffLeveragedPosition; + +} MatchedBookTotal; int32_t prices_syntheticprofits(int64_t &costbasis, int32_t firstheight, int32_t height, int16_t leverage, std::vector vec, int64_t positionsize, int64_t &profits, int64_t &outprice); @@ -2081,33 +2088,64 @@ UniValue PricesGetOrderbook() // extract out opposite bets: std::map > bookmatched; + int64_t totalBets = 0; + int64_t totalRekt = 0; + int64_t totalEquity = 0; while (book.size() > 0) { - if (book[0].vecparsed.size() <= 3) { // only short expr matched: "BTC_USD,1" or "BTC_USD,!,1" - char name[65]; - komodo_pricename(name, (book[0].vecparsed[0] & (KOMODO_MAXPRICES - 1))); - std::string sname = name; - bookmatched[sname].push_back(book[0]); + int64_t betspos = 0; + for (auto bet : book[0].bets) betspos += bet.positionsize; + + if (!book[0].isRekt) { + + totalBets += betspos; + totalEquity += book[0].equity; - for (int j = 1; j < book.size(); j++) { - if (book[0].isOpen && book[j].isOpen) { - if (prices_isopposite(book[0], book[j])) { + if (book[0].vecparsed.size() <= 3) { // only short expr check for match: "BTC_USD,1" or "BTC_USD,!,1" + char name[65]; + komodo_pricename(name, (book[0].vecparsed[0] & (KOMODO_MAXPRICES - 1))); + std::string sname = name; + bookmatched[sname].push_back(book[0]); - bookmatched[sname].push_back(book[j]); - book.erase(book.begin() + j); + for (int j = 1; j < book.size(); j++) { + if (book[0].isOpen && book[j].isOpen) { + if (prices_isopposite(book[0], book[j])) { + + bookmatched[sname].push_back(book[j]); + book.erase(book.begin() + j); + } } } } + else { + // store as is + std::string sname = prices_getsourceexpression(book[0].vecparsed); + bookmatched[sname].push_back(book[0]); + } } - else { - // store as is - std::string sname = prices_getsourceexpression(book[0].vecparsed); - bookmatched[sname].push_back(book[0]); + else { + totalRekt += betspos; } book.erase(book.begin()); } - UniValue resbook (UniValue::VARR); + // calculate cancelling amount + std::map matchedTotals; + for (auto m : bookmatched) { + int64_t totalLeveragedPositionUp = 0; + int64_t totalLeveragedPositionDown = 0; + int64_t totalLeverageUp = 0; + int64_t totalLeverageDown = 0; + + + for (int i = 0; i < m.second.size(); i++) { + + } + matchedTotals[m.first].diffLeveragedPosition = totalLeveragedPositionUp / totalLeverageUp - totalLeveragedPositionDown / totalLeverageDown; + } + + + /*UniValue resbook (UniValue::VARR); for (int i = 0; i < book.size(); i++) { UniValue entry(UniValue::VOBJ); entry.push_back(Pair("expression", prices_getsourceexpression(book[i].vecparsed))); @@ -2116,7 +2154,7 @@ UniValue PricesGetOrderbook() entry.push_back(Pair("equity", book[i].equity)); resbook.push_back(entry); } - result.push_back(Pair("unmatched", resbook)); + result.push_back(Pair("unmatched", resbook)); */ for (auto m : bookmatched) { UniValue resbook(UniValue::VARR); @@ -2131,18 +2169,23 @@ UniValue PricesGetOrderbook() result.push_back(Pair(m.first, resbook)); } - - int64_t totalliabilities = 0; + int64_t totalLiabilities = 0; + /* empty for (int i = 0; i < book.size(); i++) { if (book[i].isOpen) { int64_t t = 0; for (auto b : book[i].bets) t += b.positionsize; std::cerr << "book[i].txid=" << book[i].txid.GetHex() << " exp=" << prices_getsourceexpression(book[i].vecparsed) << " totalpos=" << t << " equity=" << book[i].equity << std::endl; - totalliabilities += book[i].equity; + totalLiabilities += book[i].equity; } - } + } */ result.push_back(Pair("TotalFund", ValueFromAmount(totalfund))); - result.push_back(Pair("TotalLiabilities", ValueFromAmount(totalliabilities))); + result.push_back(Pair("TotalRekt", ValueFromAmount(totalRekt))); + result.push_back(Pair("TotalBets", ValueFromAmount(totalBets))); + result.push_back(Pair("TotalEquity", ValueFromAmount(totalEquity))); + + +// result.push_back(Pair("TotalLiabilities", ValueFromAmount(totalLiabilities))); return result; } From b8b80c934107334a83a5909c14f0d9fa71d94282 Mon Sep 17 00:00:00 2001 From: dimxy Date: Thu, 9 May 2019 16:12:33 +0500 Subject: [PATCH 334/447] corr calc --- src/cc/prices.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 55bccf686..dc4f09127 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -889,10 +889,10 @@ int32_t prices_syntheticvec(std::vector &vec, std::vector return(-3); } depth -= need; - //std::cerr << "prices_syntheticvec() opcode=" << opcode << " opstr=" << opstr << " need=" << need << " depth=" << depth << std::endl; + ///std::cerr << "prices_syntheticvec() opcode=" << opcode << " opstr=" << opstr << " need=" << need << " depth=" << depth << std::endl; if ((opcode & KOMODO_PRICEMASK) != PRICES_WEIGHT) { // skip weight depth++; // increase operands count - std::cerr << "depth++=" << depth << std::endl; + ///std::cerr << "depth++=" << depth << std::endl; } if (depth > 3) { std::cerr << "prices_syntheticvec() too many operands, last=" << opstr << std::endl; @@ -1620,8 +1620,9 @@ int32_t prices_getbetinfo(uint256 bettxid, BetInfo &betinfo) else betinfo.isOpen = true; - //bet1.amount = betinfo.positionsize; - //bet1.firstheight = firstheight; + // override with real amount (TODO: check this) + bet1.positionsize = bettx.vout[2].nValue; + betinfo.bets.push_back(bet1); prices_enumaddedbets(batontxid, betinfo.bets, bettxid); From 0ca3bbdb12c5c1ea70b4e2f140b73a76ce0639df Mon Sep 17 00:00:00 2001 From: dimxy Date: Thu, 9 May 2019 16:16:28 +0500 Subject: [PATCH 335/447] corr totals calc --- src/cc/prices.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index dc4f09127..763e3b038 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -1883,8 +1883,6 @@ UniValue PricesCashout(int64_t txfee, uint256 bettxid) } - - // pricesinfo rpc impl UniValue PricesInfo(uint256 bettxid, int32_t refheight) { @@ -2125,7 +2123,7 @@ UniValue PricesGetOrderbook() } } else { - totalRekt += betspos; + totalRekt += (betspos - book[0].rektfee); } book.erase(book.begin()); } From 6a51c67aeb21f26f8b7d3ae98882e0d0cfbdedfb Mon Sep 17 00:00:00 2001 From: dimxy Date: Thu, 9 May 2019 17:08:10 +0500 Subject: [PATCH 336/447] added lev position calc --- src/cc/prices.cpp | 59 +++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 52 insertions(+), 7 deletions(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 763e3b038..e44e30cb7 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -72,6 +72,7 @@ GetKomodoEarlytxidScriptPub is on line #2080 of komodo_bitcoind.h #include "CCassets.h" #include "CCPrices.h" +#include #include #define IS_CHARINSTR(c, str) (std::string(str).find((char)(c)) != std::string::npos) @@ -1142,8 +1143,13 @@ int64_t prices_syntheticprice(std::vector vec, int32_t height, int32_t mpz_clear(mpzTotalPrice); mpz_clear(mpzPriceValue); - if (errcode != 0) + if (errcode != 0) std::cerr << "prices_syntheticprice errcode in switch=" << errcode << std::endl; + + if( errcode = -1 ) { + std::cerr << "prices_syntheticprice error getting price (could be end of chain)" << std::endl; + return errcode; + } if (errcode == -13) { std::cerr << "prices_syntheticprice overflow in price" << std::endl; @@ -2021,6 +2027,40 @@ static bool prices_addbookentry(uint256 txid, std::vector &book) return false; } + +static bool prices_ispositionup(BetInfo p) { + if (p.vecparsed.size() <= 3) { + uint16_t opcode = p.vecparsed[0]; + + int32_t value = (opcode & (KOMODO_MAXPRICES - 1)); // index or weight + + if ((opcode & KOMODO_PRICEMASK)) { + char name[65]; + if (komodo_pricename(name, value)) { + std::string upperquote, bottomquote; + prices_splitpair(std::string(name), upperquote, bottomquote); + + if (upperquote == "BTC" || bottomquote == "BTC") { // it is relatively btc + if (upperquote == "BTC" && (p.leverage > 0 || (opcode & KOMODO_PRICEMASK) != PRICES_INV) || + bottomquote == "BTC" && (p.leverage < 0 || (opcode & KOMODO_PRICEMASK) == PRICES_INV)) + return true; + else + return false; + } + + if (upperquote == "USD" || bottomquote == "USD") { // it is relatively usd + if (upperquote == "USD" && (p.leverage > 0 || (opcode & KOMODO_PRICEMASK) != PRICES_INV) || + bottomquote == "USD" && (p.leverage < 0 || (opcode & KOMODO_PRICEMASK) == PRICES_INV)) + return true; + else + return false; + } + } + } + } + return false; +} + static bool prices_isopposite(BetInfo p1, BetInfo p2) { if (p1.vecparsed.size() <= 3 && p2.vecparsed.size() <= 3) { // simple synthetic exp @@ -2133,14 +2173,16 @@ UniValue PricesGetOrderbook() for (auto m : bookmatched) { int64_t totalLeveragedPositionUp = 0; int64_t totalLeveragedPositionDown = 0; - int64_t totalLeverageUp = 0; - int64_t totalLeverageDown = 0; - for (int i = 0; i < m.second.size(); i++) { - + int64_t betspos = 0; + for (auto bet : m.second[i].bets) betspos += bet.positionsize; + if (prices_ispositionup(m.second[i])) + totalLeveragedPositionUp += betspos * abs(m.second[i].leverage); + else + totalLeveragedPositionDown += betspos * abs(m.second[i].leverage); } - matchedTotals[m.first].diffLeveragedPosition = totalLeveragedPositionUp / totalLeverageUp - totalLeveragedPositionDown / totalLeverageDown; + matchedTotals[m.first].diffLeveragedPosition = totalLeveragedPositionUp - totalLeveragedPositionDown; } @@ -2156,6 +2198,7 @@ UniValue PricesGetOrderbook() result.push_back(Pair("unmatched", resbook)); */ for (auto m : bookmatched) { + UniValue mathedBookHeader(UniValue::VOBJ); UniValue resbook(UniValue::VARR); for (int i = 0; i < m.second.size(); i++) { UniValue entry(UniValue::VOBJ); @@ -2165,7 +2208,9 @@ UniValue PricesGetOrderbook() entry.push_back(Pair("equity", m.second[i].equity)); resbook.push_back(entry); } - result.push_back(Pair(m.first, resbook)); + mathedBookHeader.push_back(Pair("positions", resbook)); + mathedBookHeader.push_back(Pair("DiffLeveragedPosition", matchedTotals[m.first].diffLeveragedPosition)); + result.push_back(Pair(m.first, mathedBookHeader)); } int64_t totalLiabilities = 0; From cd58050445f584e7d8ffa40c007a4a96383a6e78 Mon Sep 17 00:00:00 2001 From: dimxy Date: Thu, 9 May 2019 17:46:37 +0500 Subject: [PATCH 337/447] changed back bet.positionsize calc --- src/cc/prices.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index e44e30cb7..a30f50994 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -1627,7 +1627,7 @@ int32_t prices_getbetinfo(uint256 bettxid, BetInfo &betinfo) betinfo.isOpen = true; // override with real amount (TODO: check this) - bet1.positionsize = bettx.vout[2].nValue; + //bet1.positionsize = bettx.vout[2].nValue; betinfo.bets.push_back(bet1); From 4d9de1ef923efb7e24716756ad401b274a37e088 Mon Sep 17 00:00:00 2001 From: dimxy Date: Thu, 9 May 2019 18:05:53 +0500 Subject: [PATCH 338/447] returned back err check --- src/cc/prices.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index a30f50994..11ad87353 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -1146,10 +1146,10 @@ int64_t prices_syntheticprice(std::vector vec, int32_t height, int32_t if (errcode != 0) std::cerr << "prices_syntheticprice errcode in switch=" << errcode << std::endl; - if( errcode = -1 ) { - std::cerr << "prices_syntheticprice error getting price (could be end of chain)" << std::endl; - return errcode; - } + //if( errcode = -1 ) { + // std::cerr << "prices_syntheticprice error getting price (could be end of chain)" << std::endl; + // return errcode; + //} if (errcode == -13) { std::cerr << "prices_syntheticprice overflow in price" << std::endl; From ab7d088b254e9a7c060a70e5cf4122ade19ec0f1 Mon Sep 17 00:00:00 2001 From: dimxy Date: Thu, 9 May 2019 18:18:04 +0500 Subject: [PATCH 339/447] corr errcode check in syntheticprice --- src/cc/prices.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 11ad87353..d71a3363c 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -1146,10 +1146,10 @@ int64_t prices_syntheticprice(std::vector vec, int32_t height, int32_t if (errcode != 0) std::cerr << "prices_syntheticprice errcode in switch=" << errcode << std::endl; - //if( errcode = -1 ) { - // std::cerr << "prices_syntheticprice error getting price (could be end of chain)" << std::endl; - // return errcode; - //} + if( errcode == -1 ) { + std::cerr << "prices_syntheticprice error getting price (could be end of chain)" << std::endl; + return errcode; + } if (errcode == -13) { std::cerr << "prices_syntheticprice overflow in price" << std::endl; From c8f56fb60973788c62510b358a0d0a44c3b83478 Mon Sep 17 00:00:00 2001 From: dimxy Date: Thu, 9 May 2019 20:08:57 +0500 Subject: [PATCH 340/447] isup pos flag added --- src/cc/prices.cpp | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index d71a3363c..8380a2010 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -95,7 +95,7 @@ typedef struct BetInfo { int64_t rektfee; int32_t lastheight; int16_t leverage; - bool isOpen, isRekt; + bool isOpen, isRekt, isUp; uint256 tokenid; std::vector vecparsed; @@ -107,7 +107,7 @@ typedef struct BetInfo { lastheight = 0; leverage = 0; rektfee = 0; - isOpen = isRekt = false; + isOpen = isRekt = isUp = false; } } BetInfo; @@ -1633,6 +1633,15 @@ int32_t prices_getbetinfo(uint256 bettxid, BetInfo &betinfo) prices_enumaddedbets(batontxid, betinfo.bets, bettxid); + if (!betinfo.isOpen) { + CTransaction finaltx; + uint256 hashBlock; + if (myGetTransaction(finaltxid, finaltx, hashBlock) && finaltx.vout.size() > 0 && prices_finalopretdecode) + { + } + } + + if (prices_scanchain(betinfo.bets, betinfo.leverage, betinfo.vecparsed, betinfo.lastprice, betinfo.lastheight) < 0) { return -4; } @@ -1793,7 +1802,7 @@ UniValue PricesRekt(int64_t txfee, uint256 bettxid, int32_t rektheight) mtx.vout.push_back(MakeCC1vout(cp->evalcode, CCchange, pricespk)); /// mtx.vout.push_back(MakeCC1vout(cp->evalcode, bettx.vout[2].nValue - myfee - txfee, pricespk)); // change - rawtx = FinalizeCCTx(0, cp, mtx, mypk, txfee, prices_finalopret(bettxid, totalprofits, rektheight, mypk, betinfo.firstprice, 0, totalbets /*- positionsize*/, 0/*positionsize*/, betinfo.leverage)); + rawtx = FinalizeCCTx(0, cp, mtx, mypk, txfee, prices_finalopret(bettxid, totalprofits, rektheight, mypk, betinfo.firstprice, betinfo.averageCostbasis, totalbets, 0, betinfo.leverage)); return(prices_rawtxresult(result, rawtx, 0)); } else @@ -1877,13 +1886,13 @@ UniValue PricesCashout(int64_t txfee, uint256 bettxid) } mtx.vin.push_back(CTxIn(bettxid, NVOUT_CCMARKER, CScript())); // spend cc marker - if ((inputsum = AddPricesInputs(cp, mtx, destaddr, betinfo.equity + txfee, 64)) > betinfo.equity + txfee) + if ((inputsum = AddPricesInputs(cp, mtx, destaddr, betinfo.equity + txfee, 64)) > betinfo.equity + txfee) // TODO: why txfee from the fund? CCchange = (inputsum - betinfo.equity); mtx.vout.push_back(CTxOut(betinfo.equity, CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); if (CCchange >= txfee) mtx.vout.push_back(MakeCC1vout(cp->evalcode, CCchange, pricespk)); // TODO: what should the opret param be: - rawtx = FinalizeCCTx(0, cp, mtx, mypk, txfee, prices_finalopret(bettxid, totalprofits, nextheight - 1, mypk, betinfo.firstprice, 0, totalbets/*- betinfo.positionsize*/, 0/*betinfo.positionsize*/, betinfo.leverage)); + rawtx = FinalizeCCTx(0, cp, mtx, mypk, txfee, prices_finalopret(bettxid, totalprofits, nextheight - 1, mypk, betinfo.firstprice, betinfo.averageCostbasis, totalbets, 0, betinfo.leverage)); return(prices_rawtxresult(result, rawtx, 0)); } @@ -2177,10 +2186,12 @@ UniValue PricesGetOrderbook() for (int i = 0; i < m.second.size(); i++) { int64_t betspos = 0; for (auto bet : m.second[i].bets) betspos += bet.positionsize; - if (prices_ispositionup(m.second[i])) + m.second[i].isUp = prices_ispositionup(m.second[i]); + if (m.second[i].isUp) totalLeveragedPositionUp += betspos * abs(m.second[i].leverage); else totalLeveragedPositionDown += betspos * abs(m.second[i].leverage); + } matchedTotals[m.first].diffLeveragedPosition = totalLeveragedPositionUp - totalLeveragedPositionDown; } @@ -2206,6 +2217,7 @@ UniValue PricesGetOrderbook() entry.push_back(Pair("costbasis", m.second[i].averageCostbasis)); entry.push_back(Pair("leverage", m.second[i].leverage)); entry.push_back(Pair("equity", m.second[i].equity)); + entry.push_back(Pair("isUpPosition", (m.second[i].isUp ? 1 : 0))); resbook.push_back(entry); } mathedBookHeader.push_back(Pair("positions", resbook)); From b297400d6c700bb09d9bbce772458ad96455396f Mon Sep 17 00:00:00 2001 From: dimxy Date: Thu, 9 May 2019 20:23:51 +0500 Subject: [PATCH 341/447] corr isup calc --- src/cc/prices.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 8380a2010..18a496a54 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -2043,23 +2043,25 @@ static bool prices_ispositionup(BetInfo p) { int32_t value = (opcode & (KOMODO_MAXPRICES - 1)); // index or weight - if ((opcode & KOMODO_PRICEMASK)) { + if ((opcode & KOMODO_PRICEMASK) == 0) { char name[65]; if (komodo_pricename(name, value)) { std::string upperquote, bottomquote; prices_splitpair(std::string(name), upperquote, bottomquote); + + uint16_t opcode1 = p.vecparsed[1]; if (upperquote == "BTC" || bottomquote == "BTC") { // it is relatively btc - if (upperquote == "BTC" && (p.leverage > 0 || (opcode & KOMODO_PRICEMASK) != PRICES_INV) || - bottomquote == "BTC" && (p.leverage < 0 || (opcode & KOMODO_PRICEMASK) == PRICES_INV)) + if (upperquote == "BTC" && (p.leverage > 0 || (opcode1 & KOMODO_PRICEMASK) != PRICES_INV) || + bottomquote == "BTC" && (p.leverage < 0 || (opcode1 & KOMODO_PRICEMASK) == PRICES_INV)) return true; else return false; } if (upperquote == "USD" || bottomquote == "USD") { // it is relatively usd - if (upperquote == "USD" && (p.leverage > 0 || (opcode & KOMODO_PRICEMASK) != PRICES_INV) || - bottomquote == "USD" && (p.leverage < 0 || (opcode & KOMODO_PRICEMASK) == PRICES_INV)) + if (upperquote == "USD" && (p.leverage > 0 || (opcode1 & KOMODO_PRICEMASK) != PRICES_INV) || + bottomquote == "USD" && (p.leverage < 0 || (opcode1 & KOMODO_PRICEMASK) == PRICES_INV)) return true; else return false; From 909d3cbafbff82853196d896427ff036be7be4c7 Mon Sep 17 00:00:00 2001 From: dimxy Date: Thu, 9 May 2019 20:44:17 +0500 Subject: [PATCH 342/447] logging added --- src/cc/prices.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 18a496a54..2430dd714 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -2038,10 +2038,10 @@ static bool prices_addbookentry(uint256 txid, std::vector &book) static bool prices_ispositionup(BetInfo p) { - if (p.vecparsed.size() <= 3) { + if (p.vecparsed.size() > 1 && p.vecparsed.size() <= 3) { uint16_t opcode = p.vecparsed[0]; - int32_t value = (opcode & (KOMODO_MAXPRICES - 1)); // index or weight + int32_t value = (opcode & (KOMODO_MAXPRICES - 1)); // filter index or weight = opcode & (2048-1) if ((opcode & KOMODO_PRICEMASK) == 0) { char name[65]; @@ -2051,18 +2051,24 @@ static bool prices_ispositionup(BetInfo p) { uint16_t opcode1 = p.vecparsed[1]; + std::cerr << "prices_ispositionup upperquote=" << upperquote << " bottomquote=" << bottomquote << " opcode1=" << opcode1 << " (opcode1 & KOMODO_PRICEMASK)=" << (opcode1 & KOMODO_PRICEMASK) << std::endl; + if (upperquote == "BTC" || bottomquote == "BTC") { // it is relatively btc if (upperquote == "BTC" && (p.leverage > 0 || (opcode1 & KOMODO_PRICEMASK) != PRICES_INV) || - bottomquote == "BTC" && (p.leverage < 0 || (opcode1 & KOMODO_PRICEMASK) == PRICES_INV)) + bottomquote == "BTC" && (p.leverage < 0 || (opcode1 & KOMODO_PRICEMASK) == PRICES_INV)) { + std::cerr << "prices_ispositionup return true for BTC" << std::endl; return true; + } else return false; } if (upperquote == "USD" || bottomquote == "USD") { // it is relatively usd if (upperquote == "USD" && (p.leverage > 0 || (opcode1 & KOMODO_PRICEMASK) != PRICES_INV) || - bottomquote == "USD" && (p.leverage < 0 || (opcode1 & KOMODO_PRICEMASK) == PRICES_INV)) + bottomquote == "USD" && (p.leverage < 0 || (opcode1 & KOMODO_PRICEMASK) == PRICES_INV)) { + std::cerr << "prices_ispositionup return true for USD" << std::endl; return true; + } else return false; } From 6489732013bdb45375c4cead6b06c6804b23d764 Mon Sep 17 00:00:00 2001 From: dimxy Date: Thu, 9 May 2019 21:01:28 +0500 Subject: [PATCH 343/447] more loggin --- src/cc/prices.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 2430dd714..55dfe706f 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -2199,6 +2199,7 @@ UniValue PricesGetOrderbook() totalLeveragedPositionUp += betspos * abs(m.second[i].leverage); else totalLeveragedPositionDown += betspos * abs(m.second[i].leverage); + std::cerr << "PricesGetOrderbook 0 m.second[i].isUp=" << m.second[i].isUp << " i=" << i << std::endl; } matchedTotals[m.first].diffLeveragedPosition = totalLeveragedPositionUp - totalLeveragedPositionDown; @@ -2216,6 +2217,7 @@ UniValue PricesGetOrderbook() } result.push_back(Pair("unmatched", resbook)); */ + // copy to rpc UniResult for (auto m : bookmatched) { UniValue mathedBookHeader(UniValue::VOBJ); UniValue resbook(UniValue::VARR); @@ -2225,6 +2227,7 @@ UniValue PricesGetOrderbook() entry.push_back(Pair("costbasis", m.second[i].averageCostbasis)); entry.push_back(Pair("leverage", m.second[i].leverage)); entry.push_back(Pair("equity", m.second[i].equity)); + std::cerr << "PricesGetOrderbook 1 m.second[i].isUp=" << m.second[i].isUp << " i=" << i << std::endl; entry.push_back(Pair("isUpPosition", (m.second[i].isUp ? 1 : 0))); resbook.push_back(entry); } From 7cb1794d9148cc5b1b6fe77c9f4618a556fbf033 Mon Sep 17 00:00:00 2001 From: dimxy Date: Thu, 9 May 2019 21:28:39 +0500 Subject: [PATCH 344/447] test --- src/cc/prices.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 55dfe706f..69ee376aa 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -95,13 +95,15 @@ typedef struct BetInfo { int64_t rektfee; int32_t lastheight; int16_t leverage; - bool isOpen, isRekt, isUp; + bool isOpen, isRekt; uint256 tokenid; std::vector vecparsed; std::vector bets; CPubKey pk; + bool isUp; + BetInfo() { averageCostbasis = firstprice = lastprice = liquidationprice = equity = 0; lastheight = 0; @@ -2181,6 +2183,7 @@ UniValue PricesGetOrderbook() } else { totalRekt += (betspos - book[0].rektfee); + //TODO: store rekt } book.erase(book.begin()); } From 60d585913618891174be0cdb3b8ea8746c040e18 Mon Sep 17 00:00:00 2001 From: dimxy Date: Thu, 9 May 2019 21:37:04 +0500 Subject: [PATCH 345/447] test --- src/cc/prices.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 69ee376aa..ffd9d04e2 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -2190,7 +2190,7 @@ UniValue PricesGetOrderbook() // calculate cancelling amount std::map matchedTotals; - for (auto m : bookmatched) { + for (auto &m : bookmatched) { int64_t totalLeveragedPositionUp = 0; int64_t totalLeveragedPositionDown = 0; @@ -2221,11 +2221,12 @@ UniValue PricesGetOrderbook() result.push_back(Pair("unmatched", resbook)); */ // copy to rpc UniResult - for (auto m : bookmatched) { + for (auto &m : bookmatched) { UniValue mathedBookHeader(UniValue::VOBJ); UniValue resbook(UniValue::VARR); for (int i = 0; i < m.second.size(); i++) { UniValue entry(UniValue::VOBJ); + entry.push_back(Pair("isOpen", (m.second[i].isOpen ? 1 : 0 ))); entry.push_back(Pair("expression", prices_getsourceexpression(m.second[i].vecparsed))); entry.push_back(Pair("costbasis", m.second[i].averageCostbasis)); entry.push_back(Pair("leverage", m.second[i].leverage)); From 039a3128f2d3e3abc4e5955605d4475f50eb2342 Mon Sep 17 00:00:00 2001 From: dimxy Date: Fri, 10 May 2019 01:50:33 +0500 Subject: [PATCH 346/447] added check amount acceptable --- src/cc/prices.cpp | 160 ++++++++++++++++++++++++++++++++-------------- 1 file changed, 112 insertions(+), 48 deletions(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index ffd9d04e2..87fc17e4e 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -119,7 +119,16 @@ typedef struct MatchedBookTotal { } MatchedBookTotal; +typedef struct TotalFund { + int64_t totalFund; + int64_t totalBets; + int64_t totalRekt; + int64_t totalEquity; + +} TotalFund; + int32_t prices_syntheticprofits(int64_t &costbasis, int32_t firstheight, int32_t height, int16_t leverage, std::vector vec, int64_t positionsize, int64_t &profits, int64_t &outprice); +static bool prices_isacceptableamount(const std::vector &vecparsed, int64_t amount, int16_t leverage); // helpers: @@ -1423,6 +1432,13 @@ UniValue PricesBet(int64_t txfee, int64_t amount, int16_t leverage, std::vector< result.push_back(Pair("error", "invalid synthetic")); return(result); } + + if (prices_isacceptableamount(vec, amount, leverage)) { + result.push_back(Pair("result", "error")); + result.push_back(Pair("error", "too large amount and leverage")); + return(result); + } + if (AddNormalinputs(mtx, mypk, amount + 4 * txfee, 64) >= amount + 4 * txfee) { betamount = (amount * 199) / 200; @@ -1431,14 +1447,14 @@ UniValue PricesBet(int64_t txfee, int64_t amount, int16_t leverage, std::vector< mtx.vout.push_back(MakeCC1vout(cp->evalcode, txfee, pricespk)); // vout1 cc marker (NVOUT_CCMARKER) mtx.vout.push_back(MakeCC1vout(cp->evalcode, betamount, pricespk)); // vout2 betamount mtx.vout.push_back(CTxOut(txfee, CScript() << ParseHex(HexStr(pricespk)) << OP_CHECKSIG)); // vout3 normal marker NVOUT_NORMALMARKER - TODO: remove it as we have cc marker now, when move to the new chain - if ( ASSETCHAINS_EARLYTXIDCONTRACT == EVAL_PRICES && KOMODO_EARLYTXID_SCRIPTPUB.size() == 0 ) + /*if ( ASSETCHAINS_EARLYTXIDCONTRACT == EVAL_PRICES && KOMODO_EARLYTXID_SCRIPTPUB.size() == 0 ) { // Lock here, as in validation we cannot call lock in the function itself. // may not be needed as the validation call to update the global, is called in a LOCK already, and it can only update there and here. LOCK(cs_main); GetKomodoEarlytxidScriptPub(); } - mtx.vout.push_back(CTxOut(amount-betamount, KOMODO_EARLYTXID_SCRIPTPUB)); + mtx.vout.push_back(CTxOut(amount-betamount, KOMODO_EARLYTXID_SCRIPTPUB)); */ rawtx = FinalizeCCTx(0, cp, mtx, mypk, txfee, prices_betopret(mypk, nextheight - 1, amount, leverage, firstprice, vec, zeroid)); return(prices_rawtxresult(result, rawtx, 0)); @@ -1635,13 +1651,13 @@ int32_t prices_getbetinfo(uint256 bettxid, BetInfo &betinfo) prices_enumaddedbets(batontxid, betinfo.bets, bettxid); - if (!betinfo.isOpen) { + /*if (!betinfo.isOpen) { CTransaction finaltx; uint256 hashBlock; if (myGetTransaction(finaltxid, finaltx, hashBlock) && finaltx.vout.size() > 0 && prices_finalopretdecode) { } - } + }*/ if (prices_scanchain(betinfo.bets, betinfo.leverage, betinfo.vecparsed, betinfo.lastprice, betinfo.lastheight) < 0) { @@ -2039,9 +2055,9 @@ static bool prices_addbookentry(uint256 txid, std::vector &book) } -static bool prices_ispositionup(BetInfo p) { - if (p.vecparsed.size() > 1 && p.vecparsed.size() <= 3) { - uint16_t opcode = p.vecparsed[0]; +static bool prices_ispositionup(const std::vector &vecparsed, int16_t leverage) { + if (vecparsed.size() > 1 && vecparsed.size() <= 3) { + uint16_t opcode = vecparsed[0]; int32_t value = (opcode & (KOMODO_MAXPRICES - 1)); // filter index or weight = opcode & (2048-1) @@ -2051,13 +2067,13 @@ static bool prices_ispositionup(BetInfo p) { std::string upperquote, bottomquote; prices_splitpair(std::string(name), upperquote, bottomquote); - uint16_t opcode1 = p.vecparsed[1]; + uint16_t opcode1 = vecparsed[1]; - std::cerr << "prices_ispositionup upperquote=" << upperquote << " bottomquote=" << bottomquote << " opcode1=" << opcode1 << " (opcode1 & KOMODO_PRICEMASK)=" << (opcode1 & KOMODO_PRICEMASK) << std::endl; + //std::cerr << "prices_ispositionup upperquote=" << upperquote << " bottomquote=" << bottomquote << " opcode1=" << opcode1 << " (opcode1 & KOMODO_PRICEMASK)=" << (opcode1 & KOMODO_PRICEMASK) << std::endl; if (upperquote == "BTC" || bottomquote == "BTC") { // it is relatively btc - if (upperquote == "BTC" && (p.leverage > 0 || (opcode1 & KOMODO_PRICEMASK) != PRICES_INV) || - bottomquote == "BTC" && (p.leverage < 0 || (opcode1 & KOMODO_PRICEMASK) == PRICES_INV)) { + if (upperquote == "BTC" && (leverage > 0 || (opcode1 & KOMODO_PRICEMASK) != PRICES_INV) || + bottomquote == "BTC" && (leverage < 0 || (opcode1 & KOMODO_PRICEMASK) == PRICES_INV)) { std::cerr << "prices_ispositionup return true for BTC" << std::endl; return true; } @@ -2066,8 +2082,8 @@ static bool prices_ispositionup(BetInfo p) { } if (upperquote == "USD" || bottomquote == "USD") { // it is relatively usd - if (upperquote == "USD" && (p.leverage > 0 || (opcode1 & KOMODO_PRICEMASK) != PRICES_INV) || - bottomquote == "USD" && (p.leverage < 0 || (opcode1 & KOMODO_PRICEMASK) == PRICES_INV)) { + if (upperquote == "USD" && (leverage > 0 || (opcode1 & KOMODO_PRICEMASK) != PRICES_INV) || + bottomquote == "USD" && (leverage < 0 || (opcode1 & KOMODO_PRICEMASK) == PRICES_INV)) { std::cerr << "prices_ispositionup return true for USD" << std::endl; return true; } @@ -2111,15 +2127,30 @@ static bool prices_isopposite(BetInfo p1, BetInfo p2) { } -// walk through uxtos on the global address -// calculate the balance: -// + rekt positions -// = opposite positions -// - unbalanced positions -UniValue PricesGetOrderbook() + +static std::string findMatchedBook(const std::vector &vecparsed, const std::map > & bookmatched) { + + if (vecparsed.size() > 1 && vecparsed.size() <= 3) { + uint16_t opcode = vecparsed[0]; + + int32_t value = (opcode & (KOMODO_MAXPRICES - 1)); // filter index or weight = opcode & (2048-1) + + if ((opcode & KOMODO_PRICEMASK) == 0) { + char name[65]; + if (komodo_pricename(name, value)) { + auto it = bookmatched.find(std::string(name)); + if (it != bookmatched.end()) + return it->first; + } + } + } + return std::string(""); +} + + +void prices_getorderbook(std::map > & bookmatched, std::map &matchedTotals, TotalFund &fundTotals) { - UniValue result(UniValue::VOBJ); - std::vector book, opposits; + std::vector book; std::vector > addressIndex; struct CCcontract_info *cp, C; @@ -2135,29 +2166,25 @@ UniValue PricesGetOrderbook() // calc total fund amount - int64_t totalfund = 0; + fundTotals.totalFund = 0; std::vector > addressCCunspents; SetCCunspents(addressCCunspents, cp->unspendableCCaddr, true); // cc marker for (std::vector >::const_iterator it = addressCCunspents.begin(); it != addressCCunspents.end(); it++) { std::cerr << "totalfund calc txid=" << it->first.txhash.GetHex() << " nvout=" << it->first.index << " satoshis=" << it->second.satoshis << std::endl; - totalfund += it->second.satoshis; + fundTotals.totalFund += it->second.satoshis; } - + // extract out opposite bets: - std::map > bookmatched; - int64_t totalBets = 0; - int64_t totalRekt = 0; - int64_t totalEquity = 0; while (book.size() > 0) { int64_t betspos = 0; for (auto bet : book[0].bets) betspos += bet.positionsize; - + if (!book[0].isRekt) { - - totalBets += betspos; - totalEquity += book[0].equity; + + fundTotals.totalBets += betspos; + fundTotals.totalEquity += book[0].equity; if (book[0].vecparsed.size() <= 3) { // only short expr check for match: "BTC_USD,1" or "BTC_USD,!,1" char name[65]; @@ -2182,14 +2209,13 @@ UniValue PricesGetOrderbook() } } else { - totalRekt += (betspos - book[0].rektfee); + fundTotals.totalRekt += (betspos - book[0].rektfee); //TODO: store rekt } book.erase(book.begin()); } // calculate cancelling amount - std::map matchedTotals; for (auto &m : bookmatched) { int64_t totalLeveragedPositionUp = 0; int64_t totalLeveragedPositionDown = 0; @@ -2197,17 +2223,55 @@ UniValue PricesGetOrderbook() for (int i = 0; i < m.second.size(); i++) { int64_t betspos = 0; for (auto bet : m.second[i].bets) betspos += bet.positionsize; - m.second[i].isUp = prices_ispositionup(m.second[i]); + m.second[i].isUp = prices_ispositionup(m.second[i].vecparsed, m.second[i].leverage); if (m.second[i].isUp) totalLeveragedPositionUp += betspos * abs(m.second[i].leverage); else totalLeveragedPositionDown += betspos * abs(m.second[i].leverage); - std::cerr << "PricesGetOrderbook 0 m.second[i].isUp=" << m.second[i].isUp << " i=" << i << std::endl; - + //std::cerr << "PricesGetOrderbook 0 m.second[i].isUp=" << m.second[i].isUp << " i=" << i << std::endl; + } matchedTotals[m.first].diffLeveragedPosition = totalLeveragedPositionUp - totalLeveragedPositionDown; } +} +static bool prices_isacceptableamount(const std::vector &vecparsed, int64_t amount, int16_t leverage) { + + std::map > matchedBook; + std::map matchedTotals; + TotalFund fundTotals; + + prices_getorderbook(matchedBook, matchedTotals, fundTotals); + std::string pricename = findMatchedBook(vecparsed, matchedBook); + if (!pricename.empty()) { + std::cerr << "IsAcceptableAmount() found matched book=" << pricename << " diffLeveragedPosition=" << matchedTotals[pricename].diffLeveragedPosition << std::endl; + // could fit into leveraged amount + if ((prices_ispositionup(vecparsed, leverage) || leverage > 0) && amount*abs(leverage) + matchedTotals[pricename].diffLeveragedPosition <= 0) { + std::cerr << "IsAcceptableAmount() could fit into opposite negative lev amount" << std::endl; + return true; + } + if ((!prices_ispositionup(vecparsed, leverage) || leverage < 0) && -amount*abs(leverage) + matchedTotals[pricename].diffLeveragedPosition >= 0) { + std::cerr << "IsAcceptableAmount() could fit into opposite positive lev amount" << std::endl; + return true; + } + } + return false; +} + + +// walk through uxtos on the global address +// calculate the balance: +// + rekt positions +// = opposite positions +// - unbalanced positions +UniValue PricesGetOrderbook() +{ + UniValue result(UniValue::VOBJ); + std::map > matchedBook; + std::map matchedTotals; + TotalFund fundTotals; + + prices_getorderbook(matchedBook, matchedTotals, fundTotals); /*UniValue resbook (UniValue::VARR); for (int i = 0; i < book.size(); i++) { @@ -2221,8 +2285,8 @@ UniValue PricesGetOrderbook() result.push_back(Pair("unmatched", resbook)); */ // copy to rpc UniResult - for (auto &m : bookmatched) { - UniValue mathedBookHeader(UniValue::VOBJ); + for (auto &m : matchedBook) { + UniValue resheader(UniValue::VOBJ); UniValue resbook(UniValue::VARR); for (int i = 0; i < m.second.size(); i++) { UniValue entry(UniValue::VOBJ); @@ -2231,16 +2295,16 @@ UniValue PricesGetOrderbook() entry.push_back(Pair("costbasis", m.second[i].averageCostbasis)); entry.push_back(Pair("leverage", m.second[i].leverage)); entry.push_back(Pair("equity", m.second[i].equity)); - std::cerr << "PricesGetOrderbook 1 m.second[i].isUp=" << m.second[i].isUp << " i=" << i << std::endl; + //std::cerr << "PricesGetOrderbook 1 m.second[i].isUp=" << m.second[i].isUp << " i=" << i << std::endl; entry.push_back(Pair("isUpPosition", (m.second[i].isUp ? 1 : 0))); resbook.push_back(entry); } - mathedBookHeader.push_back(Pair("positions", resbook)); - mathedBookHeader.push_back(Pair("DiffLeveragedPosition", matchedTotals[m.first].diffLeveragedPosition)); - result.push_back(Pair(m.first, mathedBookHeader)); + resheader.push_back(Pair("positions", resbook)); + resheader.push_back(Pair("DiffLeveragedPosition", matchedTotals[m.first].diffLeveragedPosition)); + result.push_back(Pair(m.first, resheader)); } - int64_t totalLiabilities = 0; + //int64_t totalLiabilities = 0; /* empty for (int i = 0; i < book.size(); i++) { if (book[i].isOpen) { @@ -2251,10 +2315,10 @@ UniValue PricesGetOrderbook() } } */ - result.push_back(Pair("TotalFund", ValueFromAmount(totalfund))); - result.push_back(Pair("TotalRekt", ValueFromAmount(totalRekt))); - result.push_back(Pair("TotalBets", ValueFromAmount(totalBets))); - result.push_back(Pair("TotalEquity", ValueFromAmount(totalEquity))); + result.push_back(Pair("TotalFund", ValueFromAmount(fundTotals.totalFund))); + result.push_back(Pair("TotalRekt", ValueFromAmount(fundTotals.totalRekt))); + result.push_back(Pair("TotalBets", ValueFromAmount(fundTotals.totalBets))); + result.push_back(Pair("TotalEquity", ValueFromAmount(fundTotals.totalEquity))); // result.push_back(Pair("TotalLiabilities", ValueFromAmount(totalLiabilities))); From e286938a2215c68d8ded3b3bd9f668982d7d23c2 Mon Sep 17 00:00:00 2001 From: dimxy Date: Fri, 10 May 2019 01:59:45 +0500 Subject: [PATCH 347/447] corr check amount and lev in pricebet --- src/cc/prices.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 87fc17e4e..edc71867b 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -1433,9 +1433,9 @@ UniValue PricesBet(int64_t txfee, int64_t amount, int16_t leverage, std::vector< return(result); } - if (prices_isacceptableamount(vec, amount, leverage)) { + if (!prices_isacceptableamount(vec, amount, leverage)) { result.push_back(Pair("result", "error")); - result.push_back(Pair("error", "too large amount and leverage")); + result.push_back(Pair("error", "too big amount and leverage")); return(result); } @@ -2244,14 +2244,14 @@ static bool prices_isacceptableamount(const std::vector &vecparsed, in prices_getorderbook(matchedBook, matchedTotals, fundTotals); std::string pricename = findMatchedBook(vecparsed, matchedBook); if (!pricename.empty()) { - std::cerr << "IsAcceptableAmount() found matched book=" << pricename << " diffLeveragedPosition=" << matchedTotals[pricename].diffLeveragedPosition << std::endl; + std::cerr << "prices_isacceptableamount() found matched book=" << pricename << " diffLeveragedPosition=" << matchedTotals[pricename].diffLeveragedPosition << std::endl; // could fit into leveraged amount if ((prices_ispositionup(vecparsed, leverage) || leverage > 0) && amount*abs(leverage) + matchedTotals[pricename].diffLeveragedPosition <= 0) { - std::cerr << "IsAcceptableAmount() could fit into opposite negative lev amount" << std::endl; + std::cerr << "prices_isacceptableamount() could fit into opposite negative lev amount" << std::endl; return true; } if ((!prices_ispositionup(vecparsed, leverage) || leverage < 0) && -amount*abs(leverage) + matchedTotals[pricename].diffLeveragedPosition >= 0) { - std::cerr << "IsAcceptableAmount() could fit into opposite positive lev amount" << std::endl; + std::cerr << "prices_isacceptableamount() could fit into opposite positive lev amount" << std::endl; return true; } } From fa1a0875fc0272fef2fd42e1ba30c5cfe304ebc4 Mon Sep 17 00:00:00 2001 From: dimxy Date: Fri, 10 May 2019 10:24:45 +0500 Subject: [PATCH 348/447] logging added --- src/cc/prices.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index edc71867b..916528fc4 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -2069,7 +2069,7 @@ static bool prices_ispositionup(const std::vector &vecparsed, int16_t uint16_t opcode1 = vecparsed[1]; - //std::cerr << "prices_ispositionup upperquote=" << upperquote << " bottomquote=" << bottomquote << " opcode1=" << opcode1 << " (opcode1 & KOMODO_PRICEMASK)=" << (opcode1 & KOMODO_PRICEMASK) << std::endl; + std::cerr << "prices_ispositionup upperquote=" << upperquote << " bottomquote=" << bottomquote << " opcode1=" << opcode1 << " (opcode1 & KOMODO_PRICEMASK)=" << (opcode1 & KOMODO_PRICEMASK) << std::endl; if (upperquote == "BTC" || bottomquote == "BTC") { // it is relatively btc if (upperquote == "BTC" && (leverage > 0 || (opcode1 & KOMODO_PRICEMASK) != PRICES_INV) || @@ -2246,11 +2246,11 @@ static bool prices_isacceptableamount(const std::vector &vecparsed, in if (!pricename.empty()) { std::cerr << "prices_isacceptableamount() found matched book=" << pricename << " diffLeveragedPosition=" << matchedTotals[pricename].diffLeveragedPosition << std::endl; // could fit into leveraged amount - if ((prices_ispositionup(vecparsed, leverage) || leverage > 0) && amount*abs(leverage) + matchedTotals[pricename].diffLeveragedPosition <= 0) { + if (prices_ispositionup(vecparsed, leverage) && amount*abs(leverage) + matchedTotals[pricename].diffLeveragedPosition <= 0) { std::cerr << "prices_isacceptableamount() could fit into opposite negative lev amount" << std::endl; return true; } - if ((!prices_ispositionup(vecparsed, leverage) || leverage < 0) && -amount*abs(leverage) + matchedTotals[pricename].diffLeveragedPosition >= 0) { + if (!prices_ispositionup(vecparsed, leverage) && -amount*abs(leverage) + matchedTotals[pricename].diffLeveragedPosition >= 0) { std::cerr << "prices_isacceptableamount() could fit into opposite positive lev amount" << std::endl; return true; } From 00d5328699be240d7883eab788046f193e6b5d2f Mon Sep 17 00:00:00 2001 From: dimxy Date: Fri, 10 May 2019 10:32:44 +0500 Subject: [PATCH 349/447] more logging --- src/cc/prices.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 916528fc4..08cd20575 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -2244,7 +2244,7 @@ static bool prices_isacceptableamount(const std::vector &vecparsed, in prices_getorderbook(matchedBook, matchedTotals, fundTotals); std::string pricename = findMatchedBook(vecparsed, matchedBook); if (!pricename.empty()) { - std::cerr << "prices_isacceptableamount() found matched book=" << pricename << " diffLeveragedPosition=" << matchedTotals[pricename].diffLeveragedPosition << std::endl; + std::cerr << "prices_isacceptableamount() found matched book=" << pricename << " diffLeveragedPosition=" << matchedTotals[pricename].diffLeveragedPosition << "expr=" << prices_getsourceexpression(vecparsed) << std::endl; // could fit into leveraged amount if (prices_ispositionup(vecparsed, leverage) && amount*abs(leverage) + matchedTotals[pricename].diffLeveragedPosition <= 0) { std::cerr << "prices_isacceptableamount() could fit into opposite negative lev amount" << std::endl; From 8a910e5952382b26aaa86b8495ec881c0691a768 Mon Sep 17 00:00:00 2001 From: dimxy Date: Fri, 10 May 2019 10:56:40 +0500 Subject: [PATCH 350/447] corr logic expr --- src/cc/prices.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 08cd20575..a902ef5e5 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -2068,12 +2068,13 @@ static bool prices_ispositionup(const std::vector &vecparsed, int16_t prices_splitpair(std::string(name), upperquote, bottomquote); uint16_t opcode1 = vecparsed[1]; + bool isInverted = ((opcode1 & KOMODO_PRICEMASK) == PRICES_INV); std::cerr << "prices_ispositionup upperquote=" << upperquote << " bottomquote=" << bottomquote << " opcode1=" << opcode1 << " (opcode1 & KOMODO_PRICEMASK)=" << (opcode1 & KOMODO_PRICEMASK) << std::endl; if (upperquote == "BTC" || bottomquote == "BTC") { // it is relatively btc - if (upperquote == "BTC" && (leverage > 0 || (opcode1 & KOMODO_PRICEMASK) != PRICES_INV) || - bottomquote == "BTC" && (leverage < 0 || (opcode1 & KOMODO_PRICEMASK) == PRICES_INV)) { + if (upperquote == "BTC" && (leverage > 0 && !isInverted || leverage < 0 && isInverted) || + bottomquote == "BTC" && (leverage < 0 && !isInverted || leverage > 0 && isInverted)) { std::cerr << "prices_ispositionup return true for BTC" << std::endl; return true; } @@ -2082,8 +2083,8 @@ static bool prices_ispositionup(const std::vector &vecparsed, int16_t } if (upperquote == "USD" || bottomquote == "USD") { // it is relatively usd - if (upperquote == "USD" && (leverage > 0 || (opcode1 & KOMODO_PRICEMASK) != PRICES_INV) || - bottomquote == "USD" && (leverage < 0 || (opcode1 & KOMODO_PRICEMASK) == PRICES_INV)) { + if (upperquote == "USD" && (leverage > 0 && !isInverted || leverage < 0 && isInverted) || + bottomquote == "USD" && (leverage < 0 && !isInverted || leverage > 0 && isInverted)) { std::cerr << "prices_ispositionup return true for USD" << std::endl; return true; } From 31030492e5eb6d07222db9f631809932dac75a7b Mon Sep 17 00:00:00 2001 From: dimxy Date: Fri, 10 May 2019 12:04:36 +0500 Subject: [PATCH 351/447] added check amount for 10% --- src/cc/prices.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index a902ef5e5..edcd430f4 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -2256,6 +2256,11 @@ static bool prices_isacceptableamount(const std::vector &vecparsed, in return true; } } + + // if not fit to matched = allow to bet for leveraged amount no more than 10% from free fund + if (amount * leverage < (fundTotals.totalFund - fundTotals.totalEquity) * 0.1) + return true; + return false; } From 771d5d8b84746dbcab5fd6b413e8c2b6161cc6b2 Mon Sep 17 00:00:00 2001 From: dimxy Date: Fri, 10 May 2019 12:39:52 +0500 Subject: [PATCH 352/447] added > 5342 height --- src/cc/prices.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index edcd430f4..fb5bd363b 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -1630,6 +1630,12 @@ int32_t prices_getbetinfo(uint256 bettxid, BetInfo &betinfo) if (hashBlock.IsNull()) return -2; + + // TODO: forget old tx + CBlockIndex *bi = komodo_getblockindex(hashBlock); + if (bi && bi->GetHeight() > 5342) + return -5; + OneBetData bet1; if (prices_betopretdecode(bettx.vout.back().scriptPubKey, betinfo.pk, bet1.firstheight, bet1.positionsize, betinfo.leverage, betinfo.firstprice, betinfo.vecparsed, betinfo.tokenid) == 'B') { @@ -2002,6 +2008,12 @@ UniValue PricesList(uint32_t filter, CPubKey mypk) if (GetTransaction(txid, vintx, hashBlock, false) != 0) { + + // TODO: forget old tx + CBlockIndex *bi = komodo_getblockindex(hashBlock); + if (bi && bi->GetHeight() > 5342) + return; + bool bAppend = false; if (vintx.vout.size() > 0 && prices_betopretdecode(vintx.vout.back().scriptPubKey, pk, height, amount, leverage, firstprice, vec, tokenid) == 'B' && (mypk == CPubKey() || mypk == pk)) // if only mypubkey to list From bb2ade543c52564bf94d9585ee8431a456abe583 Mon Sep 17 00:00:00 2001 From: dimxy Date: Fri, 10 May 2019 12:47:25 +0500 Subject: [PATCH 353/447] corr height --- src/cc/prices.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index fb5bd363b..4682df726 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -1633,7 +1633,7 @@ int32_t prices_getbetinfo(uint256 bettxid, BetInfo &betinfo) // TODO: forget old tx CBlockIndex *bi = komodo_getblockindex(hashBlock); - if (bi && bi->GetHeight() > 5342) + if (bi && bi->GetHeight() < 5342) return -5; OneBetData bet1; @@ -2011,7 +2011,7 @@ UniValue PricesList(uint32_t filter, CPubKey mypk) // TODO: forget old tx CBlockIndex *bi = komodo_getblockindex(hashBlock); - if (bi && bi->GetHeight() > 5342) + if (bi && bi->GetHeight() < 5342) return; bool bAppend = false; From 8975bbf9c9de2e92183a827b8a52e0c02c37dc06 Mon Sep 17 00:00:00 2001 From: dimxy Date: Fri, 10 May 2019 15:01:44 +0500 Subject: [PATCH 354/447] added check amount for addbet rpc --- src/cc/prices.cpp | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 4682df726..a1f13122f 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -1388,7 +1388,7 @@ int64_t prices_enumaddedbets(uint256 &batontxid, std::vector &bets, addedBetsTotal += amount; added.positionsize = amount; - added.firstheight = blockIdx.GetHeight(); + added.firstheight = blockIdx.GetHeight(); //TODO: check if this is correct (to get height from the block not from the opret) bets.push_back(added); //std::cerr << "prices_batontxid() added amount=" << amount << std::endl; } @@ -1469,11 +1469,14 @@ UniValue PricesAddFunding(int64_t txfee, uint256 bettxid, int64_t amount) { int32_t nextheight = komodo_nextheight(); CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), nextheight); UniValue result(UniValue::VOBJ); - struct CCcontract_info *cp, C; CTransaction bettx; - CPubKey pricespk, mypk; - //int64_t addedbets = 0, betamount, firstprice; - std::vector vec; - uint256 batontxid; + struct CCcontract_info *cp, C; + CTransaction bettx; + CPubKey pricespk, mypk, pk; + int64_t positionsize, betamount, firstprice; + int32_t firstheight; + std::vector vecparsed; + uint256 batontxid, tokenid, hashBlock; + int16_t leverage; std::string rawtx; //char myaddr[64]; @@ -1482,7 +1485,22 @@ UniValue PricesAddFunding(int64_t txfee, uint256 bettxid, int64_t amount) txfee = PRICES_TXFEE; mypk = pubkey2pk(Mypubkey()); pricespk = GetUnspendable(cp, 0); - //GetCCaddress(cp, myaddr, mypk); + + if (!myGetTransaction(bettxid, bettx, hashBlock) || + bettx.vout.size() <= 3 || + hashBlock.IsNull() || + prices_betopretdecode(bettx.vout.back().scriptPubKey, pk, firstheight, positionsize, leverage, firstprice, vecparsed, tokenid) != 'B') { + result.push_back(Pair("result", "error")); + result.push_back(Pair("error", "invalid bet tx")); + return(result); + } + + if (!prices_isacceptableamount(vecparsed, amount, leverage)) { + result.push_back(Pair("result", "error")); + result.push_back(Pair("error", "too big amount and leverage")); + return(result); + } + if (AddNormalinputs(mtx, mypk, amount + 2*txfee, 64) >= amount + 2*txfee) { std::vector bets; @@ -2229,7 +2247,7 @@ void prices_getorderbook(std::map > & bookmatc } // calculate cancelling amount - for (auto &m : bookmatched) { + for (auto &m : bookmatched) { // note: use reference &m otherwise isUp will be changed only in a copy int64_t totalLeveragedPositionUp = 0; int64_t totalLeveragedPositionDown = 0; From a6194b8c04eeb954a3d21a93058e752bed9cdbf1 Mon Sep 17 00:00:00 2001 From: dimxy Date: Fri, 10 May 2019 15:23:45 +0500 Subject: [PATCH 355/447] added logging --- src/cc/prices.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index a1f13122f..657b389de 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -1476,7 +1476,7 @@ UniValue PricesAddFunding(int64_t txfee, uint256 bettxid, int64_t amount) int32_t firstheight; std::vector vecparsed; uint256 batontxid, tokenid, hashBlock; - int16_t leverage; + int16_t leverage = 0; std::string rawtx; //char myaddr[64]; @@ -2287,6 +2287,7 @@ static bool prices_isacceptableamount(const std::vector &vecparsed, in } } + std::cerr << "prices_isacceptableamount() amount=" << amount << " leverage=" << leverage << " fundTotals.totalFund=" << fundTotals.totalFund << " fundTotals.totalEquity=" << fundTotals.totalEquity << std::endl; // if not fit to matched = allow to bet for leveraged amount no more than 10% from free fund if (amount * leverage < (fundTotals.totalFund - fundTotals.totalEquity) * 0.1) return true; From 239cc223e49b4ec600d881669c1b8602454c33b9 Mon Sep 17 00:00:00 2001 From: dimxy Date: Fri, 10 May 2019 15:40:00 +0500 Subject: [PATCH 356/447] init uninited total vars --- src/cc/prices.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 657b389de..26c2c887e 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -125,6 +125,10 @@ typedef struct TotalFund { int64_t totalRekt; int64_t totalEquity; + TotalFund() { + totalFund = totalBets = totalRekt = totalEquity = 0; + } + } TotalFund; int32_t prices_syntheticprofits(int64_t &costbasis, int32_t firstheight, int32_t height, int16_t leverage, std::vector vec, int64_t positionsize, int64_t &profits, int64_t &outprice); @@ -2198,6 +2202,10 @@ void prices_getorderbook(std::map > & bookmatc // calc total fund amount fundTotals.totalFund = 0; + fundTotals.totalRekt = 0; + fundTotals.totalEquity = 0; + fundTotals.totalBets = 0; + std::vector > addressCCunspents; SetCCunspents(addressCCunspents, cp->unspendableCCaddr, true); // cc marker for (std::vector >::const_iterator it = addressCCunspents.begin(); it != addressCCunspents.end(); it++) @@ -2275,7 +2283,7 @@ static bool prices_isacceptableamount(const std::vector &vecparsed, in prices_getorderbook(matchedBook, matchedTotals, fundTotals); std::string pricename = findMatchedBook(vecparsed, matchedBook); if (!pricename.empty()) { - std::cerr << "prices_isacceptableamount() found matched book=" << pricename << " diffLeveragedPosition=" << matchedTotals[pricename].diffLeveragedPosition << "expr=" << prices_getsourceexpression(vecparsed) << std::endl; + std::cerr << "prices_isacceptableamount() found matched book=" << pricename << " diffLeveragedPosition=" << matchedTotals[pricename].diffLeveragedPosition << " expr=" << prices_getsourceexpression(vecparsed) << std::endl; // could fit into leveraged amount if (prices_ispositionup(vecparsed, leverage) && amount*abs(leverage) + matchedTotals[pricename].diffLeveragedPosition <= 0) { std::cerr << "prices_isacceptableamount() could fit into opposite negative lev amount" << std::endl; From adcb0315514845a01456e7be367c1f81fd3b3126 Mon Sep 17 00:00:00 2001 From: dimxy Date: Fri, 10 May 2019 16:42:01 +0500 Subject: [PATCH 357/447] logic expr optimized logging added --- src/cc/prices.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 26c2c887e..fe80e9bdd 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -2109,7 +2109,7 @@ static bool prices_ispositionup(const std::vector &vecparsed, int16_t if (upperquote == "BTC" || bottomquote == "BTC") { // it is relatively btc if (upperquote == "BTC" && (leverage > 0 && !isInverted || leverage < 0 && isInverted) || bottomquote == "BTC" && (leverage < 0 && !isInverted || leverage > 0 && isInverted)) { - std::cerr << "prices_ispositionup return true for BTC" << std::endl; + std::cerr << "prices_ispositionup return true for BTC for expr=" << prices_getsourceexpression(vecparsed) << std::endl; return true; } else @@ -2119,7 +2119,7 @@ static bool prices_ispositionup(const std::vector &vecparsed, int16_t if (upperquote == "USD" || bottomquote == "USD") { // it is relatively usd if (upperquote == "USD" && (leverage > 0 && !isInverted || leverage < 0 && isInverted) || bottomquote == "USD" && (leverage < 0 && !isInverted || leverage > 0 && isInverted)) { - std::cerr << "prices_ispositionup return true for USD" << std::endl; + std::cerr << "prices_ispositionup return true for USD for expr=" << prices_getsourceexpression(vecparsed) << std::endl; return true; } else @@ -2128,6 +2128,7 @@ static bool prices_ispositionup(const std::vector &vecparsed, int16_t } } } + std::cerr << "prices_ispositionup returns false for expr=" << prices_getsourceexpression(vecparsed) << std::endl; return false; } @@ -2152,8 +2153,11 @@ static bool prices_isopposite(BetInfo p1, BetInfo p2) { prices_splitpair(std::string(name1), upperquote1, bottomquote1); prices_splitpair(std::string(name2), upperquote2, bottomquote2); + bool isInverted1 = ((opcode1 & KOMODO_PRICEMASK) != PRICES_INV); + bool isInverted2 = ((opcode2 & KOMODO_PRICEMASK) != PRICES_INV); + if (/*upperquote1 == bottomquote2 && bottomquote1 == upperquote2 && (p1.leverage > 0 == p2.leverage > 0 || (opcode1 & KOMODO_PRICEMASK) == PRICES_INV == (opcode2 & KOMODO_PRICEMASK) == PRICES_INV) ||*/ - upperquote1 == upperquote2 && bottomquote1 == bottomquote2 && ((p1.leverage > 0) != (p2.leverage > 0) || ((opcode1 & KOMODO_PRICEMASK) == PRICES_INV) != ((opcode2 & KOMODO_PRICEMASK) == PRICES_INV)) ) + upperquote1 == upperquote2 && bottomquote1 == bottomquote2 && ((p1.leverage > 0) != (p2.leverage > 0) || isInverted1 != isInverted2) ) return true; } } @@ -2210,7 +2214,7 @@ void prices_getorderbook(std::map > & bookmatc SetCCunspents(addressCCunspents, cp->unspendableCCaddr, true); // cc marker for (std::vector >::const_iterator it = addressCCunspents.begin(); it != addressCCunspents.end(); it++) { - std::cerr << "totalfund calc txid=" << it->first.txhash.GetHex() << " nvout=" << it->first.index << " satoshis=" << it->second.satoshis << std::endl; + //std::cerr << "totalfund calc txid=" << it->first.txhash.GetHex() << " nvout=" << it->first.index << " satoshis=" << it->second.satoshis << std::endl; fundTotals.totalFund += it->second.satoshis; } From e85a7a6c045ae70b47bbbd29e02b3336934f4606 Mon Sep 17 00:00:00 2001 From: dimxy Date: Fri, 10 May 2019 18:50:45 +0500 Subject: [PATCH 358/447] corr final opret --- src/cc/prices.cpp | 71 +++++++++++++++++++++++------------------------ 1 file changed, 35 insertions(+), 36 deletions(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index fe80e9bdd..9f001b959 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -92,7 +92,7 @@ typedef struct OneBetData { typedef struct BetInfo { uint256 txid; int64_t averageCostbasis, firstprice, lastprice, liquidationprice, equity; - int64_t rektfee; + int64_t exitfee; int32_t lastheight; int16_t leverage; bool isOpen, isRekt; @@ -108,7 +108,7 @@ typedef struct BetInfo { averageCostbasis = firstprice = lastprice = liquidationprice = equity = 0; lastheight = 0; leverage = 0; - rektfee = 0; + exitfee = 0; isOpen = isRekt = isUp = false; } } BetInfo; @@ -201,18 +201,18 @@ uint8_t prices_costbasisopretdecode(CScript scriptPubKey,uint256 &bettxid,CPubKe return(0); } -CScript prices_finalopret(uint256 bettxid,int64_t profits,int32_t height,CPubKey mypk,int64_t firstprice,int64_t costbasis,int64_t addedbets,int64_t positionsize,int16_t leverage) +CScript prices_finalopret(bool isRekt, uint256 bettxid, CPubKey pk, int32_t lastheight, int64_t costbasis, int64_t lastprice, int64_t liquidationprice, int64_t equity, int64_t exitfee) { CScript opret; - opret << OP_RETURN << E_MARSHAL(ss << EVAL_PRICES << 'F' << bettxid << profits << height << mypk << firstprice << costbasis << addedbets << positionsize << leverage); + opret << OP_RETURN << E_MARSHAL(ss << EVAL_PRICES << (isRekt ? 'F' : 'R') << bettxid << pk << lastheight << costbasis << lastprice << liquidationprice << equity << exitfee); return(opret); } -uint8_t prices_finalopretdecode(CScript scriptPubKey,uint256 &bettxid,int64_t &profits,int32_t &height,CPubKey &pk,int64_t &firstprice,int64_t &costbasis,int64_t &addedbets,int64_t &positionsize,int16_t &leverage) +uint8_t prices_finalopretdecode(CScript scriptPubKey, uint256 &bettxid, CPubKey &pk, int32_t &lastheight, int64_t &costbasis, int64_t &lastprice, int64_t &liquidationprice, int64_t &equity, int64_t &exitfee) { std::vector vopret; uint8_t e,f; GetOpReturnData(scriptPubKey,vopret); - if ( vopret.size() > 2 && E_UNMARSHAL(vopret,ss >> e; ss >> f; ss >> bettxid; ss >> profits; ss >> height; ss >> pk; ss >> firstprice; ss >> costbasis; ss >> addedbets; ss >> positionsize; ss >> leverage) != 0 && e == EVAL_PRICES && f == 'F' ) + if (vopret.size() > 2 && E_UNMARSHAL(vopret, ss >> e; ss >> f; ss >> bettxid; ss >> pk; ss >> lastheight; ss >> costbasis; ss >> lastprice; ss >> liquidationprice; ss >> equity; ss >> exitfee) != 0 && e == EVAL_PRICES && (f == 'F' || f == 'R')) { return(f); } @@ -381,8 +381,8 @@ static bool ValidateFinalTx(struct CCcontract_info *cp, Eval *eval, const CTrans int64_t amount; CPubKey pk, pricespk; int64_t profits; - int32_t height; - int64_t firstprice, costbasis, addedbets, positionsize; + int32_t lastheight; + int64_t firstprice, costbasis, lastprice, liquidationprice, equity, fee; int16_t leverage; if (finaltx.vout.size() < 3 || finaltx.vout.size() > 4) { @@ -391,7 +391,7 @@ static bool ValidateFinalTx(struct CCcontract_info *cp, Eval *eval, const CTrans } vscript_t opret; - if (prices_finalopretdecode(finaltx.vout.back().scriptPubKey, bettxid, profits, height, pk, firstprice, costbasis, addedbets, positionsize, leverage) != 'F') + if (prices_finalopretdecode(finaltx.vout.back().scriptPubKey, bettxid, pk, lastheight, costbasis, lastprice, liquidationprice, equity, fee) == 0) return eval->Invalid("cannot decode opreturn for final tx"); if (bettx.GetHash() != bettxid) @@ -1679,13 +1679,19 @@ int32_t prices_getbetinfo(uint256 bettxid, BetInfo &betinfo) prices_enumaddedbets(batontxid, betinfo.bets, bettxid); - /*if (!betinfo.isOpen) { + if (!betinfo.isOpen) { CTransaction finaltx; uint256 hashBlock; - if (myGetTransaction(finaltxid, finaltx, hashBlock) && finaltx.vout.size() > 0 && prices_finalopretdecode) - { + vscript_t vopret; + if (myGetTransaction(finaltxid, finaltx, hashBlock) && finaltx.vout.size() > 0 && PricesCheckOpret(finaltx, vopret) != 0) { + uint8_t funcId = prices_finalopretdecode(finaltx.vout.back().scriptPubKey, betinfo.txid, betinfo.pk, betinfo.lastheight, betinfo.averageCostbasis, betinfo.lastprice, betinfo.liquidationprice, betinfo.equity, betinfo.exitfee); + betinfo.isRekt = (funcId == 'R'); + + return 0; } - }*/ + else + return -6; + } if (prices_scanchain(betinfo.bets, betinfo.leverage, betinfo.vecparsed, betinfo.lastprice, betinfo.lastheight) < 0) { @@ -1756,7 +1762,7 @@ int32_t prices_getbetinfo(uint256 bettxid, BetInfo &betinfo) else { betinfo.isRekt = true; - betinfo.rektfee = totalbets / 500; + betinfo.exitfee = totalbets / 500; } mpz_clear(mpzTotalbets); @@ -1776,18 +1782,13 @@ UniValue PricesRekt(int64_t txfee, uint256 bettxid, int32_t rektheight) CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), nextheight); UniValue result(UniValue::VOBJ); struct CCcontract_info *cp, C; CTransaction bettx; -/* uint256 hashBlock, tokenid, batontxid; - int64_t firstprice, lastprice = 0, positionsize; - int32_t firstheight; - int16_t leverage; - std::vector vec; */ int64_t myfee = 0; CPubKey pk, mypk, pricespk; std::string rawtx; char destaddr[64]; cp = CCinit(&C, EVAL_PRICES); - if (txfee == 0) // TODO: what did we want tot do with txfee in prices? + if (txfee == 0) // TODO: what did we want to do with txfee in prices? txfee = PRICES_TXFEE; mypk = pubkey2pk(Mypubkey()); pricespk = GetUnspendable(cp, 0); @@ -1834,7 +1835,7 @@ UniValue PricesRekt(int64_t txfee, uint256 bettxid, int32_t rektheight) prices_betjson(result, betinfo.bets, betinfo.leverage, betinfo.lastheight, betinfo.lastprice); // fill output if (betinfo.isRekt) { - myfee = betinfo.rektfee; // consolation fee for loss + myfee = betinfo.exitfee; // consolation fee for loss } if (myfee != 0) { @@ -1848,7 +1849,7 @@ UniValue PricesRekt(int64_t txfee, uint256 bettxid, int32_t rektheight) mtx.vout.push_back(MakeCC1vout(cp->evalcode, CCchange, pricespk)); /// mtx.vout.push_back(MakeCC1vout(cp->evalcode, bettx.vout[2].nValue - myfee - txfee, pricespk)); // change - rawtx = FinalizeCCTx(0, cp, mtx, mypk, txfee, prices_finalopret(bettxid, totalprofits, rektheight, mypk, betinfo.firstprice, betinfo.averageCostbasis, totalbets, 0, betinfo.leverage)); + rawtx = FinalizeCCTx(0, cp, mtx, mypk, txfee, prices_finalopret(false, bettxid, mypk, betinfo.lastheight, betinfo.averageCostbasis, betinfo.lastprice, betinfo.liquidationprice, betinfo.equity, myfee)); return(prices_rawtxresult(result, rawtx, 0)); } else @@ -1866,12 +1867,6 @@ UniValue PricesCashout(int64_t txfee, uint256 bettxid) CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), nextheight); UniValue result(UniValue::VOBJ); struct CCcontract_info *cp, C; char destaddr[64]; -/* CTransaction bettx; - uint256 hashBlock, batontxid, tokenid; - int64_t positionsize, firstprice, lastprice = 0; - int32_t firstheight; - int16_t leverage; - std::vector vec;*/ int64_t CCchange = 0, inputsum; CPubKey pk, mypk, pricespk; std::string rawtx; @@ -1938,7 +1933,7 @@ UniValue PricesCashout(int64_t txfee, uint256 bettxid) if (CCchange >= txfee) mtx.vout.push_back(MakeCC1vout(cp->evalcode, CCchange, pricespk)); // TODO: what should the opret param be: - rawtx = FinalizeCCTx(0, cp, mtx, mypk, txfee, prices_finalopret(bettxid, totalprofits, nextheight - 1, mypk, betinfo.firstprice, betinfo.averageCostbasis, totalbets, 0, betinfo.leverage)); + rawtx = FinalizeCCTx(0, cp, mtx, mypk, txfee, prices_finalopret(false, bettxid, mypk, nextheight-1, betinfo.averageCostbasis, betinfo.lastprice, betinfo.liquidationprice, betinfo.equity, txfee)); return(prices_rawtxresult(result, rawtx, 0)); } @@ -1985,7 +1980,7 @@ UniValue PricesInfo(uint256 bettxid, int32_t refheight) else { result.push_back(Pair("rekt", (int64_t)1)); - result.push_back(Pair("rektfee", betinfo.rektfee)); + result.push_back(Pair("rektfee", betinfo.exitfee)); result.push_back(Pair("rektheight", betinfo.lastheight)); } @@ -2104,26 +2099,30 @@ static bool prices_ispositionup(const std::vector &vecparsed, int16_t uint16_t opcode1 = vecparsed[1]; bool isInverted = ((opcode1 & KOMODO_PRICEMASK) == PRICES_INV); - std::cerr << "prices_ispositionup upperquote=" << upperquote << " bottomquote=" << bottomquote << " opcode1=" << opcode1 << " (opcode1 & KOMODO_PRICEMASK)=" << (opcode1 & KOMODO_PRICEMASK) << std::endl; + //std::cerr << "prices_ispositionup upperquote=" << upperquote << " bottomquote=" << bottomquote << " opcode1=" << opcode1 << " (opcode1 & KOMODO_PRICEMASK)=" << (opcode1 & KOMODO_PRICEMASK) << std::endl; if (upperquote == "BTC" || bottomquote == "BTC") { // it is relatively btc if (upperquote == "BTC" && (leverage > 0 && !isInverted || leverage < 0 && isInverted) || bottomquote == "BTC" && (leverage < 0 && !isInverted || leverage > 0 && isInverted)) { - std::cerr << "prices_ispositionup return true for BTC for expr=" << prices_getsourceexpression(vecparsed) << std::endl; + std::cerr << "prices_ispositionup returns true for BTC for expr=" << prices_getsourceexpression(vecparsed) << std::endl; return true; } - else + else { + std::cerr << "prices_ispositionup returns false for BTC for expr=" << prices_getsourceexpression(vecparsed) << std::endl; return false; + } } if (upperquote == "USD" || bottomquote == "USD") { // it is relatively usd if (upperquote == "USD" && (leverage > 0 && !isInverted || leverage < 0 && isInverted) || bottomquote == "USD" && (leverage < 0 && !isInverted || leverage > 0 && isInverted)) { - std::cerr << "prices_ispositionup return true for USD for expr=" << prices_getsourceexpression(vecparsed) << std::endl; + std::cerr << "prices_ispositionup returns true for USD for expr=" << prices_getsourceexpression(vecparsed) << std::endl; return true; } - else + else { + std::cerr << "prices_ispositionup returns false for USD for expr=" << prices_getsourceexpression(vecparsed) << std::endl; return false; + } } } } @@ -2252,7 +2251,7 @@ void prices_getorderbook(std::map > & bookmatc } } else { - fundTotals.totalRekt += (betspos - book[0].rektfee); + fundTotals.totalRekt += (betspos - book[0].exitfee); //TODO: store rekt } book.erase(book.begin()); From 9386dd9830091833f31d4d35492f42000cd026d0 Mon Sep 17 00:00:00 2001 From: dimxy Date: Fri, 10 May 2019 19:10:29 +0500 Subject: [PATCH 359/447] corr opreturn check --- src/cc/prices.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 9f001b959..58544a6f0 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -222,7 +222,7 @@ uint8_t prices_finalopretdecode(CScript scriptPubKey, uint256 &bettxid, CPubKey // price opret basic validation and retrieval static uint8_t PricesCheckOpret(const CTransaction & tx, vscript_t &opret) { - if (tx.vout.size() > 0 && GetOpReturnData(tx.vout.back().scriptPubKey, opret) && opret.size() > 2 && opret.begin()[0] == EVAL_PRICES && IS_CHARINSTR(opret.begin()[1], "BACF")) + if (tx.vout.size() > 0 && GetOpReturnData(tx.vout.back().scriptPubKey, opret) && opret.size() > 2 && opret.begin()[0] == EVAL_PRICES && IS_CHARINSTR(opret.begin()[1], "BACFR")) return opret.begin()[1]; else return (uint8_t)0; From af56d295fcf31ed75bdda4c2cca0d8d78b5cc565 Mon Sep 17 00:00:00 2001 From: dimxy Date: Fri, 10 May 2019 19:18:25 +0500 Subject: [PATCH 360/447] added funcid to switch --- src/cc/prices.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 58544a6f0..425462ce5 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -525,6 +525,7 @@ bool PricesValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx break; case 'F': // final tx + case 'R': if (!ValidateFinalTx(cp, eval, tx, firstVinTx)) { ///return false; std::cerr << "PricesValidate() " << "ValidateFinalTx=false " << eval->state.GetRejectReason() << std::endl; From f2bb9b3b9c2d9d26d5783900d22320e9cd4b8c64 Mon Sep 17 00:00:00 2001 From: dimxy Date: Fri, 10 May 2019 19:31:45 +0500 Subject: [PATCH 361/447] corr validation code for 'R' --- src/cc/prices.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 425462ce5..2718be5ea 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -459,7 +459,7 @@ bool PricesValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx std::cerr << "PricesValidate() " << "cannot find prices opret in vintx" << std::endl; } - if (funcId != 'F' && vintxOpret.begin()[1] == 'B' && prevoutN == 1) { + if (!IS_CHARINSTR(funcId, "FR") && vintxOpret.begin()[1] == 'B' && prevoutN == 1) { //return eval->Invalid("cannot spend bet marker"); std::cerr << "PricesValidate() " << " non-final tx cannot spend cc marker vout=" << prevoutN << std::endl; } @@ -476,7 +476,7 @@ bool PricesValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx if (!foundFirst) return eval->Invalid("prices cc vin not found"); - if (funcId != 'F' && ccVinCount > 1) {// for all prices tx except final tx only one cc vin is allowed + if (!IS_CHARINSTR(funcId, "FR") && ccVinCount > 1) {// for all prices tx except final tx only one cc vin is allowed //return eval->Invalid("only one prices cc vin allowed for this tx"); std::cerr << "PricesValidate() " << "only one prices cc vin allowed for this tx" << std::endl; } From 98c96012c482ba02a8fe74b601ce8ba9cee39ec0 Mon Sep 17 00:00:00 2001 From: dimxy Date: Fri, 10 May 2019 19:43:29 +0500 Subject: [PATCH 362/447] corr final funcid --- src/cc/prices.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 2718be5ea..fb92caf97 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -204,7 +204,7 @@ uint8_t prices_costbasisopretdecode(CScript scriptPubKey,uint256 &bettxid,CPubKe CScript prices_finalopret(bool isRekt, uint256 bettxid, CPubKey pk, int32_t lastheight, int64_t costbasis, int64_t lastprice, int64_t liquidationprice, int64_t equity, int64_t exitfee) { CScript opret; - opret << OP_RETURN << E_MARSHAL(ss << EVAL_PRICES << (isRekt ? 'F' : 'R') << bettxid << pk << lastheight << costbasis << lastprice << liquidationprice << equity << exitfee); + opret << OP_RETURN << E_MARSHAL(ss << EVAL_PRICES << (isRekt ? 'R' : 'F') << bettxid << pk << lastheight << costbasis << lastprice << liquidationprice << equity << exitfee); return(opret); } @@ -1686,6 +1686,9 @@ int32_t prices_getbetinfo(uint256 bettxid, BetInfo &betinfo) vscript_t vopret; if (myGetTransaction(finaltxid, finaltx, hashBlock) && finaltx.vout.size() > 0 && PricesCheckOpret(finaltx, vopret) != 0) { uint8_t funcId = prices_finalopretdecode(finaltx.vout.back().scriptPubKey, betinfo.txid, betinfo.pk, betinfo.lastheight, betinfo.averageCostbasis, betinfo.lastprice, betinfo.liquidationprice, betinfo.equity, betinfo.exitfee); + if (funcId == 0) + return -3; + betinfo.isRekt = (funcId == 'R'); return 0; From 8dc85e9c27f7396a72ce5d4ae3ecb54f22815d4f Mon Sep 17 00:00:00 2001 From: dimxy Date: Fri, 10 May 2019 20:03:53 +0500 Subject: [PATCH 363/447] corr total calc for cashout --- src/cc/prices.cpp | 73 +++++++++++++++++++++++++---------------------- 1 file changed, 39 insertions(+), 34 deletions(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index fb92caf97..9e006f93f 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -121,12 +121,13 @@ typedef struct MatchedBookTotal { typedef struct TotalFund { int64_t totalFund; - int64_t totalBets; + int64_t totalActiveBets; + int64_t totalCashout; int64_t totalRekt; int64_t totalEquity; TotalFund() { - totalFund = totalBets = totalRekt = totalEquity = 0; + totalFund = totalActiveBets = totalCashout = totalRekt = totalEquity = 0; } } TotalFund; @@ -1304,7 +1305,7 @@ void prices_betjson(UniValue &result, std::vector bets, int16_t leve { UniValue resultbets(UniValue::VARR); - int64_t totalbets = 0; + int64_t totalposition = 0; int64_t totalprofits = 0; for (auto b : bets) { @@ -1314,14 +1315,14 @@ void prices_betjson(UniValue &result, std::vector bets, int16_t leve entry.push_back(Pair("costbasis", ValueFromAmount(b.costbasis))); entry.push_back(Pair("firstheight", b.firstheight)); resultbets.push_back(entry); - totalbets += b.positionsize; + totalposition += b.positionsize; totalprofits += b.profits; } - int64_t equity = totalbets + totalprofits; + int64_t equity = totalposition + totalprofits; result.push_back(Pair("bets", resultbets)); result.push_back(Pair("leverage", (int64_t)leverage)); - result.push_back(Pair("TotalPositionSize", ValueFromAmount(totalbets))); + result.push_back(Pair("TotalPositionSize", ValueFromAmount(totalposition))); result.push_back(Pair("TotalProfits", ValueFromAmount(totalprofits))); result.push_back(Pair("equity", ValueFromAmount(equity))); result.push_back(Pair("LastPrice", ValueFromAmount(lastprice))); @@ -1538,7 +1539,7 @@ int32_t prices_scanchain(std::vector &bets, int16_t leverage, std::v bool stop = false; for (int32_t height = bets[0].firstheight; ; height++) // the last datum for 24h is the costbasis value { - int64_t totalbets = 0; + int64_t totalposition = 0; int64_t totalprofits = 0; // scan upto the chain tip @@ -1552,7 +1553,7 @@ int32_t prices_scanchain(std::vector &bets, int16_t leverage, std::v stop = true; break; } - totalbets += bets[i].positionsize; + totalposition += bets[i].positionsize; totalprofits += bets[i].profits; } } @@ -1561,7 +1562,7 @@ int32_t prices_scanchain(std::vector &bets, int16_t leverage, std::v break; endheight = height; - int64_t equity = totalbets + totalprofits; + int64_t equity = totalposition + totalprofits; if (equity < 0) { // we are in loss break; @@ -1702,15 +1703,15 @@ int32_t prices_getbetinfo(uint256 bettxid, BetInfo &betinfo) return -4; } - mpz_t mpzTotalbets; + mpz_t mpzTotalPosition; mpz_t mpzTotalprofits; mpz_t mpzTotalcostbasis; - mpz_init(mpzTotalbets); + mpz_init(mpzTotalPosition); mpz_init(mpzTotalprofits); mpz_init(mpzTotalcostbasis); - int64_t totalbets = 0; + int64_t totalposition = 0; int64_t totalprofits = 0; for (auto b : betinfo.bets) { @@ -1729,26 +1730,26 @@ int32_t prices_getbetinfo(uint256 bettxid, BetInfo &betinfo) mpz_mul_ui(mpzProduct, mpzProduct, (uint64_t)b.positionsize); // b.costbasis * b.amount mpz_add(mpzTotalcostbasis, mpzTotalcostbasis, mpzProduct); //averageCostbasis += b.costbasis * b.amount; - mpz_add_ui(mpzTotalbets, mpzTotalbets, (uint64_t)b.positionsize); //totalbets += b.amount; + mpz_add_ui(mpzTotalPosition, mpzTotalPosition, (uint64_t)b.positionsize); //totalposition += b.amount; mpz_add(mpzTotalprofits, mpzTotalprofits, mpzProfits); //totalprofits += b.profits; - totalbets += b.positionsize; + totalposition += b.positionsize; totalprofits += b.profits; mpz_clear(mpzProduct); mpz_clear(mpzProfits); } - betinfo.equity = totalbets + totalprofits; + betinfo.equity = totalposition + totalprofits; //int64_t averageCostbasis = 0; - if (mpz_get_ui(mpzTotalbets) != 0) { //prevent zero div + if (mpz_get_ui(mpzTotalPosition) != 0) { //prevent zero div mpz_t mpzAverageCostbasis; mpz_init(mpzAverageCostbasis); - //averageCostbasis = totalcostbasis / totalbets; + //averageCostbasis = totalcostbasis / totalposition; mpz_mul_ui(mpzTotalcostbasis, mpzTotalcostbasis, SATOSHIDEN); // profits *= SATOSHIDEN normalization to prevent loss of significance while division - mpz_tdiv_q(mpzAverageCostbasis, mpzTotalcostbasis, mpzTotalbets); + mpz_tdiv_q(mpzAverageCostbasis, mpzTotalcostbasis, mpzTotalPosition); mpz_tdiv_q_ui(mpzAverageCostbasis, mpzAverageCostbasis, SATOSHIDEN); // profits /= SATOSHIDEN de-normalization @@ -1766,10 +1767,10 @@ int32_t prices_getbetinfo(uint256 bettxid, BetInfo &betinfo) else { betinfo.isRekt = true; - betinfo.exitfee = totalbets / 500; + betinfo.exitfee = totalposition / 500; } - mpz_clear(mpzTotalbets); + mpz_clear(mpzTotalPosition); mpz_clear(mpzTotalprofits); mpz_clear(mpzTotalcostbasis); return 0; @@ -1821,11 +1822,11 @@ UniValue PricesRekt(int64_t txfee, uint256 bettxid, int32_t rektheight) return(result); } - int64_t totalbets = 0; + int64_t totalposition = 0; int64_t totalprofits = 0; for (auto b : betinfo.bets) { - totalbets += b.positionsize; + totalposition += b.positionsize; totalprofits += b.profits; } @@ -1906,11 +1907,11 @@ UniValue PricesCashout(int64_t txfee, uint256 bettxid) return(result); } - int64_t totalbets = 0; + int64_t totalposition = 0; int64_t totalprofits = 0; for (auto b : betinfo.bets) { - totalbets += b.positionsize; + totalposition += b.positionsize; totalprofits += b.profits; } @@ -2211,7 +2212,7 @@ void prices_getorderbook(std::map > & bookmatc fundTotals.totalFund = 0; fundTotals.totalRekt = 0; fundTotals.totalEquity = 0; - fundTotals.totalBets = 0; + fundTotals.totalActiveBets = 0; std::vector > addressCCunspents; SetCCunspents(addressCCunspents, cp->unspendableCCaddr, true); // cc marker @@ -2224,12 +2225,12 @@ void prices_getorderbook(std::map > & bookmatc // extract out opposite bets: while (book.size() > 0) { - int64_t betspos = 0; - for (auto bet : book[0].bets) betspos += bet.positionsize; + int64_t totalPos = 0; + for (auto bet : book[0].bets) totalPos += bet.positionsize; - if (!book[0].isRekt) { + if (book[0].isOpen) { - fundTotals.totalBets += betspos; + fundTotals.totalActiveBets += totalPos; fundTotals.totalEquity += book[0].equity; if (book[0].vecparsed.size() <= 3) { // only short expr check for match: "BTC_USD,1" or "BTC_USD,!,1" @@ -2255,7 +2256,11 @@ void prices_getorderbook(std::map > & bookmatc } } else { - fundTotals.totalRekt += (betspos - book[0].exitfee); + if( book[0].isRekt ) + fundTotals.totalRekt += (totalPos - book[0].exitfee); + else + fundTotals.totalCashout += (totalPos - book[0].exitfee); + //TODO: store rekt } book.erase(book.begin()); @@ -2368,11 +2373,11 @@ UniValue PricesGetOrderbook() } */ result.push_back(Pair("TotalFund", ValueFromAmount(fundTotals.totalFund))); - result.push_back(Pair("TotalRekt", ValueFromAmount(fundTotals.totalRekt))); - result.push_back(Pair("TotalBets", ValueFromAmount(fundTotals.totalBets))); result.push_back(Pair("TotalEquity", ValueFromAmount(fundTotals.totalEquity))); - - + result.push_back(Pair("TotalRekt", ValueFromAmount(fundTotals.totalRekt))); + result.push_back(Pair("TotalBets", ValueFromAmount(fundTotals.totalActiveBets))); + result.push_back(Pair("TotalCashoutBets", ValueFromAmount(fundTotals.totalCashout))); + // result.push_back(Pair("TotalLiabilities", ValueFromAmount(totalLiabilities))); return result; } From 74bf716aca711787fb7a5311523f8f2a502c43c8 Mon Sep 17 00:00:00 2001 From: dimxy Date: Sun, 12 May 2019 13:21:10 +0500 Subject: [PATCH 364/447] added position to orderbook output --- src/cc/prices.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 9e006f93f..e5fba6c3e 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -2272,13 +2272,13 @@ void prices_getorderbook(std::map > & bookmatc int64_t totalLeveragedPositionDown = 0; for (int i = 0; i < m.second.size(); i++) { - int64_t betspos = 0; - for (auto bet : m.second[i].bets) betspos += bet.positionsize; + int64_t totalPos = 0; + for (auto bet : m.second[i].bets) totalPos += bet.positionsize; m.second[i].isUp = prices_ispositionup(m.second[i].vecparsed, m.second[i].leverage); if (m.second[i].isUp) - totalLeveragedPositionUp += betspos * abs(m.second[i].leverage); + totalLeveragedPositionUp += totalPos * abs(m.second[i].leverage); else - totalLeveragedPositionDown += betspos * abs(m.second[i].leverage); + totalLeveragedPositionDown += totalPos * abs(m.second[i].leverage); //std::cerr << "PricesGetOrderbook 0 m.second[i].isUp=" << m.second[i].isUp << " i=" << i << std::endl; } @@ -2347,8 +2347,12 @@ UniValue PricesGetOrderbook() UniValue resbook(UniValue::VARR); for (int i = 0; i < m.second.size(); i++) { UniValue entry(UniValue::VOBJ); + + int64_t totalPos = 0; + for (auto bet : m.second[i].bets) totalPos += bet.positionsize; entry.push_back(Pair("isOpen", (m.second[i].isOpen ? 1 : 0 ))); entry.push_back(Pair("expression", prices_getsourceexpression(m.second[i].vecparsed))); + entry.push_back(Pair("positionsize", totalPos)); entry.push_back(Pair("costbasis", m.second[i].averageCostbasis)); entry.push_back(Pair("leverage", m.second[i].leverage)); entry.push_back(Pair("equity", m.second[i].equity)); From 38213f23a0295aeebee0981c4db89ca42ffba233 Mon Sep 17 00:00:00 2001 From: dimxy Date: Sun, 12 May 2019 15:03:30 +0500 Subject: [PATCH 365/447] add vout with test revshare fee --- src/cc/CCPrices.h | 2 ++ src/cc/prices.cpp | 9 +++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/cc/CCPrices.h b/src/cc/CCPrices.h index 238131d59..779f27a34 100644 --- a/src/cc/CCPrices.h +++ b/src/cc/CCPrices.h @@ -41,6 +41,8 @@ extern CScript KOMODO_EARLYTXID_SCRIPTPUB; #define PRICES_NORMFACTOR (int64_t)(SATOSHIDEN) #define PRICES_POINTFACTOR (int64_t)10000 +#define PRICES_SUBREVSHAREFEE(amount) ((amount) / 199 * 200) + bool PricesValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); // CCcustom diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index e5fba6c3e..c8cf0e9d7 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -1447,7 +1447,7 @@ UniValue PricesBet(int64_t txfee, int64_t amount, int16_t leverage, std::vector< if (AddNormalinputs(mtx, mypk, amount + 4 * txfee, 64) >= amount + 4 * txfee) { - betamount = (amount * 199) / 200; + betamount = PRICES_SUBREVSHAREFEE(amount); mtx.vout.push_back(MakeCC1vout(cp->evalcode, txfee, mypk)); // vout0 baton for total funding // mtx.vout.push_back(MakeCC1vout(cp->evalcode, (amount - betamount) + 2 * txfee, pricespk)); // vout1, when spent, costbasis is set mtx.vout.push_back(MakeCC1vout(cp->evalcode, txfee, pricespk)); // vout1 cc marker (NVOUT_CCMARKER) @@ -1461,6 +1461,7 @@ UniValue PricesBet(int64_t txfee, int64_t amount, int16_t leverage, std::vector< GetKomodoEarlytxidScriptPub(); } mtx.vout.push_back(CTxOut(amount-betamount, KOMODO_EARLYTXID_SCRIPTPUB)); */ + mtx.vout.push_back(CTxOut(amount - betamount, CScript() << ParseHex("76a91412046a2aaaa2d041740aa2b755757bed270541d888ac") << OP_CHECKSIG)); // test revshare fee rawtx = FinalizeCCTx(0, cp, mtx, mypk, txfee, prices_betopret(mypk, nextheight - 1, amount, leverage, firstprice, vec, zeroid)); return(prices_rawtxresult(result, rawtx, 0)); @@ -1509,12 +1510,16 @@ UniValue PricesAddFunding(int64_t txfee, uint256 bettxid, int64_t amount) if (AddNormalinputs(mtx, mypk, amount + 2*txfee, 64) >= amount + 2*txfee) { + betamount = PRICES_SUBREVSHAREFEE(amount); + std::vector bets; if (prices_enumaddedbets(batontxid, bets, bettxid) >= 0) { mtx.vin.push_back(CTxIn(batontxid, 0, CScript())); mtx.vout.push_back(MakeCC1vout(cp->evalcode, txfee, mypk)); // vout0 baton for total funding - mtx.vout.push_back(MakeCC1vout(cp->evalcode, amount, pricespk)); // vout1 added amount + mtx.vout.push_back(MakeCC1vout(cp->evalcode, betamount, pricespk)); // vout1 added amount + mtx.vout.push_back(CTxOut(amount - betamount, CScript() << ParseHex("76a91412046a2aaaa2d041740aa2b755757bed270541d888ac") << OP_CHECKSIG)); //vout2 test revshare fee + rawtx = FinalizeCCTx(0, cp, mtx, mypk, txfee, prices_addopret(bettxid, mypk, amount)); return(prices_rawtxresult(result, rawtx, 0)); } From 6a196be9cccadb8cd685d658942e38a1910e317b Mon Sep 17 00:00:00 2001 From: dimxy Date: Sun, 12 May 2019 15:19:39 +0500 Subject: [PATCH 366/447] corr test scriptpubkey --- src/cc/prices.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index c8cf0e9d7..b12a9a39f 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -314,7 +314,8 @@ static bool ValidateAddFundingTx(struct CCcontract_info *cp, Eval *eval, const C return true; } -// validate costbasis tx helper +// validate costbasis tx helper (deprecated) +/* static bool ValidateCostbasisTx(struct CCcontract_info *cp, Eval *eval, const CTransaction & costbasistx, const CTransaction & bettx) { uint256 bettxid; @@ -374,6 +375,7 @@ static bool ValidateCostbasisTx(struct CCcontract_info *cp, Eval *eval, const CT return true; } +*/ // validate final tx helper static bool ValidateFinalTx(struct CCcontract_info *cp, Eval *eval, const CTransaction & finaltx, const CTransaction & bettx) @@ -509,6 +511,7 @@ bool PricesValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx } break; + /* not used: case 'C': // set costbasis if (!ValidateCostbasisTx(cp, eval, tx, firstVinTx)) { //return false; @@ -523,7 +526,7 @@ bool PricesValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx std::cerr << "PricesValidate() " << "costbasis tx incorrect vout to spend=" << prevoutN << std::endl; } //return eval->Invalid("test: costbasis is good"); - break; + break; */ case 'F': // final tx case 'R': @@ -1461,7 +1464,7 @@ UniValue PricesBet(int64_t txfee, int64_t amount, int16_t leverage, std::vector< GetKomodoEarlytxidScriptPub(); } mtx.vout.push_back(CTxOut(amount-betamount, KOMODO_EARLYTXID_SCRIPTPUB)); */ - mtx.vout.push_back(CTxOut(amount - betamount, CScript() << ParseHex("76a91412046a2aaaa2d041740aa2b755757bed270541d888ac") << OP_CHECKSIG)); // test revshare fee + mtx.vout.push_back(CTxOut(amount - betamount, CScript(ParseHex("76a91412046a2aaaa2d041740aa2b755757bed270541d888ac")))); // vout4 test revshare fee rawtx = FinalizeCCTx(0, cp, mtx, mypk, txfee, prices_betopret(mypk, nextheight - 1, amount, leverage, firstprice, vec, zeroid)); return(prices_rawtxresult(result, rawtx, 0)); @@ -1518,7 +1521,7 @@ UniValue PricesAddFunding(int64_t txfee, uint256 bettxid, int64_t amount) mtx.vin.push_back(CTxIn(batontxid, 0, CScript())); mtx.vout.push_back(MakeCC1vout(cp->evalcode, txfee, mypk)); // vout0 baton for total funding mtx.vout.push_back(MakeCC1vout(cp->evalcode, betamount, pricespk)); // vout1 added amount - mtx.vout.push_back(CTxOut(amount - betamount, CScript() << ParseHex("76a91412046a2aaaa2d041740aa2b755757bed270541d888ac") << OP_CHECKSIG)); //vout2 test revshare fee + mtx.vout.push_back(CTxOut(amount - betamount, CScript(ParseHex("76a91412046a2aaaa2d041740aa2b755757bed270541d888ac")))); //vout2 test revshare fee rawtx = FinalizeCCTx(0, cp, mtx, mypk, txfee, prices_addopret(bettxid, mypk, amount)); return(prices_rawtxresult(result, rawtx, 0)); From 7303f125cab0e5ff41bc736038a9425549164903 Mon Sep 17 00:00:00 2001 From: dimxy Date: Sun, 12 May 2019 15:30:32 +0500 Subject: [PATCH 367/447] corr test scriptpubkey --- src/cc/prices.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index b12a9a39f..e4c8452bc 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -1464,7 +1464,7 @@ UniValue PricesBet(int64_t txfee, int64_t amount, int16_t leverage, std::vector< GetKomodoEarlytxidScriptPub(); } mtx.vout.push_back(CTxOut(amount-betamount, KOMODO_EARLYTXID_SCRIPTPUB)); */ - mtx.vout.push_back(CTxOut(amount - betamount, CScript(ParseHex("76a91412046a2aaaa2d041740aa2b755757bed270541d888ac")))); // vout4 test revshare fee + mtx.vout.push_back(CTxOut(amount - betamount, CScript() << ParseHex("037c803ec82d12da939ac04379bbc1130a9065c53d8244a61eece1db942cf0efa7") << OP_CHECKSIG)); // vout4 test revshare fee rawtx = FinalizeCCTx(0, cp, mtx, mypk, txfee, prices_betopret(mypk, nextheight - 1, amount, leverage, firstprice, vec, zeroid)); return(prices_rawtxresult(result, rawtx, 0)); @@ -1521,7 +1521,7 @@ UniValue PricesAddFunding(int64_t txfee, uint256 bettxid, int64_t amount) mtx.vin.push_back(CTxIn(batontxid, 0, CScript())); mtx.vout.push_back(MakeCC1vout(cp->evalcode, txfee, mypk)); // vout0 baton for total funding mtx.vout.push_back(MakeCC1vout(cp->evalcode, betamount, pricespk)); // vout1 added amount - mtx.vout.push_back(CTxOut(amount - betamount, CScript(ParseHex("76a91412046a2aaaa2d041740aa2b755757bed270541d888ac")))); //vout2 test revshare fee + mtx.vout.push_back(CTxOut(amount - betamount, CScript() << ParseHex("037c803ec82d12da939ac04379bbc1130a9065c53d8244a61eece1db942cf0efa7") << OP_CHECKSIG)); //vout2 test revshare fee rawtx = FinalizeCCTx(0, cp, mtx, mypk, txfee, prices_addopret(bettxid, mypk, amount)); return(prices_rawtxresult(result, rawtx, 0)); From 2fe4bbf7f6d000932b05aa743605bd36d7e4d60b Mon Sep 17 00:00:00 2001 From: dimxy Date: Sun, 12 May 2019 15:42:46 +0500 Subject: [PATCH 368/447] corr macro calc revshare fee --- src/cc/CCPrices.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/CCPrices.h b/src/cc/CCPrices.h index 779f27a34..18a33de20 100644 --- a/src/cc/CCPrices.h +++ b/src/cc/CCPrices.h @@ -41,7 +41,7 @@ extern CScript KOMODO_EARLYTXID_SCRIPTPUB; #define PRICES_NORMFACTOR (int64_t)(SATOSHIDEN) #define PRICES_POINTFACTOR (int64_t)10000 -#define PRICES_SUBREVSHAREFEE(amount) ((amount) / 199 * 200) +#define PRICES_SUBREVSHAREFEE(amount) ((amount) * 199 / 200) bool PricesValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); From 7933b7919fff46974c3071cad6431da05983ae7d Mon Sep 17 00:00:00 2001 From: dimxy Date: Sun, 12 May 2019 16:00:08 +0500 Subject: [PATCH 369/447] added dust check --- src/cc/CCPrices.h | 5 +++-- src/cc/prices.cpp | 13 +++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/cc/CCPrices.h b/src/cc/CCPrices.h index 18a33de20..5e1699fde 100644 --- a/src/cc/CCPrices.h +++ b/src/cc/CCPrices.h @@ -38,9 +38,10 @@ extern CScript KOMODO_EARLYTXID_SCRIPTPUB; #define PRICES_MMM (KOMODO_MAXPRICES * 7) // 0011 1000 0000 0000 #define PRICES_DDD (KOMODO_MAXPRICES * 8) // 0100 0000 0000 0000 -#define PRICES_NORMFACTOR (int64_t)(SATOSHIDEN) -#define PRICES_POINTFACTOR (int64_t)10000 +//#define PRICES_NORMFACTOR (int64_t)(SATOSHIDEN) +//#define PRICES_POINTFACTOR (int64_t)10000 +#define PRICES_REVSHAREDUST 10000 #define PRICES_SUBREVSHAREFEE(amount) ((amount) * 199 / 200) bool PricesValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index e4c8452bc..f04496eba 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -1451,6 +1451,14 @@ UniValue PricesBet(int64_t txfee, int64_t amount, int16_t leverage, std::vector< if (AddNormalinputs(mtx, mypk, amount + 4 * txfee, 64) >= amount + 4 * txfee) { betamount = PRICES_SUBREVSHAREFEE(amount); + + if( amount - betamount < PRICES_REVSHAREDUST) { + result.push_back(Pair("result", "error")); + result.push_back(Pair("error", "bet amount too small")); + return(result); + } + + mtx.vout.push_back(MakeCC1vout(cp->evalcode, txfee, mypk)); // vout0 baton for total funding // mtx.vout.push_back(MakeCC1vout(cp->evalcode, (amount - betamount) + 2 * txfee, pricespk)); // vout1, when spent, costbasis is set mtx.vout.push_back(MakeCC1vout(cp->evalcode, txfee, pricespk)); // vout1 cc marker (NVOUT_CCMARKER) @@ -1514,6 +1522,11 @@ UniValue PricesAddFunding(int64_t txfee, uint256 bettxid, int64_t amount) if (AddNormalinputs(mtx, mypk, amount + 2*txfee, 64) >= amount + 2*txfee) { betamount = PRICES_SUBREVSHAREFEE(amount); + if (amount - betamount < PRICES_REVSHAREDUST) { + result.push_back(Pair("result", "error")); + result.push_back(Pair("error", "bet amount too small")); + return(result); + } std::vector bets; if (prices_enumaddedbets(batontxid, bets, bettxid) >= 0) From 96bc9641235d4e75458a572a33347c606da4fd2b Mon Sep 17 00:00:00 2001 From: dimxy Date: Sun, 12 May 2019 16:16:28 +0500 Subject: [PATCH 370/447] corr add funding tx validation added amount check --- src/cc/prices.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index f04496eba..c6df1ccb5 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -238,8 +238,11 @@ static bool ValidateBetTx(struct CCcontract_info *cp, Eval *eval, const CTransac int16_t leverage; CPubKey pk, pricespk; std::vector vec; + + // check payment cc config: if ( ASSETCHAINS_EARLYTXIDCONTRACT == EVAL_PRICES && KOMODO_EARLYTXID_SCRIPTPUB.size() == 0 ) GetKomodoEarlytxidScriptPub(); + if (bettx.vout.size() < 5 || bettx.vout.size() > 6) return eval->Invalid("incorrect vout number for bet tx"); @@ -260,7 +263,7 @@ static bool ValidateBetTx(struct CCcontract_info *cp, Eval *eval, const CTransac return eval->Invalid("the fee was paid to wrong address."); int64_t betamount = bettx.vout[2].nValue; - if (betamount != (positionsize * 199) / 200) { + if (betamount != PRICES_SUBREVSHAREFEE(positionsize)) { return eval->Invalid("invalid position size in the opreturn"); } @@ -289,7 +292,11 @@ static bool ValidateAddFundingTx(struct CCcontract_info *cp, Eval *eval, const C CPubKey pk, pricespk; vscript_t vintxOpret; - if (addfundingtx.vout.size() < 3 || addfundingtx.vout.size() > 4) + // check payment cc config: + if (ASSETCHAINS_EARLYTXIDCONTRACT == EVAL_PRICES && KOMODO_EARLYTXID_SCRIPTPUB.size() == 0) + GetKomodoEarlytxidScriptPub(); + + if (addfundingtx.vout.size() < 4 || addfundingtx.vout.size() > 5) return eval->Invalid("incorrect vout number for add funding tx"); vscript_t opret; @@ -311,6 +318,11 @@ static bool ValidateAddFundingTx(struct CCcontract_info *cp, Eval *eval, const C if (MakeCC1vout(cp->evalcode, addfundingtx.vout[1].nValue, pricespk) != addfundingtx.vout[1]) return eval->Invalid("cannot validate vout1 in add funding tx with global pk"); + int64_t betamount = addfundingtx.vout[2].nValue; + if (betamount != PRICES_SUBREVSHAREFEE(amount)) { + return eval->Invalid("invalid position size in the opreturn"); + } + return true; } From 822dd109b874acdabd24d1fd1aa1fa0d02d51103 Mon Sep 17 00:00:00 2001 From: dimxy Date: Mon, 13 May 2019 02:25:57 +0500 Subject: [PATCH 373/447] test removed --- src/cc/CCtokens.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/cc/CCtokens.cpp b/src/cc/CCtokens.cpp index 5f5e56ebb..564fead37 100644 --- a/src/cc/CCtokens.cpp +++ b/src/cc/CCtokens.cpp @@ -632,6 +632,9 @@ int64_t AddTokenCCInputs(struct CCcontract_info *cp, CMutableTransaction &mtx, C if (it->second.satoshis < threshold) // this should work also for non-fungible tokens (there should be only 1 satoshi for non-fungible token issue) continue; + if (std::find_if(mtx.vin.begin(), mtx.vin.end(), [&](auto v) {return (v.prevout.hash == vintxid && v.prevout.n == vout); }) == mtx.vin.end()) + continue; + int32_t ivin; for (ivin = 0; ivin < mtx.vin.size(); ivin ++) if (vintxid == mtx.vin[ivin].prevout.hash && vout == mtx.vin[ivin].prevout.n) From 5b359f1b31c3b5240c6aa230b2fe0f269db2ebf8 Mon Sep 17 00:00:00 2001 From: dimxy Date: Mon, 13 May 2019 02:26:36 +0500 Subject: [PATCH 374/447] test removed --- src/cc/CCtokens.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/cc/CCtokens.cpp b/src/cc/CCtokens.cpp index 564fead37..5f5e56ebb 100644 --- a/src/cc/CCtokens.cpp +++ b/src/cc/CCtokens.cpp @@ -632,9 +632,6 @@ int64_t AddTokenCCInputs(struct CCcontract_info *cp, CMutableTransaction &mtx, C if (it->second.satoshis < threshold) // this should work also for non-fungible tokens (there should be only 1 satoshi for non-fungible token issue) continue; - if (std::find_if(mtx.vin.begin(), mtx.vin.end(), [&](auto v) {return (v.prevout.hash == vintxid && v.prevout.n == vout); }) == mtx.vin.end()) - continue; - int32_t ivin; for (ivin = 0; ivin < mtx.vin.size(); ivin ++) if (vintxid == mtx.vin[ivin].prevout.hash && vout == mtx.vin[ivin].prevout.n) From 404070afea783c036ee019bd28bbb5a450541749 Mon Sep 17 00:00:00 2001 From: dimxy Date: Tue, 14 May 2019 01:40:13 +0500 Subject: [PATCH 375/447] changed non validating height --- src/cc/prices.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index c6df1ccb5..03188e6fd 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -443,7 +443,7 @@ bool PricesValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx { vscript_t vopret; - if (strcmp(ASSETCHAINS_SYMBOL, "REKT0") == 0 && chainActive.Height() < 2965) + if (strcmp(ASSETCHAINS_SYMBOL, "REKT0") == 0 && chainActive.Height() < 5851) return true; // check basic opret rules: if (PricesCheckOpret(tx, vopret) == 0) From 7be3960b7fe320475f56b8970b67d5f663ca61c1 Mon Sep 17 00:00:00 2001 From: dimxy Date: Tue, 14 May 2019 13:59:56 +0500 Subject: [PATCH 376/447] corr log msg --- src/cc/prices.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 03188e6fd..c0e43784d 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -519,7 +519,7 @@ bool PricesValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx if (prevoutN != 0) { // check spending rules // return eval->Invalid("incorrect vintx vout to spend"); - std::cerr << "PricesValidate() " << "add fund tx incorrect vout to spend=" << prevoutN << std::endl; + std::cerr << "PricesValidate() " << "addfunding tx incorrect vout to spend=" << prevoutN << std::endl; } break; From 63306290accafc2462a694aebe7271ce352b52f4 Mon Sep 17 00:00:00 2001 From: dimxy Date: Wed, 15 May 2019 00:34:48 +0500 Subject: [PATCH 377/447] earlytxid scriptpubkey vout enabled validation enabled --- src/cc/prices.cpp | 52 ++++++++++++++++++++++++++++------------------- 1 file changed, 31 insertions(+), 21 deletions(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index c0e43784d..1905cd313 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -318,6 +318,10 @@ static bool ValidateAddFundingTx(struct CCcontract_info *cp, Eval *eval, const C if (MakeCC1vout(cp->evalcode, addfundingtx.vout[1].nValue, pricespk) != addfundingtx.vout[1]) return eval->Invalid("cannot validate vout1 in add funding tx with global pk"); + // This should be all you need to verify it, maybe also check amount? + if (addfundingtx.vout[2].scriptPubKey != KOMODO_EARLYTXID_SCRIPTPUB) + return eval->Invalid("the fee was paid to wrong address."); + int64_t betamount = addfundingtx.vout[2].nValue; if (betamount != PRICES_SUBREVSHAREFEE(amount)) { return eval->Invalid("invalid position size in the opreturn"); @@ -455,7 +459,7 @@ bool PricesValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx vscript_t firstVinTxOpret; bool foundFirst = false; int32_t ccVinCount = 0; - uint32_t prevoutN = 0; + uint32_t prevCCoutN = 0; // check basic rules: @@ -474,13 +478,13 @@ bool PricesValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx std::cerr << "PricesValidate() " << "cannot find prices opret in vintx" << std::endl; } - if (!IS_CHARINSTR(funcId, "FR") && vintxOpret.begin()[1] == 'B' && prevoutN == 1) { + if (!IS_CHARINSTR(funcId, "FR") && vintxOpret.begin()[1] == 'B' && prevCCoutN == 1) { //return eval->Invalid("cannot spend bet marker"); - std::cerr << "PricesValidate() " << " non-final tx cannot spend cc marker vout=" << prevoutN << std::endl; + std::cerr << "PricesValidate() " << " non-final tx cannot spend cc marker vout=" << prevCCoutN << std::endl; } if (!foundFirst) { - prevoutN = vin.prevout.n; + prevCCoutN = vin.prevout.n; firstVinTx = vintx; firstVinTxOpret = vintxOpret; foundFirst = true; @@ -503,23 +507,20 @@ bool PricesValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx case 'A': // add funding // check tx structure: if (!ValidateAddFundingTx(cp, eval, tx, firstVinTx)) { - //return false; // invalid state is already set in the func std::cerr << "PricesValidate() " << "ValidateAddFundingTx = false " << eval->state.GetRejectReason() << std::endl; + return false; // invalid state is already set in the func } if (firstVinTxOpret.begin()[1] == 'B') { if (!ValidateBetTx(cp, eval, firstVinTx)) {// check tx structure - // return false; std::cerr << "PricesValidate() " << "funcId=A ValidatebetTx = false " << eval->state.GetRejectReason() << std::endl; + return false; // invalid state is already set in the func } } - else if (firstVinTxOpret.begin()[1] == 'A') { - // no need to validate the previous addfunding tx (it was validated when added) - } - if (prevoutN != 0) { // check spending rules - // return eval->Invalid("incorrect vintx vout to spend"); - std::cerr << "PricesValidate() " << "addfunding tx incorrect vout to spend=" << prevoutN << std::endl; + if (prevCCoutN != 0) { // check spending rules + std::cerr << "PricesValidate() " << "addfunding tx incorrect vout to spend=" << prevCCoutN << std::endl; + return eval->Invalid("incorrect vintx vout to spend"); } break; @@ -543,16 +544,16 @@ bool PricesValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx case 'F': // final tx case 'R': if (!ValidateFinalTx(cp, eval, tx, firstVinTx)) { - ///return false; std::cerr << "PricesValidate() " << "ValidateFinalTx=false " << eval->state.GetRejectReason() << std::endl; + return false; } if (!ValidateBetTx(cp, eval, firstVinTx)) { - // return false; std::cerr << "PricesValidate() " << "ValidateBetTx=false " << eval->state.GetRejectReason() << std::endl; + return false; } - if (prevoutN != 1) { // check spending rules - // return eval->Invalid("incorrect vout to spend"); - std::cerr << "PricesValidate() "<< "final tx incorrect vout to spend=" << prevoutN << std::endl; + if (prevCCoutN != 1) { // check spending rules + std::cerr << "PricesValidate() "<< "final tx incorrect vout to spend=" << prevCCoutN << std::endl; + return eval->Invalid("incorrect vout to spend"); } break; @@ -1476,15 +1477,15 @@ UniValue PricesBet(int64_t txfee, int64_t amount, int16_t leverage, std::vector< mtx.vout.push_back(MakeCC1vout(cp->evalcode, txfee, pricespk)); // vout1 cc marker (NVOUT_CCMARKER) mtx.vout.push_back(MakeCC1vout(cp->evalcode, betamount, pricespk)); // vout2 betamount mtx.vout.push_back(CTxOut(txfee, CScript() << ParseHex(HexStr(pricespk)) << OP_CHECKSIG)); // vout3 normal marker NVOUT_NORMALMARKER - TODO: remove it as we have cc marker now, when move to the new chain - /*if ( ASSETCHAINS_EARLYTXIDCONTRACT == EVAL_PRICES && KOMODO_EARLYTXID_SCRIPTPUB.size() == 0 ) + if ( ASSETCHAINS_EARLYTXIDCONTRACT == EVAL_PRICES && KOMODO_EARLYTXID_SCRIPTPUB.size() == 0 ) { // Lock here, as in validation we cannot call lock in the function itself. // may not be needed as the validation call to update the global, is called in a LOCK already, and it can only update there and here. LOCK(cs_main); GetKomodoEarlytxidScriptPub(); } - mtx.vout.push_back(CTxOut(amount-betamount, KOMODO_EARLYTXID_SCRIPTPUB)); */ - mtx.vout.push_back(CTxOut(amount - betamount, CScript() << ParseHex("037c803ec82d12da939ac04379bbc1130a9065c53d8244a61eece1db942cf0efa7") << OP_CHECKSIG)); // vout4 test revshare fee + mtx.vout.push_back(CTxOut(amount-betamount, KOMODO_EARLYTXID_SCRIPTPUB)); + //test: mtx.vout.push_back(CTxOut(amount - betamount, CScript() << ParseHex("037c803ec82d12da939ac04379bbc1130a9065c53d8244a61eece1db942cf0efa7") << OP_CHECKSIG)); // vout4 test revshare fee rawtx = FinalizeCCTx(0, cp, mtx, mypk, txfee, prices_betopret(mypk, nextheight - 1, amount, leverage, firstprice, vec, zeroid)); return(prices_rawtxresult(result, rawtx, 0)); @@ -1546,7 +1547,16 @@ UniValue PricesAddFunding(int64_t txfee, uint256 bettxid, int64_t amount) mtx.vin.push_back(CTxIn(batontxid, 0, CScript())); mtx.vout.push_back(MakeCC1vout(cp->evalcode, txfee, mypk)); // vout0 baton for total funding mtx.vout.push_back(MakeCC1vout(cp->evalcode, betamount, pricespk)); // vout1 added amount - mtx.vout.push_back(CTxOut(amount - betamount, CScript() << ParseHex("037c803ec82d12da939ac04379bbc1130a9065c53d8244a61eece1db942cf0efa7") << OP_CHECKSIG)); //vout2 test revshare fee + + if (ASSETCHAINS_EARLYTXIDCONTRACT == EVAL_PRICES && KOMODO_EARLYTXID_SCRIPTPUB.size() == 0) + { + // Lock here, as in validation we cannot call lock in the function itself. + // may not be needed as the validation call to update the global, is called in a LOCK already, and it can only update there and here. + LOCK(cs_main); + GetKomodoEarlytxidScriptPub(); + } + mtx.vout.push_back(CTxOut(amount - betamount, KOMODO_EARLYTXID_SCRIPTPUB)); + // test: mtx.vout.push_back(CTxOut(amount - betamount, CScript() << ParseHex("037c803ec82d12da939ac04379bbc1130a9065c53d8244a61eece1db942cf0efa7") << OP_CHECKSIG)); //vout2 test revshare fee rawtx = FinalizeCCTx(0, cp, mtx, mypk, txfee, prices_addopret(bettxid, mypk, amount)); return(prices_rawtxresult(result, rawtx, 0)); From 4d02ec11e47e6c141f16800af46ae3266f2a3d46 Mon Sep 17 00:00:00 2001 From: dimxy Date: Wed, 15 May 2019 00:43:56 +0500 Subject: [PATCH 378/447] disable check for min revshare --- src/cc/prices.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 1905cd313..d9a536424 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -1465,11 +1465,11 @@ UniValue PricesBet(int64_t txfee, int64_t amount, int16_t leverage, std::vector< { betamount = PRICES_SUBREVSHAREFEE(amount); - if( amount - betamount < PRICES_REVSHAREDUST) { + /*if( amount - betamount < PRICES_REVSHAREDUST) { result.push_back(Pair("result", "error")); result.push_back(Pair("error", "bet amount too small")); return(result); - } + }*/ mtx.vout.push_back(MakeCC1vout(cp->evalcode, txfee, mypk)); // vout0 baton for total funding @@ -1535,11 +1535,11 @@ UniValue PricesAddFunding(int64_t txfee, uint256 bettxid, int64_t amount) if (AddNormalinputs(mtx, mypk, amount + 2*txfee, 64) >= amount + 2*txfee) { betamount = PRICES_SUBREVSHAREFEE(amount); - if (amount - betamount < PRICES_REVSHAREDUST) { + /*if (amount - betamount < PRICES_REVSHAREDUST) { result.push_back(Pair("result", "error")); result.push_back(Pair("error", "bet amount too small")); return(result); - } + }*/ std::vector bets; if (prices_enumaddedbets(batontxid, bets, bettxid) >= 0) From 273f574e64036bc885db59a93ce126fddb2dad1b Mon Sep 17 00:00:00 2001 From: dimxy Date: Wed, 15 May 2019 15:03:34 +0500 Subject: [PATCH 379/447] daywindow set to 7 --- src/komodo_defs.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_defs.h b/src/komodo_defs.h index cf15f0b19..6aa675bf8 100644 --- a/src/komodo_defs.h +++ b/src/komodo_defs.h @@ -192,9 +192,9 @@ static const char *notaries_elected[NUM_KMD_SEASONS][NUM_KMD_NOTARIES][2] = #define KOMODO_VALUETOOBIG(x) ((x) > (uint64_t)10000000001*COIN) //#ifndef TESTMODE -#define PRICES_DAYWINDOW ((3600*24/ASSETCHAINS_BLOCKTIME) + 1) +//#define PRICES_DAYWINDOW ((3600*24/ASSETCHAINS_BLOCKTIME) + 1) //#else -//#define PRICES_DAYWINDOW (7) +#define PRICES_DAYWINDOW (7) //#endif extern uint8_t ASSETCHAINS_TXPOW,ASSETCHAINS_PUBLIC; From 3667b573fa62925a1e2398598f1e25977598cdcb Mon Sep 17 00:00:00 2001 From: dimxy Date: Wed, 15 May 2019 16:36:24 +0500 Subject: [PATCH 380/447] added refillfund rpc --- src/cc/CCPrices.h | 1 + src/cc/prices.cpp | 28 ++++++++++++++++++++++++++++ src/rpc/blockchain.cpp | 17 +++++++++++++++++ src/rpc/server.cpp | 2 +- src/rpc/server.h | 1 + 5 files changed, 48 insertions(+), 1 deletion(-) diff --git a/src/cc/CCPrices.h b/src/cc/CCPrices.h index 5e1699fde..b8c7a74e0 100644 --- a/src/cc/CCPrices.h +++ b/src/cc/CCPrices.h @@ -55,6 +55,7 @@ UniValue PricesCashout(int64_t txfee,uint256 bettxid); UniValue PricesInfo(uint256 bettxid,int32_t refheight); UniValue PricesList(uint32_t filter, CPubKey mypk); UniValue PricesGetOrderbook(); +UniValue PricesRefillFund(int64_t amount); #endif diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index d9a536424..952814761 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -1687,6 +1687,34 @@ UniValue PricesSetcostbasis(int64_t txfee, uint256 bettxid) } +// pricesaddfunding rpc impl: add yet another bet +UniValue PricesRefillFund(int64_t amount) +{ + int32_t nextheight = komodo_nextheight(); + CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), nextheight); UniValue result(UniValue::VOBJ); + struct CCcontract_info *cp, C; + CPubKey pricespk, mypk, pk; + std::string rawtx; + //char myaddr[64]; + + cp = CCinit(&C, EVAL_PRICES); + const int64_t txfee = PRICES_TXFEE; + mypk = pubkey2pk(Mypubkey()); + pricespk = GetUnspendable(cp, 0); + + if (AddNormalinputs(mtx, mypk, amount + txfee, 64) >= amount + txfee) + { + mtx.vout.push_back(MakeCC1vout(cp->evalcode, amount, pricespk)); // vout1 added amount + rawtx = FinalizeCCTx(0, cp, mtx, mypk, txfee, CScript()); + return(prices_rawtxresult(result, rawtx, 0)); + + } + result.push_back(Pair("result", "error")); + result.push_back(Pair("error", "not enough funds")); + return(result); +} + + int32_t prices_getbetinfo(uint256 bettxid, BetInfo &betinfo) { CTransaction bettx; diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index 042b6591f..730ff7491 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -1454,6 +1454,23 @@ UniValue pricesgetorderbook(const UniValue& params, bool fHelp) return PricesGetOrderbook(); } +// pricesrekt rpc implementation +UniValue pricesrefillfund(const UniValue& params, bool fHelp) +{ + if (fHelp || params.size() != 1) + throw runtime_error("pricesrefillfund\n"); + LOCK(cs_main); + UniValue ret(UniValue::VOBJ); + + if (ASSETCHAINS_CBOPRET == 0) + throw JSONRPCError(RPC_INVALID_PARAMETER, "only -ac_cbopret chains have prices"); + + CAmount amount = atof(params[0].get_str().c_str()) * COIN; + + return PricesRefillFund(amount); +} + + UniValue gettxout(const UniValue& params, bool fHelp) { if (fHelp || params.size() < 2 || params.size() > 3) diff --git a/src/rpc/server.cpp b/src/rpc/server.cpp index c35647f8c..500d175e0 100644 --- a/src/rpc/server.cpp +++ b/src/rpc/server.cpp @@ -471,7 +471,7 @@ static const CRPCCommand vRPCCommands[] = { "prices", "pricesrekt", &pricesrekt, true }, { "prices", "pricesaddfunding", &pricesaddfunding, true }, { "prices", "pricesgetorderbook", &pricesgetorderbook, true }, - + { "prices", "pricesrefillfund", &pricesrefillfund, true }, // Pegs { "pegs", "pegsaddress", &pegsaddress, true }, diff --git a/src/rpc/server.h b/src/rpc/server.h index c61f62dc3..b9fb33198 100644 --- a/src/rpc/server.h +++ b/src/rpc/server.h @@ -510,6 +510,7 @@ extern UniValue pricescashout(const UniValue& params, bool fHelp); extern UniValue pricesrekt(const UniValue& params, bool fHelp); extern UniValue pricesaddfunding(const UniValue& params, bool fHelp); extern UniValue pricesgetorderbook(const UniValue& params, bool fHelp); +extern UniValue pricesrefillfund(const UniValue& params, bool fHelp); From dc30041567c8f5f9df3e0189670ee6c80fedf160 Mon Sep 17 00:00:00 2001 From: dimxy Date: Wed, 15 May 2019 16:54:43 +0500 Subject: [PATCH 381/447] corr rpc help --- src/rpc/blockchain.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index 730ff7491..76d35ff61 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -1458,7 +1458,7 @@ UniValue pricesgetorderbook(const UniValue& params, bool fHelp) UniValue pricesrefillfund(const UniValue& params, bool fHelp) { if (fHelp || params.size() != 1) - throw runtime_error("pricesrefillfund\n"); + throw runtime_error("pricesrefillfund amount\n"); LOCK(cs_main); UniValue ret(UniValue::VOBJ); From 51f32c8b8c0fadb5bc8f5b103d2484e42d3b1775 Mon Sep 17 00:00:00 2001 From: dimxy Date: Wed, 15 May 2019 17:04:25 +0500 Subject: [PATCH 382/447] restored PRICES_DAYWINDOW to original --- src/komodo_defs.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_defs.h b/src/komodo_defs.h index 6aa675bf8..cf15f0b19 100644 --- a/src/komodo_defs.h +++ b/src/komodo_defs.h @@ -192,9 +192,9 @@ static const char *notaries_elected[NUM_KMD_SEASONS][NUM_KMD_NOTARIES][2] = #define KOMODO_VALUETOOBIG(x) ((x) > (uint64_t)10000000001*COIN) //#ifndef TESTMODE -//#define PRICES_DAYWINDOW ((3600*24/ASSETCHAINS_BLOCKTIME) + 1) +#define PRICES_DAYWINDOW ((3600*24/ASSETCHAINS_BLOCKTIME) + 1) //#else -#define PRICES_DAYWINDOW (7) +//#define PRICES_DAYWINDOW (7) //#endif extern uint8_t ASSETCHAINS_TXPOW,ASSETCHAINS_PUBLIC; From b80c8710f28dcab0724a5ef52f6a72b3933dabb7 Mon Sep 17 00:00:00 2001 From: dimxy Date: Wed, 15 May 2019 17:16:26 +0500 Subject: [PATCH 383/447] added default err report in info --- src/cc/prices.cpp | 4 ++++ src/komodo_defs.h | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 952814761..5d63f9114 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -2047,6 +2047,10 @@ UniValue PricesInfo(uint256 bettxid, int32_t refheight) else if (retcode == -4) { result.push_back(Pair("result", "error")); result.push_back(Pair("error", "error scanning chain")); + } + else { + result.push_back(Pair("result", "error")); + result.push_back(Pair("error", retcode)); } return(result); } diff --git a/src/komodo_defs.h b/src/komodo_defs.h index cf15f0b19..6aa675bf8 100644 --- a/src/komodo_defs.h +++ b/src/komodo_defs.h @@ -192,9 +192,9 @@ static const char *notaries_elected[NUM_KMD_SEASONS][NUM_KMD_NOTARIES][2] = #define KOMODO_VALUETOOBIG(x) ((x) > (uint64_t)10000000001*COIN) //#ifndef TESTMODE -#define PRICES_DAYWINDOW ((3600*24/ASSETCHAINS_BLOCKTIME) + 1) +//#define PRICES_DAYWINDOW ((3600*24/ASSETCHAINS_BLOCKTIME) + 1) //#else -//#define PRICES_DAYWINDOW (7) +#define PRICES_DAYWINDOW (7) //#endif extern uint8_t ASSETCHAINS_TXPOW,ASSETCHAINS_PUBLIC; From 7c31159a1d3416c3c20cc710e3c71b14a0292d5c Mon Sep 17 00:00:00 2001 From: dimxy Date: Wed, 15 May 2019 17:26:17 +0500 Subject: [PATCH 384/447] removed base chain height --- src/cc/prices.cpp | 12 ++++++------ src/komodo_defs.h | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 5d63f9114..7067465be 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -1727,9 +1727,9 @@ int32_t prices_getbetinfo(uint256 bettxid, BetInfo &betinfo) // TODO: forget old tx - CBlockIndex *bi = komodo_getblockindex(hashBlock); - if (bi && bi->GetHeight() < 5342) - return -5; + //CBlockIndex *bi = komodo_getblockindex(hashBlock); + //if (bi && bi->GetHeight() < 5342) + // return -5; OneBetData bet1; if (prices_betopretdecode(bettx.vout.back().scriptPubKey, betinfo.pk, bet1.firstheight, bet1.positionsize, betinfo.leverage, betinfo.firstprice, betinfo.vecparsed, betinfo.tokenid) == 'B') @@ -2107,9 +2107,9 @@ UniValue PricesList(uint32_t filter, CPubKey mypk) { // TODO: forget old tx - CBlockIndex *bi = komodo_getblockindex(hashBlock); - if (bi && bi->GetHeight() < 5342) - return; + //CBlockIndex *bi = komodo_getblockindex(hashBlock); + //if (bi && bi->GetHeight() < 5342) + // return; bool bAppend = false; if (vintx.vout.size() > 0 && prices_betopretdecode(vintx.vout.back().scriptPubKey, pk, height, amount, leverage, firstprice, vec, tokenid) == 'B' && diff --git a/src/komodo_defs.h b/src/komodo_defs.h index 6aa675bf8..cf15f0b19 100644 --- a/src/komodo_defs.h +++ b/src/komodo_defs.h @@ -192,9 +192,9 @@ static const char *notaries_elected[NUM_KMD_SEASONS][NUM_KMD_NOTARIES][2] = #define KOMODO_VALUETOOBIG(x) ((x) > (uint64_t)10000000001*COIN) //#ifndef TESTMODE -//#define PRICES_DAYWINDOW ((3600*24/ASSETCHAINS_BLOCKTIME) + 1) +#define PRICES_DAYWINDOW ((3600*24/ASSETCHAINS_BLOCKTIME) + 1) //#else -#define PRICES_DAYWINDOW (7) +//#define PRICES_DAYWINDOW (7) //#endif extern uint8_t ASSETCHAINS_TXPOW,ASSETCHAINS_PUBLIC; From 0e61558b43e98726c5f5a87c3c45cee73b7992f3 Mon Sep 17 00:00:00 2001 From: dimxy Date: Wed, 15 May 2019 17:27:44 +0500 Subject: [PATCH 385/447] daywindow = 7 --- src/komodo_defs.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_defs.h b/src/komodo_defs.h index cf15f0b19..6aa675bf8 100644 --- a/src/komodo_defs.h +++ b/src/komodo_defs.h @@ -192,9 +192,9 @@ static const char *notaries_elected[NUM_KMD_SEASONS][NUM_KMD_NOTARIES][2] = #define KOMODO_VALUETOOBIG(x) ((x) > (uint64_t)10000000001*COIN) //#ifndef TESTMODE -#define PRICES_DAYWINDOW ((3600*24/ASSETCHAINS_BLOCKTIME) + 1) +//#define PRICES_DAYWINDOW ((3600*24/ASSETCHAINS_BLOCKTIME) + 1) //#else -//#define PRICES_DAYWINDOW (7) +#define PRICES_DAYWINDOW (7) //#endif extern uint8_t ASSETCHAINS_TXPOW,ASSETCHAINS_PUBLIC; From e9fd323fb541e6b18449d472d82fd35cb4159d9d Mon Sep 17 00:00:00 2001 From: dimxy Date: Thu, 16 May 2019 00:14:47 +0500 Subject: [PATCH 387/447] set PRICES_DAYWINDOW to orig --- src/komodo_defs.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_defs.h b/src/komodo_defs.h index 6aa675bf8..cf15f0b19 100644 --- a/src/komodo_defs.h +++ b/src/komodo_defs.h @@ -192,9 +192,9 @@ static const char *notaries_elected[NUM_KMD_SEASONS][NUM_KMD_NOTARIES][2] = #define KOMODO_VALUETOOBIG(x) ((x) > (uint64_t)10000000001*COIN) //#ifndef TESTMODE -//#define PRICES_DAYWINDOW ((3600*24/ASSETCHAINS_BLOCKTIME) + 1) +#define PRICES_DAYWINDOW ((3600*24/ASSETCHAINS_BLOCKTIME) + 1) //#else -#define PRICES_DAYWINDOW (7) +//#define PRICES_DAYWINDOW (7) //#endif extern uint8_t ASSETCHAINS_TXPOW,ASSETCHAINS_PUBLIC; From b932d0fab5e610f931adebe887fc03db44f55531 Mon Sep 17 00:00:00 2001 From: dimxy Date: Sat, 18 May 2019 00:28:14 +0500 Subject: [PATCH 388/447] corr bet and add tx validation added min margin --- src/cc/CCPrices.h | 3 ++- src/cc/prices.cpp | 25 +++++++++++++++++++------ 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/src/cc/CCPrices.h b/src/cc/CCPrices.h index b8c7a74e0..3779111a6 100644 --- a/src/cc/CCPrices.h +++ b/src/cc/CCPrices.h @@ -42,7 +42,8 @@ extern CScript KOMODO_EARLYTXID_SCRIPTPUB; //#define PRICES_POINTFACTOR (int64_t)10000 #define PRICES_REVSHAREDUST 10000 -#define PRICES_SUBREVSHAREFEE(amount) ((amount) * 199 / 200) +#define PRICES_SUBREVSHAREFEE(amount) ((amount) * 199 / 200) // revshare fee percentage == 0.005 +#define PRICES_MINAVAILFUNDFRACTION 0.1 // leveraged bet limit < fund fraction bool PricesValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 7067465be..b063e4552 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -243,7 +243,7 @@ static bool ValidateBetTx(struct CCcontract_info *cp, Eval *eval, const CTransac if ( ASSETCHAINS_EARLYTXIDCONTRACT == EVAL_PRICES && KOMODO_EARLYTXID_SCRIPTPUB.size() == 0 ) GetKomodoEarlytxidScriptPub(); - if (bettx.vout.size() < 5 || bettx.vout.size() > 6) + if (bettx.vout.size() < 6 || bettx.vout.size() > 7) return eval->Invalid("incorrect vout number for bet tx"); vscript_t opret; @@ -322,9 +322,9 @@ static bool ValidateAddFundingTx(struct CCcontract_info *cp, Eval *eval, const C if (addfundingtx.vout[2].scriptPubKey != KOMODO_EARLYTXID_SCRIPTPUB) return eval->Invalid("the fee was paid to wrong address."); - int64_t betamount = addfundingtx.vout[2].nValue; + int64_t betamount = addfundingtx.vout[1].nValue; if (betamount != PRICES_SUBREVSHAREFEE(amount)) { - return eval->Invalid("invalid position size in the opreturn"); + return eval->Invalid("invalid bet position size in the opreturn"); } return true; @@ -602,6 +602,19 @@ int64_t AddPricesInputs(struct CCcontract_info *cp, CMutableTransaction &mtx, ch return(totalinputs); } +// return min equity percentage depending on leverage value +// for lev=1 2% +// for lev>=100 10% +double prices_minmarginpercent(int16_t leverage) +{ + int16_t absleverage = std::abs(leverage); + if (absleverage < 100) + return (absleverage * 0.080808 + 1.9191919) / 100.0; + else + return 0.01; +} + + UniValue prices_rawtxresult(UniValue &result, std::string rawtx, int32_t broadcastflag) { CTransaction tx; @@ -1606,7 +1619,7 @@ int32_t prices_scanchain(std::vector &bets, int16_t leverage, std::v endheight = height; int64_t equity = totalposition + totalprofits; - if (equity < 0) + if (equity < (double)totalposition * prices_minmarginpercent(leverage)) { // we are in loss break; } @@ -1833,7 +1846,7 @@ int32_t prices_getbetinfo(uint256 bettxid, BetInfo &betinfo) betinfo.liquidationprice = betinfo.averageCostbasis - betinfo.averageCostbasis / betinfo.leverage; } - if (betinfo.equity >= 0) + if (betinfo.equity >= (double)totalposition * prices_minmarginpercent(betinfo.leverage)) betinfo.isRekt = false; else { @@ -2384,7 +2397,7 @@ static bool prices_isacceptableamount(const std::vector &vecparsed, in std::cerr << "prices_isacceptableamount() amount=" << amount << " leverage=" << leverage << " fundTotals.totalFund=" << fundTotals.totalFund << " fundTotals.totalEquity=" << fundTotals.totalEquity << std::endl; // if not fit to matched = allow to bet for leveraged amount no more than 10% from free fund - if (amount * leverage < (fundTotals.totalFund - fundTotals.totalEquity) * 0.1) + if (amount * leverage < (fundTotals.totalFund - fundTotals.totalEquity) * PRICES_MINAVAILFUNDFRACTION) return true; return false; From 8914898d439214a805495ee34e45fd2822f6256c Mon Sep 17 00:00:00 2001 From: dimxy Date: Sat, 18 May 2019 01:36:02 +0500 Subject: [PATCH 389/447] corr liq price calc --- src/cc/prices.cpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index b063e4552..043882ef3 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -424,6 +424,9 @@ static bool ValidateFinalTx(struct CCcontract_info *cp, Eval *eval, const CTrans if( finaltx.vout.size() == 3 && MakeCC1vout(cp->evalcode, finaltx.vout[1].nValue, pricespk) != finaltx.vout[1] ) return eval->Invalid("cannot validate vout1 in final tx with global pk"); + // TODO: validate exitfee for 'R' + // TODO: validate amount for 'F' + return true; } @@ -1262,13 +1265,13 @@ int32_t prices_syntheticprofits(int64_t &costbasis, int32_t firstheight, int32_t //} } else { - if (height == firstheight + COSTBASIS_PERIOD) { + //if (height == firstheight + COSTBASIS_PERIOD) { // if costbasis not set, just set it //costbasis = price; // use calculated minmax costbasis //std::cerr << "prices_syntheticprofits() use permanent costbasis=" << costbasis << " at height=" << height << std::endl; - } + //} } // normalize to 10,000,000 to prevent underflow @@ -1619,7 +1622,7 @@ int32_t prices_scanchain(std::vector &bets, int16_t leverage, std::v endheight = height; int64_t equity = totalposition + totalprofits; - if (equity < (double)totalposition * prices_minmarginpercent(leverage)) + if (equity <= (int64_t)((double)totalposition * prices_minmarginpercent(leverage))) { // we are in loss break; } @@ -1843,15 +1846,15 @@ int32_t prices_getbetinfo(uint256 bettxid, BetInfo &betinfo) betinfo.liquidationprice = 0; if (betinfo.leverage != 0) {// prevent zero div - betinfo.liquidationprice = betinfo.averageCostbasis - betinfo.averageCostbasis / betinfo.leverage; + betinfo.liquidationprice = betinfo.averageCostbasis - (betinfo.averageCostbasis * (1 - prices_minmarginpercent(betinfo.leverage)))/ betinfo.leverage; } - if (betinfo.equity >= (double)totalposition * prices_minmarginpercent(betinfo.leverage)) + if (betinfo.equity > (int64_t)((double)totalposition * prices_minmarginpercent(betinfo.leverage))) betinfo.isRekt = false; else { betinfo.isRekt = true; - betinfo.exitfee = totalposition / 500; + betinfo.exitfee = (totalposition - betinfo.equity) / 10; // was: totalposition / 500 } mpz_clear(mpzTotalPosition); From 7e57b812a8350fe99055427b5b3caa286bad8fbb Mon Sep 17 00:00:00 2001 From: dimxy Date: Sat, 18 May 2019 01:58:06 +0500 Subject: [PATCH 390/447] added zero prices err code --- src/cc/prices.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 043882ef3..7691dfb24 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -1013,7 +1013,7 @@ int64_t prices_syntheticprice(std::vector vec, int32_t height, int32_t errcode = -1; if (pricestack[depth] == 0) - errcode = -1; + errcode = -14; depth++; break; @@ -1204,7 +1204,10 @@ int64_t prices_syntheticprice(std::vector vec, int32_t height, int32_t std::cerr << "prices_syntheticprice overflow in price" << std::endl; return errcode; } - + if (errcode == -14) { + std::cerr << "prices_syntheticprice price is zero, not enough historic data yet" << std::endl; + return errcode; + } if (den == 0) { std::cerr << "prices_syntheticprice den==0 return err=-11" << std::endl; return(-11); From 1a5f486916b1a53d06e9a98820ff6c5d57953753 Mon Sep 17 00:00:00 2001 From: dimxy Date: Sat, 18 May 2019 02:36:46 +0500 Subject: [PATCH 391/447] logging added for cb --- src/cc/prices.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 7691dfb24..a9aef8722 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -1257,11 +1257,11 @@ int32_t prices_syntheticprofits(int64_t &costbasis, int32_t firstheight, int32_t if (minmax) { // if we are within day window, set temp costbasis to max (or min) price value if (leverage > 0 && price > costbasis) { costbasis = price; // set temp costbasis - //std::cerr << "prices_syntheticprofits() minmax costbasis=" << costbasis << std::endl; + std::cerr << "prices_syntheticprofits() minmax costbasis=" << costbasis << std::endl; } else if (leverage < 0 && (costbasis == 0 || price < costbasis)) { costbasis = price; - //std::cerr << "prices_syntheticprofits() minmax costbasis=" << costbasis << std::endl; + std::cerr << "prices_syntheticprofits() minmax costbasis=" << costbasis << std::endl; } //else { //-> use the previous value // std::cerr << "prices_syntheticprofits() unchanged costbasis=" << costbasis << " price=" << price << " leverage=" << leverage << std::endl; @@ -1273,7 +1273,7 @@ int32_t prices_syntheticprofits(int64_t &costbasis, int32_t firstheight, int32_t //costbasis = price; // use calculated minmax costbasis - //std::cerr << "prices_syntheticprofits() use permanent costbasis=" << costbasis << " at height=" << height << std::endl; + std::cerr << "prices_syntheticprofits() use permanent costbasis=" << costbasis << " at height=" << height << std::endl; //} } From 2117941bb3d0dbf0cbf5567e97579963eb4ac99f Mon Sep 17 00:00:00 2001 From: dimxy Date: Sat, 18 May 2019 02:58:34 +0500 Subject: [PATCH 392/447] corr start scan h --- src/cc/prices.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index a9aef8722..463732e7c 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -1599,7 +1599,7 @@ int32_t prices_scanchain(std::vector &bets, int16_t leverage, std::v return -1; bool stop = false; - for (int32_t height = bets[0].firstheight; ; height++) // the last datum for 24h is the costbasis value + for (int32_t height = bets[0].firstheight+1; ; height++) // the last datum for 24h is the costbasis value { int64_t totalposition = 0; int64_t totalprofits = 0; From 6a23133b4226d094834b04401b9479f533adda06 Mon Sep 17 00:00:00 2001 From: dimxy Date: Sat, 18 May 2019 03:04:29 +0500 Subject: [PATCH 393/447] removed extra logging --- src/cc/prices.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 463732e7c..380af303e 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -1257,11 +1257,11 @@ int32_t prices_syntheticprofits(int64_t &costbasis, int32_t firstheight, int32_t if (minmax) { // if we are within day window, set temp costbasis to max (or min) price value if (leverage > 0 && price > costbasis) { costbasis = price; // set temp costbasis - std::cerr << "prices_syntheticprofits() minmax costbasis=" << costbasis << std::endl; + //std::cerr << "prices_syntheticprofits() minmax costbasis=" << costbasis << std::endl; } else if (leverage < 0 && (costbasis == 0 || price < costbasis)) { costbasis = price; - std::cerr << "prices_syntheticprofits() minmax costbasis=" << costbasis << std::endl; + //std::cerr << "prices_syntheticprofits() minmax costbasis=" << costbasis << std::endl; } //else { //-> use the previous value // std::cerr << "prices_syntheticprofits() unchanged costbasis=" << costbasis << " price=" << price << " leverage=" << leverage << std::endl; @@ -1273,7 +1273,7 @@ int32_t prices_syntheticprofits(int64_t &costbasis, int32_t firstheight, int32_t //costbasis = price; // use calculated minmax costbasis - std::cerr << "prices_syntheticprofits() use permanent costbasis=" << costbasis << " at height=" << height << std::endl; + //std::cerr << "prices_syntheticprofits() use permanent costbasis=" << costbasis << " at height=" << height << std::endl; //} } From 8531278b3477cfdcf9d3af4db149d914a5798974 Mon Sep 17 00:00:00 2001 From: dimxy Date: Sat, 18 May 2019 03:13:01 +0500 Subject: [PATCH 394/447] corr isrekt to true for'R' funcid --- src/cc/prices.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 380af303e..803de625c 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -1944,7 +1944,7 @@ UniValue PricesRekt(int64_t txfee, uint256 bettxid, int32_t rektheight) mtx.vout.push_back(MakeCC1vout(cp->evalcode, CCchange, pricespk)); /// mtx.vout.push_back(MakeCC1vout(cp->evalcode, bettx.vout[2].nValue - myfee - txfee, pricespk)); // change - rawtx = FinalizeCCTx(0, cp, mtx, mypk, txfee, prices_finalopret(false, bettxid, mypk, betinfo.lastheight, betinfo.averageCostbasis, betinfo.lastprice, betinfo.liquidationprice, betinfo.equity, myfee)); + rawtx = FinalizeCCTx(0, cp, mtx, mypk, txfee, prices_finalopret(true, bettxid, mypk, betinfo.lastheight, betinfo.averageCostbasis, betinfo.lastprice, betinfo.liquidationprice, betinfo.equity, myfee)); return(prices_rawtxresult(result, rawtx, 0)); } else From 0816d0e7c24e7042e7616c856af6a0c3db0a9cd9 Mon Sep 17 00:00:00 2001 From: dimxy Date: Sat, 18 May 2019 03:27:56 +0500 Subject: [PATCH 395/447] returned scan chain for finalized for getinfo to work --- src/cc/prices.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 803de625c..defcc567a 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -1782,7 +1782,7 @@ int32_t prices_getbetinfo(uint256 bettxid, BetInfo &betinfo) betinfo.isRekt = (funcId == 'R'); - return 0; + // return 0; } else return -6; From 3e43396242f2e22d379aa23ba31816f04c2e1cb8 Mon Sep 17 00:00:00 2001 From: dimxy Date: Sat, 18 May 2019 03:31:37 +0500 Subject: [PATCH 396/447] added check for isrekt set by final tx --- src/cc/prices.cpp | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index defcc567a..0fb23ac0e 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -1775,12 +1775,12 @@ int32_t prices_getbetinfo(uint256 bettxid, BetInfo &betinfo) CTransaction finaltx; uint256 hashBlock; vscript_t vopret; - if (myGetTransaction(finaltxid, finaltx, hashBlock) && finaltx.vout.size() > 0 && PricesCheckOpret(finaltx, vopret) != 0) { + if (myGetTransaction(finaltxid, finaltx, hashBlock) && finaltx.vout.size() > 0 && PricesCheckOpret(finaltx, vopret) != 0) { uint8_t funcId = prices_finalopretdecode(finaltx.vout.back().scriptPubKey, betinfo.txid, betinfo.pk, betinfo.lastheight, betinfo.averageCostbasis, betinfo.lastprice, betinfo.liquidationprice, betinfo.equity, betinfo.exitfee); if (funcId == 0) return -3; - betinfo.isRekt = (funcId == 'R'); + betinfo.isRekt = (funcId == 'R'); // return 0; } @@ -1849,15 +1849,18 @@ int32_t prices_getbetinfo(uint256 bettxid, BetInfo &betinfo) betinfo.liquidationprice = 0; if (betinfo.leverage != 0) {// prevent zero div - betinfo.liquidationprice = betinfo.averageCostbasis - (betinfo.averageCostbasis * (1 - prices_minmarginpercent(betinfo.leverage)))/ betinfo.leverage; + betinfo.liquidationprice = betinfo.averageCostbasis - (betinfo.averageCostbasis * (1 - prices_minmarginpercent(betinfo.leverage))) / betinfo.leverage; } - if (betinfo.equity > (int64_t)((double)totalposition * prices_minmarginpercent(betinfo.leverage))) - betinfo.isRekt = false; - else - { - betinfo.isRekt = true; - betinfo.exitfee = (totalposition - betinfo.equity) / 10; // was: totalposition / 500 + if (!betinfo.isRekt) { // not set by check for final tx + + if (betinfo.equity > (int64_t)((double)totalposition * prices_minmarginpercent(betinfo.leverage))) + betinfo.isRekt = false; + else + { + betinfo.isRekt = true; + betinfo.exitfee = (totalposition - betinfo.equity) / 10; // was: totalposition / 500 + } } mpz_clear(mpzTotalPosition); From 18452ff4a9453707a0c9f641b5ce3da122c8d598 Mon Sep 17 00:00:00 2001 From: dimxy Date: Sat, 18 May 2019 18:13:47 +0500 Subject: [PATCH 397/447] updated rekt fee calculation --- src/cc/prices.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 0fb23ac0e..01e43cada 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -1859,7 +1859,7 @@ int32_t prices_getbetinfo(uint256 bettxid, BetInfo &betinfo) else { betinfo.isRekt = true; - betinfo.exitfee = (totalposition - betinfo.equity) / 10; // was: totalposition / 500 + betinfo.exitfee = (int64_t)(((double)totalposition * prices_minmarginpercent(betinfo.leverage)) / 10); // was: totalposition / 500 } } From c054a5abdcb7adb319aaf5066310037207e5cb05 Mon Sep 17 00:00:00 2001 From: dimxy Date: Sat, 18 May 2019 18:34:26 +0500 Subject: [PATCH 398/447] logging added --- src/cc/prices.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 01e43cada..1d33c257e 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -2206,11 +2206,11 @@ static bool prices_ispositionup(const std::vector &vecparsed, int16_t if (upperquote == "BTC" || bottomquote == "BTC") { // it is relatively btc if (upperquote == "BTC" && (leverage > 0 && !isInverted || leverage < 0 && isInverted) || bottomquote == "BTC" && (leverage < 0 && !isInverted || leverage > 0 && isInverted)) { - std::cerr << "prices_ispositionup returns true for BTC for expr=" << prices_getsourceexpression(vecparsed) << std::endl; + std::cerr << "prices_ispositionup returns true for BTC for expr=" << prices_getsourceexpression(vecparsed) << " lev=" << leverage << std::endl; return true; } else { - std::cerr << "prices_ispositionup returns false for BTC for expr=" << prices_getsourceexpression(vecparsed) << std::endl; + std::cerr << "prices_ispositionup returns false for BTC for expr=" << prices_getsourceexpression(vecparsed) << " lev=" << leverage << std::endl; return false; } } @@ -2218,18 +2218,18 @@ static bool prices_ispositionup(const std::vector &vecparsed, int16_t if (upperquote == "USD" || bottomquote == "USD") { // it is relatively usd if (upperquote == "USD" && (leverage > 0 && !isInverted || leverage < 0 && isInverted) || bottomquote == "USD" && (leverage < 0 && !isInverted || leverage > 0 && isInverted)) { - std::cerr << "prices_ispositionup returns true for USD for expr=" << prices_getsourceexpression(vecparsed) << std::endl; + std::cerr << "prices_ispositionup returns true for USD for expr=" << prices_getsourceexpression(vecparsed) << " lev=" << leverage << std::endl; return true; } else { - std::cerr << "prices_ispositionup returns false for USD for expr=" << prices_getsourceexpression(vecparsed) << std::endl; + std::cerr << "prices_ispositionup returns false for USD for expr=" << prices_getsourceexpression(vecparsed) << " lev=" << leverage << std::endl; return false; } } } } } - std::cerr << "prices_ispositionup returns false for expr=" << prices_getsourceexpression(vecparsed) << std::endl; + std::cerr << "prices_ispositionup returns false for expr=" << prices_getsourceexpression(vecparsed) << " lev=" << leverage << std::endl; return false; } From e1bd5163cb9b75c77cddb628906e28258cd52c3f Mon Sep 17 00:00:00 2001 From: dimxy Date: Sat, 18 May 2019 19:14:10 +0500 Subject: [PATCH 399/447] added lastprice to orderbook print --- src/cc/prices.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 1d33c257e..10ecd246f 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -2450,10 +2450,10 @@ UniValue PricesGetOrderbook() entry.push_back(Pair("isOpen", (m.second[i].isOpen ? 1 : 0 ))); entry.push_back(Pair("expression", prices_getsourceexpression(m.second[i].vecparsed))); entry.push_back(Pair("positionsize", totalPos)); - entry.push_back(Pair("costbasis", m.second[i].averageCostbasis)); entry.push_back(Pair("leverage", m.second[i].leverage)); + entry.push_back(Pair("costbasis", m.second[i].averageCostbasis)); + entry.push_back(Pair("lastprice", m.second[i].lastprice)); entry.push_back(Pair("equity", m.second[i].equity)); - //std::cerr << "PricesGetOrderbook 1 m.second[i].isUp=" << m.second[i].isUp << " i=" << i << std::endl; entry.push_back(Pair("isUpPosition", (m.second[i].isUp ? 1 : 0))); resbook.push_back(entry); } From 669645b4d4e160484252f73bd6952b456ec5c0ec Mon Sep 17 00:00:00 2001 From: dimxy Date: Sat, 18 May 2019 21:11:10 +0500 Subject: [PATCH 400/447] corr rekt fee for big leverages --- src/cc/prices.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 10ecd246f..246d02329 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -614,7 +614,7 @@ double prices_minmarginpercent(int16_t leverage) if (absleverage < 100) return (absleverage * 0.080808 + 1.9191919) / 100.0; else - return 0.01; + return 0.1; } From 661fe3457181241489a13479eb1cf773e81423d5 Mon Sep 17 00:00:00 2001 From: dimxy Date: Tue, 21 May 2019 20:56:30 +0500 Subject: [PATCH 401/447] added pow to rekt txid --- src/cc/prices.cpp | 41 +++++++++++++++++++++++++++++++++++------ 1 file changed, 35 insertions(+), 6 deletions(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 246d02329..be4d68e7d 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -202,18 +202,20 @@ uint8_t prices_costbasisopretdecode(CScript scriptPubKey,uint256 &bettxid,CPubKe return(0); } -CScript prices_finalopret(bool isRekt, uint256 bettxid, CPubKey pk, int32_t lastheight, int64_t costbasis, int64_t lastprice, int64_t liquidationprice, int64_t equity, int64_t exitfee) +CScript prices_finalopret(bool isRekt, uint256 bettxid, CPubKey pk, int32_t lastheight, int64_t costbasis, int64_t lastprice, int64_t liquidationprice, int64_t equity, int64_t exitfee, uint32_t nonce) { CScript opret; - opret << OP_RETURN << E_MARSHAL(ss << EVAL_PRICES << (isRekt ? 'R' : 'F') << bettxid << pk << lastheight << costbasis << lastprice << liquidationprice << equity << exitfee); + opret << OP_RETURN << E_MARSHAL(ss << EVAL_PRICES << (isRekt ? 'R' : 'F') << bettxid << pk << lastheight << costbasis << lastprice << liquidationprice << equity << exitfee << nonce); return(opret); } uint8_t prices_finalopretdecode(CScript scriptPubKey, uint256 &bettxid, CPubKey &pk, int32_t &lastheight, int64_t &costbasis, int64_t &lastprice, int64_t &liquidationprice, int64_t &equity, int64_t &exitfee) { std::vector vopret; uint8_t e,f; + uint32_t nonce; + GetOpReturnData(scriptPubKey,vopret); - if (vopret.size() > 2 && E_UNMARSHAL(vopret, ss >> e; ss >> f; ss >> bettxid; ss >> pk; ss >> lastheight; ss >> costbasis; ss >> lastprice; ss >> liquidationprice; ss >> equity; ss >> exitfee) != 0 && e == EVAL_PRICES && (f == 'F' || f == 'R')) + if (vopret.size() > 2 && E_UNMARSHAL(vopret, ss >> e; ss >> f; ss >> bettxid; ss >> pk; ss >> lastheight; ss >> costbasis; ss >> lastprice; ss >> liquidationprice; ss >> equity; ss >> exitfee; if (!ss.eof()) ss >> nonce; ) != 0 && e == EVAL_PRICES && (f == 'F' || f == 'R')) { return(f); } @@ -1947,8 +1949,35 @@ UniValue PricesRekt(int64_t txfee, uint256 bettxid, int32_t rektheight) mtx.vout.push_back(MakeCC1vout(cp->evalcode, CCchange, pricespk)); /// mtx.vout.push_back(MakeCC1vout(cp->evalcode, bettx.vout[2].nValue - myfee - txfee, pricespk)); // change - rawtx = FinalizeCCTx(0, cp, mtx, mypk, txfee, prices_finalopret(true, bettxid, mypk, betinfo.lastheight, betinfo.averageCostbasis, betinfo.lastprice, betinfo.liquidationprice, betinfo.equity, myfee)); - return(prices_rawtxresult(result, rawtx, 0)); + + // make some PoW to get txid=0x00.....00 to 'faucet' rekts + fprintf(stderr, "start PoW at %u\n", (uint32_t)time(NULL)); + uint32_t nonce = rand() & 0xfffffff; + for (int i = 0; i<1000000; i++, nonce++) + { + CMutableTransaction tmpmtx = mtx; + int32_t len; + uint8_t txbuf[32768]; + + rawtx = FinalizeCCTx(0, cp, tmpmtx, mypk, txfee, prices_finalopret(true, bettxid, mypk, betinfo.lastheight, betinfo.averageCostbasis, betinfo.lastprice, betinfo.liquidationprice, betinfo.equity, myfee, nonce)); + if ((len = (int32_t)rawtx.size()) > 0 && len < sizeof(txbuf) / sizeof(txbuf[0]) * 2) + { + len >>= 1; // sizeof hex divide by 2 + decode_hex(txbuf, len, (char *)rawtx.c_str()); + bits256 hash = bits256_doublesha256(0, txbuf, 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(prices_rawtxresult(result, rawtx, 0)); + } + //fprintf(stderr,"%02x%02x ",hash.bytes[0],hash.bytes[31]); + } + } + fprintf(stderr, "couldnt generate valid txid %u\n", (uint32_t)time(NULL)); + + result.push_back(Pair("result", "error")); + result.push_back(Pair("error", "could not generate valid txid")); + return(result); } else { @@ -2031,7 +2060,7 @@ UniValue PricesCashout(int64_t txfee, uint256 bettxid) if (CCchange >= txfee) mtx.vout.push_back(MakeCC1vout(cp->evalcode, CCchange, pricespk)); // TODO: what should the opret param be: - rawtx = FinalizeCCTx(0, cp, mtx, mypk, txfee, prices_finalopret(false, bettxid, mypk, nextheight-1, betinfo.averageCostbasis, betinfo.lastprice, betinfo.liquidationprice, betinfo.equity, txfee)); + rawtx = FinalizeCCTx(0, cp, mtx, mypk, txfee, prices_finalopret(false, bettxid, mypk, nextheight-1, betinfo.averageCostbasis, betinfo.lastprice, betinfo.liquidationprice, betinfo.equity, txfee, 0)); return(prices_rawtxresult(result, rawtx, 0)); } From bf3874ef765033955e4d38c8f0c5dd5c442f9bd8 Mon Sep 17 00:00:00 2001 From: dimxy Date: Tue, 21 May 2019 21:21:52 +0500 Subject: [PATCH 402/447] simplified rekt hash check --- src/cc/prices.cpp | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index be4d68e7d..5ab1ff12f 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -1956,22 +1956,24 @@ UniValue PricesRekt(int64_t txfee, uint256 bettxid, int32_t rektheight) for (int i = 0; i<1000000; i++, nonce++) { CMutableTransaction tmpmtx = mtx; - int32_t len; - uint8_t txbuf[32768]; + //int32_t len; + //uint8_t txbuf[32768]; rawtx = FinalizeCCTx(0, cp, tmpmtx, mypk, txfee, prices_finalopret(true, bettxid, mypk, betinfo.lastheight, betinfo.averageCostbasis, betinfo.lastprice, betinfo.liquidationprice, betinfo.equity, myfee, nonce)); - if ((len = (int32_t)rawtx.size()) > 0 && len < sizeof(txbuf) / sizeof(txbuf[0]) * 2) - { - len >>= 1; // sizeof hex divide by 2 - decode_hex(txbuf, len, (char *)rawtx.c_str()); - bits256 hash = bits256_doublesha256(0, txbuf, len); - if ((hash.bytes[0] & 0xff) == 0 && (hash.bytes[31] & 0xff) == 0) + //if ((len = (int32_t)rawtx.size()) > 0 && len < sizeof(txbuf) / sizeof(txbuf[0]) * 2) + //{ + // len >>= 1; // sizeof hex divide by 2 + //decode_hex(txbuf, len, (char *)rawtx.c_str()); + //bits256 hash = bits256_doublesha256(0, txbuf, len); + uint256 hash = tmpmtx.GetHash(); + //if ((hash.bytes[0] & 0xff) == 0 && (hash.bytes[31] & 0xff) == 0) + if ((hash.begin()[0] & 0xff) == 0 && (hash.begin()[31] & 0xff) == 0) { fprintf(stderr, "found valid txid after %d iterations %u\n", i, (uint32_t)time(NULL)); return(prices_rawtxresult(result, rawtx, 0)); } //fprintf(stderr,"%02x%02x ",hash.bytes[0],hash.bytes[31]); - } + //} } fprintf(stderr, "couldnt generate valid txid %u\n", (uint32_t)time(NULL)); From 74c29d0df7a5d5ed0ec3460cad1e21886ad56100 Mon Sep 17 00:00:00 2001 From: dimxy Date: Tue, 21 May 2019 22:12:46 +0500 Subject: [PATCH 403/447] added validation for rekt txid --- src/cc/prices.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 5ab1ff12f..218211324 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -412,9 +412,14 @@ static bool ValidateFinalTx(struct CCcontract_info *cp, Eval *eval, const CTrans } vscript_t opret; - if (prices_finalopretdecode(finaltx.vout.back().scriptPubKey, bettxid, pk, lastheight, costbasis, lastprice, liquidationprice, equity, fee) == 0) + uint8_t funcId; + if ((funcId = prices_finalopretdecode(finaltx.vout.back().scriptPubKey, bettxid, pk, lastheight, costbasis, lastprice, liquidationprice, equity, fee)) == 0) return eval->Invalid("cannot decode opreturn for final tx"); + // check rekt txid mining: + if( funcId == 'R' && (finaltx.GetHash().begin()[0] != 0 || finaltx.GetHash().begin()[31] != 0) ) + return eval->Invalid("incorrect rekt txid"); + if (bettx.GetHash() != bettxid) return eval->Invalid("incorrect bettx id"); From 9553165287264dd6b24abaaeea8f07d5af40fbdc Mon Sep 17 00:00:00 2001 From: dimxy Date: Tue, 21 May 2019 23:40:29 +0500 Subject: [PATCH 404/447] remove rekt txid validation --- src/cc/prices.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 218211324..2c0a33b20 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -417,8 +417,8 @@ static bool ValidateFinalTx(struct CCcontract_info *cp, Eval *eval, const CTrans return eval->Invalid("cannot decode opreturn for final tx"); // check rekt txid mining: - if( funcId == 'R' && (finaltx.GetHash().begin()[0] != 0 || finaltx.GetHash().begin()[31] != 0) ) - return eval->Invalid("incorrect rekt txid"); +// if( funcId == 'R' && (finaltx.GetHash().begin()[0] != 0 || finaltx.GetHash().begin()[31] != 0) ) +// return eval->Invalid("incorrect rekt txid"); if (bettx.GetHash() != bettxid) return eval->Invalid("incorrect bettx id"); From e7cf45efbe7524b1b2341568a367c9f540880437 Mon Sep 17 00:00:00 2001 From: PHBA2061 Date: Thu, 23 May 2019 21:55:55 +0200 Subject: [PATCH 405/447] Update notaries_staked.h Adding PHBA2061's publey & address --- src/notaries_staked.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/notaries_staked.h b/src/notaries_staked.h index fb6051b2b..76c304e71 100644 --- a/src/notaries_staked.h +++ b/src/notaries_staked.h @@ -50,6 +50,7 @@ static const char *notaries_STAKED[NUM_STAKED_ERAS][64][2] = {"SHossain", "02791f5c215b8a19c143a98e3371ff03b5613df9ac430c4a331ca55fed5761c800" }, // RKdLoHkyeorXmMtj91B1AAnAGiwsdt9MdF {"Nabob", "03ee91c20b6d26e3604022f42df6bb8de6f669da4591f93b568778cba13d9e9ddf" }, // RRwCLPZDzpHEFJnLev4phy51e2stHRUAaU {"mylo", "03f6b7fcaf0b8b8ec432d0de839a76598b78418dadd50c8e5594c0e557d914ec09" }, // RXN4hoZkhUkkrnef9nTUDw3E3vVALAD8Kx + {"PHBA2061", "039fc98c764bc85aed97d690d7942a4fd1190b2fa4f5f4c5c8e0957fac5c6ede00" }, // RPHba2o61hcpX4ds91oj3sKJ8aDXv6QdQf }, { {"blackjok3r", "021914947402d936a89fbdd1b12be49eb894a1568e5e17bb18c8a6cffbd3dc106e" }, // RTVti13NP4eeeZaCCmQxc2bnPdHxCJFP9x From 45aecd9c3c1729bf7060ac01a147ca714f175d04 Mon Sep 17 00:00:00 2001 From: DeckerSU Date: Fri, 24 May 2019 11:36:20 +0300 Subject: [PATCH 406/447] osx: switch to gcc-8 static build --- depends/builders/darwin.mk | 8 ++++---- src/Makefile.am | 5 +++++ src/chain.h | 2 +- src/consensus/params.h | 4 ++-- src/crypto/verus_hash.h | 1 + src/main.cpp | 4 +++- src/miner.cpp | 2 +- src/script/script_ext.cpp | 1 + zcutil/build-mac.sh | 2 +- 9 files changed, 19 insertions(+), 10 deletions(-) diff --git a/depends/builders/darwin.mk b/depends/builders/darwin.mk index f9b066fcf..cbbc5a667 100644 --- a/depends/builders/darwin.mk +++ b/depends/builders/darwin.mk @@ -1,5 +1,5 @@ -build_darwin_CC = gcc-6 -build_darwin_CXX = g++-6 +build_darwin_CC = gcc-8 +build_darwin_CXX = g++-8 build_darwin_AR: = $(shell xcrun -f ar) build_darwin_RANLIB: = $(shell xcrun -f ranlib) build_darwin_STRIP: = $(shell xcrun -f strip) @@ -10,8 +10,8 @@ build_darwin_SHA256SUM = shasum -a 256 build_darwin_DOWNLOAD = curl --connect-timeout $(DOWNLOAD_CONNECT_TIMEOUT) --retry $(DOWNLOAD_RETRIES) -L -f -o #darwin host on darwin builder. overrides darwin host preferences. -darwin_CC= gcc-6 -darwin_CXX= g++-6 +darwin_CC= gcc-8 +darwin_CXX= g++-8 darwin_AR:=$(shell xcrun -f ar) darwin_RANLIB:=$(shell xcrun -f ranlib) darwin_STRIP:=$(shell xcrun -f strip) diff --git a/src/Makefile.am b/src/Makefile.am index 874c3a8b4..a1b403b07 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -574,6 +574,11 @@ if ENABLE_PROTON komodod_LDADD += $(LIBBITCOIN_PROTON) $(PROTON_LIBS) endif +# [+] Decker: use static linking for libstdc++.6.dylib, libgomp.1.dylib, libgcc_s.1.dylib +if TARGET_DARWIN +komodod_LDFLAGS += -static-libgcc +endif + # bitcoin-cli binary # komodo_cli_SOURCES = bitcoin-cli.cpp komodo_cli_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES) $(EVENT_CFLAGS) diff --git a/src/chain.h b/src/chain.h index 0b6e2b046..d5310e4e5 100644 --- a/src/chain.h +++ b/src/chain.h @@ -335,7 +335,7 @@ public: nSolution = block.nSolution; } - int32_t SetHeight(int32_t height) + void SetHeight(int32_t height) { this->chainPower.nHeight = height; } diff --git a/src/consensus/params.h b/src/consensus/params.h index b7dc8b475..0ea5b1fff 100644 --- a/src/consensus/params.h +++ b/src/consensus/params.h @@ -115,8 +115,8 @@ struct Params { int64_t AveragingWindowTimespan() const { return nPowAveragingWindow * nPowTargetSpacing; } int64_t MinActualTimespan() const { return (AveragingWindowTimespan() * (100 - nPowMaxAdjustUp )) / 100; } int64_t MaxActualTimespan() const { return (AveragingWindowTimespan() * (100 + nPowMaxAdjustDown)) / 100; } - int32_t SetSaplingHeight(int32_t height) { vUpgrades[Consensus::UPGRADE_SAPLING].nActivationHeight = height; } - int32_t SetOverwinterHeight(int32_t height) { vUpgrades[Consensus::UPGRADE_OVERWINTER].nActivationHeight = height; } + void SetSaplingHeight(int32_t height) { vUpgrades[Consensus::UPGRADE_SAPLING].nActivationHeight = height; } + void SetOverwinterHeight(int32_t height) { vUpgrades[Consensus::UPGRADE_OVERWINTER].nActivationHeight = height; } uint256 nMinimumChainWork; }; } // namespace Consensus diff --git a/src/crypto/verus_hash.h b/src/crypto/verus_hash.h index 5ac49c209..f6cb3d9bd 100644 --- a/src/crypto/verus_hash.h +++ b/src/crypto/verus_hash.h @@ -86,6 +86,7 @@ class CVerusHashV2 result = buf2; curPos = 0; std::fill(buf1, buf1 + sizeof(buf1), 0); + return *this; } int64_t *ExtraI64Ptr() { return (int64_t *)(curBuf + 32); } diff --git a/src/main.cpp b/src/main.cpp index 3d2f19b55..84f1b611a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3839,7 +3839,8 @@ bool static DisconnectTip(CValidationState &state, bool fBare = false) { int32_t komodo_activate_sapling(CBlockIndex *pindex) { - uint32_t blocktime,prevtime; CBlockIndex *prev; int32_t i,transition=0,height,prevht,activation = 0; + uint32_t blocktime,prevtime; CBlockIndex *prev; int32_t i,transition=0,height,prevht; + int32_t activation = 0; if ( pindex == 0 ) { fprintf(stderr,"komodo_activate_sapling null pindex\n"); @@ -3897,6 +3898,7 @@ int32_t komodo_activate_sapling(CBlockIndex *pindex) fprintf(stderr,"%s sapling activation at %d\n",ASSETCHAINS_SYMBOL,activation); ASSETCHAINS_SAPLING = activation; } + return activation; } static int64_t nTimeReadFromDisk = 0; diff --git a/src/miner.cpp b/src/miner.cpp index 01ee92234..c4944fbad 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -840,7 +840,7 @@ int32_t roundrobin_delay; arith_uint256 HASHTarget,HASHTarget_POW; // wait for peers to connect -int32_t waitForPeers(const CChainParams &chainparams) +void waitForPeers(const CChainParams &chainparams) { if (chainparams.MiningRequiresPeers()) { diff --git a/src/script/script_ext.cpp b/src/script/script_ext.cpp index 613b50c05..a0786fa9c 100644 --- a/src/script/script_ext.cpp +++ b/src/script/script_ext.cpp @@ -70,6 +70,7 @@ const CScriptExt &CScriptExt::AddCheckLockTimeVerify(int64_t unlocktime) const *((CScript *)this) << OP_DROP; return *this; } + return *this; } // combined CLTV script and P2PKH diff --git a/zcutil/build-mac.sh b/zcutil/build-mac.sh index 138508cb5..0a9ec688a 100755 --- a/zcutil/build-mac.sh +++ b/zcutil/build-mac.sh @@ -44,7 +44,7 @@ make "$@" -C ./depends/ V=1 NO_QT=1 NO_PROTON=1 ./autogen.sh CPPFLAGS="-I$PREFIX/include -arch x86_64" LDFLAGS="-L$PREFIX/lib -arch x86_64 -Wl,-no_pie" \ -CXXFLAGS='-arch x86_64 -I/usr/local/Cellar/gcc\@6/6.4.0_2/include/c++/6.4.0/ -I$PREFIX/include -fwrapv -fno-strict-aliasing -Werror -g -Wl,-undefined -Wl,dynamic_lookup' \ +CXXFLAGS='-arch x86_64 -I/usr/local/Cellar/gcc\@6/6.4.0_2/include/c++/6.4.0/ -I$PREFIX/include -fwrapv -fno-strict-aliasing -Wno-builtin-declaration-mismatch -Werror -g -Wl,-undefined -Wl,dynamic_lookup' \ ./configure --prefix="${PREFIX}" --with-gui=no "$HARDENING_ARG" "$LCOV_ARG" make "$@" V=1 NO_GTEST=1 STATIC=1 From a8680fed32f13cb63a0771cc6215c01a321cf0aa Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Fri, 24 May 2019 21:39:14 +0800 Subject: [PATCH 407/447] kill RCTEST, update pubkeys --- src/notaries_staked.cpp | 2 +- src/notaries_staked.h | 65 +++-------------------------------------- 2 files changed, 5 insertions(+), 62 deletions(-) diff --git a/src/notaries_staked.cpp b/src/notaries_staked.cpp index bb1518262..cbbcd57db 100644 --- a/src/notaries_staked.cpp +++ b/src/notaries_staked.cpp @@ -18,7 +18,7 @@ int8_t is_STAKED(const char *chain_name) if (doneinit == 1 && ASSETCHAINS_SYMBOL[0] != 0) return(STAKED); else STAKED = 0; - if ( (strcmp(chain_name, "LABS") == 0) || (strcmp(chain_name, "LABSRCTEST") == 0) ) + if ( (strcmp(chain_name, "LABS") == 0) ) STAKED = 1; // These chains are allowed coin emissions. else if ( (strncmp(chain_name, "LABS", 4) == 0) ) STAKED = 2; // These chains have no coin emission, block subsidy is always 0, and comission is 0. Notary pay is allowed. diff --git a/src/notaries_staked.h b/src/notaries_staked.h index e7a891f7b..f5129ae16 100644 --- a/src/notaries_staked.h +++ b/src/notaries_staked.h @@ -24,7 +24,7 @@ static const int STAKED_ERA_GAP = 777; static const int NUM_STAKED_ERAS = 4; static const int STAKED_NOTARIES_TIMESTAMP[NUM_STAKED_ERAS] = {1604244444, 1604244444, 1604244444, 1604244444}; -static const int32_t num_notaries_STAKED[NUM_STAKED_ERAS] = { 20, 25, 19, 17 }; +static const int32_t num_notaries_STAKED[NUM_STAKED_ERAS] = { 22, 1, 1, 1 }; // Era array of pubkeys. static const char *notaries_STAKED[NUM_STAKED_ERAS][64][2] = @@ -35,12 +35,12 @@ static const char *notaries_STAKED[NUM_STAKED_ERAS][64][2] = {"webworker01", "031d1fb39ae4dca28965c3abdbd21faa0f685f6d7b87a60561afa7c448343fef6d" }, //RGsQiArk5sTmjXZV9UzGMW5njyvtSnsTN8 {"CrisF", "024d19acf0d5de212cdd50326cd143292545d366a71b2b9c6df9f2110de2dfa1f2" }, // RKtAD2kyRRMx4EiG1eeTNprF5h2nmGbzzu {"smk762", "02381616fbc02d3f0398c912fe7b7daf2f3f29e55dc35287f686b15686d8135a9f" }, // RSchwBApVquaG6mXH31bQ6P83kMN4Hound - {"jorian", "0288e682c1ac449f1b85c4acb2d0bcd216d5df34c15fd18b8a8dd5fa64b8ece8ef" }, // RR1yT5aB19VwFoUCGTW4q4pk4qmhHEEE4t + {"jorian", "0343eec31037d7b909efd968a5b5e7af60321bf7e464da28f815f0fb23ee7aadd7" }, // RJorianBXNwfNDYPxtNYJJ6vX7Z3VdTR25 {"TonyL", "021a559101e355c907d9c553671044d619769a6e71d624f68bfec7d0afa6bd6a96" }, // RHq3JsvLxU45Z8ufYS6RsDpSG4wi6ucDev {"CHMEX", "03ed125d1beb118d12ff0a052bdb0cee32591386d718309b2924f2c36b4e7388e6" }, // RF4HiVeuYpaznRPs7fkRAKKYqT5tuxQQTL {"metaphilibert", "0344182c376f054e3755d712361672138660bda8005abb64067eb5aa98bdb40d10" }, // RG28QSnYFADBg1dAVkH1uPGYS6F8ioEUM2 {"gt", "02312dcecb6e4a32927a075972d3c009f3c68635d8100562cc1813ea66751b9fde" }, // RCg4tzKWQ7i3wrZEU8bvCbCQ4xRJnHnyoo - {"CMaurice", "025830ce81bd1301fb67d5872344efa7a9ff99ae85fe1234f18c085db9072b740f" }, // RX7pXUaV24xFn6DVKV8t3PrRF3gKw6TBjf + {"CMaurice", "026c6d094523e810641b89f2d7f0ddd8f0b59d97c32e1fa97f0e3e0ac119c26ae4" }, // RSjayeSuYUE1E22rBjnqoexobaRjbAZ2Yb {"Bar_F1sh_Rel", "0395f2d9dd9ccb78caf74bff49b6d959afb95af746462e1b35f4a167d8e82b3666" }, // RBbLxJagCA9QHDazQvfnDZe874V1K4Gu8t {"zatJUM", "030fff499b6dc0215344b28a0b6b4becdfb00cd34cd1b36b983ec14f47965fd4bc" }, // RSoEDLBasth7anxS8gbkg6KgeGiz8rhqv1 {"dwy", "03669457b2934d98b5761121dd01b243aed336479625b293be9f8c43a6ae7aaeff" }, // RKhZMqRF361FSGFAzstP5AhozekPjoVh5q @@ -51,73 +51,16 @@ static const char *notaries_STAKED[NUM_STAKED_ERAS][64][2] = {"Nabob", "03ee91c20b6d26e3604022f42df6bb8de6f669da4591f93b568778cba13d9e9ddf" }, // RRwCLPZDzpHEFJnLev4phy51e2stHRUAaU {"mylo", "03f6b7fcaf0b8b8ec432d0de839a76598b78418dadd50c8e5594c0e557d914ec09" }, // RXN4hoZkhUkkrnef9nTUDw3E3vVALAD8Kx {"PHBA2061", "039fc98c764bc85aed97d690d7942a4fd1190b2fa4f5f4c5c8e0957fac5c6ede00" }, // RPHba2o61hcpX4ds91oj3sKJ8aDXv6QdQf + {"Exile13", "0247b2120a39faf83678b5de6883e039180ff42925bcb298d32f3792cd59001aae" }, // RTDJ3CDZ6ANbeDKab8nqTVrGw7ViAKLeDV }, { {"blackjok3r", "021914947402d936a89fbdd1b12be49eb894a1568e5e17bb18c8a6cffbd3dc106e" }, // RTVti13NP4eeeZaCCmQxc2bnPdHxCJFP9x - {"alright", "0285657c689b903218c97f5f10fe1d10ace2ed6595112d9017f54fb42ea1c1dda8" }, //RXmXeQ8LfJK6Y1aTM97cRz9Gu5f6fmR3sg - {"webworker01", "031d1fb39ae4dca28965c3abdbd21faa0f685f6d7b87a60561afa7c448343fef6d" }, //RGsQiArk5sTmjXZV9UzGMW5njyvtSnsTN8 - {"CrisF", "024d19acf0d5de212cdd50326cd143292545d366a71b2b9c6df9f2110de2dfa1f2" }, // RKtAD2kyRRMx4EiG1eeTNprF5h2nmGbzzu - {"smk762", "029f6c1f38c4d6825acb3b4b5147f7992e943b617cdaa0f4f5f36187e239d52d5a" }, // RPy6Xj2LWrxNoEW9YyREDgBZDZZ5qURXBU - {"jorian", "0288e682c1ac449f1b85c4acb2d0bcd216d5df34c15fd18b8a8dd5fa64b8ece8ef" }, // RR1yT5aB19VwFoUCGTW4q4pk4qmhHEEE4t - {"TonyL", "021a559101e355c907d9c553671044d619769a6e71d624f68bfec7d0afa6bd6a96" }, // RHq3JsvLxU45Z8ufYS6RsDpSG4wi6ucDev - {"Emman", "038f642dcdacbdf510b7869d74544dbc6792548d9d1f8d73a999dd9f45f513c935" }, //RN2KsQGW36Ah4NorJDxLJp2xiYJJEzk9Y6 - {"CHMEX", "03ed125d1beb118d12ff0a052bdb0cee32591386d718309b2924f2c36b4e7388e6" }, // RF4HiVeuYpaznRPs7fkRAKKYqT5tuxQQTL - {"metaphilibert", "0344182c376f054e3755d712361672138660bda8005abb64067eb5aa98bdb40d10" }, // RG28QSnYFADBg1dAVkH1uPGYS6F8ioEUM2 - {"jusoaresf", "02dfb7ed72a23f6d07f0ea2f28192ee174733cc8412ec0f97b073007b78fab6346" }, // RBQGfE5Hxsjm1BPraTxbneRuNasPDuoLnu - {"mylo", "03f6b7fcaf0b8b8ec432d0de839a76598b78418dadd50c8e5594c0e557d914ec09" }, // RXN4hoZkhUkkrnef9nTUDw3E3vVALAD8Kx - {"greentea", "02054c14ae81838a063d22a75eaa3c961415f6825a57c8b8e4148d19dad64f128e" }, // REF7R76WpL1v7nSXjjiNHtRa2xYtq5qk1p - {"CMaurice", "025830ce81bd1301fb67d5872344efa7a9ff99ae85fe1234f18c085db9072b740f" }, // RX7pXUaV24xFn6DVKV8t3PrRF3gKw6TBjf - {"kmdkrazy", "02da444a2627d420f1f622fcdfb9bddb67d6d4241ad6b4d5054716ddbde8a25dfb" }, // RJPJBbHcm5mkAxhkkERHRfEE9Cvkr4Euoi - {"Bar_F1sh_Rel", "0395f2d9dd9ccb78caf74bff49b6d959afb95af746462e1b35f4a167d8e82b3666" }, // RBbLxJagCA9QHDazQvfnDZe874V1K4Gu8t - {"zatJUM", "030fff499b6dc0215344b28a0b6b4becdfb00cd34cd1b36b983ec14f47965fd4bc" }, // RSoEDLBasth7anxS8gbkg6KgeGiz8rhqv1 - {"dwy", "03669457b2934d98b5761121dd01b243aed336479625b293be9f8c43a6ae7aaeff" }, // RKhZMqRF361FSGFAzstP5AhozekPjoVh5q - {"dukeleto", "03e4322510ee46d417b8382fe124f5a381a3cef6aef08f8a4e90c66a42a04b4015" }, // RB8vS1fkGuttoNYkA2B1ivNn8vhqbCEqbe - {"gcharang", "03336ca9db27cb6e882830e20dc525884e27dc94d557a5e68b972a5cbf9e8c62a8" }, // RJYiWn3FRCSSLf9Pe5RJcbrKQYosaMburP - {"ca333", "03a18a33313ccdbf3c9778776e33c423e073ff5833fa1de092ce9e921de52f22f6" }, // RX333A56jWdeW15MwZsaW3mHxGaDu2Yutp - {"computergenie", "03448ce28fb21748e8b05bbe32d6b1e758b589ac1eb359e5d552f8868f2b75dc92" }, // RGeniexxkjnR34hg7ZnCf36kmfuJusf6rE - {"daemonfox", "0383484bdc745b2b953c85b5a0c496a1f27bc42ae971f15779ed1532421b3dd943" }, // - {"SHossain", "02791f5c215b8a19c143a98e3371ff03b5613df9ac430c4a331ca55fed5761c800" }, // RKdLoHkyeorXmMtj91B1AAnAGiwsdt9MdF - {"Nabob", "03ee91c20b6d26e3604022f42df6bb8de6f669da4591f93b568778cba13d9e9ddf" }, // RRwCLPZDzpHEFJnLev4phy51e2stHRUAaU }, { {"blackjok3r", "021914947402d936a89fbdd1b12be49eb894a1568e5e17bb18c8a6cffbd3dc106e" }, // RTVti13NP4eeeZaCCmQxc2bnPdHxCJFP9x - {"alright", "0285657c689b903218c97f5f10fe1d10ace2ed6595112d9017f54fb42ea1c1dda8" }, //RXmXeQ8LfJK6Y1aTM97cRz9Gu5f6fmR3sg - {"webworker01", "031d1fb39ae4dca28965c3abdbd21faa0f685f6d7b87a60561afa7c448343fef6d" }, //RGsQiArk5sTmjXZV9UzGMW5njyvtSnsTN8 - {"CrisF", "024d19acf0d5de212cdd50326cd143292545d366a71b2b9c6df9f2110de2dfa1f2" }, // RKtAD2kyRRMx4EiG1eeTNprF5h2nmGbzzu - {"smk762", "029f6c1f38c4d6825acb3b4b5147f7992e943b617cdaa0f4f5f36187e239d52d5a" }, // RPy6Xj2LWrxNoEW9YyREDgBZDZZ5qURXBU - {"jorian", "0288e682c1ac449f1b85c4acb2d0bcd216d5df34c15fd18b8a8dd5fa64b8ece8ef" }, // RR1yT5aB19VwFoUCGTW4q4pk4qmhHEEE4t - {"TonyL", "021a559101e355c907d9c553671044d619769a6e71d624f68bfec7d0afa6bd6a96" }, // RHq3JsvLxU45Z8ufYS6RsDpSG4wi6ucDev - {"CHMEX", "03ed125d1beb118d12ff0a052bdb0cee32591386d718309b2924f2c36b4e7388e6" }, // RF4HiVeuYpaznRPs7fkRAKKYqT5tuxQQTL - {"metaphilibert", "0344182c376f054e3755d712361672138660bda8005abb64067eb5aa98bdb40d10" }, // RG28QSnYFADBg1dAVkH1uPGYS6F8ioEUM2 - {"greentea", "02054c14ae81838a063d22a75eaa3c961415f6825a57c8b8e4148d19dad64f128e" }, // REF7R76WpL1v7nSXjjiNHtRa2xYtq5qk1p - {"CMaurice", "025830ce81bd1301fb67d5872344efa7a9ff99ae85fe1234f18c085db9072b740f" }, // RX7pXUaV24xFn6DVKV8t3PrRF3gKw6TBjf - {"Bar_F1sh_Rel", "0395f2d9dd9ccb78caf74bff49b6d959afb95af746462e1b35f4a167d8e82b3666" }, // RBbLxJagCA9QHDazQvfnDZe874V1K4Gu8t - {"zatJUM", "030fff499b6dc0215344b28a0b6b4becdfb00cd34cd1b36b983ec14f47965fd4bc" }, // RSoEDLBasth7anxS8gbkg6KgeGiz8rhqv1 - {"dwy", "03669457b2934d98b5761121dd01b243aed336479625b293be9f8c43a6ae7aaeff" }, // RKhZMqRF361FSGFAzstP5AhozekPjoVh5q - {"gcharang", "03336ca9db27cb6e882830e20dc525884e27dc94d557a5e68b972a5cbf9e8c62a8" }, // RJYiWn3FRCSSLf9Pe5RJcbrKQYosaMburP - {"computergenie", "03448ce28fb21748e8b05bbe32d6b1e758b589ac1eb359e5d552f8868f2b75dc92" }, // RGeniexxkjnR34hg7ZnCf36kmfuJusf6rE - {"daemonfox", "0383484bdc745b2b953c85b5a0c496a1f27bc42ae971f15779ed1532421b3dd943" }, // - {"SHossain", "02791f5c215b8a19c143a98e3371ff03b5613df9ac430c4a331ca55fed5761c800" }, // RKdLoHkyeorXmMtj91B1AAnAGiwsdt9MdF - {"Nabob", "03ee91c20b6d26e3604022f42df6bb8de6f669da4591f93b568778cba13d9e9ddf" }, // RRwCLPZDzpHEFJnLev4phy51e2stHRUAaU }, { {"blackjok3r", "021914947402d936a89fbdd1b12be49eb894a1568e5e17bb18c8a6cffbd3dc106e" }, // RTVti13NP4eeeZaCCmQxc2bnPdHxCJFP9x - {"alright", "0285657c689b903218c97f5f10fe1d10ace2ed6595112d9017f54fb42ea1c1dda8" }, //RXmXeQ8LfJK6Y1aTM97cRz9Gu5f6fmR3sg - {"webworker01", "031d1fb39ae4dca28965c3abdbd21faa0f685f6d7b87a60561afa7c448343fef6d" }, //RGsQiArk5sTmjXZV9UzGMW5njyvtSnsTN8 - {"CrisF", "03f87f1bccb744d90fdbf7fad1515a98e9fc7feb1800e460d2e7565b88c3971bf3" }, //RMwEpnaVe3cesWbMqqKYPPkaLcDkooTDgZ - {"smk762", "02eacef682d2f86e0103c18f4da46116e17196f3fb8f73ed931acb78e81d8e1aa5" }, // RQVvzJ8gepCDVjhqCAc5Tia1kTmt8KDPL9 - {"jorian", "02150c410a606b898bcab4f083e48e0f98a510e0d48d4db367d37f318d26ae72e3" }, // RFgzxZe2P4RWKx6E9QGPK3rx3TXeWxSqa8 - {"TonyL", "021a559101e355c907d9c553671044d619769a6e71d624f68bfec7d0afa6bd6a96" }, // RHq3JsvLxU45Z8ufYS6RsDpSG4wi6ucDev - {"Emman", "038f642dcdacbdf510b7869d74544dbc6792548d9d1f8d73a999dd9f45f513c935" }, //RN2KsQGW36Ah4NorJDxLJp2xiYJJEzk9Y6 - {"CHMEX", "03ed125d1beb118d12ff0a052bdb0cee32591386d718309b2924f2c36b4e7388e6" }, // RF4HiVeuYpaznRPs7fkRAKKYqT5tuxQQTL - {"metaphilibert", "0344182c376f054e3755d712361672138660bda8005abb64067eb5aa98bdb40d10" }, // RG28QSnYFADBg1dAVkH1uPGYS6F8ioEUM2 - {"jusoaresf", "02dfb7ed72a23f6d07f0ea2f28192ee174733cc8412ec0f97b073007b78fab6346" }, // RBQGfE5Hxsjm1BPraTxbneRuNasPDuoLnu - {"mylo", "03f6b7fcaf0b8b8ec432d0de839a76598b78418dadd50c8e5594c0e557d914ec09" }, // RXN4hoZkhUkkrnef9nTUDw3E3vVALAD8Kx - {"blackjok3r2", "02f7597468703c1c5c8465dd6d43acaae697df9df30bed21494d193412a1ea193e" }, // RWHGbrLSP89fTzNVF9U9xiekDYJqcibTca - {"blackjok3r3", "03c3e4c0206551dbf3a4b24d18e5d2737080541184211e3bfd2b1092177410b9c2" }, // RMMav2AVse5XHPvDfTzRpMbFhK3GqFmtSN - {"kmdkrazy", "02f7597468703c1c5c8465dd6d43acaae697df9df30bed21494d193412a1ea193e" }, // RWHGbrLSP89fTzNVF9U9xiekDYJqcibTca - {"alrighttest", "02e9dfe248f453b499315a90375e58a1c9ad79f5f3932ecb2205399a0f262d65fc" }, // RBevSstS8JtDXMEFNcJws4QTYN4PcE2VL5 - {"alrighttest1", "03527c7ecd6a8c5db6d685a64e6e18c1edb49e2f057a434f56c3f1253a26e9c6a2" }, // RBw2jNU3dnGk86ZLqPMadJwRwg3NU8eC6s } }; From 39b3ea70626fe36ac6a5c532ba13a81f620f2e92 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Fri, 24 May 2019 21:43:26 +0800 Subject: [PATCH 408/447] fix CrisF --- src/notaries_staked.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/notaries_staked.h b/src/notaries_staked.h index f5129ae16..fc6b24d58 100644 --- a/src/notaries_staked.h +++ b/src/notaries_staked.h @@ -15,7 +15,7 @@ static const char *iguanaSeeds[8][1] = {"18.224.176.46"}, {"45.76.120.247"}, {"185.62.57.32"}, - {"103.6.12.112"}, + {"149.28.253.160"}, {"103.6.12.112"}, {"103.6.12.112"}, }; @@ -33,7 +33,7 @@ static const char *notaries_STAKED[NUM_STAKED_ERAS][64][2] = {"blackjok3r", "021914947402d936a89fbdd1b12be49eb894a1568e5e17bb18c8a6cffbd3dc106e" }, // RTVti13NP4eeeZaCCmQxc2bnPdHxCJFP9x {"alright", "0285657c689b903218c97f5f10fe1d10ace2ed6595112d9017f54fb42ea1c1dda8" }, //RXmXeQ8LfJK6Y1aTM97cRz9Gu5f6fmR3sg {"webworker01", "031d1fb39ae4dca28965c3abdbd21faa0f685f6d7b87a60561afa7c448343fef6d" }, //RGsQiArk5sTmjXZV9UzGMW5njyvtSnsTN8 - {"CrisF", "024d19acf0d5de212cdd50326cd143292545d366a71b2b9c6df9f2110de2dfa1f2" }, // RKtAD2kyRRMx4EiG1eeTNprF5h2nmGbzzu + {"CrisF", "03745656c8991c4597828aad2820760c43c00ff2e3b381fef3b5c040f32a7b3a34" }, // RKtAD2kyRRMx4EiG1eeTNprF5h2nmGbzzu {"smk762", "02381616fbc02d3f0398c912fe7b7daf2f3f29e55dc35287f686b15686d8135a9f" }, // RSchwBApVquaG6mXH31bQ6P83kMN4Hound {"jorian", "0343eec31037d7b909efd968a5b5e7af60321bf7e464da28f815f0fb23ee7aadd7" }, // RJorianBXNwfNDYPxtNYJJ6vX7Z3VdTR25 {"TonyL", "021a559101e355c907d9c553671044d619769a6e71d624f68bfec7d0afa6bd6a96" }, // RHq3JsvLxU45Z8ufYS6RsDpSG4wi6ucDev From b54e05cf17cbd877f095a7df70616100073749f0 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Fri, 24 May 2019 21:45:39 +0800 Subject: [PATCH 409/447] change blackjoker --- src/notaries_staked.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/notaries_staked.h b/src/notaries_staked.h index fc6b24d58..76e0d192f 100644 --- a/src/notaries_staked.h +++ b/src/notaries_staked.h @@ -30,14 +30,14 @@ static const int32_t num_notaries_STAKED[NUM_STAKED_ERAS] = { 22, 1, 1, 1 }; static const char *notaries_STAKED[NUM_STAKED_ERAS][64][2] = { { - {"blackjok3r", "021914947402d936a89fbdd1b12be49eb894a1568e5e17bb18c8a6cffbd3dc106e" }, // RTVti13NP4eeeZaCCmQxc2bnPdHxCJFP9x + {"blackjok3r", "035fc678bf796ad52f69e1f5759be54ec671c559a22adf27eed067e0ddf1531574" }, // RTcYRJ6WopYkUqcmksyjxoV1CueYyqxFuk {"alright", "0285657c689b903218c97f5f10fe1d10ace2ed6595112d9017f54fb42ea1c1dda8" }, //RXmXeQ8LfJK6Y1aTM97cRz9Gu5f6fmR3sg {"webworker01", "031d1fb39ae4dca28965c3abdbd21faa0f685f6d7b87a60561afa7c448343fef6d" }, //RGsQiArk5sTmjXZV9UzGMW5njyvtSnsTN8 {"CrisF", "03745656c8991c4597828aad2820760c43c00ff2e3b381fef3b5c040f32a7b3a34" }, // RKtAD2kyRRMx4EiG1eeTNprF5h2nmGbzzu {"smk762", "02381616fbc02d3f0398c912fe7b7daf2f3f29e55dc35287f686b15686d8135a9f" }, // RSchwBApVquaG6mXH31bQ6P83kMN4Hound - {"jorian", "0343eec31037d7b909efd968a5b5e7af60321bf7e464da28f815f0fb23ee7aadd7" }, // RJorianBXNwfNDYPxtNYJJ6vX7Z3VdTR25 + {"jorian", "0343eec31037d7b909efd968a5b5e7af60321bf7e464da28f815f0fb23ee7aadd7" }, // RJorianBXNwfNDYPxtNYJJ6vX7Z3VdTR25 right {"TonyL", "021a559101e355c907d9c553671044d619769a6e71d624f68bfec7d0afa6bd6a96" }, // RHq3JsvLxU45Z8ufYS6RsDpSG4wi6ucDev - {"CHMEX", "03ed125d1beb118d12ff0a052bdb0cee32591386d718309b2924f2c36b4e7388e6" }, // RF4HiVeuYpaznRPs7fkRAKKYqT5tuxQQTL + {"CHMEX", "03ed125d1beb118d12ff0a052bdb0cee32591386d718309b2924f2c36b4e7388e6" }, // RF4HiVeuYpaznRPs7fkRAKKYqT5tuxQQTL right {"metaphilibert", "0344182c376f054e3755d712361672138660bda8005abb64067eb5aa98bdb40d10" }, // RG28QSnYFADBg1dAVkH1uPGYS6F8ioEUM2 {"gt", "02312dcecb6e4a32927a075972d3c009f3c68635d8100562cc1813ea66751b9fde" }, // RCg4tzKWQ7i3wrZEU8bvCbCQ4xRJnHnyoo {"CMaurice", "026c6d094523e810641b89f2d7f0ddd8f0b59d97c32e1fa97f0e3e0ac119c26ae4" }, // RSjayeSuYUE1E22rBjnqoexobaRjbAZ2Yb From 80de737568f7b7c78826338a0df938ff3db3edd8 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Fri, 24 May 2019 22:19:04 +0800 Subject: [PATCH 410/447] fix --- src/cc/makecclib | 2 +- src/notaries_staked.h | 20 ++++++++++---------- src/wallet/db.h | 4 ++-- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/cc/makecclib b/src/cc/makecclib index 5241ea675..e9a015e2f 100755 --- a/src/cc/makecclib +++ b/src/cc/makecclib @@ -7,7 +7,7 @@ make -f Makefile_rogue rm ../libcc.so cp librogue.so ../libcc.so -#exit 0 +exit 0 echo sudoku/musig/dilithium gcc -O3 -std=c++11 -I../secp256k1/include -I../univalue/include -I../cryptoconditions/include -I../cryptoconditions/src -I../cryptoconditions/src/asn -I.. -I. -fPIC -shared -c -o sudokucc.so cclib.cpp diff --git a/src/notaries_staked.h b/src/notaries_staked.h index 76e0d192f..503a895ae 100644 --- a/src/notaries_staked.h +++ b/src/notaries_staked.h @@ -16,8 +16,8 @@ static const char *iguanaSeeds[8][1] = {"45.76.120.247"}, {"185.62.57.32"}, {"149.28.253.160"}, - {"103.6.12.112"}, - {"103.6.12.112"}, + {"68.183.226.124"}, + {"149.28.246.230"}, }; static const int STAKED_ERA_GAP = 777; @@ -30,27 +30,27 @@ static const int32_t num_notaries_STAKED[NUM_STAKED_ERAS] = { 22, 1, 1, 1 }; static const char *notaries_STAKED[NUM_STAKED_ERAS][64][2] = { { - {"blackjok3r", "035fc678bf796ad52f69e1f5759be54ec671c559a22adf27eed067e0ddf1531574" }, // RTcYRJ6WopYkUqcmksyjxoV1CueYyqxFuk + {"blackjok3r", "035fc678bf796ad52f69e1f5759be54ec671c559a22adf27eed067e0ddf1531574" }, // RTcYRJ6WopYkUqcmksyjxoV1CueYyqxFuk right {"alright", "0285657c689b903218c97f5f10fe1d10ace2ed6595112d9017f54fb42ea1c1dda8" }, //RXmXeQ8LfJK6Y1aTM97cRz9Gu5f6fmR3sg {"webworker01", "031d1fb39ae4dca28965c3abdbd21faa0f685f6d7b87a60561afa7c448343fef6d" }, //RGsQiArk5sTmjXZV9UzGMW5njyvtSnsTN8 - {"CrisF", "03745656c8991c4597828aad2820760c43c00ff2e3b381fef3b5c040f32a7b3a34" }, // RKtAD2kyRRMx4EiG1eeTNprF5h2nmGbzzu - {"smk762", "02381616fbc02d3f0398c912fe7b7daf2f3f29e55dc35287f686b15686d8135a9f" }, // RSchwBApVquaG6mXH31bQ6P83kMN4Hound - {"jorian", "0343eec31037d7b909efd968a5b5e7af60321bf7e464da28f815f0fb23ee7aadd7" }, // RJorianBXNwfNDYPxtNYJJ6vX7Z3VdTR25 right + {"CrisF", "03745656c8991c4597828aad2820760c43c00ff2e3b381fef3b5c040f32a7b3a34" }, // RNhYJAaPHJCVXGWNVEJeP3TfepEPdhjrRr right + {"smk762", "02381616fbc02d3f0398c912fe7b7daf2f3f29e55dc35287f686b15686d8135a9f" }, // RSchwBApVquaG6mXH31bQ6P83kMN4Hound right + {"jorian", "0343eec31037d7b909efd968a5b5e7af60321bf7e464da28f815f0fb23ee7aadd7" }, // RJorianBXNwfNDYPxtNYJJ6vX7Z3VdTR25 right {"TonyL", "021a559101e355c907d9c553671044d619769a6e71d624f68bfec7d0afa6bd6a96" }, // RHq3JsvLxU45Z8ufYS6RsDpSG4wi6ucDev - {"CHMEX", "03ed125d1beb118d12ff0a052bdb0cee32591386d718309b2924f2c36b4e7388e6" }, // RF4HiVeuYpaznRPs7fkRAKKYqT5tuxQQTL right + {"CHMEX", "03ed125d1beb118d12ff0a052bdb0cee32591386d718309b2924f2c36b4e7388e6" }, // RF4HiVeuYpaznRPs7fkRAKKYqT5tuxQQTL right {"metaphilibert", "0344182c376f054e3755d712361672138660bda8005abb64067eb5aa98bdb40d10" }, // RG28QSnYFADBg1dAVkH1uPGYS6F8ioEUM2 {"gt", "02312dcecb6e4a32927a075972d3c009f3c68635d8100562cc1813ea66751b9fde" }, // RCg4tzKWQ7i3wrZEU8bvCbCQ4xRJnHnyoo {"CMaurice", "026c6d094523e810641b89f2d7f0ddd8f0b59d97c32e1fa97f0e3e0ac119c26ae4" }, // RSjayeSuYUE1E22rBjnqoexobaRjbAZ2Yb {"Bar_F1sh_Rel", "0395f2d9dd9ccb78caf74bff49b6d959afb95af746462e1b35f4a167d8e82b3666" }, // RBbLxJagCA9QHDazQvfnDZe874V1K4Gu8t {"zatJUM", "030fff499b6dc0215344b28a0b6b4becdfb00cd34cd1b36b983ec14f47965fd4bc" }, // RSoEDLBasth7anxS8gbkg6KgeGiz8rhqv1 {"dwy", "03669457b2934d98b5761121dd01b243aed336479625b293be9f8c43a6ae7aaeff" }, // RKhZMqRF361FSGFAzstP5AhozekPjoVh5q - {"gcharang", "021569dd350d99e685a739c5b36bd01f217efb4f448a6f9a56da80c5edf6ce20ee" }, // RE8SsNwhYoygXJSvw9DuQbJicDc28dwR78 - {"computergenie", "027313dabde94fb72f823231d0a1c59fc7baa2e5b3bb2af97ca7d70aae116026b9" }, // RLabsCGxTRqJcJvz6foKuXAB61puJ2x8yt + {"gcharang", "021569dd350d99e685a739c5b36bd01f217efb4f448a6f9a56da80c5edf6ce20ee" }, // RE8SsNwhYoygXJSvw9DuQbJicDc28dwR78 right + {"computergenie", "027313dabde94fb72f823231d0a1c59fc7baa2e5b3bb2af97ca7d70aae116026b9" }, // RLabsCGxTRqJcJvz6foKuXAB61puJ2x8yt right {"daemonfox", "0383484bdc745b2b953c85b5a0c496a1f27bc42ae971f15779ed1532421b3dd943" }, // {"SHossain", "02791f5c215b8a19c143a98e3371ff03b5613df9ac430c4a331ca55fed5761c800" }, // RKdLoHkyeorXmMtj91B1AAnAGiwsdt9MdF {"Nabob", "03ee91c20b6d26e3604022f42df6bb8de6f669da4591f93b568778cba13d9e9ddf" }, // RRwCLPZDzpHEFJnLev4phy51e2stHRUAaU {"mylo", "03f6b7fcaf0b8b8ec432d0de839a76598b78418dadd50c8e5594c0e557d914ec09" }, // RXN4hoZkhUkkrnef9nTUDw3E3vVALAD8Kx - {"PHBA2061", "039fc98c764bc85aed97d690d7942a4fd1190b2fa4f5f4c5c8e0957fac5c6ede00" }, // RPHba2o61hcpX4ds91oj3sKJ8aDXv6QdQf + {"PHBA2061", "039fc98c764bc85aed97d690d7942a4fd1190b2fa4f5f4c5c8e0957fac5c6ede00" }, // RPHba2o61hcpX4ds91oj3sKJ8aDXv6QdQf right {"Exile13", "0247b2120a39faf83678b5de6883e039180ff42925bcb298d32f3792cd59001aae" }, // RTDJ3CDZ6ANbeDKab8nqTVrGw7ViAKLeDV }, { diff --git a/src/wallet/db.h b/src/wallet/db.h index e1ae52909..f23122830 100644 --- a/src/wallet/db.h +++ b/src/wallet/db.h @@ -34,8 +34,8 @@ #include // If CCLIB fails to compile with this, use the one below. -#include -//#include "../depends/x86_64-unknown-linux-gnu/include/db_cxx.h" +//#include +#include "../depends/x86_64-unknown-linux-gnu/include/db_cxx.h" extern unsigned int nWalletDBUpdated; From 13c186acdb3d2048f04aba7929ba51fba0ea6c43 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Fri, 24 May 2019 22:40:25 +0800 Subject: [PATCH 411/447] update --- src/notaries_staked.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/notaries_staked.h b/src/notaries_staked.h index 503a895ae..76adc5e91 100644 --- a/src/notaries_staked.h +++ b/src/notaries_staked.h @@ -10,7 +10,7 @@ static const int8_t BTCminsigs = 13; static const int8_t overrideMinSigs = 6; static const char *iguanaSeeds[8][1] = { - {"80.240.17.222"}, + {"94.23.1.95"}, {"103.6.12.112"}, {"18.224.176.46"}, {"45.76.120.247"}, @@ -32,17 +32,17 @@ static const char *notaries_STAKED[NUM_STAKED_ERAS][64][2] = { {"blackjok3r", "035fc678bf796ad52f69e1f5759be54ec671c559a22adf27eed067e0ddf1531574" }, // RTcYRJ6WopYkUqcmksyjxoV1CueYyqxFuk right {"alright", "0285657c689b903218c97f5f10fe1d10ace2ed6595112d9017f54fb42ea1c1dda8" }, //RXmXeQ8LfJK6Y1aTM97cRz9Gu5f6fmR3sg - {"webworker01", "031d1fb39ae4dca28965c3abdbd21faa0f685f6d7b87a60561afa7c448343fef6d" }, //RGsQiArk5sTmjXZV9UzGMW5njyvtSnsTN8 + {"webworker01", "031d1fb39ae4dca28965c3abdbd21faa0f685f6d7b87a60561afa7c448343fef6d" }, //RGsQiArk5sTmjXZV9UzGMW5njyvtSnsTN8 right {"CrisF", "03745656c8991c4597828aad2820760c43c00ff2e3b381fef3b5c040f32a7b3a34" }, // RNhYJAaPHJCVXGWNVEJeP3TfepEPdhjrRr right {"smk762", "02381616fbc02d3f0398c912fe7b7daf2f3f29e55dc35287f686b15686d8135a9f" }, // RSchwBApVquaG6mXH31bQ6P83kMN4Hound right {"jorian", "0343eec31037d7b909efd968a5b5e7af60321bf7e464da28f815f0fb23ee7aadd7" }, // RJorianBXNwfNDYPxtNYJJ6vX7Z3VdTR25 right {"TonyL", "021a559101e355c907d9c553671044d619769a6e71d624f68bfec7d0afa6bd6a96" }, // RHq3JsvLxU45Z8ufYS6RsDpSG4wi6ucDev {"CHMEX", "03ed125d1beb118d12ff0a052bdb0cee32591386d718309b2924f2c36b4e7388e6" }, // RF4HiVeuYpaznRPs7fkRAKKYqT5tuxQQTL right - {"metaphilibert", "0344182c376f054e3755d712361672138660bda8005abb64067eb5aa98bdb40d10" }, // RG28QSnYFADBg1dAVkH1uPGYS6F8ioEUM2 - {"gt", "02312dcecb6e4a32927a075972d3c009f3c68635d8100562cc1813ea66751b9fde" }, // RCg4tzKWQ7i3wrZEU8bvCbCQ4xRJnHnyoo + {"metaphilibert", "0344182c376f054e3755d712361672138660bda8005abb64067eb5aa98bdb40d10" }, // RG28QSnYFADBg1dAVkH1uPGYS6F8ioEUM2 right + {"gt", "02312dcecb6e4a32927a075972d3c009f3c68635d8100562cc1813ea66751b9fde" }, // RCg4tzKWQ7i3wrZEU8bvCbCQ4xRJnHnyoo right {"CMaurice", "026c6d094523e810641b89f2d7f0ddd8f0b59d97c32e1fa97f0e3e0ac119c26ae4" }, // RSjayeSuYUE1E22rBjnqoexobaRjbAZ2Yb {"Bar_F1sh_Rel", "0395f2d9dd9ccb78caf74bff49b6d959afb95af746462e1b35f4a167d8e82b3666" }, // RBbLxJagCA9QHDazQvfnDZe874V1K4Gu8t - {"zatJUM", "030fff499b6dc0215344b28a0b6b4becdfb00cd34cd1b36b983ec14f47965fd4bc" }, // RSoEDLBasth7anxS8gbkg6KgeGiz8rhqv1 + {"zatJUM", "030fff499b6dc0215344b28a0b6b4becdfb00cd34cd1b36b983ec14f47965fd4bc" }, // RSoEDLBasth7anxS8gbkg6KgeGiz8rhqv1 right {"dwy", "03669457b2934d98b5761121dd01b243aed336479625b293be9f8c43a6ae7aaeff" }, // RKhZMqRF361FSGFAzstP5AhozekPjoVh5q {"gcharang", "021569dd350d99e685a739c5b36bd01f217efb4f448a6f9a56da80c5edf6ce20ee" }, // RE8SsNwhYoygXJSvw9DuQbJicDc28dwR78 right {"computergenie", "027313dabde94fb72f823231d0a1c59fc7baa2e5b3bb2af97ca7d70aae116026b9" }, // RLabsCGxTRqJcJvz6foKuXAB61puJ2x8yt right From b818907066743849f878dcc95a448cd2c18ab1a0 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Fri, 24 May 2019 22:56:51 +0800 Subject: [PATCH 412/447] update --- src/notaries_staked.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/notaries_staked.h b/src/notaries_staked.h index 76adc5e91..13ac997fc 100644 --- a/src/notaries_staked.h +++ b/src/notaries_staked.h @@ -40,7 +40,7 @@ static const char *notaries_STAKED[NUM_STAKED_ERAS][64][2] = {"CHMEX", "03ed125d1beb118d12ff0a052bdb0cee32591386d718309b2924f2c36b4e7388e6" }, // RF4HiVeuYpaznRPs7fkRAKKYqT5tuxQQTL right {"metaphilibert", "0344182c376f054e3755d712361672138660bda8005abb64067eb5aa98bdb40d10" }, // RG28QSnYFADBg1dAVkH1uPGYS6F8ioEUM2 right {"gt", "02312dcecb6e4a32927a075972d3c009f3c68635d8100562cc1813ea66751b9fde" }, // RCg4tzKWQ7i3wrZEU8bvCbCQ4xRJnHnyoo right - {"CMaurice", "026c6d094523e810641b89f2d7f0ddd8f0b59d97c32e1fa97f0e3e0ac119c26ae4" }, // RSjayeSuYUE1E22rBjnqoexobaRjbAZ2Yb + {"CMaurice", "026c6d094523e810641b89f2d7f0ddd8f0b59d97c32e1fa97f0e3e0ac119c26ae4" }, // RSjayeSuYUE1E22rBjnqoexobaRjbAZ2Yb right {"Bar_F1sh_Rel", "0395f2d9dd9ccb78caf74bff49b6d959afb95af746462e1b35f4a167d8e82b3666" }, // RBbLxJagCA9QHDazQvfnDZe874V1K4Gu8t {"zatJUM", "030fff499b6dc0215344b28a0b6b4becdfb00cd34cd1b36b983ec14f47965fd4bc" }, // RSoEDLBasth7anxS8gbkg6KgeGiz8rhqv1 right {"dwy", "03669457b2934d98b5761121dd01b243aed336479625b293be9f8c43a6ae7aaeff" }, // RKhZMqRF361FSGFAzstP5AhozekPjoVh5q @@ -51,7 +51,7 @@ static const char *notaries_STAKED[NUM_STAKED_ERAS][64][2] = {"Nabob", "03ee91c20b6d26e3604022f42df6bb8de6f669da4591f93b568778cba13d9e9ddf" }, // RRwCLPZDzpHEFJnLev4phy51e2stHRUAaU {"mylo", "03f6b7fcaf0b8b8ec432d0de839a76598b78418dadd50c8e5594c0e557d914ec09" }, // RXN4hoZkhUkkrnef9nTUDw3E3vVALAD8Kx {"PHBA2061", "039fc98c764bc85aed97d690d7942a4fd1190b2fa4f5f4c5c8e0957fac5c6ede00" }, // RPHba2o61hcpX4ds91oj3sKJ8aDXv6QdQf right - {"Exile13", "0247b2120a39faf83678b5de6883e039180ff42925bcb298d32f3792cd59001aae" }, // RTDJ3CDZ6ANbeDKab8nqTVrGw7ViAKLeDV + {"Exile13", "0247b2120a39faf83678b5de6883e039180ff42925bcb298d32f3792cd59001aae" }, // RTDJ3CDZ6ANbeDKab8nqTVrGw7ViAKLeDV right }, { {"blackjok3r", "021914947402d936a89fbdd1b12be49eb894a1568e5e17bb18c8a6cffbd3dc106e" }, // RTVti13NP4eeeZaCCmQxc2bnPdHxCJFP9x From d6b611210420195d7267c51a62e70259a9694123 Mon Sep 17 00:00:00 2001 From: Alrighttt <36680730+Alrighttt@users.noreply.github.com> Date: Fri, 24 May 2019 17:09:06 +0200 Subject: [PATCH 413/447] change Alright key --- src/notaries_staked.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/notaries_staked.h b/src/notaries_staked.h index 13ac997fc..f6e2cc384 100644 --- a/src/notaries_staked.h +++ b/src/notaries_staked.h @@ -31,7 +31,7 @@ static const char *notaries_STAKED[NUM_STAKED_ERAS][64][2] = { { {"blackjok3r", "035fc678bf796ad52f69e1f5759be54ec671c559a22adf27eed067e0ddf1531574" }, // RTcYRJ6WopYkUqcmksyjxoV1CueYyqxFuk right - {"alright", "0285657c689b903218c97f5f10fe1d10ace2ed6595112d9017f54fb42ea1c1dda8" }, //RXmXeQ8LfJK6Y1aTM97cRz9Gu5f6fmR3sg + {"Alright", "02b718c60a035f77b7103a507d36aed942b4f655b8d13bce6f28b8eac523944278" }, //RG77F4mQpP1K1q2CDSc2vZSJvKUZgF8R26 {"webworker01", "031d1fb39ae4dca28965c3abdbd21faa0f685f6d7b87a60561afa7c448343fef6d" }, //RGsQiArk5sTmjXZV9UzGMW5njyvtSnsTN8 right {"CrisF", "03745656c8991c4597828aad2820760c43c00ff2e3b381fef3b5c040f32a7b3a34" }, // RNhYJAaPHJCVXGWNVEJeP3TfepEPdhjrRr right {"smk762", "02381616fbc02d3f0398c912fe7b7daf2f3f29e55dc35287f686b15686d8135a9f" }, // RSchwBApVquaG6mXH31bQ6P83kMN4Hound right From 90f310f41ac3acf69f58bb2047e4a055f326e81e Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Sat, 25 May 2019 00:00:58 +0800 Subject: [PATCH 414/447] fix --- src/wallet/rpcwallet.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index d63a387b2..ba2dd8a97 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -8030,7 +8030,7 @@ UniValue opreturn_burn(const UniValue& params, bool fHelp) struct CCcontract_info *cp, C; UniValue ret(UniValue::VOBJ); if (ensure_CCrequirements(EVAL_PAYMENTS) < 0) throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); - cp = CCinit(&C, EVAL_PAYMENTS); + cp = CCinit(&C, EVAL_ORACLES); CAmount nAmount = AmountFromValue(params[0]); if (nAmount <= 10000) From 7bb9ee7ffa65e150b7cef4bfc439904a1824f0b4 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Sat, 25 May 2019 00:02:31 +0800 Subject: [PATCH 415/447] fix --- src/wallet/rpcwallet.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index ba2dd8a97..e9a9e38c6 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -8028,7 +8028,7 @@ UniValue opreturn_burn(const UniValue& params, bool fHelp) if (fHelp || (params.size() != 2)) throw runtime_error("amount to burn, hexstring to send\n"); struct CCcontract_info *cp, C; UniValue ret(UniValue::VOBJ); - if (ensure_CCrequirements(EVAL_PAYMENTS) < 0) + if (ensure_CCrequirements(EVAL_ORACLES) < 0) throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); cp = CCinit(&C, EVAL_ORACLES); From 25eec688e83f7f04a20523af4e4a6d7a18ea903b Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Sat, 25 May 2019 00:42:57 +0800 Subject: [PATCH 416/447] min sig =7, and change iguana port --- src/notaries_staked.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/notaries_staked.h b/src/notaries_staked.h index f6e2cc384..f48c1a671 100644 --- a/src/notaries_staked.h +++ b/src/notaries_staked.h @@ -5,9 +5,9 @@ #include "crosschain.h" #include "cc/CCinclude.h" -static const int32_t iguanaPort = 9997; +static const int32_t iguanaPort = 9333; static const int8_t BTCminsigs = 13; -static const int8_t overrideMinSigs = 6; +static const int8_t overrideMinSigs = 7; static const char *iguanaSeeds[8][1] = { {"94.23.1.95"}, From a2a0cd2425048f38beb16e0d0911f64306c34ab8 Mon Sep 17 00:00:00 2001 From: DeckerSU Date: Sat, 25 May 2019 00:04:44 +0300 Subject: [PATCH 417/447] komodo-cli, wallet-utility and komodo-tx also need static build on OSX --- src/Makefile.am | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/Makefile.am b/src/Makefile.am index a1b403b07..764a1b579 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -584,6 +584,10 @@ komodo_cli_SOURCES = bitcoin-cli.cpp komodo_cli_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES) $(EVENT_CFLAGS) komodo_cli_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS) komodo_cli_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS) $(LIBTOOL_APP_LDFLAGS) +if TARGET_DARWIN +komodo_cli_LDFLAGS += -static-libgcc +endif + # wallet-utility binary # if ENABLE_WALLET @@ -591,6 +595,9 @@ wallet_utility_SOURCES = wallet-utility.cpp wallet_utility_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES) wallet_utility_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS) wallet_utility_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS) $(LIBTOOL_APP_LDFLAGS) +if TARGET_DARWIN +wallet_utility_LDFLAGS += -static-libgcc +endif endif if TARGET_WINDOWS @@ -634,6 +641,9 @@ komodo_tx_SOURCES = komodo-tx.cpp komodo_tx_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES) komodo_tx_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS) komodo_tx_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS) $(LIBTOOL_APP_LDFLAGS) +if TARGET_DARWIN +komodo_tx_LDFLAGS += -static-libgcc +endif if TARGET_WINDOWS komodo_tx_SOURCES += bitcoin-tx-res.rc From 35bff713b0a4a075ec2a033d02418acf7fe64fd9 Mon Sep 17 00:00:00 2001 From: DeckerSU Date: Sat, 25 May 2019 00:05:00 +0300 Subject: [PATCH 418/447] Update README.md to use gcc@8 on OSX --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 9a8582891..8cbbef297 100644 --- a/README.md +++ b/README.md @@ -74,7 +74,7 @@ cd komodo #### OSX Ensure you have [brew](https://brew.sh) and the command line tools installed (comes automatically with XCode) and run: ```shell -brew update && brew install gcc@6 +brew update && brew install gcc@8 git clone https://github.com/komodoplatform/komodo --branch master --single-branch cd komodo ./zcutil/fetch-params.sh From 7983e6d23c057791d1d4f0df102418a87304d3b4 Mon Sep 17 00:00:00 2001 From: DeckerSU Date: Sat, 25 May 2019 00:20:23 +0300 Subject: [PATCH 419/447] Revert "komodo-cli, wallet-utility and komodo-tx also need static build on OSX" This reverts commit a2a0cd2425048f38beb16e0d0911f64306c34ab8. --- src/Makefile.am | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/src/Makefile.am b/src/Makefile.am index 764a1b579..a1b403b07 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -584,10 +584,6 @@ komodo_cli_SOURCES = bitcoin-cli.cpp komodo_cli_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES) $(EVENT_CFLAGS) komodo_cli_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS) komodo_cli_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS) $(LIBTOOL_APP_LDFLAGS) -if TARGET_DARWIN -komodo_cli_LDFLAGS += -static-libgcc -endif - # wallet-utility binary # if ENABLE_WALLET @@ -595,9 +591,6 @@ wallet_utility_SOURCES = wallet-utility.cpp wallet_utility_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES) wallet_utility_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS) wallet_utility_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS) $(LIBTOOL_APP_LDFLAGS) -if TARGET_DARWIN -wallet_utility_LDFLAGS += -static-libgcc -endif endif if TARGET_WINDOWS @@ -641,9 +634,6 @@ komodo_tx_SOURCES = komodo-tx.cpp komodo_tx_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES) komodo_tx_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS) komodo_tx_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS) $(LIBTOOL_APP_LDFLAGS) -if TARGET_DARWIN -komodo_tx_LDFLAGS += -static-libgcc -endif if TARGET_WINDOWS komodo_tx_SOURCES += bitcoin-tx-res.rc From f8bd669f2058a0bd35d17fe2eccb2ca5fb963c59 Mon Sep 17 00:00:00 2001 From: DeckerSU Date: Sat, 25 May 2019 00:35:26 +0300 Subject: [PATCH 420/447] osx: komodo-cli binary static libgcc linking --- src/Makefile.am | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Makefile.am b/src/Makefile.am index a1b403b07..034333bbc 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -584,6 +584,9 @@ komodo_cli_SOURCES = bitcoin-cli.cpp komodo_cli_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES) $(EVENT_CFLAGS) komodo_cli_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS) komodo_cli_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS) $(LIBTOOL_APP_LDFLAGS) +if TARGET_DARWIN +komodo_cli_LDFLAGS += -static-libgcc +endif # wallet-utility binary # if ENABLE_WALLET From 12678a579cf59cadfe3926647d5891536389e319 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Sat, 25 May 2019 13:54:22 +0800 Subject: [PATCH 421/447] fix notaryname in getinfo? --- src/notaries_staked.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/notaries_staked.cpp b/src/notaries_staked.cpp index cbbcd57db..d3281127e 100644 --- a/src/notaries_staked.cpp +++ b/src/notaries_staked.cpp @@ -113,7 +113,14 @@ void UpdateNotaryAddrs(uint8_t pubkeys[64][33],int8_t numNotaries) { // staked era is set. pthread_mutex_lock(&staked_mutex); for (int i = 0; i Date: Sun, 26 May 2019 14:35:59 +0800 Subject: [PATCH 422/447] last_notarized_height to getrawtransaction --- src/rpc/rawtransaction.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/rpc/rawtransaction.cpp b/src/rpc/rawtransaction.cpp index 1c3cb96f2..41be747dd 100644 --- a/src/rpc/rawtransaction.cpp +++ b/src/rpc/rawtransaction.cpp @@ -185,10 +185,13 @@ int32_t myIsutxo_spent(uint256 &spenttxid,uint256 txid,int32_t vout) void TxToJSONExpanded(const CTransaction& tx, const uint256 hashBlock, UniValue& entry, int nHeight = 0, int nConfirmations = 0, int nBlockTime = 0) { + uint256 notarized_hash,notarized_desttxid; int32_t prevMoMheight,notarized_height; + notarized_height = komodo_notarized_height(&prevMoMheight,¬arized_hash,¬arized_desttxid); uint256 txid = tx.GetHash(); entry.push_back(Pair("txid", txid.GetHex())); entry.push_back(Pair("overwintered", tx.fOverwintered)); entry.push_back(Pair("version", tx.nVersion)); + entry.push_back(Pair("last_notarized_height", notarized_height)); if (tx.fOverwintered) { entry.push_back(Pair("versiongroupid", HexInt(tx.nVersionGroupId))); } From eaca3f21373497aa8a0c0775145701526edfd838 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Sun, 26 May 2019 14:38:31 +0800 Subject: [PATCH 423/447] fix --- src/rpc/rawtransaction.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/rpc/rawtransaction.cpp b/src/rpc/rawtransaction.cpp index 41be747dd..578c2f9ad 100644 --- a/src/rpc/rawtransaction.cpp +++ b/src/rpc/rawtransaction.cpp @@ -48,6 +48,8 @@ #include +int32_t komodo_notarized_height(int32_t *prevMoMheightp,uint256 *hashp,uint256 *txidp); + using namespace std; extern char ASSETCHAINS_SYMBOL[]; From 1874ca7284e8f932a38dd88eb06647022fab0688 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Sun, 26 May 2019 14:54:59 +0800 Subject: [PATCH 424/447] undo build changes --- src/cc/makecclib | 2 +- src/wallet/db.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cc/makecclib b/src/cc/makecclib index e9a015e2f..5241ea675 100755 --- a/src/cc/makecclib +++ b/src/cc/makecclib @@ -7,7 +7,7 @@ make -f Makefile_rogue rm ../libcc.so cp librogue.so ../libcc.so -exit 0 +#exit 0 echo sudoku/musig/dilithium gcc -O3 -std=c++11 -I../secp256k1/include -I../univalue/include -I../cryptoconditions/include -I../cryptoconditions/src -I../cryptoconditions/src/asn -I.. -I. -fPIC -shared -c -o sudokucc.so cclib.cpp diff --git a/src/wallet/db.h b/src/wallet/db.h index f23122830..e1ae52909 100644 --- a/src/wallet/db.h +++ b/src/wallet/db.h @@ -34,8 +34,8 @@ #include // If CCLIB fails to compile with this, use the one below. -//#include -#include "../depends/x86_64-unknown-linux-gnu/include/db_cxx.h" +#include +//#include "../depends/x86_64-unknown-linux-gnu/include/db_cxx.h" extern unsigned int nWalletDBUpdated; From 90f6d123adca067618208cb942c1175f73f41223 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Sun, 26 May 2019 23:43:27 +0800 Subject: [PATCH 425/447] fix build --- src/cc/makecclib | 2 +- src/wallet/db.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cc/makecclib b/src/cc/makecclib index 5241ea675..e9a015e2f 100755 --- a/src/cc/makecclib +++ b/src/cc/makecclib @@ -7,7 +7,7 @@ make -f Makefile_rogue rm ../libcc.so cp librogue.so ../libcc.so -#exit 0 +exit 0 echo sudoku/musig/dilithium gcc -O3 -std=c++11 -I../secp256k1/include -I../univalue/include -I../cryptoconditions/include -I../cryptoconditions/src -I../cryptoconditions/src/asn -I.. -I. -fPIC -shared -c -o sudokucc.so cclib.cpp diff --git a/src/wallet/db.h b/src/wallet/db.h index e1ae52909..f23122830 100644 --- a/src/wallet/db.h +++ b/src/wallet/db.h @@ -34,8 +34,8 @@ #include // If CCLIB fails to compile with this, use the one below. -#include -//#include "../depends/x86_64-unknown-linux-gnu/include/db_cxx.h" +//#include +#include "../depends/x86_64-unknown-linux-gnu/include/db_cxx.h" extern unsigned int nWalletDBUpdated; From 784679fff6564757b761d9af6aedfd5fc1169f6b Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 27 May 2019 02:51:11 +0800 Subject: [PATCH 426/447] This kind of works, result comes out as negative number though. --- src/rpc/mining.cpp | 35 ++++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/src/rpc/mining.cpp b/src/rpc/mining.cpp index c95d7b891..8e5de0f53 100644 --- a/src/rpc/mining.cpp +++ b/src/rpc/mining.cpp @@ -59,6 +59,20 @@ arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t he * Return average network hashes per second based on the last 'lookup' blocks, * or over the difficulty averaging window if 'lookup' is nonpositive. * If 'height' is nonnegative, compute the estimate at the time when a given block was found. +time =0, lastBlockTime=time_of_last_block, PoWblocks=0 +for x = 1 to 100 +get block info +if PoS then + lastBlockTime = ThisBlockTime + next x +else + PoWblocks += 1 + some var/array about diff + newTime = timeNow - lastBlockTime + totalTime = totalTime + newTime + lastBlockTime = newTime +next x +do math of num PoW blocks over PoW active Time with stored diff info */ int64_t GetNetworkHashPS(int lookup, int height) { CBlockIndex *pb = chainActive.LastTip(); @@ -79,21 +93,36 @@ int64_t GetNetworkHashPS(int lookup, int height) { CBlockIndex *pb0 = pb; int64_t minTime = pb0->GetBlockTime(); + int64_t timeoffset = 0, n=0,i=0; int64_t maxTime = minTime; - for (int i = 0; i < lookup; i++) { + for (i = 0; i < lookup; i++) { pb0 = pb0->pprev; + // if PoW block save block time, and skip the hash. + if ( pb0->segid >= 0 && pb0->segid != -2 ) + { + n++; + // only staking chains should ever set this. + + timeoffset += pb0->GetBlockTime() - pb0->pprev->GetBlockTime(); + //fprintf(stderr, "staking tx.%li segid.%i blocktime.%li\n", n, pb0->segid, (pb0->GetBlockTime() - pb0->pprev->GetBlockTime())); + if ( lookup > pb->GetHeight() ) + break; + lookup++; + continue; + } int64_t time = pb0->GetBlockTime(); minTime = std::min(time, minTime); maxTime = std::max(time, maxTime); } + //fprintf(stderr, "number blocks scanned.%li\n",i ); // In case there's a situation where minTime == maxTime, we don't want a divide by zero exception. if (minTime == maxTime) return 0; arith_uint256 workDiff = pb->chainPower.chainWork - pb0->chainPower.chainWork; - int64_t timeDiff = maxTime - minTime; - + int64_t timeDiff = maxTime - minTime;// - timeoffset; + fprintf(stderr, "timediff.%li timeoffset.%li mintime.%li maxtime.%li\n", timeDiff, timeoffset, minTime, maxTime); return (int64_t)(workDiff.getdouble() / timeDiff); } From 1c6723b9f1428f3e79ed614275a1863d556ee77f Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 27 May 2019 16:22:43 +0800 Subject: [PATCH 427/447] for gcharang --- src/rpc/blockchain.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index 76d35ff61..ddb5dab12 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -51,6 +51,7 @@ using namespace std; extern int32_t KOMODO_INSYNC; extern void TxToJSON(const CTransaction& tx, const uint256 hashBlock, UniValue& entry); void ScriptPubKeyToJSON(const CScript& scriptPubKey, UniValue& out, bool fIncludeHex); +int32_t komodo_notarized_height(int32_t *prevMoMheightp,uint256 *hashp,uint256 *txidp); #include "komodo_defs.h" #include "komodo_structs.h" @@ -133,6 +134,9 @@ UniValue blockheaderToJSON(const CBlockIndex* blockindex) result.push_back(Pair("error", "null blockhash")); return(result); } + uint256 notarized_hash,notarized_desttxid; int32_t prevMoMheight,notarized_height; + notarized_height = komodo_notarized_height(&prevMoMheight,¬arized_hash,¬arized_desttxid); + result.push_back(Pair("last_notarized_height", notarized_height)); result.push_back(Pair("hash", blockindex->GetBlockHash().GetHex())); int confirmations = -1; // Only report confirmations if the block is on the main chain @@ -284,6 +288,9 @@ UniValue blockToDeltasJSON(const CBlock& block, const CBlockIndex* blockindex) UniValue blockToJSON(const CBlock& block, const CBlockIndex* blockindex, bool txDetails = false) { UniValue result(UniValue::VOBJ); + uint256 notarized_hash,notarized_desttxid; int32_t prevMoMheight,notarized_height; + notarized_height = komodo_notarized_height(&prevMoMheight,¬arized_hash,¬arized_desttxid); + result.push_back(Pair("last_notarized_height", notarized_height)); result.push_back(Pair("hash", block.GetHash().GetHex())); int confirmations = -1; // Only report confirmations if the block is on the main chain From f08a7d2d03f47036f25845931faa2a060cd04a32 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 27 May 2019 17:58:23 +0800 Subject: [PATCH 428/447] add ENABLE LABS global var to build cclib correctly with start.sh. --- src/cc/makecclib | 5 ++++- src/wallet/db.h | 8 +++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/cc/makecclib b/src/cc/makecclib index e9a015e2f..0d82463c4 100755 --- a/src/cc/makecclib +++ b/src/cc/makecclib @@ -7,7 +7,10 @@ make -f Makefile_rogue rm ../libcc.so cp librogue.so ../libcc.so -exit 0 +if [ "${LABS_FLAGS}" = "ENABLE_LABS" ] +then + exit +fi echo sudoku/musig/dilithium gcc -O3 -std=c++11 -I../secp256k1/include -I../univalue/include -I../cryptoconditions/include -I../cryptoconditions/src -I../cryptoconditions/src/asn -I.. -I. -fPIC -shared -c -o sudokucc.so cclib.cpp diff --git a/src/wallet/db.h b/src/wallet/db.h index f23122830..3aaf3d34b 100644 --- a/src/wallet/db.h +++ b/src/wallet/db.h @@ -33,9 +33,11 @@ #include -// If CCLIB fails to compile with this, use the one below. -//#include -#include "../depends/x86_64-unknown-linux-gnu/include/db_cxx.h" +#ifdef BUILD_ROGUE + #include "../depends/x86_64-unknown-linux-gnu/include/db_cxx.h" +#else + #include +#endif extern unsigned int nWalletDBUpdated; From 0f24aec58740a6afeedd186705e9dc8e1c39e880 Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Mon, 27 May 2019 21:31:15 -0700 Subject: [PATCH 429/447] Give correct CLI asset name and RPC ports in rpc examples --- src/rpc/server.cpp | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/rpc/server.cpp b/src/rpc/server.cpp index 500d175e0..e36e8b4c9 100644 --- a/src/rpc/server.cpp +++ b/src/rpc/server.cpp @@ -1,5 +1,6 @@ // Copyright (c) 2010 Satoshi Nakamoto // Copyright (c) 2009-2014 The Bitcoin Core developers +// Copyright (c) 2019 The Hush developers // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. @@ -45,6 +46,7 @@ using namespace RPCServer; using namespace std; +extern uint16_t ASSETCHAINS_P2PPORT,ASSETCHAINS_RPCPORT; static bool fRPCRunning = false; static bool fRPCInWarmup = true; @@ -853,21 +855,30 @@ UniValue CRPCTable::execute(const std::string &strMethod, const UniValue ¶ms std::string HelpExampleCli(const std::string& methodname, const std::string& args) { - return "> komodo-cli " + methodname + " " + args + "\n"; + if ( ASSETCHAINS_SYMBOL[0] == 0 ) { + return "> komodo-cli " + methodname + " " + args + "\n"; + } else if ((strncmp(ASSETCHAINS_SYMBOL, "HUSH3", 5) == 0) ) { + return "> hush-cli " + methodname + " " + args + "\n"; + } else { + return "> komodo-cli -ac_name=" + strprintf("%s", ASSETCHAINS_SYMBOL) + " " + methodname + " " + args + "\n"; + } } std::string HelpExampleRpc(const std::string& methodname, const std::string& args) { - return "> curl --user myusername --data-binary '{\"jsonrpc\": \"1.0\", \"id\":\"curltest\", " - "\"method\": \"" + methodname + "\", \"params\": [" + args + "] }' -H 'content-type: text/plain;' http://127.0.0.1:7771/\n"; + return "> curl --user myusername --data-binary '{\"jsonrpc\": \"1.0\", \"id\":\"curltest\", " + "\"method\": \"" + methodname + "\", \"params\": [" + args + "] }' -H 'content-type: text/plain;' http://127.0.0.1:" + to_string(ASSETCHAINS_RPCPORT) + "/\n"; } string experimentalDisabledHelpMsg(const string& rpc, const string& enableArg) { + string daemon = ASSETCHAINS_SYMBOL[0] == 0 ? "komodod" : "hushd"; + string ticker = ASSETCHAINS_SYMBOL[0] == 0 ? "komodo" : ASSETCHAINS_SYMBOL; + return "\nWARNING: " + rpc + " is disabled.\n" - "To enable it, restart zcashd with the -experimentalfeatures and\n" + "To enable it, restart " + daemon + " with the -experimentalfeatures and\n" "-" + enableArg + " commandline options, or add these two lines\n" - "to the zcash.conf file:\n\n" + "to the " + ticker + ".conf file:\n\n" "experimentalfeatures=1\n" + enableArg + "=1\n"; } From 01f597a2c83264fc7dddf9496bec972d9ba8ed68 Mon Sep 17 00:00:00 2001 From: Mihailo Milenkovic Date: Tue, 28 May 2019 15:40:43 +0200 Subject: [PATCH 430/447] Oracles pubkey spoofing in register tx fix - Fix activation on July 15th 2019 00:00 - Added oraclesfund tx to fund Oracles CC address of pubkey that will register, and spend it in register tx - oraclessamples gets baton address as input instead of txid to show all data from publisher --- src/cc/CCOracles.h | 4 +- src/cc/oracles.cpp | 246 ++++++++++++++++++++++++++++++++------- src/rpc/server.cpp | 1 + src/rpc/server.h | 1 + src/wallet/rpcwallet.cpp | 28 ++++- 5 files changed, 233 insertions(+), 47 deletions(-) diff --git a/src/cc/CCOracles.h b/src/cc/CCOracles.h index 7f952e5f5..9f6a35966 100644 --- a/src/cc/CCOracles.h +++ b/src/cc/CCOracles.h @@ -21,12 +21,12 @@ bool OraclesValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); std::string OracleCreate(int64_t txfee,std::string name,std::string description,std::string format); +std::string OracleFund(int64_t txfee,uint256 oracletxid); std::string OracleRegister(int64_t txfee,uint256 oracletxid,int64_t datafee); std::string OracleSubscribe(int64_t txfee,uint256 oracletxid,CPubKey publisher,int64_t amount); std::string OracleData(int64_t txfee,uint256 oracletxid,std::vector data); - // CCcustom -UniValue OracleDataSamples(uint256 reforacletxid,uint256 batontxid,int32_t num); +UniValue OracleDataSamples(uint256 reforacletxid,char* batonaddr,int32_t num); UniValue OracleInfo(uint256 origtxid); UniValue OraclesList(); diff --git a/src/cc/oracles.cpp b/src/cc/oracles.cpp index 7cd429182..f019ae271 100644 --- a/src/cc/oracles.cpp +++ b/src/cc/oracles.cpp @@ -92,10 +92,11 @@ vout.n-1: opreturn with oracletxid, prevbatontxid and data in proper format */ +extern int32_t komodo_currentheight(); +#define PUBKEY_SPOOFING_FIX_ACTIVATION 1563148800 +#define CC_MARKER_VALUE 10000 // start of consensus code - - CScript EncodeOraclesCreateOpRet(uint8_t funcid,std::string name,std::string description,std::string format) { CScript opret; uint8_t evalcode = EVAL_ORACLES; @@ -124,6 +125,7 @@ uint8_t DecodeOraclesCreateOpRet(const CScript &scriptPubKey,std::string &name,s CScript EncodeOraclesOpRet(uint8_t funcid,uint256 oracletxid,CPubKey pk,int64_t num) { CScript opret; uint8_t evalcode = EVAL_ORACLES; + opret << OP_RETURN << E_MARSHAL(ss << evalcode << funcid << oracletxid << pk << num); return(opret); } @@ -131,11 +133,12 @@ CScript EncodeOraclesOpRet(uint8_t funcid,uint256 oracletxid,CPubKey pk,int64_t uint8_t DecodeOraclesOpRet(const CScript &scriptPubKey,uint256 &oracletxid,CPubKey &pk,int64_t &num) { std::vector vopret; uint8_t *script,e,f; + GetOpReturnData(scriptPubKey,vopret); script = (uint8_t *)vopret.data(); if ( vopret.size() > 2 && script[0] == EVAL_ORACLES ) { - if (script[0] == EVAL_ORACLES && (script[1]== 'R' || script[1] == 'S') && E_UNMARSHAL(vopret,ss >> e; ss >> f; ss >> oracletxid; ss >> pk; ss >> num)!=0) + if (script[0] == EVAL_ORACLES && (script[1]== 'R' || script[1] == 'S' || script[1] == 'F') && E_UNMARSHAL(vopret,ss >> e; ss >> f; ss >> oracletxid; ss >> pk; ss >> num)!=0) return(f); else return(script[1]); } @@ -633,9 +636,25 @@ bool OraclesDataValidate(struct CCcontract_info *cp,Eval* eval,const CTransactio else return(true); } +int32_t GetLatestTimestamp(int32_t height) +{ + uint256 blockHash; CBlock block; CBlockIndex* pindex; + + blockHash = chainActive[height]->GetBlockHash(); + pindex = mapBlockIndex[blockHash]; + if ( komodo_blockload(block,pindex) == 0 ) + { + return(block.nTime); + } + return(0); +} + bool OraclesValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn) { - uint256 txid,oracletxid,batontxid; uint64_t txfee=10000; int32_t numvins,numvouts,preventCCvins,preventCCvouts; uint8_t *script; std::vector vopret,data; CScript scriptPubKey; CPubKey publisher; + uint256 oracletxid,batontxid; uint64_t txfee=10000; int32_t numvins,numvouts,preventCCvins,preventCCvouts; int64_t amount; uint256 hashblock; + uint8_t *script; std::vector vopret,data; CPubKey publisher,tmppk,oraclespk; char tmpaddress[64],vinaddress[64],oraclesaddr[64]; + CTransaction tmptx; std::string name,desc,format; + numvins = tx.vin.size(); numvouts = tx.vout.size(); preventCCvins = preventCCvouts = -1; @@ -643,10 +662,11 @@ bool OraclesValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &t return eval->Invalid("no vouts"); else { - txid = tx.GetHash(); GetOpReturnData(tx.vout[numvouts-1].scriptPubKey,vopret); if ( vopret.size() > 2 ) - { + { + oraclespk=GetUnspendable(cp,0); + Getscriptaddress(oraclesaddr,CScript() << ParseHex(HexStr(oraclespk)) << OP_CHECKSIG); script = (uint8_t *)vopret.data(); switch ( script[1] ) { @@ -657,13 +677,45 @@ bool OraclesValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &t // vout.n-1: opreturn with name and description and format for data return eval->Invalid("unexpected OraclesValidate for create"); break; - case 'R': // register + case 'F': // fund (activation on Jul 15th 2019 00:00) // vins.*: normal inputs + // vout.0: txfee to oracle CC address of users pubkey + // vout.1: change, if any + // vout.n-1: opreturn with createtxid, pubkey and amount + return eval->Invalid("unexpected OraclesValidate for create"); + break; + case 'R': // register + // vin.0: normal inputs + // vin.n-1: CC input from pubkeys oracle CC addres - to prove that register came from pubkey that is registred (activation on Jul 15th 2019 00:00) // vout.0: txfee tag to normal marker address // vout.1: baton CC utxo - // vout.2: change, if any + // vout.2: marker from oraclesfund tx to normal pubkey address (activation on Jul 15th 2019 00:00) + // vout.n-2: change, if any // vout.n-1: opreturn with createtxid, pubkey and price per data point - return eval->Invalid("unexpected OraclesValidate for register"); + if (GetLatestTimestamp(eval->GetCurrentHeight())>PUBKEY_SPOOFING_FIX_ACTIVATION) + { + if ((numvouts=tx.vout.size()) < 1 || DecodeOraclesOpRet(tx.vout[numvouts-1].scriptPubKey,oracletxid,tmppk,amount)!='R') + return eval->Invalid("invalid oraclesregister OP_RETURN data!"); + else if (myGetTransaction(oracletxid,tmptx,hashblock) == 0) + return eval->Invalid("invalid oraclescreate txid!"); + else if ((numvouts=tmptx.vout.size()) < 1 || DecodeOraclesCreateOpRet(tmptx.vout[numvouts-1].scriptPubKey,name,desc,format)!='C') + return eval->Invalid("invalid oraclescreate OP_RETURN data!"); + else if ( IsCCInput(tmptx.vin[0].scriptSig) != 0 ) + return eval->Invalid("vin.0 is normal for oraclescreate!"); + else if (ConstrainVout(tmptx.vout[0],0,oraclesaddr,txfee)==0) + return eval->Invalid("invalid marker for oraclescreate!"); + else if ( IsCCInput(tx.vin[0].scriptSig) != 0 ) + return eval->Invalid("vin.0 is normal for oraclesregister!"); + else if ((*cp->ismyvin)(tx.vin[tx.vin.size()-1].scriptSig) == 0 || myGetTransaction(tx.vin[tx.vin.size()-1].prevout.hash,tmptx,hashblock)==0 + || tmptx.vout[tx.vin[tx.vin.size()-1].prevout.n].nValue!=CC_MARKER_VALUE || !Getscriptaddress(vinaddress,tmptx.vout[tx.vin[tx.vin.size()-1].prevout.n].scriptPubKey) + || !GetCCaddress(cp,tmpaddress,tmppk) || strcmp(tmpaddress,vinaddress)!=0) + return eval->Invalid("vin."+std::to_string(tx.vin.size()-1)+" is CC for oraclesregister or pubkey not same as vin pubkey, register must be done from owner of pubkey that registers to oracle!!"); + else if (CCtxidaddr(tmpaddress,oracletxid).IsValid() && ConstrainVout(tx.vout[0],0,tmpaddress,txfee)==0) + return eval->Invalid("invalid marker for oraclesregister!"); + else if (!Getscriptaddress(tmpaddress,CScript() << ParseHex(HexStr(tmppk)) << OP_CHECKSIG) || ConstrainVout(tx.vout[2],0,tmpaddress,CC_MARKER_VALUE)==0) + return eval->Invalid("pubkey in OP_RETURN and in vout.2 not matching, register must be done from owner of pubkey that registers to oracle!"); + } + else return eval->Invalid("unexpected OraclesValidate for register"); break; case 'S': // subscribe // vins.*: normal inputs @@ -762,6 +814,45 @@ int64_t LifetimeOraclesFunds(struct CCcontract_info *cp,uint256 oracletxid,CPubK return(total); } +int64_t AddMyOraclesFunds(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey pk,uint256 oracletxid) +{ + char coinaddr[64],funcid; int64_t nValue,tmpamount; uint256 tmporacletxid,txid,hashBlock,ignoretxid; int32_t numvouts,vout,ignorevin; + std::vector > unspentOutputs; CTransaction vintx; CPubKey tmppk; + + GetCCaddress(cp,coinaddr,pk); + SetCCunspents(unspentOutputs,coinaddr,true); + for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) + { + txid = it->first.txhash; + vout = (int32_t)it->first.index; + nValue = it->second.satoshis; + if ( GetTransaction(txid,vintx,hashBlock,false) != 0 && (numvouts=vintx.vout.size())>0) + { + if ((funcid=DecodeOraclesOpRet(vintx.vout[numvouts-1].scriptPubKey,tmporacletxid,tmppk,tmpamount))!=0 && funcid=='F' && tmppk==pk + && tmporacletxid==oracletxid && tmpamount==nValue && myIsutxo_spentinmempool(ignoretxid,ignorevin,txid,vout)==0) + { + mtx.vin.push_back(CTxIn(txid,vout,CScript())); + return (nValue); + } + } else fprintf(stderr,"couldnt find transaction\n"); + } + + BOOST_FOREACH(const CTxMemPoolEntry &e, mempool.mapTx) + { + const CTransaction &txmempool = e.GetTx(); + const uint256 &hash = txmempool.GetHash(); + nValue=txmempool.vout[0].nValue; + + if ((funcid=DecodeOraclesOpRet(txmempool.vout[txmempool.vout.size()-1].scriptPubKey,tmporacletxid,tmppk,tmpamount))!=0 && funcid=='F' + && tmppk==pk && tmporacletxid==oracletxid && tmpamount==nValue && myIsutxo_spentinmempool(ignoretxid,ignorevin,hash,0)==0) + { + mtx.vin.push_back(CTxIn(hash,0,CScript())); + return (nValue); + } + } + return (0); +} + std::string OracleCreate(int64_t txfee,std::string name,std::string description,std::string format) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); @@ -802,10 +893,36 @@ std::string OracleCreate(int64_t txfee,std::string name,std::string description, return(""); } +std::string OracleFund(int64_t txfee,uint256 oracletxid) +{ + CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); + CPubKey mypk,oraclespk; struct CCcontract_info *cp,C; + + if (GetLatestTimestamp(komodo_currentheight())evalcode,CC_MARKER_VALUE,mypk)); + return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodeOraclesOpRet('F',oracletxid,mypk,CC_MARKER_VALUE))); + } + CCerror = strprintf("error adding normal inputs"); + fprintf(stderr,"%s\n", CCerror.c_str() ); + return(""); +} + std::string OracleRegister(int64_t txfee,uint256 oracletxid,int64_t datafee) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CPubKey mypk,markerpubkey,batonpk; struct CCcontract_info *cp,C; char markeraddr[64],batonaddr[64]; + CPubKey mypk,markerpubkey,batonpk,oraclespk; struct CCcontract_info *cp,C; char markeraddr[64],batonaddr[64]; + cp = CCinit(&C,EVAL_ORACLES); if ( txfee == 0 ) txfee = 10000; @@ -816,12 +933,20 @@ std::string OracleRegister(int64_t txfee,uint256 oracletxid,int64_t datafee) return(""); } mypk = pubkey2pk(Mypubkey()); + oraclespk = GetUnspendable(cp,0); batonpk = OracleBatonPk(batonaddr,cp); markerpubkey = CCtxidaddr(markeraddr,oracletxid); - if ( AddNormalinputs(mtx,mypk,3*txfee,4) > 0 ) + if (AddNormalinputs(mtx,mypk,3*txfee,4)) { + if (GetLatestTimestamp(komodo_currentheight())>PUBKEY_SPOOFING_FIX_ACTIVATION && AddMyOraclesFunds(cp,mtx,mypk,oracletxid)!=CC_MARKER_VALUE) + { + CCerror = strprintf("error adding inputs from your Oracles CC address, please fund it first with oraclesfund rpc!"); + fprintf(stderr,"%s\n", CCerror.c_str() ); + return(""); + } mtx.vout.push_back(CTxOut(txfee,CScript() << ParseHex(HexStr(markerpubkey)) << OP_CHECKSIG)); mtx.vout.push_back(MakeCC1vout(cp->evalcode,txfee,batonpk)); + if (GetLatestTimestamp(komodo_currentheight())>PUBKEY_SPOOFING_FIX_ACTIVATION) mtx.vout.push_back(CTxOut(txfee,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodeOraclesOpRet('R',oracletxid,mypk,datafee))); } CCerror = strprintf("error adding normal inputs"); @@ -924,43 +1049,70 @@ std::string OracleData(int64_t txfee,uint256 oracletxid,std::vector da UniValue OracleFormat(uint8_t *data,int32_t datalen,char *format,int32_t formatlen) { - uint256 hash; int32_t i,j=0; int64_t val; char str[IGUANA_MAXSCRIPTSIZE*2+1]; + UniValue obj(UniValue::VARR); uint256 hash; int32_t i,j=0; int64_t val; char str[IGUANA_MAXSCRIPTSIZE*2+1]; for (i=0; i= datalen ) break; } - return(str); + return(obj); } -UniValue OracleDataSamples(uint256 reforacletxid,uint256 batontxid,int32_t num) +UniValue OracleDataSamples(uint256 reforacletxid,char* batonaddr,int32_t num) { - UniValue result(UniValue::VOBJ),b(UniValue::VARR); CTransaction tx,oracletx; uint256 hashBlock,btxid,oracletxid; - CPubKey pk; std::string name,description,format; int32_t numvouts,n=0; std::vector data; char str[67], *formatstr = 0; + UniValue result(UniValue::VOBJ),b(UniValue::VARR); CTransaction tx,oracletx; uint256 txid,hashBlock,btxid,oracletxid; + CPubKey pk; std::string name,description,format; int32_t numvouts,n=0,vout; std::vector data; char *formatstr = 0; + std::vector > addressIndex; int64_t nValue; result.push_back(Pair("result","success")); if ( GetTransaction(reforacletxid,oracletx,hashBlock,false) != 0 && (numvouts=oracletx.vout.size()) > 0 ) { if ( DecodeOraclesCreateOpRet(oracletx.vout[numvouts-1].scriptPubKey,name,description,format) == 'C' ) { - while ( GetTransaction(batontxid,tx,hashBlock,false) != 0 && (numvouts=tx.vout.size()) > 0 ) + BOOST_FOREACH(const CTxMemPoolEntry &e, mempool.mapTx) { - if ( DecodeOraclesData(tx.vout[numvouts-1].scriptPubKey,oracletxid,btxid,pk,data) == 'D' && reforacletxid == oracletxid ) + const CTransaction &txmempool = e.GetTx(); + const uint256 &hash = txmempool.GetHash(); + if ((numvouts=txmempool.vout.size())>0 && DecodeOraclesData(txmempool.vout[numvouts-1].scriptPubKey,oracletxid,btxid,pk,data) == 'D' && reforacletxid == oracletxid ) { if ( (formatstr= (char *)format.c_str()) == 0 ) formatstr = (char *)""; UniValue a(UniValue::VOBJ); - a.push_back(Pair("data",OracleFormat((uint8_t *)data.data(),(int32_t)data.size(),formatstr,(int32_t)format.size()))); - a.push_back(Pair("txid",uint256_str(str,batontxid))); + a.push_back(Pair("txid",hash.GetHex())); + a.push_back(Pair("data",OracleFormat((uint8_t *)data.data(),(int32_t)data.size(),formatstr,(int32_t)format.size()))); b.push_back(a); - batontxid = btxid; if ( ++n >= num && num != 0) break; - } else break; + } + } + SetCCtxids(addressIndex,batonaddr,true); + if (addressIndex.size()>0) + { + for (std::vector >::const_iterator it=addressIndex.end()-1; it!=addressIndex.begin(); it--) + { + txid=it->first.txhash; + vout = (int32_t)it->first.index; + nValue = (int64_t)it->second; + if (vout==1 && nValue==10000 && GetTransaction(txid,tx,hashBlock,false) != 0 && (numvouts=tx.vout.size()) > 0 ) + { + if ( DecodeOraclesData(tx.vout[numvouts-1].scriptPubKey,oracletxid,btxid,pk,data) == 'D' && reforacletxid == oracletxid ) + { + if ( (formatstr= (char *)format.c_str()) == 0 ) + formatstr = (char *)""; + UniValue a(UniValue::VOBJ); + a.push_back(Pair("txid",txid.GetHex())); + a.push_back(Pair("data",OracleFormat((uint8_t *)data.data(),(int32_t)data.size(),formatstr,(int32_t)format.size()))); + b.push_back(a); + if ( ++n >= num && num != 0) + break; + } + } + } } } } @@ -971,10 +1123,12 @@ UniValue OracleDataSamples(uint256 reforacletxid,uint256 batontxid,int32_t num) UniValue OracleInfo(uint256 origtxid) { UniValue result(UniValue::VOBJ),a(UniValue::VARR); - std::vector > unspentOutputs; + std::vector > unspentOutputs; int32_t height; CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CTransaction regtx,tx; std::string name,description,format; uint256 hashBlock,txid,oracletxid,batontxid; CPubKey pk; + CTransaction tx; std::string name,description,format; uint256 hashBlock,txid,oracletxid,batontxid; CPubKey pk; struct CCcontract_info *cp,C; int64_t datafee,funding; char str[67],markeraddr[64],numstr[64],batonaddr[64]; std::vector data; + std::map> publishers; + cp = CCinit(&C,EVAL_ORACLES); CCtxidaddr(markeraddr,origtxid); if ( GetTransaction(origtxid,tx,hashBlock,false) == 0 ) @@ -998,28 +1152,38 @@ UniValue OracleInfo(uint256 origtxid) for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) { txid = it->first.txhash; - if ( GetTransaction(txid,regtx,hashBlock,false) != 0 ) + height = (int32_t)it->second.blockHeight; + if ( GetTransaction(txid,tx,hashBlock,false) != 0 && tx.vout.size() > 0 && + DecodeOraclesOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,oracletxid,pk,datafee) == 'R' && oracletxid == origtxid ) { - if ( regtx.vout.size() > 0 && DecodeOraclesOpRet(regtx.vout[regtx.vout.size()-1].scriptPubKey,oracletxid,pk,datafee) == 'R' && oracletxid == origtxid ) + if (publishers.find(pk)==publishers.end() || height>publishers[pk].second) { - UniValue obj(UniValue::VOBJ); - obj.push_back(Pair("publisher",pubkey33_str(str,(uint8_t *)pk.begin()))); - Getscriptaddress(batonaddr,regtx.vout[1].scriptPubKey); - batontxid = OracleBatonUtxo(10000,cp,oracletxid,batonaddr,pk,data); - obj.push_back(Pair("baton",batonaddr)); - obj.push_back(Pair("batontxid",uint256_str(str,batontxid))); - funding = LifetimeOraclesFunds(cp,oracletxid,pk); - sprintf(numstr,"%.8f",(double)funding/COIN); - obj.push_back(Pair("lifetime",numstr)); - funding = AddOracleInputs(cp,mtx,oracletxid,pk,0,0); - sprintf(numstr,"%.8f",(double)funding/COIN); - obj.push_back(Pair("funds",numstr)); - sprintf(numstr,"%.8f",(double)datafee/COIN); - obj.push_back(Pair("datafee",numstr)); - a.push_back(obj); + publishers[pk].first=txid; + publishers[pk].second=height; } } } + for (std::map>::iterator it = publishers.begin(); it != publishers.end(); ++it) + { + if ( GetTransaction(it->second.first,tx,hashBlock,false) != 0 && DecodeOraclesOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,oracletxid,pk,datafee) == 'R') + { + UniValue obj(UniValue::VOBJ); + obj.push_back(Pair("publisher",pubkey33_str(str,(uint8_t *)pk.begin()))); + Getscriptaddress(batonaddr,tx.vout[1].scriptPubKey); + batontxid = OracleBatonUtxo(10000,cp,oracletxid,batonaddr,pk,data); + obj.push_back(Pair("baton",batonaddr)); + obj.push_back(Pair("batontxid",uint256_str(str,batontxid))); + funding = LifetimeOraclesFunds(cp,oracletxid,pk); + sprintf(numstr,"%.8f",(double)funding/COIN); + obj.push_back(Pair("lifetime",numstr)); + funding = AddOracleInputs(cp,mtx,oracletxid,pk,0,0); + sprintf(numstr,"%.8f",(double)funding/COIN); + obj.push_back(Pair("funds",numstr)); + sprintf(numstr,"%.8f",(double)datafee/COIN); + obj.push_back(Pair("datafee",numstr)); + a.push_back(obj); + } + } result.push_back(Pair("registered",a)); } } diff --git a/src/rpc/server.cpp b/src/rpc/server.cpp index e36e8b4c9..5d7fd6d74 100644 --- a/src/rpc/server.cpp +++ b/src/rpc/server.cpp @@ -456,6 +456,7 @@ static const CRPCCommand vRPCCommands[] = { "oracles", "oracleslist", &oracleslist, true }, { "oracles", "oraclesinfo", &oraclesinfo, true }, { "oracles", "oraclescreate", &oraclescreate, true }, + { "oracles", "oraclesfund", &oraclesfund, true }, { "oracles", "oraclesregister", &oraclesregister, true }, { "oracles", "oraclessubscribe", &oraclessubscribe, true }, { "oracles", "oraclesdata", &oraclesdata, true }, diff --git a/src/rpc/server.h b/src/rpc/server.h index b9fb33198..27e7288cd 100644 --- a/src/rpc/server.h +++ b/src/rpc/server.h @@ -267,6 +267,7 @@ extern UniValue oraclesaddress(const UniValue& params, bool fHelp); extern UniValue oracleslist(const UniValue& params, bool fHelp); extern UniValue oraclesinfo(const UniValue& params, bool fHelp); extern UniValue oraclescreate(const UniValue& params, bool fHelp); +extern UniValue oraclesfund(const UniValue& params, bool fHelp); extern UniValue oraclesregister(const UniValue& params, bool fHelp); extern UniValue oraclessubscribe(const UniValue& params, bool fHelp); extern UniValue oraclesdata(const UniValue& params, bool fHelp); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index e9a9e38c6..e6e66caf7 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -6760,6 +6760,26 @@ UniValue oraclesinfo(const UniValue& params, bool fHelp) return(OracleInfo(txid)); } +UniValue oraclesfund(const UniValue& params, bool fHelp) +{ + UniValue result(UniValue::VOBJ); uint256 txid; std::string hex; + if ( fHelp || params.size() != 1 ) + throw runtime_error("oraclesfund oracletxid\n"); + if ( ensure_CCrequirements(EVAL_ORACLES) < 0 ) + throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + const CKeyStore& keystore = *pwalletMain; + LOCK2(cs_main, pwalletMain->cs_wallet); + txid = Parseuint256((char *)params[0].get_str().c_str()); + hex = OracleFund(0,txid); + RETURN_IF_ERROR(CCerror); + if ( hex.size() > 0 ) + { + result.push_back(Pair("result", "success")); + result.push_back(Pair("hex", hex)); + } else ERR_RESULT("couldnt fund with oracle txid"); + return(result); +} + UniValue oraclesregister(const UniValue& params, bool fHelp) { UniValue result(UniValue::VOBJ); uint256 txid; int64_t datafee; std::string hex; @@ -6806,17 +6826,17 @@ UniValue oraclessubscribe(const UniValue& params, bool fHelp) UniValue oraclessamples(const UniValue& params, bool fHelp) { - UniValue result(UniValue::VOBJ); uint256 txid,batontxid; int32_t num; + UniValue result(UniValue::VOBJ); uint256 txid; int32_t num; char *batonaddr; if ( fHelp || params.size() != 3 ) - throw runtime_error("oraclessamples oracletxid batonutxo num\n"); + throw runtime_error("oraclessamples oracletxid batonaddress num\n"); if ( ensure_CCrequirements(EVAL_ORACLES) < 0 ) throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); const CKeyStore& keystore = *pwalletMain; LOCK2(cs_main, pwalletMain->cs_wallet); txid = Parseuint256((char *)params[0].get_str().c_str()); - batontxid = Parseuint256((char *)params[1].get_str().c_str()); + batonaddr = (char *)params[1].get_str().c_str(); num = atoi((char *)params[2].get_str().c_str()); - return(OracleDataSamples(txid,batontxid,num)); + return(OracleDataSamples(txid,batonaddr,num)); } UniValue oraclesdata(const UniValue& params, bool fHelp) From b04b41e19d9547785ab15a06401a5c165bf02d81 Mon Sep 17 00:00:00 2001 From: smk762 <35845239+smk762@users.noreply.github.com> Date: Wed, 29 May 2019 16:41:15 +0800 Subject: [PATCH 431/447] Update cryptoconditions_oracles.py -change tests to use baton address instead of baton utxo -update samples results reference index -add test for oraclesfund -modify test loop flow to avoid spent utxo errors. Note: Successful test requires timestamp after July 15th 2019, or changing PUBKEY_SPOOFING_FIX_ACTIVATION value in oracles.cpp --- qa/rpc-tests/cryptoconditions_oracles.py | 121 +++++++++++++++-------- 1 file changed, 78 insertions(+), 43 deletions(-) diff --git a/qa/rpc-tests/cryptoconditions_oracles.py b/qa/rpc-tests/cryptoconditions_oracles.py index 953df5ca9..1db33bef7 100755 --- a/qa/rpc-tests/cryptoconditions_oracles.py +++ b/qa/rpc-tests/cryptoconditions_oracles.py @@ -3,7 +3,6 @@ # Distributed under the MIT software license, see the accompanying # file COPYING or http://www.opensource.org/licenses/mit-license.php. - from test_framework.test_framework import CryptoconditionsTestFramework from test_framework.authproxy import JSONRPCException from test_framework.util import assert_equal, assert_greater_than, \ @@ -11,13 +10,11 @@ from test_framework.util import assert_equal, assert_greater_than, \ stop_nodes, sync_blocks, sync_mempools, wait_bitcoinds, rpc_port, assert_raises from cryptoconditions import assert_success, assert_error, generate_random_string - class CryptoconditionsOraclesTest(CryptoconditionsTestFramework): def run_oracles_tests(self): rpc = self.nodes[0] rpc1 = self.nodes[1] - result = rpc1.oraclesaddress() result = rpc.oraclesaddress() @@ -54,159 +51,197 @@ class CryptoconditionsOraclesTest(CryptoconditionsTestFramework): too_long_description = generate_random_string(4100) result = rpc.oraclescreate("Test", too_long_description, "s") assert_error(result) + + # need uxtos to create oracle? Crashes if without generate + rpc.generate(2) + # valid creating oracles of different types # using such naming to re-use it for data publishing / reading (e.g. oracle_s for s type) + valid_formats = ["s", "S", "d", "D", "c", "C", "t", "T", "i", "I", "l", "L", "h", "Ihh"] for f in valid_formats: - result = rpc.oraclescreate("Test", "Test", f) + result = rpc.oraclescreate("Test_"+f, "Test_"+f, f) assert_success(result) globals()["oracle_{}".format(f)] = self.send_and_mine(result['hex'], rpc) # trying to register with negative datafee - for f in valid_formats: result = rpc.oraclesregister(globals()["oracle_{}".format(f)], "-100") assert_error(result) # trying to register with zero datafee - for f in valid_formats: result = rpc.oraclesregister(globals()["oracle_{}".format(f)], "0") assert_error(result) # trying to register with datafee less than txfee - for f in valid_formats: result = rpc.oraclesregister(globals()["oracle_{}".format(f)], "500") assert_error(result) - # trying to register valid - for f in valid_formats: + # trying to register valid (unfunded) result = rpc.oraclesregister(globals()["oracle_{}".format(f)], "10000") + assert_error(result) + + # Fund the oracles + result = rpc.oraclesfund(globals()["oracle_{}".format(f)]) + assert_success(result) + fund_txid = self.send_and_mine(result["hex"], rpc) + assert fund_txid, "got txid" + + # trying to register valid (funded) + result = rpc.oraclesregister(globals()["oracle_{}".format(f)], "10000") + print(f) assert_success(result) register_txid = self.send_and_mine(result["hex"], rpc) assert register_txid, "got txid" # TODO: for most of the non valid oraclesregister and oraclessubscribe transactions generating and broadcasting now # so trying only valid oraclessubscribe atm - for f in valid_formats: result = rpc.oraclessubscribe(globals()["oracle_{}".format(f)], self.pubkey, "1") assert_success(result) subscribe_txid = self.send_and_mine(result["hex"], rpc) assert register_txid, "got txid" + rpc.generate(1) + # now lets publish and read valid data for each oracle type # s type result = rpc.oraclesdata(globals()["oracle_{}".format("s")], "05416e746f6e") assert_success(result) - # baton - oraclesdata_s = self.send_and_mine(result["hex"], rpc) - result = rpc.oraclessamples(globals()["oracle_{}".format("s")], oraclesdata_s, "1") - assert_equal("[u'Anton']", str(result["samples"][0]), "Data match") + oraclesdata_s = self.send_and_mine(result["hex"], rpc) + info = rpc.oraclesinfo(globals()["oracle_{}".format("s")]) + batonaddr = info['registered'][0]['baton'] + result = rpc.oraclessamples(globals()["oracle_{}".format("s")], batonaddr, "1") + assert_equal("[u'Anton']", str(result["samples"][0]['data']), "Data match") # S type result = rpc.oraclesdata(globals()["oracle_{}".format("S")], "000161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161") assert_success(result) - # baton oraclesdata_S = self.send_and_mine(result["hex"], rpc) - result = rpc.oraclessamples(globals()["oracle_{}".format("S")], oraclesdata_S, "1") - assert_equal("[u'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa']", str(result["samples"][0]), "Data match") + info = rpc.oraclesinfo(globals()["oracle_{}".format("S")]) + batonaddr = info['registered'][0]['baton'] + result = rpc.oraclessamples(globals()["oracle_{}".format("S")], batonaddr, "1") + assert_equal("[u'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa']", str(result["samples"][0]['data']), "Data match") # d type result = rpc.oraclesdata(globals()["oracle_{}".format("d")], "0101") assert_success(result) # baton oraclesdata_d = self.send_and_mine(result["hex"], rpc) - result = rpc.oraclessamples(globals()["oracle_{}".format("d")], oraclesdata_d, "1") - assert_equal("[u'01']", str(result["samples"][0]), "Data match") + info = rpc.oraclesinfo(globals()["oracle_{}".format("d")]) + batonaddr = info['registered'][0]['baton'] + result = rpc.oraclessamples(globals()["oracle_{}".format("d")], batonaddr, "1") + assert_equal("[u'01']", str(result["samples"][0]['data']), "Data match") # D type 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") - assert_equal("[u'01']", str(result["samples"][0]), "Data match") + info = rpc.oraclesinfo(globals()["oracle_{}".format("D")]) + batonaddr = info['registered'][0]['baton'] + result = rpc.oraclessamples(globals()["oracle_{}".format("D")], batonaddr, "1") + assert_equal("[u'01']", str(result["samples"][0]['data']), "Data match") # c type result = rpc.oraclesdata(globals()["oracle_{}".format("c")], "ff") assert_success(result) # baton oraclesdata_c = self.send_and_mine(result["hex"], rpc) - result = rpc.oraclessamples(globals()["oracle_{}".format("c")], oraclesdata_c, "1") - assert_equal("[u'-1']", str(result["samples"][0]), "Data match") + info = rpc.oraclesinfo(globals()["oracle_{}".format("c")]) + batonaddr = info['registered'][0]['baton'] + result = rpc.oraclessamples(globals()["oracle_{}".format("c")], batonaddr, "1") + assert_equal("[u'-1']", str(result["samples"][0]['data']), "Data match") # C type result = rpc.oraclesdata(globals()["oracle_{}".format("C")], "ff") assert_success(result) # baton oraclesdata_C = self.send_and_mine(result["hex"], rpc) - result = rpc.oraclessamples(globals()["oracle_{}".format("C")], oraclesdata_C, "1") - assert_equal("[u'255']", str(result["samples"][0]), "Data match") + info = rpc.oraclesinfo(globals()["oracle_{}".format("C")]) + batonaddr = info['registered'][0]['baton'] + result = rpc.oraclessamples(globals()["oracle_{}".format("C")], batonaddr, "1") + assert_equal("[u'255']", str(result["samples"][0]['data']), "Data match") # t type result = rpc.oraclesdata(globals()["oracle_{}".format("t")], "ffff") assert_success(result) # baton oraclesdata_t = self.send_and_mine(result["hex"], rpc) - result = rpc.oraclessamples(globals()["oracle_{}".format("t")], oraclesdata_t, "1") - assert_equal("[u'-1']", str(result["samples"][0]), "Data match") + info = rpc.oraclesinfo(globals()["oracle_{}".format("t")]) + batonaddr = info['registered'][0]['baton'] + result = rpc.oraclessamples(globals()["oracle_{}".format("t")], batonaddr, "1") + assert_equal("[u'-1']", str(result["samples"][0]['data']), "Data match") # T type result = rpc.oraclesdata(globals()["oracle_{}".format("T")], "ffff") assert_success(result) # baton oraclesdata_T = self.send_and_mine(result["hex"], rpc) - result = rpc.oraclessamples(globals()["oracle_{}".format("T")], oraclesdata_T, "1") - assert_equal("[u'65535']", str(result["samples"][0]), "Data match") + info = rpc.oraclesinfo(globals()["oracle_{}".format("T")]) + batonaddr = info['registered'][0]['baton'] + result = rpc.oraclessamples(globals()["oracle_{}".format("T")], batonaddr, "1") + assert_equal("[u'65535']", str(result["samples"][0]['data']), "Data match") # i type result = rpc.oraclesdata(globals()["oracle_{}".format("i")], "ffffffff") assert_success(result) # baton oraclesdata_i = self.send_and_mine(result["hex"], rpc) - result = rpc.oraclessamples(globals()["oracle_{}".format("i")], oraclesdata_i, "1") - assert_equal("[u'-1']", str(result["samples"][0]), "Data match") + info = rpc.oraclesinfo(globals()["oracle_{}".format("i")]) + batonaddr = info['registered'][0]['baton'] + result = rpc.oraclessamples(globals()["oracle_{}".format("i")], batonaddr, "1") + assert_equal("[u'-1']", str(result["samples"][0]['data']), "Data match") # I type result = rpc.oraclesdata(globals()["oracle_{}".format("I")], "ffffffff") assert_success(result) # baton oraclesdata_I = self.send_and_mine(result["hex"], rpc) - result = rpc.oraclessamples(globals()["oracle_{}".format("I")], oraclesdata_I, "1") - assert_equal("[u'4294967295']", str(result["samples"][0]), "Data match") + info = rpc.oraclesinfo(globals()["oracle_{}".format("I")]) + batonaddr = info['registered'][0]['baton'] + result = rpc.oraclessamples(globals()["oracle_{}".format("I")], batonaddr, "1") + assert_equal("[u'4294967295']", str(result["samples"][0]['data']), "Data match") # l type result = rpc.oraclesdata(globals()["oracle_{}".format("l")], "00000000ffffffff") assert_success(result) # baton oraclesdata_l = self.send_and_mine(result["hex"], rpc) - result = rpc.oraclessamples(globals()["oracle_{}".format("l")], oraclesdata_l, "1") - # TODO: working not correct now! - #assert_equal("[u'-4294967296']", str(result["samples"][0]), "Data match") + info = rpc.oraclesinfo(globals()["oracle_{}".format("l")]) + batonaddr = info['registered'][0]['baton'] + result = rpc.oraclessamples(globals()["oracle_{}".format("l")], batonaddr, "1") + assert_equal("[u'-4294967296']", str(result["samples"][0]['data']), "Data match") # L type result = rpc.oraclesdata(globals()["oracle_{}".format("L")], "00000000ffffffff") assert_success(result) # baton oraclesdata_L = self.send_and_mine(result["hex"], rpc) - result = rpc.oraclessamples(globals()["oracle_{}".format("L")], oraclesdata_L, "1") - assert_equal("[u'18446744069414584320']", str(result["samples"][0]), "Data match") + info = rpc.oraclesinfo(globals()["oracle_{}".format("L")]) + batonaddr = info['registered'][0]['baton'] + result = rpc.oraclessamples(globals()["oracle_{}".format("L")], batonaddr, "1") + assert_equal("[u'18446744069414584320']", str(result["samples"][0]['data']), "Data match") # h type result = rpc.oraclesdata(globals()["oracle_{}".format("h")], "00000000ffffffff00000000ffffffff00000000ffffffff00000000ffffffff") assert_success(result) # baton oraclesdata_h = self.send_and_mine(result["hex"], rpc) - result = rpc.oraclessamples(globals()["oracle_{}".format("h")], oraclesdata_h, "1") - assert_equal("[u'ffffffff00000000ffffffff00000000ffffffff00000000ffffffff00000000']", str(result["samples"][0]), "Data match") + info = rpc.oraclesinfo(globals()["oracle_{}".format("h")]) + batonaddr = info['registered'][0]['baton'] + result = rpc.oraclessamples(globals()["oracle_{}".format("h")], batonaddr, "1") + assert_equal("[u'ffffffff00000000ffffffff00000000ffffffff00000000ffffffff00000000']", str(result["samples"][0]['data']), "Data match") # Ihh type 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'4294967295', u'ffffffff00000000ffffffff00000000ffffffff00000000ffffffff00000000', u'ffffffff00000000ffffffff00000000ffffffff00000000ffffffff00000000']", str(result["samples"][0]), "Data match") - + info = rpc.oraclesinfo(globals()["oracle_{}".format("Ihh")]) + batonaddr = info['registered'][0]['baton'] + result = rpc.oraclessamples(globals()["oracle_{}".format("Ihh")], batonaddr, "1") + print(result) + assert_equal("[u'4294967295', u'ffffffff00000000ffffffff00000000ffffffff00000000ffffffff00000000', u'ffffffff00000000ffffffff00000000ffffffff00000000ffffffff00000000']", str(result["samples"][0]['data']), "Data match") def run_test(self): print("Mining blocks...") From 9a5de83ebc486053aed16db8011f60e66fcf84fe Mon Sep 17 00:00:00 2001 From: DeckerSU Date: Wed, 29 May 2019 23:14:15 +0300 Subject: [PATCH 432/447] sort64 / revsort64s has void return-type --- src/cc/crypto777/OS_portable.h | 4 ++-- src/komodo_gateway.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/cc/crypto777/OS_portable.h b/src/cc/crypto777/OS_portable.h index d6abc98c5..aeb45bc32 100755 --- a/src/cc/crypto777/OS_portable.h +++ b/src/cc/crypto777/OS_portable.h @@ -309,8 +309,8 @@ char *uppercase_str(char *buf,char *str); char *lowercase_str(char *buf,char *str); int32_t strsearch(char *strs[],int32_t num,char *name); int32_t OS_getline(int32_t waitflag,char *line,int32_t max,char *dispstr); -int32_t sort64s(uint64_t *buf,uint32_t num,int32_t size); -int32_t revsort64s(uint64_t *buf,uint32_t num,int32_t size); +void sort64s(uint64_t *buf,uint32_t num,int32_t size); +void revsort64s(uint64_t *buf,uint32_t num,int32_t size); int decode_base32(uint8_t *token,uint8_t *tokenstr,int32_t len); int init_base32(char *tokenstr,uint8_t *token,int32_t len); char *OS_mvstr(); diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 1455c34b3..7cfe870b4 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -2597,7 +2597,7 @@ static int cmp_llu(const void *a, const void*b) else return(1); } -static int64_t sort64(int64_t *l, int32_t llen) +static void sort64(int64_t *l, int32_t llen) { qsort(l,llen,sizeof(uint64_t),cmp_llu); } @@ -2611,7 +2611,7 @@ static int revcmp_llu(const void *a, const void*b) else return(1); } -static int64_t revsort64(int64_t *l, int32_t llen) +static void revsort64(int64_t *l, int32_t llen) { qsort(l,llen,sizeof(uint64_t),revcmp_llu); } From 33a0059a18d416a4ee7695381bbca755a018a8c1 Mon Sep 17 00:00:00 2001 From: DeckerSU Date: Thu, 30 May 2019 00:11:50 +0300 Subject: [PATCH 433/447] gcc-8: fix komodo_connectblock reaches end of non-void function error --- src/komodo.h | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index cd7c6573a..4de6ee4f3 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -803,7 +803,10 @@ int32_t komodo_notarycmp(uint8_t *scriptPubKey,int32_t scriptlen,uint8_t pubkeys return(-1); } -// int32_t ! +// int32_t (!!!) +/* + read blackjok3rtt comments in main.cpp +*/ int32_t komodo_connectblock(bool fJustCheck, CBlockIndex *pindex,CBlock& block) { static int32_t hwmheight; @@ -897,8 +900,8 @@ int32_t komodo_connectblock(bool fJustCheck, CBlockIndex *pindex,CBlock& block) } numvalid = bitweight(signedmask); if ( ((height < 90000 || (signedmask & 1) != 0) && numvalid >= KOMODO_MINRATIFY) || - (numvalid >= KOMODO_MINRATIFY && ASSETCHAINS_SYMBOL[0] != 0) || - numvalid > (numnotaries/5) ) + (numvalid >= KOMODO_MINRATIFY && ASSETCHAINS_SYMBOL[0] != 0) || + numvalid > (numnotaries/5) ) { if ( !fJustCheck && ASSETCHAINS_SYMBOL[0] != 0) { @@ -918,7 +921,7 @@ int32_t komodo_connectblock(bool fJustCheck, CBlockIndex *pindex,CBlock& block) fflush(signedfp); } transaction = i; - printf("[%s] ht.%d txi.%d signedmask.%llx numvins.%d numvouts.%d <<<<<<<<<<< notarized\n",ASSETCHAINS_SYMBOL,height,i,(long long)signedmask,numvins,numvouts); + printf("[%s] ht.%d txi.%d signedmask.%llx numvins.%d numvouts.%d <<<<<<<<<<< notarized\n",ASSETCHAINS_SYMBOL,height,i,(long long)signedmask,numvins,numvouts); } notarized = 1; } @@ -1014,7 +1017,9 @@ int32_t komodo_connectblock(bool fJustCheck, CBlockIndex *pindex,CBlock& block) printf("%s ht.%d\n",ASSETCHAINS_SYMBOL[0] == 0 ? "KMD" : ASSETCHAINS_SYMBOL,height); if ( !fJustCheck && pindex->GetHeight() == hwmheight ) komodo_stateupdate(height,0,0,0,zero,0,0,0,0,height,(uint32_t)pindex->nTime,0,0,0,0,zero,0); - } else fprintf(stderr,"komodo_connectblock: unexpected null pindex\n"); + } + else + { fprintf(stderr,"komodo_connectblock: unexpected null pindex\n"); return(0); } //KOMODO_INITDONE = (uint32_t)time(NULL); //fprintf(stderr,"%s end connect.%d\n",ASSETCHAINS_SYMBOL,pindex->GetHeight()); if (fJustCheck) @@ -1025,6 +1030,12 @@ int32_t komodo_connectblock(bool fJustCheck, CBlockIndex *pindex,CBlock& block) return(1); if ( notarisations.size() > 1 || (notarisations.size() == 1 && notarisations[0] != 1) ) return(-1); + + fprintf(stderr,"komodo_connectblock: unxexpected behaviour when fJustCheck == true, report blackjok3rtt plz ! \n"); + /* this needed by gcc-8, it counts here that control reaches end of non-void function without this. + by default, we count that if control reached here -> the valid notarization isnt in position 1 or there are too many notarizations in this block. + */ + return(-1); } else return(0); } From 4f989b26ebf76a424ed9df4f78e24205c0168aef Mon Sep 17 00:00:00 2001 From: DeckerSU Date: Thu, 30 May 2019 00:23:38 +0300 Subject: [PATCH 434/447] fix notarisationTx type --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index c14e4351d..a8ae8b60c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3392,7 +3392,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin { // do a full block scan to get notarisation position and to enforce a valid notarization is in position 1. // if notarisation in the block, must be position 1 and the coinbase must pay notaries. - int notarisationTx = komodo_connectblock(true,pindex,*(CBlock *)&block); + int32_t notarisationTx = komodo_connectblock(true,pindex,*(CBlock *)&block); // -1 means that the valid notarization isnt in position 1 or there are too many notarizations in this block. if ( notarisationTx == -1 ) return state.DoS(100, error("ConnectBlock(): Notarization is not in TX position 1 or block contains more than 1 notarization! Invalid Block!"), From 8c9fc38a928cbd21b9034dd9a12fa07a5cc0ce73 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Thu, 30 May 2019 21:19:15 +0800 Subject: [PATCH 435/447] fix --- src/cc/makecclib | 5 ----- src/cc/makerogue | 3 +++ zcutil/build.sh | 2 +- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/cc/makecclib b/src/cc/makecclib index 0d82463c4..e4816c55c 100755 --- a/src/cc/makecclib +++ b/src/cc/makecclib @@ -7,11 +7,6 @@ make -f Makefile_rogue rm ../libcc.so cp librogue.so ../libcc.so -if [ "${LABS_FLAGS}" = "ENABLE_LABS" ] -then - exit -fi - echo sudoku/musig/dilithium gcc -O3 -std=c++11 -I../secp256k1/include -I../univalue/include -I../cryptoconditions/include -I../cryptoconditions/src -I../cryptoconditions/src/asn -I.. -I. -fPIC -shared -c -o sudokucc.so cclib.cpp diff --git a/src/cc/makerogue b/src/cc/makerogue index ff16cbb16..a389ba2dd 100755 --- a/src/cc/makerogue +++ b/src/cc/makerogue @@ -35,3 +35,6 @@ else echo ROGUE BUILD FAILED exit 1 fi + +rm ../libcc.so +cp librogue.so ../libcc.so diff --git a/zcutil/build.sh b/zcutil/build.sh index dc4d027b1..df3dfa234 100755 --- a/zcutil/build.sh +++ b/zcutil/build.sh @@ -106,7 +106,7 @@ CONFIG_SITE="$PWD/depends/$HOST/share/config.site" ./configure "$HARDENING_ARG" WD=$PWD cd src/cc echo $PWD -./makecclib +./makerogue cd $WD "$MAKE" "$@" V=1 From 5e6d7bad4b8f47aed3eac35c68665a17a789a1a2 Mon Sep 17 00:00:00 2001 From: ca333 Date: Fri, 31 May 2019 03:11:54 +0200 Subject: [PATCH 436/447] fix OSX this fixes the faulty OSX patch --- src/cc/Makefile_rogue | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/Makefile_rogue b/src/cc/Makefile_rogue index baf8767aa..3b2f65e00 100644 --- a/src/cc/Makefile_rogue +++ b/src/cc/Makefile_rogue @@ -1,6 +1,6 @@ SHELL = /bin/sh CC = gcc -CC_DARWIN = g++-6 +CC_DARWIN = g++-8 CC_WIN = x86_64-w64-mingw32-gcc-posix CFLAGS_DARWIN = -DBUILD_ROGUE -std=c++11 -arch x86_64 -I../../depends/$(shell echo `../..//depends/config.guess`/include) -I../univalue/include -I../cryptoconditions/include -I../cryptoconditions/src -I../cryptoconditions/src/asn -I.. -I. -fPIC -Wl,-undefined -Wl,dynamic_lookup -Wno-write-strings -shared -dynamiclib CFLAGS = -Wno-write-strings -DBUILD_ROGUE -std=c++11 -I../../depends/$(shell echo `../..//depends/config.guess`/include) -I../univalue/include -I../cryptoconditions/include -I../cryptoconditions/src -I../cryptoconditions/src/asn -I.. -I. -fPIC -shared @@ -14,7 +14,7 @@ TARGET = librogue.so TARGET_DARWIN = librogue.dylib TARGET_WIN = librogue.dll SOURCES = cclib.cpp -#HEADERS = $(shell echo ../cryptoconditions/include/*.h) -I/usr/local/Cellar/gcc\@6/6.4.0_2/include/c++/6.4.0/ +#HEADERS = $(shell echo ../cryptoconditions/include/*.h) -I/usr/local/Cellar/gcc\@8/8.3.0/include/c++/8.3.0/ all: $(TARGET) From 43d3043d34e08eb631938e1826da489ef74ae304 Mon Sep 17 00:00:00 2001 From: ca333 Date: Fri, 31 May 2019 03:12:33 +0200 Subject: [PATCH 437/447] fix OSX this fixes the faulty OSX patch --- depends/hosts/darwin.mk | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/depends/hosts/darwin.mk b/depends/hosts/darwin.mk index d01e8b5a3..7be744aeb 100644 --- a/depends/hosts/darwin.mk +++ b/depends/hosts/darwin.mk @@ -1,9 +1,9 @@ -OSX_MIN_VERSION=10.8 -OSX_SDK_VERSION=10.11 +OSX_MIN_VERSION=10.12 +OSX_SDK_VERSION=10.12 OSX_SDK=$(SDK_PATH)/MacOSX$(OSX_SDK_VERSION).sdk LD64_VERSION=253.9 -darwin_CC=gcc-6 -target $(host) -mmacosx-version-min=$(OSX_MIN_VERSION) --sysroot $(OSX_SDK) -mlinker-version=$(LD64_VERSION) -darwin_CXX=g++-6 -target $(host) -mmacosx-version-min=$(OSX_MIN_VERSION) --sysroot $(OSX_SDK) -mlinker-version=$(LD64_VERSION) +darwin_CC=gcc-8 -target $(host) -mmacosx-version-min=$(OSX_MIN_VERSION) --sysroot $(OSX_SDK) -mlinker-version=$(LD64_VERSION) +darwin_CXX=g++-8 -target $(host) -mmacosx-version-min=$(OSX_MIN_VERSION) --sysroot $(OSX_SDK) -mlinker-version=$(LD64_VERSION) darwin_CFLAGS=-pipe darwin_CXXFLAGS=$(darwin_CFLAGS) From 2d5a95ca8886e4650e33dea861347aa57a46ce45 Mon Sep 17 00:00:00 2001 From: ca333 Date: Fri, 31 May 2019 03:12:58 +0200 Subject: [PATCH 438/447] fix OSX --- zcutil/build-mac.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/zcutil/build-mac.sh b/zcutil/build-mac.sh index 5f1817e9e..89847ddac 100755 --- a/zcutil/build-mac.sh +++ b/zcutil/build-mac.sh @@ -1,6 +1,6 @@ #!/bin/bash -export CC=gcc-6 -export CXX=g++-6 +export CC=gcc-8 +export CXX=g++-8 export LIBTOOL=libtool export AR=ar export RANLIB=ranlib @@ -52,7 +52,7 @@ cd $WD ./autogen.sh CPPFLAGS="-I$PREFIX/include -arch x86_64" LDFLAGS="-L$PREFIX/lib -arch x86_64 -Wl,-no_pie" \ -CXXFLAGS='-arch x86_64 -I/usr/local/Cellar/gcc\@6/6.4.0_2/include/c++/6.4.0/ -I$PREFIX/include -fwrapv -fno-strict-aliasing -Wno-builtin-declaration-mismatch -Werror -g -Wl,-undefined -Wl,dynamic_lookup' \ +CXXFLAGS='-arch x86_64 -I/usr/local/Cellar/gcc\@8/8.3.0/include/c++/8.3.0/ -I$PREFIX/include -fwrapv -fno-strict-aliasing -Wno-builtin-declaration-mismatch -Werror -g -Wl,-undefined -Wl,dynamic_lookup' \ ./configure --prefix="${PREFIX}" --with-gui=no "$HARDENING_ARG" "$LCOV_ARG" make "$@" V=1 NO_GTEST=1 STATIC=1 From df7f46285ae0525bbfbb00da481033cd8b836756 Mon Sep 17 00:00:00 2001 From: ca333 Date: Fri, 31 May 2019 03:14:38 +0200 Subject: [PATCH 439/447] fix OSX --- toolchain-info.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/toolchain-info.sh b/toolchain-info.sh index 0bb39c19b..6a0fc7e75 100755 --- a/toolchain-info.sh +++ b/toolchain-info.sh @@ -1,6 +1,6 @@ #!/bin/bash -tools=("gcc-6" "g++-6" "otool" "nm") +tools=("gcc-8" "g++-8" "otool" "nm") echo "Platform: `uname -a`" echo "-------------------------------------" From 01fb676782b5a0c26ca165c49ce5b2690d73f670 Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Fri, 31 May 2019 10:53:02 +0200 Subject: [PATCH 440/447] Allow duplicate receivers in z_sendmany --- 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 e9a9e38c6..ffec43355 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4353,8 +4353,9 @@ UniValue z_sendmany(const UniValue& params, bool fHelp) //else if ( ASSETCHAINS_PRIVATE != 0 && komodo_isnotaryvout((char *)address.c_str()) == 0 ) // throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "cant use transparent addresses in private chain"); - if (setAddress.count(address)) - throw JSONRPCError(RPC_INVALID_PARAMETER, string("Invalid parameter, duplicated address: ")+address); + // Allowing duplicate receivers helps various HushList protocol operations + //if (setAddress.count(address)) + // throw JSONRPCError(RPC_INVALID_PARAMETER, string("Invalid parameter, duplicated address: ")+address); setAddress.insert(address); UniValue memoValue = find_value(o, "memo"); From f5d4ff421e035592a21cff2f42811652bb2cfe64 Mon Sep 17 00:00:00 2001 From: Mihail Fedorov Date: Mon, 3 Jun 2019 02:04:54 +0300 Subject: [PATCH 441/447] Notaries 2019 --- src/komodo_defs.h | 66 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/src/komodo_defs.h b/src/komodo_defs.h index cf15f0b19..656c20c53 100644 --- a/src/komodo_defs.h +++ b/src/komodo_defs.h @@ -178,6 +178,72 @@ static const char *notaries_elected[NUM_KMD_SEASONS][NUM_KMD_NOTARIES][2] = {"webworker01_NA", "03bb7d005e052779b1586f071834c5facbb83470094cff5112f0072b64989f97d7" }, {"xrobesx_NA", "03f0cc6d142d14a40937f12dbd99dbd9021328f45759e26f1877f2a838876709e1" }, }, + { + {"madmax_NA", "02016371f90f195ed9aeaf37be06f3fbbfbfe2ef8a4fd66378378289476e7751db", "03489b67faabdf450c9661ca386ba8a65eca859f39b3ec4c7a6be40c9c7bf153b7" }, + {"alright_AR", "020566fe2fb3874258b2d3cf1809a5d650e0edc7ba746fa5eec72750c5188c9cc9", "036a6bca1c2a8166f79fa8a979662892742346cc972b432f8e61950a358d705517" }, + {"strob_NA", "0206f7a2e972d9dfef1c424c731503a0a27de1ba7a15a91a362dc7ec0d0fb47685", "02049202f3872877e81035549f6f3a0f868d0ad1c9b0e0d2b48b1f30324255d26d" }, + {"dwy_EU", "020a77f454a1d3fcdc0312048fc58d713fe6153189e0c59cdd12fedbf09553d4b0", "021a7e11182f3603720436daea4e9a2ad5a9990943f0c96d6bcb5d7823040317fa" }, + {"phm87_SH", "021773a38db1bc3ede7f28142f901a161c7b7737875edbb40082a201c55dcf0add", "03889a10f9df2caef57220628515693cf25316fe1b0693b0241419e75d0d0e66ed" }, + {"chainmakers_NA", "021ad488cc063e17d0f1a2aade6be65ef8b5ff879987cb0b86bb700733099fe524", "0369aa258f317f028afd3acbe74658c4b483b7e0069107c5885ac49128dd18a13d" }, + {"indenodes_EU", "0221387ff95c44cb52b86552e3ec118a3c311ca65b75bf807c6c07eaeb1be8303c", "03a416533cace0814455a1bb1cd7861ce825a543c6f6284a432c4c8d8875b7ace9" }, + {"blackjok3r_SH", "0226293d7644e1380555ecc2d385ba038a66f4202b24b643ab31bcad0dc1474de2", "03c90bee400010904acb42464807feb0039ab42cc86d5401222299280b876b52e3" }, + {"chainmakers_EU", "022a6b583e8820d14d911a11820fd80853c5b8406e91a0a6fcac1f133d098d75cb", "034a6ae969bbd13258f9b7d3bbbdb81c93f2914d3fdb01ce31ad1d2a9078ef5fcd" }, + {"titomane_AR", "023e3aa9834c46971ff3e7cb86a200ec9c8074a9566a3ea85d400d5739662ee989", "0358cd6d7460654a0ddd5125dd6fa0402d0719999444c6cc3888689a0b4446136a" }, + {"fullmoon_SH", "02639998420688ee935d279d1cd52f1c6f3ae12c1f3afc20b3bf7ece1057f8b93b", "0370f07837cfefe1542f030b80e8fffa57218f4b7fff2dd181b0e21700c5480a7b" }, // 10 + {"indenodes_NA", "02698c6f1c9e43b66e82dbb163e8df0e5a2f62f3a7a882ca387d82f86e0b3fa988", "02b3908eda4078f0e9b6704451cdc24d418e899c0f515fab338d7494da6f0a647b" }, + {"chmex_EU", "0281304ebbcc39e4f09fda85f4232dd8dacd668e20e5fc11fba6b985186c90086e", "03e5b7ab96b7271ecd585d6f22807fa87da374210a843ec3a90134cbf4a62c3db1" }, + {"metaphilibert_SH", "0284af1a5ef01503e6316a2ca4abf8423a794e9fc17ac6846f042b6f4adedc3309", "03b21ff042bf1730b28bde43f44c064578b41996117ac7634b567c3773089e3be3" }, + {"ca333_DEV", "02856843af2d9457b5b1c907068bef6077ea0904cc8bd4df1ced013f64bf267958", "029c0342ce2a4f9146c7d1ee012b26f5c2df78b507fb4461bf48df71b4e3031b56" }, + {"cipi_NA", "02858904a2a1a0b44df4c937b65ee1f5b66186ab87a751858cf270dee1d5031f18", "034406ac4cf94e84561c5d3f25384dd59145e92fefc5972a037dc6a44bfa286688" }, + {"pungocloud_SH", "02863628f842a8aa424daf745cf43a1717cfcd571338ba87bfcec4d340703d01d6", "03f42c8052decf9a9d2eba60b1c8cd8b2b8e858d6b1ef0e5f09ba8a9ac1b1ced62" }, + {"voskcoin_EU", "028cfb0bbce2207425bc8d40fff634269bb61aade2d1d03883398275550b465600", "037135718fa54e59bcb71f9f9e9c4ab43daa86be50dbaadce10bc176a4f611d546" }, + {"decker_DEV", "028eea44a09674dda00d88ffd199a09c9b75ba9782382cc8f1e97c0fd565fe5707", "02fca8ee50e49f480de275745618db7b0b3680b0bdcce7dcae7d2e0fd5c3345744" }, + {"cryptoeconomy_EU", "0290ab4937e85246e048552df3e9a66cba2c1602db76e03763e16c671e750145d1", "037d04b7d16de61a44a3fc766bea4b7791023a36675d6cee862fe53defd04dd8f2" }, + {"etszombi_EU", "0293ea48d8841af7a419a24d9da11c34b39127ef041f847651bae6ab14dcd1f6b4", "02f65da26061d1b9f1756a274918a37e83086dbfe9a43d2f0b35b9d2f593b31907" }, // 20 + {"karasugoi_NA", "02a348b03b9c1a8eac1b56f85c402b041c9bce918833f2ea16d13452309052a982", "024ba10f7f5325fd6ec6cab50c5242d142d00fab3537c0002097c0e98f72014177" }, + {"pirate_AR", "02a5e865af771eee0c6bd3bd238f01f5eb589907ba52efa9f37e5102375c8eb7a0", "0228431427395f0cefdb0d10402d0d726119508945eb66ca9c0bba5d64df79832c" }, + {"metaphilibert_AR", "02adad675fae12b25fdd0f57250b0caf7f795c43f346153a31fe3e72e7db1d6ac6", "0239e34ad22957bbf4c8df824401f237b2afe8d40f7a645ecd43e8f27dde1ab0da" }, + {"zatjum_SH", "02b315714f99fdd70bafd50a4c3aa4b9db0fd8d63978bd8d47763773400b28734c", "031675aae243d2e4f3e8b67dbc4a68f50f487a37df959d739b26a80ce917b10d84" }, + {"madmax_AR", "02b37913ac0250d17cca5bb94ef65928b1515f13f839075446db73b9b067c13aa0", "032f5fc01607c2e82417cfe822b981116262961c0a66f715fbb7e84614aadfe5df" }, + {"lukechilds_NA", "02c191a085bbb0bd86d126c62d3e801c503038b69c0c2de121c9a7abe3e6684420", "03dbda3ea207b1aca24803fa53f990402b0bea9ec6bdc4486d9878add7623faf35" }, + {"cipi_AR", "02c4f89a5b382750836cb787880d30e23502265054e1c327a5bfce67116d757ce8", "025b7655826f5fd3a807cbb4918ef9f02fe64661153ca170db981e9b0861f8c5ad" }, + {"tonyl_AR", "02cc8bc862f2b65ad4f99d5f68d3011c138bf517acdc8d4261166b0be8f64189e1", "03a8db38075c80348889871b4318b0a79a1fd7e9e21daefb4ca6e4f05e5963569c" }, + {"infotech_DEV", "02d7d63ac441dbcd5535bcad741701519c190e89e17e4180aa0f61fdda0b6195ea", "032a8265e3c5029d17bbb5a46da81aedd81dad74c152a21568ef082d3d497dcada" }, + {"fullmoon_NA", "02da228a67e519b21bca6426ed982509a21d24d45f1ac1bdf698b6083fed442ec3", "0291038301dea2ec683a3f686579dcebe37b2113cc6137ef0bfe87b505bcd16016" }, // 30 + {"etszombi_AR", "02e55e104aa94f70cde68165d7df3e162d4410c76afd4643b161dea044aa6d06ce", "03c786702b81e0122157739c8e2377cf945998d36c0d187ec5c5ff95855848dfdd" }, + {"node-9_EU", "02e90f0528f8fd7d2b7f28d53ed7368cc4b1dfc5814c70c486c533862ee05e37dc", "03a48773670b53e7d139182e1be70b8b3deeb38298af1950f7f9e9061a78156032" }, + {"phba2061_EU", "02eaa599f5434039adc5748b3b830f605342e11b51273046b04f24acc5bcecc74a", "03f1bc7f22f3895069ba11442f8868211dd5953105dd6a65862775c8f033535f32" }, + {"indenodes_AR", "02ec0fa5a40f47fd4a38ea5c89e375ad0b6ddf4807c99733c9c3dc15fb978ee147", "0242778789986d614f75bcf629081651b851a12ab1cc10c73995b27b90febb75a2" }, + {"and1-89_EU", "02f2af778c62888cfb106c0ef5c89cefe012ef3e6abed3ef28425092637d7ae3cc", "02bca5e635c2d1c3506510c3c662e317636e41495688fa8f37cff42737fe048565" }, + {"komodopioneers_SH", "02ffde73d51b56bf9e23b6f03008ac7916cacd3be090f44eab59877792e08b6751", "02805ef7a915c90d0719d83f1287b9509c481be735d019df212b71002a21bb860f" }, + {"komodopioneers_EU", "03014f3fceb9f851f9dba5f5b371c7758b3f1fe44a70b4e60e3d6c70d1e5265358", "0222a74c839d67346250b953a790abcb3d92cb5187f1c25f02d193f8d10d04ed64" }, + {"d0ct0r_NA", "0303725d8525b6f969122faf04152653eb4bf34e10de92182263321769c334bf58", "0235b211469d7c1881d30ab647e0d6ddb4daf9466f60e85e6a33a92e39dedde3a7" }, + {"kolo_DEV", "030f34af4b908fb8eb2099accb56b8d157d49f6cfb691baa80fdd34f385efed961", "0292cec4c966787ebd436bc2af6fc375a8292b6d368385ce717f27fac64c1a9ed4" }, + {"peer2cloud_AR", "030fe3c77db0f91d79c26f951b674bba557b899f16570cd75332829a07031b0097", "03e63fbeff5db594b6903128b38630abc1b89bb1995ef76d0f5f5b7f88f473df78" }, // 40 + {"webworker01_SH", "031e50ba6de3c16f99d414bb89866e578d963a54bde7916c810608966fb5700776", "0221365d89a6f6373b15daa4a50d56d34ad1b4b8a48a7fd090163b6b5a5ecd7a0a" }, + {"webworker01_NA", "032735e9cad1bb00eaababfa6d27864fa4c1db0300c85e01e52176be2ca6a243ce", "03bfc36a60194b495c075b89995f307bec68c1bcbe381b6b29db47af23494430f9" }, + {"pbca26_NA", "0331c51abb78a9891d1b9483747a7fd9bbbbdd5256f40af23c87384e3d9a974289", "0371bf57314b24a0e4dfc31e8df83fb76231173912d962172600a5c395d59312f3" }, + {"indenodes_SH", "0334e6e1ec8285c4b85bd6dae67e17d67d1f20e7328efad17ce6fd24ae97cdd65e", "031d1584cf0eb4a2d314465e49e2677226b1615c3718013b8d6b4854c15676a58c" }, + {"pirate_NA", "033c8cef71f704f357c9ac1aeaafde3acd7bbfd0a09494e5e129ee0999fb2bc368", "035f1d94fd43ce3bf334c493cab29ab0635f75704650aaadb1d476a2bb3d74f34f" }, + {"lukechilds_AR", "035004d780316008c8afd5ac28d08aae56f4746bf70eb2c999e3c7d9a7a50ca8b6", "02b1a3fb6e47f566f96efc4dcd450abe370692806dff9090c24733c46728e9a342" }, + {"dragonhound_NA", "0354c779b9b111fdc825ee0250b33a79a837e0775a111a89916853d02a8999285c", "03c0d07f0b9932d5db003fe047e328f2bfd61fc24e19db79ef9471efd10ea4c102" }, + {"fullmoon_AR", "035673e913d603137f7f517d88bf316e51d408e0ec2b2cdcbfbdd5c0b553fc9351", "022e316df71f51f2bda83318aaeaebe7a12514429e85ba4f5402b1478c6d7873a4" }, + {"chainzilla_SH", "0360804b8817fd25ded6e9c0b50e3b0782ac666545b5416644198e18bc3903d9f9", "03fe36ff13cb224217898682ce8b87ba6e3cdd4a98941bb7060c04508b57a6b014" }, + {"titomane_EU", "03772ac0aad6b0e9feec5e591bff5de6775d6132e888633e73d3ba896bdd8e0afb", "03d691cd0914a711f651082e2b7b27bee778c1309a38840e40a6cf650682d17bb5" }, // 50 + {"jeezy_EU", "037f182facbad35684a6e960699f5da4ba89e99f0d0d62a87e8400dd086c8e5dd7", "022bca828b572cb2b3daff713ed2eb0bbc7378df20f799191eebecf3ef319509cd" }, + {"titomane_SH", "03850fdddf2413b51790daf51dd30823addb37313c8854b508ea6228205047ef9b", "038c2a64f7647633c0e74eec93f9a668d4bf80214a43ed7cd08e4e30d3f2f7acfb" }, + {"alien_AR", "03911a60395801082194b6834244fa78a3c30ff3e888667498e157b4aa80b0a65f", "024f20c096b085308e21893383f44b4faf1cdedea9ad53cc7d7e7fbfa0c30c1e71" }, + {"pirate_EU", "03986339bebe3891e369a528356a220bc17a5bef3d337edfcf0114e66e6b1c120f", "0377d4ed0264ad80fea05b3cd68cb1700404c0c08981830ba8ffae56b944e2ee77" }, + {"thegaltmines_NA", "03b113c7aa1042c965154bf791713f562891ac75e60ab78886205535bcaabb5013", "022138be032da85227fde7d1d5cc665ea21ba3f149601e8c23db269750991bc0c3" }, + {"computergenie_NA", "03b41c764c8cd63b48b79f15f112a9b5105a0dce35df7d6990d6919503a1f3f245", "02e01fe2bc6fd6eeeda6e84fdd67647b94058ee4ffd090d3ac67fd546f8bced39a" }, + {"nutellalicka_SH", "03b422ec85a8465ae42e7004bc6d0856a458f0f920ec0f58fd4d5613994f3faa5b", "03c8220bb835791b875f4060ff2d40c2dcc9346cc3390c04f5e202d207a1980b59" }, + {"chainstrike_SH", "03b806be3bf7a1f2f6290ec5c1ea7d3ea57774dcfcf2129a82b2569e585100e1cb", "0221f9dee04b7da1f3833c6ea7f7325652c951b1c239052b0dadb57209084ca6a8" }, + {"dwy_SH", "03b9162f9713d7cddd89aaad0398b67f66377cc17547ec0643a67c2d6fb099ecf0", "02f221458f84a3cf918cae6ec7fe553eff20bbed9fc4289e75af69b69478ccf0a4" }, // 60 + {"alien_EU", "03bb749e337b9074465fa28e757b5aa92cb1f0fea1a39589bca91a602834d443cd", "022b85908191788f409506ebcf96a892f3274f352864c3ed566c5a16de63953236" }, + {"gt_AR", "03e22a6aad65c9a4c2ce2e724b26edf631b5f41253449dd5feaeba68e7c0cf3058", "038b4f509468bfe51937bdce3f4529702d806b0e8fd4f7c487235d06d9c1b411ef" }, + {"patchkez_SH", "03f45e9beb5c4cd46525db8195eb05c1db84ae7ef3603566b3d775770eba3b96ee", "03d7c187689bf829ca076a30bbf36d2e67bb74e16a3290d8a55df21d6cb15c80c1" }, + {"decker_AR", "03ffdf1a116300a78729608d9930742cd349f11a9d64fcc336b8f18592dd9c91bc", "02a85540db8d41c7e60bf0d33d1364b4151cad883dd032878ea4c037f67b769635" }, + }, { {"webworker01_NA", "03bb7d005e052779b1586f071834c5facbb83470094cff5112f0072b64989f97d7" } } From c62ddda360ab44527702d7029212e574fe0ffea4 Mon Sep 17 00:00:00 2001 From: Mihail Fedorov Date: Mon, 3 Jun 2019 17:36:28 +0300 Subject: [PATCH 442/447] Notaries 2019 --- src/komodo_defs.h | 131 ++++++++++++++++++++++------------------------ 1 file changed, 64 insertions(+), 67 deletions(-) diff --git a/src/komodo_defs.h b/src/komodo_defs.h index 656c20c53..b3e4d7ad2 100644 --- a/src/komodo_defs.h +++ b/src/komodo_defs.h @@ -179,73 +179,70 @@ static const char *notaries_elected[NUM_KMD_SEASONS][NUM_KMD_NOTARIES][2] = {"xrobesx_NA", "03f0cc6d142d14a40937f12dbd99dbd9021328f45759e26f1877f2a838876709e1" }, }, { - {"madmax_NA", "02016371f90f195ed9aeaf37be06f3fbbfbfe2ef8a4fd66378378289476e7751db", "03489b67faabdf450c9661ca386ba8a65eca859f39b3ec4c7a6be40c9c7bf153b7" }, - {"alright_AR", "020566fe2fb3874258b2d3cf1809a5d650e0edc7ba746fa5eec72750c5188c9cc9", "036a6bca1c2a8166f79fa8a979662892742346cc972b432f8e61950a358d705517" }, - {"strob_NA", "0206f7a2e972d9dfef1c424c731503a0a27de1ba7a15a91a362dc7ec0d0fb47685", "02049202f3872877e81035549f6f3a0f868d0ad1c9b0e0d2b48b1f30324255d26d" }, - {"dwy_EU", "020a77f454a1d3fcdc0312048fc58d713fe6153189e0c59cdd12fedbf09553d4b0", "021a7e11182f3603720436daea4e9a2ad5a9990943f0c96d6bcb5d7823040317fa" }, - {"phm87_SH", "021773a38db1bc3ede7f28142f901a161c7b7737875edbb40082a201c55dcf0add", "03889a10f9df2caef57220628515693cf25316fe1b0693b0241419e75d0d0e66ed" }, - {"chainmakers_NA", "021ad488cc063e17d0f1a2aade6be65ef8b5ff879987cb0b86bb700733099fe524", "0369aa258f317f028afd3acbe74658c4b483b7e0069107c5885ac49128dd18a13d" }, - {"indenodes_EU", "0221387ff95c44cb52b86552e3ec118a3c311ca65b75bf807c6c07eaeb1be8303c", "03a416533cace0814455a1bb1cd7861ce825a543c6f6284a432c4c8d8875b7ace9" }, - {"blackjok3r_SH", "0226293d7644e1380555ecc2d385ba038a66f4202b24b643ab31bcad0dc1474de2", "03c90bee400010904acb42464807feb0039ab42cc86d5401222299280b876b52e3" }, - {"chainmakers_EU", "022a6b583e8820d14d911a11820fd80853c5b8406e91a0a6fcac1f133d098d75cb", "034a6ae969bbd13258f9b7d3bbbdb81c93f2914d3fdb01ce31ad1d2a9078ef5fcd" }, - {"titomane_AR", "023e3aa9834c46971ff3e7cb86a200ec9c8074a9566a3ea85d400d5739662ee989", "0358cd6d7460654a0ddd5125dd6fa0402d0719999444c6cc3888689a0b4446136a" }, - {"fullmoon_SH", "02639998420688ee935d279d1cd52f1c6f3ae12c1f3afc20b3bf7ece1057f8b93b", "0370f07837cfefe1542f030b80e8fffa57218f4b7fff2dd181b0e21700c5480a7b" }, // 10 - {"indenodes_NA", "02698c6f1c9e43b66e82dbb163e8df0e5a2f62f3a7a882ca387d82f86e0b3fa988", "02b3908eda4078f0e9b6704451cdc24d418e899c0f515fab338d7494da6f0a647b" }, - {"chmex_EU", "0281304ebbcc39e4f09fda85f4232dd8dacd668e20e5fc11fba6b985186c90086e", "03e5b7ab96b7271ecd585d6f22807fa87da374210a843ec3a90134cbf4a62c3db1" }, - {"metaphilibert_SH", "0284af1a5ef01503e6316a2ca4abf8423a794e9fc17ac6846f042b6f4adedc3309", "03b21ff042bf1730b28bde43f44c064578b41996117ac7634b567c3773089e3be3" }, - {"ca333_DEV", "02856843af2d9457b5b1c907068bef6077ea0904cc8bd4df1ced013f64bf267958", "029c0342ce2a4f9146c7d1ee012b26f5c2df78b507fb4461bf48df71b4e3031b56" }, - {"cipi_NA", "02858904a2a1a0b44df4c937b65ee1f5b66186ab87a751858cf270dee1d5031f18", "034406ac4cf94e84561c5d3f25384dd59145e92fefc5972a037dc6a44bfa286688" }, - {"pungocloud_SH", "02863628f842a8aa424daf745cf43a1717cfcd571338ba87bfcec4d340703d01d6", "03f42c8052decf9a9d2eba60b1c8cd8b2b8e858d6b1ef0e5f09ba8a9ac1b1ced62" }, - {"voskcoin_EU", "028cfb0bbce2207425bc8d40fff634269bb61aade2d1d03883398275550b465600", "037135718fa54e59bcb71f9f9e9c4ab43daa86be50dbaadce10bc176a4f611d546" }, - {"decker_DEV", "028eea44a09674dda00d88ffd199a09c9b75ba9782382cc8f1e97c0fd565fe5707", "02fca8ee50e49f480de275745618db7b0b3680b0bdcce7dcae7d2e0fd5c3345744" }, - {"cryptoeconomy_EU", "0290ab4937e85246e048552df3e9a66cba2c1602db76e03763e16c671e750145d1", "037d04b7d16de61a44a3fc766bea4b7791023a36675d6cee862fe53defd04dd8f2" }, - {"etszombi_EU", "0293ea48d8841af7a419a24d9da11c34b39127ef041f847651bae6ab14dcd1f6b4", "02f65da26061d1b9f1756a274918a37e83086dbfe9a43d2f0b35b9d2f593b31907" }, // 20 - {"karasugoi_NA", "02a348b03b9c1a8eac1b56f85c402b041c9bce918833f2ea16d13452309052a982", "024ba10f7f5325fd6ec6cab50c5242d142d00fab3537c0002097c0e98f72014177" }, - {"pirate_AR", "02a5e865af771eee0c6bd3bd238f01f5eb589907ba52efa9f37e5102375c8eb7a0", "0228431427395f0cefdb0d10402d0d726119508945eb66ca9c0bba5d64df79832c" }, - {"metaphilibert_AR", "02adad675fae12b25fdd0f57250b0caf7f795c43f346153a31fe3e72e7db1d6ac6", "0239e34ad22957bbf4c8df824401f237b2afe8d40f7a645ecd43e8f27dde1ab0da" }, - {"zatjum_SH", "02b315714f99fdd70bafd50a4c3aa4b9db0fd8d63978bd8d47763773400b28734c", "031675aae243d2e4f3e8b67dbc4a68f50f487a37df959d739b26a80ce917b10d84" }, - {"madmax_AR", "02b37913ac0250d17cca5bb94ef65928b1515f13f839075446db73b9b067c13aa0", "032f5fc01607c2e82417cfe822b981116262961c0a66f715fbb7e84614aadfe5df" }, - {"lukechilds_NA", "02c191a085bbb0bd86d126c62d3e801c503038b69c0c2de121c9a7abe3e6684420", "03dbda3ea207b1aca24803fa53f990402b0bea9ec6bdc4486d9878add7623faf35" }, - {"cipi_AR", "02c4f89a5b382750836cb787880d30e23502265054e1c327a5bfce67116d757ce8", "025b7655826f5fd3a807cbb4918ef9f02fe64661153ca170db981e9b0861f8c5ad" }, - {"tonyl_AR", "02cc8bc862f2b65ad4f99d5f68d3011c138bf517acdc8d4261166b0be8f64189e1", "03a8db38075c80348889871b4318b0a79a1fd7e9e21daefb4ca6e4f05e5963569c" }, - {"infotech_DEV", "02d7d63ac441dbcd5535bcad741701519c190e89e17e4180aa0f61fdda0b6195ea", "032a8265e3c5029d17bbb5a46da81aedd81dad74c152a21568ef082d3d497dcada" }, - {"fullmoon_NA", "02da228a67e519b21bca6426ed982509a21d24d45f1ac1bdf698b6083fed442ec3", "0291038301dea2ec683a3f686579dcebe37b2113cc6137ef0bfe87b505bcd16016" }, // 30 - {"etszombi_AR", "02e55e104aa94f70cde68165d7df3e162d4410c76afd4643b161dea044aa6d06ce", "03c786702b81e0122157739c8e2377cf945998d36c0d187ec5c5ff95855848dfdd" }, - {"node-9_EU", "02e90f0528f8fd7d2b7f28d53ed7368cc4b1dfc5814c70c486c533862ee05e37dc", "03a48773670b53e7d139182e1be70b8b3deeb38298af1950f7f9e9061a78156032" }, - {"phba2061_EU", "02eaa599f5434039adc5748b3b830f605342e11b51273046b04f24acc5bcecc74a", "03f1bc7f22f3895069ba11442f8868211dd5953105dd6a65862775c8f033535f32" }, - {"indenodes_AR", "02ec0fa5a40f47fd4a38ea5c89e375ad0b6ddf4807c99733c9c3dc15fb978ee147", "0242778789986d614f75bcf629081651b851a12ab1cc10c73995b27b90febb75a2" }, - {"and1-89_EU", "02f2af778c62888cfb106c0ef5c89cefe012ef3e6abed3ef28425092637d7ae3cc", "02bca5e635c2d1c3506510c3c662e317636e41495688fa8f37cff42737fe048565" }, - {"komodopioneers_SH", "02ffde73d51b56bf9e23b6f03008ac7916cacd3be090f44eab59877792e08b6751", "02805ef7a915c90d0719d83f1287b9509c481be735d019df212b71002a21bb860f" }, - {"komodopioneers_EU", "03014f3fceb9f851f9dba5f5b371c7758b3f1fe44a70b4e60e3d6c70d1e5265358", "0222a74c839d67346250b953a790abcb3d92cb5187f1c25f02d193f8d10d04ed64" }, - {"d0ct0r_NA", "0303725d8525b6f969122faf04152653eb4bf34e10de92182263321769c334bf58", "0235b211469d7c1881d30ab647e0d6ddb4daf9466f60e85e6a33a92e39dedde3a7" }, - {"kolo_DEV", "030f34af4b908fb8eb2099accb56b8d157d49f6cfb691baa80fdd34f385efed961", "0292cec4c966787ebd436bc2af6fc375a8292b6d368385ce717f27fac64c1a9ed4" }, - {"peer2cloud_AR", "030fe3c77db0f91d79c26f951b674bba557b899f16570cd75332829a07031b0097", "03e63fbeff5db594b6903128b38630abc1b89bb1995ef76d0f5f5b7f88f473df78" }, // 40 - {"webworker01_SH", "031e50ba6de3c16f99d414bb89866e578d963a54bde7916c810608966fb5700776", "0221365d89a6f6373b15daa4a50d56d34ad1b4b8a48a7fd090163b6b5a5ecd7a0a" }, - {"webworker01_NA", "032735e9cad1bb00eaababfa6d27864fa4c1db0300c85e01e52176be2ca6a243ce", "03bfc36a60194b495c075b89995f307bec68c1bcbe381b6b29db47af23494430f9" }, - {"pbca26_NA", "0331c51abb78a9891d1b9483747a7fd9bbbbdd5256f40af23c87384e3d9a974289", "0371bf57314b24a0e4dfc31e8df83fb76231173912d962172600a5c395d59312f3" }, - {"indenodes_SH", "0334e6e1ec8285c4b85bd6dae67e17d67d1f20e7328efad17ce6fd24ae97cdd65e", "031d1584cf0eb4a2d314465e49e2677226b1615c3718013b8d6b4854c15676a58c" }, - {"pirate_NA", "033c8cef71f704f357c9ac1aeaafde3acd7bbfd0a09494e5e129ee0999fb2bc368", "035f1d94fd43ce3bf334c493cab29ab0635f75704650aaadb1d476a2bb3d74f34f" }, - {"lukechilds_AR", "035004d780316008c8afd5ac28d08aae56f4746bf70eb2c999e3c7d9a7a50ca8b6", "02b1a3fb6e47f566f96efc4dcd450abe370692806dff9090c24733c46728e9a342" }, - {"dragonhound_NA", "0354c779b9b111fdc825ee0250b33a79a837e0775a111a89916853d02a8999285c", "03c0d07f0b9932d5db003fe047e328f2bfd61fc24e19db79ef9471efd10ea4c102" }, - {"fullmoon_AR", "035673e913d603137f7f517d88bf316e51d408e0ec2b2cdcbfbdd5c0b553fc9351", "022e316df71f51f2bda83318aaeaebe7a12514429e85ba4f5402b1478c6d7873a4" }, - {"chainzilla_SH", "0360804b8817fd25ded6e9c0b50e3b0782ac666545b5416644198e18bc3903d9f9", "03fe36ff13cb224217898682ce8b87ba6e3cdd4a98941bb7060c04508b57a6b014" }, - {"titomane_EU", "03772ac0aad6b0e9feec5e591bff5de6775d6132e888633e73d3ba896bdd8e0afb", "03d691cd0914a711f651082e2b7b27bee778c1309a38840e40a6cf650682d17bb5" }, // 50 - {"jeezy_EU", "037f182facbad35684a6e960699f5da4ba89e99f0d0d62a87e8400dd086c8e5dd7", "022bca828b572cb2b3daff713ed2eb0bbc7378df20f799191eebecf3ef319509cd" }, - {"titomane_SH", "03850fdddf2413b51790daf51dd30823addb37313c8854b508ea6228205047ef9b", "038c2a64f7647633c0e74eec93f9a668d4bf80214a43ed7cd08e4e30d3f2f7acfb" }, - {"alien_AR", "03911a60395801082194b6834244fa78a3c30ff3e888667498e157b4aa80b0a65f", "024f20c096b085308e21893383f44b4faf1cdedea9ad53cc7d7e7fbfa0c30c1e71" }, - {"pirate_EU", "03986339bebe3891e369a528356a220bc17a5bef3d337edfcf0114e66e6b1c120f", "0377d4ed0264ad80fea05b3cd68cb1700404c0c08981830ba8ffae56b944e2ee77" }, - {"thegaltmines_NA", "03b113c7aa1042c965154bf791713f562891ac75e60ab78886205535bcaabb5013", "022138be032da85227fde7d1d5cc665ea21ba3f149601e8c23db269750991bc0c3" }, - {"computergenie_NA", "03b41c764c8cd63b48b79f15f112a9b5105a0dce35df7d6990d6919503a1f3f245", "02e01fe2bc6fd6eeeda6e84fdd67647b94058ee4ffd090d3ac67fd546f8bced39a" }, - {"nutellalicka_SH", "03b422ec85a8465ae42e7004bc6d0856a458f0f920ec0f58fd4d5613994f3faa5b", "03c8220bb835791b875f4060ff2d40c2dcc9346cc3390c04f5e202d207a1980b59" }, - {"chainstrike_SH", "03b806be3bf7a1f2f6290ec5c1ea7d3ea57774dcfcf2129a82b2569e585100e1cb", "0221f9dee04b7da1f3833c6ea7f7325652c951b1c239052b0dadb57209084ca6a8" }, - {"dwy_SH", "03b9162f9713d7cddd89aaad0398b67f66377cc17547ec0643a67c2d6fb099ecf0", "02f221458f84a3cf918cae6ec7fe553eff20bbed9fc4289e75af69b69478ccf0a4" }, // 60 - {"alien_EU", "03bb749e337b9074465fa28e757b5aa92cb1f0fea1a39589bca91a602834d443cd", "022b85908191788f409506ebcf96a892f3274f352864c3ed566c5a16de63953236" }, - {"gt_AR", "03e22a6aad65c9a4c2ce2e724b26edf631b5f41253449dd5feaeba68e7c0cf3058", "038b4f509468bfe51937bdce3f4529702d806b0e8fd4f7c487235d06d9c1b411ef" }, - {"patchkez_SH", "03f45e9beb5c4cd46525db8195eb05c1db84ae7ef3603566b3d775770eba3b96ee", "03d7c187689bf829ca076a30bbf36d2e67bb74e16a3290d8a55df21d6cb15c80c1" }, - {"decker_AR", "03ffdf1a116300a78729608d9930742cd349f11a9d64fcc336b8f18592dd9c91bc", "02a85540db8d41c7e60bf0d33d1364b4151cad883dd032878ea4c037f67b769635" }, - }, - { - {"webworker01_NA", "03bb7d005e052779b1586f071834c5facbb83470094cff5112f0072b64989f97d7" } + {"madmax_NA", "02016371f90f195ed9aeaf37be06f3fbbfbfe2ef8a4fd66378378289476e7751db" }, + {"alright_AR", "020566fe2fb3874258b2d3cf1809a5d650e0edc7ba746fa5eec72750c5188c9cc9" }, + {"strob_NA", "0206f7a2e972d9dfef1c424c731503a0a27de1ba7a15a91a362dc7ec0d0fb47685" }, + {"dwy_EU", "020a77f454a1d3fcdc0312048fc58d713fe6153189e0c59cdd12fedbf09553d4b0" }, + {"phm87_SH", "021773a38db1bc3ede7f28142f901a161c7b7737875edbb40082a201c55dcf0add" }, + {"chainmakers_NA", "021ad488cc063e17d0f1a2aade6be65ef8b5ff879987cb0b86bb700733099fe524" }, + {"indenodes_EU", "0221387ff95c44cb52b86552e3ec118a3c311ca65b75bf807c6c07eaeb1be8303c" }, + {"blackjok3r_SH", "0226293d7644e1380555ecc2d385ba038a66f4202b24b643ab31bcad0dc1474de2" }, + {"chainmakers_EU", "022a6b583e8820d14d911a11820fd80853c5b8406e91a0a6fcac1f133d098d75cb" }, + {"titomane_AR", "023e3aa9834c46971ff3e7cb86a200ec9c8074a9566a3ea85d400d5739662ee989" }, + {"fullmoon_SH", "02639998420688ee935d279d1cd52f1c6f3ae12c1f3afc20b3bf7ece1057f8b93b" }, // 10 + {"indenodes_NA", "02698c6f1c9e43b66e82dbb163e8df0e5a2f62f3a7a882ca387d82f86e0b3fa988" }, + {"chmex_EU", "0281304ebbcc39e4f09fda85f4232dd8dacd668e20e5fc11fba6b985186c90086e" }, + {"metaphilibert_SH", "0284af1a5ef01503e6316a2ca4abf8423a794e9fc17ac6846f042b6f4adedc3309" }, + {"ca333_DEV", "02856843af2d9457b5b1c907068bef6077ea0904cc8bd4df1ced013f64bf267958" }, + {"cipi_NA", "02858904a2a1a0b44df4c937b65ee1f5b66186ab87a751858cf270dee1d5031f18" }, + {"pungocloud_SH", "02863628f842a8aa424daf745cf43a1717cfcd571338ba87bfcec4d340703d01d6" }, + {"voskcoin_EU", "028cfb0bbce2207425bc8d40fff634269bb61aade2d1d03883398275550b465600" }, + {"decker_DEV", "028eea44a09674dda00d88ffd199a09c9b75ba9782382cc8f1e97c0fd565fe5707" }, + {"cryptoeconomy_EU", "0290ab4937e85246e048552df3e9a66cba2c1602db76e03763e16c671e750145d1" }, + {"etszombi_EU", "0293ea48d8841af7a419a24d9da11c34b39127ef041f847651bae6ab14dcd1f6b4" }, // 20 + {"karasugoi_NA", "02a348b03b9c1a8eac1b56f85c402b041c9bce918833f2ea16d13452309052a982" }, + {"pirate_AR", "02a5e865af771eee0c6bd3bd238f01f5eb589907ba52efa9f37e5102375c8eb7a0" }, + {"metaphilibert_AR", "02adad675fae12b25fdd0f57250b0caf7f795c43f346153a31fe3e72e7db1d6ac6" }, + {"zatjum_SH", "02b315714f99fdd70bafd50a4c3aa4b9db0fd8d63978bd8d47763773400b28734c" }, + {"madmax_AR", "02b37913ac0250d17cca5bb94ef65928b1515f13f839075446db73b9b067c13aa0" }, + {"lukechilds_NA", "02c191a085bbb0bd86d126c62d3e801c503038b69c0c2de121c9a7abe3e6684420" }, + {"cipi_AR", "02c4f89a5b382750836cb787880d30e23502265054e1c327a5bfce67116d757ce8" }, + {"tonyl_AR", "02cc8bc862f2b65ad4f99d5f68d3011c138bf517acdc8d4261166b0be8f64189e1" }, + {"infotech_DEV", "02d7d63ac441dbcd5535bcad741701519c190e89e17e4180aa0f61fdda0b6195ea" }, + {"fullmoon_NA", "02da228a67e519b21bca6426ed982509a21d24d45f1ac1bdf698b6083fed442ec3" }, // 30 + {"etszombi_AR", "02e55e104aa94f70cde68165d7df3e162d4410c76afd4643b161dea044aa6d06ce" }, + {"node-9_EU", "02e90f0528f8fd7d2b7f28d53ed7368cc4b1dfc5814c70c486c533862ee05e37dc" }, + {"phba2061_EU", "02eaa599f5434039adc5748b3b830f605342e11b51273046b04f24acc5bcecc74a" }, + {"indenodes_AR", "02ec0fa5a40f47fd4a38ea5c89e375ad0b6ddf4807c99733c9c3dc15fb978ee147" }, + {"and1-89_EU", "02f2af778c62888cfb106c0ef5c89cefe012ef3e6abed3ef28425092637d7ae3cc" }, + {"komodopioneers_SH", "02ffde73d51b56bf9e23b6f03008ac7916cacd3be090f44eab59877792e08b6751" }, + {"komodopioneers_EU", "03014f3fceb9f851f9dba5f5b371c7758b3f1fe44a70b4e60e3d6c70d1e5265358" }, + {"d0ct0r_NA", "0303725d8525b6f969122faf04152653eb4bf34e10de92182263321769c334bf58" }, + {"kolo_DEV", "030f34af4b908fb8eb2099accb56b8d157d49f6cfb691baa80fdd34f385efed961" }, + {"peer2cloud_AR", "030fe3c77db0f91d79c26f951b674bba557b899f16570cd75332829a07031b0097" }, // 40 + {"webworker01_SH", "031e50ba6de3c16f99d414bb89866e578d963a54bde7916c810608966fb5700776" }, + {"webworker01_NA", "032735e9cad1bb00eaababfa6d27864fa4c1db0300c85e01e52176be2ca6a243ce" }, + {"pbca26_NA", "0331c51abb78a9891d1b9483747a7fd9bbbbdd5256f40af23c87384e3d9a974289" }, + {"indenodes_SH", "0334e6e1ec8285c4b85bd6dae67e17d67d1f20e7328efad17ce6fd24ae97cdd65e" }, + {"pirate_NA", "033c8cef71f704f357c9ac1aeaafde3acd7bbfd0a09494e5e129ee0999fb2bc368" }, + {"lukechilds_AR", "035004d780316008c8afd5ac28d08aae56f4746bf70eb2c999e3c7d9a7a50ca8b6" }, + {"dragonhound_NA", "0354c779b9b111fdc825ee0250b33a79a837e0775a111a89916853d02a8999285c" }, + {"fullmoon_AR", "035673e913d603137f7f517d88bf316e51d408e0ec2b2cdcbfbdd5c0b553fc9351" }, + {"chainzilla_SH", "0360804b8817fd25ded6e9c0b50e3b0782ac666545b5416644198e18bc3903d9f9" }, + {"titomane_EU", "03772ac0aad6b0e9feec5e591bff5de6775d6132e888633e73d3ba896bdd8e0afb" }, // 50 + {"jeezy_EU", "037f182facbad35684a6e960699f5da4ba89e99f0d0d62a87e8400dd086c8e5dd7" }, + {"titomane_SH", "03850fdddf2413b51790daf51dd30823addb37313c8854b508ea6228205047ef9b" }, + {"alien_AR", "03911a60395801082194b6834244fa78a3c30ff3e888667498e157b4aa80b0a65f" }, + {"pirate_EU", "03986339bebe3891e369a528356a220bc17a5bef3d337edfcf0114e66e6b1c120f" }, + {"thegaltmines_NA", "03b113c7aa1042c965154bf791713f562891ac75e60ab78886205535bcaabb5013" }, + {"computergenie_NA", "03b41c764c8cd63b48b79f15f112a9b5105a0dce35df7d6990d6919503a1f3f245" }, + {"nutellalicka_SH", "03b422ec85a8465ae42e7004bc6d0856a458f0f920ec0f58fd4d5613994f3faa5b" }, + {"chainstrike_SH", "03b806be3bf7a1f2f6290ec5c1ea7d3ea57774dcfcf2129a82b2569e585100e1cb" }, + {"dwy_SH", "03b9162f9713d7cddd89aaad0398b67f66377cc17547ec0643a67c2d6fb099ecf0" }, // 60 + {"alien_EU", "03bb749e337b9074465fa28e757b5aa92cb1f0fea1a39589bca91a602834d443cd" }, + {"gt_AR", "03e22a6aad65c9a4c2ce2e724b26edf631b5f41253449dd5feaeba68e7c0cf3058" }, + {"patchkez_SH", "03f45e9beb5c4cd46525db8195eb05c1db84ae7ef3603566b3d775770eba3b96ee" }, + {"decker_AR", "03ffdf1a116300a78729608d9930742cd349f11a9d64fcc336b8f18592dd9c91bc" }, } }; From b29c95a26d1a6b9ec9caf551e5e3ab8d85ebf577 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Tue, 4 Jun 2019 11:53:38 +0800 Subject: [PATCH 443/447] fix PIRATE forced rescan. --- src/wallet/walletdb.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/wallet/walletdb.cpp b/src/wallet/walletdb.cpp index e81eba03d..bed635d3b 100644 --- a/src/wallet/walletdb.cpp +++ b/src/wallet/walletdb.cpp @@ -488,7 +488,8 @@ ReadKeyValue(CWallet* pwallet, CDataStream& ssKey, CDataStream& ssValue, auto verifier = libzcash::ProofVerifier::Strict(); // ac_public chains set at height like KMD and ZEX, will force a rescan if we dont ignore this error: bad-txns-acpublic-chain // there cannot be any ztx in the wallet on ac_public chains that started from block 1, so this wont affect those. - if ( !(CheckTransaction(0,wtx, state, verifier) && (wtx.GetHash() == hash) && state.IsValid()) && (state.GetRejectReason() != "bad-txns-acpublic-chain") ) + // PIRATE fails this check for notary nodes, need exception. Triggers full rescan without it. + if ( !(CheckTransaction(0,wtx, state, verifier) && (wtx.GetHash() == hash) && state.IsValid()) && (state.GetRejectReason() != "bad-txns-acpublic-chain" || state.GetRejectReason() != "bad-txns-acprivacy-chain") ) { //fprintf(stderr, "tx failed: %s rejectreason.%s\n", wtx.GetHash().GetHex().c_str(), state.GetRejectReason().c_str()); // vin-empty on staking chains is error relating to a failed staking tx, that for some unknown reason did not fully erase. save them here to erase and re-add later on. From 86926e33f0ec9f66b4e7811d78af28d22a51c7f9 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Tue, 4 Jun 2019 13:34:50 +0800 Subject: [PATCH 444/447] fix uint --- src/komodo_notary.h | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/komodo_notary.h b/src/komodo_notary.h index e2c7dfb4c..028bc4dc2 100644 --- a/src/komodo_notary.h +++ b/src/komodo_notary.h @@ -65,7 +65,6 @@ const char *Notaries_genesis[][2] = int32_t getkmdseason(int32_t height) { - int8_t season = 0; if ( height <= KMD_SEASON_HEIGHTS[0] ) return(1); for (int32_t i = 1; i < NUM_KMD_SEASONS; i++) @@ -76,9 +75,8 @@ int32_t getkmdseason(int32_t height) return(0); }; -int32_t getacseason(int32_t timestamp) +int32_t getacseason(uint32_t timestamp) { - int8_t season = 0; if ( timestamp <= KMD_SEASON_TIMESTAMPS[0] ) return(1); for (int32_t i = 1; i < NUM_KMD_SEASONS; i++) From 17dd062feebb409589c4ec2716281367ad7772b9 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Tue, 4 Jun 2019 14:10:15 +0800 Subject: [PATCH 445/447] woops --- src/wallet/walletdb.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wallet/walletdb.cpp b/src/wallet/walletdb.cpp index bed635d3b..d2d90a85f 100644 --- a/src/wallet/walletdb.cpp +++ b/src/wallet/walletdb.cpp @@ -489,7 +489,7 @@ ReadKeyValue(CWallet* pwallet, CDataStream& ssKey, CDataStream& ssValue, // ac_public chains set at height like KMD and ZEX, will force a rescan if we dont ignore this error: bad-txns-acpublic-chain // there cannot be any ztx in the wallet on ac_public chains that started from block 1, so this wont affect those. // PIRATE fails this check for notary nodes, need exception. Triggers full rescan without it. - if ( !(CheckTransaction(0,wtx, state, verifier) && (wtx.GetHash() == hash) && state.IsValid()) && (state.GetRejectReason() != "bad-txns-acpublic-chain" || state.GetRejectReason() != "bad-txns-acprivacy-chain") ) + if ( !(CheckTransaction(0,wtx, state, verifier) && (wtx.GetHash() == hash) && state.IsValid()) && (state.GetRejectReason() != "bad-txns-acpublic-chain" && state.GetRejectReason() != "bad-txns-acprivacy-chain") ) { //fprintf(stderr, "tx failed: %s rejectreason.%s\n", wtx.GetHash().GetHex().c_str(), state.GetRejectReason().c_str()); // vin-empty on staking chains is error relating to a failed staking tx, that for some unknown reason did not fully erase. save them here to erase and re-add later on. From ee3aef50668054683f5f50040ecd463b6ec19e2d Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 3 Jun 2019 21:10:49 -1100 Subject: [PATCH 446/447] Define getacseason --- src/komodo_defs.h | 1 + src/komodo_utils.h | 1 - src/main.cpp | 2 -- 3 files changed, 1 insertion(+), 3 deletions(-) diff --git a/src/komodo_defs.h b/src/komodo_defs.h index b3e4d7ad2..c6d4dd30b 100644 --- a/src/komodo_defs.h +++ b/src/komodo_defs.h @@ -304,6 +304,7 @@ extern int32_t ASSETCHAINS_EARLYTXIDCONTRACT; int tx_height( const uint256 &hash ); extern std::vector vWhiteListAddress; void komodo_netevent(std::vector payload); +int32_t getacseason(uint32_t timestamp); #define IGUANA_MAXSCRIPTSIZE 10001 #define KOMODO_KVDURATION 1440 diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 11cbea808..48c29ea6f 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1665,7 +1665,6 @@ uint64_t komodo_ac_block_subsidy(int nHeight) extern int64_t MAX_MONEY; void komodo_cbopretupdate(int32_t forceflag); -int32_t getacseason(int32_t timestamp); void SplitStr(const std::string& strVal, std::vector &outVals); int8_t equihash_params_possible(uint64_t n, uint64_t k) diff --git a/src/main.cpp b/src/main.cpp index a8ae8b60c..9f837a016 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1373,8 +1373,6 @@ bool CheckTransaction(uint32_t tiptime,const CTransaction& tx, CValidationState } } -extern int32_t getacseason(int32_t timestamp); - int32_t komodo_isnotaryvout(char *coinaddr,uint32_t tiptime) // from ac_private chains only { int32_t season = getacseason(tiptime); From bc69675fc386b0977df26a57b8d73109cd99a198 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Tue, 4 Jun 2019 17:55:34 +0800 Subject: [PATCH 447/447] undo attempt at hs/s for staking chains --- src/rpc/mining.cpp | 38 +++++--------------------------------- 1 file changed, 5 insertions(+), 33 deletions(-) diff --git a/src/rpc/mining.cpp b/src/rpc/mining.cpp index 8e5de0f53..53a744497 100644 --- a/src/rpc/mining.cpp +++ b/src/rpc/mining.cpp @@ -59,22 +59,9 @@ arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t he * Return average network hashes per second based on the last 'lookup' blocks, * or over the difficulty averaging window if 'lookup' is nonpositive. * If 'height' is nonnegative, compute the estimate at the time when a given block was found. -time =0, lastBlockTime=time_of_last_block, PoWblocks=0 -for x = 1 to 100 -get block info -if PoS then - lastBlockTime = ThisBlockTime - next x -else - PoWblocks += 1 - some var/array about diff - newTime = timeNow - lastBlockTime - totalTime = totalTime + newTime - lastBlockTime = newTime -next x -do math of num PoW blocks over PoW active Time with stored diff info */ -int64_t GetNetworkHashPS(int lookup, int height) { +int64_t GetNetworkHashPS(int lookup, int height) +{ CBlockIndex *pb = chainActive.LastTip(); if (height >= 0 && height < chainActive.Height()) @@ -93,36 +80,21 @@ int64_t GetNetworkHashPS(int lookup, int height) { CBlockIndex *pb0 = pb; int64_t minTime = pb0->GetBlockTime(); - int64_t timeoffset = 0, n=0,i=0; int64_t maxTime = minTime; - for (i = 0; i < lookup; i++) { + for (int i = 0; i < lookup; i++) { pb0 = pb0->pprev; - // if PoW block save block time, and skip the hash. - if ( pb0->segid >= 0 && pb0->segid != -2 ) - { - n++; - // only staking chains should ever set this. - - timeoffset += pb0->GetBlockTime() - pb0->pprev->GetBlockTime(); - //fprintf(stderr, "staking tx.%li segid.%i blocktime.%li\n", n, pb0->segid, (pb0->GetBlockTime() - pb0->pprev->GetBlockTime())); - if ( lookup > pb->GetHeight() ) - break; - lookup++; - continue; - } int64_t time = pb0->GetBlockTime(); minTime = std::min(time, minTime); maxTime = std::max(time, maxTime); } - //fprintf(stderr, "number blocks scanned.%li\n",i ); // In case there's a situation where minTime == maxTime, we don't want a divide by zero exception. if (minTime == maxTime) return 0; arith_uint256 workDiff = pb->chainPower.chainWork - pb0->chainPower.chainWork; - int64_t timeDiff = maxTime - minTime;// - timeoffset; - fprintf(stderr, "timediff.%li timeoffset.%li mintime.%li maxtime.%li\n", timeDiff, timeoffset, minTime, maxTime); + int64_t timeDiff = maxTime - minTime; + return (int64_t)(workDiff.getdouble() / timeDiff); }