Pharao Release
Version 4.0.0.4 - refactored code - migrated vom Qt4 to Qt5 - added secure messaging
This commit is contained in:
+92
-103
@@ -5,62 +5,38 @@
|
||||
|
||||
#include "main.h"
|
||||
#include "db.h"
|
||||
#include "txdb.h"
|
||||
#include "init.h"
|
||||
#include "bitcoinrpc.h"
|
||||
#include "miner.h"
|
||||
#include "trianglesrpc.h"
|
||||
|
||||
using namespace json_spirit;
|
||||
using namespace std;
|
||||
|
||||
Value getgenerate(const Array& params, bool fHelp)
|
||||
extern unsigned int nTargetSpacing;
|
||||
|
||||
Value getsubsidy(const Array& params, bool fHelp)
|
||||
{
|
||||
if (fHelp || params.size() != 0)
|
||||
if (fHelp || params.size() > 1)
|
||||
throw runtime_error(
|
||||
"getgenerate\n"
|
||||
"Returns true or false.");
|
||||
"getsubsidy [nTarget]\n"
|
||||
"Returns proof-of-work subsidy value for the specified value of target.");
|
||||
|
||||
return GetBoolArg("-gen");
|
||||
}
|
||||
unsigned int nBits = 0;
|
||||
|
||||
|
||||
Value setgenerate(const Array& params, bool fHelp)
|
||||
{
|
||||
if (fHelp || params.size() < 1 || params.size() > 2)
|
||||
throw runtime_error(
|
||||
"setgenerate <generate> [genproclimit]\n"
|
||||
"<generate> is true or false to turn generation on or off.\n"
|
||||
"Generation is limited to [genproclimit] processors, -1 is unlimited.");
|
||||
|
||||
bool fGenerate = true;
|
||||
if (params.size() > 0)
|
||||
fGenerate = params[0].get_bool();
|
||||
|
||||
if (params.size() > 1)
|
||||
if (params.size() != 0)
|
||||
{
|
||||
int nGenProcLimit = params[1].get_int();
|
||||
mapArgs["-genproclimit"] = itostr(nGenProcLimit);
|
||||
if (nGenProcLimit == 0)
|
||||
fGenerate = false;
|
||||
CBigNum bnTarget(uint256(params[0].get_str()));
|
||||
nBits = bnTarget.GetCompact();
|
||||
}
|
||||
else
|
||||
{
|
||||
nBits = GetNextTargetRequired(pindexBest, false);
|
||||
}
|
||||
mapArgs["-gen"] = (fGenerate ? "1" : "0");
|
||||
|
||||
GenerateBitcoins(fGenerate, pwalletMain);
|
||||
return Value::null;
|
||||
return (uint64_t)GetProofOfWorkReward(0);
|
||||
}
|
||||
|
||||
|
||||
Value gethashespersec(const Array& params, bool fHelp)
|
||||
{
|
||||
if (fHelp || params.size() != 0)
|
||||
throw runtime_error(
|
||||
"gethashespersec\n"
|
||||
"Returns a recent hashes per second performance measurement while generating.");
|
||||
|
||||
if (GetTimeMillis() - nHPSTimerStart > 8000)
|
||||
return (boost::int64_t)0;
|
||||
return (boost::int64_t)dHashesPerSec;
|
||||
}
|
||||
|
||||
|
||||
Value getmininginfo(const Array& params, bool fHelp)
|
||||
{
|
||||
if (fHelp || params.size() != 0)
|
||||
@@ -68,56 +44,70 @@ Value getmininginfo(const Array& params, bool fHelp)
|
||||
"getmininginfo\n"
|
||||
"Returns an object containing mining-related information.");
|
||||
|
||||
Object obj;
|
||||
uint64_t nMinWeight = 0, nMaxWeight = 0, nWeight = 0;
|
||||
pwalletMain->GetStakeWeight(*pwalletMain, nMinWeight, nMaxWeight, nWeight);
|
||||
|
||||
Object obj, diff, weight;
|
||||
obj.push_back(Pair("blocks", (int)nBestHeight));
|
||||
obj.push_back(Pair("currentblocksize",(uint64_t)nLastBlockSize));
|
||||
obj.push_back(Pair("currentblocktx",(uint64_t)nLastBlockTx));
|
||||
obj.push_back(Pair("difficulty", (double)GetDifficulty()));
|
||||
|
||||
diff.push_back(Pair("proof-of-work", GetDifficulty()));
|
||||
diff.push_back(Pair("proof-of-stake", GetDifficulty(GetLastBlockIndex(pindexBest, true))));
|
||||
diff.push_back(Pair("search-interval", (int)nLastCoinStakeSearchInterval));
|
||||
obj.push_back(Pair("difficulty", diff));
|
||||
|
||||
obj.push_back(Pair("blockvalue", (uint64_t)GetProofOfWorkReward(0)));
|
||||
obj.push_back(Pair("netmhashps", GetPoWMHashPS()));
|
||||
obj.push_back(Pair("netstakeweight", GetPoSKernelPS()));
|
||||
obj.push_back(Pair("errors", GetWarnings("statusbar")));
|
||||
obj.push_back(Pair("generate", GetBoolArg("-gen")));
|
||||
obj.push_back(Pair("genproclimit", (int)GetArg("-genproclimit", -1)));
|
||||
obj.push_back(Pair("hashespersec", gethashespersec(params, false)));
|
||||
obj.push_back(Pair("networkhashps", getnetworkhashps(params, false)));
|
||||
obj.push_back(Pair("pooledtx", (uint64_t)mempool.size()));
|
||||
|
||||
weight.push_back(Pair("minimum", (uint64_t)nMinWeight));
|
||||
weight.push_back(Pair("maximum", (uint64_t)nMaxWeight));
|
||||
weight.push_back(Pair("combined", (uint64_t)nWeight));
|
||||
obj.push_back(Pair("stakeweight", weight));
|
||||
|
||||
obj.push_back(Pair("stakeinterest", (uint64_t)COIN_YEAR_REWARD));
|
||||
obj.push_back(Pair("testnet", fTestNet));
|
||||
return obj;
|
||||
}
|
||||
|
||||
// Litecoin: Return average network hashes per second based on last number of blocks.
|
||||
Value GetNetworkHashPS(int lookup) {
|
||||
if (pindexBest == NULL)
|
||||
return 0;
|
||||
|
||||
// If lookup is -1, then use blocks since last difficulty change.
|
||||
if (lookup <= 0)
|
||||
lookup = pindexBest->nHeight % 2016 + 1;
|
||||
|
||||
// If lookup is larger than chain, then set it to chain length.
|
||||
if (lookup > pindexBest->nHeight)
|
||||
lookup = pindexBest->nHeight;
|
||||
|
||||
CBlockIndex* pindexPrev = pindexBest;
|
||||
for (int i = 0; i < lookup; i++)
|
||||
pindexPrev = pindexPrev->pprev;
|
||||
|
||||
double timeDiff = pindexBest->GetBlockTime() - pindexPrev->GetBlockTime();
|
||||
double timePerBlock = timeDiff / lookup;
|
||||
|
||||
return (boost::int64_t)(((double)GetDifficulty() * pow(2.0, 32)) / timePerBlock);
|
||||
}
|
||||
|
||||
Value getnetworkhashps(const Array& params, bool fHelp)
|
||||
Value getstakinginfo(const Array& params, bool fHelp)
|
||||
{
|
||||
if (fHelp || params.size() > 1)
|
||||
if (fHelp || params.size() != 0)
|
||||
throw runtime_error(
|
||||
"getnetworkhashps [blocks]\n"
|
||||
"Returns the estimated network hashes per second based on the last 120 blocks.\n"
|
||||
"Pass in [blocks] to override # of blocks, -1 specifies since last difficulty change.");
|
||||
"getstakinginfo\n"
|
||||
"Returns an object containing staking-related information.");
|
||||
|
||||
return GetNetworkHashPS(params.size() > 0 ? params[0].get_int() : 120);
|
||||
uint64_t nMinWeight = 0, nMaxWeight = 0, nWeight = 0;
|
||||
pwalletMain->GetStakeWeight(*pwalletMain, nMinWeight, nMaxWeight, nWeight);
|
||||
|
||||
uint64_t nNetworkWeight = GetPoSKernelPS();
|
||||
bool staking = nLastCoinStakeSearchInterval && nWeight;
|
||||
int nExpectedTime = staking ? (nTargetSpacing * nNetworkWeight / nWeight) : -1;
|
||||
|
||||
Object obj;
|
||||
|
||||
obj.push_back(Pair("enabled", GetBoolArg("-staking", true)));
|
||||
obj.push_back(Pair("staking", staking));
|
||||
obj.push_back(Pair("errors", GetWarnings("statusbar")));
|
||||
|
||||
obj.push_back(Pair("currentblocksize", (uint64_t)nLastBlockSize));
|
||||
obj.push_back(Pair("currentblocktx", (uint64_t)nLastBlockTx));
|
||||
obj.push_back(Pair("pooledtx", (uint64_t)mempool.size()));
|
||||
|
||||
obj.push_back(Pair("difficulty", GetDifficulty(GetLastBlockIndex(pindexBest, true))));
|
||||
obj.push_back(Pair("search-interval", (int)nLastCoinStakeSearchInterval));
|
||||
|
||||
obj.push_back(Pair("weight", (uint64_t)nWeight));
|
||||
obj.push_back(Pair("netstakeweight", (uint64_t)nNetworkWeight));
|
||||
|
||||
obj.push_back(Pair("expectedtime", nExpectedTime));
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
|
||||
Value getworkex(const Array& params, bool fHelp)
|
||||
{
|
||||
if (fHelp || params.size() > 2)
|
||||
@@ -127,10 +117,13 @@ Value getworkex(const Array& params, bool fHelp)
|
||||
);
|
||||
|
||||
if (vNodes.empty())
|
||||
throw JSONRPCError(-9, "triangles is not connected!");
|
||||
throw JSONRPCError(-9, "Triangles is not connected!");
|
||||
|
||||
if (IsInitialBlockDownload())
|
||||
throw JSONRPCError(-10, "triangles is downloading blocks...");
|
||||
throw JSONRPCError(-10, "Triangles is downloading blocks...");
|
||||
|
||||
if (pindexBest->nHeight >= CUTOFF_POW_BLOCK)
|
||||
throw JSONRPCError(RPC_MISC_ERROR, "No more PoW blocks");
|
||||
|
||||
typedef map<uint256, pair<CBlock*, CScript> > mapNewBlock_t;
|
||||
static mapNewBlock_t mapNewBlock;
|
||||
@@ -142,7 +135,7 @@ Value getworkex(const Array& params, bool fHelp)
|
||||
// Update block
|
||||
static unsigned int nTransactionsUpdatedLast;
|
||||
static CBlockIndex* pindexPrev;
|
||||
static int64 nStart;
|
||||
static int64_t nStart;
|
||||
static CBlock* pblock;
|
||||
if (pindexPrev != pindexBest ||
|
||||
(nTransactionsUpdated != nTransactionsUpdatedLast && GetTime() - nStart > 60))
|
||||
@@ -167,7 +160,7 @@ Value getworkex(const Array& params, bool fHelp)
|
||||
}
|
||||
|
||||
// Update nTime
|
||||
pblock->nTime = max(pindexPrev->GetMedianTimePast()+1, GetAdjustedTime());
|
||||
pblock->nTime = max(pindexPrev->GetPastTimeLimit()+1, GetAdjustedTime());
|
||||
pblock->nNonce = 0;
|
||||
|
||||
// Update nExtraNonce
|
||||
@@ -236,13 +229,10 @@ Value getworkex(const Array& params, bool fHelp)
|
||||
if(coinbase.size() == 0)
|
||||
pblock->vtx[0].vin[0].scriptSig = mapNewBlock[pdata->hashMerkleRoot].second;
|
||||
else
|
||||
CDataStream(coinbase, SER_NETWORK, PROTOCOL_VERSION) >> pblock->vtx[0]; // FIXME - HACK!
|
||||
CDataStream(coinbase, SER_NETWORK, PROTOCOL_VERSION) >> pblock->vtx[0]; // FIXME - DRM!
|
||||
|
||||
pblock->hashMerkleRoot = pblock->BuildMerkleTree();
|
||||
|
||||
if (!pblock->SignBlock(*pwalletMain))
|
||||
throw JSONRPCError(-100, "Unable to sign block, wallet locked?");
|
||||
|
||||
return CheckWork(pblock, *pwalletMain, reservekey);
|
||||
}
|
||||
}
|
||||
@@ -261,10 +251,13 @@ Value getwork(const Array& params, bool fHelp)
|
||||
"If [data] is specified, tries to solve the block and returns true if it was successful.");
|
||||
|
||||
if (vNodes.empty())
|
||||
throw JSONRPCError(RPC_CLIENT_NOT_CONNECTED, "triangles is not connected!");
|
||||
throw JSONRPCError(RPC_CLIENT_NOT_CONNECTED, "Triangles is not connected!");
|
||||
|
||||
if (IsInitialBlockDownload())
|
||||
throw JSONRPCError(RPC_CLIENT_IN_INITIAL_DOWNLOAD, "triangles is downloading blocks...");
|
||||
throw JSONRPCError(RPC_CLIENT_IN_INITIAL_DOWNLOAD, "Triangles is downloading blocks...");
|
||||
|
||||
if (pindexBest->nHeight >= CUTOFF_POW_BLOCK)
|
||||
throw JSONRPCError(RPC_MISC_ERROR, "No more PoW blocks");
|
||||
|
||||
typedef map<uint256, pair<CBlock*, CScript> > mapNewBlock_t;
|
||||
static mapNewBlock_t mapNewBlock; // FIXME: thread safety
|
||||
@@ -276,7 +269,7 @@ Value getwork(const Array& params, bool fHelp)
|
||||
// Update block
|
||||
static unsigned int nTransactionsUpdatedLast;
|
||||
static CBlockIndex* pindexPrev;
|
||||
static int64 nStart;
|
||||
static int64_t nStart;
|
||||
static CBlock* pblock;
|
||||
if (pindexPrev != pindexBest ||
|
||||
(nTransactionsUpdated != nTransactionsUpdatedLast && GetTime() - nStart > 60))
|
||||
@@ -356,9 +349,6 @@ Value getwork(const Array& params, bool fHelp)
|
||||
pblock->vtx[0].vin[0].scriptSig = mapNewBlock[pdata->hashMerkleRoot].second;
|
||||
pblock->hashMerkleRoot = pblock->BuildMerkleTree();
|
||||
|
||||
if (!pblock->SignBlock(*pwalletMain))
|
||||
throw JSONRPCError(-100, "Unable to sign block, wallet locked?");
|
||||
|
||||
return CheckWork(pblock, *pwalletMain, reservekey);
|
||||
}
|
||||
}
|
||||
@@ -383,8 +373,7 @@ Value getblocktemplate(const Array& params, bool fHelp)
|
||||
" \"sigoplimit\" : limit of sigops in blocks\n"
|
||||
" \"sizelimit\" : limit of block size\n"
|
||||
" \"bits\" : compressed target of next block\n"
|
||||
" \"height\" : height of the next block\n"
|
||||
"See https://en.bitcoin.it/wiki/BIP_0022 for full specification.");
|
||||
" \"height\" : height of the next block");
|
||||
|
||||
std::string strMode = "template";
|
||||
if (params.size() > 0)
|
||||
@@ -405,17 +394,20 @@ Value getblocktemplate(const Array& params, bool fHelp)
|
||||
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid mode");
|
||||
|
||||
if (vNodes.empty())
|
||||
throw JSONRPCError(RPC_CLIENT_NOT_CONNECTED, "triangles is not connected!");
|
||||
throw JSONRPCError(RPC_CLIENT_NOT_CONNECTED, "Triangles is not connected!");
|
||||
|
||||
if (IsInitialBlockDownload())
|
||||
throw JSONRPCError(RPC_CLIENT_IN_INITIAL_DOWNLOAD, "triangles is downloading blocks...");
|
||||
throw JSONRPCError(RPC_CLIENT_IN_INITIAL_DOWNLOAD, "Triangles is downloading blocks...");
|
||||
|
||||
if (pindexBest->nHeight >= CUTOFF_POW_BLOCK)
|
||||
throw JSONRPCError(RPC_MISC_ERROR, "No more PoW blocks");
|
||||
|
||||
static CReserveKey reservekey(pwalletMain);
|
||||
|
||||
// Update block
|
||||
static unsigned int nTransactionsUpdatedLast;
|
||||
static CBlockIndex* pindexPrev;
|
||||
static int64 nStart;
|
||||
static int64_t nStart;
|
||||
static CBlock* pblock;
|
||||
if (pindexPrev != pindexBest ||
|
||||
(nTransactionsUpdated != nTransactionsUpdatedLast && GetTime() - nStart > 5))
|
||||
@@ -509,7 +501,7 @@ Value getblocktemplate(const Array& params, bool fHelp)
|
||||
result.push_back(Pair("coinbaseaux", aux));
|
||||
result.push_back(Pair("coinbasevalue", (int64_t)pblock->vtx[0].vout[0].nValue));
|
||||
result.push_back(Pair("target", hashTarget.GetHex()));
|
||||
result.push_back(Pair("mintime", (int64_t)pindexPrev->GetMedianTimePast()+1));
|
||||
result.push_back(Pair("mintime", (int64_t)pindexPrev->GetPastTimeLimit()+1));
|
||||
result.push_back(Pair("mutable", aMutable));
|
||||
result.push_back(Pair("noncerange", "00000000ffffffff"));
|
||||
result.push_back(Pair("sigoplimit", (int64_t)MAX_BLOCK_SIGOPS));
|
||||
@@ -527,8 +519,7 @@ Value submitblock(const Array& params, bool fHelp)
|
||||
throw runtime_error(
|
||||
"submitblock <hex data> [optional-params-obj]\n"
|
||||
"[optional-params-obj] parameter is currently ignored.\n"
|
||||
"Attempts to submit new block to network.\n"
|
||||
"See https://en.bitcoin.it/wiki/BIP_0022 for full specification.");
|
||||
"Attempts to submit new block to network.");
|
||||
|
||||
vector<unsigned char> blockData(ParseHex(params[0].get_str()));
|
||||
CDataStream ssBlock(blockData, SER_NETWORK, PROTOCOL_VERSION);
|
||||
@@ -540,9 +531,6 @@ Value submitblock(const Array& params, bool fHelp)
|
||||
throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Block decode failed");
|
||||
}
|
||||
|
||||
if (!block.SignBlock(*pwalletMain))
|
||||
throw JSONRPCError(-100, "Unable to sign block, wallet locked?");
|
||||
|
||||
bool fAccepted = ProcessBlock(NULL, &block);
|
||||
if (!fAccepted)
|
||||
return "rejected";
|
||||
@@ -550,3 +538,4 @@ Value submitblock(const Array& params, bool fHelp)
|
||||
return Value::null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user