コード例 #1
0
ファイル: alert.cpp プロジェクト: GeopaymeEE/libbitcoin
bool alert::from_data(reader& source)
{
    reset();

    auto size = source.read_variable_uint_little_endian();
    BITCOIN_ASSERT(size <= bc::max_size_t);
    const auto payload_size = static_cast<size_t>(size);
    size_t signature_size = 0;
    auto result = static_cast<bool>(source);

    if (result)
    {
        payload = source.read_data(payload_size);
        result = source && (payload.size() == payload_size);
    }

    if (result)
    {
        size = source.read_variable_uint_little_endian();
        BITCOIN_ASSERT(size <= bc::max_size_t);
        signature_size = static_cast<size_t>(size);
        result = source;
    }

    if (result)
    {
        signature = source.read_data(signature_size);
        result = source && (signature.size() == signature_size);
    }

    if (!result)
        reset();

    return result;
}
コード例 #2
0
ファイル: operation.cpp プロジェクト: zauguin/libbitcoin
bool operation::from_data(reader& source)
{
    reset();
    const auto byte = source.read_byte();
    auto result = static_cast<bool>(source);

    auto op_code = static_cast<opcode>(byte);
    if (byte == 0 && op_code != opcode::zero)
        return false;

    code = ((0 < byte && byte <= 75) ? opcode::special : op_code);

    if (operation::must_read_data(code))
    {
        uint32_t size;
        read_opcode_data_size(size, code, byte, source);
        data = source.read_data(size);
        result = (source && (data.size() == size));

    }

    if (!result)
        reset();

    return result;
}
コード例 #3
0
bool merkle_block::from_data(reader& source)
{
    reset();

    bool result = header.from_data(source, true);
    uint64_t hash_count = 0;

    if (result)
    {
        hash_count = source.read_variable_uint_little_endian();
        result = source;
    }

    for (uint64_t i = 0; (i < hash_count) && result; ++i)
    {
        hashes.push_back(source.read_hash());
        result = source;
    }

    if (result)
    {
        auto size = source.read_variable_uint_little_endian();
        BITCOIN_ASSERT(size <= bc::max_size_t);
        const auto flag_count = static_cast<size_t>(size);
        flags = source.read_data(flag_count);
        result = source && (flags.size() == flag_count);
    }

    if (!result)
        reset();

    return result;
}
コード例 #4
0
bool filter_load::from_data(reader& source)
{
    bool result = false;

    reset();

    uint64_t filter_size = source.read_variable_uint_little_endian();
    result = source;

    if (result)
    {
        filter = source.read_data(filter_size);
        hash_functions = source.read_4_bytes_little_endian();
        tweak = source.read_4_bytes_little_endian();
        flags = source.read_byte();
        result = source && (filter.size() == filter_size);
    }

    if (!result)
        reset();

    return result;
}