Exemplo n.º 1
0
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;
}
Exemplo n.º 2
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;
}
Exemplo n.º 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;
}
Exemplo n.º 4
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;
}
Exemplo n.º 5
0
bool headers::from_data(reader& source)
{
    reset();

    uint64_t count = source.read_variable_uint_little_endian();
    auto result = static_cast<bool>(source);

    for (uint64_t i = 0; (i < count) && result; ++i)
    {
        elements.emplace_back();
        result = elements.back().from_data(source, true);
    }

    if (!result)
        reset();

    return result;
}
Exemplo n.º 6
0
bool block::from_data(reader& source)
{
    reset();
    auto result = header.from_data(source, false);

    if (result)
    {
        header.transaction_count = source.read_variable_uint_little_endian();
        result = source;
    }

    for (uint64_t i = 0; (i < header.transaction_count) && result; ++i)
    {
        transactions.emplace_back();
        result = transactions.back().from_data(source);
    }

    if (!result)
        reset();

    return result;
}
Exemplo n.º 7
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;
}