本文整理汇总了C++中BinaryArray::empty方法的典型用法代码示例。如果您正苦于以下问题:C++ BinaryArray::empty方法的具体用法?C++ BinaryArray::empty怎么用?C++ BinaryArray::empty使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BinaryArray
的用法示例。
在下文中一共展示了BinaryArray::empty方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: constructMinerTx
bool Currency::constructMinerTx(uint32_t height, size_t medianSize, uint64_t alreadyGeneratedCoins, size_t currentBlockSize,
uint64_t fee, const AccountPublicAddress& minerAddress, Transaction& tx,
const BinaryArray& extraNonce/* = BinaryArray()*/, size_t maxOuts/* = 1*/) const {
tx.inputs.clear();
tx.outputs.clear();
tx.extra.clear();
KeyPair txkey = generateKeyPair();
addTransactionPublicKeyToExtra(tx.extra, txkey.publicKey);
if (!extraNonce.empty()) {
if (!addExtraNonceToTransactionExtra(tx.extra, extraNonce)) {
return false;
}
}
BaseInput in;
in.blockIndex = height;
uint64_t blockReward;
int64_t emissionChange;
if (!getBlockReward(medianSize, currentBlockSize, alreadyGeneratedCoins, fee, height, blockReward, emissionChange)) {
logger(INFO) << "Block is too big";
return false;
}
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); });
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::KeyDerivation derivation = boost::value_initialized<Crypto::KeyDerivation>();
Crypto::PublicKey outEphemeralPubKey = boost::value_initialized<Crypto::PublicKey>();
bool r = Crypto::generate_key_derivation(minerAddress.viewPublicKey, txkey.secretKey, derivation);
if (!(r)) {
logger(ERROR, BRIGHT_RED)
<< "while creating outs: failed to generate_key_derivation("
<< minerAddress.viewPublicKey << ", " << txkey.secretKey << ")";
return false;
}
r = Crypto::derive_public_key(derivation, no, minerAddress.spendPublicKey, outEphemeralPubKey);
if (!(r)) {
logger(ERROR, BRIGHT_RED)
<< "while creating outs: failed to derive_public_key("
<< derivation << ", " << no << ", "
<< minerAddress.spendPublicKey << ")";
return false;
}
KeyOutput tk;
tk.key = outEphemeralPubKey;
TransactionOutput out;
summaryAmounts += out.amount = outAmounts[no];
out.target = tk;
tx.outputs.push_back(out);
}
if (!(summaryAmounts == blockReward)) {
logger(ERROR, BRIGHT_RED) << "Failed to construct miner tx, summaryAmounts = " << summaryAmounts << " not equal blockReward = " << blockReward;
return false;
}
tx.version = TRANSACTION_VERSION_1;
//lock
tx.unlockTime = height + m_minedMoneyUnlockWindow;
tx.inputs.push_back(in);
return true;
}