示例#1
0
bool version::from_data(reader& source)
{
    reset();
    value = source.read_4_bytes_little_endian();
    services = source.read_8_bytes_little_endian();
    timestamp = source.read_8_bytes_little_endian();
    auto result = static_cast<bool>(source);
    if (result)
        result = address_me.from_data(source, false);

    if (result && (value >= 106))
    {
        result = address_you.from_data(source, false);
        nonce = source.read_8_bytes_little_endian();
        user_agent = source.read_string();
        if (value >= 209)
            start_height = source.read_4_bytes_little_endian();

        // The satoshi client treats 209 as the "initial protocol version"
        // and disconnects peers below 31800 (for getheaders support).
        if (value >= 70001)
            relay = (source.read_byte() != 0);

        result &= source;
    }

    if (!result)
        reset();

    return result;
}
示例#2
0
// Optimize reads by short-circuiting what is unnecessary.
// Invalid returns are conflated with skipped, but are store only.
bool stealth_record::from_data(reader& source, size_t start_height,
    const binary& filter)
{
    height_ = source.read_4_bytes_little_endian();

    if (height_ < start_height)
    {
        reset();
        source.skip(serialized_size(false) - sizeof(uint32_t));
        return false;
    }

    prefix_ = source.read_4_bytes_little_endian();

    if (!filter.is_prefix_of(prefix_))
    {
        reset();
        source.skip(serialized_size(false) - 2 * sizeof(uint32_t));
        return false;
    }

    unsigned_ephemeral_ = source.read_hash();
    public_key_hash_ = source.read_short_hash();
    transaction_hash_ = source.read_hash();

    if (!source)
        reset();

    return source;
}
// Avoid point reuse due to affect on store tx serialization.
bool payment_record::from_data(reader& source, bool wire)
{
    valid_ = true;
    output_ = (source.read_byte() == 1);

    if (wire)
    {
        height_ = source.read_4_bytes_little_endian();
        link_ = unlinked;
        hash_ = source.read_hash();
        index_ = source.read_4_bytes_little_endian();
    }
    else
    {
        height_ = 0;
        link_ = source.read_8_bytes_little_endian();
        hash_ = null_hash;
        index_ = source.read_2_bytes_little_endian();

        // Convert 16 bit sentinel to 32 bit sentinel.
        if (index_ == max_uint16)
            index_ = point::null_index;
    }

    data_ = source.read_8_bytes_little_endian();

    if (!source)
        reset();

    return source;
}
示例#4
0
bool heading::from_data(reader& source)
{
    reset();
    magic = source.read_4_bytes_little_endian();
    command = source.read_fixed_string(command_size);
    payload_size = source.read_4_bytes_little_endian();
    checksum = source.read_4_bytes_little_endian();
    if (!source)
        reset();

    return source;
}
示例#5
0
bool point::from_data(reader& source, bool wire)
{
    reset();

    valid_ = true;
    hash_ = source.read_hash();

    if (wire)
    {
        index_ = source.read_4_bytes_little_endian();
    }
    else
    {
        index_ = source.read_2_bytes_little_endian();

        // Convert 16 bit sentinel to 32 bit sentinel.
        if (index_ == max_uint16)
            index_ = null_index;
    }

    if (!source)
        reset();

    return source;
}
示例#6
0
bool transaction::from_data(reader& source)
{
    auto result = true;
    reset();
    version = source.read_4_bytes_little_endian();
    result = source;

    if (result)
    {
        uint64_t tx_in_count = source.read_variable_uint_little_endian();
        result = source;

        for (uint64_t i = 0; (i < tx_in_count) && result; ++i)
        {
            inputs.emplace_back();
            result = inputs.back().from_data(source);
        }
    }

    if (result)
    {
        auto tx_out_count = source.read_variable_uint_little_endian();
        result = source;

        for (uint64_t i = 0; (i < tx_out_count) && result; ++i)
        {
            outputs.emplace_back();
            result = outputs.back().from_data(source);
        }
    }

    if (result)
    {
        locktime = source.read_4_bytes_little_endian();
        result = source;
    }

    if (!result)
        reset();

    return result;
}
示例#7
0
bool point::from_data(reader& source)
{
    auto result = true;
    reset();
    hash = source.read_hash();
    index = source.read_4_bytes_little_endian();
    result = source;
    if (!result)
        reset();

    return result;
}
示例#8
0
bool alert_payload::from_data(reader& source)
{
    reset();

    version = source.read_4_bytes_little_endian();
    relay_until = source.read_8_bytes_little_endian();
    expiration = source.read_8_bytes_little_endian();
    id = source.read_4_bytes_little_endian();
    cancel = source.read_4_bytes_little_endian();

    uint64_t set_cancel_size = source.read_variable_uint_little_endian();
    for (uint64_t i = 0; i < set_cancel_size && source; i++)
        set_cancel.push_back(source.read_4_bytes_little_endian());

    min_version = source.read_4_bytes_little_endian();
    max_version = source.read_4_bytes_little_endian();

    uint64_t set_sub_version_size = source.read_variable_uint_little_endian();
    for (uint64_t i = 0; i < set_sub_version_size && source; i++)
        set_sub_version.push_back(source.read_string());

    priority = source.read_4_bytes_little_endian();
    comment = source.read_string();
    status_bar = source.read_string();
    reserved = source.read_string();

    if (!source)
        reset();

    return source;
}
示例#9
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;
}
示例#10
0
bool operation::read_opcode_data_size(uint32_t& count, opcode code,
    uint8_t raw_byte, reader& source)
{
    switch (code)
    {
        case opcode::special:
            count = raw_byte;
            return true;
        case opcode::pushdata1:
            count = source.read_byte();
            return true;
        case opcode::pushdata2:
            count = source.read_2_bytes_little_endian();
            return true;
        case opcode::pushdata4:
            count = source.read_4_bytes_little_endian();
            return true;
        default:
            return false;
    }
}