本文整理汇总了C++中cryptonote::Currency::difficultyWindow方法的典型用法代码示例。如果您正苦于以下问题:C++ Currency::difficultyWindow方法的具体用法?C++ Currency::difficultyWindow怎么用?C++ Currency::difficultyWindow使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cryptonote::Currency
的用法示例。
在下文中一共展示了Currency::difficultyWindow方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char *argv[]) {
if (argc != 2) {
cerr << "Wrong arguments" << endl;
return 1;
}
Logging::ConsoleLogger logger;
CryptoNote::CurrencyBuilder currencyBuilder(logger);
currencyBuilder.difficultyTarget(120);
currencyBuilder.difficultyWindow(720);
currencyBuilder.difficultyCut(60);
currencyBuilder.difficultyLag(15);
CryptoNote::Currency currency = currencyBuilder.currency();
vector<uint64_t> timestamps, cumulative_difficulties;
fstream data(argv[1], fstream::in);
data.exceptions(fstream::badbit);
data.clear(data.rdstate());
uint64_t timestamp, difficulty, cumulative_difficulty = 0;
size_t n = 0;
while (data >> timestamp >> difficulty) {
size_t begin, end;
if (n < currency.difficultyWindow() + currency.difficultyLag()) {
begin = 0;
end = min(n, currency.difficultyWindow());
} else {
end = n - currency.difficultyLag();
begin = end - currency.difficultyWindow();
}
uint64_t res = currency.nextDifficulty(
vector<uint64_t>(timestamps.begin() + begin, timestamps.begin() + end),
vector<uint64_t>(cumulative_difficulties.begin() + begin, cumulative_difficulties.begin() + end));
if (res != difficulty) {
cerr << "Wrong difficulty for block " << n << endl
<< "Expected: " << difficulty << endl
<< "Found: " << res << endl;
return 1;
}
timestamps.push_back(timestamp);
cumulative_difficulties.push_back(cumulative_difficulty += difficulty);
++n;
}
if (!data.eof()) {
data.clear(fstream::badbit);
}
return 0;
}