本文整理汇总了C++中CBigNum::ToString方法的典型用法代码示例。如果您正苦于以下问题:C++ CBigNum::ToString方法的具体用法?C++ CBigNum::ToString怎么用?C++ CBigNum::ToString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CBigNum
的用法示例。
在下文中一共展示了CBigNum::ToString方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: listprimerecords
// pNut: list prime chain records within pnut network
Value listprimerecords(const Array& params, bool fHelp)
{
if (fHelp || params.size() < 1 || params.size() > 2)
throw runtime_error(
"listprimerecords <primechain length> [primechain type]\n"
"Returns the list of record prime chains in pnut network.\n"
"<primechain length> is integer like 10, 11, 12 etc.\n"
"[primechain type] is optional type, among 1CC, 2CC and TWN");
int nPrimeChainLength = params[0].get_int();
unsigned int nPrimeChainType = 0;
if (params.size() > 1)
{
std::string strPrimeChainType = params[1].get_str();
if (strPrimeChainType.compare("1CC") == 0)
nPrimeChainType = PRIME_CHAIN_CUNNINGHAM1;
else if (strPrimeChainType.compare("2CC") == 0)
nPrimeChainType = PRIME_CHAIN_CUNNINGHAM2;
else if (strPrimeChainType.compare("TWN") == 0)
nPrimeChainType = PRIME_CHAIN_BI_TWIN;
else
throw runtime_error("Prime chain type must be 1CC, 2CC or TWN.");
}
Array ret;
CBigNum bnPrimeRecord = 0;
for (CBlockIndex* pindex = pindexGenesisBlock; pindex; pindex = pindex->pnext)
{
if (nPrimeChainLength != (int) TargetGetLength(pindex->nPrimeChainLength))
continue; // length not matching, next block
if (nPrimeChainType && nPrimeChainType != pindex->nPrimeChainType)
continue; // type not matching, next block
CBlock block;
block.ReadFromDisk(pindex); // read block
CBigNum bnPrimeChainOrigin = CBigNum(block.GetHeaderHash()) * block.bnPrimeChainMultiplier; // compute prime chain origin
if (bnPrimeChainOrigin > bnPrimeRecord)
{
bnPrimeRecord = bnPrimeChainOrigin; // new record in pnut
Object entry;
entry.push_back(Pair("time", DateTimeStrFormat("%Y-%m-%d %H:%M:%S UTC", pindex->GetBlockTime()).c_str()));
entry.push_back(Pair("epoch", (boost::int64_t) pindex->GetBlockTime()));
entry.push_back(Pair("height", pindex->nHeight));
entry.push_back(Pair("ismine", pwalletMain->IsMine(block.vtx[0])));
CTxDestination address;
entry.push_back(Pair("mineraddress", (block.vtx[0].vout.size() > 1)? "multiple" : ExtractDestination(block.vtx[0].vout[0].scriptPubKey, address)? CBitcoinAddress(address).ToString().c_str() : "invalid"));
entry.push_back(Pair("primedigit", (int) bnPrimeChainOrigin.ToString().length()));
entry.push_back(Pair("primechain", GetPrimeChainName(pindex->nPrimeChainType, pindex->nPrimeChainLength).c_str()));
entry.push_back(Pair("primeorigin", bnPrimeChainOrigin.ToString().c_str()));
entry.push_back(Pair("primorialform", GetPrimeOriginPrimorialForm(bnPrimeChainOrigin).c_str()));
ret.push_back(entry);
}
}
return ret;
}
示例2: blockToJSON
Object blockToJSON(const CBlock& block, const CBlockIndex* blockindex)
{
Object result;
result.push_back(Pair("hash", block.GetHash().GetHex()));
CMerkleTx txGen(block.vtx[0]);
txGen.SetMerkleBranch(&block);
result.push_back(Pair("confirmations", (int)txGen.GetDepthInMainChain()));
result.push_back(Pair("size", (int)::GetSerializeSize(block, SER_NETWORK, PROTOCOL_VERSION)));
result.push_back(Pair("height", blockindex->nHeight));
result.push_back(Pair("version", block.nVersion));
result.push_back(Pair("headerhash", block.GetHeaderHash().GetHex()));
result.push_back(Pair("merkleroot", block.hashMerkleRoot.GetHex()));
Array txs;
BOOST_FOREACH(const CTransaction&tx, block.vtx)
txs.push_back(tx.GetHash().GetHex());
result.push_back(Pair("tx", txs));
result.push_back(Pair("time", (boost::int64_t)block.GetBlockTime()));
result.push_back(Pair("nonce", (boost::uint64_t)block.nNonce));
result.push_back(Pair("bits", HexBits(block.nBits)));
result.push_back(Pair("difficulty", GetPrimeDifficulty(block.nBits)));
result.push_back(Pair("transition", GetPrimeDifficulty(blockindex->nWorkTransition)));
CBigNum bnPrimeChainOrigin = CBigNum(block.GetHeaderHash()) * block.bnPrimeChainMultiplier;
result.push_back(Pair("primechain", GetPrimeChainName(blockindex->nPrimeChainType, blockindex->nPrimeChainLength).c_str()));
result.push_back(Pair("primeorigin", bnPrimeChainOrigin.ToString().c_str()));
if (blockindex->pprev)
result.push_back(Pair("previousblockhash", blockindex->pprev->GetBlockHash().GetHex()));
if (blockindex->pnext)
result.push_back(Pair("nextblockhash", blockindex->pnext->GetBlockHash().GetHex()));
return result;
}
示例3: formatTimeInterval
static QString formatTimeInterval(CBigNum t)
{
enum EUnit { YEAR, MONTH, DAY, HOUR, MINUTE, SECOND, NUM_UNITS };
const int SecondsPerUnit[NUM_UNITS] =
{
31556952, // average number of seconds in gregorian year
31556952/12, // average number of seconds in gregorian month
24*60*60, // number of seconds in a day
60*60, // number of seconds in an hour
60, // number of seconds in a minute
1
};
const char* UnitNames[NUM_UNITS] =
{
"year",
"month",
"day",
"hour",
"minute",
"second"
};
if (t > 0xFFFFFFFF)
{
t /= SecondsPerUnit[YEAR];
return QString("%1 years").arg(t.ToString(10).c_str());
}
else
{
unsigned int t32 = t.getuint();
int Values[NUM_UNITS];
for (int i = 0; i < NUM_UNITS; i++)
{
Values[i] = t32/SecondsPerUnit[i];
t32 %= SecondsPerUnit[i];
}
int FirstNonZero = 0;
while (FirstNonZero < NUM_UNITS && Values[FirstNonZero] == 0)
FirstNonZero++;
QString TimeStr;
for (int i = FirstNonZero; i < std::min(FirstNonZero + 3, (int)NUM_UNITS); i++)
{
int Value = Values[i];
TimeStr += QString("%1 %2%3 ").arg(Value).arg(UnitNames[i]).arg((Value == 1)? "" : "s"); // FIXME: this is English specific
}
return TimeStr;
}
}
示例4: addr
CMainParams() {
// The message start string is designed to be unlikely to occur in normal data.
// The characters are rarely used upper ASCII, not valid as UTF-8, and produce
// a large 4-byte int at any alignment.
pchMessageStart[0] = 0xf9;
pchMessageStart[1] = 0xbe;
pchMessageStart[2] = 0xb4;
pchMessageStart[3] = 0xd9;
vAlertPubKey = ParseHex("04fc9702847840aaf195de8442ebecedf5b095cdbb9bc716bda9110971b28a49e0ead8564ff0db22209e0374782c093bb899692d524e9d6a6956e7c5ecbcd68284");
nDefaultPort = 28333;
nRPCPort = 8332;
bnProofOfWorkLimit = CBigNum(~uint256(0) >> 16);
nSubsidyHalvingInterval = 210000;
// Build the genesis block. Note that the output of the genesis coinbase cannot
// be spent as it did not originally exist in the database.
//
// CBlock(hash=000000000019d6, ver=1, hashPrevBlock=00000000000000, hashMerkleRoot=4a5e1e, nTime=1231006505, nBits=1d00ffff, nNonce=2083236893, vtx=1)
// CTransaction(hash=4a5e1e, ver=1, vin.size=1, vout.size=1, nLockTime=0)
// CTxIn(COutPoint(000000, -1), coinbase 04ffff001d0104455468652054696d65732030332f4a616e2f32303039204368616e63656c6c6f72206f6e206272696e6b206f66207365636f6e64206261696c6f757420666f722062616e6b73)
// CTxOut(nValue=50.00000000, scriptPubKey=0x5F1DF16B2B704C8A578D0B)
// vMerkleTree: 4a5e1e
const char* pszTimestamp = "2014-03-30 Nobody 50.06, Kiska 29.66, Fico 20.28; Founder: heXKRhnGdSg";
int extranonce = 42;
CTransaction txNew;
txNew.vin.resize(1);
txNew.vout.resize(1);
txNew.vin[0].scriptSig = CScript() << extranonce << CBigNum(4) << vector<unsigned char>((const unsigned char*)pszTimestamp, (const unsigned char*)pszTimestamp + strlen(pszTimestamp));
txNew.vout[0].nValue = 50 * COIN;
txNew.vout[0].scriptPubKey = CScript() << ParseHex("2dc4f1967fbf825c77dadd9da14c3608428ada53") << OP_EQUALVERIFY << OP_CHECKSIG;
genesis.vtx.push_back(txNew);
genesis.hashPrevBlock = 0;
genesis.hashMerkleRoot = genesis.BuildMerkleTree();
genesis.nVersion = 1;
genesis.nTime = 1396187239;
genesis.nBits = 0x1e008fff;
genesis.nNonce = 23443383;
hashGenesisBlock = genesis.GetHash();
#ifdef MINE_GENESIS
CBigNum bnTarget;
bnTarget.SetCompact(genesis.nBits);
fprintf(stderr, "Target: %s\n", bnTarget.ToString().c_str());
assert(!(bnTarget <= 0 || bnTarget > Params().ProofOfWorkLimit()));
while(hashGenesisBlock > bnTarget.getuint256()) {
++genesis.nNonce;
if(!genesis.nNonce) {
++extranonce;
};
hashGenesisBlock = genesis.GetHash();
}
fprintf(stderr, "Nonce = %d\nExtranonce = %d\n", genesis.nNonce, extranonce);
fprintf(stderr, "Genesis hash = %s\nMerkle root = %s\n", hashGenesisBlock.GetHex().c_str(), genesis.hashMerkleRoot.GetHex().c_str());
#else
assert(hashGenesisBlock == uint256("0x000000530b4b2d75534bfa61c42e62f4402ce579dd8507c70009e69439f4bd19"));
assert(genesis.hashMerkleRoot == uint256("0x2446d19ab3361d3484c4f1dade799a54dfd010f193521659a26341c6f50b811a"));
#endif
vSeeds.push_back(CDNSSeedData("bitcoin.sipa.be", "seed.bitcoin.sipa.be"));
vSeeds.push_back(CDNSSeedData("bluematt.me", "dnsseed.bluematt.me"));
vSeeds.push_back(CDNSSeedData("dashjr.org", "dnsseed.bitcoin.dashjr.org"));
vSeeds.push_back(CDNSSeedData("bitcoinstats.com", "seed.bitcoinstats.com"));
vSeeds.push_back(CDNSSeedData("xf2.org", "bitseed.xf2.org"));
base58Prefixes[PUBKEY_ADDRESS] = list_of(45);
base58Prefixes[SCRIPT_ADDRESS] = list_of(50);
base58Prefixes[SECRET_KEY] = list_of(173);
base58Prefixes[EXT_PUBLIC_KEY] = list_of(0x04)(0x88)(0xB2)(0x1E);
base58Prefixes[EXT_SECRET_KEY] = list_of(0x04)(0x88)(0xAD)(0xE4);
// Convert the pnSeeds array into usable address objects.
for (unsigned int i = 0; i < ARRAYLEN(pnSeed); i++)
{
// It'll only connect to one or two seed nodes because once it connects,
// it'll get a pile of addresses with newer timestamps.
// Seed nodes are given a random 'last seen time' of between one and two
// weeks ago.
const int64_t nOneWeek = 7*24*60*60;
struct in_addr ip;
memcpy(&ip, &pnSeed[i], sizeof(ip));
CAddress addr(CService(ip, GetDefaultPort()));
addr.nTime = GetTime() - GetRand(nOneWeek) - nOneWeek;
vFixedSeeds.push_back(addr);
}
}
示例5: main
int main(int argc, char **argv)
{
static CBigNum resultModulus(0);
uint32_t numBits = DEFAULT_MODULUS_SIZE;
ofstream outfile;
char* outfileName;
bool writeToFile = false;
while ((argc > 1) && (argv[1][0] == '-'))
{
switch (argv[1][1])
{
case 'b':
numBits = atoi(argv[2]);
++argv;
--argc;
break;
case 'o':
outfileName = argv[2];
writeToFile = true;
break;
case 'h':
usage();
break;
default:
printf("Wrong Argument: %s\n", argv[1]);
usage();
break;
}
++argv;
--argc;
}
if (numBits < MIN_MODULUS_SIZE) {
cout << "Modulus is below minimum length (" << MIN_MODULUS_SIZE << ") bits" << endl;
return(0);
}
PrintWarning();
cout << "Modulus size set to " << numBits << " bits." << endl;
cout << "Generating parameters. This may take a few minutes..." << endl;
// Generate two safe primes "p" and "q"
CBigNum *p, *q;
p = new CBigNum(0);
q = new CBigNum(0);
*p = CBigNum::generatePrime(numBits / 2, true);
*q = CBigNum::generatePrime(numBits / 2, true);
// Multiply to compute N
resultModulus = (*p) * (*q);
// Wipe out the factors
delete p;
delete q;
// Convert to a hexidecimal string
std::string resultHex = resultModulus.ToString(16);
cout << endl << "N = " << endl << resultHex << endl;
if (writeToFile) {
try {
outfile.open (outfileName);
outfile << resultHex;
outfile.close();
cout << endl << "Result has been written to file '" << outfileName << "'." << endl;
} catch (std::runtime_error &e) {
cout << "Unable to write to file:" << e.what() << endl;
}
}
}
示例6: listtopprimes
// pNut: list top prime chain within pnut network
Value listtopprimes(const Array& params, bool fHelp)
{
if (fHelp || params.size() < 1 || params.size() > 2)
throw runtime_error(
"listtopprimes <primechain length> [primechain type]\n"
"Returns the list of top prime chains in pnut network.\n"
"<primechain length> is integer like 10, 11, 12 etc.\n"
"[primechain type] is optional type, among 1CC, 2CC and TWN");
int nPrimeChainLength = params[0].get_int();
unsigned int nPrimeChainType = 0;
if (params.size() > 1)
{
std::string strPrimeChainType = params[1].get_str();
if (strPrimeChainType.compare("1CC") == 0)
nPrimeChainType = PRIME_CHAIN_CUNNINGHAM1;
else if (strPrimeChainType.compare("2CC") == 0)
nPrimeChainType = PRIME_CHAIN_CUNNINGHAM2;
else if (strPrimeChainType.compare("TWN") == 0)
nPrimeChainType = PRIME_CHAIN_BI_TWIN;
else
throw runtime_error("Prime chain type must be 1CC, 2CC or TWN.");
}
// Search for top prime chains
unsigned int nRankingSize = 10; // ranking list size
unsigned int nSortVectorSize = 64; // vector size for sort operation
CBigNum bnPrimeQualify = 0; // minimum qualify value for ranking list
vector<pair<CBigNum, uint256> > vSortedByOrigin;
for (CBlockIndex* pindex = pindexGenesisBlock; pindex; pindex = pindex->pnext)
{
if (nPrimeChainLength != (int) TargetGetLength(pindex->nPrimeChainLength))
continue; // length not matching, next block
if (nPrimeChainType && nPrimeChainType != pindex->nPrimeChainType)
continue; // type not matching, next block
CBlock block;
block.ReadFromDisk(pindex); // read block
CBigNum bnPrimeChainOrigin = CBigNum(block.GetHeaderHash()) * block.bnPrimeChainMultiplier; // compute prime chain origin
if (bnPrimeChainOrigin > bnPrimeQualify)
vSortedByOrigin.push_back(make_pair(bnPrimeChainOrigin, block.GetHash()));
if (vSortedByOrigin.size() >= nSortVectorSize)
{
// Sort prime chain candidates
sort(vSortedByOrigin.begin(), vSortedByOrigin.end());
reverse(vSortedByOrigin.begin(), vSortedByOrigin.end());
// Truncate candidate list
while (vSortedByOrigin.size() > nRankingSize)
vSortedByOrigin.pop_back();
// Update minimum qualify value for top prime chains
bnPrimeQualify = vSortedByOrigin.back().first;
}
}
// Final sort of prime chain candidates
sort(vSortedByOrigin.begin(), vSortedByOrigin.end());
reverse(vSortedByOrigin.begin(), vSortedByOrigin.end());
// Truncate candidate list
while (vSortedByOrigin.size() > nRankingSize)
vSortedByOrigin.pop_back();
// Output top prime chains
Array ret;
BOOST_FOREACH(const PAIRTYPE(CBigNum, uint256)& item, vSortedByOrigin)
{
CBigNum bnPrimeChainOrigin = item.first;
CBlockIndex* pindex = mapBlockIndex[item.second];
CBlock block;
block.ReadFromDisk(pindex); // read block
Object entry;
entry.push_back(Pair("time", DateTimeStrFormat("%Y-%m-%d %H:%M:%S UTC", pindex->GetBlockTime()).c_str()));
entry.push_back(Pair("epoch", (boost::int64_t) pindex->GetBlockTime()));
entry.push_back(Pair("height", pindex->nHeight));
entry.push_back(Pair("ismine", pwalletMain->IsMine(block.vtx[0])));
CTxDestination address;
entry.push_back(Pair("mineraddress", (block.vtx[0].vout.size() > 1)? "multiple" : ExtractDestination(block.vtx[0].vout[0].scriptPubKey, address)? CBitcoinAddress(address).ToString().c_str() : "invalid"));
entry.push_back(Pair("primedigit", (int) bnPrimeChainOrigin.ToString().length()));
entry.push_back(Pair("primechain", GetPrimeChainName(pindex->nPrimeChainType, pindex->nPrimeChainLength).c_str()));
entry.push_back(Pair("primeorigin", bnPrimeChainOrigin.ToString().c_str()));
entry.push_back(Pair("primorialform", GetPrimeOriginPrimorialForm(bnPrimeChainOrigin).c_str()));
ret.push_back(entry);
}
return ret;
}