本文整理汇总了C++中CBlockIndex::GetBlockTime方法的典型用法代码示例。如果您正苦于以下问题:C++ CBlockIndex::GetBlockTime方法的具体用法?C++ CBlockIndex::GetBlockTime怎么用?C++ CBlockIndex::GetBlockTime使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CBlockIndex
的用法示例。
在下文中一共展示了CBlockIndex::GetBlockTime方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getcheckpoint
// get information of sync-checkpoint
Value getcheckpoint(const Array& params, bool fHelp)
{
if (fHelp || params.size() != 0)
throw runtime_error(
"getcheckpoint\n"
"Show info of synchronized checkpoint.\n");
Object result;
CBlockIndex* pindexCheckpoint;
result.push_back(Pair("synccheckpoint", Checkpoints::hashSyncCheckpoint.ToString().c_str()));
pindexCheckpoint = mapBlockIndex[Checkpoints::hashSyncCheckpoint];
result.push_back(Pair("height", pindexCheckpoint->nHeight));
result.push_back(Pair("timestamp", DateTimeStrFormat(pindexCheckpoint->GetBlockTime()).c_str()));
if (Checkpoints::checkpointMessage.vchSig.size() != 0)
{
Object msgdata;
CUnsignedSyncCheckpoint checkpoint;
CDataStream sMsg(Checkpoints::checkpointMessage.vchMsg, SER_NETWORK, PROTOCOL_VERSION);
sMsg >> checkpoint;
Object parsed; // message version and data (block hash)
parsed.push_back(Pair("version", checkpoint.nVersion));
parsed.push_back(Pair("hash", checkpoint.hashCheckpoint.GetHex().c_str()));
msgdata.push_back(Pair("parsed", parsed));
Object raw; // raw checkpoint message data
raw.push_back(Pair("data", HexStr(Checkpoints::checkpointMessage.vchMsg).c_str()));
raw.push_back(Pair("signature", HexStr(Checkpoints::checkpointMessage.vchSig).c_str()));
msgdata.push_back(Pair("raw", raw));
result.push_back(Pair("data", msgdata));
}
示例2: sendcheckpoint
Value sendcheckpoint(const Array& params, bool fHelp)
{
if (fHelp || params.size() != 1)
throw runtime_error(
"sendcheckpoint <blockhash>\n"
"Send a synchronized checkpoint.\n");
if (!mapArgs.count("-checkpointkey") || CSyncCheckpoint::strMasterPrivKey.empty())
throw runtime_error("Not a checkpointmaster node, first set checkpointkey in configuration and restart client. ");
std::string strHash = params[0].get_str();
uint256 hash(strHash);
if (!SendSyncCheckpoint(hash))
throw runtime_error("Failed to send checkpoint, check log. ");
Object result;
CBlockIndex* pindexCheckpoint;
result.push_back(Pair("synccheckpoint", hashSyncCheckpoint.ToString().c_str()));
if (mapBlockIndex.count(hashSyncCheckpoint))
{
pindexCheckpoint = mapBlockIndex[hashSyncCheckpoint];
result.push_back(Pair("height", pindexCheckpoint->nHeight));
result.push_back(Pair("timestamp", (boost::int64_t) pindexCheckpoint->GetBlockTime()));
}
result.push_back(Pair("subscribemode", IsSyncCheckpointEnforced()? "enforce" : "advisory"));
if (mapArgs.count("-checkpointkey"))
result.push_back(Pair("checkpointmaster", true));
return result;
}
示例3: GetNetworkHashPS
// Return average network hashes per second based on the last 'lookup' blocks,
// or from the last difficulty change if 'lookup' is nonpositive.
// If 'height' is nonnegative, compute the estimate at the time when a given block was found.
Value GetNetworkHashPS(int lookup, int height) {
CBlockIndex *pb = pindexBest;
if (height >= 0 && height < nBestHeight)
pb = FindBlockByHeight(height);
if (pb == NULL || !pb->nHeight)
return 0;
// If lookup is -1, then use blocks since last difficulty change.
if (lookup <= 0)
lookup = pb->nHeight % 2016 + 1;
// If lookup is larger than chain, then set it to chain length.
if (lookup > pb->nHeight)
lookup = pb->nHeight;
double sum = 0.0;
for (int i = 0; i < lookup; i++)
{
sum += (pb->GetBlockTime() - pb->pprev->GetBlockTime()) / GetDifficulty(pb);
pb = pb->pprev;
}
return (boost::int64_t)(pow(2.0, 32) / (sum / lookup));
}
示例4: getpolopointsstate
/*
* 获取最近 N个块状态信息: getpolopointsstate param
*
* */
Value getpolopointsstate(const Array& params, bool fHelp)
{
if (fHelp || params.size() != 1)
throw runtime_error(
"getpolopointsstate \"num\"\n"
"\nget state data about the recently blocks.\n"
"\nArguments:\n"
"1.num (numeric,required, > 0) The number of the recently blocks.\n"
"\nResult:\n"
"{\n"
" \"blocktime\": n, (numeric)get the time of each block\n"
" \"difficulty\": n, (numeric)get the difficulty of each block\n"
" \"transactions\": n, (numeric)get the transactions of each block\n"
" \"fuel\": n, (numeric)get fuel of each block\n"
" \"blockminer\": n, (numeric)get the miner of each block\n"
"}\n"
"\nExamples:\n"
+ HelpExampleCli("getpolopointsstate", "\"5\"")
+ HelpExampleRpc("getpolopointsstate", "\"5\"")
);
int i = 0,nHeight = 0;
if (int_type == params[0].type()) {
nHeight = params[0].get_int();
if(nHeight < 1)
throw runtime_error("Block number out of range.");
if(nHeight > chainActive.Height())
{ //防止超过最大高度
nHeight = chainActive.Height();
}
}
CBlockIndex * pBlockIndex = chainActive.Tip();
CBlock block;
Array blocktime;
Array difficulty;
Array transactions;
Array fuel;
Array blockminer;
for (i = 0; (i < nHeight) && (pBlockIndex != NULL); i++) {
blocktime.push_back(pBlockIndex->GetBlockTime());
difficulty.push_back(GetDifficulty(pBlockIndex));
transactions.push_back((int)pBlockIndex->nTx);
fuel.push_back(pBlockIndex->nFuel);
block.SetNull();
if(ReadBlockFromDisk(block, pBlockIndex))
{
string miner(boost::get<CRegID>(dynamic_pointer_cast<CRewardTransaction>(block.vptx[0])->account).ToString());
blockminer.push_back(move(miner));
}
pBlockIndex = pBlockIndex->pprev;
}
Object obj;
obj.push_back(Pair("blocktime", blocktime));
obj.push_back(Pair("difficulty", difficulty));
obj.push_back(Pair("transactions", transactions));
obj.push_back(Pair("fuel", fuel));
obj.push_back(Pair("blockminer",blockminer));
return obj;
}
示例5: getcheckpoint
// apexcoin: get information of sync-checkpoint
Value getcheckpoint(const Array& params, bool fHelp)
{
if (fHelp || params.size() != 0)
throw runtime_error(
"getcheckpoint\n"
"Show info of synchronized checkpoint.\n");
Object result;
CBlockIndex* pindexCheckpoint;
result.push_back(Pair("synccheckpoint", Checkpoints::hashSyncCheckpoint.ToString().c_str()));
pindexCheckpoint = mapBlockIndex[Checkpoints::hashSyncCheckpoint];
result.push_back(Pair("height", pindexCheckpoint->nHeight));
result.push_back(Pair("timestamp", DateTimeStrFormat(pindexCheckpoint->GetBlockTime()).c_str()));
// Check that the block satisfies synchronized checkpoint
if (CheckpointsMode == Checkpoints::STRICT)
result.push_back(Pair("policy", "strict"));
if (CheckpointsMode == Checkpoints::ADVISORY)
result.push_back(Pair("policy", "advisory"));
if (CheckpointsMode == Checkpoints::PERMISSIVE)
result.push_back(Pair("policy", "permissive"));
if (mapArgs.count("-checkpointkey"))
result.push_back(Pair("checkpointmaster", true));
return result;
}
示例6: GetPoWKHashPM
double GetPoWKHashPM()
{
int nPoWInterval = 72;
int64_t nTargetSpacingWorkMin = 30, nTargetSpacingWork = 30;
CBlockIndex* pindex = pindexGenesisBlock;
CBlockIndex* pindexPrevWork = pindexGenesisBlock;
while (pindex)
{
int64_t nActualSpacingWork = pindex->GetBlockTime() - pindexPrevWork->GetBlockTime();
nTargetSpacingWork = ((nPoWInterval - 1) * nTargetSpacingWork + nActualSpacingWork + nActualSpacingWork) / (nPoWInterval + 1);
nTargetSpacingWork = max(nTargetSpacingWork, nTargetSpacingWorkMin);
pindexPrevWork = pindex;
pindex = pindex->pnext;
}
return (GetDifficulty() * 1024 * 4294.967296 / nTargetSpacingWork) * 60; // 60= sec to min, 1024= standard scrypt work to scrypt^2
}
示例7: GetPoWMHashPS
double GetPoWMHashPS()
{
if (GetBoolArg("-testnet")){
if (pindexBest->nHeight >= P1_End_TestNet && pindexBest->nHeight < P2_Start_TestNet){
return 0;
} else if (pindexBest->nHeight > P2_End_TestNet){
return 0;
}
}else {
if (pindexBest->nHeight >= P1_End && pindexBest->nHeight < P2_Start){
return 0;
} else if (pindexBest->nHeight > P2_End){
return 0;
}
}
int nPoWInterval = 72;
int64_t nTargetSpacingWorkMin = 30, nTargetSpacingWork = 30;
CBlockIndex* pindex = pindexGenesisBlock;
CBlockIndex* pindexPrevWork = pindexGenesisBlock;
while (pindex)
{
if (pindex->IsProofOfWork())
{
int64_t nActualSpacingWork = pindex->GetBlockTime() - pindexPrevWork->GetBlockTime();
nTargetSpacingWork = ((nPoWInterval - 1) * nTargetSpacingWork + nActualSpacingWork + nActualSpacingWork) / (nPoWInterval + 1);
nTargetSpacingWork = max(nTargetSpacingWork, nTargetSpacingWorkMin);
pindexPrevWork = pindex;
}
pindex = pindex->pnext;
}
return GetDifficulty() * 4294.967296 / nTargetSpacingWork;
}
示例8: GetPoWMHashPS
double GetPoWMHashPS()
{
int nPoWInterval = 72;
int64 nTargetSpacingWorkMin = 30, nTargetSpacingWork = 30;
CBlockIndex* pindex = pindexGenesisBlock;
CBlockIndex* pindexPrevWork = pindexGenesisBlock;
while (pindex)
{
if (pindex->IsProofOfWork())
{
int64 nActualSpacingWork = pindex->GetBlockTime() - pindexPrevWork->GetBlockTime();
nTargetSpacingWork = ((nPoWInterval - 1) * nTargetSpacingWork + nActualSpacingWork + nActualSpacingWork) / (nPoWInterval + 1);
nTargetSpacingWork = max(nTargetSpacingWork, nTargetSpacingWorkMin);
pindexPrevWork = pindex;
}
pindex = pindex->pnext;
}
return GetDifficulty() * 4294.967296 / nTargetSpacingWork;
}
示例9: TxToJSON
void TxToJSON(const CTransaction& tx, const uint256 hashBlock, UniValue& entry)
{
// Call into TxToUniv() in bitcoin-common to decode the transaction hex.
//
// Blockchain contextual information (confirmations and blocktime) is not
// available to code in bitcoin-common, so we query them here and push the
// data into the returned UniValue.
TxToUniv(tx, uint256(), entry, true, RPCSerializationFlags());
if (!hashBlock.IsNull()) {
entry.push_back(Pair("blockhash", hashBlock.GetHex()));
BlockMap::iterator mi = mapBlockIndex.find(hashBlock);
if (mi != mapBlockIndex.end() && (*mi).second) {
CBlockIndex* pindex = (*mi).second;
if (chainActive.Contains(pindex)) {
entry.push_back(Pair("confirmations", 1 + chainActive.Height() - pindex->nHeight));
entry.push_back(Pair("time", pindex->GetBlockTime()));
entry.push_back(Pair("blocktime", pindex->GetBlockTime()));
}
else
entry.push_back(Pair("confirmations", 0));
}
}
}
示例10: getcheckpoint
// ppcoin: get information of sync-checkpoint
Value getcheckpoint(const Array& params, bool fHelp)
{
if (fHelp || params.size() != 0)
throw runtime_error(
"getcheckpoint\n"
"Show info of synchronized checkpoint.\n");
Object result;
CBlockIndex* pindexCheckpoint;
result.push_back(Pair("synccheckpoint", Checkpoints::hashSyncCheckpoint.ToString().c_str()));
pindexCheckpoint = mapBlockIndex[Checkpoints::hashSyncCheckpoint];
result.push_back(Pair("height", pindexCheckpoint->nHeight));
result.push_back(Pair("timestamp", DateTimeStrFormat(pindexCheckpoint->GetBlockTime()).c_str()));
if (mapArgs.count("-checkpointkey"))
result.push_back(Pair("checkpointmaster", true));
return result;
}
示例11: GetNetworkHashPS
// 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);
}
示例12: peggypayments
Value peggypayments(const Array& params, bool fHelp)
{
if (fHelp || params.size() < 1)
throw runtime_error(
"peggypayments <block height>\n"
"Shows all redeems for a certain block: \n"
"(-1 for latest block)\n"
);
int64_t nHeight, nBlockTime;
nHeight = params[0].get_int64();
if(nHeight != -1){
if(nHeight < nMinPeggyHeight || nHeight > pindexBest->nHeight)
throw runtime_error(
"peggypayments <block height> <block time>\n"
"the block height you entered is not a peggy block, or the height is out of range\n"
);
CBlockIndex *pindex = FindBlockByHeight(nHeight);
nHeight = pindex->nHeight;
nBlockTime = pindex->GetBlockTime();
}
else{
nHeight = pindexBest->nHeight;
nBlockTime = pindexBest->GetBlockTime();
}
CWallet wallet;
char *paymentScript = peggypayments(nHeight, nBlockTime);
//char *priceFeedHash = peggybase(nHeight, nBlockTime);
std::string retVal = std::string(paymentScript);
free(paymentScript);
return std::string(paymentScript);
}
示例13: GetNetworkHashPS
uint64_t GetNetworkHashPS( int lookup )
{
if( !pindexBest )
return 0;
if( lookup < 0 )
lookup = 0;
// 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 (uint64_t)(((double)GetDifficulty() * pow(2.0, 32)) / timePerBlock);
}
示例14: getcheckpoint
// RPC commands related to sync checkpoints
// get information of sync-checkpoint (first introduced in ppcoin)
Value getcheckpoint(const Array& params, bool fHelp)
{
if (fHelp || params.size() != 0)
throw runtime_error(
"getcheckpoint\n"
"Show info of synchronized checkpoint.\n");
Object result;
CBlockIndex* pindexCheckpoint;
result.push_back(Pair("synccheckpoint", hashSyncCheckpoint.ToString().c_str()));
if (mapBlockIndex.count(hashSyncCheckpoint))
{
pindexCheckpoint = mapBlockIndex[hashSyncCheckpoint];
result.push_back(Pair("height", pindexCheckpoint->nHeight));
result.push_back(Pair("timestamp", (boost::int64_t) pindexCheckpoint->GetBlockTime()));
}
result.push_back(Pair("subscribemode", IsSyncCheckpointEnforced()? "enforce" : "advisory"));
if (mapArgs.count("-checkpointkey"))
result.push_back(Pair("checkpointmaster", true));
return result;
}
示例15: TxToJSON
void TxToJSON(const CTransaction& tx, const uint256 hashBlock, UniValue& entry)
{
entry.push_back(Pair("txid", tx.GetHash().GetHex()));
entry.push_back(Pair("hash", tx.GetWitnessHash().GetHex()));
entry.push_back(Pair("size", (int)::GetSerializeSize(tx, SER_NETWORK, PROTOCOL_VERSION)));
entry.push_back(Pair("vsize", (int)::GetVirtualTransactionSize(tx)));
entry.push_back(Pair("version", tx.nVersion));
entry.push_back(Pair("locktime", (int64_t)tx.nLockTime));
UniValue vin(UniValue::VARR);
for (unsigned int i = 0; i < tx.vin.size(); i++) {
const CTxIn& txin = tx.vin[i];
UniValue in(UniValue::VOBJ);
if (tx.IsCoinBase())
in.push_back(Pair("coinbase", HexStr(txin.scriptSig.begin(), txin.scriptSig.end())));
else {
in.push_back(Pair("txid", txin.prevout.hash.GetHex()));
in.push_back(Pair("vout", (int64_t)txin.prevout.n));
UniValue o(UniValue::VOBJ);
o.push_back(Pair("asm", ScriptToAsmStr(txin.scriptSig, true)));
o.push_back(Pair("hex", HexStr(txin.scriptSig.begin(), txin.scriptSig.end())));
in.push_back(Pair("scriptSig", o));
}
if (!tx.wit.IsNull()) {
if (!tx.wit.vtxinwit[i].IsNull()) {
UniValue txinwitness(UniValue::VARR);
for (unsigned int j = 0; j < tx.wit.vtxinwit[i].scriptWitness.stack.size(); j++) {
std::vector<unsigned char> item = tx.wit.vtxinwit[i].scriptWitness.stack[j];
txinwitness.push_back(HexStr(item.begin(), item.end()));
}
in.push_back(Pair("txinwitness", txinwitness));
}
}
in.push_back(Pair("sequence", (int64_t)txin.nSequence));
vin.push_back(in);
}
entry.push_back(Pair("vin", vin));
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("value", ValueFromAmount(txout.nValue)));
out.push_back(Pair("n", (int64_t)i));
UniValue o(UniValue::VOBJ);
ScriptPubKeyToJSON(txout.scriptPubKey, o, true);
out.push_back(Pair("scriptPubKey", o));
vout.push_back(out);
}
entry.push_back(Pair("vout", vout));
if (!hashBlock.IsNull()) {
entry.push_back(Pair("blockhash", hashBlock.GetHex()));
BlockMap::iterator mi = mapBlockIndex.find(hashBlock);
if (mi != mapBlockIndex.end() && (*mi).second) {
CBlockIndex* pindex = (*mi).second;
if (chainActive.Contains(pindex)) {
entry.push_back(Pair("confirmations", 1 + chainActive.Height() - pindex->nHeight));
entry.push_back(Pair("time", pindex->GetBlockTime()));
entry.push_back(Pair("blocktime", pindex->GetBlockTime()));
}
else
entry.push_back(Pair("confirmations", 0));
}
}
}