From 536cb5f86d68b8cc9d368986f20ad6c0731fda81 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Thu, 21 Feb 2019 20:17:08 +0800 Subject: [PATCH] geterablockheights RPC --- src/main.cpp | 5 +++-- src/rpc/misc.cpp | 30 ++++++++++++++++++++++++++++-- src/rpc/server.cpp | 1 + src/rpc/server.h | 1 + 4 files changed, 33 insertions(+), 4 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 6bee5855c..6ad0e613d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1111,8 +1111,9 @@ bool ContextualCheckTransaction( if (IsExpiredTx(tx, nHeight)) { // Don't increase banscore if the transaction only just expired int expiredDosLevel = IsExpiredTx(tx, nHeight - 1) ? (dosLevel > 10 ? dosLevel : 10) : 0; - - return state.DoS(expiredDosLevel, error("ContextualCheckTransaction(): transaction %s is expired, expiry block %i vs current block %i",tx.GetHash().ToString(),tx.nExpiryHeight,nHeight), REJECT_INVALID, "tx-overwinter-expired"); + string strHex = EncodeHexTx(tx); + //fprintf(stderr, "transaction exipred.%s\n",strHex.c_str()); + return state.DoS(expiredDosLevel, error("ContextualCheckTransaction(): transaction %s is expired, expiry block %i vs current block %i\n txhex.%s",tx.GetHash().ToString(),tx.nExpiryHeight,nHeight,strHex), REJECT_INVALID, "tx-overwinter-expired"); } } diff --git a/src/rpc/misc.cpp b/src/rpc/misc.cpp index 564d76c9c..a6b0e7923 100644 --- a/src/rpc/misc.cpp +++ b/src/rpc/misc.cpp @@ -86,10 +86,10 @@ extern int32_t ASSETCHAINS_LWMAPOS,ASSETCHAINS_SAPLING,ASSETCHAINS_STAKED; extern uint64_t ASSETCHAINS_ENDSUBSIDY[],ASSETCHAINS_REWARD[],ASSETCHAINS_HALVING[],ASSETCHAINS_DECAY[],ASSETCHAINS_NOTARY_PAY[]; extern std::string NOTARY_PUBKEY,NOTARY_ADDRESS; extern uint8_t NOTARY_PUBKEY33[]; -int32_t getera(int now) +int32_t getera(int timestamp) { for (int32_t i = 0; i < NUM_STAKED_ERAS; i++) { - if ( now <= STAKED_NOTARIES_TIMESTAMP[i] ) { + if ( timestamp <= STAKED_NOTARIES_TIMESTAMP[i] ) { return(i); } } @@ -163,6 +163,32 @@ UniValue getnotarysendmany(const UniValue& params, bool fHelp) return ret; } +UniValue geterablockheights(const UniValue& params, bool fHelp) +{ + if (fHelp || params.size() != 0) + throw runtime_error( + "getnotarysendmany\n" + "Returns a JSON object with the first block in each era.\n" + ); + + CBlockIndex *pindex; int8_t lastera,era = 0; UniValue ret(UniValue::VOBJ); + + for (size_t i = 1; i < chainActive.LastTip()->GetHeight(); i++) + { + pindex = chainActive[i]; + era = getera(pindex->nTime)+1; + if ( era > lastera ) + { + char str[16]; + sprintf(str, "%d", era); + ret.push_back(Pair(str,i)); + lastera = era; + } + } + + return(ret); +} + UniValue getinfo(const UniValue& params, bool fHelp) { uint256 notarized_hash,notarized_desttxid; int32_t prevMoMheight,notarized_height,longestchain,kmdnotarized_height,txid_height; diff --git a/src/rpc/server.cpp b/src/rpc/server.cpp index 89baeddf5..46eb95a25 100644 --- a/src/rpc/server.cpp +++ b/src/rpc/server.cpp @@ -293,6 +293,7 @@ static const CRPCCommand vRPCCommands[] = { "control", "help", &help, true }, { "control", "getiguanajson", &getiguanajson, true }, { "control", "getnotarysendmany", &getnotarysendmany, true }, + { "control", "geterablockheights", &geterablockheights, true }, { "control", "stop", &stop, true }, /* P2P networking */ diff --git a/src/rpc/server.h b/src/rpc/server.h index 6aedeb254..abd0ea6a8 100644 --- a/src/rpc/server.h +++ b/src/rpc/server.h @@ -381,6 +381,7 @@ extern UniValue decodeccopret(const UniValue& params, bool fHelp); extern UniValue getinfo(const UniValue& params, bool fHelp); extern UniValue getiguanajson(const UniValue& params, bool fHelp); extern UniValue getnotarysendmany(const UniValue& params, bool fHelp); +extern UniValue geterablockheights(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);