本文整理汇总了C++中data_chunk类的典型用法代码示例。如果您正苦于以下问题:C++ data_chunk类的具体用法?C++ data_chunk怎么用?C++ data_chunk使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了data_chunk类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
}
开发者ID:BWallet,项目名称:libwallet,代码行数:26,代码来源:hd_keys.cpp
示例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;
}
开发者ID:arorts,项目名称:libbitcoin,代码行数:29,代码来源:script.cpp
示例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);
}
开发者ID:BitcoinKinetics,项目名称:airbitz-core,代码行数:35,代码来源:obelisk_codec.cpp
示例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;
}
开发者ID:ballisticwhisper,项目名称:decentralised,代码行数:34,代码来源:base58.cpp
示例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());
}
开发者ID:grazcoin,项目名称:obelisk,代码行数:7,代码来源:fetch_x.cpp
示例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());
}
开发者ID:reklaim,项目名称:libbitcoin-blockchain,代码行数:29,代码来源:validate_block.cpp
示例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;
}
开发者ID:nazgee,项目名称:libosock,代码行数:31,代码来源:BIO.cpp
示例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;
}
开发者ID:Mrkebubun,项目名称:libbitcoin,代码行数:33,代码来源:base85.cpp
示例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;
}
开发者ID:kaostao,项目名称:libbitcoin,代码行数:8,代码来源:leveldb_common.cpp
示例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;
}
开发者ID:keystore00,项目名称:libbitcoin,代码行数:8,代码来源:hash.cpp
示例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;
}
开发者ID:bitkevin,项目名称:libbitcoin,代码行数:9,代码来源:hmac512.cpp
示例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;
};
开发者ID:TheBitcoin,项目名称:Feathercoin2,代码行数:9,代码来源:stealth.cpp
示例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());
}
开发者ID:nazgee,项目名称:libosock,代码行数:9,代码来源:BIO.cpp
示例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;
}
开发者ID:grazcoin,项目名称:obelisk,代码行数:10,代码来源:interface.cpp
示例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;
}
开发者ID:keystore00,项目名称:libbitcoin,代码行数:10,代码来源:hash.cpp
示例16: unpack_char
void unpack_char(data_chunk& data, int carry)
{
for (auto it = data.rbegin(); it != data.rend(); it++)
{
carry += 58 * (*it);
*it = carry % 256;
carry /= 256;
}
BITCOIN_ASSERT(carry == 0);
}
开发者ID:ballisticwhisper,项目名称:decentralised,代码行数:10,代码来源:base58.cpp
示例17: wrap_fetch_history_args
void wrap_fetch_history_args(data_chunk& data,
const payment_address& address, size_t from_height)
{
data.resize(1 + short_hash_size + 4);
auto serial = make_serializer(data.begin());
serial.write_byte(address.version());
serial.write_short_hash(address.hash());
serial.write_4_bytes(from_height);
BITCOIN_ASSERT(serial.iterator() == data.end());
}
开发者ID:grazcoin,项目名称:obelisk,代码行数:10,代码来源:fetch_x.cpp
示例18: get_record
record_type get_record(htdb_record_header& header, record_allocator& alloc,
const data_chunk& key_data)
{
typedef byte_array<N> hash_type;
htdb_record<hash_type> ht(header, alloc, "test");
hash_type key;
BITCOIN_ASSERT(key.size() == key_data.size());
std::copy(key_data.begin(), key_data.end(), key.begin());
return ht.get(key);
}
开发者ID:Belxjander,项目名称:Kirito,代码行数:10,代码来源:read_htdb_record_value.cpp
示例19: parse_token
bool parse_token(data_chunk& raw_script, std::string token)
{
boost::algorithm::trim(token);
// skip this
if (token.empty())
return true;
static data_chunk hex_raw;
if (token == "ENDING" || !is_hex_data(token))
{
if (!hex_raw.empty())
{
extend_data(raw_script, hex_raw);
hex_raw.resize(0);
}
}
if (token == "ENDING")
{
// Do nothing...
}
else if (is_number(token))
{
int64_t value = boost::lexical_cast<int64_t>(token);
if (is_opx(value))
push_literal(raw_script, value);
else
{
script_number bignum(value);
push_data(raw_script, bignum.data());
}
}
else if (is_hex_data(token))
{
std::string hex_part(token.begin() + 2, token.end());
data_chunk raw_data;
if (!decode_base16(raw_data, hex_part))
return false;
extend_data(hex_raw, raw_data);
}
else if (is_quoted_string(token))
{
data_chunk inner_value(token.begin() + 1, token.end() - 1);
push_data(raw_script, inner_value);
}
else if (is_opcode(token))
{
opcode tokenized_opcode = token_to_opcode(token);
raw_script.push_back(static_cast<uint8_t>(tokenized_opcode));
}
else
{
log_error() << "Token parsing failed with: " << token;
return false;
}
return true;
}
开发者ID:genjix,项目名称:libbitcoin,代码行数:55,代码来源:script.cpp
示例20: set_public_key
bool elliptic_curve_key::set_public_key(const data_chunk& pubkey)
{
if (!initialize())
return false;
const unsigned char* pubkey_bytes = pubkey.data();
if (!o2i_ECPublicKey(&key_, &pubkey_bytes, pubkey.size()))
return false;
if (pubkey.size() == 33)
use_compressed();
return true;
}
开发者ID:ballisticwhisper,项目名称:decentralised,代码行数:11,代码来源:elliptic_curve_key.cpp
注:本文中的data_chunk类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论