From 0cf52141ef9e7636bda85cbbdb80bbc0803414c5 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Tue, 16 Oct 2018 12:58:43 +0800 Subject: [PATCH 001/127] give this a go --- src/komodo_bitcoind.h | 48 +++++++++-------- src/komodo_globals.h | 2 +- src/komodo_utils.h | 6 ++- src/main.cpp | 16 +++++- src/miner.cpp | 117 +++++++++++++++++++++--------------------- src/pow.cpp | 48 +++++++++-------- 6 files changed, 135 insertions(+), 102 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 86ed8f7b3..8bfca7dc4 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -169,7 +169,7 @@ try_again: curl_handle = curl_easy_init(); init_string(&s); headers = curl_slist_append(0,"Expect:"); - + curl_easy_setopt(curl_handle,CURLOPT_USERAGENT,"mozilla/4.0");//"Mozilla/4.0 (compatible; )"); curl_easy_setopt(curl_handle,CURLOPT_HTTPHEADER, headers); curl_easy_setopt(curl_handle,CURLOPT_URL, url); @@ -198,7 +198,7 @@ try_again: bracket0 = (char *)"["; bracket1 = (char *)"]"; } - + databuf = (char *)malloc(256 + strlen(command) + strlen(params)); sprintf(databuf,"{\"id\":\"jl777\",\"method\":\"%s\",\"params\":%s%s%s}",command,bracket0,params,bracket1); //printf("url.(%s) userpass.(%s) databuf.(%s)\n",url,userpass,databuf); @@ -238,7 +238,7 @@ try_again: free(s.ptr); sleep((1<= 10000 sats PoS stake must be without txfee and in the last tx in the block at vout[0] */ +extern int32_t ASSETCHAINS_STREAM; uint64_t komodo_commission(const CBlock *pblock) { - int32_t i,j,n=0,txn_count; uint64_t commission,total = 0; - txn_count = pblock->vtx.size(); - for (i=0; ivtx[i].vout.size(); - for (j=0; jvtx[i].vout[j].nValue; - } + int32_t i,j,n=0,txn_count; uint64_t commission,total = 0; + txn_count = pblock->vtx.size(); + for (i=0; ivtx[i].vout.size(); + for (j=0; jvtx[i].vout[j].nValue; + } + } + //fprintf(stderr,"txn.%d n.%d commission total %.8f -> %.8f\n",txn_count,n,dstr(total),dstr((total * ASSETCHAINS_COMMISSION) / COIN)); + commission = ((total * ASSETCHAINS_COMMISSION) / COIN); + if ( commission < 10000 ) + commission = 0; + } + else + { + commission = 10000; } - //fprintf(stderr,"txn.%d n.%d commission total %.8f -> %.8f\n",txn_count,n,dstr(total),dstr((total * ASSETCHAINS_COMMISSION) / COIN)); - commission = ((total * ASSETCHAINS_COMMISSION) / COIN); - if ( commission < 10000 ) - commission = 0; return(commission); } diff --git a/src/komodo_globals.h b/src/komodo_globals.h index f352b5333..c456d3e44 100644 --- a/src/komodo_globals.h +++ b/src/komodo_globals.h @@ -45,7 +45,7 @@ struct komodo_state KOMODO_STATES[34]; #define _COINBASE_MATURITY 100 int COINBASE_MATURITY = _COINBASE_MATURITY;//100; -int32_t KOMODO_MININGTHREADS = -1,IS_KOMODO_NOTARY,USE_EXTERNAL_PUBKEY,KOMODO_CHOSEN_ONE,ASSETCHAINS_SEED,KOMODO_ON_DEMAND,KOMODO_EXTERNAL_NOTARIES,KOMODO_PASSPORT_INITDONE,KOMODO_PAX,KOMODO_EXCHANGEWALLET,KOMODO_REWIND,KOMODO_CONNECTING = -1; +int32_t KOMODO_MININGTHREADS = -1,IS_KOMODO_NOTARY,ASSETCHAINS_STREAM,USE_EXTERNAL_PUBKEY,KOMODO_CHOSEN_ONE,ASSETCHAINS_SEED,KOMODO_ON_DEMAND,KOMODO_EXTERNAL_NOTARIES,KOMODO_PASSPORT_INITDONE,KOMODO_PAX,KOMODO_EXCHANGEWALLET,KOMODO_REWIND,KOMODO_CONNECTING = -1; int32_t KOMODO_INSYNC,KOMODO_LASTMINED,prevKOMODO_LASTMINED,KOMODO_CCACTIVATE,JUMBLR_PAUSE = 1; std::string NOTARY_PUBKEY,ASSETCHAINS_NOTARIES,ASSETCHAINS_OVERRIDE_PUBKEY,DONATION_PUBKEY; uint8_t NOTARY_PUBKEY33[33],ASSETCHAINS_OVERRIDE_PUBKEY33[33],ASSETCHAINS_PUBLIC,ASSETCHAINS_PRIVATE; diff --git a/src/komodo_utils.h b/src/komodo_utils.h index bfd59fd57..50b0e3020 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1561,6 +1561,7 @@ void komodo_args(char *argv0) ASSETCHAINS_DECAY = GetArg("-ac_decay",0); ASSETCHAINS_COMMISSION = GetArg("-ac_perc",0); ASSETCHAINS_OVERRIDE_PUBKEY = GetArg("-ac_pubkey",""); + ASSETCHAINS_STREAM = GetArg("-ac_stream",0); if ( (ASSETCHAINS_STAKED= GetArg("-ac_staked",0)) > 100 ) ASSETCHAINS_STAKED = 100; if ( ASSETCHAINS_STAKED != 0 && ASSETCHAINS_PRIVATE != 0 ) @@ -1589,7 +1590,10 @@ void komodo_args(char *argv0) { ASSETCHAINS_COMMISSION = 0; printf("ASSETCHAINS_COMMISSION needs an ASETCHAINS_OVERRIDE_PUBKEY and cant be more than 100000000 (100%%)\n"); - } + } else if ( ASSETCHAINS_STREAM != 0) { + ASSETCHAINS_STREAM = 0; + printf("ASSETCHAINS_STREAM needs ASSETCHAINS_OVERRIDE_PUBKEY! This parameter has been ignored! \n"); + } if ( ASSETCHAINS_ENDSUBSIDY != 0 || ASSETCHAINS_REWARD != 0 || ASSETCHAINS_HALVING != 0 || ASSETCHAINS_DECAY != 0 || ASSETCHAINS_COMMISSION != 0 || ASSETCHAINS_PUBLIC != 0 || ASSETCHAINS_PRIVATE != 0 ) { fprintf(stderr,"end.%llu blocks, reward %.8f halving.%llu blocks, decay.%llu perc %.4f%% ac_pub=[%02x...]\n",(long long)ASSETCHAINS_ENDSUBSIDY,dstr(ASSETCHAINS_REWARD),(long long)ASSETCHAINS_HALVING,(long long)ASSETCHAINS_DECAY,dstr(ASSETCHAINS_COMMISSION)*100,ASSETCHAINS_OVERRIDE_PUBKEY33[0]); diff --git a/src/main.cpp b/src/main.cpp index 1ff5f8012..39270a0b9 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1866,6 +1866,7 @@ bool ReadBlockFromDisk(CBlock& block, const CBlockIndex* pindex,bool checkPOW) //uint64_t komodo_moneysupply(int32_t height); extern char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN]; extern uint32_t ASSETCHAINS_MAGIC; +extern int32_t ASSETCHAINS_STREAM; extern uint64_t ASSETCHAINS_STAKED,ASSETCHAINS_ENDSUBSIDY,ASSETCHAINS_REWARD,ASSETCHAINS_HALVING,ASSETCHAINS_LINEAR,ASSETCHAINS_COMMISSION,ASSETCHAINS_SUPPLY; extern uint8_t ASSETCHAINS_PUBLIC,ASSETCHAINS_PRIVATE; @@ -1895,7 +1896,7 @@ CAmount GetBlockSubsidy(int nHeight, const Consensus::Params& consensusParams) { if ( ASSETCHAINS_REWARD == 0 ) return(10000); - else if ( ASSETCHAINS_ENDSUBSIDY != 0 && nHeight >= ASSETCHAINS_ENDSUBSIDY ) + else if ( ( ASSETCHAINS_ENDSUBSIDY != 0 && nHeight >= ASSETCHAINS_ENDSUBSIDY )|| ASSETCHAINS_STREAM != 0) return(0); else { @@ -2961,6 +2962,19 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin if (!view.HaveJoinSplitRequirements(tx)) return state.DoS(100, error("ConnectBlock(): JoinSplit requirements not met"), REJECT_INVALID, "bad-txns-joinsplit-requirements-not-met"); + + if ( ASSETCHAINS_SYMBOL[0] != 0 ) + { + if ( ASSETCHAINS_STREAM != 0 ) + { + if ( block.vtx.size() == 1 && block.vtx[0].vout.size() == 2 && pindex->nHeight > ASSETCHAINS_MINHEIGHT) + { + return state.DoS(100, error("ConnectBlock(): There are no TX in this block, it is invalid!"), + REJECT_INVALID, "bad-block-no-transactions"); + } + } + } + if (fAddressIndex || fSpentIndex) { for (size_t j = 0; j < tx.vin.size(); j++) { diff --git a/src/miner.cpp b/src/miner.cpp index 874c1b4f8..8fbfcff05 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -64,7 +64,7 @@ public: set setDependsOn; CFeeRate feeRate; double dPriority; - + COrphan(const CTransaction* ptxIn) : ptx(ptxIn), feeRate(0), dPriority(0) { } @@ -78,10 +78,10 @@ typedef boost::tuple TxPriority; class TxPriorityCompare { bool byFee; - + public: TxPriorityCompare(bool _byFee) : byFee(_byFee) { } - + bool operator()(const TxPriority& a, const TxPriority& b) { if (byFee) @@ -106,7 +106,7 @@ void UpdateTime(CBlockHeader* pblock, const Consensus::Params& consensusParams, #include "komodo_defs.h" -extern int32_t KOMODO_MININGTHREADS,KOMODO_LONGESTCHAIN,ASSETCHAINS_SEED,IS_KOMODO_NOTARY,USE_EXTERNAL_PUBKEY,KOMODO_CHOSEN_ONE,ASSETCHAIN_INIT,KOMODO_INITDONE,KOMODO_ON_DEMAND,KOMODO_INITDONE,KOMODO_PASSPORT_INITDONE; +extern int32_t KOMODO_MININGTHREADS,KOMODO_LONGESTCHAIN,ASSETCHAINS_SEED,IS_KOMODO_NOTARY,ASSETCHAINS_STREAM,USE_EXTERNAL_PUBKEY,KOMODO_CHOSEN_ONE,ASSETCHAIN_INIT,KOMODO_INITDONE,KOMODO_ON_DEMAND,KOMODO_INITDONE,KOMODO_PASSPORT_INITDONE; extern uint64_t ASSETCHAINS_REWARD,ASSETCHAINS_COMMISSION,ASSETCHAINS_STAKED; extern char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN]; extern std::string NOTARY_PUBKEY,ASSETCHAINS_OVERRIDE_PUBKEY; @@ -141,27 +141,27 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount) // -blockversion=N to test forking scenarios if (Params().MineBlocksOnDemand()) pblock->nVersion = GetArg("-blockversion", pblock->nVersion); - + // Add dummy coinbase tx as first transaction pblock->vtx.push_back(CTransaction()); pblocktemplate->vTxFees.push_back(-1); // updated at end pblocktemplate->vTxSigOps.push_back(-1); // updated at end - + // Largest block you're willing to create: unsigned int nBlockMaxSize = GetArg("-blockmaxsize", DEFAULT_BLOCK_MAX_SIZE); // Limit to betweeen 1K and MAX_BLOCK_SIZE-1K for sanity: nBlockMaxSize = std::max((unsigned int)1000, std::min((unsigned int)(MAX_BLOCK_SIZE-1000), nBlockMaxSize)); - + // How much of the block should be dedicated to high-priority transactions, // included regardless of the fees they pay unsigned int nBlockPrioritySize = GetArg("-blockprioritysize", DEFAULT_BLOCK_PRIORITY_SIZE); nBlockPrioritySize = std::min(nBlockMaxSize, nBlockPrioritySize); - + // Minimum block size you want to create; block will be filled with free transactions // until there are no more or the block reaches this size: unsigned int nBlockMinSize = GetArg("-blockminsize", DEFAULT_BLOCK_MIN_SIZE); nBlockMinSize = std::min(nBlockMaxSize, nBlockMinSize); - + // Collect memory pool transactions into the block CAmount nFees = 0; CBlockIndex* pindexPrev = 0; @@ -174,12 +174,12 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount) const int64_t nMedianTimePast = pindexPrev->GetMedianTimePast(); CCoinsViewCache view(pcoinsTip); uint32_t expired; uint64_t commission; - + // Priority order to process transactions list vOrphan; // list memory doesn't move map > mapDependers; bool fPrintPriority = GetBoolArg("-printpriority", false); - + // This vector will be sorted into a priority queue: vector vecPriority; vecPriority.reserve(mempool.mapTx.size()); @@ -187,11 +187,11 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount) mi != mempool.mapTx.end(); ++mi) { const CTransaction& tx = mi->GetTx(); - + int64_t nLockTimeCutoff = (STANDARD_LOCKTIME_VERIFY_FLAGS & LOCKTIME_MEDIAN_TIME_PAST) ? nMedianTimePast : pblock->GetBlockTime(); - + if (tx.IsCoinBase() || !IsFinalTx(tx, nHeight, nLockTimeCutoff) || IsExpiredTx(tx, nHeight)) { //fprintf(stderr,"coinbase.%d finaltx.%d expired.%d\n",tx.IsCoinBase(),IsFinalTx(tx, nHeight, nLockTimeCutoff),IsExpiredTx(tx, nHeight)); @@ -256,16 +256,16 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount) } if (fMissingInputs) continue; - + // Priority is sum(valuein * age) / modified_txsize unsigned int nTxSize = ::GetSerializeSize(tx, SER_NETWORK, PROTOCOL_VERSION); dPriority = tx.ComputePriority(dPriority, nTxSize); - + uint256 hash = tx.GetHash(); mempool.ApplyDeltas(hash, dPriority, nTotalIn); - + CFeeRate feeRate(nTotalIn-tx.GetValueOut(), nTxSize); - + if (porphan) { porphan->dPriority = dPriority; @@ -274,27 +274,27 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount) else vecPriority.push_back(TxPriority(dPriority, feeRate, &(mi->GetTx()))); } - + // Collect transactions into block uint64_t nBlockSize = 1000; uint64_t nBlockTx = 0; int64_t interest; int nBlockSigOps = 100; bool fSortedByFee = (nBlockPrioritySize <= 0); - + TxPriorityCompare comparer(fSortedByFee); std::make_heap(vecPriority.begin(), vecPriority.end(), comparer); - + while (!vecPriority.empty()) { // Take highest priority transaction off the priority queue: double dPriority = vecPriority.front().get<0>(); CFeeRate feeRate = vecPriority.front().get<1>(); const CTransaction& tx = *(vecPriority.front().get<2>()); - + std::pop_heap(vecPriority.begin(), vecPriority.end(), comparer); vecPriority.pop_back(); - + // Size limits unsigned int nTxSize = ::GetSerializeSize(tx, SER_NETWORK, PROTOCOL_VERSION); if (nBlockSize + nTxSize >= nBlockMaxSize-512) // room for extra autotx @@ -302,7 +302,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount) //fprintf(stderr,"nBlockSize %d + %d nTxSize >= %d nBlockMaxSize\n",(int32_t)nBlockSize,(int32_t)nTxSize,(int32_t)nBlockMaxSize); continue; } - + // Legacy limits on sigOps: unsigned int nTxSigOps = GetLegacySigOpCount(tx); if (nBlockSigOps + nTxSigOps >= MAX_BLOCK_SIGOPS-1) @@ -329,14 +329,14 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount) comparer = TxPriorityCompare(fSortedByFee); std::make_heap(vecPriority.begin(), vecPriority.end(), comparer); } - + if (!view.HaveInputs(tx)) { //fprintf(stderr,"dont have inputs\n"); continue; } CAmount nTxFees = view.GetValueIn(chainActive.LastTip()->nHeight,&interest,tx,chainActive.LastTip()->nTime)-tx.GetValueOut(); - + nTxSigOps += GetP2SHSigOpCount(tx, view); if (nBlockSigOps + nTxSigOps >= MAX_BLOCK_SIGOPS-1) { @@ -354,7 +354,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount) continue; } UpdateCoins(tx, view, nHeight); - + // Added pblock->vtx.push_back(tx); pblocktemplate->vTxFees.push_back(nTxFees); @@ -363,12 +363,12 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount) ++nBlockTx; nBlockSigOps += nTxSigOps; nFees += nTxFees; - + if (fPrintPriority) { LogPrintf("priority %.1f fee %s txid %s\n",dPriority, feeRate.ToString(), tx.GetHash().ToString()); } - + // Add transactions that depend on this one to the priority queue if (mapDependers.count(hash)) { @@ -386,7 +386,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount) } } } - + nLastBlockTx = nBlockTx; nLastBlockSize = nBlockSize; blocktime = 1 + std::max(pindexPrev->GetMedianTimePast()+1, GetAdjustedTime()); @@ -411,7 +411,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount) //printf("staking PoS ht.%d t%u lag.%u\n",(int32_t)chainActive.LastTip()->nHeight+1,blocktime,(uint32_t)(GetAdjustedTime() - (blocktime-13))); } else return(0); //fprintf(stderr,"no utxos eligible for staking\n"); } - + // Create coinbase tx CMutableTransaction txNew = CreateNewContextualCMutableTransaction(chainparams.GetConsensus(), nHeight); txNew.vin.resize(1); @@ -426,9 +426,9 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount) // Add fees txNew.vout[0].nValue += nFees; txNew.vin[0].scriptSig = CScript() << nHeight << OP_0; - + pblock->vtx[0] = txNew; - if ( nHeight > 1 && ASSETCHAINS_SYMBOL[0] != 0 && ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 && ASSETCHAINS_COMMISSION != 0 && (commission= komodo_commission((CBlock*)&pblocktemplate->block)) != 0 ) + if ( nHeight > 1 && ASSETCHAINS_SYMBOL[0] != 0 && ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 && (ASSETCHAINS_COMMISSION != 0 || ASSETCHAINS_STREAM != 0) && (commission= komodo_commission((CBlock*)&pblocktemplate->block)) != 0 ) { int32_t i; uint8_t *ptr; txNew.vout.resize(2); @@ -449,7 +449,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount) nonce <<= 32; nonce >>= 16; pblock->nNonce = ArithToUint256(nonce); - + // Fill in header pblock->hashPrevBlock = pindexPrev->GetBlockHash(); pblock->hashReserved = uint256(); @@ -527,7 +527,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount) return pblocktemplate.release(); } - + /* #ifdef ENABLE_WALLET boost::optional GetMinerScriptPubKey(CReserveKey& reservekey) @@ -550,11 +550,11 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount) return boost::optional(); #endif } - + CScript scriptPubKey = CScript() << OP_DUP << OP_HASH160 << ToByteVector(keyID) << OP_EQUALVERIFY << OP_CHECKSIG; return scriptPubKey; } - + #ifdef ENABLE_WALLET CBlockTemplate* CreateNewBlockWithKey(CReserveKey& reservekey) { @@ -564,7 +564,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount) { boost::optional scriptPubKey = GetMinerScriptPubKey(); #endif - + if (!scriptPubKey) { return NULL; } @@ -592,7 +592,7 @@ void IncrementExtraNonce(CBlock* pblock, CBlockIndex* pindexPrev, unsigned int& CMutableTransaction txCoinbase(pblock->vtx[0]); txCoinbase.vin[0].scriptSig = (CScript() << nHeight << CScriptNum(nExtraNonce)) + COINBASE_FLAGS; assert(txCoinbase.vin[0].scriptSig.size() <= 100); - + pblock->vtx[0] = txCoinbase; pblock->hashMerkleRoot = pblock->BuildMerkleTree(); } @@ -606,7 +606,7 @@ void IncrementExtraNonce(CBlock* pblock, CBlockIndex* pindexPrev, unsigned int& CBlockTemplate* CreateNewBlockWithKey(CReserveKey& reservekey,int32_t nHeight,int32_t gpucount) { CPubKey pubkey; CScript scriptPubKey; uint8_t *script,*ptr; int32_t i; - if ( nHeight == 1 && ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 ) + if ( (nHeight == 1 || ASSETCHAINS_STREAM != 0 ) && ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 ) { scriptPubKey = CScript() << ParseHex(ASSETCHAINS_OVERRIDE_PUBKEY) << OP_CHECKSIG; } @@ -615,7 +615,6 @@ CBlockTemplate* CreateNewBlockWithKey(CReserveKey& reservekey,int32_t nHeight,in //fprintf(stderr,"use notary pubkey\n"); scriptPubKey = CScript() << ParseHex(NOTARY_PUBKEY) << OP_CHECKSIG; } - else { if (!reservekey.GetReservedKey(pubkey)) { @@ -661,7 +660,7 @@ static bool ProcessBlockFound(CBlock* pblock) { LogPrintf("%s\n", pblock->ToString()); LogPrintf("generated %s height.%d\n", FormatMoney(pblock->vtx[0].vout[0].nValue),chainActive.LastTip()->nHeight+1); - + // Found a solution { //LOCK(cs_main); @@ -676,11 +675,11 @@ static bool ProcessBlockFound(CBlock* pblock) for (i=31; i>=0; i--) fprintf(stderr,"%02x",((uint8_t *)&hash)[i]); fprintf(stderr," <- chainTip (stale)\n"); - + return error("KomodoMiner: generated block is stale"); } } - + #ifdef ENABLE_WALLET // Remove key from key pool if ( IS_KOMODO_NOTARY == 0 ) @@ -704,7 +703,7 @@ static bool ProcessBlockFound(CBlock* pblock) CValidationState state; if (!ProcessNewBlock(1,chainActive.LastTip()->nHeight+1,state, NULL, pblock, true, NULL)) return error("KomodoMiner: ProcessNewBlock, block not accepted"); - + TrackMinedBlock(pblock->GetHash()); komodo_broadcast(pblock,16); return true; @@ -728,15 +727,15 @@ void static BitcoinMiner() SetThreadPriority(THREAD_PRIORITY_LOWEST); RenameThread("komodo-miner"); const CChainParams& chainparams = Params(); - + #ifdef ENABLE_WALLET // Each thread has its own key CReserveKey reservekey(pwallet); #endif - + // Each thread has its own counter unsigned int nExtraNonce = 0; - + unsigned int n = chainparams.EquihashN(); unsigned int k = chainparams.EquihashK(); uint8_t *script; uint64_t total,checktoshis; int32_t i,j,gpucount=KOMODO_MAXGPUCOUNT,notaryid = -1; @@ -767,7 +766,7 @@ void static BitcoinMiner() } ); miningTimer.start(); - + try { if ( ASSETCHAINS_SYMBOL[0] != 0 ) fprintf(stderr,"try %s Mining with %s\n",ASSETCHAINS_SYMBOL,solver.c_str()); @@ -790,7 +789,7 @@ void static BitcoinMiner() break; MilliSleep(15000); //fprintf(stderr,"fvNodesEmpty %d IsInitialBlockDownload(%s) %d\n",(int32_t)fvNodesEmpty,ASSETCHAINS_SYMBOL,(int32_t)IsInitialBlockDownload()); - + } while (true); //fprintf(stderr,"%s Found peers\n",ASSETCHAINS_SYMBOL); miningTimer.start(); @@ -1054,13 +1053,13 @@ void static BitcoinMiner() std::lock_guard lock{m_cs}; return cancelSolver; }; - + // TODO: factor this out into a function with the same API for each solver. if (solver == "tromp" ) { //&& notaryid >= 0 ) { // Create solver and initialize it. equi eq(1); eq.setstate(&curr_state); - + // Initialization done, start algo driver. eq.digit0(0); eq.xfull = eq.bfull = eq.hfull = 0; @@ -1072,7 +1071,7 @@ void static BitcoinMiner() } eq.digitK(0); ehSolverRuns.increment(); - + // Convert solution indices to byte array (decompress) and pass it to validBlock method. for (size_t s = 0; s < eq.nsols; s++) { LogPrint("pow", "Checking solution %d\n", s+1); @@ -1081,7 +1080,7 @@ void static BitcoinMiner() index_vector[i] = eq.sols[s][i]; } std::vector sol_char = GetMinimalFromIndices(index_vector, DIGITBITS); - + if (validBlock(sol_char)) { // If we find a POW solution, do not try other solutions // because they become invalid as we created a new block in blockchain. @@ -1108,7 +1107,7 @@ void static BitcoinMiner() cancelSolver = false; } } - + // Check for stop or if block needs to be rebuilt boost::this_thread::interruption_point(); // Regtest mode doesn't require peers @@ -1178,7 +1177,7 @@ void static BitcoinMiner() miningTimer.stop(); c.disconnect(); } - + #ifdef ENABLE_WALLET void GenerateBitcoins(bool fGenerate, CWallet* pwallet, int nThreads) #else @@ -1186,10 +1185,10 @@ void static BitcoinMiner() #endif { static boost::thread_group* minerThreads = NULL; - + if (nThreads < 0) nThreads = GetNumCores(); - + if (minerThreads != NULL) { minerThreads->interrupt_all(); @@ -1201,7 +1200,7 @@ void static BitcoinMiner() nThreads = 1; if (nThreads == 0 || !fGenerate) return; - + minerThreads = new boost::thread_group(); for (int i = 0; i < nThreads; i++) { #ifdef ENABLE_WALLET @@ -1211,5 +1210,5 @@ void static BitcoinMiner() #endif } } - + #endif // ENABLE_MINING diff --git a/src/pow.cpp b/src/pow.cpp index 1291e445e..9c8f68586 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -20,31 +20,39 @@ #include "librustzcash.h" #endif // ENABLE_RUST uint32_t komodo_chainactive_timestamp(); +extern int32_t ASSETCHAINS_STREAM; unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHeader *pblock, const Consensus::Params& params) { - unsigned int nProofOfWorkLimit = UintToArith256(params.powLimit).GetCompact(); - // Genesis block - if (pindexLast == NULL ) - return nProofOfWorkLimit; + if ( ASSETCHAINS_STREAM == 0) + { + unsigned int nProofOfWorkLimit = UintToArith256(params.powLimit).GetCompact(); + // Genesis block + if (pindexLast == NULL ) + return nProofOfWorkLimit; - // Find the first block in the averaging interval - const CBlockIndex* pindexFirst = pindexLast; - arith_uint256 bnTot {0}; - for (int i = 0; pindexFirst && i < params.nPowAveragingWindow; i++) { - arith_uint256 bnTmp; - bnTmp.SetCompact(pindexFirst->nBits); - bnTot += bnTmp; - pindexFirst = pindexFirst->pprev; + // Find the first block in the averaging interval + const CBlockIndex* pindexFirst = pindexLast; + arith_uint256 bnTot {0}; + for (int i = 0; pindexFirst && i < params.nPowAveragingWindow; i++) { + arith_uint256 bnTmp; + bnTmp.SetCompact(pindexFirst->nBits); + bnTot += bnTmp; + pindexFirst = pindexFirst->pprev; + } + + // Check we have enough blocks + if (pindexFirst == NULL) + return nProofOfWorkLimit; + + arith_uint256 bnAvg {bnTot / params.nPowAveragingWindow}; + + return CalculateNextWorkRequired(bnAvg, pindexLast->GetMedianTimePast(), pindexFirst->GetMedianTimePast(), params); + } + else + { + return 537857807; } - - // Check we have enough blocks - if (pindexFirst == NULL) - return nProofOfWorkLimit; - - arith_uint256 bnAvg {bnTot / params.nPowAveragingWindow}; - - return CalculateNextWorkRequired(bnAvg, pindexLast->GetMedianTimePast(), pindexFirst->GetMedianTimePast(), params); } unsigned int CalculateNextWorkRequired(arith_uint256 bnAvg, From 4e9596efeab6fa2426960c338b1dc72576143e98 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Tue, 16 Oct 2018 13:02:16 +0800 Subject: [PATCH 002/127] fix commission --- 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 8bfca7dc4..1b8daf3a7 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1109,9 +1109,9 @@ extern int32_t ASSETCHAINS_STREAM; uint64_t komodo_commission(const CBlock *pblock) { + int32_t i,j,n=0,txn_count; uint64_t commission,total = 0; if ( ASSETCHAINS_STREAM == 0 ) { - int32_t i,j,n=0,txn_count; uint64_t commission,total = 0; txn_count = pblock->vtx.size(); for (i=0; i Date: Tue, 16 Oct 2018 13:07:30 +0800 Subject: [PATCH 003/127] prevent STREAM and PERC being used at the same time --- src/komodo_utils.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 50b0e3020..4c4827f6d 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1562,6 +1562,11 @@ void komodo_args(char *argv0) ASSETCHAINS_COMMISSION = GetArg("-ac_perc",0); ASSETCHAINS_OVERRIDE_PUBKEY = GetArg("-ac_pubkey",""); ASSETCHAINS_STREAM = GetArg("-ac_stream",0); + if ( ASSETCHAINS_STREAM != 0 && ASSETCHAINS_COMMISSION != 0 ) { + printf("ASSETCHAINS_STREAM cannot be used with ASSETCHAINS_COMMISSION setting both to 0! \n"); + ASSETCHAINS_STREAM = 0; + ASSETCHAINS_COMMISSION = 0; + } if ( (ASSETCHAINS_STAKED= GetArg("-ac_staked",0)) > 100 ) ASSETCHAINS_STAKED = 100; if ( ASSETCHAINS_STAKED != 0 && ASSETCHAINS_PRIVATE != 0 ) From c175848729fa19799d0910a6bac236c2123e1d4c Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Tue, 16 Oct 2018 13:12:53 +0800 Subject: [PATCH 004/127] set minimum supply for ac_stream to 100k --- src/komodo_utils.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 4c4827f6d..b60328c54 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1599,6 +1599,10 @@ void komodo_args(char *argv0) ASSETCHAINS_STREAM = 0; printf("ASSETCHAINS_STREAM needs ASSETCHAINS_OVERRIDE_PUBKEY! This parameter has been ignored! \n"); } + if ( ASSETCHAINS_STREAM != 0 && ASSETCHAINS_SUPPLY == 10 ) { + ASSETCHAINS_SUPPLY = 100000; + printf("ASSETCHAINS_STREAM is set with no supply, setting supply at 100,000 coins. \n"); + } if ( ASSETCHAINS_ENDSUBSIDY != 0 || ASSETCHAINS_REWARD != 0 || ASSETCHAINS_HALVING != 0 || ASSETCHAINS_DECAY != 0 || ASSETCHAINS_COMMISSION != 0 || ASSETCHAINS_PUBLIC != 0 || ASSETCHAINS_PRIVATE != 0 ) { fprintf(stderr,"end.%llu blocks, reward %.8f halving.%llu blocks, decay.%llu perc %.4f%% ac_pub=[%02x...]\n",(long long)ASSETCHAINS_ENDSUBSIDY,dstr(ASSETCHAINS_REWARD),(long long)ASSETCHAINS_HALVING,(long long)ASSETCHAINS_DECAY,dstr(ASSETCHAINS_COMMISSION)*100,ASSETCHAINS_OVERRIDE_PUBKEY33[0]); From 0d63c1f908db9bcd68e2dddb89d9eae7f01cd966 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Tue, 16 Oct 2018 13:36:24 +0800 Subject: [PATCH 005/127] add some prints --- src/komodo_bitcoind.h | 5 ++++- src/miner.cpp | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 1b8daf3a7..83b8399b8 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1577,9 +1577,12 @@ int32_t komodo_checkPOW(int32_t slowflag,CBlock *pblock,int32_t height) { if ( height == 1 ) { + fprintf(stderr, "checking override pubkey thingo \n"); script = (uint8_t *)pblock->vtx[0].vout[0].scriptPubKey.data(); - if ( script[0] != 33 || script[34] != OP_CHECKSIG || memcmp(script+1,ASSETCHAINS_OVERRIDE_PUBKEY33,33) != 0 ) + if ( script[0] != 33 || script[34] != OP_CHECKSIG || memcmp(script+1,ASSETCHAINS_OVERRIDE_PUBKEY33,33) != 0 ) { + fprintf(stderr, "failed the check\n"); return(-1); + } } else { diff --git a/src/miner.cpp b/src/miner.cpp index 8fbfcff05..79a3c1eec 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -609,6 +609,7 @@ CBlockTemplate* CreateNewBlockWithKey(CReserveKey& reservekey,int32_t nHeight,in if ( (nHeight == 1 || ASSETCHAINS_STREAM != 0 ) && ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 ) { scriptPubKey = CScript() << ParseHex(ASSETCHAINS_OVERRIDE_PUBKEY) << OP_CHECKSIG; + fprintf(stderr, "assechains stream should be mining to override pubkey\n"); } else if ( USE_EXTERNAL_PUBKEY != 0 ) { From 497f834d1f1d81ef89f99c9e84b57d8640b310e3 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Tue, 16 Oct 2018 13:49:38 +0800 Subject: [PATCH 006/127] disable check to see what block is being created --- src/komodo_bitcoind.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 83b8399b8..d0ee426b8 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1575,7 +1575,7 @@ int32_t komodo_checkPOW(int32_t slowflag,CBlock *pblock,int32_t height) } if ( failed == 0 && ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 ) { - if ( height == 1 ) + /*if ( height == 1 ) { fprintf(stderr, "checking override pubkey thingo \n"); script = (uint8_t *)pblock->vtx[0].vout[0].scriptPubKey.data(); @@ -1585,10 +1585,10 @@ int32_t komodo_checkPOW(int32_t slowflag,CBlock *pblock,int32_t height) } } else - { + {*/ if ( komodo_checkcommission(pblock,height) < 0 ) return(-1); - } + //} } //fprintf(stderr,"komodo_checkPOW possible.%d slowflag.%d ht.%d notaryid.%d failed.%d\n",possible,slowflag,height,notaryid,failed); if ( failed != 0 && possible == 0 && notaryid < 0 ) From 45ef1a21c7552c5dfe9a722104b777c9ea0aeb56 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Tue, 16 Oct 2018 14:21:23 +0800 Subject: [PATCH 007/127] try this --- src/komodo_bitcoind.h | 8 ++++---- src/komodo_gateway.h | 13 ++++++------- src/komodo_utils.h | 2 +- src/main.cpp | 2 +- 4 files changed, 12 insertions(+), 13 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index d0ee426b8..f1f5b8efd 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1472,7 +1472,7 @@ int32_t komodo_is_PoSblock(int32_t slowflag,int32_t height,CBlock *pblock,arith_ int64_t komodo_checkcommission(CBlock *pblock,int32_t height) { int64_t checktoshis=0; uint8_t *script; - if ( ASSETCHAINS_COMMISSION != 0 ) + if ( ASSETCHAINS_COMMISSION != 0 || ASSETCHAINS_STREAM != 0) { checktoshis = komodo_commission(pblock); if ( checktoshis > 10000 && pblock->vtx[0].vout.size() != 2 ) @@ -1575,7 +1575,7 @@ int32_t komodo_checkPOW(int32_t slowflag,CBlock *pblock,int32_t height) } if ( failed == 0 && ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 ) { - /*if ( height == 1 ) + if ( height == 1 ) { fprintf(stderr, "checking override pubkey thingo \n"); script = (uint8_t *)pblock->vtx[0].vout[0].scriptPubKey.data(); @@ -1585,10 +1585,10 @@ int32_t komodo_checkPOW(int32_t slowflag,CBlock *pblock,int32_t height) } } else - {*/ + { if ( komodo_checkcommission(pblock,height) < 0 ) return(-1); - //} + } } //fprintf(stderr,"komodo_checkPOW possible.%d slowflag.%d ht.%d notaryid.%d failed.%d\n",possible,slowflag,height,notaryid,failed); if ( failed != 0 && possible == 0 && notaryid < 0 ) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 379224b48..233f87fcf 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -90,7 +90,7 @@ struct pax_transaction *komodo_paxmark(int32_t height,uint256 txid,uint16_t vout pax->marked = mark; //if ( height > 214700 || pax->height > 214700 ) // printf("mark ht.%d %.8f %.8f\n",pax->height,dstr(pax->komodoshis),dstr(pax->fiatoshis)); - + } pthread_mutex_unlock(&komodo_mutex); return(pax); @@ -203,9 +203,9 @@ int32_t komodo_issued_opreturn(char *base,uint256 *txids,uint16_t *vouts,int64_t // return(0); incr = 34 + (iskomodo * (2*sizeof(fiatoshis) + 2*sizeof(height) + 20 + 4)); //41e77b91cb68dc2aa02fa88550eae6b6d44db676a7e935337b6d1392d9718f03cb0200305c90660400000000fbcbeb1f000000bde801006201000058e7945ad08ddba1eac9c9b6c8e1e97e8016a2d152 - + // 41e94d736ec69d88c08b5d238abeeca609c02357a8317e0d56c328bcb1c259be5d0200485bc80200000000404b4c000000000059470200b80b000061f22ba7d19fe29ac3baebd839af8b7127d1f9075553440046bb4cc7a3b5cd39dffe7206507a3482a00780e617f68b273cce9817ed69298d02001069ca1b0000000080f0fa02000000005b470200b90b000061f22ba7d19fe29ac3baebd839af8b7127d1f90755 - + //for (i=0; i 1 ) + if ( (ASSETCHAINS_COMMISSION != 0 || ASSETCHAINS_STREAM != 0) && height > 1 ) { if ( (checktoshis= komodo_checkcommission((CBlock *)&block,height)) < 0 ) { @@ -772,7 +772,7 @@ int32_t komodo_check_deposit(int32_t height,const CBlock& block,uint32_t prevtim const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int32_t opretlen,uint256 txid,uint16_t vout,char *source) { - uint8_t rmd160[20],rmd160s[64*20],addrtype,shortflag,pubkey33[33]; int32_t didstats,i,j,n,kvheight,len,tokomodo,kmdheight,otherheights[64],kmdheights[64]; int8_t baseids[64]; char base[4],coinaddr[64],destaddr[64]; uint256 txids[64]; uint16_t vouts[64]; uint64_t convtoshis,seed; int64_t fee,fiatoshis,komodoshis,checktoshis,values[64],srcvalues[64]; struct pax_transaction *pax,*pax2; struct komodo_state *basesp; double diff; + uint8_t rmd160[20],rmd160s[64*20],addrtype,shortflag,pubkey33[33]; int32_t didstats,i,j,n,kvheight,len,tokomodo,kmdheight,otherheights[64],kmdheights[64]; int8_t baseids[64]; char base[4],coinaddr[64],destaddr[64]; uint256 txids[64]; uint16_t vouts[64]; uint64_t convtoshis,seed; int64_t fee,fiatoshis,komodoshis,checktoshis,values[64],srcvalues[64]; struct pax_transaction *pax,*pax2; struct komodo_state *basesp; double diff; const char *typestr = "unknown"; if ( ASSETCHAINS_SYMBOL[0] != 0 && komodo_baseid(ASSETCHAINS_SYMBOL) < 0 && opretbuf[0] != 'K' ) { @@ -1185,7 +1185,7 @@ void komodo_stateind_set(struct komodo_state *sp,uint32_t *inds,int32_t n,uint8_ printf("numR.%d numV.%d numN.%d count.%d\n",numR,numV,numN,count); /*else if ( func == 'K' ) // KMD height: stop after 1st else if ( func == 'T' ) // KMD height+timestamp: stop after 1st - + else if ( func == 'N' ) // notarization, scan backwards 1440+ blocks; else if ( func == 'V' ) // price feed: can stop after 1440+ else if ( func == 'R' ) // opreturn:*/ @@ -1518,4 +1518,3 @@ void komodo_passport_iteration() printf("READY for %s RPC calls at %u! done PASSPORT %s refid.%d\n",ASSETCHAINS_SYMBOL,(uint32_t)time(NULL),ASSETCHAINS_SYMBOL,refid); } } - diff --git a/src/komodo_utils.h b/src/komodo_utils.h index b60328c54..ebeb8324f 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1597,7 +1597,7 @@ void komodo_args(char *argv0) printf("ASSETCHAINS_COMMISSION needs an ASETCHAINS_OVERRIDE_PUBKEY and cant be more than 100000000 (100%%)\n"); } else if ( ASSETCHAINS_STREAM != 0) { ASSETCHAINS_STREAM = 0; - printf("ASSETCHAINS_STREAM needs ASSETCHAINS_OVERRIDE_PUBKEY! This parameter has been ignored! \n"); + printf("ASSETCHAINS_STREAM needs ASSETCHAINS_OVERRIDE_PUBKEY! This parameter has been ignored! \n %s",ASSETCHAINS_OVERRIDE_PUBKEY.c_str()); } if ( ASSETCHAINS_STREAM != 0 && ASSETCHAINS_SUPPLY == 10 ) { ASSETCHAINS_SUPPLY = 100000; diff --git a/src/main.cpp b/src/main.cpp index 39270a0b9..42f1d624d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3124,7 +3124,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin LogPrint("bench", " - Connect %u transactions: %.2fms (%.3fms/tx, %.3fms/txin) [%.2fs]\n", (unsigned)block.vtx.size(), 0.001 * (nTime1 - nTimeStart), 0.001 * (nTime1 - nTimeStart) / block.vtx.size(), nInputs <= 1 ? 0 : 0.001 * (nTime1 - nTimeStart) / (nInputs-1), nTimeConnect * 0.000001); CAmount blockReward = nFees + GetBlockSubsidy(pindex->nHeight, chainparams.GetConsensus()) + sum; - if ( ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 && ASSETCHAINS_COMMISSION != 0 ) + if ( ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 && (ASSETCHAINS_COMMISSION != 0 || ASSETCHAINS_STREAM != 0) ) { uint64_t checktoshis; if ( (checktoshis= komodo_commission((CBlock *)&block)) != 0 ) From 8ca9133eb4c7ef0735cf93d6e3721d12160dcbb4 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Tue, 16 Oct 2018 14:44:55 +0800 Subject: [PATCH 008/127] fix --- src/komodo_utils.h | 2 +- src/miner.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_utils.h b/src/komodo_utils.h index ebeb8324f..5dc218d76 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1603,7 +1603,7 @@ void komodo_args(char *argv0) ASSETCHAINS_SUPPLY = 100000; printf("ASSETCHAINS_STREAM is set with no supply, setting supply at 100,000 coins. \n"); } - if ( ASSETCHAINS_ENDSUBSIDY != 0 || ASSETCHAINS_REWARD != 0 || ASSETCHAINS_HALVING != 0 || ASSETCHAINS_DECAY != 0 || ASSETCHAINS_COMMISSION != 0 || ASSETCHAINS_PUBLIC != 0 || ASSETCHAINS_PRIVATE != 0 ) + if ( ASSETCHAINS_ENDSUBSIDY != 0 || ASSETCHAINS_REWARD != 0 || ASSETCHAINS_HALVING != 0 || ASSETCHAINS_DECAY != 0 || ASSETCHAINS_STREAM != 0 || ASSETCHAINS_COMMISSION != 0 || ASSETCHAINS_PUBLIC != 0 || ASSETCHAINS_PRIVATE != 0 ) { fprintf(stderr,"end.%llu blocks, reward %.8f halving.%llu blocks, decay.%llu perc %.4f%% ac_pub=[%02x...]\n",(long long)ASSETCHAINS_ENDSUBSIDY,dstr(ASSETCHAINS_REWARD),(long long)ASSETCHAINS_HALVING,(long long)ASSETCHAINS_DECAY,dstr(ASSETCHAINS_COMMISSION)*100,ASSETCHAINS_OVERRIDE_PUBKEY33[0]); extraptr = extrabuf; diff --git a/src/miner.cpp b/src/miner.cpp index 79a3c1eec..b058a7c7d 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -439,7 +439,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount) for (i=0; i<33; i++) ptr[i+1] = ASSETCHAINS_OVERRIDE_PUBKEY33[i]; ptr[34] = OP_CHECKSIG; - //printf("autocreate commision vout\n"); + printf("autocreate commission vout\n"); pblock->vtx[0] = txNew; } pblocktemplate->vTxFees[0] = -nFees; From 3793c6386097185cd973b6823e55c208564228e8 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Tue, 16 Oct 2018 15:33:09 +0800 Subject: [PATCH 009/127] oops LOL --- src/miner.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/miner.cpp b/src/miner.cpp index b058a7c7d..36ed84f05 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -615,7 +615,7 @@ CBlockTemplate* CreateNewBlockWithKey(CReserveKey& reservekey,int32_t nHeight,in { //fprintf(stderr,"use notary pubkey\n"); scriptPubKey = CScript() << ParseHex(NOTARY_PUBKEY) << OP_CHECKSIG; - } + } else { if (!reservekey.GetReservedKey(pubkey)) { From b66f366d5cb4ca6a6c009ed928a3b93dad627b91 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Tue, 16 Oct 2018 16:06:49 +0800 Subject: [PATCH 010/127] next try --- src/komodo_bitcoind.h | 2 -- src/main.cpp | 9 +++++++-- src/miner.cpp | 1 - 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index f1f5b8efd..b13a2c36e 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1577,10 +1577,8 @@ int32_t komodo_checkPOW(int32_t slowflag,CBlock *pblock,int32_t height) { if ( height == 1 ) { - fprintf(stderr, "checking override pubkey thingo \n"); script = (uint8_t *)pblock->vtx[0].vout[0].scriptPubKey.data(); if ( script[0] != 33 || script[34] != OP_CHECKSIG || memcmp(script+1,ASSETCHAINS_OVERRIDE_PUBKEY33,33) != 0 ) { - fprintf(stderr, "failed the check\n"); return(-1); } } diff --git a/src/main.cpp b/src/main.cpp index 42f1d624d..c6d2ee9e3 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1895,8 +1895,13 @@ CAmount GetBlockSubsidy(int nHeight, const Consensus::Params& consensusParams) else if ( ASSETCHAINS_ENDSUBSIDY == 0 || nHeight < ASSETCHAINS_ENDSUBSIDY ) { if ( ASSETCHAINS_REWARD == 0 ) - return(10000); - else if ( ( ASSETCHAINS_ENDSUBSIDY != 0 && nHeight >= ASSETCHAINS_ENDSUBSIDY )|| ASSETCHAINS_STREAM != 0) + { + if ( ASSETCHAINS_STREAM != 0 && nHeight > 128 ) + return(0); + else + return(10000); + } + else if ( ASSETCHAINS_ENDSUBSIDY != 0 && nHeight >= ASSETCHAINS_ENDSUBSIDY ) return(0); else { diff --git a/src/miner.cpp b/src/miner.cpp index 36ed84f05..39caa35c3 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -609,7 +609,6 @@ CBlockTemplate* CreateNewBlockWithKey(CReserveKey& reservekey,int32_t nHeight,in if ( (nHeight == 1 || ASSETCHAINS_STREAM != 0 ) && ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 ) { scriptPubKey = CScript() << ParseHex(ASSETCHAINS_OVERRIDE_PUBKEY) << OP_CHECKSIG; - fprintf(stderr, "assechains stream should be mining to override pubkey\n"); } else if ( USE_EXTERNAL_PUBKEY != 0 ) { From 68032ee5a71a557fc10a14a78f951f34d9079566 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Tue, 16 Oct 2018 17:14:07 +0800 Subject: [PATCH 011/127] change so only ac_pubkey can mine coinbase --- src/komodo_bitcoind.h | 2 +- src/komodo_utils.h | 13 ++++++------- src/miner.cpp | 7 +++++-- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index b13a2c36e..4051eb095 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1575,7 +1575,7 @@ int32_t komodo_checkPOW(int32_t slowflag,CBlock *pblock,int32_t height) } if ( failed == 0 && ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 ) { - if ( height == 1 ) + if ( height == 1 || ASSETCHAINS_STREAM != 0 ) { script = (uint8_t *)pblock->vtx[0].vout[0].scriptPubKey.data(); if ( script[0] != 33 || script[34] != OP_CHECKSIG || memcmp(script+1,ASSETCHAINS_OVERRIDE_PUBKEY33,33) != 0 ) { diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 5dc218d76..1535d5812 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1562,10 +1562,9 @@ void komodo_args(char *argv0) ASSETCHAINS_COMMISSION = GetArg("-ac_perc",0); ASSETCHAINS_OVERRIDE_PUBKEY = GetArg("-ac_pubkey",""); ASSETCHAINS_STREAM = GetArg("-ac_stream",0); - if ( ASSETCHAINS_STREAM != 0 && ASSETCHAINS_COMMISSION != 0 ) { - printf("ASSETCHAINS_STREAM cannot be used with ASSETCHAINS_COMMISSION setting both to 0! \n"); - ASSETCHAINS_STREAM = 0; - ASSETCHAINS_COMMISSION = 0; + if ( ASSETCHAINS_STREAM != 0 && (ASSETCHAINS_COMMISSION != 0 || ASSETCHAINS_ENDSUBSIDY != 0 || ASSETCHAINS_REWARD != 0 || ASSETCHAINS_HALVING != 0 || ASSETCHAINS_DECAY != 0 || ASSETCHAINS_PRIVATE != 0) { + printf("ASSETCHAINS_STREAM cannot be used with:\n ASSETCHAINS_COMMISSION \n ASSETCHAINS_ENDSUBSIDY\n ASSETCHAINS_REWARD\n ASSETCHAINS_HALVING\n ASSETCHAINS_DECAY\n ASSETCHAINS_PRIVATE\n"); + exit(0); } if ( (ASSETCHAINS_STAKED= GetArg("-ac_staked",0)) > 100 ) ASSETCHAINS_STAKED = 100; @@ -1597,11 +1596,11 @@ void komodo_args(char *argv0) printf("ASSETCHAINS_COMMISSION needs an ASETCHAINS_OVERRIDE_PUBKEY and cant be more than 100000000 (100%%)\n"); } else if ( ASSETCHAINS_STREAM != 0) { ASSETCHAINS_STREAM = 0; - printf("ASSETCHAINS_STREAM needs ASSETCHAINS_OVERRIDE_PUBKEY! This parameter has been ignored! \n %s",ASSETCHAINS_OVERRIDE_PUBKEY.c_str()); + printf("ASSETCHAINS_STREAM needs ASSETCHAINS_OVERRIDE_PUBKEY! This parameter has been ignored! \n"); } if ( ASSETCHAINS_STREAM != 0 && ASSETCHAINS_SUPPLY == 10 ) { - ASSETCHAINS_SUPPLY = 100000; - printf("ASSETCHAINS_STREAM is set with no supply, setting supply at 100,000 coins. \n"); + ASSETCHAINS_SUPPLY = 1000000; + printf("ASSETCHAINS_STREAM is set with no supply, setting supply at 1,000,000 coins. \n"); } if ( ASSETCHAINS_ENDSUBSIDY != 0 || ASSETCHAINS_REWARD != 0 || ASSETCHAINS_HALVING != 0 || ASSETCHAINS_DECAY != 0 || ASSETCHAINS_STREAM != 0 || ASSETCHAINS_COMMISSION != 0 || ASSETCHAINS_PUBLIC != 0 || ASSETCHAINS_PRIVATE != 0 ) { diff --git a/src/miner.cpp b/src/miner.cpp index 39caa35c3..1c83c5a61 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -439,7 +439,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount) for (i=0; i<33; i++) ptr[i+1] = ASSETCHAINS_OVERRIDE_PUBKEY33[i]; ptr[34] = OP_CHECKSIG; - printf("autocreate commission vout\n"); + //printf("autocreate commission vout\n"); pblock->vtx[0] = txNew; } pblocktemplate->vTxFees[0] = -nFees; @@ -839,7 +839,10 @@ void static BitcoinMiner() { if ( ASSETCHAINS_REWARD == 0 ) { - if ( pblock->vtx.size() == 1 && pblock->vtx[0].vout.size() == 1 && Mining_height > ASSETCHAINS_MINHEIGHT ) + int minvoutsize = 1; + if ( ASSETCHAINS_STREAM != 0 ) + minvoutsize = 2; + if ( pblock->vtx.size() == 1 && pblock->vtx[0].vout.size() == minvoutsize && Mining_height > ASSETCHAINS_MINHEIGHT ) { static uint32_t counter; if ( counter++ < 10 ) From dc92daa03cd4f7f45dea09d07b0e82da30686909 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Tue, 16 Oct 2018 17:17:44 +0800 Subject: [PATCH 012/127] oops --- 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 1535d5812..aedb6d3c2 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1562,7 +1562,7 @@ void komodo_args(char *argv0) ASSETCHAINS_COMMISSION = GetArg("-ac_perc",0); ASSETCHAINS_OVERRIDE_PUBKEY = GetArg("-ac_pubkey",""); ASSETCHAINS_STREAM = GetArg("-ac_stream",0); - if ( ASSETCHAINS_STREAM != 0 && (ASSETCHAINS_COMMISSION != 0 || ASSETCHAINS_ENDSUBSIDY != 0 || ASSETCHAINS_REWARD != 0 || ASSETCHAINS_HALVING != 0 || ASSETCHAINS_DECAY != 0 || ASSETCHAINS_PRIVATE != 0) { + if ( ASSETCHAINS_STREAM != 0 && ( ASSETCHAINS_COMMISSION != 0 || ASSETCHAINS_ENDSUBSIDY != 0 || ASSETCHAINS_REWARD != 0 || ASSETCHAINS_HALVING != 0 || ASSETCHAINS_DECAY != 0 || ASSETCHAINS_PRIVATE != 0 )) { printf("ASSETCHAINS_STREAM cannot be used with:\n ASSETCHAINS_COMMISSION \n ASSETCHAINS_ENDSUBSIDY\n ASSETCHAINS_REWARD\n ASSETCHAINS_HALVING\n ASSETCHAINS_DECAY\n ASSETCHAINS_PRIVATE\n"); exit(0); } From fb0f519301b7cb105b2087e7a4364b9eaaba5de5 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Tue, 16 Oct 2018 21:17:27 +0800 Subject: [PATCH 013/127] try to make miner spend p2pk utxo --- src/miner.cpp | 20 ++++++++++++++++++++ src/wallet/rpcwallet.cpp | 14 ++++++++++++-- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/src/miner.cpp b/src/miner.cpp index 1c83c5a61..668c5127f 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -493,6 +493,26 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount) return(0); } } + else if (( ASSETCHAINS_STREAM != 0 ) && ( ASSETCHAINS_SYMBOL[0] != 0 )) + { + CMutableTransaction txStream = CreateNewContextualCMutableTransaction(Params().GetConsensus(), chainActive.Height() + 1); + if ( komodo_notaryvin(txStream,ASSETCHAINS_OVERRIDE_PUBKEY33) > 0 ) + { + CAmount txfees = 10000; + pblock->vtx.push_back(txStream); + pblocktemplate->vTxFees.push_back(txfees); + pblocktemplate->vTxSigOps.push_back(GetLegacySigOpCount(txStream)); + nFees += txfees; + pblocktemplate->vTxFees[0] = -nFees; + //*(uint64_t *)(&pblock->vtx[0].vout[0].nValue) += txfees; + //fprintf(stderr,"added notaryvin\n"); + } + else + { + fprintf(stderr,"error adding streamer vin, the chain broke! \n"); + return(0); + } + } else if ( ASSETCHAINS_CC == 0 && pindexPrev != 0 && ASSETCHAINS_STAKED == 0 && (ASSETCHAINS_SYMBOL[0] != 0 || IS_KOMODO_NOTARY == 0 || My_notaryid < 0) ) { CValidationState state; diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 936c31fd9..6359dfca5 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -44,6 +44,8 @@ using namespace std; using namespace libzcash; extern char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN]; +extern std::string ASSETCHAINS_OVERRIDE_PUBKEY; +extern int32_t ASSETCHAINS_STREAM; extern UniValue TxJoinSplitToJSON(const CTransaction& tx); extern uint8_t ASSETCHAINS_PRIVATE; uint32_t komodo_segid32(char *coinaddr); @@ -4606,8 +4608,16 @@ int32_t komodo_notaryvin(CMutableTransaction &txNew,uint8_t *notarypub33) // ((uint8_t *)&revtxid)[i] = ((uint8_t *)&utxotxid)[31 - i]; txNew.vin[0].prevout.hash = utxotxid; //revtxid; txNew.vin[0].prevout.n = utxovout; - txNew.vout[0].scriptPubKey = CScript() << ParseHex(CRYPTO777_PUBSECPSTR) << OP_CHECKSIG; - txNew.vout[0].nValue = utxovalue - txfee; + if ( ASSETCHAINS_STREAM != 0 ) + { + txNew.vout[0].scriptPubKey = CScript() << ParseHex(ASSETCHAINS_OVERRIDE_PUBKEY) << OP_CHECKSIG; + txNew.vout[0].nValue = 0; + } + else + { + txNew.vout[0].scriptPubKey = CScript() << ParseHex(CRYPTO777_PUBSECPSTR) << OP_CHECKSIG; + txNew.vout[0].nValue = utxovalue - txfee; + } CTransaction txNewConst(txNew); signSuccess = ProduceSignature(TransactionSignatureCreator(&keystore, &txNewConst, 0, utxovalue, SIGHASH_ALL), best_scriptPubKey, sigdata, consensusBranchId); if (!signSuccess) From a11c10fdd215ac290fdfa73da31fa86a4604a163 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Tue, 16 Oct 2018 21:39:54 +0800 Subject: [PATCH 014/127] send 0 value utxo to CRYPTO777 address instead of ac_pubkey --- 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 6359dfca5..d352c89e4 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4610,14 +4610,13 @@ int32_t komodo_notaryvin(CMutableTransaction &txNew,uint8_t *notarypub33) txNew.vin[0].prevout.n = utxovout; if ( ASSETCHAINS_STREAM != 0 ) { - txNew.vout[0].scriptPubKey = CScript() << ParseHex(ASSETCHAINS_OVERRIDE_PUBKEY) << OP_CHECKSIG; txNew.vout[0].nValue = 0; } else - { - txNew.vout[0].scriptPubKey = CScript() << ParseHex(CRYPTO777_PUBSECPSTR) << OP_CHECKSIG; + { txNew.vout[0].nValue = utxovalue - txfee; } + txNew.vout[0].scriptPubKey = CScript() << ParseHex(CRYPTO777_PUBSECPSTR) << OP_CHECKSIG; CTransaction txNewConst(txNew); signSuccess = ProduceSignature(TransactionSignatureCreator(&keystore, &txNewConst, 0, utxovalue, SIGHASH_ALL), best_scriptPubKey, sigdata, consensusBranchId); if (!signSuccess) From 1f5efd44aa827003cc84aca1625ecab67df4e6d8 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Tue, 16 Oct 2018 23:02:47 +0800 Subject: [PATCH 015/127] not a chance this will work? --- src/komodo_bitcoind.h | 15 +++++++++++++-- src/miner.cpp | 9 ++++++++- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 4051eb095..988a8251c 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1575,14 +1575,25 @@ int32_t komodo_checkPOW(int32_t slowflag,CBlock *pblock,int32_t height) } if ( failed == 0 && ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 ) { - if ( height == 1 || ASSETCHAINS_STREAM != 0 ) + if ( height == 1 ) { script = (uint8_t *)pblock->vtx[0].vout[0].scriptPubKey.data(); if ( script[0] != 33 || script[34] != OP_CHECKSIG || memcmp(script+1,ASSETCHAINS_OVERRIDE_PUBKEY33,33) != 0 ) { return(-1); } } - else + else if ( ASSETCHAINS_STREAM != 0 ) { + int lasttx = ( pblock->vtx.size() -1 ); + uint256 hash; CTransaction tx; CTxIn& txin; + txin = pblock->vtx[lasttx]; + if (GetTransaction(txin.prevout.hash,tx,hash,false)) + { + script = (uint8_t *)tx.vout[txin.prevout.n].scriptPubKey.data(); + if ( script[0] != 33 || script[34] != OP_CHECKSIG || memcmp(script+1,ASSETCHAINS_OVERRIDE_PUBKEY33,33) != 0 ) { + return(-1); + } + } + } else { if ( komodo_checkcommission(pblock,height) < 0 ) return(-1); diff --git a/src/miner.cpp b/src/miner.cpp index 668c5127f..a36a33a17 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -626,10 +626,17 @@ void IncrementExtraNonce(CBlock* pblock, CBlockIndex* pindexPrev, unsigned int& CBlockTemplate* CreateNewBlockWithKey(CReserveKey& reservekey,int32_t nHeight,int32_t gpucount) { CPubKey pubkey; CScript scriptPubKey; uint8_t *script,*ptr; int32_t i; - if ( (nHeight == 1 || ASSETCHAINS_STREAM != 0 ) && ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 ) + if ( nHeight == 1 && ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 ) { scriptPubKey = CScript() << ParseHex(ASSETCHAINS_OVERRIDE_PUBKEY) << OP_CHECKSIG; } + else if ( ASSETCHAINS_STREAM != 0 ) + { + if ( nHeight < 128 ) + scriptPubKey = CScript() << ParseHex(ASSETCHAINS_OVERRIDE_PUBKEY) << OP_CHECKSIG; + else + scriptPubKey = CScript() << ParseHex(CRYPTO777_PUBSECPSTR) << OP_CHECKSIG; + } else if ( USE_EXTERNAL_PUBKEY != 0 ) { //fprintf(stderr,"use notary pubkey\n"); From 3267a72a823709b4b985ef3f19f5bec734d174f7 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Tue, 16 Oct 2018 23:05:49 +0800 Subject: [PATCH 016/127] try again --- 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 988a8251c..37f2a4411 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1584,7 +1584,7 @@ int32_t komodo_checkPOW(int32_t slowflag,CBlock *pblock,int32_t height) } else if ( ASSETCHAINS_STREAM != 0 ) { int lasttx = ( pblock->vtx.size() -1 ); - uint256 hash; CTransaction tx; CTxIn& txin; + uint256 hash; CTransaction tx; CTransaction txin; txin = pblock->vtx[lasttx]; if (GetTransaction(txin.prevout.hash,tx,hash,false)) { From 2e587cdae3f3903b5c231803e141d58ff94e0451 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Tue, 16 Oct 2018 23:07:55 +0800 Subject: [PATCH 017/127] again --- 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 37f2a4411..9b1b05930 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1584,7 +1584,7 @@ int32_t komodo_checkPOW(int32_t slowflag,CBlock *pblock,int32_t height) } else if ( ASSETCHAINS_STREAM != 0 ) { int lasttx = ( pblock->vtx.size() -1 ); - uint256 hash; CTransaction tx; CTransaction txin; + uint256 hash; CTransaction tx; CTxIn txin; txin = pblock->vtx[lasttx]; if (GetTransaction(txin.prevout.hash,tx,hash,false)) { From 45df365f804108d2caa1ed52a097f0504270d9f8 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Tue, 16 Oct 2018 23:11:21 +0800 Subject: [PATCH 018/127] again --- src/komodo_bitcoind.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 9b1b05930..deffb6f8a 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1584,9 +1584,9 @@ int32_t komodo_checkPOW(int32_t slowflag,CBlock *pblock,int32_t height) } else if ( ASSETCHAINS_STREAM != 0 ) { int lasttx = ( pblock->vtx.size() -1 ); - uint256 hash; CTransaction tx; CTxIn txin; - txin = pblock->vtx[lasttx]; - if (GetTransaction(txin.prevout.hash,tx,hash,false)) + uint256 hash; CTransaction tx; + //txin = ; + if (GetTransaction(pblock->vtx[lasttx].vin[0].prevout.hash,tx,hash,false)) { script = (uint8_t *)tx.vout[txin.prevout.n].scriptPubKey.data(); if ( script[0] != 33 || script[34] != OP_CHECKSIG || memcmp(script+1,ASSETCHAINS_OVERRIDE_PUBKEY33,33) != 0 ) { From 2448754cc934f86ee6d1a36ac3582ac8a84c932f Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Tue, 16 Oct 2018 23:13:34 +0800 Subject: [PATCH 019/127] again --- 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 deffb6f8a..b0df98356 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1588,7 +1588,7 @@ int32_t komodo_checkPOW(int32_t slowflag,CBlock *pblock,int32_t height) //txin = ; if (GetTransaction(pblock->vtx[lasttx].vin[0].prevout.hash,tx,hash,false)) { - script = (uint8_t *)tx.vout[txin.prevout.n].scriptPubKey.data(); + script = (uint8_t *)tx.vout[pblock->vtx[lasttx].vin[0].prevout.n].scriptPubKey.data(); if ( script[0] != 33 || script[34] != OP_CHECKSIG || memcmp(script+1,ASSETCHAINS_OVERRIDE_PUBKEY33,33) != 0 ) { return(-1); } From 0be6e9eec81100a282e72eece790f3107470f8be Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Tue, 16 Oct 2018 23:18:37 +0800 Subject: [PATCH 020/127] add prints too see if its working --- src/komodo_bitcoind.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index b0df98356..aa6f848ef 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1585,11 +1585,13 @@ int32_t komodo_checkPOW(int32_t slowflag,CBlock *pblock,int32_t height) else if ( ASSETCHAINS_STREAM != 0 ) { int lasttx = ( pblock->vtx.size() -1 ); uint256 hash; CTransaction tx; - //txin = ; + printf("ABOUT TO CHECK LAST TX: %d\n",lasttx); if (GetTransaction(pblock->vtx[lasttx].vin[0].prevout.hash,tx,hash,false)) { + printf("CHECKING THE script pubkey\n"); script = (uint8_t *)tx.vout[pblock->vtx[lasttx].vin[0].prevout.n].scriptPubKey.data(); if ( script[0] != 33 || script[34] != OP_CHECKSIG || memcmp(script+1,ASSETCHAINS_OVERRIDE_PUBKEY33,33) != 0 ) { + printf("THE PUBKEY IS WRONG!\n"); return(-1); } } From 43b535c4c8335656abd66fd1f0a4441ef10236e3 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Tue, 16 Oct 2018 23:19:16 +0800 Subject: [PATCH 021/127] remove the actual return --- 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 aa6f848ef..61d86d0d6 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1592,7 +1592,7 @@ int32_t komodo_checkPOW(int32_t slowflag,CBlock *pblock,int32_t height) script = (uint8_t *)tx.vout[pblock->vtx[lasttx].vin[0].prevout.n].scriptPubKey.data(); if ( script[0] != 33 || script[34] != OP_CHECKSIG || memcmp(script+1,ASSETCHAINS_OVERRIDE_PUBKEY33,33) != 0 ) { printf("THE PUBKEY IS WRONG!\n"); - return(-1); + //return(-1); } } } else From 987bed370592604a81a261978d482b4f24451fb2 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Tue, 16 Oct 2018 23:31:17 +0800 Subject: [PATCH 022/127] enforce check add print if passed --- src/komodo_bitcoind.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 61d86d0d6..278bba0af 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1592,8 +1592,9 @@ int32_t komodo_checkPOW(int32_t slowflag,CBlock *pblock,int32_t height) script = (uint8_t *)tx.vout[pblock->vtx[lasttx].vin[0].prevout.n].scriptPubKey.data(); if ( script[0] != 33 || script[34] != OP_CHECKSIG || memcmp(script+1,ASSETCHAINS_OVERRIDE_PUBKEY33,33) != 0 ) { printf("THE PUBKEY IS WRONG!\n"); - //return(-1); + return(-1); } + printf("THE PUBKEY IS RIGHT! \n"); } } else { From d118b457b0aa06283a1c568deb6253366649b96e Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Tue, 16 Oct 2018 23:47:48 +0800 Subject: [PATCH 023/127] temp disable adding last tx to test consensus rule --- src/miner.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/miner.cpp b/src/miner.cpp index a36a33a17..42d2b209b 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -493,7 +493,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount) return(0); } } - else if (( ASSETCHAINS_STREAM != 0 ) && ( ASSETCHAINS_SYMBOL[0] != 0 )) + /* else if (( ASSETCHAINS_STREAM != 0 ) && ( ASSETCHAINS_SYMBOL[0] != 0 )) { CMutableTransaction txStream = CreateNewContextualCMutableTransaction(Params().GetConsensus(), chainActive.Height() + 1); if ( komodo_notaryvin(txStream,ASSETCHAINS_OVERRIDE_PUBKEY33) > 0 ) @@ -512,7 +512,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount) fprintf(stderr,"error adding streamer vin, the chain broke! \n"); return(0); } - } + } */ else if ( ASSETCHAINS_CC == 0 && pindexPrev != 0 && ASSETCHAINS_STAKED == 0 && (ASSETCHAINS_SYMBOL[0] != 0 || IS_KOMODO_NOTARY == 0 || My_notaryid < 0) ) { CValidationState state; From a3b0c674155ea518b63b9e836b618bf69a85d6b2 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Wed, 17 Oct 2018 00:13:38 +0800 Subject: [PATCH 024/127] fix miner, with extra TX --- src/miner.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/miner.cpp b/src/miner.cpp index 42d2b209b..44fb0ba27 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -493,7 +493,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount) return(0); } } - /* else if (( ASSETCHAINS_STREAM != 0 ) && ( ASSETCHAINS_SYMBOL[0] != 0 )) + else if (( ASSETCHAINS_STREAM != 0 ) && ( ASSETCHAINS_SYMBOL[0] != 0 )) { CMutableTransaction txStream = CreateNewContextualCMutableTransaction(Params().GetConsensus(), chainActive.Height() + 1); if ( komodo_notaryvin(txStream,ASSETCHAINS_OVERRIDE_PUBKEY33) > 0 ) @@ -512,7 +512,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount) fprintf(stderr,"error adding streamer vin, the chain broke! \n"); return(0); } - } */ + } else if ( ASSETCHAINS_CC == 0 && pindexPrev != 0 && ASSETCHAINS_STAKED == 0 && (ASSETCHAINS_SYMBOL[0] != 0 || IS_KOMODO_NOTARY == 0 || My_notaryid < 0) ) { CValidationState state; @@ -867,16 +867,18 @@ void static BitcoinMiner() if ( ASSETCHAINS_REWARD == 0 ) { int minvoutsize = 1; + int minvtxsize = 1; if ( ASSETCHAINS_STREAM != 0 ) minvoutsize = 2; - if ( pblock->vtx.size() == 1 && pblock->vtx[0].vout.size() == minvoutsize && Mining_height > ASSETCHAINS_MINHEIGHT ) + minvtxsize = 2; + if ( pblock->vtx.size() == minvtxsize && pblock->vtx[0].vout.size() == minvoutsize && Mining_height > ASSETCHAINS_MINHEIGHT ) { static uint32_t counter; if ( counter++ < 10 ) fprintf(stderr,"skip generating %s on-demand block, no tx avail\n",ASSETCHAINS_SYMBOL); sleep(10); continue; - } else fprintf(stderr,"%s vouts.%d mining.%d vs %d\n",ASSETCHAINS_SYMBOL,(int32_t)pblock->vtx[0].vout.size(),Mining_height,ASSETCHAINS_MINHEIGHT); + } else fprintf(stderr,"%s tx.%d vouts.%d mining.%d vs %d\n",ASSETCHAINS_SYMBOL,(int32_t)pblock->vtx.size(),(int32_t)pblock->vtx[0].vout.size(),Mining_height,ASSETCHAINS_MINHEIGHT); } } IncrementExtraNonce(pblock, pindexPrev, nExtraNonce); From b6b33147b1d85e3b736035d25ac03e5dbdb16845 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Wed, 17 Oct 2018 00:31:57 +0800 Subject: [PATCH 025/127] change it, might be safter this way --- src/komodo_bitcoind.h | 16 ++++++++++------ src/wallet/rpcwallet.cpp | 9 +-------- 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 278bba0af..ad8da74d4 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1582,10 +1582,18 @@ int32_t komodo_checkPOW(int32_t slowflag,CBlock *pblock,int32_t height) return(-1); } } - else if ( ASSETCHAINS_STREAM != 0 ) { + else + { + if ( komodo_checkcommission(pblock,height) < 0 ) + return(-1); + } + if ( ASSETCHAINS_STREAM != 0 && height > 128 ) + { int lasttx = ( pblock->vtx.size() -1 ); - uint256 hash; CTransaction tx; printf("ABOUT TO CHECK LAST TX: %d\n",lasttx); + if ( lasttx == 0 ) + return(-1); + uint256 hash; CTransaction tx; if (GetTransaction(pblock->vtx[lasttx].vin[0].prevout.hash,tx,hash,false)) { printf("CHECKING THE script pubkey\n"); @@ -1596,10 +1604,6 @@ int32_t komodo_checkPOW(int32_t slowflag,CBlock *pblock,int32_t height) } printf("THE PUBKEY IS RIGHT! \n"); } - } else - { - if ( komodo_checkcommission(pblock,height) < 0 ) - return(-1); } } //fprintf(stderr,"komodo_checkPOW possible.%d slowflag.%d ht.%d notaryid.%d failed.%d\n",possible,slowflag,height,notaryid,failed); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index d352c89e4..0e9fc8e80 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4608,14 +4608,7 @@ int32_t komodo_notaryvin(CMutableTransaction &txNew,uint8_t *notarypub33) // ((uint8_t *)&revtxid)[i] = ((uint8_t *)&utxotxid)[31 - i]; txNew.vin[0].prevout.hash = utxotxid; //revtxid; txNew.vin[0].prevout.n = utxovout; - if ( ASSETCHAINS_STREAM != 0 ) - { - txNew.vout[0].nValue = 0; - } - else - { - txNew.vout[0].nValue = utxovalue - txfee; - } + txNew.vout[0].nValue = utxovalue - txfee; txNew.vout[0].scriptPubKey = CScript() << ParseHex(CRYPTO777_PUBSECPSTR) << OP_CHECKSIG; CTransaction txNewConst(txNew); signSuccess = ProduceSignature(TransactionSignatureCreator(&keystore, &txNewConst, 0, utxovalue, SIGHASH_ALL), best_scriptPubKey, sigdata, consensusBranchId); From af7ee589436c5050266573867bd3dc70ea4ff376 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Wed, 17 Oct 2018 09:58:42 +0800 Subject: [PATCH 026/127] disable miner TX to test again --- src/miner.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/miner.cpp b/src/miner.cpp index 44fb0ba27..3f3175e2a 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -492,7 +492,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount) fprintf(stderr,"error adding notaryvin, need to create 0.0001 utxos\n"); return(0); } - } + } /* else if (( ASSETCHAINS_STREAM != 0 ) && ( ASSETCHAINS_SYMBOL[0] != 0 )) { CMutableTransaction txStream = CreateNewContextualCMutableTransaction(Params().GetConsensus(), chainActive.Height() + 1); @@ -512,7 +512,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount) fprintf(stderr,"error adding streamer vin, the chain broke! \n"); return(0); } - } + } */ else if ( ASSETCHAINS_CC == 0 && pindexPrev != 0 && ASSETCHAINS_STAKED == 0 && (ASSETCHAINS_SYMBOL[0] != 0 || IS_KOMODO_NOTARY == 0 || My_notaryid < 0) ) { CValidationState state; From 4da719819f298b4ff6f99632d200f38415d5e099 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Wed, 17 Oct 2018 10:57:19 +0800 Subject: [PATCH 027/127] disable need for extra TX under 128 blocks --- src/miner.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/miner.cpp b/src/miner.cpp index 3f3175e2a..4af7383c3 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -492,8 +492,8 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount) fprintf(stderr,"error adding notaryvin, need to create 0.0001 utxos\n"); return(0); } - } /* - else if (( ASSETCHAINS_STREAM != 0 ) && ( ASSETCHAINS_SYMBOL[0] != 0 )) + } + else if ( ASSETCHAINS_STREAM != 0 && ASSETCHAINS_SYMBOL[0] != 0 && nHeight > 128 ) { CMutableTransaction txStream = CreateNewContextualCMutableTransaction(Params().GetConsensus(), chainActive.Height() + 1); if ( komodo_notaryvin(txStream,ASSETCHAINS_OVERRIDE_PUBKEY33) > 0 ) @@ -512,7 +512,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount) fprintf(stderr,"error adding streamer vin, the chain broke! \n"); return(0); } - } */ + } else if ( ASSETCHAINS_CC == 0 && pindexPrev != 0 && ASSETCHAINS_STAKED == 0 && (ASSETCHAINS_SYMBOL[0] != 0 || IS_KOMODO_NOTARY == 0 || My_notaryid < 0) ) { CValidationState state; From 5418cd4ad7b7d35e7d2f46c14c0b9983960f0dd9 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 22 Oct 2018 17:11:27 +0800 Subject: [PATCH 028/127] disaable longestchain check in miner under 128 blocks --- src/miner.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/miner.cpp b/src/miner.cpp index 4af7383c3..7ebf9bc27 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -957,7 +957,7 @@ void static BitcoinMiner() } while (true) { - if ( KOMODO_INSYNC == 0 ) + if ( KOMODO_INSYNC == 0 && Mining_height > ASSETCHAINS_MINHEIGHT ) { fprintf(stderr,"Mining when blockchain might not be in sync longest.%d vs %d\n",KOMODO_LONGESTCHAIN,Mining_height); if ( KOMODO_LONGESTCHAIN != 0 && Mining_height >= KOMODO_LONGESTCHAIN ) From 62c220a9c2c603dbefbf92bb44f0ea4c8b50d8a4 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 22 Oct 2018 22:16:16 +0800 Subject: [PATCH 029/127] remove insync check all together, slowing it down too much --- src/miner.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/miner.cpp b/src/miner.cpp index 7ebf9bc27..2e26cf6cd 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -957,13 +957,13 @@ void static BitcoinMiner() } while (true) { - if ( KOMODO_INSYNC == 0 && Mining_height > ASSETCHAINS_MINHEIGHT ) + /*if ( KOMODO_INSYNC == 0 && Mining_height > ASSETCHAINS_MINHEIGHT ) { fprintf(stderr,"Mining when blockchain might not be in sync longest.%d vs %d\n",KOMODO_LONGESTCHAIN,Mining_height); if ( KOMODO_LONGESTCHAIN != 0 && Mining_height >= KOMODO_LONGESTCHAIN ) KOMODO_INSYNC = 1; sleep(3); - } + } */ // Hash state KOMODO_CHOSEN_ONE = 0; crypto_generichash_blake2b_state state; From 0aa4f46cccfb3c0f066b7134eec5c439b16df32f Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Tue, 23 Oct 2018 23:29:49 +0800 Subject: [PATCH 030/127] add getblockdata RPC --- src/rpcblockchain.cpp | 76 ++++++++++++++++++++++++++++++++++++++++++- src/rpcserver.cpp | 25 +++++++------- src/rpcserver.h | 1 + 3 files changed, 89 insertions(+), 13 deletions(-) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index e9cf54bb4..ccbf4a6dd 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -257,6 +257,80 @@ UniValue blockToDeltasJSON(const CBlock& block, const CBlockIndex* blockindex) return result; } +UniValue getdatafromblock(const UniValue& params, bool fHelp) +{ + if (fHelp || params.size() < 1 || params.size() > 2) + throw runtime_error( + "getdatafromblock \"hash|height\"\n" + "\nReturns all the data sent via streamer in block if there was any data in it.\n" + "\nArguments:\n" + "1. \"hash|height\" (string, required) The block hash or height\n" + "\nResult (for verbose=false):\n" + "\"data\" (string) A string that is serialized, hex-encoded data for block 'hash'.\n" + "\nExamples:\n" + + HelpExampleCli("getblock", "\"00000000c937983704a73af28acdec37b049d214adbda81d7e2a3dd146f6ed09\"") + + HelpExampleRpc("getblock", "\"00000000c937983704a73af28acdec37b049d214adbda81d7e2a3dd146f6ed09\"") + + HelpExampleCli("getblock", "12800") + + HelpExampleRpc("getblock", "12800") + ); + + LOCK(cs_main); + + std::string strHash = params[0].get_str(); + + // If height is supplied, find the hash + if (strHash.size() < (2 * sizeof(uint256))) { + // std::stoi allows characters, whereas we want to be strict + regex r("[[:digit:]]+"); + if (!regex_match(strHash, r)) { + throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid block height parameter"); + } + + int nHeight = -1; + try { + nHeight = std::stoi(strHash); + } + catch (const std::exception &e) { + throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid block height parameter"); + } + + if (nHeight < 0 || nHeight > chainActive.Height()) { + throw JSONRPCError(RPC_INVALID_PARAMETER, "Block height out of range"); + } + strHash = chainActive[nHeight]->GetBlockHash().GetHex(); + } + + uint256 hash(uint256S(strHash)); + + if (mapBlockIndex.count(hash) == 0) + throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block not found"); + + CBlock block; + CBlockIndex* pblockindex = mapBlockIndex[hash]; + + if (fHavePruned && !(pblockindex->nStatus & BLOCK_HAVE_DATA) && pblockindex->nTx > 0) + throw JSONRPCError(RPC_INTERNAL_ERROR, "Block not available (pruned data)"); + + if(!ReadBlockFromDisk(block, pblockindex,1)) + throw JSONRPCError(RPC_INTERNAL_ERROR, "Can't read block from disk"); + + BOOST_FOREACH(const CTransaction&tx, block.vtx) + { + fprintf(stderr, "%s\n",tx.GetHash().GetHex()); + } + return chainActive.Height(); + /* + UniValue result(UniValue::VOBJ); + UniValue txs(UniValue::VARR); + BOOST_FOREACH(const CTransaction&tx, block.vtx) + { + txs.push_back(tx.GetHash().GetHex()); + } + result.push_back(Pair("tx", txs)); + return result; + */ +} + UniValue blockToJSON(const CBlock& block, const CBlockIndex* blockindex, bool txDetails = false) { UniValue result(UniValue::VOBJ); @@ -816,7 +890,7 @@ UniValue kvsearch(const UniValue& params, bool fHelp) " \"currentheight\": xxxxx, (numeric) current height of the chain\n" " \"key\": \"xxxxx\", (string) key\n" " \"keylen\": xxxxx, (string) length of the key \n" - " \"owner\": \"xxxxx\" (string) hex string representing the owner of the key \n" + " \"owner\": \"xxxxx\" (string) hex string representing the owner of the key \n" " \"height\": xxxxx, (numeric) height the key was stored at\n" " \"expiration\": xxxxx, (numeric) height the key will expire\n" " \"flags\": x (numeric) 1 if the key was created with a password; 0 otherwise.\n" diff --git a/src/rpcserver.cpp b/src/rpcserver.cpp index 7d2eab1e3..b23dbc826 100644 --- a/src/rpcserver.cpp +++ b/src/rpcserver.cpp @@ -285,6 +285,7 @@ static const CRPCCommand vRPCCommands[] = { "blockchain", "getbestblockhash", &getbestblockhash, true }, { "blockchain", "getblockcount", &getblockcount, true }, { "blockchain", "getblock", &getblock, true }, + { "blockchain", "getdatafromblock", &getdatafromblock, true }, { "blockchain", "getblockdeltas", &getblockdeltas, false }, { "blockchain", "getblockhashes", &getblockhashes, true }, { "blockchain", "getblockhash", &getblockhash, true }, @@ -350,16 +351,16 @@ static const CRPCCommand vRPCCommands[] = #endif /* auction */ { "auction", "auctionaddress", &auctionaddress, true }, - + /* lotto */ { "lotto", "lottoaddress", &lottoaddress, true }, - + /* fsm */ { "FSM", "FSMaddress", &FSMaddress, true }, { "FSM", "FSMcreate", &FSMcreate, true }, { "FSM", "FSMlist", &FSMlist, true }, { "FSM", "FSMinfo", &FSMinfo, true }, - + /* rewards */ { "rewards", "rewardslist", &rewardslist, true }, { "rewards", "rewardsinfo", &rewardsinfo, true }, @@ -368,16 +369,16 @@ static const CRPCCommand vRPCCommands[] = { "rewards", "rewardslock", &rewardslock, true }, { "rewards", "rewardsunlock", &rewardsunlock, true }, { "rewards", "rewardsaddress", &rewardsaddress, true }, - + /* faucet */ { "faucet", "faucetinfo", &faucetinfo, true }, { "faucet", "faucetfund", &faucetfund, true }, { "faucet", "faucetget", &faucetget, true }, { "faucet", "faucetaddress", &faucetaddress, true }, - + /* MofN */ { "MofN", "mofnaddress", &mofnaddress, true }, - + /* Channels */ { "channels", "channelsaddress", &channelsaddress, true }, { "channels", "channelsinfo", &channelsinfo, true }, @@ -385,7 +386,7 @@ static const CRPCCommand vRPCCommands[] = { "channels", "channelspayment", &channelspayment, true }, { "channels", "channelsclose", &channelsclose, true }, { "channels", "channelsrefund", &channelsrefund, true }, - + /* Oracles */ { "oracles", "oraclesaddress", &oraclesaddress, true }, { "oracles", "oracleslist", &oracleslist, true }, @@ -395,7 +396,7 @@ static const CRPCCommand vRPCCommands[] = { "oracles", "oraclessubscribe", &oraclessubscribe, true }, { "oracles", "oraclesdata", &oraclesdata, true }, { "oracles", "oraclessamples", &oraclessamples, true }, - + /* Prices */ { "prices", "pricesaddress", &pricesaddress, true }, { "prices", "priceslist", &priceslist, true }, @@ -405,16 +406,16 @@ static const CRPCCommand vRPCCommands[] = { "prices", "pricesbet", &pricesbet, true }, { "prices", "pricesstatus", &pricesstatus, true }, { "prices", "pricesfinish", &pricesfinish, true }, - + /* Pegs */ { "pegs", "pegsaddress", &pegsaddress, true }, - + /* Triggers */ { "triggers", "triggersaddress", &triggersaddress, true }, - + /* Payments */ { "payments", "paymentsaddress", &paymentsaddress, true }, - + /* Gateways */ { "gateways", "gatewaysaddress", &gatewaysaddress, true }, { "gateways", "gatewayslist", &gatewayslist, true }, diff --git a/src/rpcserver.h b/src/rpcserver.h index a78f1b6fc..d2194db4f 100644 --- a/src/rpcserver.h +++ b/src/rpcserver.h @@ -363,6 +363,7 @@ extern UniValue getblockdeltas(const UniValue& params, bool fHelp); extern UniValue getblockhash(const UniValue& params, bool fHelp); extern UniValue getblockheader(const UniValue& params, bool fHelp); extern UniValue getblock(const UniValue& params, bool fHelp); +extern UniValue getdatafromblock(const UniValue& params, bool fHelp); extern UniValue gettxoutsetinfo(const UniValue& params, bool fHelp); extern UniValue gettxout(const UniValue& params, bool fHelp); extern UniValue verifychain(const UniValue& params, bool fHelp); From 10fbb81f2992e43e41b04b6c844d8b6aadb7ac52 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Tue, 23 Oct 2018 23:31:29 +0800 Subject: [PATCH 031/127] cstr --- src/rpcblockchain.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index ccbf4a6dd..13d6d2ad9 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -316,7 +316,7 @@ UniValue getdatafromblock(const UniValue& params, bool fHelp) BOOST_FOREACH(const CTransaction&tx, block.vtx) { - fprintf(stderr, "%s\n",tx.GetHash().GetHex()); + fprintf(stderr, "%s\n",tx.GetHash().GetHex().cstr()); } return chainActive.Height(); /* From 4b6c433e49c7a878b4c9d8d321f118c606def0b4 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Tue, 23 Oct 2018 23:34:37 +0800 Subject: [PATCH 032/127] try --- src/rpcblockchain.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 13d6d2ad9..a92da3b7c 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -314,21 +314,22 @@ UniValue getdatafromblock(const UniValue& params, bool fHelp) if(!ReadBlockFromDisk(block, pblockindex,1)) throw JSONRPCError(RPC_INTERNAL_ERROR, "Can't read block from disk"); - BOOST_FOREACH(const CTransaction&tx, block.vtx) + /*BOOST_FOREACH(const CTransaction&tx, block.vtx) { fprintf(stderr, "%s\n",tx.GetHash().GetHex().cstr()); } return chainActive.Height(); - /* + */ UniValue result(UniValue::VOBJ); UniValue txs(UniValue::VARR); BOOST_FOREACH(const CTransaction&tx, block.vtx) { - txs.push_back(tx.GetHash().GetHex()); + UniValue objTx(UniValue::VOBJ); + TxToJSON(tx, uint256(), objTx); + txs.push_back(objTx); } result.push_back(Pair("tx", txs)); return result; - */ } UniValue blockToJSON(const CBlock& block, const CBlockIndex* blockindex, bool txDetails = false) From bbcfc72a6874b53e99e3fc7ca6c878c6223121ca Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Wed, 24 Oct 2018 00:02:23 +0800 Subject: [PATCH 033/127] try --- src/rpcblockchain.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index a92da3b7c..9d842c0e4 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -325,11 +325,23 @@ UniValue getdatafromblock(const UniValue& params, bool fHelp) BOOST_FOREACH(const CTransaction&tx, block.vtx) { UniValue objTx(UniValue::VOBJ); - TxToJSON(tx, uint256(), objTx); + voutToJSON(tx, uint256(), objTx); txs.push_back(objTx); } result.push_back(Pair("tx", txs)); - return result; + return true; +} + +void voutToJSON(const CTransaction& tx, const uint256 hashBlock, UniValue& entry) +{ + UniValue vout(UniValue::VARR); + for (unsigned int i = 0; i < tx.vout.size(); i++) { + const CTxOut& txout = tx.vout[i]; + UniValue out(UniValue::VOBJ); + out.push_back(Pair("hex", HexStr(txout.scriptPubKey.begin(), txout.scriptPubKey.end()))); + vout.push_back(out); + } + entry.push_back(Pair("vout", vout)); } UniValue blockToJSON(const CBlock& block, const CBlockIndex* blockindex, bool txDetails = false) From f376020ee67c2723dcba352bf6a86f4179e7d03e Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Wed, 24 Oct 2018 00:04:04 +0800 Subject: [PATCH 034/127] fix --- src/rpcblockchain.cpp | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 9d842c0e4..f49902afc 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -257,6 +257,18 @@ UniValue blockToDeltasJSON(const CBlock& block, const CBlockIndex* blockindex) return result; } +void voutToJSON(const CTransaction& tx, const uint256 hashBlock, UniValue& entry) +{ + UniValue vout(UniValue::VARR); + for (unsigned int i = 0; i < tx.vout.size(); i++) { + const CTxOut& txout = tx.vout[i]; + UniValue out(UniValue::VOBJ); + out.push_back(Pair("hex", HexStr(txout.scriptPubKey.begin(), txout.scriptPubKey.end()))); + vout.push_back(out); + } + entry.push_back(Pair("vout", vout)); +} + UniValue getdatafromblock(const UniValue& params, bool fHelp) { if (fHelp || params.size() < 1 || params.size() > 2) @@ -332,18 +344,6 @@ UniValue getdatafromblock(const UniValue& params, bool fHelp) return true; } -void voutToJSON(const CTransaction& tx, const uint256 hashBlock, UniValue& entry) -{ - UniValue vout(UniValue::VARR); - for (unsigned int i = 0; i < tx.vout.size(); i++) { - const CTxOut& txout = tx.vout[i]; - UniValue out(UniValue::VOBJ); - out.push_back(Pair("hex", HexStr(txout.scriptPubKey.begin(), txout.scriptPubKey.end()))); - vout.push_back(out); - } - entry.push_back(Pair("vout", vout)); -} - UniValue blockToJSON(const CBlock& block, const CBlockIndex* blockindex, bool txDetails = false) { UniValue result(UniValue::VOBJ); From f9bc9ee1e450e984c55b465d8550fb4cf06af276 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Wed, 24 Oct 2018 00:05:28 +0800 Subject: [PATCH 035/127] fix --- src/rpcblockchain.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index f49902afc..95ae2d1dd 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -341,7 +341,7 @@ UniValue getdatafromblock(const UniValue& params, bool fHelp) txs.push_back(objTx); } result.push_back(Pair("tx", txs)); - return true; + return result; } UniValue blockToJSON(const CBlock& block, const CBlockIndex* blockindex, bool txDetails = false) From 5143ef0c76287ebe10c5689375682cda0bfd5f3b Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Wed, 24 Oct 2018 00:11:06 +0800 Subject: [PATCH 036/127] try --- src/rpcblockchain.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 95ae2d1dd..fd520122b 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -334,11 +334,16 @@ UniValue getdatafromblock(const UniValue& params, bool fHelp) */ UniValue result(UniValue::VOBJ); UniValue txs(UniValue::VARR); + unsigned int i = 0; BOOST_FOREACH(const CTransaction&tx, block.vtx) { + if ( i != 0 || i != block.vxt.size() ) + { UniValue objTx(UniValue::VOBJ); voutToJSON(tx, uint256(), objTx); txs.push_back(objTx); + i = i + 1; + } } result.push_back(Pair("tx", txs)); return result; From b93f04b2bd2c6c29fc6be5bb6f8d16d1c8ea319e Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Wed, 24 Oct 2018 00:12:14 +0800 Subject: [PATCH 037/127] xt --- src/rpcblockchain.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index fd520122b..9bfc8c696 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -337,7 +337,7 @@ UniValue getdatafromblock(const UniValue& params, bool fHelp) unsigned int i = 0; BOOST_FOREACH(const CTransaction&tx, block.vtx) { - if ( i != 0 || i != block.vxt.size() ) + if ( i != 0 || i != block.vtx.size() ) { UniValue objTx(UniValue::VOBJ); voutToJSON(tx, uint256(), objTx); From c540920d85329997400e6a18c066f09122072554 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Wed, 24 Oct 2018 00:14:33 +0800 Subject: [PATCH 038/127] again --- src/rpcblockchain.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 9bfc8c696..25853bc5b 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -337,7 +337,7 @@ UniValue getdatafromblock(const UniValue& params, bool fHelp) unsigned int i = 0; BOOST_FOREACH(const CTransaction&tx, block.vtx) { - if ( i != 0 || i != block.vtx.size() ) + if ( i != 0 || i != (block.vtx.size() -1) ) { UniValue objTx(UniValue::VOBJ); voutToJSON(tx, uint256(), objTx); From f0d9eab81c29a55d8c763c44d058b3b1b239253f Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Wed, 24 Oct 2018 00:18:03 +0800 Subject: [PATCH 039/127] prints --- src/rpcblockchain.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 25853bc5b..00db32085 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -335,8 +335,10 @@ UniValue getdatafromblock(const UniValue& params, bool fHelp) UniValue result(UniValue::VOBJ); UniValue txs(UniValue::VARR); unsigned int i = 0; + fprintf(stderr, "%d\n", block.vtx.size()); BOOST_FOREACH(const CTransaction&tx, block.vtx) { + fprintf(stderr, "tx number: %d \n",i); if ( i != 0 || i != (block.vtx.size() -1) ) { UniValue objTx(UniValue::VOBJ); From 10a51db52fba6f11d52ec2ebf1290b2661abe062 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Wed, 24 Oct 2018 00:19:24 +0800 Subject: [PATCH 040/127] fix --- src/rpcblockchain.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 00db32085..97339ef82 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -335,7 +335,7 @@ UniValue getdatafromblock(const UniValue& params, bool fHelp) UniValue result(UniValue::VOBJ); UniValue txs(UniValue::VARR); unsigned int i = 0; - fprintf(stderr, "%d\n", block.vtx.size()); + fprintf(stderr, "%ld\n", block.vtx.size()); BOOST_FOREACH(const CTransaction&tx, block.vtx) { fprintf(stderr, "tx number: %d \n",i); From 65453a89387c04e0f62b31394d77b3b717920b49 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Wed, 24 Oct 2018 00:22:44 +0800 Subject: [PATCH 041/127] t --- src/rpcblockchain.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 97339ef82..3d1ea7e90 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -338,9 +338,9 @@ UniValue getdatafromblock(const UniValue& params, bool fHelp) fprintf(stderr, "%ld\n", block.vtx.size()); BOOST_FOREACH(const CTransaction&tx, block.vtx) { - fprintf(stderr, "tx number: %d \n",i); if ( i != 0 || i != (block.vtx.size() -1) ) { + fprintf(stderr, "tx number: %d \n",i); UniValue objTx(UniValue::VOBJ); voutToJSON(tx, uint256(), objTx); txs.push_back(objTx); From 9408ce62bd1bea34947bd1cc6b642c736203905b Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Wed, 24 Oct 2018 00:27:04 +0800 Subject: [PATCH 042/127] wtf --- src/rpcblockchain.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 3d1ea7e90..00d18c4ba 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -338,14 +338,14 @@ UniValue getdatafromblock(const UniValue& params, bool fHelp) fprintf(stderr, "%ld\n", block.vtx.size()); BOOST_FOREACH(const CTransaction&tx, block.vtx) { - if ( i != 0 || i != (block.vtx.size() -1) ) + if ( (i === 0) || (i == (block.vtx.size() -1)) ) { fprintf(stderr, "tx number: %d \n",i); UniValue objTx(UniValue::VOBJ); voutToJSON(tx, uint256(), objTx); txs.push_back(objTx); - i = i + 1; } + i = i + 1; } result.push_back(Pair("tx", txs)); return result; From b6a0c1d55ab2ca187b9cefef6d593b82cd9a8646 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Wed, 24 Oct 2018 00:28:12 +0800 Subject: [PATCH 043/127] fix --- src/rpcblockchain.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 00d18c4ba..a674dba2d 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -338,7 +338,7 @@ UniValue getdatafromblock(const UniValue& params, bool fHelp) fprintf(stderr, "%ld\n", block.vtx.size()); BOOST_FOREACH(const CTransaction&tx, block.vtx) { - if ( (i === 0) || (i == (block.vtx.size() -1)) ) + if ( (i == 0) || (i == (block.vtx.size() -1)) ) { fprintf(stderr, "tx number: %d \n",i); UniValue objTx(UniValue::VOBJ); From c465fbf0d3358425d8aac17289f58cdf9450297f Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Wed, 24 Oct 2018 00:30:58 +0800 Subject: [PATCH 044/127] fix --- src/rpcblockchain.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index a674dba2d..ad36e2818 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -333,17 +333,16 @@ UniValue getdatafromblock(const UniValue& params, bool fHelp) return chainActive.Height(); */ UniValue result(UniValue::VOBJ); - UniValue txs(UniValue::VARR); unsigned int i = 0; - fprintf(stderr, "%ld\n", block.vtx.size()); + fprintf(stderr, "number of tx in block: %ld\n", block.vtx.size()); BOOST_FOREACH(const CTransaction&tx, block.vtx) { - if ( (i == 0) || (i == (block.vtx.size() -1)) ) + if ( (i != 0) || (i != (block.vtx.size() -1)) ) { fprintf(stderr, "tx number: %d \n",i); UniValue objTx(UniValue::VOBJ); voutToJSON(tx, uint256(), objTx); - txs.push_back(objTx); + result.push_back(objTx); } i = i + 1; } From dc9e877b656b65a298af434fbc858efd759437ee Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Wed, 24 Oct 2018 00:32:09 +0800 Subject: [PATCH 045/127] fix --- src/rpcblockchain.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index ad36e2818..afc0159ba 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -346,7 +346,6 @@ UniValue getdatafromblock(const UniValue& params, bool fHelp) } i = i + 1; } - result.push_back(Pair("tx", txs)); return result; } From 85fecb9f761cc579c88b9f7022244bc43521622d Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Wed, 24 Oct 2018 00:36:38 +0800 Subject: [PATCH 046/127] fix? --- src/rpcblockchain.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index afc0159ba..8ed47c140 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -332,14 +332,16 @@ UniValue getdatafromblock(const UniValue& params, bool fHelp) } return chainActive.Height(); */ - UniValue result(UniValue::VOBJ); + UniValue result(UniValue::VARR); unsigned int i = 0; fprintf(stderr, "number of tx in block: %ld\n", block.vtx.size()); BOOST_FOREACH(const CTransaction&tx, block.vtx) { - if ( (i != 0) || (i != (block.vtx.size() -1)) ) + if ( (i == 0) || (i == (block.vtx.size() -1)) ) { - fprintf(stderr, "tx number: %d \n",i); + fprintf(stderr, "skipped tx number: %d \n",i); + } else { + fprintf(stderr, "added tx number: %d \n",i); UniValue objTx(UniValue::VOBJ); voutToJSON(tx, uint256(), objTx); result.push_back(objTx); From 5a363fdffcf612133e218ea3f37b665fd61f03f1 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Wed, 24 Oct 2018 00:41:36 +0800 Subject: [PATCH 047/127] maybe --- src/rpcblockchain.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 8ed47c140..e54ff8fb8 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -343,7 +343,10 @@ UniValue getdatafromblock(const UniValue& params, bool fHelp) } else { fprintf(stderr, "added tx number: %d \n",i); UniValue objTx(UniValue::VOBJ); - voutToJSON(tx, uint256(), objTx); + //voutToJSON(tx, uint256(), objTx); + //const CTxOut& txout = tx.vout[i]; + //UniValue out(UniValue::VOBJ); + objTx.push_back(Pair("hex", HexStr(tx.vout[2].scriptPubKey.begin(), tx.vout[2].scriptPubKey.end()))); result.push_back(objTx); } i = i + 1; From c4ee47ec3651ec29ce2a5da50ad0cbb21cee8990 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Wed, 24 Oct 2018 12:12:18 +0800 Subject: [PATCH 048/127] add rpc to return pubkey --- src/rpcblockchain.cpp | 20 +++++--------------- src/rpcserver.cpp | 1 + src/rpcserver.h | 1 + src/wallet/rpcwallet.cpp | 29 +++++++++++++++++++++++++++++ 4 files changed, 36 insertions(+), 15 deletions(-) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index e54ff8fb8..5499ca742 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -257,18 +257,6 @@ UniValue blockToDeltasJSON(const CBlock& block, const CBlockIndex* blockindex) return result; } -void voutToJSON(const CTransaction& tx, const uint256 hashBlock, UniValue& entry) -{ - UniValue vout(UniValue::VARR); - for (unsigned int i = 0; i < tx.vout.size(); i++) { - const CTxOut& txout = tx.vout[i]; - UniValue out(UniValue::VOBJ); - out.push_back(Pair("hex", HexStr(txout.scriptPubKey.begin(), txout.scriptPubKey.end()))); - vout.push_back(out); - } - entry.push_back(Pair("vout", vout)); -} - UniValue getdatafromblock(const UniValue& params, bool fHelp) { if (fHelp || params.size() < 1 || params.size() > 2) @@ -335,18 +323,20 @@ UniValue getdatafromblock(const UniValue& params, bool fHelp) UniValue result(UniValue::VARR); unsigned int i = 0; fprintf(stderr, "number of tx in block: %ld\n", block.vtx.size()); + // Iif block tx size is > 2 then we can do this BOOST_FOREACH(const CTransaction&tx, block.vtx) { + //if the vout size = 3 then its a valid TX get the data. dont use the test here! it wont work with notarisations! if ( (i == 0) || (i == (block.vtx.size() -1)) ) { fprintf(stderr, "skipped tx number: %d \n",i); } else { fprintf(stderr, "added tx number: %d \n",i); UniValue objTx(UniValue::VOBJ); - //voutToJSON(tx, uint256(), objTx); - //const CTxOut& txout = tx.vout[i]; - //UniValue out(UniValue::VOBJ); + objTx.push_back(Pair("hex", HexStr(tx.vout[2].scriptPubKey.begin(), tx.vout[2].scriptPubKey.end()))); + // function here to extract seqid from first and last TX + // we an push the data or not depending on input from RPC. result.push_back(objTx); } i = i + 1; diff --git a/src/rpcserver.cpp b/src/rpcserver.cpp index b23dbc826..15f31d8ef 100644 --- a/src/rpcserver.cpp +++ b/src/rpcserver.cpp @@ -264,6 +264,7 @@ static const CRPCCommand vRPCCommands[] = { "control", "getinfo", &getinfo, true }, /* uses wallet if enabled */ { "control", "help", &help, true }, { "control", "stop", &stop, true }, + { "control", "getpubkey", &getpubkey, true }, /* P2P networking */ { "network", "getnetworkinfo", &getnetworkinfo, true }, diff --git a/src/rpcserver.h b/src/rpcserver.h index d2194db4f..658102af0 100644 --- a/src/rpcserver.h +++ b/src/rpcserver.h @@ -322,6 +322,7 @@ extern UniValue walletlock(const UniValue& params, bool fHelp); extern UniValue encryptwallet(const UniValue& params, bool fHelp); extern UniValue validateaddress(const UniValue& params, bool fHelp); extern UniValue getinfo(const UniValue& params, bool fHelp); +extern UniValue getpubkey(const UniValue& params, bool fHelp); extern UniValue getwalletinfo(const UniValue& params, bool fHelp); extern UniValue getblockchaininfo(const UniValue& params, bool fHelp); extern UniValue getnetworkinfo(const UniValue& params, bool fHelp); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 0e9fc8e80..e075a0d8b 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4953,6 +4953,35 @@ UniValue channelsaddress(const UniValue& params, bool fHelp) return(result); } +UniValue getpubkey(const UniValue& params, bool fHelp) +{ + UniValue result(UniValue::VOBJ); + if (fHelp || params.size() > 0) + throw runtime_error( + "getpubkey\n" + "\nReturns the -pubkey the daemon was started with.\n" + "\nResult:\n" + "[\n" + " {\n" + " \"pubkey\" : \"pubkey\", (string) The pubkey\n" + " }\n" + "]\n" + "\nExamples:\n" + "\nList pubkey.\n" + + HelpExampleCli("getpubkey", "") + + HelpExampleRpc("getpubkey", "") + ); + + extern uint8_t NOTARY_PUBKEY33[]; + extern std::string NOTARY_PUBKEY; + if ( NOTARY_PUBKEY33[0] == 0 ) { + result.push_back(Pair("error","pubkey was not set!"; + } else { + result.push_back(Pair("pubkey", NOTARY_PUBKEY); + } + return result; +} + UniValue oraclesaddress(const UniValue& params, bool fHelp) { struct CCcontract_info *cp,C; std::vector pubkey; From 9920c80bde876e8b598b13ec4c3bde9c81ae801b Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Wed, 24 Oct 2018 12:49:12 +0800 Subject: [PATCH 049/127] add pubkey output to getinfo, and try setpubkey RPC --- src/rpcmisc.cpp | 3 +++ src/rpcserver.cpp | 2 +- src/rpcserver.h | 2 +- src/wallet/rpcwallet.cpp | 20 ++++++++++---------- 4 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/rpcmisc.cpp b/src/rpcmisc.cpp index a42afbb61..f104899e1 100644 --- a/src/rpcmisc.cpp +++ b/src/rpcmisc.cpp @@ -64,6 +64,7 @@ extern uint64_t ASSETCHAINS_ENDSUBSIDY,ASSETCHAINS_REWARD,ASSETCHAINS_HALVING,AS UniValue getinfo(const UniValue& params, bool fHelp) { uint256 notarized_hash,notarized_desttxid; int32_t prevMoMheight,notarized_height,longestchain,kmdnotarized_height,txid_height; + extern std::string NOTARY_PUBKEY; extern uint8_t NOTARY_PUBKEY33[]; if (fHelp || params.size() != 0) throw runtime_error( "getinfo\n" @@ -158,6 +159,8 @@ UniValue getinfo(const UniValue& params, bool fHelp) obj.push_back(Pair("pubkey", pubkeystr)); if ( KOMODO_LASTMINED != 0 ) obj.push_back(Pair("lastmined", KOMODO_LASTMINED)); + } else if ( NOTARY_PUBKEY33[0] != 0 ) { + obj.push_back(Pair("pubkey", NOTARY_PUBKEY)); } } if ( ASSETCHAINS_CC != 0 ) diff --git a/src/rpcserver.cpp b/src/rpcserver.cpp index 15f31d8ef..1b590c5ae 100644 --- a/src/rpcserver.cpp +++ b/src/rpcserver.cpp @@ -264,7 +264,7 @@ static const CRPCCommand vRPCCommands[] = { "control", "getinfo", &getinfo, true }, /* uses wallet if enabled */ { "control", "help", &help, true }, { "control", "stop", &stop, true }, - { "control", "getpubkey", &getpubkey, true }, + { "control", "setpubkey", &setpubkey, true }, /* P2P networking */ { "network", "getnetworkinfo", &getnetworkinfo, true }, diff --git a/src/rpcserver.h b/src/rpcserver.h index 658102af0..81ca8a8b9 100644 --- a/src/rpcserver.h +++ b/src/rpcserver.h @@ -322,7 +322,7 @@ extern UniValue walletlock(const UniValue& params, bool fHelp); extern UniValue encryptwallet(const UniValue& params, bool fHelp); extern UniValue validateaddress(const UniValue& params, bool fHelp); extern UniValue getinfo(const UniValue& params, bool fHelp); -extern UniValue getpubkey(const UniValue& params, bool fHelp); +extern UniValue setpubkey(const UniValue& params, bool fHelp); extern UniValue getwalletinfo(const UniValue& params, bool fHelp); extern UniValue getblockchaininfo(const UniValue& params, bool fHelp); extern UniValue getnetworkinfo(const UniValue& params, bool fHelp); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index e075a0d8b..acbe165c2 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4953,13 +4953,13 @@ UniValue channelsaddress(const UniValue& params, bool fHelp) return(result); } -UniValue getpubkey(const UniValue& params, bool fHelp) +UniValue setpubkey(const UniValue& params, bool fHelp) { UniValue result(UniValue::VOBJ); - if (fHelp || params.size() > 0) + if ( fHelp || params.size() != 1 ) throw runtime_error( - "getpubkey\n" - "\nReturns the -pubkey the daemon was started with.\n" + "setpubkey\n" + "\Sets the -pubkey if the daemon was not started with it, if it was started, it returns the pubkey.\n" "\nResult:\n" "[\n" " {\n" @@ -4968,17 +4968,17 @@ UniValue getpubkey(const UniValue& params, bool fHelp) "]\n" "\nExamples:\n" "\nList pubkey.\n" - + HelpExampleCli("getpubkey", "") - + HelpExampleRpc("getpubkey", "") + + HelpExampleCli("setpubkey", "02f7597468703c1c5c8465dd6d43acaae697df9df30bed21494d193412a1ea193e") + + HelpExampleRpc("setpubkey", "02f7597468703c1c5c8465dd6d43acaae697df9df30bed21494d193412a1ea193e") ); extern uint8_t NOTARY_PUBKEY33[]; extern std::string NOTARY_PUBKEY; - if ( NOTARY_PUBKEY33[0] == 0 ) { - result.push_back(Pair("error","pubkey was not set!"; - } else { - result.push_back(Pair("pubkey", NOTARY_PUBKEY); + if ( NOTARY_PUBKEY33[0] == 0 && strlen(params[0].get_str().c_str()) == 66 )) { + NOTARY_PUBKEY = params[0].get_str(); + decode_hex(NOTARY_PUBKEY33,33,(char *)NOTARY_PUBKEY.c_str()); } + result.push_back(Pair("pubkey", NOTARY_PUBKEY); return result; } From 07bc62d2c3dd601a14408eee62605b7a993ef592 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Wed, 24 Oct 2018 13:06:51 +0800 Subject: [PATCH 050/127] fix --- src/wallet/rpcwallet.cpp | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index acbe165c2..19ec2a498 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4958,27 +4958,26 @@ UniValue setpubkey(const UniValue& params, bool fHelp) UniValue result(UniValue::VOBJ); if ( fHelp || params.size() != 1 ) throw runtime_error( - "setpubkey\n" - "\Sets the -pubkey if the daemon was not started with it, if it was started, it returns the pubkey.\n" - "\nResult:\n" - "[\n" - " {\n" - " \"pubkey\" : \"pubkey\", (string) The pubkey\n" - " }\n" - "]\n" - "\nExamples:\n" - "\nList pubkey.\n" - + HelpExampleCli("setpubkey", "02f7597468703c1c5c8465dd6d43acaae697df9df30bed21494d193412a1ea193e") - + HelpExampleRpc("setpubkey", "02f7597468703c1c5c8465dd6d43acaae697df9df30bed21494d193412a1ea193e") - ); + "setpubkey\n" + "\nSets the -pubkey if the daemon was not started with it, if it was started, it returns the pubkey.\n" + "\nArguments:\n" + "1. \"pubkey\" (string) pubkey to set.\n" + "\nResult:\n" + " {\n" + " \"pubkey\" : \"pubkey\", (string) The pubkey\n" + " }\n" + "\nExamples:\n" + + HelpExampleCli("setpubkey", "02f7597468703c1c5c8465dd6d43acaae697df9df30bed21494d193412a1ea193e") + + HelpExampleRpc("setpubkey", "02f7597468703c1c5c8465dd6d43acaae697df9df30bed21494d193412a1ea193e") + ); extern uint8_t NOTARY_PUBKEY33[]; extern std::string NOTARY_PUBKEY; - if ( NOTARY_PUBKEY33[0] == 0 && strlen(params[0].get_str().c_str()) == 66 )) { + if ( NOTARY_PUBKEY33[0] == 0 && strlen(params[0].get_str().c_str()) == 66 ) { NOTARY_PUBKEY = params[0].get_str(); decode_hex(NOTARY_PUBKEY33,33,(char *)NOTARY_PUBKEY.c_str()); } - result.push_back(Pair("pubkey", NOTARY_PUBKEY); + result.push_back(Pair("pubkey", NOTARY_PUBKEY)); return result; } From 9b6bc59d958e71523db59dfc6daeac591d33cfdf Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Wed, 24 Oct 2018 13:34:52 +0800 Subject: [PATCH 051/127] set pubkey fix --- src/wallet/rpcwallet.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 19ec2a498..fd51c47b6 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4959,7 +4959,7 @@ UniValue setpubkey(const UniValue& params, bool fHelp) if ( fHelp || params.size() != 1 ) throw runtime_error( "setpubkey\n" - "\nSets the -pubkey if the daemon was not started with it, if it was started, it returns the pubkey.\n" + "\nSets the -pubkey if the daemon was not started with it, if it was already set, it returns the pubkey.\n" "\nArguments:\n" "1. \"pubkey\" (string) pubkey to set.\n" "\nResult:\n" @@ -4974,8 +4974,12 @@ UniValue setpubkey(const UniValue& params, bool fHelp) extern uint8_t NOTARY_PUBKEY33[]; extern std::string NOTARY_PUBKEY; if ( NOTARY_PUBKEY33[0] == 0 && strlen(params[0].get_str().c_str()) == 66 ) { + LOCK(cs_main); NOTARY_PUBKEY = params[0].get_str(); decode_hex(NOTARY_PUBKEY33,33,(char *)NOTARY_PUBKEY.c_str()); + + } else { + result.push_back(Pair("error", "Can only set pubkey once, to change it you need to restart your daemon.")); } result.push_back(Pair("pubkey", NOTARY_PUBKEY)); return result; From 5e95a0e51f0e6c6d60f8b5888172dc32b38400e4 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Wed, 24 Oct 2018 14:13:39 +0800 Subject: [PATCH 052/127] add convert pubkey to address call --- src/wallet/rpcwallet.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index fd51c47b6..5509a6b09 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4971,13 +4971,15 @@ UniValue setpubkey(const UniValue& params, bool fHelp) + HelpExampleRpc("setpubkey", "02f7597468703c1c5c8465dd6d43acaae697df9df30bed21494d193412a1ea193e") ); + char *address; extern uint8_t NOTARY_PUBKEY33[]; extern std::string NOTARY_PUBKEY; if ( NOTARY_PUBKEY33[0] == 0 && strlen(params[0].get_str().c_str()) == 66 ) { LOCK(cs_main); NOTARY_PUBKEY = params[0].get_str(); decode_hex(NOTARY_PUBKEY33,33,(char *)NOTARY_PUBKEY.c_str()); - + pubkey2addr(address,(uint8_t *)NOTARY_PUBKEY33); + result.push_back(Pair("R-address", address)); } else { result.push_back(Pair("error", "Can only set pubkey once, to change it you need to restart your daemon.")); } From bec8436996ad4d495b6e6fa74799963edd3f5b93 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Wed, 24 Oct 2018 14:16:02 +0800 Subject: [PATCH 053/127] try --- src/wallet/rpcwallet.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 5509a6b09..26e9602e9 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4953,6 +4953,8 @@ UniValue channelsaddress(const UniValue& params, bool fHelp) return(result); } +bool pubkey2addr(char *destaddr,uint8_t *pubkey33); + UniValue setpubkey(const UniValue& params, bool fHelp) { UniValue result(UniValue::VOBJ); From 064e6b67e435ff96092ab8360db6079299bf18ab Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Wed, 24 Oct 2018 14:19:33 +0800 Subject: [PATCH 054/127] fix? --- src/wallet/rpcwallet.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 26e9602e9..1b85e2494 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4980,7 +4980,8 @@ UniValue setpubkey(const UniValue& params, bool fHelp) LOCK(cs_main); NOTARY_PUBKEY = params[0].get_str(); decode_hex(NOTARY_PUBKEY33,33,(char *)NOTARY_PUBKEY.c_str()); - pubkey2addr(address,(uint8_t *)NOTARY_PUBKEY33); + pubkey2addr((char *)address,(uint8_t *)NOTARY_PUBKEY33); + printf("%s\n",address); result.push_back(Pair("R-address", address)); } else { result.push_back(Pair("error", "Can only set pubkey once, to change it you need to restart your daemon.")); From fb13ce2e73ee2465c8d70301a8e2b8eedbca6410 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Wed, 24 Oct 2018 14:23:43 +0800 Subject: [PATCH 055/127] 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 1b85e2494..c69b9250e 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4973,7 +4973,7 @@ UniValue setpubkey(const UniValue& params, bool fHelp) + HelpExampleRpc("setpubkey", "02f7597468703c1c5c8465dd6d43acaae697df9df30bed21494d193412a1ea193e") ); - char *address; + char address[20]; extern uint8_t NOTARY_PUBKEY33[]; extern std::string NOTARY_PUBKEY; if ( NOTARY_PUBKEY33[0] == 0 && strlen(params[0].get_str().c_str()) == 66 ) { From 4e989f5d0ed25909ad31b4c9dad6bc5f90377537 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Wed, 24 Oct 2018 14:30:30 +0800 Subject: [PATCH 056/127] fix? --- src/wallet/rpcwallet.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index c69b9250e..ab9eeced1 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4982,7 +4982,8 @@ UniValue setpubkey(const UniValue& params, bool fHelp) decode_hex(NOTARY_PUBKEY33,33,(char *)NOTARY_PUBKEY.c_str()); pubkey2addr((char *)address,(uint8_t *)NOTARY_PUBKEY33); printf("%s\n",address); - result.push_back(Pair("R-address", address)); + std::string str(address); + result.push_back(Pair("R-address", str)); } else { result.push_back(Pair("error", "Can only set pubkey once, to change it you need to restart your daemon.")); } From 327f5aeb966f7ceced26409af97e212c4bb0065f Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Wed, 24 Oct 2018 14:35:47 +0800 Subject: [PATCH 057/127] hmm --- src/wallet/rpcwallet.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index ab9eeced1..1724be26f 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4983,7 +4983,8 @@ UniValue setpubkey(const UniValue& params, bool fHelp) pubkey2addr((char *)address,(uint8_t *)NOTARY_PUBKEY33); printf("%s\n",address); std::string str(address); - result.push_back(Pair("R-address", str)); + cout << str; + //result.push_back(Pair("R-address", str)); } else { result.push_back(Pair("error", "Can only set pubkey once, to change it you need to restart your daemon.")); } From 7cc09a50cc13a2e13a5e4b65259c9d2b255a5c68 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Wed, 24 Oct 2018 14:39:04 +0800 Subject: [PATCH 058/127] try --- src/wallet/rpcwallet.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 1724be26f..9f25005c1 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4973,18 +4973,16 @@ UniValue setpubkey(const UniValue& params, bool fHelp) + HelpExampleRpc("setpubkey", "02f7597468703c1c5c8465dd6d43acaae697df9df30bed21494d193412a1ea193e") ); - char address[20]; + char address[18]; extern uint8_t NOTARY_PUBKEY33[]; extern std::string NOTARY_PUBKEY; if ( NOTARY_PUBKEY33[0] == 0 && strlen(params[0].get_str().c_str()) == 66 ) { - LOCK(cs_main); + //LOCK(cs_main); NOTARY_PUBKEY = params[0].get_str(); decode_hex(NOTARY_PUBKEY33,33,(char *)NOTARY_PUBKEY.c_str()); pubkey2addr((char *)address,(uint8_t *)NOTARY_PUBKEY33); printf("%s\n",address); - std::string str(address); - cout << str; - //result.push_back(Pair("R-address", str)); + result.push_back(Pair("R-address", address)); } else { result.push_back(Pair("error", "Can only set pubkey once, to change it you need to restart your daemon.")); } From 27402fecd1251487d8c2348e87b1eb4fec7959cf Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Wed, 24 Oct 2018 14:46:37 +0800 Subject: [PATCH 059/127] try --- src/wallet/rpcwallet.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 9f25005c1..00b33f7e6 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4974,14 +4974,17 @@ UniValue setpubkey(const UniValue& params, bool fHelp) ); char address[18]; + uint8_t pubkey33[33]; + decode_hex(pubkey33,33,(char *)params[0].get_str().c_str()); + pubkey2addr((char *)address,(uint8_t *)pubkey33); + printf("%s\n",address); + extern uint8_t NOTARY_PUBKEY33[]; extern std::string NOTARY_PUBKEY; if ( NOTARY_PUBKEY33[0] == 0 && strlen(params[0].get_str().c_str()) == 66 ) { //LOCK(cs_main); NOTARY_PUBKEY = params[0].get_str(); decode_hex(NOTARY_PUBKEY33,33,(char *)NOTARY_PUBKEY.c_str()); - pubkey2addr((char *)address,(uint8_t *)NOTARY_PUBKEY33); - printf("%s\n",address); result.push_back(Pair("R-address", address)); } else { result.push_back(Pair("error", "Can only set pubkey once, to change it you need to restart your daemon.")); From ecfeb9dd9c449c54c1a6893963a6a3166f85fbce Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Wed, 24 Oct 2018 14:50:43 +0800 Subject: [PATCH 060/127] try --- src/wallet/rpcwallet.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 00b33f7e6..63e2371f6 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4976,9 +4976,9 @@ UniValue setpubkey(const UniValue& params, bool fHelp) char address[18]; uint8_t pubkey33[33]; decode_hex(pubkey33,33,(char *)params[0].get_str().c_str()); - pubkey2addr((char *)address,(uint8_t *)pubkey33); - printf("%s\n",address); - + if (pubkey2addr((char *)address,(uint8_t *)pubkey33)) + printf("%s\n",address); + extern uint8_t NOTARY_PUBKEY33[]; extern std::string NOTARY_PUBKEY; if ( NOTARY_PUBKEY33[0] == 0 && strlen(params[0].get_str().c_str()) == 66 ) { From b412964cf243607a1aec635968ee4aecd672c409 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Wed, 24 Oct 2018 14:58:07 +0800 Subject: [PATCH 061/127] fix --- src/wallet/rpcwallet.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 63e2371f6..9bb049371 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4967,6 +4967,7 @@ UniValue setpubkey(const UniValue& params, bool fHelp) "\nResult:\n" " {\n" " \"pubkey\" : \"pubkey\", (string) The pubkey\n" + " \"R-address\" : \"R address\", (string) The pubkey\n" " }\n" "\nExamples:\n" + HelpExampleCli("setpubkey", "02f7597468703c1c5c8465dd6d43acaae697df9df30bed21494d193412a1ea193e") @@ -4975,16 +4976,14 @@ UniValue setpubkey(const UniValue& params, bool fHelp) char address[18]; uint8_t pubkey33[33]; - decode_hex(pubkey33,33,(char *)params[0].get_str().c_str()); - if (pubkey2addr((char *)address,(uint8_t *)pubkey33)) - printf("%s\n",address); - extern uint8_t NOTARY_PUBKEY33[]; extern std::string NOTARY_PUBKEY; if ( NOTARY_PUBKEY33[0] == 0 && strlen(params[0].get_str().c_str()) == 66 ) { //LOCK(cs_main); NOTARY_PUBKEY = params[0].get_str(); decode_hex(NOTARY_PUBKEY33,33,(char *)NOTARY_PUBKEY.c_str()); + decode_hex(pubkey33,33,(char *)params[0].get_str().c_str()); + pubkey2addr((char *)address,(uint8_t *)pubkey33) result.push_back(Pair("R-address", address)); } else { result.push_back(Pair("error", "Can only set pubkey once, to change it you need to restart your daemon.")); From 906935b4efa6e7c9c00212f84b754618e30d315e Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Wed, 24 Oct 2018 15:00:49 +0800 Subject: [PATCH 062/127] 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 9bb049371..f32f08a84 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4983,7 +4983,7 @@ UniValue setpubkey(const UniValue& params, bool fHelp) NOTARY_PUBKEY = params[0].get_str(); decode_hex(NOTARY_PUBKEY33,33,(char *)NOTARY_PUBKEY.c_str()); decode_hex(pubkey33,33,(char *)params[0].get_str().c_str()); - pubkey2addr((char *)address,(uint8_t *)pubkey33) + pubkey2addr((char *)address,(uint8_t *)pubkey33); result.push_back(Pair("R-address", address)); } else { result.push_back(Pair("error", "Can only set pubkey once, to change it you need to restart your daemon.")); From 6ef59e5094e3bae67ec15cf322b2241d1dba90d4 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Wed, 24 Oct 2018 15:14:54 +0800 Subject: [PATCH 063/127] error checks --- src/wallet/rpcwallet.cpp | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index f32f08a84..77863165e 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4978,13 +4978,19 @@ UniValue setpubkey(const UniValue& params, bool fHelp) uint8_t pubkey33[33]; extern uint8_t NOTARY_PUBKEY33[]; extern std::string NOTARY_PUBKEY; - if ( NOTARY_PUBKEY33[0] == 0 && strlen(params[0].get_str().c_str()) == 66 ) { - //LOCK(cs_main); - NOTARY_PUBKEY = params[0].get_str(); - decode_hex(NOTARY_PUBKEY33,33,(char *)NOTARY_PUBKEY.c_str()); - decode_hex(pubkey33,33,(char *)params[0].get_str().c_str()); - pubkey2addr((char *)address,(uint8_t *)pubkey33); - result.push_back(Pair("R-address", address)); + if ( NOTARY_PUBKEY33[0] == 0 ) { + if (strlen(params[0].get_str().c_str()) == 66) { + decode_hex(pubkey33,33,(char *)params[0].get_str().c_str()); + pubkey2addr((char *)address,(uint8_t *)pubkey33); + if (strncmp("RRmWExvapDM9YbLT9X9xAyzDgxomYf63ng",address) == 0) { + result.push_back(Pair("error", "pubkey entered is invalid.")); + } else { + LOCK(cs_main); + NOTARY_PUBKEY = params[0].get_str(); + decode_hex(NOTARY_PUBKEY33,33,(char *)NOTARY_PUBKEY.c_str()); + result.push_back(Pair("R-address", address)); + } + } } else { result.push_back(Pair("error", "Can only set pubkey once, to change it you need to restart your daemon.")); } From 841a3cc642236f0dfa045dc438a3338b7b44f8c9 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Wed, 24 Oct 2018 15:16:10 +0800 Subject: [PATCH 064/127] 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 77863165e..f24deadf8 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4982,7 +4982,7 @@ UniValue setpubkey(const UniValue& params, bool fHelp) if (strlen(params[0].get_str().c_str()) == 66) { decode_hex(pubkey33,33,(char *)params[0].get_str().c_str()); pubkey2addr((char *)address,(uint8_t *)pubkey33); - if (strncmp("RRmWExvapDM9YbLT9X9xAyzDgxomYf63ng",address) == 0) { + if (strcmp("RRmWExvapDM9YbLT9X9xAyzDgxomYf63ng",address) == 0) { result.push_back(Pair("error", "pubkey entered is invalid.")); } else { LOCK(cs_main); From 021d89a826201e2719ccd1829b23dbb47df51406 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Wed, 24 Oct 2018 15:19:05 +0800 Subject: [PATCH 065/127] fix --- src/wallet/rpcwallet.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index f24deadf8..74bdf7e47 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4990,6 +4990,8 @@ UniValue setpubkey(const UniValue& params, bool fHelp) decode_hex(NOTARY_PUBKEY33,33,(char *)NOTARY_PUBKEY.c_str()); result.push_back(Pair("R-address", address)); } + } else { + result.push_back(Pair("error", "pubkey is wrong length, must be 66 char hex string.")); } } else { result.push_back(Pair("error", "Can only set pubkey once, to change it you need to restart your daemon.")); From fc9a044c7e1be004b04ccdc890e6c995f619d0be Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Wed, 24 Oct 2018 15:31:27 +0800 Subject: [PATCH 066/127] try --- src/wallet/rpcwallet.cpp | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 74bdf7e47..7a166a495 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4974,21 +4974,37 @@ UniValue setpubkey(const UniValue& params, bool fHelp) + HelpExampleRpc("setpubkey", "02f7597468703c1c5c8465dd6d43acaae697df9df30bed21494d193412a1ea193e") ); - char address[18]; +#ifdef ENABLE_WALLET + LOCK2(cs_main, pwalletMain ? &pwalletMain->cs_wallet : NULL); +#else + LOCK(cs_main); +#endif + + char Raddress[18]; uint8_t pubkey33[33]; extern uint8_t NOTARY_PUBKEY33[]; extern std::string NOTARY_PUBKEY; if ( NOTARY_PUBKEY33[0] == 0 ) { if (strlen(params[0].get_str().c_str()) == 66) { decode_hex(pubkey33,33,(char *)params[0].get_str().c_str()); - pubkey2addr((char *)address,(uint8_t *)pubkey33); - if (strcmp("RRmWExvapDM9YbLT9X9xAyzDgxomYf63ng",address) == 0) { + pubkey2addr((char *)Raddress,(uint8_t *)pubkey33); + if (strcmp("RRmWExvapDM9YbLT9X9xAyzDgxomYf63ng",Raddress) == 0) { result.push_back(Pair("error", "pubkey entered is invalid.")); } else { - LOCK(cs_main); + CBitcoinAddress address(Raddress); + bool isValid = address.IsValid(); + if (isValid) + { + CTxDestination dest = address.Get(); + string currentAddress = address.ToString(); + result.push_back(Pair("address", currentAddress)); +#ifdef ENABLE_WALLET + isminetype mine = pwalletMain ? IsMine(*pwalletMain, dest) : ISMINE_NO; + result.push_back(Pair("ismine", (mine & ISMINE_SPENDABLE) ? true : false)); +#endif + } NOTARY_PUBKEY = params[0].get_str(); decode_hex(NOTARY_PUBKEY33,33,(char *)NOTARY_PUBKEY.c_str()); - result.push_back(Pair("R-address", address)); } } else { result.push_back(Pair("error", "pubkey is wrong length, must be 66 char hex string.")); From dc28f2eb66d2552ea0856e4e4dcbf709fbcac3b5 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Wed, 24 Oct 2018 23:57:26 +0800 Subject: [PATCH 067/127] update getdata function --- src/rpcblockchain.cpp | 39 +++++++++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 5499ca742..2212811ef 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -324,22 +324,33 @@ UniValue getdatafromblock(const UniValue& params, bool fHelp) unsigned int i = 0; fprintf(stderr, "number of tx in block: %ld\n", block.vtx.size()); // Iif block tx size is > 2 then we can do this - BOOST_FOREACH(const CTransaction&tx, block.vtx) - { - //if the vout size = 3 then its a valid TX get the data. dont use the test here! it wont work with notarisations! - if ( (i == 0) || (i == (block.vtx.size() -1)) ) + if ( block.vtx.size() > 2 ) { + BOOST_FOREACH(const CTransaction&tx, block.vtx) { - fprintf(stderr, "skipped tx number: %d \n",i); - } else { - fprintf(stderr, "added tx number: %d \n",i); - UniValue objTx(UniValue::VOBJ); - - objTx.push_back(Pair("hex", HexStr(tx.vout[2].scriptPubKey.begin(), tx.vout[2].scriptPubKey.end()))); - // function here to extract seqid from first and last TX - // we an push the data or not depending on input from RPC. - result.push_back(objTx); + // ignore first and last TX and any TX that does not have 3 vouts. + if ( (i == 0) || (i == (block.vtx.size() -1)) || (tx.vout.size() != 3) ) + { + fprintf(stderr, "skipped tx number: %d \n",i); + } else { + fprintf(stderr, "added tx number: %d \n",i); + UniValue objTx(UniValue::VOBJ); + std::string opretstr = HexStr(tx.vout[2].scriptPubKey.begin(), tx.vout[2].scriptPubKey.end()) + if ( opretstr.size() > 81 ) { + std::string idstr = str.substr (8,64); // stream ID or txid + std::string seqid = str.substr (72,8); // sequence ID + std::string data = str.substr (80); // data chunk + objTx.push_back(Pair("idstr", idstr)); + objTx.push_back(Pair("seqid", seqid)); + objTx.push_back(Pair("data", data)); + result.push_back(objTx); + } + // function here to extract seqid from first and last TX + // we an push the data or not depending on input from RPC. + } + i = i + 1; } - i = i + 1; + } else { + result.push_back(Pair("error","there are no TX in this block.")) } return result; } From d89e0313cbb0fcd71a274693741386707ecf7b5e Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Thu, 25 Oct 2018 00:01:15 +0800 Subject: [PATCH 068/127] ; --- src/rpcblockchain.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 2212811ef..eb0aa4675 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -334,7 +334,7 @@ UniValue getdatafromblock(const UniValue& params, bool fHelp) } else { fprintf(stderr, "added tx number: %d \n",i); UniValue objTx(UniValue::VOBJ); - std::string opretstr = HexStr(tx.vout[2].scriptPubKey.begin(), tx.vout[2].scriptPubKey.end()) + std::string opretstr = HexStr(tx.vout[2].scriptPubKey.begin(), tx.vout[2].scriptPubKey.end()); if ( opretstr.size() > 81 ) { std::string idstr = str.substr (8,64); // stream ID or txid std::string seqid = str.substr (72,8); // sequence ID @@ -345,7 +345,7 @@ UniValue getdatafromblock(const UniValue& params, bool fHelp) result.push_back(objTx); } // function here to extract seqid from first and last TX - // we an push the data or not depending on input from RPC. + // we an push the data or not depending on input from RPC. } i = i + 1; } From e80718809fad34d12529b19192b2325bb87c95ed Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Thu, 25 Oct 2018 00:02:31 +0800 Subject: [PATCH 069/127] oops --- src/rpcblockchain.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index eb0aa4675..206aabfcf 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -336,9 +336,9 @@ UniValue getdatafromblock(const UniValue& params, bool fHelp) UniValue objTx(UniValue::VOBJ); std::string opretstr = HexStr(tx.vout[2].scriptPubKey.begin(), tx.vout[2].scriptPubKey.end()); if ( opretstr.size() > 81 ) { - std::string idstr = str.substr (8,64); // stream ID or txid - std::string seqid = str.substr (72,8); // sequence ID - std::string data = str.substr (80); // data chunk + std::string idstr = opretstr.substr (8,64); // stream ID or txid + std::string seqid = opretstr.substr (72,8); // sequence ID + std::string data = opretstr.substr (80); // data chunk objTx.push_back(Pair("idstr", idstr)); objTx.push_back(Pair("seqid", seqid)); objTx.push_back(Pair("data", data)); From deeb2e2d20c347557162c948ef51ad4c8446fbcb Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Thu, 25 Oct 2018 00:03:36 +0800 Subject: [PATCH 070/127] ; --- src/rpcblockchain.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 206aabfcf..85c7ce343 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -350,7 +350,7 @@ UniValue getdatafromblock(const UniValue& params, bool fHelp) i = i + 1; } } else { - result.push_back(Pair("error","there are no TX in this block.")) + result.push_back(Pair("error","there are no TX in this block.")); } return result; } From 7566c9f1612f5bcd1bdf0c6f8ccbe5e799acf925 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Thu, 25 Oct 2018 00:21:50 +0800 Subject: [PATCH 071/127] seqid as int --- src/rpcblockchain.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 85c7ce343..cfa823112 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -321,6 +321,7 @@ UniValue getdatafromblock(const UniValue& params, bool fHelp) return chainActive.Height(); */ UniValue result(UniValue::VARR); + unsigned int lastseqid = 0; unsigned int i = 0; fprintf(stderr, "number of tx in block: %ld\n", block.vtx.size()); // Iif block tx size is > 2 then we can do this @@ -337,7 +338,11 @@ UniValue getdatafromblock(const UniValue& params, bool fHelp) std::string opretstr = HexStr(tx.vout[2].scriptPubKey.begin(), tx.vout[2].scriptPubKey.end()); if ( opretstr.size() > 81 ) { std::string idstr = opretstr.substr (8,64); // stream ID or txid - std::string seqid = opretstr.substr (72,8); // sequence ID + std::string seqidstr = opretstr.substr (72,8); // sequence ID + unsigned int seqid; + std::stringstream ss; + ss << std::hex << seqidstr; + ss >> seqid; std::string data = opretstr.substr (80); // data chunk objTx.push_back(Pair("idstr", idstr)); objTx.push_back(Pair("seqid", seqid)); From f8dbd08dc8b14988ae4621b33b115a1630af127e Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Thu, 25 Oct 2018 00:24:20 +0800 Subject: [PATCH 072/127] ? --- src/rpcblockchain.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index cfa823112..16316ae4e 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -345,7 +345,7 @@ UniValue getdatafromblock(const UniValue& params, bool fHelp) ss >> seqid; std::string data = opretstr.substr (80); // data chunk objTx.push_back(Pair("idstr", idstr)); - objTx.push_back(Pair("seqid", seqid)); + objTx.push_back(Pair("seqid", (int)seqid)); objTx.push_back(Pair("data", data)); result.push_back(objTx); } From b52da6b92141cfff32588b7e17f5a50982b25fa1 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Thu, 25 Oct 2018 00:52:33 +0800 Subject: [PATCH 073/127] try --- src/rpcblockchain.cpp | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 16316ae4e..a4d5d8040 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -321,8 +321,9 @@ UniValue getdatafromblock(const UniValue& params, bool fHelp) return chainActive.Height(); */ UniValue result(UniValue::VARR); - unsigned int lastseqid = 0; - unsigned int i = 0; + unsigned int firstdeqid = lastseqid = i = did1 = 0; + static std::string streamid,firsttxid; + std::string blockdata; fprintf(stderr, "number of tx in block: %ld\n", block.vtx.size()); // Iif block tx size is > 2 then we can do this if ( block.vtx.size() > 2 ) { @@ -334,26 +335,37 @@ UniValue getdatafromblock(const UniValue& params, bool fHelp) fprintf(stderr, "skipped tx number: %d \n",i); } else { fprintf(stderr, "added tx number: %d \n",i); - UniValue objTx(UniValue::VOBJ); std::string opretstr = HexStr(tx.vout[2].scriptPubKey.begin(), tx.vout[2].scriptPubKey.end()); if ( opretstr.size() > 81 ) { std::string idstr = opretstr.substr (8,64); // stream ID or txid std::string seqidstr = opretstr.substr (72,8); // sequence ID + std::string data = opretstr.substr (80); // data chunk unsigned int seqid; std::stringstream ss; ss << std::hex << seqidstr; ss >> seqid; - std::string data = opretstr.substr (80); // data chunk - objTx.push_back(Pair("idstr", idstr)); - objTx.push_back(Pair("seqid", (int)seqid)); - objTx.push_back(Pair("data", data)); - result.push_back(objTx); + if ( seqid == 1 ) { + streamid = idstr; + } + if ( seqid == (lastseqid + 1 )) { + blockdata.append(data); + } + if ( did1 == 0 ) { + firstdeqid = seqid; + did1 = 1; + } + lastseqid = seqid; } // function here to extract seqid from first and last TX // we an push the data or not depending on input from RPC. } i = i + 1; } + result.push_back(Pair("streamid", streamid)); + result.push_back(Pair("firstseqid", (int)firstseqid)); + result.push_back(Pair("lastseqid", (int)lastseqid)); + result.push_back(Pair("data", blockdata)); + result.push_back(objTx); } else { result.push_back(Pair("error","there are no TX in this block.")); } From d640ffcea71a8012ec84fdfa120d1b884161f5d9 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Thu, 25 Oct 2018 00:54:11 +0800 Subject: [PATCH 074/127] fix --- src/rpcblockchain.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index a4d5d8040..c9942a5f4 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -321,7 +321,7 @@ UniValue getdatafromblock(const UniValue& params, bool fHelp) return chainActive.Height(); */ UniValue result(UniValue::VARR); - unsigned int firstdeqid = lastseqid = i = did1 = 0; + unsigned int firstdeqid,lastseqid,i,did1; static std::string streamid,firsttxid; std::string blockdata; fprintf(stderr, "number of tx in block: %ld\n", block.vtx.size()); From 04278865dc9596951bed0fb46a60ea0209b7c3d3 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Thu, 25 Oct 2018 00:54:28 +0800 Subject: [PATCH 075/127] fix --- src/rpcblockchain.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index c9942a5f4..674f99f42 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -365,7 +365,6 @@ UniValue getdatafromblock(const UniValue& params, bool fHelp) result.push_back(Pair("firstseqid", (int)firstseqid)); result.push_back(Pair("lastseqid", (int)lastseqid)); result.push_back(Pair("data", blockdata)); - result.push_back(objTx); } else { result.push_back(Pair("error","there are no TX in this block.")); } From 61cbc5257fceb7435faa3f238411a745176df961 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Thu, 25 Oct 2018 00:55:30 +0800 Subject: [PATCH 076/127] fix --- src/rpcblockchain.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 674f99f42..847ee13db 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -321,7 +321,7 @@ UniValue getdatafromblock(const UniValue& params, bool fHelp) return chainActive.Height(); */ UniValue result(UniValue::VARR); - unsigned int firstdeqid,lastseqid,i,did1; + unsigned int firstseqid,lastseqid,i,did1; static std::string streamid,firsttxid; std::string blockdata; fprintf(stderr, "number of tx in block: %ld\n", block.vtx.size()); From 11eccfa80bbdea7da4995e8001fb5185156c7910 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Thu, 25 Oct 2018 00:56:24 +0800 Subject: [PATCH 077/127] fix --- src/rpcblockchain.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 847ee13db..51036995d 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -351,7 +351,7 @@ UniValue getdatafromblock(const UniValue& params, bool fHelp) blockdata.append(data); } if ( did1 == 0 ) { - firstdeqid = seqid; + firstseqid = seqid; did1 = 1; } lastseqid = seqid; From 659f97c027ca016c0ef9224cb5dc86308cb69fca Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Thu, 25 Oct 2018 01:02:19 +0800 Subject: [PATCH 078/127] fix? --- src/rpcblockchain.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 51036995d..f3f483b5b 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -320,7 +320,7 @@ UniValue getdatafromblock(const UniValue& params, bool fHelp) } return chainActive.Height(); */ - UniValue result(UniValue::VARR); + UniValue result(UniValue::VOBJ); unsigned int firstseqid,lastseqid,i,did1; static std::string streamid,firsttxid; std::string blockdata; @@ -332,9 +332,9 @@ UniValue getdatafromblock(const UniValue& params, bool fHelp) // ignore first and last TX and any TX that does not have 3 vouts. if ( (i == 0) || (i == (block.vtx.size() -1)) || (tx.vout.size() != 3) ) { - fprintf(stderr, "skipped tx number: %d \n",i); + fprintf(stderr, "skipped tx number: %u \n",i); } else { - fprintf(stderr, "added tx number: %d \n",i); + fprintf(stderr, "added tx number: %u \n",i); std::string opretstr = HexStr(tx.vout[2].scriptPubKey.begin(), tx.vout[2].scriptPubKey.end()); if ( opretstr.size() > 81 ) { std::string idstr = opretstr.substr (8,64); // stream ID or txid @@ -346,6 +346,7 @@ UniValue getdatafromblock(const UniValue& params, bool fHelp) ss >> seqid; if ( seqid == 1 ) { streamid = idstr; + printf("streamid: %s\n",streamid.c_str()); } if ( seqid == (lastseqid + 1 )) { blockdata.append(data); @@ -353,6 +354,7 @@ UniValue getdatafromblock(const UniValue& params, bool fHelp) if ( did1 == 0 ) { firstseqid = seqid; did1 = 1; + printf("DID 1 first seqid = %u\n", firstseqid); } lastseqid = seqid; } From 426015aa75d50e763065e15d5c629f3ef80a9f05 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Thu, 25 Oct 2018 01:09:19 +0800 Subject: [PATCH 079/127] WOW! it works --- src/rpcblockchain.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index f3f483b5b..adaed6b2e 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -321,7 +321,7 @@ UniValue getdatafromblock(const UniValue& params, bool fHelp) return chainActive.Height(); */ UniValue result(UniValue::VOBJ); - unsigned int firstseqid,lastseqid,i,did1; + signed int firstseqid,lastseqid,i,did1; static std::string streamid,firsttxid; std::string blockdata; fprintf(stderr, "number of tx in block: %ld\n", block.vtx.size()); @@ -332,9 +332,9 @@ UniValue getdatafromblock(const UniValue& params, bool fHelp) // ignore first and last TX and any TX that does not have 3 vouts. if ( (i == 0) || (i == (block.vtx.size() -1)) || (tx.vout.size() != 3) ) { - fprintf(stderr, "skipped tx number: %u \n",i); + fprintf(stderr, "skipped tx number: %d \n",i); } else { - fprintf(stderr, "added tx number: %u \n",i); + fprintf(stderr, "added tx number: %d \n",i); std::string opretstr = HexStr(tx.vout[2].scriptPubKey.begin(), tx.vout[2].scriptPubKey.end()); if ( opretstr.size() > 81 ) { std::string idstr = opretstr.substr (8,64); // stream ID or txid @@ -346,7 +346,8 @@ UniValue getdatafromblock(const UniValue& params, bool fHelp) ss >> seqid; if ( seqid == 1 ) { streamid = idstr; - printf("streamid: %s\n",streamid.c_str()); + } else if ( seqid == 2 ) { + firsttxid = idstr; } if ( seqid == (lastseqid + 1 )) { blockdata.append(data); @@ -354,7 +355,6 @@ UniValue getdatafromblock(const UniValue& params, bool fHelp) if ( did1 == 0 ) { firstseqid = seqid; did1 = 1; - printf("DID 1 first seqid = %u\n", firstseqid); } lastseqid = seqid; } @@ -364,6 +364,7 @@ UniValue getdatafromblock(const UniValue& params, bool fHelp) i = i + 1; } result.push_back(Pair("streamid", streamid)); + result.push_back(Pair("firsttxid", firsttxid)); result.push_back(Pair("firstseqid", (int)firstseqid)); result.push_back(Pair("lastseqid", (int)lastseqid)); result.push_back(Pair("data", blockdata)); From 3d29921a2562895d1634031e36400618a76aa111 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Thu, 25 Oct 2018 01:13:43 +0800 Subject: [PATCH 080/127] fix --- src/rpcblockchain.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index adaed6b2e..56ac5f777 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -321,7 +321,9 @@ UniValue getdatafromblock(const UniValue& params, bool fHelp) return chainActive.Height(); */ UniValue result(UniValue::VOBJ); - signed int firstseqid,lastseqid,i,did1; + signed int firstseqid,lastseqid; + int i = 0; + int did1 = 0; static std::string streamid,firsttxid; std::string blockdata; fprintf(stderr, "number of tx in block: %ld\n", block.vtx.size()); @@ -332,9 +334,8 @@ UniValue getdatafromblock(const UniValue& params, bool fHelp) // ignore first and last TX and any TX that does not have 3 vouts. if ( (i == 0) || (i == (block.vtx.size() -1)) || (tx.vout.size() != 3) ) { - fprintf(stderr, "skipped tx number: %d \n",i); + fprintf(stderr, "skipped tx number: %d\n,i"; } else { - fprintf(stderr, "added tx number: %d \n",i); std::string opretstr = HexStr(tx.vout[2].scriptPubKey.begin(), tx.vout[2].scriptPubKey.end()); if ( opretstr.size() > 81 ) { std::string idstr = opretstr.substr (8,64); // stream ID or txid From 81ae02e649f3565bf3a285ea29de52b322c05341 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Thu, 25 Oct 2018 01:14:47 +0800 Subject: [PATCH 081/127] oops --- src/rpcblockchain.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 56ac5f777..a972900c1 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -334,7 +334,7 @@ UniValue getdatafromblock(const UniValue& params, bool fHelp) // ignore first and last TX and any TX that does not have 3 vouts. if ( (i == 0) || (i == (block.vtx.size() -1)) || (tx.vout.size() != 3) ) { - fprintf(stderr, "skipped tx number: %d\n,i"; + fprintf(stderr, "skipped tx number: %d\n,i)"; } else { std::string opretstr = HexStr(tx.vout[2].scriptPubKey.begin(), tx.vout[2].scriptPubKey.end()); if ( opretstr.size() > 81 ) { From e42dcb0474697084d94ad3c1761e6a19cbfcf4f6 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Thu, 25 Oct 2018 10:24:19 +0800 Subject: [PATCH 082/127] more stuff --- src/rpcblockchain.cpp | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index a972900c1..0468ace89 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -257,6 +257,12 @@ UniValue blockToDeltasJSON(const CBlock& block, const CBlockIndex* blockindex) return result; } +int convertstreamid(char *streamid_str, char *streamid_hex) { + char decodedhextest[32]; + decode_hex(streamid_str,32,streamid_hex); + printf("decoded hex: %s\n",decodedhextest); +} + UniValue getdatafromblock(const UniValue& params, bool fHelp) { if (fHelp || params.size() < 1 || params.size() > 2) @@ -314,12 +320,6 @@ UniValue getdatafromblock(const UniValue& params, bool fHelp) if(!ReadBlockFromDisk(block, pblockindex,1)) throw JSONRPCError(RPC_INTERNAL_ERROR, "Can't read block from disk"); - /*BOOST_FOREACH(const CTransaction&tx, block.vtx) - { - fprintf(stderr, "%s\n",tx.GetHash().GetHex().cstr()); - } - return chainActive.Height(); - */ UniValue result(UniValue::VOBJ); signed int firstseqid,lastseqid; int i = 0; @@ -338,9 +338,9 @@ UniValue getdatafromblock(const UniValue& params, bool fHelp) } else { std::string opretstr = HexStr(tx.vout[2].scriptPubKey.begin(), tx.vout[2].scriptPubKey.end()); if ( opretstr.size() > 81 ) { - std::string idstr = opretstr.substr (8,64); // stream ID or txid + std::string idstr = opretstr.substr (8,64); // stream ID or txid std::string seqidstr = opretstr.substr (72,8); // sequence ID - std::string data = opretstr.substr (80); // data chunk + std::string data = opretstr.substr (80); // data chunk unsigned int seqid; std::stringstream ss; ss << std::hex << seqidstr; @@ -349,6 +349,8 @@ UniValue getdatafromblock(const UniValue& params, bool fHelp) streamid = idstr; } else if ( seqid == 2 ) { firsttxid = idstr; + } else if (firsttxid.isempty()) { + firsttxid == idstr; } if ( seqid == (lastseqid + 1 )) { blockdata.append(data); @@ -364,13 +366,24 @@ UniValue getdatafromblock(const UniValue& params, bool fHelp) } i = i + 1; } - result.push_back(Pair("streamid", streamid)); + if (streamid.isempty()) { + uint256 hash,firsttxid_256; CTransaction firsttx; + firsttxid_256 = bits256_conv(firsttxid); + if (GetTransaction(firsttxid_256,firsttx,hash,false)) { + std::string firststreamid = HexStr(firsttx.vout[2].scriptPubKey.begin(), firsttx.vout[2].scriptPubKey.end()); + std::string streamid = firststreamid.substr (8,64); + } + } + char decodedstreamid[32]; + decode_hex(decodedstreamid,32,streamid.c_str()); + printf("decoded hex: %s\n",decodedstreamid); + result.push_back(Pair("streamid", decodedstreamid); result.push_back(Pair("firsttxid", firsttxid)); result.push_back(Pair("firstseqid", (int)firstseqid)); result.push_back(Pair("lastseqid", (int)lastseqid)); result.push_back(Pair("data", blockdata)); } else { - result.push_back(Pair("error","there are no TX in this block.")); + result.push_back(Pair("error","there is no data in this block.")); } return result; } From be21e25e563456e18a6642358cb2bb80778e4a1f Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Thu, 25 Oct 2018 10:32:55 +0800 Subject: [PATCH 083/127] fix --- src/rpcblockchain.cpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 0468ace89..45ce9b70c 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -257,10 +257,14 @@ UniValue blockToDeltasJSON(const CBlock& block, const CBlockIndex* blockindex) return result; } -int convertstreamid(char *streamid_str, char *streamid_hex) { - char decodedhextest[32]; - decode_hex(streamid_str,32,streamid_hex); - printf("decoded hex: %s\n",decodedhextest); +int32_t decode_hex(uint8_t *bytes,int32_t n,char *hex); +bits256 bits256_conv(char *hexstr) +{ + bits256 x; + memset(&x,0,sizeof(x)); + if ( strlen(hexstr) == sizeof(x)*2) + decode_hex(x.bytes,sizeof(x.bytes),hexstr); + return(x); } UniValue getdatafromblock(const UniValue& params, bool fHelp) @@ -349,7 +353,7 @@ UniValue getdatafromblock(const UniValue& params, bool fHelp) streamid = idstr; } else if ( seqid == 2 ) { firsttxid = idstr; - } else if (firsttxid.isempty()) { + } else if (firsttxid.empty()) { firsttxid == idstr; } if ( seqid == (lastseqid + 1 )) { @@ -366,7 +370,7 @@ UniValue getdatafromblock(const UniValue& params, bool fHelp) } i = i + 1; } - if (streamid.isempty()) { + if (streamid.empty()) { uint256 hash,firsttxid_256; CTransaction firsttx; firsttxid_256 = bits256_conv(firsttxid); if (GetTransaction(firsttxid_256,firsttx,hash,false)) { From aae6bbcdf263295a4fbcc7fa025c493a91716f1c Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Thu, 25 Oct 2018 10:35:51 +0800 Subject: [PATCH 084/127] fix some --- src/rpcblockchain.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 45ce9b70c..f77f5dba7 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -338,7 +338,7 @@ UniValue getdatafromblock(const UniValue& params, bool fHelp) // ignore first and last TX and any TX that does not have 3 vouts. if ( (i == 0) || (i == (block.vtx.size() -1)) || (tx.vout.size() != 3) ) { - fprintf(stderr, "skipped tx number: %d\n,i)"; + fprintf(stderr, "skipped tx number: %d\n",i); } else { std::string opretstr = HexStr(tx.vout[2].scriptPubKey.begin(), tx.vout[2].scriptPubKey.end()); if ( opretstr.size() > 81 ) { @@ -381,7 +381,7 @@ UniValue getdatafromblock(const UniValue& params, bool fHelp) char decodedstreamid[32]; decode_hex(decodedstreamid,32,streamid.c_str()); printf("decoded hex: %s\n",decodedstreamid); - result.push_back(Pair("streamid", decodedstreamid); + result.push_back(Pair("streamid", decodedstreamid)); result.push_back(Pair("firsttxid", firsttxid)); result.push_back(Pair("firstseqid", (int)firstseqid)); result.push_back(Pair("lastseqid", (int)lastseqid)); From 5e0dd924c6cda3f6d2f24eaa9cc8e24956ec0dcf Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Thu, 25 Oct 2018 10:51:28 +0800 Subject: [PATCH 085/127] try --- src/rpcblockchain.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index f77f5dba7..e48473c1c 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -258,9 +258,9 @@ UniValue blockToDeltasJSON(const CBlock& block, const CBlockIndex* blockindex) } int32_t decode_hex(uint8_t *bytes,int32_t n,char *hex); -bits256 bits256_conv(char *hexstr) +uint256 bits256_conv(char *hexstr) { - bits256 x; + uint256 x; memset(&x,0,sizeof(x)); if ( strlen(hexstr) == sizeof(x)*2) decode_hex(x.bytes,sizeof(x.bytes),hexstr); @@ -379,8 +379,8 @@ UniValue getdatafromblock(const UniValue& params, bool fHelp) } } char decodedstreamid[32]; - decode_hex(decodedstreamid,32,streamid.c_str()); - printf("decoded hex: %s\n",decodedstreamid); + decode_hex((char *)decodedstreamid,32,streamid.c_str()); + printf("decoded hex: %s\n",(char *)decodedstreamid); result.push_back(Pair("streamid", decodedstreamid)); result.push_back(Pair("firsttxid", firsttxid)); result.push_back(Pair("firstseqid", (int)firstseqid)); From a1141951cab2afa1c0ebeb3a3547579be9c5d884 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Thu, 25 Oct 2018 11:05:53 +0800 Subject: [PATCH 086/127] try --- src/rpcblockchain.cpp | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index e48473c1c..d0eb45401 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -258,14 +258,6 @@ UniValue blockToDeltasJSON(const CBlock& block, const CBlockIndex* blockindex) } int32_t decode_hex(uint8_t *bytes,int32_t n,char *hex); -uint256 bits256_conv(char *hexstr) -{ - uint256 x; - memset(&x,0,sizeof(x)); - if ( strlen(hexstr) == sizeof(x)*2) - decode_hex(x.bytes,sizeof(x.bytes),hexstr); - return(x); -} UniValue getdatafromblock(const UniValue& params, bool fHelp) { @@ -371,15 +363,15 @@ UniValue getdatafromblock(const UniValue& params, bool fHelp) i = i + 1; } if (streamid.empty()) { - uint256 hash,firsttxid_256; CTransaction firsttx; - firsttxid_256 = bits256_conv(firsttxid); + uint256 hash; CTransaction firsttx; + uint256 firsttxid_256 = ParseHashV(firsttxid); if (GetTransaction(firsttxid_256,firsttx,hash,false)) { std::string firststreamid = HexStr(firsttx.vout[2].scriptPubKey.begin(), firsttx.vout[2].scriptPubKey.end()); std::string streamid = firststreamid.substr (8,64); } } char decodedstreamid[32]; - decode_hex((char *)decodedstreamid,32,streamid.c_str()); + decode_hex((uint8_t)decodedstreamid,32,streamid.c_str()); printf("decoded hex: %s\n",(char *)decodedstreamid); result.push_back(Pair("streamid", decodedstreamid)); result.push_back(Pair("firsttxid", firsttxid)); From 7768292e180714c1b980c18425a9ddb5f7d378f2 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Thu, 25 Oct 2018 11:08:15 +0800 Subject: [PATCH 087/127] ? --- src/rpcblockchain.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index d0eb45401..b798cb22e 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -364,7 +364,7 @@ UniValue getdatafromblock(const UniValue& params, bool fHelp) } if (streamid.empty()) { uint256 hash; CTransaction firsttx; - uint256 firsttxid_256 = ParseHashV(firsttxid); + uint256 firsttxid_256 = ParseHashV(firsttxid,"firsttxid"); if (GetTransaction(firsttxid_256,firsttx,hash,false)) { std::string firststreamid = HexStr(firsttx.vout[2].scriptPubKey.begin(), firsttx.vout[2].scriptPubKey.end()); std::string streamid = firststreamid.substr (8,64); From 2630e93a16851c5b6549fe2604d63ff2abe492fb Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Thu, 25 Oct 2018 11:11:42 +0800 Subject: [PATCH 088/127] ? --- src/rpcblockchain.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index b798cb22e..c32e645da 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -257,7 +257,7 @@ UniValue blockToDeltasJSON(const CBlock& block, const CBlockIndex* blockindex) return result; } -int32_t decode_hex(uint8_t *bytes,int32_t n,char *hex); +int32_t decode_hex(char *bytes,int32_t n,char *hex); UniValue getdatafromblock(const UniValue& params, bool fHelp) { @@ -371,7 +371,7 @@ UniValue getdatafromblock(const UniValue& params, bool fHelp) } } char decodedstreamid[32]; - decode_hex((uint8_t)decodedstreamid,32,streamid.c_str()); + decode_hex(decodedstreamid,32,streamid.c_str()); printf("decoded hex: %s\n",(char *)decodedstreamid); result.push_back(Pair("streamid", decodedstreamid)); result.push_back(Pair("firsttxid", firsttxid)); From 5b11f256aae923e98c47920000131a2b61e7b1ad Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Thu, 25 Oct 2018 11:15:07 +0800 Subject: [PATCH 089/127] fix --- src/rpcblockchain.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index c32e645da..a009a2752 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -371,7 +371,7 @@ UniValue getdatafromblock(const UniValue& params, bool fHelp) } } char decodedstreamid[32]; - decode_hex(decodedstreamid,32,streamid.c_str()); + decode_hex(decodedstreamid,32,(char *)streamid.c_str()); printf("decoded hex: %s\n",(char *)decodedstreamid); result.push_back(Pair("streamid", decodedstreamid)); result.push_back(Pair("firsttxid", firsttxid)); From 89f6e171dee2c861b7928b89eca6bb8b722c74e5 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Thu, 25 Oct 2018 11:17:16 +0800 Subject: [PATCH 090/127] again --- src/rpcblockchain.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index a009a2752..b0dd031a9 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -257,7 +257,7 @@ UniValue blockToDeltasJSON(const CBlock& block, const CBlockIndex* blockindex) return result; } -int32_t decode_hex(char *bytes,int32_t n,char *hex); +int32_t decode_hex(uint8_t bytes,int32_t n,char *hex); UniValue getdatafromblock(const UniValue& params, bool fHelp) { From 5d5c1bd4738821416cbf01b57f616cbb68a62098 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Thu, 25 Oct 2018 11:25:40 +0800 Subject: [PATCH 091/127] try --- src/rpcblockchain.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index b0dd031a9..c062669a7 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -370,7 +370,7 @@ UniValue getdatafromblock(const UniValue& params, bool fHelp) std::string streamid = firststreamid.substr (8,64); } } - char decodedstreamid[32]; + uint8_t decodedstreamid[32]; decode_hex(decodedstreamid,32,(char *)streamid.c_str()); printf("decoded hex: %s\n",(char *)decodedstreamid); result.push_back(Pair("streamid", decodedstreamid)); From 1e8cd9ff69ddcb4a37ff5c1d47a2d69133e9ff63 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Thu, 25 Oct 2018 11:28:28 +0800 Subject: [PATCH 092/127] ? --- src/rpcblockchain.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index c062669a7..74b3f297d 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -371,7 +371,7 @@ UniValue getdatafromblock(const UniValue& params, bool fHelp) } } uint8_t decodedstreamid[32]; - decode_hex(decodedstreamid,32,(char *)streamid.c_str()); + decode_hex(*decodedstreamid,32,(char *)streamid.c_str()); printf("decoded hex: %s\n",(char *)decodedstreamid); result.push_back(Pair("streamid", decodedstreamid)); result.push_back(Pair("firsttxid", firsttxid)); From e8caddfca3adfbc4f848e8c3b3da961332c02bab Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Thu, 25 Oct 2018 11:31:20 +0800 Subject: [PATCH 093/127] include decode hex --- src/rpcblockchain.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 74b3f297d..76395ca8f 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -20,6 +20,7 @@ #include "script/script_error.h" #include "script/sign.h" #include "script/standard.h" +#include "komodo_utils.h" #include From 5489c976f0c479a69997ad69b315471deebc2832 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Thu, 25 Oct 2018 11:37:54 +0800 Subject: [PATCH 094/127] fix --- src/rpcblockchain.cpp | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 76395ca8f..eec2130c1 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -20,7 +20,6 @@ #include "script/script_error.h" #include "script/sign.h" #include "script/standard.h" -#include "komodo_utils.h" #include @@ -258,7 +257,30 @@ UniValue blockToDeltasJSON(const CBlock& block, const CBlockIndex* blockindex) return result; } -int32_t decode_hex(uint8_t bytes,int32_t n,char *hex); +unsigned char hexval(unsigned char c) +{ + if ('0' <= c && c <= '9') + return c - '0'; + else if ('a' <= c && c <= 'f') + return c - 'a' + 10; + else if ('A' <= c && c <= 'F') + return c - 'A' + 10; + else abort(); +} + +void hex2ascii(const string& in, string& out) +{ + out.clear(); + out.reserve(in.length() / 2); + for (string::const_iterator p = in.begin(); p != in.end(); p++) + { + unsigned char c = hexval(*p); + p++; + if (p == in.end()) break; // incomplete last digit - should report error + c = (c << 4) + hexval(*p); // + takes precedence over << + out.push_back(c); + } +} UniValue getdatafromblock(const UniValue& params, bool fHelp) { @@ -371,9 +393,8 @@ UniValue getdatafromblock(const UniValue& params, bool fHelp) std::string streamid = firststreamid.substr (8,64); } } - uint8_t decodedstreamid[32]; - decode_hex(*decodedstreamid,32,(char *)streamid.c_str()); - printf("decoded hex: %s\n",(char *)decodedstreamid); + std::string decodedstreamid; + hex2ascii(streamid, decodedstreamid); result.push_back(Pair("streamid", decodedstreamid)); result.push_back(Pair("firsttxid", firsttxid)); result.push_back(Pair("firstseqid", (int)firstseqid)); From 95992d4492aff6bdd2ce865697b357fe7e1f0192 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Thu, 25 Oct 2018 11:50:47 +0800 Subject: [PATCH 095/127] add t/f flag for data --- src/rpcblockchain.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index eec2130c1..5f6142300 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -330,6 +330,10 @@ UniValue getdatafromblock(const UniValue& params, bool fHelp) if (mapBlockIndex.count(hash) == 0) throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block not found"); + bool fVerbose = true; + if (params.size() > 1) + fVerbose = params[1].get_bool(); + CBlock block; CBlockIndex* pblockindex = mapBlockIndex[hash]; @@ -399,7 +403,9 @@ UniValue getdatafromblock(const UniValue& params, bool fHelp) result.push_back(Pair("firsttxid", firsttxid)); result.push_back(Pair("firstseqid", (int)firstseqid)); result.push_back(Pair("lastseqid", (int)lastseqid)); - result.push_back(Pair("data", blockdata)); + if (fVerbose) { + result.push_back(Pair("data", blockdata)); + } } else { result.push_back(Pair("error","there is no data in this block.")); } From c4434400d19d42dc9fd05d767f5d9244c6c1dc40 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Thu, 25 Oct 2018 11:55:29 +0800 Subject: [PATCH 096/127] try --- src/rpcblockchain.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 5f6142300..612acf2bf 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -330,9 +330,9 @@ UniValue getdatafromblock(const UniValue& params, bool fHelp) if (mapBlockIndex.count(hash) == 0) throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block not found"); - bool fVerbose = true; + bool fVerbose = false; if (params.size() > 1) - fVerbose = params[1].get_bool(); + fVerbose = (params[1].get_int() != 0); CBlock block; CBlockIndex* pblockindex = mapBlockIndex[hash]; From e8cd54ea2fbdb43b495792acf5979ac3d8851f94 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Thu, 25 Oct 2018 12:02:58 +0800 Subject: [PATCH 097/127] ? --- src/rpcblockchain.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 612acf2bf..0178fbf43 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -373,6 +373,7 @@ UniValue getdatafromblock(const UniValue& params, bool fHelp) } else if ( seqid == 2 ) { firsttxid = idstr; } else if (firsttxid.empty()) { + printf("firsttxid is empty: %s\n",idstr.c_str()); firsttxid == idstr; } if ( seqid == (lastseqid + 1 )) { From 6ac869140f17fbead6dff7e1e68d5315032aea8f Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Thu, 25 Oct 2018 12:53:05 +0800 Subject: [PATCH 098/127] ? --- src/rpcblockchain.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 0178fbf43..204ea7b23 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -374,7 +374,7 @@ UniValue getdatafromblock(const UniValue& params, bool fHelp) firsttxid = idstr; } else if (firsttxid.empty()) { printf("firsttxid is empty: %s\n",idstr.c_str()); - firsttxid == idstr; + firsttxid.append(idstr); } if ( seqid == (lastseqid + 1 )) { blockdata.append(data); @@ -392,7 +392,7 @@ UniValue getdatafromblock(const UniValue& params, bool fHelp) } if (streamid.empty()) { uint256 hash; CTransaction firsttx; - uint256 firsttxid_256 = ParseHashV(firsttxid,"firsttxid"); + uint256 firsttxid_256(uint256S(firsttxid)); if (GetTransaction(firsttxid_256,firsttx,hash,false)) { std::string firststreamid = HexStr(firsttx.vout[2].scriptPubKey.begin(), firsttx.vout[2].scriptPubKey.end()); std::string streamid = firststreamid.substr (8,64); From ee7e3de254a836821036585c8f60ffca8a54ec7c Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Thu, 25 Oct 2018 12:57:07 +0800 Subject: [PATCH 099/127] fix --- src/rpcblockchain.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 204ea7b23..0fdb17dea 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -395,7 +395,7 @@ UniValue getdatafromblock(const UniValue& params, bool fHelp) uint256 firsttxid_256(uint256S(firsttxid)); if (GetTransaction(firsttxid_256,firsttx,hash,false)) { std::string firststreamid = HexStr(firsttx.vout[2].scriptPubKey.begin(), firsttx.vout[2].scriptPubKey.end()); - std::string streamid = firststreamid.substr (8,64); + streamid.append(firststreamid.substr (8,64)); } } std::string decodedstreamid; From 07f2fa7b1f4a1d7a45708008df4860cf2dac563f Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Thu, 25 Oct 2018 13:00:29 +0800 Subject: [PATCH 100/127] hex --- src/rpcblockchain.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 0fdb17dea..38c450224 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -401,6 +401,7 @@ UniValue getdatafromblock(const UniValue& params, bool fHelp) std::string decodedstreamid; hex2ascii(streamid, decodedstreamid); result.push_back(Pair("streamid", decodedstreamid)); + result.push_back(Pair("streamidhex", streamid)); result.push_back(Pair("firsttxid", firsttxid)); result.push_back(Pair("firstseqid", (int)firstseqid)); result.push_back(Pair("lastseqid", (int)lastseqid)); From d32cdefe7bc9b415469d407e9ea91e145a3bb68f Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Thu, 25 Oct 2018 13:18:23 +0800 Subject: [PATCH 101/127] test --- src/rpcblockchain.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 38c450224..f013420e4 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -278,6 +278,7 @@ void hex2ascii(const string& in, string& out) p++; if (p == in.end()) break; // incomplete last digit - should report error c = (c << 4) + hexval(*p); // + takes precedence over << + printf("char: %d\n",c); out.push_back(c); } } From ed7c03730365c8cca5a77a38570eed48009d52c6 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Thu, 25 Oct 2018 13:26:17 +0800 Subject: [PATCH 102/127] try --- src/rpcblockchain.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index f013420e4..655d2c906 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -278,7 +278,6 @@ void hex2ascii(const string& in, string& out) p++; if (p == in.end()) break; // incomplete last digit - should report error c = (c << 4) + hexval(*p); // + takes precedence over << - printf("char: %d\n",c); out.push_back(c); } } @@ -401,7 +400,7 @@ UniValue getdatafromblock(const UniValue& params, bool fHelp) } std::string decodedstreamid; hex2ascii(streamid, decodedstreamid); - result.push_back(Pair("streamid", decodedstreamid)); + result.push_back(Pair("streamid", decodedstreamid.c_str())); result.push_back(Pair("streamidhex", streamid)); result.push_back(Pair("firsttxid", firsttxid)); result.push_back(Pair("firstseqid", (int)firstseqid)); From 1ec39b2b97a7b1361303020f7048988b3466455a Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Thu, 25 Oct 2018 14:09:51 +0800 Subject: [PATCH 103/127] try 2 arg as str --- src/rpcblockchain.cpp | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 655d2c906..cd7167dcf 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -303,6 +303,11 @@ UniValue getdatafromblock(const UniValue& params, bool fHelp) std::string strHash = params[0].get_str(); + if (params.size() > 1) { + std::string getdata = params[1].get_str(); + printf("%s\n",getdata.c_str()); + } + // If height is supplied, find the hash if (strHash.size() < (2 * sizeof(uint256))) { // std::stoi allows characters, whereas we want to be strict @@ -330,10 +335,6 @@ UniValue getdatafromblock(const UniValue& params, bool fHelp) if (mapBlockIndex.count(hash) == 0) throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block not found"); - bool fVerbose = false; - if (params.size() > 1) - fVerbose = (params[1].get_int() != 0); - CBlock block; CBlockIndex* pblockindex = mapBlockIndex[hash]; @@ -360,6 +361,7 @@ UniValue getdatafromblock(const UniValue& params, bool fHelp) fprintf(stderr, "skipped tx number: %d\n",i); } else { std::string opretstr = HexStr(tx.vout[2].scriptPubKey.begin(), tx.vout[2].scriptPubKey.end()); + // scriptPubKey is longer than 81, should mean its an OP_RETURN. if ( opretstr.size() > 81 ) { std::string idstr = opretstr.substr (8,64); // stream ID or txid std::string seqidstr = opretstr.substr (72,8); // sequence ID @@ -373,11 +375,15 @@ UniValue getdatafromblock(const UniValue& params, bool fHelp) } else if ( seqid == 2 ) { firsttxid = idstr; } else if (firsttxid.empty()) { - printf("firsttxid is empty: %s\n",idstr.c_str()); firsttxid.append(idstr); } + if ( seqid == (lastseqid + 1 )) { blockdata.append(data); + } else { + result.push_back(Pair("error","chunck out of order in this block!")); + result.push_back(Pair("lastvalidseqid", (int)seqid)); + break; } if ( did1 == 0 ) { firstseqid = seqid; @@ -401,7 +407,6 @@ UniValue getdatafromblock(const UniValue& params, bool fHelp) std::string decodedstreamid; hex2ascii(streamid, decodedstreamid); result.push_back(Pair("streamid", decodedstreamid.c_str())); - result.push_back(Pair("streamidhex", streamid)); result.push_back(Pair("firsttxid", firsttxid)); result.push_back(Pair("firstseqid", (int)firstseqid)); result.push_back(Pair("lastseqid", (int)lastseqid)); From a5c99046866f2eaae4616ae4d5a315ba93ff377a Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Thu, 25 Oct 2018 14:11:33 +0800 Subject: [PATCH 104/127] fix --- src/rpcblockchain.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index cd7167dcf..b7def7ea6 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -410,9 +410,9 @@ UniValue getdatafromblock(const UniValue& params, bool fHelp) result.push_back(Pair("firsttxid", firsttxid)); result.push_back(Pair("firstseqid", (int)firstseqid)); result.push_back(Pair("lastseqid", (int)lastseqid)); - if (fVerbose) { - result.push_back(Pair("data", blockdata)); - } + //if (fVerbose) { + // result.push_back(Pair("data", blockdata)); + //} } else { result.push_back(Pair("error","there is no data in this block.")); } From 806a8e93aa997779fd9cb5920db65d8fb78e9a62 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Thu, 25 Oct 2018 14:15:12 +0800 Subject: [PATCH 105/127] fix? --- src/rpcblockchain.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index b7def7ea6..f4ec0d1fa 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -378,7 +378,7 @@ UniValue getdatafromblock(const UniValue& params, bool fHelp) firsttxid.append(idstr); } - if ( seqid == (lastseqid + 1 )) { + if ( (seqid == (lastseqid + 1 )) && lastseqid != 0 ) { blockdata.append(data); } else { result.push_back(Pair("error","chunck out of order in this block!")); From 9b3cd72603436b8f8e4cc0b0835388b94e49c9fa Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Thu, 25 Oct 2018 14:23:26 +0800 Subject: [PATCH 106/127] wtf --- src/rpcblockchain.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index f4ec0d1fa..74536a2af 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -345,7 +345,8 @@ UniValue getdatafromblock(const UniValue& params, bool fHelp) throw JSONRPCError(RPC_INTERNAL_ERROR, "Can't read block from disk"); UniValue result(UniValue::VOBJ); - signed int firstseqid,lastseqid; + int firstseqid = 0; + int lastseqid = 0; int i = 0; int did1 = 0; static std::string streamid,firsttxid; @@ -378,12 +379,13 @@ UniValue getdatafromblock(const UniValue& params, bool fHelp) firsttxid.append(idstr); } - if ( (seqid == (lastseqid + 1 )) && lastseqid != 0 ) { + if ( seqid == (lastseqid + 1 ) ) { blockdata.append(data); } else { + printf("seqid.%d lastseqid.%d\n",seqid,lastseqid); result.push_back(Pair("error","chunck out of order in this block!")); result.push_back(Pair("lastvalidseqid", (int)seqid)); - break; + //break; } if ( did1 == 0 ) { firstseqid = seqid; From 1dd2a13d7c7ea8f231be9b9cdc59d56821910ed7 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Thu, 25 Oct 2018 14:29:13 +0800 Subject: [PATCH 107/127] fixed --- src/rpcblockchain.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 74536a2af..02547ac66 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -379,7 +379,7 @@ UniValue getdatafromblock(const UniValue& params, bool fHelp) firsttxid.append(idstr); } - if ( seqid == (lastseqid + 1 ) ) { + if ( seqid == (lastseqid + 1) || did1 == 0 ) { blockdata.append(data); } else { printf("seqid.%d lastseqid.%d\n",seqid,lastseqid); From a3b73317734d4552f78175e8b1c08a57c811317a Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Thu, 25 Oct 2018 14:52:23 +0800 Subject: [PATCH 108/127] try --- src/rpcblockchain.cpp | 39 +++++++++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 02547ac66..5309b9536 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -286,26 +286,38 @@ UniValue getdatafromblock(const UniValue& params, bool fHelp) { if (fHelp || params.size() < 1 || params.size() > 2) throw runtime_error( - "getdatafromblock \"hash|height\"\n" + "getdatafromblock \"hash|height\" true/false\n" "\nReturns all the data sent via streamer in block if there was any data in it.\n" "\nArguments:\n" "1. \"hash|height\" (string, required) The block hash or height\n" + "2. \"true/false\" (bool, optional) if false do not return the actual data. Default true.\n" + "\nResult (for verbose = true):\n" + "{\n" + " \"streamid\" : \"string\", (string) the name of the stream.\n" + " \"firsttxid\" : \"hash\", (string) the first transaction of the stream.\n" + " \"firstdeqid\" : n, (numeric) The sequence id of the first data chunk in this block\n" + " \"lastseqid\" : n, (numeric) The sequence id of the last data chunk in this block\n" + " \"data\" : \"xxxx\", (string) A hex string containing all the data chunks in this block.\n" + "}\n" "\nResult (for verbose=false):\n" - "\"data\" (string) A string that is serialized, hex-encoded data for block 'hash'.\n" - "\nExamples:\n" - + HelpExampleCli("getblock", "\"00000000c937983704a73af28acdec37b049d214adbda81d7e2a3dd146f6ed09\"") + " \"streamid\" : \"string\", (string) the name of the stream.\n" + " \"firsttxid\" : \"hash\", (string) the first transaction of the stream.\n" + " \"firstdeqid\" : n, (numeric) The sequence id of the first data chunk in this block\n" + " \"lastseqid\" : n, (numeric) The sequence id of the last data chunk in this block\n" + + HelpExampleCli("getblock", "\"00000000c937983704a73af28acdec37b049d214adbda81d7e2a3dd146f6ed09 false\"") + HelpExampleRpc("getblock", "\"00000000c937983704a73af28acdec37b049d214adbda81d7e2a3dd146f6ed09\"") + HelpExampleCli("getblock", "12800") - + HelpExampleRpc("getblock", "12800") + + HelpExampleRpc("getblock", "12800 false") ); LOCK(cs_main); std::string strHash = params[0].get_str(); - + bool fVerbose = true; if (params.size() > 1) { - std::string getdata = params[1].get_str(); - printf("%s\n",getdata.c_str()); + std::string verboseflag = params[1].get_str(); + if ( verboseflag.compare("false") ) + fVerbose = false; } // If height is supplied, find the hash @@ -382,10 +394,9 @@ UniValue getdatafromblock(const UniValue& params, bool fHelp) if ( seqid == (lastseqid + 1) || did1 == 0 ) { blockdata.append(data); } else { - printf("seqid.%d lastseqid.%d\n",seqid,lastseqid); result.push_back(Pair("error","chunck out of order in this block!")); - result.push_back(Pair("lastvalidseqid", (int)seqid)); - //break; + result.push_back(Pair("lastvalidseqid", (int)lastseqid)); + break; } if ( did1 == 0 ) { firstseqid = seqid; @@ -412,9 +423,9 @@ UniValue getdatafromblock(const UniValue& params, bool fHelp) result.push_back(Pair("firsttxid", firsttxid)); result.push_back(Pair("firstseqid", (int)firstseqid)); result.push_back(Pair("lastseqid", (int)lastseqid)); - //if (fVerbose) { - // result.push_back(Pair("data", blockdata)); - //} + if (fVerbose) { + result.push_back(Pair("data", blockdata)); + } } else { result.push_back(Pair("error","there is no data in this block.")); } From abddda8830bf5f4df0b09f95d6b3f66b4ca6d295 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Thu, 25 Oct 2018 14:54:50 +0800 Subject: [PATCH 109/127] try --- src/rpcblockchain.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 5309b9536..31b629ac3 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -316,7 +316,7 @@ UniValue getdatafromblock(const UniValue& params, bool fHelp) bool fVerbose = true; if (params.size() > 1) { std::string verboseflag = params[1].get_str(); - if ( verboseflag.compare("false") ) + if ( verboseflag.compare("false") == 1 ) fVerbose = false; } From 71ee7345e5b5a03e8b03a2272d61f31e2eb9c52f Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Thu, 25 Oct 2018 14:58:22 +0800 Subject: [PATCH 110/127] try again --- src/rpcblockchain.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 31b629ac3..6badd753e 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -316,7 +316,7 @@ UniValue getdatafromblock(const UniValue& params, bool fHelp) bool fVerbose = true; if (params.size() > 1) { std::string verboseflag = params[1].get_str(); - if ( verboseflag.compare("false") == 1 ) + if ( verboseflag == "false" ) fVerbose = false; } From ce5bf4b0811a0fe15848022d4d6a0ffb3deaac9b Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Thu, 25 Oct 2018 14:59:02 +0800 Subject: [PATCH 111/127] fix --- src/rpcblockchain.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 6badd753e..0c19bcc20 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -423,7 +423,7 @@ UniValue getdatafromblock(const UniValue& params, bool fHelp) result.push_back(Pair("firsttxid", firsttxid)); result.push_back(Pair("firstseqid", (int)firstseqid)); result.push_back(Pair("lastseqid", (int)lastseqid)); - if (fVerbose) { + if (fVerbose == true) { result.push_back(Pair("data", blockdata)); } } else { From 900f9fc8ec43a0bef74fd5d0d8423b7cc972c9cf Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Thu, 25 Oct 2018 16:08:39 +0800 Subject: [PATCH 112/127] try to print block hash --- src/rpcblockchain.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 0c19bcc20..1edd2152c 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -415,6 +415,7 @@ UniValue getdatafromblock(const UniValue& params, bool fHelp) if (GetTransaction(firsttxid_256,firsttx,hash,false)) { std::string firststreamid = HexStr(firsttx.vout[2].scriptPubKey.begin(), firsttx.vout[2].scriptPubKey.end()); streamid.append(firststreamid.substr (8,64)); + printf("block hash: %s\n",hash.ToString().c_str()); } } std::string decodedstreamid; From 8cec48894b7c16b6761a270b6d265839eb8cf2fd Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Thu, 25 Oct 2018 16:39:17 +0800 Subject: [PATCH 113/127] more error checks --- src/rpcblockchain.cpp | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 1edd2152c..f2387a691 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -361,17 +361,22 @@ UniValue getdatafromblock(const UniValue& params, bool fHelp) int lastseqid = 0; int i = 0; int did1 = 0; + int skippedtxs = 0; + int failed = 0; static std::string streamid,firsttxid; + static int firsttxnHeight; std::string blockdata; fprintf(stderr, "number of tx in block: %ld\n", block.vtx.size()); // Iif block tx size is > 2 then we can do this - if ( block.vtx.size() > 2 ) { + if ( block.vtx.size() > 2 ) + { BOOST_FOREACH(const CTransaction&tx, block.vtx) { // ignore first and last TX and any TX that does not have 3 vouts. if ( (i == 0) || (i == (block.vtx.size() -1)) || (tx.vout.size() != 3) ) { fprintf(stderr, "skipped tx number: %d\n",i); + skippedtxs = skippedtxs + 1; } else { std::string opretstr = HexStr(tx.vout[2].scriptPubKey.begin(), tx.vout[2].scriptPubKey.end()); // scriptPubKey is longer than 81, should mean its an OP_RETURN. @@ -389,6 +394,8 @@ UniValue getdatafromblock(const UniValue& params, bool fHelp) firsttxid = idstr; } else if (firsttxid.empty()) { firsttxid.append(idstr); + } else if ( firsttxid != idstr ) { + printf("firsttxid.%s idstr.%s change firsttxid and wipe streamid?\n",firsttxid.c_str(),idstr.c_str()); } if ( seqid == (lastseqid + 1) || did1 == 0 ) { @@ -403,6 +410,9 @@ UniValue getdatafromblock(const UniValue& params, bool fHelp) did1 = 1; } lastseqid = seqid; + } else { + skippedtxs = skippedtxs + 1; + fprintf(stderr, "skipped tx number: %d\n",i); } // function here to extract seqid from first and last TX // we an push the data or not depending on input from RPC. @@ -415,7 +425,14 @@ UniValue getdatafromblock(const UniValue& params, bool fHelp) if (GetTransaction(firsttxid_256,firsttx,hash,false)) { std::string firststreamid = HexStr(firsttx.vout[2].scriptPubKey.begin(), firsttx.vout[2].scriptPubKey.end()); streamid.append(firststreamid.substr (8,64)); - printf("block hash: %s\n",hash.ToString().c_str()); + BlockMap::iterator mi = mapBlockIndex.find(hash); + if (mi != mapBlockIndex.end() && (*mi).second) { + CBlockIndex* pindex = (*mi).second; + if (chainActive.Contains(pindex)) { + firsttxnHeight = pindex->nHeight; + printf("block hash: %s block height: %d\n",hash.ToString().c_str(),firsttxnHeight); + } + } } } std::string decodedstreamid; @@ -428,6 +445,10 @@ UniValue getdatafromblock(const UniValue& params, bool fHelp) result.push_back(Pair("data", blockdata)); } } else { + failed = 1; + } + + if ( failed == 1 || skippedtxs == i ) { result.push_back(Pair("error","there is no data in this block.")); } return result; From 2b21b2e94d534915227f58c22e2d24585ffcea40 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Thu, 25 Oct 2018 16:44:01 +0800 Subject: [PATCH 114/127] fix --- src/rpcblockchain.cpp | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index f2387a691..bbd5b6d56 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -435,21 +435,22 @@ UniValue getdatafromblock(const UniValue& params, bool fHelp) } } } - std::string decodedstreamid; - hex2ascii(streamid, decodedstreamid); - result.push_back(Pair("streamid", decodedstreamid.c_str())); - result.push_back(Pair("firsttxid", firsttxid)); - result.push_back(Pair("firstseqid", (int)firstseqid)); - result.push_back(Pair("lastseqid", (int)lastseqid)); - if (fVerbose == true) { - result.push_back(Pair("data", blockdata)); - } } else { failed = 1; } if ( failed == 1 || skippedtxs == i ) { result.push_back(Pair("error","there is no data in this block.")); + } else { + std::string decodedstreamid; + hex2ascii(streamid, decodedstreamid); + result.push_back(Pair("streamid", decodedstreamid.c_str())); + result.push_back(Pair("firsttxid", firsttxid)); + result.push_back(Pair("firstseqid", (int)firstseqid)); + result.push_back(Pair("lastseqid", (int)lastseqid)); + if (fVerbose == true) { + result.push_back(Pair("data", blockdata)); + } } return result; } From 56afde8d171868f0892b25cf0f2427498bb07724 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Thu, 25 Oct 2018 16:52:38 +0800 Subject: [PATCH 115/127] move block print --- src/rpcblockchain.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index bbd5b6d56..94e140aa5 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -430,7 +430,6 @@ UniValue getdatafromblock(const UniValue& params, bool fHelp) CBlockIndex* pindex = (*mi).second; if (chainActive.Contains(pindex)) { firsttxnHeight = pindex->nHeight; - printf("block hash: %s block height: %d\n",hash.ToString().c_str(),firsttxnHeight); } } } @@ -442,6 +441,7 @@ UniValue getdatafromblock(const UniValue& params, bool fHelp) if ( failed == 1 || skippedtxs == i ) { result.push_back(Pair("error","there is no data in this block.")); } else { + printf("block hash: %s block height: %d\n",hash.ToString().c_str(),firsttxnHeight); std::string decodedstreamid; hex2ascii(streamid, decodedstreamid); result.push_back(Pair("streamid", decodedstreamid.c_str())); From d647a00ba762de93ed5f7b63ac37fe009aa1be2b Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Thu, 25 Oct 2018 16:59:24 +0800 Subject: [PATCH 116/127] ready for a new chain --- src/rpcblockchain.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 94e140aa5..a29464201 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -295,6 +295,7 @@ UniValue getdatafromblock(const UniValue& params, bool fHelp) "{\n" " \"streamid\" : \"string\", (string) the name of the stream.\n" " \"firsttxid\" : \"hash\", (string) the first transaction of the stream.\n" + " \"firstblockheight\" : \"n\", (numeric) the block the stream starts in.\n" " \"firstdeqid\" : n, (numeric) The sequence id of the first data chunk in this block\n" " \"lastseqid\" : n, (numeric) The sequence id of the last data chunk in this block\n" " \"data\" : \"xxxx\", (string) A hex string containing all the data chunks in this block.\n" @@ -302,6 +303,7 @@ UniValue getdatafromblock(const UniValue& params, bool fHelp) "\nResult (for verbose=false):\n" " \"streamid\" : \"string\", (string) the name of the stream.\n" " \"firsttxid\" : \"hash\", (string) the first transaction of the stream.\n" + " \"firstblockheight\" : \"n\", (numeric) the block the stream starts in.\n" " \"firstdeqid\" : n, (numeric) The sequence id of the first data chunk in this block\n" " \"lastseqid\" : n, (numeric) The sequence id of the last data chunk in this block\n" + HelpExampleCli("getblock", "\"00000000c937983704a73af28acdec37b049d214adbda81d7e2a3dd146f6ed09 false\"") @@ -446,6 +448,7 @@ UniValue getdatafromblock(const UniValue& params, bool fHelp) hex2ascii(streamid, decodedstreamid); result.push_back(Pair("streamid", decodedstreamid.c_str())); result.push_back(Pair("firsttxid", firsttxid)); + result.push_back(Pair("firstblockheight", (int)firsttxnHeight)); result.push_back(Pair("firstseqid", (int)firstseqid)); result.push_back(Pair("lastseqid", (int)lastseqid)); if (fVerbose == true) { From 8c0de51c083f0b222340d2fb4c8a5d144dbcdb56 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Thu, 25 Oct 2018 17:00:35 +0800 Subject: [PATCH 117/127] fix --- src/rpcblockchain.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index a29464201..0bbba22a8 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -397,7 +397,7 @@ UniValue getdatafromblock(const UniValue& params, bool fHelp) } else if (firsttxid.empty()) { firsttxid.append(idstr); } else if ( firsttxid != idstr ) { - printf("firsttxid.%s idstr.%s change firsttxid and wipe streamid?\n",firsttxid.c_str(),idstr.c_str()); + printf("firsttxid.%s idstr.%s change firsttxid and wipe streamid?\n we are in a new stream here I think\n",firsttxid.c_str(),idstr.c_str()); } if ( seqid == (lastseqid + 1) || did1 == 0 ) { From c3a4829ba563f633ebbb72b2deb2e87ca98473ca Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Thu, 25 Oct 2018 17:46:09 +0800 Subject: [PATCH 118/127] try fix for calling getdata out of order --- src/rpcblockchain.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 0bbba22a8..6aa8ab384 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -398,6 +398,9 @@ UniValue getdatafromblock(const UniValue& params, bool fHelp) firsttxid.append(idstr); } else if ( firsttxid != idstr ) { printf("firsttxid.%s idstr.%s change firsttxid and wipe streamid?\n we are in a new stream here I think\n",firsttxid.c_str(),idstr.c_str()); + firsttxid.clear(); + firsttxid.append(idstr); + streamid.clear(); } if ( seqid == (lastseqid + 1) || did1 == 0 ) { From 7700741e46a3197ef252defbd3d7954d94ff131b Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Fri, 26 Oct 2018 23:08:26 +0800 Subject: [PATCH 119/127] try? --- src/rpcblockchain.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 6aa8ab384..f52b3ac7c 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -401,12 +401,13 @@ UniValue getdatafromblock(const UniValue& params, bool fHelp) firsttxid.clear(); firsttxid.append(idstr); streamid.clear(); + firsttxnHeight = 0; } if ( seqid == (lastseqid + 1) || did1 == 0 ) { blockdata.append(data); } else { - result.push_back(Pair("error","chunck out of order in this block!")); + result.push_back(Pair("error","chunck out of order or missing in this block!")); result.push_back(Pair("lastvalidseqid", (int)lastseqid)); break; } From 8c552c067ccbd88c682eaaa21c3e76694e1f3c09 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Fri, 26 Oct 2018 23:23:49 +0800 Subject: [PATCH 120/127] debug --- src/rpcblockchain.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index f52b3ac7c..ab9985b44 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -397,7 +397,7 @@ UniValue getdatafromblock(const UniValue& params, bool fHelp) } else if (firsttxid.empty()) { firsttxid.append(idstr); } else if ( firsttxid != idstr ) { - printf("firsttxid.%s idstr.%s change firsttxid and wipe streamid?\n we are in a new stream here I think\n",firsttxid.c_str(),idstr.c_str()); + printf("firsttxid.%s idstr.%s change firsttxid and wipe streamid?\n",firsttxid.c_str(),idstr.c_str()); firsttxid.clear(); firsttxid.append(idstr); streamid.clear(); @@ -430,10 +430,12 @@ UniValue getdatafromblock(const UniValue& params, bool fHelp) uint256 firsttxid_256(uint256S(firsttxid)); if (GetTransaction(firsttxid_256,firsttx,hash,false)) { std::string firststreamid = HexStr(firsttx.vout[2].scriptPubKey.begin(), firsttx.vout[2].scriptPubKey.end()); + printf("first stream id changed to: %s\n", firststreamid.c_str()); streamid.append(firststreamid.substr (8,64)); BlockMap::iterator mi = mapBlockIndex.find(hash); if (mi != mapBlockIndex.end() && (*mi).second) { CBlockIndex* pindex = (*mi).second; + printf("found block height: %d\n",pindex->nHeight); if (chainActive.Contains(pindex)) { firsttxnHeight = pindex->nHeight; } @@ -447,7 +449,6 @@ UniValue getdatafromblock(const UniValue& params, bool fHelp) if ( failed == 1 || skippedtxs == i ) { result.push_back(Pair("error","there is no data in this block.")); } else { - printf("block hash: %s block height: %d\n",hash.ToString().c_str(),firsttxnHeight); std::string decodedstreamid; hex2ascii(streamid, decodedstreamid); result.push_back(Pair("streamid", decodedstreamid.c_str())); From db0fa8d71cacf5ded3d1f137e3f19b5377cdf50f Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Fri, 26 Oct 2018 23:41:49 +0800 Subject: [PATCH 121/127] try? --- src/rpcblockchain.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index ab9985b44..e1877d058 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -430,8 +430,8 @@ UniValue getdatafromblock(const UniValue& params, bool fHelp) uint256 firsttxid_256(uint256S(firsttxid)); if (GetTransaction(firsttxid_256,firsttx,hash,false)) { std::string firststreamid = HexStr(firsttx.vout[2].scriptPubKey.begin(), firsttx.vout[2].scriptPubKey.end()); - printf("first stream id changed to: %s\n", firststreamid.c_str()); streamid.append(firststreamid.substr (8,64)); + printf("first stream id changed to: %s\n", streamid.c_str()); BlockMap::iterator mi = mapBlockIndex.find(hash); if (mi != mapBlockIndex.end() && (*mi).second) { CBlockIndex* pindex = (*mi).second; From b1727e55cb667e6291331537cb35278cbc4a9232 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Sat, 27 Oct 2018 00:01:24 +0800 Subject: [PATCH 122/127] try --- src/rpcblockchain.cpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index e1877d058..0b6bfc713 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -432,12 +432,16 @@ UniValue getdatafromblock(const UniValue& params, bool fHelp) std::string firststreamid = HexStr(firsttx.vout[2].scriptPubKey.begin(), firsttx.vout[2].scriptPubKey.end()); streamid.append(firststreamid.substr (8,64)); printf("first stream id changed to: %s\n", streamid.c_str()); - BlockMap::iterator mi = mapBlockIndex.find(hash); - if (mi != mapBlockIndex.end() && (*mi).second) { - CBlockIndex* pindex = (*mi).second; - printf("found block height: %d\n",pindex->nHeight); - if (chainActive.Contains(pindex)) { - firsttxnHeight = pindex->nHeight; + if ( firstdeqid == 1 ) { + firsttxnHeight == block.nHeight; + } else { + BlockMap::iterator mi = mapBlockIndex.find(hash); + if (mi != mapBlockIndex.end() && (*mi).second) { + CBlockIndex* pindex = (*mi).second; + printf("found block height: %d\n",pindex->nHeight); + if (chainActive.Contains(pindex)) { + firsttxnHeight = pindex->nHeight; + } } } } From 5e786e2e4cf3919ca6dfaaaa0f1f52022a3bdcbf Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Sat, 27 Oct 2018 00:07:45 +0800 Subject: [PATCH 123/127] fix --- src/rpcblockchain.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 0b6bfc713..e0597a541 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -432,8 +432,8 @@ UniValue getdatafromblock(const UniValue& params, bool fHelp) std::string firststreamid = HexStr(firsttx.vout[2].scriptPubKey.begin(), firsttx.vout[2].scriptPubKey.end()); streamid.append(firststreamid.substr (8,64)); printf("first stream id changed to: %s\n", streamid.c_str()); - if ( firstdeqid == 1 ) { - firsttxnHeight == block.nHeight; + if ( firstseqid == 1 ) { + firsttxnHeight == pblockindex->nHeight; } else { BlockMap::iterator mi = mapBlockIndex.find(hash); if (mi != mapBlockIndex.end() && (*mi).second) { From fd8fe7b404768508463745b6606fc54b3b01c60e Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Sat, 27 Oct 2018 00:13:26 +0800 Subject: [PATCH 124/127] try --- src/rpcblockchain.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index e0597a541..e383a87f7 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -434,6 +434,7 @@ UniValue getdatafromblock(const UniValue& params, bool fHelp) printf("first stream id changed to: %s\n", streamid.c_str()); if ( firstseqid == 1 ) { firsttxnHeight == pblockindex->nHeight; + printf("first seq id is 1 and found height: %d\n",firsttxnHeight ); } else { BlockMap::iterator mi = mapBlockIndex.find(hash); if (mi != mapBlockIndex.end() && (*mi).second) { From baa6c490848933b036e5fcb89569807b66010f46 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Sat, 27 Oct 2018 00:29:21 +0800 Subject: [PATCH 125/127] try this --- src/rpcblockchain.cpp | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index e383a87f7..53971e782 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -365,6 +365,7 @@ UniValue getdatafromblock(const UniValue& params, bool fHelp) int did1 = 0; int skippedtxs = 0; int failed = 0; + int getfirstblock = 0; static std::string streamid,firsttxid; static int firsttxnHeight; std::string blockdata; @@ -392,6 +393,7 @@ UniValue getdatafromblock(const UniValue& params, bool fHelp) ss >> seqid; if ( seqid == 1 ) { streamid = idstr; + getfirstblock = 1; } else if ( seqid == 2 ) { firsttxid = idstr; } else if (firsttxid.empty()) { @@ -403,7 +405,6 @@ UniValue getdatafromblock(const UniValue& params, bool fHelp) streamid.clear(); firsttxnHeight = 0; } - if ( seqid == (lastseqid + 1) || did1 == 0 ) { blockdata.append(data); } else { @@ -425,24 +426,22 @@ UniValue getdatafromblock(const UniValue& params, bool fHelp) } i = i + 1; } - if (streamid.empty()) { + if (streamid.empty() || getfirstblock == 1) { + if ( lastseqid == 1) { + firsttxid = block.vtx[1].GetHash().GetHex(); + } uint256 hash; CTransaction firsttx; uint256 firsttxid_256(uint256S(firsttxid)); if (GetTransaction(firsttxid_256,firsttx,hash,false)) { std::string firststreamid = HexStr(firsttx.vout[2].scriptPubKey.begin(), firsttx.vout[2].scriptPubKey.end()); streamid.append(firststreamid.substr (8,64)); printf("first stream id changed to: %s\n", streamid.c_str()); - if ( firstseqid == 1 ) { - firsttxnHeight == pblockindex->nHeight; - printf("first seq id is 1 and found height: %d\n",firsttxnHeight ); - } else { - BlockMap::iterator mi = mapBlockIndex.find(hash); - if (mi != mapBlockIndex.end() && (*mi).second) { - CBlockIndex* pindex = (*mi).second; - printf("found block height: %d\n",pindex->nHeight); - if (chainActive.Contains(pindex)) { - firsttxnHeight = pindex->nHeight; - } + BlockMap::iterator mi = mapBlockIndex.find(hash); + if (mi != mapBlockIndex.end() && (*mi).second) { + CBlockIndex* pindex = (*mi).second; + printf("found block height: %d\n",pindex->nHeight); + if (chainActive.Contains(pindex)) { + firsttxnHeight = pindex->nHeight; } } } From 99196bfb15664b1db67731259aee4d8ab4fb2432 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Sat, 27 Oct 2018 00:35:18 +0800 Subject: [PATCH 126/127] fix --- src/rpcblockchain.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 53971e782..07cf53ad2 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -433,8 +433,10 @@ UniValue getdatafromblock(const UniValue& params, bool fHelp) uint256 hash; CTransaction firsttx; uint256 firsttxid_256(uint256S(firsttxid)); if (GetTransaction(firsttxid_256,firsttx,hash,false)) { - std::string firststreamid = HexStr(firsttx.vout[2].scriptPubKey.begin(), firsttx.vout[2].scriptPubKey.end()); - streamid.append(firststreamid.substr (8,64)); + if ( streamid.empty() ) { + std::string firststreamid = HexStr(firsttx.vout[2].scriptPubKey.begin(), firsttx.vout[2].scriptPubKey.end()); + streamid.append(firststreamid.substr (8,64)); + } printf("first stream id changed to: %s\n", streamid.c_str()); BlockMap::iterator mi = mapBlockIndex.find(hash); if (mi != mapBlockIndex.end() && (*mi).second) { From 8d50000c49a41820b09a697a88b9814c68699aa3 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Sat, 27 Oct 2018 01:34:24 +0800 Subject: [PATCH 127/127] try send in chunks --- src/rpcblockchain.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 07cf53ad2..0a00a614c 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -382,7 +382,7 @@ UniValue getdatafromblock(const UniValue& params, bool fHelp) skippedtxs = skippedtxs + 1; } else { std::string opretstr = HexStr(tx.vout[2].scriptPubKey.begin(), tx.vout[2].scriptPubKey.end()); - // scriptPubKey is longer than 81, should mean its an OP_RETURN. + // scriptPubKey is longer than 81, should mean its an OP_RETURN, maybe also check vout == 0 ? if ( opretstr.size() > 81 ) { std::string idstr = opretstr.substr (8,64); // stream ID or txid std::string seqidstr = opretstr.substr (72,8); // sequence ID