本文整理汇总了C++中BinaryArray类的典型用法代码示例。如果您正苦于以下问题:C++ BinaryArray类的具体用法?C++ BinaryArray怎么用?C++ BinaryArray使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了BinaryArray类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: on_get_transactions
bool RpcServer::on_get_transactions(const COMMAND_RPC_GET_TRANSACTIONS::request& req, COMMAND_RPC_GET_TRANSACTIONS::response& res) {
std::vector<Hash> vh;
for (const auto& tx_hex_str : req.txs_hashes) {
BinaryArray b;
if (!fromHex(tx_hex_str, b))
{
res.status = "Failed to parse hex representation of transaction hash";
return true;
}
if (b.size() != sizeof(Hash))
{
res.status = "Failed, size of data mismatch";
}
vh.push_back(*reinterpret_cast<const Hash*>(b.data()));
}
std::list<Hash> missed_txs;
std::list<Transaction> txs;
m_core.getTransactions(vh, txs, missed_txs);
for (auto& tx : txs) {
res.txs_as_hex.push_back(toHex(toBinaryArray(tx)));
}
for (const auto& miss_tx : missed_txs) {
res.missed_tx.push_back(Common::podToHex(miss_tx));
}
res.status = CORE_RPC_STATUS_OK;
return true;
}
示例2: readCommand
bool LevinProtocol::readCommand(Command& cmd) {
bucket_head2 head = { 0 };
if (!readStrict(reinterpret_cast<uint8_t*>(&head), sizeof(head))) {
return false;
}
if (head.m_signature != LEVIN_SIGNATURE) {
throw std::runtime_error("Levin signature mismatch");
}
if (head.m_cb > LEVIN_DEFAULT_MAX_PACKET_SIZE) {
throw std::runtime_error("Levin packet size is too big");
}
BinaryArray buf;
if (head.m_cb != 0) {
buf.resize(head.m_cb);
if (!readStrict(&buf[0], head.m_cb)) {
return false;
}
}
cmd.command = head.m_command;
cmd.buf = std::move(buf);
cmd.isNotify = !head.m_have_to_return_data;
cmd.isResponse = (head.m_flags & LEVIN_PACKET_RESPONSE) == LEVIN_PACKET_RESPONSE;
return true;
}
示例3: prepareAndSubmitBlock
bool BaseFunctionalTests::prepareAndSubmitBlock(TestNode& node, CryptoNote::Block&& blockTemplate) {
blockTemplate.timestamp = m_nextTimestamp;
m_nextTimestamp += 2 * m_currency.difficultyTarget();
BinaryArray blockBlob = CryptoNote::toBinaryArray(blockTemplate);
return node.submitBlock(::Common::toHex(blockBlob.data(), blockBlob.size()));
}
示例4: appendMergeMiningTagToExtra
bool appendMergeMiningTagToExtra(std::vector<uint8_t>& tx_extra, const TransactionExtraMergeMiningTag& mm_tag) {
BinaryArray blob;
if (!toBinaryArray(mm_tag, blob)) {
return false;
}
tx_extra.push_back(TX_EXTRA_MERGE_MINING_TAG);
std::copy(reinterpret_cast<const uint8_t*>(blob.data()), reinterpret_cast<const uint8_t*>(blob.data() + blob.size()), std::back_inserter(tx_extra));
return true;
}
示例5: parseAndValidateTransactionFromBinaryArray
bool parseAndValidateTransactionFromBinaryArray(const BinaryArray& tx_blob, Transaction& tx, Hash& tx_hash, Hash& tx_prefix_hash) {
if (!fromBinaryArray(tx, tx_blob)) {
return false;
}
//TODO: validate tx
cn_fast_hash(tx_blob.data(), tx_blob.size(), tx_hash);
getObjectHash(*static_cast<TransactionPrefix*>(&tx), tx_prefix_hash);
return true;
}
示例6: get_block_hashing_blob
bool get_block_hashing_blob(const Block& b, BinaryArray& ba) {
if (!toBinaryArray(static_cast<const BlockHeader&>(b), ba)) {
return false;
}
Hash treeRootHash = get_tx_tree_hash(b);
ba.insert(ba.end(), treeRootHash.data, treeRootHash.data + 32);
auto transactionCount = asBinaryArray(Tools::get_varint_data(b.transactionHashes.size() + 1));
ba.insert(ba.end(), transactionCount.begin(), transactionCount.end());
return true;
}
示例7: append_message_to_extra
bool append_message_to_extra(std::vector<uint8_t>& tx_extra, const tx_extra_message& message) {
BinaryArray blob;
if (!toBinaryArray(message, blob)) {
return false;
}
tx_extra.reserve(tx_extra.size() + 1 + blob.size());
tx_extra.push_back(TX_EXTRA_MESSAGE_TAG);
std::copy(reinterpret_cast<const uint8_t*>(blob.data()), reinterpret_cast<const uint8_t*>(blob.data() + blob.size()), std::back_inserter(tx_extra));
return true;
}
示例8: getBlockHashingBinaryArray
const Crypto::Hash& CachedBlock::getBlockHash() const {
if (!blockHash.is_initialized()) {
BinaryArray blockBinaryArray = getBlockHashingBinaryArray();
if (BLOCK_MAJOR_VERSION_2 <= block.majorVersion) {
const auto& parentBlock = getParentBlockHashingBinaryArray(false);
blockBinaryArray.insert(blockBinaryArray.end(), parentBlock.begin(), parentBlock.end());
}
blockHash = getObjectHash(blockBinaryArray);
}
return blockHash.get();
}
示例9: get_block_longhash
bool get_block_longhash(cn_context &context, const Block& b, Hash& res) {
BinaryArray bd;
if (b.majorVersion == BLOCK_MAJOR_VERSION_1 || b.majorVersion >= BLOCK_MAJOR_VERSION_4) {
if (!get_block_hashing_blob(b, bd)) {
return false;
}
} else if (b.majorVersion == BLOCK_MAJOR_VERSION_2 || b.majorVersion == BLOCK_MAJOR_VERSION_3) {
if (!get_parent_block_hashing_blob(b, bd)) {
return false;
}
} else {
return false;
}
cn_slow_hash(context, bd.data(), bd.size(), res);
return true;
}
示例10: addExtraNonceToTransactionExtra
bool addExtraNonceToTransactionExtra(std::vector<uint8_t>& tx_extra, const BinaryArray& extra_nonce) {
if (extra_nonce.size() > TX_EXTRA_NONCE_MAX_COUNT) {
return false;
}
size_t start_pos = tx_extra.size();
tx_extra.resize(tx_extra.size() + 2 + extra_nonce.size());
//write tag
tx_extra[start_pos] = TX_EXTRA_NONCE;
//write len
++start_pos;
tx_extra[start_pos] = static_cast<uint8_t>(extra_nonce.size());
//write data
++start_pos;
memcpy(&tx_extra[start_pos], extra_nonce.data(), extra_nonce.size());
return true;
}
示例11: get_block_hash
bool get_block_hash(const Block& b, Hash& res) {
BinaryArray ba;
if (!get_block_hashing_blob(b, ba)) {
return false;
}
// The header of block version 1 differs from headers of blocks starting from v.2
if (BLOCK_MAJOR_VERSION_2 == b.majorVersion || BLOCK_MAJOR_VERSION_3 == b.majorVersion) {
BinaryArray parent_blob;
auto serializer = makeParentBlockSerializer(b, true, false);
if (!toBinaryArray(serializer, parent_blob))
return false;
ba.insert(ba.end(), parent_blob.begin(), parent_blob.end());
}
return getObjectHash(ba, res);
}
示例12: prepareAndSubmitBlock
bool BaseFunctionalTests::prepareAndSubmitBlock(TestNode& node, CryptoNote::Block&& blockTemplate) {
blockTemplate.timestamp = m_nextTimestamp;
m_nextTimestamp += 2 * m_currency.difficultyTarget();
if (blockTemplate.majorVersion >= BLOCK_MAJOR_VERSION_2) {
blockTemplate.parentBlock.majorVersion = BLOCK_MAJOR_VERSION_1;
blockTemplate.parentBlock.minorVersion = BLOCK_MINOR_VERSION_0;
blockTemplate.parentBlock.transactionCount = 1;
CryptoNote::TransactionExtraMergeMiningTag mmTag;
mmTag.depth = 0;
if (!CryptoNote::get_aux_block_header_hash(blockTemplate, mmTag.merkleRoot)) {
return false;
}
blockTemplate.parentBlock.baseTransaction.extra.clear();
if (!CryptoNote::appendMergeMiningTagToExtra(blockTemplate.parentBlock.baseTransaction.extra, mmTag)) {
return false;
}
}
BinaryArray blockBlob = CryptoNote::toBinaryArray(blockTemplate);
return node.submitBlock(::Common::toHex(blockBlob.data(), blockBlob.size()));
}
示例13: sendReply
void LevinProtocol::sendReply(uint32_t command, const BinaryArray& out, int32_t returnCode) {
bucket_head2 head = { 0 };
head.m_signature = LEVIN_SIGNATURE;
head.m_cb = out.size();
head.m_have_to_return_data = false;
head.m_command = command;
head.m_protocol_version = LEVIN_PROTOCOL_VER_1;
head.m_flags = LEVIN_PACKET_RESPONSE;
head.m_return_code = returnCode;
BinaryArray writeBuffer;
writeBuffer.reserve(sizeof(head) + out.size());
Common::VectorOutputStream stream(writeBuffer);
stream.writeSome(&head, sizeof(head));
stream.writeSome(out.data(), out.size());
writeStrict(writeBuffer.data(), writeBuffer.size());
}
示例14: sendMessage
void LevinProtocol::sendMessage(uint32_t command, const BinaryArray& out, bool needResponse) {
bucket_head2 head = { 0 };
head.m_signature = LEVIN_SIGNATURE;
head.m_cb = out.size();
head.m_have_to_return_data = needResponse;
head.m_command = command;
head.m_protocol_version = LEVIN_PROTOCOL_VER_1;
head.m_flags = LEVIN_PACKET_REQUEST;
// write header and body in one operation
BinaryArray writeBuffer;
writeBuffer.reserve(sizeof(head) + out.size());
Common::VectorOutputStream stream(writeBuffer);
stream.writeSome(&head, sizeof(head));
stream.writeSome(out.data(), out.size());
writeStrict(writeBuffer.data(), writeBuffer.size());
}
示例15: getBinaryArrayHash
void getBinaryArrayHash(const BinaryArray& binaryArray, Crypto::Hash& hash) {
cn_fast_hash(binaryArray.data(), binaryArray.size(), hash);
}