本文整理汇总了C++中CTransaction::parseJson方法的典型用法代码示例。如果您正苦于以下问题:C++ CTransaction::parseJson方法的具体用法?C++ CTransaction::parseJson怎么用?C++ CTransaction::parseJson使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CTransaction
的用法示例。
在下文中一共展示了CTransaction::parseJson方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Slurp
//.........这里部分代码省略.........
// Grab a page of data from the web api
SFString thisPage = urlToString(url);
// See if it's good data, if not, bail
message = nextTokenClear(thisPage, '[');
if (!message.Contains("{\"status\":\"1\",\"message\":\"OK\""))
{
if (message.Contains("{\"status\":\"0\",\"message\":\"No transactions found\",\"result\":"))
message = "No transactions were found for address '" + theAccount.addr + "'. Is it correct?";
return options.cmdFile;
}
contents += thisPage;
SFInt32 nRecords = countOf('}',thisPage)-1;
nRead += nRecords;
outErr << "\tDownloaded " << nRead << " potentially new transactions." << (isTesting?"\n":"\r");
// If we got a full page, there are more to come
done = (nRecords < options.pageSize);
if (!done)
page++;
// Etherscan.io doesn't want more than five pages per second, so sleep for a second
if (++nRequests==4)
{
SFos::sleep(1.0);
nRequests=0;
}
// Make sure we don't spin forever
if (nRead >= options.maxTransactions)
done=TRUE;
}
SFInt32 minBlock=0,maxBlock=0;
findBlockRange(contents, minBlock, maxBlock);
outErr << "\n\tDownload contains blocks from " << minBlock << " to " << maxBlock << "\n";
// Keep track of which last full page we've read
theAccount.lastPage = page;
theAccount.pageSize = options.pageSize;
// pre allocate the array
theAccount.transactions.Grow(nRead);
SFInt32 lastBlock=0;
char *p = cleanUpJson((char *)(const char*)contents);
while (p && *p)
{
CTransaction trans;SFInt32 nFields=0;
p = trans.parseJson(p,nFields);
if (nFields)
{
SFInt32 transBlock = trans.blockNumber;
if (transBlock > theAccount.lastBlock) // add the new transaction if it's in a new block
{
theAccount.transactions[nextRecord++] = trans;
lastBlock = transBlock;
if (!(++nNewBlocks%REP_FREQ))
{
outErr << "\tFound new transaction at block " << transBlock << ". Importing..." << (isTesting?"\n":"\r");
outErr.Flush();
}
}
}
}
if (!isTesting && nNewBlocks) { outErr << "\tFound new transaction at block " << lastBlock << ". Importing...\n"; outErr.Flush(); }
theAccount.lastBlock = lastBlock;
// Write the data if we got new data
SFInt32 newRecords = (theAccount.transactions.getCount() - origCount);
if (newRecords)
{
outErr << "\tWriting " << newRecords << " new records to cache\n";
SFArchive archive(FALSE, NO_SCHEMA);
if (archive.Lock(cacheFilename, binaryWriteCreate, LOCK_CREATE))
{
theAccount.transactions.Sort(sortTransactionsForWrite);
theAccount.Serialize(archive);
archive.Close();
} else
{
message = "Could not open file: '" + cacheFilename + "'\n";
return options.cmdFile;
}
}
}
if (!isTesting)
{
double stop = vrNow();
double timeSpent = stop-start;
fprintf(stderr, "\tLoaded %ld total records in %f seconds\n", theAccount.transactions.getCount(), timeSpent);
fflush(stderr);
}
return (options.cmdFile || theAccount.transactions.getCount()>0);
}