Example #1
0
void chainblender_join::encode(data_buffer & buffer)
{
    /**
     * Encode the version.
     */
    buffer.write_uint32(m_version);
    
    /**
     * The session id must be null for a cbjoin.
     */
    if (m_hash_session_id.is_empty() == false)
    {
        log_error(
            "ChainBlender join message has invalid hash session "
            "id = " << m_hash_session_id.to_string() << "."
        );
    }
    
    /**
     * Encode the session id.
     */
    buffer.write_sha256(m_hash_session_id);
    
    /**
     * Encode the denomination.
     */
    buffer.write_int64(m_denomination);
}
bool inventory_vector::encode(data_buffer & buffer)
{
    buffer.write_uint32(m_type);
    buffer.write_sha256(m_hash);
    
    return true;
}
void merkle_tree_partial::encode(data_buffer & buffer)
{
    buffer.write_uint32(m_total_transactions);
    buffer.write_var_int(m_hashes.size());
    
    for (auto & i : m_hashes)
    {
        buffer.write_sha256(i);
    }
    
    std::vector<std::uint8_t> bytes;
    
    bytes.resize((m_flags.size() + 7) / 8);
    
    for (auto i = 0; i < m_flags.size(); i++)
    {
        bytes[i / 8] |= m_flags[i] << (i % 8);
    }
    
    buffer.write_var_int(bytes.size());
    buffer.write_bytes(
        reinterpret_cast<const char *> (&bytes[0]), bytes.size()
    );
}
void checkpoint_sync_unsigned::encode(data_buffer & buffer)
{
    buffer.write_int32(m_version);
    buffer.write_sha256(m_hash_checkpoint);
}
Example #5
0
void incentive_vote::encode(data_buffer & buffer, const bool & is_copy)
{
    /**
     * Write the version.
     */
    buffer.write_uint32(m_version);
    
    /**
     * Write the block height.
     */
    buffer.write_uint32(m_block_height);
    
    /**
     * Write the block hash
     */
    buffer.write_sha256(m_hash_block);
    
    /**
     * Write the nonce hash.
     */
    buffer.write_sha256(m_hash_nonce);
    
    /**
     * Write the address length.
     */
    buffer.write_var_int(m_address.size());
    
    /**
     * Write the address.
     */
    buffer.write_bytes(m_address.data(), m_address.size());

    /**
     * Encode the public key.
     */
    m_public_key.encode(buffer);

    /**
     * If we are encoding a copy reuse the existing signature.
     */
    if (is_copy == true)
    {
        /**
         * Write the signature length.
         */
        buffer.write_var_int(m_signature.size());
        
        /**
         * Write the signature.
         */
        buffer.write_bytes(
            reinterpret_cast<char *>(&m_signature[0]),
            m_signature.size()
        );
    }
    else
    {
        /**
         * Sign the message.
         */
        sign(buffer);
    }
}