From d54d5424585c2b91ebf166f9a302eb89d37a7f73 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Thu, 29 Nov 2018 22:33:01 +0800 Subject: [PATCH] remove streamer --- src/komodo_bitcoind.h | 52 ++++------ src/komodo_gateway.h | 2 +- src/komodo_globals.h | 2 +- src/komodo_utils.h | 14 +-- src/main.cpp | 22 +--- src/miner.cpp | 40 +------- src/pow.cpp | 4 - src/rpcblockchain.cpp | 212 --------------------------------------- src/rpcserver.cpp | 1 - src/rpcserver.h | 1 - src/wallet/rpcwallet.cpp | 1 - 11 files changed, 27 insertions(+), 324 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index d0d6a7632..c00d33216 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1105,7 +1105,6 @@ int32_t komodo_validate_interest(const CTransaction &tx,int32_t txheight,uint32_ commission must be in coinbase.vout[1] and must be >= 10000 sats PoS stake must be without txfee and in the last tx in the block at vout[0] */ -extern int32_t ASSETCHAINS_STREAM; CAmount GetBlockSubsidy(int nHeight, const Consensus::Params& consensusParams); @@ -1113,29 +1112,26 @@ uint64_t komodo_commission(const CBlock *pblock,int32_t height) { int32_t i,j,n=0,txn_count; int64_t nSubsidy; uint64_t commission,total = 0; txn_count = pblock->vtx.size(); - if ( ASSETCHAINS_STREAM == 0 ) + if ( ASSETCHAINS_FOUNDERS != 0 ) { - if ( ASSETCHAINS_FOUNDERS != 0 ) + nSubsidy = GetBlockSubsidy(height,Params().GetConsensus()); + //fprintf(stderr,"ht.%d nSubsidy %.8f prod %llu\n",height,(double)nSubsidy/COIN,(long long)(nSubsidy * ASSETCHAINS_COMMISSION)); + return((nSubsidy * ASSETCHAINS_COMMISSION) / COIN); + n = pblock->vtx[0].vout.size(); + for (j=0; jvtx[0].vout[j].nValue; + } + else + { + for (i=0; ivtx[0].vout.size(); + n = pblock->vtx[i].vout.size(); for (j=0; jvtx[0].vout[j].nValue; - } - else - { - for (i=0; ivtx[i].vout.size(); - for (j=0; jvtx[i].vout[j].nValue; - } + //fprintf(stderr,"(%d %.8f).%d ",i,dstr(block.vtx[i].vout[j].nValue),j); + if ( i != 0 || j != 1 ) + total += pblock->vtx[i].vout[j].nValue; } } } @@ -1483,7 +1479,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,scripthex[8192]; int32_t scriptlen,matched = 0; - if ( ASSETCHAINS_COMMISSION != 0 || ASSETCHAINS_STREAM != 0 ) + if ( ASSETCHAINS_COMMISSION != 0 ) { checktoshis = komodo_commission(pblock,height); //fprintf(stderr,"height.%d commission %.8f\n",height,(double)checktoshis/COIN); @@ -1632,20 +1628,6 @@ int32_t komodo_checkPOW(int32_t slowflag,CBlock *pblock,int32_t height) if ( komodo_checkcommission(pblock,height) < 0 ) return(-1); } - if ( ASSETCHAINS_STREAM != 0 && height > 128 ) - { - int lasttx = ( pblock->vtx.size() -1 ); - if ( lasttx == 0 ) - return(-1); - uint256 hash; CTransaction tx; - if (GetTransaction(pblock->vtx[lasttx].vin[0].prevout.hash,tx,hash,false)) - { - 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); - } - } - } } //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 1ed05897d..3845030ca 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -744,7 +744,7 @@ int32_t komodo_check_deposit(int32_t height,const CBlock& block,uint32_t prevtim else { checktoshis = 0; - if ( (ASSETCHAINS_COMMISSION != 0 || ASSETCHAINS_STREAM != 0) && height > 1 ) + if ( ASSETCHAINS_COMMISSION != 0 && height > 1 ) { if ( (checktoshis= komodo_checkcommission((CBlock *)&block,height)) < 0 ) { diff --git a/src/komodo_globals.h b/src/komodo_globals.h index 0953713b0..dda78a6e1 100644 --- a/src/komodo_globals.h +++ b/src/komodo_globals.h @@ -44,7 +44,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,IS_STAKED_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,STAKED_ERA,KOMODO_CONNECTING = -1,KOMODO_DEALERNODE,KOMODO_EXTRASATOSHI; +int32_t KOMODO_MININGTHREADS = -1,IS_KOMODO_NOTARY,IS_STAKED_NOTARY,USE_EXTERNAL_PUBKEY,KOMODO_CHOSEN_ONE,ASSETCHAINS_SEED,KOMODO_ON_DEMAND,KOMODO_EXTERNAL_NOTARIES,KOMODO_PASSPORT_INITDONE,KOMODO_PAX,KOMODO_EXCHANGEWALLET,KOMODO_REWIND,STAKED_ERA,KOMODO_CONNECTING = -1,KOMODO_DEALERNODE,KOMODO_EXTRASATOSHI; int32_t KOMODO_INSYNC,KOMODO_LASTMINED,prevKOMODO_LASTMINED,KOMODO_CCACTIVATE,JUMBLR_PAUSE = 1; std::string NOTARY_PUBKEY,ASSETCHAINS_NOTARIES,ASSETCHAINS_OVERRIDE_PUBKEY,DONATION_PUBKEY,ASSETCHAINS_SCRIPTPUB,NOTARY_ADDRESS,WHITELIST_ADDRESS; uint8_t NOTARY_PUBKEY33[33],ASSETCHAINS_OVERRIDE_PUBKEY33[33],ASSETCHAINS_OVERRIDE_PUBKEYHASH[20],ASSETCHAINS_PUBLIC,ASSETCHAINS_PRIVATE,ASSETCHAINS_TXPOW,NUM_NOTARIES,ASSETCHAINS_FOUNDERS; diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 80581a1f8..1a6757b49 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1573,12 +1573,7 @@ void komodo_args(char *argv0) ASSETCHAINS_COMMISSION = GetArg("-ac_perc",0); ASSETCHAINS_OVERRIDE_PUBKEY = GetArg("-ac_pubkey",""); ASSETCHAINS_SCRIPTPUB = GetArg("-ac_script",""); - 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 )) { - 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; if ( ASSETCHAINS_STAKED != 0 && ASSETCHAINS_PRIVATE != 0 ) @@ -1601,11 +1596,6 @@ void komodo_args(char *argv0) ASSETCHAINS_DECAY = 0; printf("ASSETCHAINS_DECAY cant be more than 100000000\n"); } - if ( strlen(ASSETCHAINS_OVERRIDE_PUBKEY.c_str()) != 66 && ASSETCHAINS_STREAM != 0 ) - { - printf("ASSETCHAINS_STREAM needs ASSETCHAINS_OVERRIDE_PUBKEY! \n"); - exit(0); - } if ( strlen(ASSETCHAINS_OVERRIDE_PUBKEY.c_str()) == 66 || ASSETCHAINS_SCRIPTPUB.size() > 1 ) { if ( strlen(ASSETCHAINS_OVERRIDE_PUBKEY.c_str()) == 66 ) @@ -1620,10 +1610,10 @@ void komodo_args(char *argv0) ASSETCHAINS_COMMISSION = 53846154; // maps to 35% printf("ASSETCHAINS_COMMISSION defaulted to 35%% when founders reward active\n"); } - else if ( ASSETCHAINS_STREAM == 0 ) + else { ASSETCHAINS_OVERRIDE_PUBKEY.clear(); - printf("-ac_perc or -ac_stream must be set with -ac_pubkey\n"); + printf("-ac_perc must be set with -ac_pubkey\n"); } } } diff --git a/src/main.cpp b/src/main.cpp index 2b6966659..26b5e8f5b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1918,7 +1918,6 @@ 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; @@ -1947,12 +1946,7 @@ CAmount GetBlockSubsidy(int nHeight, const Consensus::Params& consensusParams) else if ( ASSETCHAINS_ENDSUBSIDY == 0 || nHeight < ASSETCHAINS_ENDSUBSIDY ) { if ( ASSETCHAINS_REWARD == 0 ) - { - if ( ASSETCHAINS_STREAM != 0 && nHeight > 128 ) - return(0); - else - return(10000); - } + return(10000); else if ( ASSETCHAINS_ENDSUBSIDY != 0 && nHeight >= ASSETCHAINS_ENDSUBSIDY ) return(0); else @@ -3020,18 +3014,6 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin 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++) { @@ -3181,7 +3163,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_COMMISSION != 0 || ASSETCHAINS_STREAM != 0 ) //ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 && + if ( ASSETCHAINS_COMMISSION != 0 ) //ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 && { uint64_t checktoshis; if ( (checktoshis= komodo_commission((CBlock *)&block,(int32_t)pindex->nHeight)) != 0 ) diff --git a/src/miner.cpp b/src/miner.cpp index 7370beb64..709ba6a65 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -107,7 +107,7 @@ void UpdateTime(CBlockHeader* pblock, const Consensus::Params& consensusParams, #include "komodo_defs.h" #define CRYPTO777_KMDADDR "RXL3YXG2ceaB6C5hfJcN4fvmLH2C34knhA" -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 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 uint64_t ASSETCHAINS_REWARD,ASSETCHAINS_COMMISSION,ASSETCHAINS_STAKED; extern char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN],NOTARYADDRS[64][36]; extern std::string NOTARY_PUBKEY,ASSETCHAINS_OVERRIDE_PUBKEY,ASSETCHAINS_SCRIPTPUB; @@ -467,7 +467,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount) 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_SCRIPTPUB.size() > 1) && (ASSETCHAINS_COMMISSION != 0 || ASSETCHAINS_STREAM != 0) && (commission= komodo_commission((CBlock*)&pblocktemplate->block,(int32_t)nHeight)) != 0 ) + if ( nHeight > 1 && ASSETCHAINS_SYMBOL[0] != 0 && (ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 || ASSETCHAINS_SCRIPTPUB.size() > 1) && ASSETCHAINS_COMMISSION != 0 && (commission= komodo_commission((CBlock*)&pblocktemplate->block,(int32_t)nHeight)) != 0 ) { int32_t i; uint8_t *ptr; txNew.vout.resize(2); @@ -544,26 +544,6 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount) return(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 ) - { - 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; @@ -690,13 +670,6 @@ CBlockTemplate* CreateNewBlockWithKey(CReserveKey& reservekey,int32_t nHeight,in decode_hex(ptr,len,(char *)ASSETCHAINS_SCRIPTPUB.c_str()); } } - 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"); @@ -926,19 +899,14 @@ void static BitcoinMiner() { if ( ASSETCHAINS_REWARD == 0 ) { - int minvoutsize = 1; - int minvtxsize = 1; - if ( ASSETCHAINS_STREAM != 0 ) - minvoutsize = 2; - minvtxsize = 2; - if ( pblock->vtx.size() == minvtxsize && pblock->vtx[0].vout.size() == minvoutsize && Mining_height > ASSETCHAINS_MINHEIGHT ) + if ( pblock->vtx.size() == 1 && pblock->vtx[0].vout.size() == 1 && 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 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); + } else fprintf(stderr,"%s vouts.%d mining.%d vs %d\n",ASSETCHAINS_SYMBOL,(int32_t)pblock->vtx[0].vout.size(),Mining_height,ASSETCHAINS_MINHEIGHT); } } IncrementExtraNonce(pblock, pindexPrev, nExtraNonce); diff --git a/src/pow.cpp b/src/pow.cpp index 07776e273..1291e445e 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -20,13 +20,9 @@ #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) { - if ( ASSETCHAINS_STREAM == 2 ) - return 537857807; - unsigned int nProofOfWorkLimit = UintToArith256(params.powLimit).GetCompact(); // Genesis block if (pindexLast == NULL ) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index abc8864bc..f078094ff 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -261,218 +261,6 @@ UniValue blockToDeltasJSON(const CBlock& block, const CBlockIndex* blockindex) return result; } -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) -{ - if (fHelp || params.size() < 1 || params.size() > 2) - throw runtime_error( - "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" - " \"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" - "}\n" - "\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\"") - + HelpExampleRpc("getblock", "\"00000000c937983704a73af28acdec37b049d214adbda81d7e2a3dd146f6ed09\"") - + HelpExampleCli("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 verboseflag = params[1].get_str(); - if ( verboseflag == "false" ) - fVerbose = false; - } - - // 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"); - - UniValue result(UniValue::VOBJ); - int firstseqid = 0; - int lastseqid = 0; - int i = 0; - int did1 = 0; - int skippedtxs = 0; - int failed = 0; - int getfirstblock = 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 ) - { - 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, 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 - std::string data = opretstr.substr (80); // data chunk - unsigned int seqid; - std::stringstream ss; - ss << std::hex << seqidstr; - ss >> seqid; - if ( seqid == 1 ) { - streamid = idstr; - getfirstblock = 1; - } else if ( seqid == 2 ) { - 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()); - 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 or missing in this block!")); - result.push_back(Pair("lastvalidseqid", (int)lastseqid)); - break; - } - if ( did1 == 0 ) { - firstseqid = seqid; - 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. - } - i = i + 1; - } - 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)) { - 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) { - CBlockIndex* pindex = (*mi).second; - printf("found block height: %d\n",pindex->nHeight); - if (chainActive.Contains(pindex)) { - firsttxnHeight = pindex->nHeight; - } - } - } - } - } 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("firstblockheight", (int)firsttxnHeight)); - 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; -} - UniValue blockToJSON(const CBlock& block, const CBlockIndex* blockindex, bool txDetails = false) { UniValue result(UniValue::VOBJ); diff --git a/src/rpcserver.cpp b/src/rpcserver.cpp index d4143fcfb..98417e201 100644 --- a/src/rpcserver.cpp +++ b/src/rpcserver.cpp @@ -287,7 +287,6 @@ 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 }, diff --git a/src/rpcserver.h b/src/rpcserver.h index 9ab033d12..851c39d42 100644 --- a/src/rpcserver.h +++ b/src/rpcserver.h @@ -368,7 +368,6 @@ 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); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index a05eede52..5e24f1530 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -46,7 +46,6 @@ 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; extern int32_t USE_EXTERNAL_PUBKEY;