本文整理汇总了C++中data_chunk类的典型用法代码示例。如果您正苦于以下问题:C++ data_chunk类的具体用法?C++ data_chunk怎么用?C++ data_chunk使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了data_chunk类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: decode_base58
BCW_API bool hd_private_key::set_serialized(std::string encoded)
{
if (!is_base58(encoded))
return false;
const data_chunk decoded = decode_base58(encoded);
if (decoded.size() != serialized_length)
return false;
if (!verify_checksum(decoded))
return false;
auto ds = make_deserializer(decoded.begin(), decoded.end());
auto prefix = ds.read_big_endian<uint32_t>();
if (prefix != mainnet_private_prefix && prefix != testnet_private_prefix)
return false;
valid_ = true;
lineage_.testnet = prefix == testnet_private_prefix;
lineage_.depth = ds.read_byte();
lineage_.parent_fingerprint = ds.read_little_endian<uint32_t>();
lineage_.child_number = ds.read_big_endian<uint32_t>();
c_ = ds.read_bytes<chain_code_size>();
ds.read_byte();
k_ = ds.read_bytes<ec_secret_size>();
K_ = secret_to_public_key(k_);
return true;
}
示例2: parse_script
script parse_script(const data_chunk& raw_script)
{
script script_object;
for (auto it = raw_script.begin(); it != raw_script.end(); ++it)
{
byte raw_byte = *it;
operation op;
op.code = static_cast<opcode>(raw_byte);
// raw_byte is unsigned so it's always >= 0
if (raw_byte <= 75)
op.code = opcode::special;
size_t read_n_bytes = number_of_bytes_from_opcode(op.code, raw_byte);
for (size_t byte_count = 0; byte_count < read_n_bytes; ++byte_count)
{
++it;
if (it == raw_script.cend())
{
log_warning() << "Premature end of script.";
return script();
}
op.data.push_back(*it);
}
script_object.push_operation(op);
}
return script_object;
}
示例3: message
BC_API void obelisk_codec::message(const data_chunk& data, bool more)
{
switch (next_part_)
{
case command_part:
wip_message_.command = std::string(data.begin(), data.end());
break;
case id_part:
if (4 != data.size())
{
next_part_ = error_part;
break;
}
wip_message_.id = from_little_endian<uint32_t>(data.begin(), data.end());
break;
case payload_part:
wip_message_.payload = data;
break;
case error_part:
break;
}
if (!more)
{
if (next_part_ == payload_part)
receive(wip_message_);
else
on_unknown_(wip_message_.command);
next_part_ = command_part;
}
else if (next_part_ < error_part)
next_part_ = static_cast<message_part>(next_part_ + 1);
}
示例4: encode_base58
std::string encode_base58(const data_chunk& unencoded)
{
size_t leading_zeros = count_leading_zeros(unencoded);
// size = log(256) / log(58), rounded up.
const size_t number_nonzero = unencoded.size() - leading_zeros;
const size_t indexes_size = number_nonzero * 138 / 100 + 1;
// Allocate enough space in big-endian base58 representation.
data_chunk indexes(indexes_size);
// Process the bytes.
for (auto it = unencoded.begin() + leading_zeros;
it != unencoded.end(); ++it)
{
pack_value(indexes, *it);
}
// Skip leading zeroes in base58 result.
auto first_nonzero = search_first_nonzero(indexes);
// Translate the result into a string.
std::string encoded;
const size_t estimated_size =
leading_zeros + (indexes.end() - first_nonzero);
encoded.reserve(estimated_size);
encoded.assign(leading_zeros, '1');
// Set actual main bytes.
for (auto it = first_nonzero; it != indexes.end(); ++it)
{
const size_t index = *it;
encoded += base58_chars[index];
}
return encoded;
}
示例5: wrap_fetch_transaction_args
void wrap_fetch_transaction_args(data_chunk& data, const hash_digest& tx_hash)
{
data.resize(hash_digest_size);
auto serial = make_serializer(data.begin());
serial.write_hash(tx_hash);
BITCOIN_ASSERT(serial.iterator() == data.end());
}
示例6: BITCOIN_ASSERT
bool validate_block::coinbase_height_match()
{
// There are old blocks with version incorrectly set to 2. Ignore them.
if (height_ < max_version1_height)
return true;
// Checks whether the block height is in the coinbase tx input script.
// Version 2 blocks and onwards.
BITCOIN_ASSERT(current_block_.header.version >= 2);
BITCOIN_ASSERT(current_block_.transactions.size() > 0);
BITCOIN_ASSERT(current_block_.transactions[0].inputs.size() > 0);
// First get the serialized coinbase input script as a series of bytes.
const auto& coinbase_tx = current_block_.transactions[0];
const auto& coinbase_script = coinbase_tx.inputs[0].script;
const auto raw_coinbase = save_script(coinbase_script);
// Try to recreate the expected bytes.
script_type expect_coinbase;
script_number expect_number(height_);
expect_coinbase.push_operation({opcode::special, expect_number.data()});
// Save the expected coinbase script.
const data_chunk expect = save_script(expect_coinbase);
// Perform comparison of the first bytes with raw_coinbase.
BITCOIN_ASSERT(expect.size() <= raw_coinbase.size());
return std::equal(expect.begin(), expect.end(), raw_coinbase.begin());
}
示例7: doWrite
unsigned int BIO::doWrite(const data_chunk& data_to_write, int offset) const
{
int written = 0;
int num2wr = data_to_write.size() - offset;
assert(num2wr > 0);
DBG << "Writing " << num2wr << "B - " << Utils::DataToString(data_to_write)
<< std::endl;
if (num2wr == 0) {
return 0;
}
for (;;) {
written = BIO_write(itsBIO, &data_to_write.at(offset), num2wr);
if (written <= 0) {
if (this->ShouldRetry()) {
std::string s("Recoverable error when writing to BIO");
if ((errno == EAGAIN) || (errno == EWOULDBLOCK)) {
throw RecoverableException(s);
}
}
std::string s("Fatal error when writing to BIO; ");
s += Utils::getLastErrorSSL();
throw RemoteDiedException(s);
}
break;
}
DBG << "Written " << written << "B" << std::endl;
return written;
}
示例8: decode_base85
// Accepts only strings bounded to 5 characters.
bool decode_base85(data_chunk& out, const std::string& in)
{
const size_t length = in.size();
if (length % 5 != 0)
return false;
const size_t decoded_size = length * 4 / 5;
data_chunk decoded;
decoded.reserve(decoded_size);
size_t char_index = 0;
uint32_t accumulator = 0;
for (const uint8_t encoded_character: in)
{
const auto position = encoded_character - 32;
if (position < 0 || position > 96)
return false;
accumulator = accumulator * 85 + decoder[position];
if (++char_index % 5 == 0)
{
for (uint32_t divise = 256 * 256 * 256; divise > 0; divise /= 256)
decoded.push_back(accumulator / divise % 256);
accumulator = 0;
}
}
out.assign(decoded.begin(), decoded.end());
BITCOIN_ASSERT(out.size() == decoded_size);
return true;
}
示例9: read_ephemkey
data_chunk read_ephemkey(const data_chunk& stealth_data)
{
// Read ephemkey
BITCOIN_ASSERT(stealth_data.size() == 1 + 4 + 33);
data_chunk ephemkey(stealth_data.begin() + 5, stealth_data.end());
BITCOIN_ASSERT(ephemkey.size() == 33);
return ephemkey;
}
示例10: hmac_sha512_hash
long_hash hmac_sha512_hash(const data_chunk& chunk,
const data_chunk& key)
{
long_hash hash;
HMACSHA512(chunk.data(), chunk.size(), key.data(),
key.size(), hash.data());
return hash;
}
示例11: single_sha512_hash
long_hash single_sha512_hash(const data_chunk& chunk)
{
long_hash digest;
SHA512_CTX ctx;
SHA512_Init(&ctx);
SHA512_Update(&ctx, chunk.data(), chunk.size());
SHA512_Final(digest.data(), &ctx);
return digest;
}
示例12: VerifyChecksum
bool VerifyChecksum(const data_chunk& data)
{
if (data.size() < 4)
return false;
uint32_t checksum = from_little_endian<uint32_t>(data.end() - 4);
return BitcoinChecksum((uint8_t*)&data[0], data.size()-4) == checksum;
};
示例13: Write
void BIO::Write(const data_chunk& data2wr) const
{
unsigned int written = 0;
do {
data_chunk tmp;
tmp.insert(tmp.end(), data2wr.begin() + written, data2wr.end());
written += doWrite(tmp, written);
} while(written < data2wr.size());
}
示例14: read_hash
bool read_hash(hash_digest& hash, const data_chunk& raw_hash)
{
if (raw_hash.size() != hash.size())
{
log_warning(LOG_SUBSCRIBER) << "Wrong size for hash. Dropping.";
return false;
}
std::copy(raw_hash.begin(), raw_hash.end(), hash.begin());
return true;
}
示例15: bitcoin_short_hash
short_hash bitcoin_short_hash(const data_chunk& chunk)
{
hash_digest sha_hash;
SHA256__(chunk.data(), chunk.size(), sha_hash.data());
short_hash ripemd_hash;
RMD160(sha_hash.data(), sha_hash.size(), ripemd_hash.data());
return ripemd_hash;
}