danicoin/src/cryptonote_core/Currency.cpp

480 lines
16 KiB
C++
Raw Normal View History

2015-05-27 12:08:46 +00:00
// Copyright (c) 2012-2015, The CryptoNote developers, The Bytecoin developers
2014-08-13 10:51:37 +00:00
//
// This file is part of Bytecoin.
//
// Bytecoin is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Bytecoin is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with Bytecoin. If not, see <http://www.gnu.org/licenses/>.
#include "Currency.h"
2015-05-27 12:08:46 +00:00
#include <cctype>
2014-08-13 10:51:37 +00:00
#include <boost/algorithm/string/trim.hpp>
#include <boost/lexical_cast.hpp>
2015-05-27 12:08:46 +00:00
#include "../Common/base58.h"
#include "../Common/int-util.h"
#include "account.h"
#include "cryptonote_basic_impl.h"
#include "cryptonote_format_utils.h"
#include "UpgradeDetector.h"
#undef ERROR
using namespace Logging;
namespace CryptoNote {
bool Currency::init() {
if (!generateGenesisBlock()) {
logger(ERROR, BRIGHT_RED) << "Failed to generate genesis block";
return false;
}
2014-08-13 10:51:37 +00:00
2015-05-27 12:08:46 +00:00
if (!get_block_hash(m_genesisBlock, m_genesisBlockHash)) {
logger(ERROR, BRIGHT_RED) << "Failed to get genesis block hash";
return false;
}
2014-08-13 10:51:37 +00:00
2015-05-27 12:08:46 +00:00
if (isTestnet()) {
m_upgradeHeight = 0;
m_blocksFileName = "testnet_" + m_blocksFileName;
m_blocksCacheFileName = "testnet_" + m_blocksCacheFileName;
m_blockIndexesFileName = "testnet_" + m_blockIndexesFileName;
m_txPoolFileName = "testnet_" + m_txPoolFileName;
2014-08-13 10:51:37 +00:00
}
2015-05-27 12:08:46 +00:00
return true;
}
2014-08-13 10:51:37 +00:00
2015-05-27 12:08:46 +00:00
bool Currency::generateGenesisBlock() {
m_genesisBlock = boost::value_initialized<Block>();
2014-08-13 10:51:37 +00:00
2015-05-27 12:08:46 +00:00
//account_public_address ac = boost::value_initialized<AccountPublicAddress>();
//std::vector<size_t> sz;
//constructMinerTx(0, 0, 0, 0, 0, ac, m_genesisBlock.minerTx); // zero fee in genesis
//blobdata txb = tx_to_blob(m_genesisBlock.minerTx);
//std::string hex_tx_represent = Common::toHex(txb);
2014-08-13 10:51:37 +00:00
2015-05-27 12:08:46 +00:00
// Hard code coinbase tx in genesis block, because through generating tx use random, but genesis should be always the same
std::string genesisCoinbaseTxHex = "010a01ff0001ffffffffffff0f029b2e4c0281c0b02e7c53291a94d1d0cbff8883f8024f5142ee494ffbbd08807121013c086a48c15fb637a96991bc6d53caf77068b5ba6eeb3c82357228c49790584a";
blobdata minerTxBlob;
2014-08-13 10:51:37 +00:00
2015-05-27 12:08:46 +00:00
bool r =
hexToBlob(genesisCoinbaseTxHex, minerTxBlob) &&
parse_and_validate_tx_from_blob(minerTxBlob, m_genesisBlock.minerTx);
2014-08-13 10:51:37 +00:00
2015-05-27 12:08:46 +00:00
if (!r) {
logger(ERROR, BRIGHT_RED) << "failed to parse coinbase tx from hard coded blob";
return false;
}
2014-08-13 10:51:37 +00:00
2015-05-27 12:08:46 +00:00
m_genesisBlock.majorVersion = BLOCK_MAJOR_VERSION_1;
m_genesisBlock.minorVersion = BLOCK_MINOR_VERSION_0;
m_genesisBlock.timestamp = 0;
m_genesisBlock.nonce = 70;
if (m_testnet) {
++m_genesisBlock.nonce;
}
//miner::find_nonce_for_given_block(bl, 1, 0);
2014-08-13 10:51:37 +00:00
2015-05-27 12:08:46 +00:00
return true;
}
2014-08-13 10:51:37 +00:00
2015-05-27 12:08:46 +00:00
bool Currency::getBlockReward(size_t medianSize, size_t currentBlockSize, uint64_t alreadyGeneratedCoins,
uint64_t fee, bool penalizeFee, uint64_t& reward, int64_t& emissionChange) const {
assert(alreadyGeneratedCoins <= m_moneySupply);
assert(m_emissionSpeedFactor > 0 && m_emissionSpeedFactor <= 8 * sizeof(uint64_t));
2014-08-13 10:51:37 +00:00
2015-05-27 12:08:46 +00:00
uint64_t baseReward = (m_moneySupply - alreadyGeneratedCoins) >> m_emissionSpeedFactor;
2014-08-13 10:51:37 +00:00
2015-05-27 12:08:46 +00:00
size_t blockGrantedFullRewardZone = penalizeFee ?
m_blockGrantedFullRewardZone :
CryptoNote::parameters::CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V1;
medianSize = std::max(medianSize, blockGrantedFullRewardZone);
if (currentBlockSize > UINT64_C(2) * medianSize) {
logger(TRACE) << "Block cumulative size is too big: " << currentBlockSize << ", expected less than " << 2 * medianSize;
return false;
2014-08-13 10:51:37 +00:00
}
2015-05-27 12:08:46 +00:00
uint64_t penalizedBaseReward = getPenalizedAmount(baseReward, medianSize, currentBlockSize);
uint64_t penalizedFee = penalizeFee ? getPenalizedAmount(fee, medianSize, currentBlockSize) : fee;
2014-08-13 10:51:37 +00:00
2015-05-27 12:08:46 +00:00
emissionChange = penalizedBaseReward - (fee - penalizedFee);
reward = penalizedBaseReward + penalizedFee;
2014-08-13 10:51:37 +00:00
2015-05-27 12:08:46 +00:00
return true;
}
2014-08-13 10:51:37 +00:00
2015-05-27 12:08:46 +00:00
size_t Currency::maxBlockCumulativeSize(uint64_t height) const {
assert(height <= std::numeric_limits<uint64_t>::max() / m_maxBlockSizeGrowthSpeedNumerator);
size_t maxSize = static_cast<size_t>(m_maxBlockSizeInitial +
(height * m_maxBlockSizeGrowthSpeedNumerator) / m_maxBlockSizeGrowthSpeedDenominator);
assert(maxSize >= m_maxBlockSizeInitial);
return maxSize;
}
2014-08-13 10:51:37 +00:00
2015-05-27 12:08:46 +00:00
bool Currency::constructMinerTx(uint32_t height, size_t medianSize, uint64_t alreadyGeneratedCoins, size_t currentBlockSize,
uint64_t fee, const AccountPublicAddress& minerAddress, Transaction& tx,
const blobdata& extraNonce/* = blobdata()*/, size_t maxOuts/* = 1*/,
bool penalizeFee/* = false*/) const {
tx.vin.clear();
tx.vout.clear();
tx.extra.clear();
KeyPair txkey = KeyPair::generate();
add_tx_pub_key_to_extra(tx, txkey.pub);
if (!extraNonce.empty()) {
if (!add_extra_nonce_to_tx_extra(tx.extra, extraNonce)) {
return false;
}
}
TransactionInputGenerate in;
in.height = height;
uint64_t blockReward;
int64_t emissionChange;
if (!getBlockReward(medianSize, currentBlockSize, alreadyGeneratedCoins, fee, penalizeFee, blockReward, emissionChange)) {
logger(INFO) << "Block is too big";
return false;
}
2014-08-13 10:51:37 +00:00
#if defined(DEBUG_CREATE_BLOCK_TEMPLATE)
2015-05-27 12:08:46 +00:00
logger(DEBUGGING) << "Creating block template: reward " << blockReward << ", fee " << fee;
2014-08-13 10:51:37 +00:00
#endif
2015-05-27 12:08:46 +00:00
std::vector<uint64_t> outAmounts;
decompose_amount_into_digits(blockReward, m_defaultDustThreshold,
[&outAmounts](uint64_t a_chunk) { outAmounts.push_back(a_chunk); },
[&outAmounts](uint64_t a_dust) { outAmounts.push_back(a_dust); });
2014-08-13 10:51:37 +00:00
2015-05-27 12:08:46 +00:00
if (!(1 <= maxOuts)) { logger(ERROR, BRIGHT_RED) << "max_out must be non-zero"; return false; }
while (maxOuts < outAmounts.size()) {
outAmounts[outAmounts.size() - 2] += outAmounts.back();
outAmounts.resize(outAmounts.size() - 1);
}
uint64_t summaryAmounts = 0;
for (size_t no = 0; no < outAmounts.size(); no++) {
crypto::key_derivation derivation = boost::value_initialized<crypto::key_derivation>();
crypto::public_key outEphemeralPubKey = boost::value_initialized<crypto::public_key>();
bool r = crypto::generate_key_derivation(minerAddress.m_viewPublicKey, txkey.sec, derivation);
2014-08-13 10:51:37 +00:00
2015-05-27 12:08:46 +00:00
if (!(r)) {
logger(ERROR, BRIGHT_RED)
<< "while creating outs: failed to generate_key_derivation("
<< minerAddress.m_viewPublicKey << ", " << txkey.sec << ")";
return false;
}
2014-08-13 10:51:37 +00:00
2015-05-27 12:08:46 +00:00
r = crypto::derive_public_key(derivation, no, minerAddress.m_spendPublicKey, outEphemeralPubKey);
2014-08-13 10:51:37 +00:00
2015-05-27 12:08:46 +00:00
if (!(r)) {
logger(ERROR, BRIGHT_RED)
<< "while creating outs: failed to derive_public_key("
<< derivation << ", " << no << ", "
<< minerAddress.m_spendPublicKey << ")";
return false;
}
2014-08-13 10:51:37 +00:00
2015-05-27 12:08:46 +00:00
TransactionOutputToKey tk;
tk.key = outEphemeralPubKey;
2014-08-13 10:51:37 +00:00
2015-05-27 12:08:46 +00:00
TransactionOutput out;
summaryAmounts += out.amount = outAmounts[no];
out.target = tk;
tx.vout.push_back(out);
}
2014-08-13 10:51:37 +00:00
2015-05-27 12:08:46 +00:00
if (!(summaryAmounts == blockReward)) {
logger(ERROR, BRIGHT_RED) << "Failed to construct miner tx, summaryAmounts = " << summaryAmounts << " not equal blockReward = " << blockReward;
return false;
2014-08-13 10:51:37 +00:00
}
2015-05-27 12:08:46 +00:00
tx.version = CURRENT_TRANSACTION_VERSION;
//lock
tx.unlockTime = height + m_minedMoneyUnlockWindow;
tx.vin.push_back(in);
return true;
}
std::string Currency::accountAddressAsString(const account_base& account) const {
return getAccountAddressAsStr(m_publicAddressBase58Prefix, account.get_keys().m_account_address);
}
2015-07-15 12:23:00 +00:00
std::string Currency::accountAddressAsString(const AccountPublicAddress& accountPublicAddress) const {
return getAccountAddressAsStr(m_publicAddressBase58Prefix, accountPublicAddress);
}
2015-05-27 12:08:46 +00:00
bool Currency::parseAccountAddressString(const std::string& str, AccountPublicAddress& addr) const {
uint64_t prefix;
if (!CryptoNote::parseAccountAddressString(prefix, addr, str)) {
return false;
2014-08-13 10:51:37 +00:00
}
2015-05-27 12:08:46 +00:00
if (prefix != m_publicAddressBase58Prefix) {
logger(DEBUGGING) << "Wrong address prefix: " << prefix << ", expected " << m_publicAddressBase58Prefix;
return false;
}
2014-08-13 10:51:37 +00:00
2015-05-27 12:08:46 +00:00
return true;
}
2014-08-13 10:51:37 +00:00
2015-05-27 12:08:46 +00:00
std::string Currency::formatAmount(uint64_t amount) const {
std::string s = std::to_string(amount);
if (s.size() < m_numberOfDecimalPlaces + 1) {
s.insert(0, m_numberOfDecimalPlaces + 1 - s.size(), '0');
2014-08-13 10:51:37 +00:00
}
2015-05-27 12:08:46 +00:00
s.insert(s.size() - m_numberOfDecimalPlaces, ".");
return s;
}
2014-08-13 10:51:37 +00:00
2015-05-27 12:08:46 +00:00
bool Currency::parseAmount(const std::string& str, uint64_t& amount) const {
std::string strAmount = str;
boost::algorithm::trim(strAmount);
size_t pointIndex = strAmount.find_first_of('.');
size_t fractionSize;
if (std::string::npos != pointIndex) {
fractionSize = strAmount.size() - pointIndex - 1;
while (m_numberOfDecimalPlaces < fractionSize && '0' == strAmount.back()) {
strAmount.erase(strAmount.size() - 1, 1);
--fractionSize;
2014-08-13 10:51:37 +00:00
}
2015-05-27 12:08:46 +00:00
if (m_numberOfDecimalPlaces < fractionSize) {
2014-08-13 10:51:37 +00:00
return false;
}
2015-05-27 12:08:46 +00:00
strAmount.erase(pointIndex, 1);
} else {
fractionSize = 0;
}
2014-08-13 10:51:37 +00:00
2015-05-27 12:08:46 +00:00
if (strAmount.empty()) {
return false;
}
2014-08-13 10:51:37 +00:00
2015-05-27 12:08:46 +00:00
if (!std::all_of(strAmount.begin(), strAmount.end(), ::isdigit)) {
return false;
2014-08-13 10:51:37 +00:00
}
2015-05-27 12:08:46 +00:00
if (fractionSize < m_numberOfDecimalPlaces) {
strAmount.append(m_numberOfDecimalPlaces - fractionSize, '0');
}
2014-08-13 10:51:37 +00:00
2015-05-27 12:08:46 +00:00
return Common::fromString(strAmount, amount);
}
2014-08-13 10:51:37 +00:00
2015-05-27 12:08:46 +00:00
difficulty_type Currency::nextDifficulty(std::vector<uint64_t> timestamps,
std::vector<difficulty_type> cumulativeDifficulties) const {
assert(m_difficultyWindow >= 2);
2014-08-13 10:51:37 +00:00
2015-05-27 12:08:46 +00:00
if (timestamps.size() > m_difficultyWindow) {
timestamps.resize(m_difficultyWindow);
cumulativeDifficulties.resize(m_difficultyWindow);
}
2014-08-13 10:51:37 +00:00
2015-05-27 12:08:46 +00:00
size_t length = timestamps.size();
assert(length == cumulativeDifficulties.size());
assert(length <= m_difficultyWindow);
if (length <= 1) {
return 1;
}
2014-08-13 10:51:37 +00:00
2015-05-27 12:08:46 +00:00
sort(timestamps.begin(), timestamps.end());
2014-08-13 10:51:37 +00:00
2015-05-27 12:08:46 +00:00
size_t cutBegin, cutEnd;
assert(2 * m_difficultyCut <= m_difficultyWindow - 2);
if (length <= m_difficultyWindow - 2 * m_difficultyCut) {
cutBegin = 0;
cutEnd = length;
} else {
cutBegin = (length - (m_difficultyWindow - 2 * m_difficultyCut) + 1) / 2;
cutEnd = cutBegin + (m_difficultyWindow - 2 * m_difficultyCut);
}
assert(/*cut_begin >= 0 &&*/ cutBegin + 2 <= cutEnd && cutEnd <= length);
uint64_t timeSpan = timestamps[cutEnd - 1] - timestamps[cutBegin];
if (timeSpan == 0) {
timeSpan = 1;
}
2014-08-13 10:51:37 +00:00
2015-05-27 12:08:46 +00:00
difficulty_type totalWork = cumulativeDifficulties[cutEnd - 1] - cumulativeDifficulties[cutBegin];
assert(totalWork > 0);
uint64_t low, high;
low = mul128(totalWork, m_difficultyTarget, &high);
if (high != 0 || low + timeSpan - 1 < low) {
return 0;
2014-08-13 10:51:37 +00:00
}
2015-05-27 12:08:46 +00:00
return (low + timeSpan - 1) / timeSpan;
}
2014-08-13 10:51:37 +00:00
2015-05-27 12:08:46 +00:00
bool Currency::checkProofOfWorkV1(crypto::cn_context& context, const Block& block, difficulty_type currentDiffic,
crypto::hash& proofOfWork) const {
if (BLOCK_MAJOR_VERSION_1 != block.majorVersion) {
return false;
}
2014-08-13 10:51:37 +00:00
2015-05-27 12:08:46 +00:00
if (!get_block_longhash(context, block, proofOfWork)) {
return false;
2014-08-13 10:51:37 +00:00
}
2015-05-27 12:08:46 +00:00
return check_hash(proofOfWork, currentDiffic);
}
2014-08-13 10:51:37 +00:00
2015-05-27 12:08:46 +00:00
bool Currency::checkProofOfWorkV2(crypto::cn_context& context, const Block& block, difficulty_type currentDiffic,
crypto::hash& proofOfWork) const {
if (BLOCK_MAJOR_VERSION_2 != block.majorVersion) {
return false;
}
2014-08-13 10:51:37 +00:00
2015-05-27 12:08:46 +00:00
if (!get_block_longhash(context, block, proofOfWork)) {
return false;
}
2014-08-13 10:51:37 +00:00
2015-05-27 12:08:46 +00:00
if (!check_hash(proofOfWork, currentDiffic)) {
return false;
}
2014-08-13 10:51:37 +00:00
2015-05-27 12:08:46 +00:00
tx_extra_merge_mining_tag mmTag;
if (!get_mm_tag_from_extra(block.parentBlock.minerTx.extra, mmTag)) {
logger(ERROR) << "merge mining tag wasn't found in extra of the parent block miner transaction";
return false;
}
2014-08-13 10:51:37 +00:00
2015-05-27 12:08:46 +00:00
if (8 * sizeof(m_genesisBlockHash) < block.parentBlock.blockchainBranch.size()) {
return false;
}
2014-08-13 10:51:37 +00:00
2015-05-27 12:08:46 +00:00
crypto::hash auxBlockHeaderHash;
if (!get_aux_block_header_hash(block, auxBlockHeaderHash)) {
return false;
}
crypto::hash auxBlocksMerkleRoot;
crypto::tree_hash_from_branch(block.parentBlock.blockchainBranch.data(), block.parentBlock.blockchainBranch.size(),
auxBlockHeaderHash, &m_genesisBlockHash, auxBlocksMerkleRoot);
2014-08-13 10:51:37 +00:00
2015-05-27 12:08:46 +00:00
if (auxBlocksMerkleRoot != mmTag.merkle_root) {
logger(ERROR, BRIGHT_YELLOW) << "Aux block hash wasn't found in merkle tree";
return false;
2014-08-13 10:51:37 +00:00
}
2015-05-27 12:08:46 +00:00
return true;
}
2014-08-13 10:51:37 +00:00
2015-05-27 12:08:46 +00:00
bool Currency::checkProofOfWork(crypto::cn_context& context, const Block& block, difficulty_type currentDiffic, crypto::hash& proofOfWork) const {
switch (block.majorVersion) {
case BLOCK_MAJOR_VERSION_1: return checkProofOfWorkV1(context, block, currentDiffic, proofOfWork);
case BLOCK_MAJOR_VERSION_2: return checkProofOfWorkV2(context, block, currentDiffic, proofOfWork);
2014-08-13 10:51:37 +00:00
}
2015-05-27 12:08:46 +00:00
logger(ERROR, BRIGHT_RED) << "Unknown block major version: " << block.majorVersion << "." << block.minorVersion;
return false;
}
2014-08-13 10:51:37 +00:00
2015-05-27 12:08:46 +00:00
CurrencyBuilder::CurrencyBuilder(Logging::ILogger& log) : m_currency(log) {
maxBlockNumber(parameters::CRYPTONOTE_MAX_BLOCK_NUMBER);
maxBlockBlobSize(parameters::CRYPTONOTE_MAX_BLOCK_BLOB_SIZE);
maxTxSize(parameters::CRYPTONOTE_MAX_TX_SIZE);
publicAddressBase58Prefix(parameters::CRYPTONOTE_PUBLIC_ADDRESS_BASE58_PREFIX);
minedMoneyUnlockWindow(parameters::CRYPTONOTE_MINED_MONEY_UNLOCK_WINDOW);
2014-08-13 10:51:37 +00:00
2015-05-27 12:08:46 +00:00
timestampCheckWindow(parameters::BLOCKCHAIN_TIMESTAMP_CHECK_WINDOW);
blockFutureTimeLimit(parameters::CRYPTONOTE_BLOCK_FUTURE_TIME_LIMIT);
2014-08-13 10:51:37 +00:00
2015-05-27 12:08:46 +00:00
moneySupply(parameters::MONEY_SUPPLY);
emissionSpeedFactor(parameters::EMISSION_SPEED_FACTOR);
2014-08-13 10:51:37 +00:00
2015-05-27 12:08:46 +00:00
rewardBlocksWindow(parameters::CRYPTONOTE_REWARD_BLOCKS_WINDOW);
blockGrantedFullRewardZone(parameters::CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE);
minerTxBlobReservedSize(parameters::CRYPTONOTE_COINBASE_BLOB_RESERVED_SIZE);
2014-08-13 10:51:37 +00:00
2015-05-27 12:08:46 +00:00
numberOfDecimalPlaces(parameters::CRYPTONOTE_DISPLAY_DECIMAL_POINT);
2014-08-13 10:51:37 +00:00
2015-05-27 12:08:46 +00:00
mininumFee(parameters::MINIMUM_FEE);
defaultDustThreshold(parameters::DEFAULT_DUST_THRESHOLD);
2014-08-13 10:51:37 +00:00
2015-05-27 12:08:46 +00:00
difficultyTarget(parameters::DIFFICULTY_TARGET);
difficultyWindow(parameters::DIFFICULTY_WINDOW);
difficultyLag(parameters::DIFFICULTY_LAG);
difficultyCut(parameters::DIFFICULTY_CUT);
2014-08-13 10:51:37 +00:00
2015-05-27 12:08:46 +00:00
maxBlockSizeInitial(parameters::MAX_BLOCK_SIZE_INITIAL);
maxBlockSizeGrowthSpeedNumerator(parameters::MAX_BLOCK_SIZE_GROWTH_SPEED_NUMERATOR);
maxBlockSizeGrowthSpeedDenominator(parameters::MAX_BLOCK_SIZE_GROWTH_SPEED_DENOMINATOR);
2014-08-13 10:51:37 +00:00
2015-05-27 12:08:46 +00:00
lockedTxAllowedDeltaSeconds(parameters::CRYPTONOTE_LOCKED_TX_ALLOWED_DELTA_SECONDS);
lockedTxAllowedDeltaBlocks(parameters::CRYPTONOTE_LOCKED_TX_ALLOWED_DELTA_BLOCKS);
2014-08-13 10:51:37 +00:00
2015-05-27 12:08:46 +00:00
mempoolTxLiveTime(parameters::CRYPTONOTE_MEMPOOL_TX_LIVETIME);
mempoolTxFromAltBlockLiveTime(parameters::CRYPTONOTE_MEMPOOL_TX_FROM_ALT_BLOCK_LIVETIME);
2015-07-15 12:23:00 +00:00
numberOfPeriodsToForgetTxDeletedFromPool(parameters::CRYPTONOTE_NUMBER_OF_PERIODS_TO_FORGET_TX_DELETED_FROM_POOL);
2014-08-13 10:51:37 +00:00
2015-05-27 12:08:46 +00:00
upgradeHeight(parameters::UPGRADE_HEIGHT);
upgradeVotingThreshold(parameters::UPGRADE_VOTING_THRESHOLD);
upgradeVotingWindow(parameters::UPGRADE_VOTING_WINDOW);
upgradeWindow(parameters::UPGRADE_WINDOW);
2014-08-13 10:51:37 +00:00
2015-05-27 12:08:46 +00:00
blocksFileName(parameters::CRYPTONOTE_BLOCKS_FILENAME);
blocksCacheFileName(parameters::CRYPTONOTE_BLOCKSCACHE_FILENAME);
blockIndexesFileName(parameters::CRYPTONOTE_BLOCKINDEXES_FILENAME);
txPoolFileName(parameters::CRYPTONOTE_POOLDATA_FILENAME);
2014-08-13 10:51:37 +00:00
2015-05-27 12:08:46 +00:00
testnet(false);
}
2014-08-13 10:51:37 +00:00
2015-05-27 12:08:46 +00:00
CurrencyBuilder& CurrencyBuilder::emissionSpeedFactor(unsigned int val) {
if (val <= 0 || val > 8 * sizeof(uint64_t)) {
throw std::invalid_argument("val at emissionSpeedFactor()");
2014-08-13 10:51:37 +00:00
}
2015-05-27 12:08:46 +00:00
m_currency.m_emissionSpeedFactor = val;
return *this;
}
2014-08-13 10:51:37 +00:00
2015-05-27 12:08:46 +00:00
CurrencyBuilder& CurrencyBuilder::numberOfDecimalPlaces(size_t val) {
m_currency.m_numberOfDecimalPlaces = val;
m_currency.m_coin = 1;
for (size_t i = 0; i < m_currency.m_numberOfDecimalPlaces; ++i) {
m_currency.m_coin *= 10;
2014-08-13 10:51:37 +00:00
}
2015-05-27 12:08:46 +00:00
return *this;
}
CurrencyBuilder& CurrencyBuilder::difficultyWindow(size_t val) {
if (val < 2) {
throw std::invalid_argument("val at difficultyWindow()");
2014-08-13 10:51:37 +00:00
}
2015-05-27 12:08:46 +00:00
m_currency.m_difficultyWindow = val;
return *this;
}
2014-08-13 10:51:37 +00:00
2015-05-27 12:08:46 +00:00
CurrencyBuilder& CurrencyBuilder::upgradeVotingThreshold(unsigned int val) {
if (val <= 0 || val > 100) {
throw std::invalid_argument("val at upgradeVotingThreshold()");
2014-08-13 10:51:37 +00:00
}
2015-05-27 12:08:46 +00:00
m_currency.m_upgradeVotingThreshold = val;
return *this;
}
CurrencyBuilder& CurrencyBuilder::upgradeWindow(size_t val) {
if (val <= 0) {
throw std::invalid_argument("val at upgradeWindow()");
2014-08-13 10:51:37 +00:00
}
2015-05-27 12:08:46 +00:00
m_currency.m_upgradeWindow = val;
return *this;
}
2014-08-13 10:51:37 +00:00
}