예제 #1
0
void hd_configuration::encode(data_buffer & buffer) const
{
    assert(m_id_key_master.digest().size() == ripemd160::digest_length);
    buffer.write_uint32(m_version);
    buffer.write_uint32(m_index);
    buffer.write_bytes(
        reinterpret_cast<const char *> (&m_id_key_master.digest()[0]),
        ripemd160::digest_length
    );
}
예제 #2
0
bool inventory_vector::encode(data_buffer & buffer)
{
    buffer.write_uint32(m_type);
    buffer.write_sha256(m_hash);
    
    return true;
}
예제 #3
0
void zerotime_lock::encode(data_buffer & buffer)
{
    /**
     * Encode the version.
     */
    buffer.write_uint32(m_version);

    /**
     * Encode the transaction.
     */
    m_transaction.encode(buffer);

    /**
     * Encode the transaction hash.
     */
    buffer.write_bytes(
        reinterpret_cast<const char *> (m_hash_tx.digest()),
        sha256::digest_length
    );

    /**
     * Encode the expiration.
     */
    buffer.write_uint64(m_expiration);

    /**
     * No signature is required because:
     * 1. The receiver may want to lock a non-zerotime transaction.
     * 2. It causes no harm to let other's lock the transaction.
     * 3. It conserves bandwidth and processing power.
     */
}
예제 #4
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);
}
예제 #5
0
void transaction::encode(
    data_buffer & buffer, const bool & encode_version
    ) const
{
    if (encode_version)
    {
        /**
         * Write the version.
         */
        buffer.write_uint32(m_version);
    }
    
    /**
     * Write the time.
     */
    buffer.write_uint32(m_time);
    
    /**
     * Write the m_transactions_in size.
     */
    buffer.write_var_int(m_transactions_in.size());
    
    for (auto & i : m_transactions_in)
    {
        i.encode(buffer);
    }
    
    /**
     * Write the m_transactions_out size.
     */
    buffer.write_var_int(m_transactions_out.size());
    
    for (auto & i : m_transactions_out)
    {
        i.encode(buffer);
    }
    
    /**
     * Write the time lock.
     */
    buffer.write_uint32(m_time_lock);
}
예제 #6
0
void key_wallet::encode(data_buffer & buffer)
{
    /**
     * Write the version.
     */
    buffer.write_uint32(constants::version_client);
    
    /**
     * Write the private key length.
     */
    buffer.write_var_int(m_key_private.size());
    
    /**
     * Write the private key.
     */
    if (m_key_private.size() > 0)
    {
        buffer.write_bytes(
            reinterpret_cast<const char *>(&m_key_private[0]),
            m_key_private.size()
        );
    }
    
    /**
     * Write the time created.
     */
    buffer.write_int64(m_time_created);
    
    /**
     * Write the time expires.
     */
    buffer.write_int64(m_time_expires);
    
    /**
     * Write the comment length.
     */
    buffer.write_var_int(m_comment.size());
    
    /**
     * Write the comment.
     */
    if (m_comment.size() > 0)
    {
        buffer.write_bytes(m_comment.data(), m_comment.size());
    }
}
예제 #7
0
void incentive_answer::encode(data_buffer & buffer, const bool & is_copy )
{
    /**
     * Encode the version.
     */
    buffer.write_uint32(m_version);

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

    /**
     * Encode the transaction_in.
     */
    m_transaction_in.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);
    }
}
예제 #8
0
void key_pool::encode(data_buffer & buffer, const bool & include_version)
{
    if (include_version)
    {
        /**
         * Write the version.
         */
        buffer.write_uint32(constants::version_client);
    }
    
    /**
     * Write the time.
     */
    buffer.write_int64(m_time);
    
    /**
     * Encode the public key.
     */
    m_key_public.encode(buffer);
}
예제 #9
0
void zerotime_question::encode(data_buffer & buffer)
{
    /**
     * Encode the version.
     */
    buffer.write_uint32(m_version);
    
    /** 
     * Encode the transaction inputs length.
     */
    buffer.write_var_int(m_transactions_in.size());
    
    for (auto & i : m_transactions_in)
    {
        /**
         * Encode the transaction_in.
         */
        i.encode(buffer);
    }
}
예제 #10
0
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()
    );
}
예제 #11
0
void incentive_collaterals::encode(data_buffer & buffer)
{
    /**
     * Encode the version.
     */
    buffer.write_uint32(m_version);
    
    /**
     * Write the number of collateral entries.
     */
    buffer.write_var_int(m_collaterals.size());
    
    /**
     * Write the collateral entries.
     */
     for (auto & i : m_collaterals)
     {
        /**
         * Write the address.
         */
        buffer.write_network_address(i.addr, false);
        
        /**
         * Write the size of the wallet address.
         */
        buffer.write_var_int(i.wallet_address.size());
        
        /**
         * Write the wallet address.
         */
        buffer.write_bytes(i.wallet_address.data(), i.wallet_address.size());
        
        auto public_key = i.public_key;
        
        /**
         * Write the public key.
         */
        public_key.encode(buffer);
        
        /**
         * Write the transaction_in.
         */
        i.tx_in.encode(buffer);
        
        /**
         * Write the time.
         */
        buffer.write_uint64(i.time);
        
        /**
         * Write the protocol version.
         */
        buffer.write_uint32(i.protocol_version);
        
        /**
         * Write the protocol user agent.
         */
        buffer.write_var_int(i.protocol_version_user_agent.size());
        
        /**
         * Write the protocol version user agent.
         */
        buffer.write_bytes(
            i.protocol_version_user_agent.data(),
            i.protocol_version_user_agent.size()
        );
        
        /**
         * Write the protocol version services.
         */
        buffer.write_uint64(i.protocol_version_services);
        
        /**
         * Write the protocol version start height.
         */
        buffer.write_int32(i.protocol_version_start_height);
     }
}
예제 #12
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);
    }
}
예제 #13
0
void transaction_wallet::encode(data_buffer & buffer)
{
    auto is_spent = false;

    m_values["fromaccount"] = m_from_account;

    std::string str;
    
    for (auto & i : m_spent)
    {
        str += (i ? '1' : '0');
        
        if (i)
        {
            is_spent = true;
        }
    }
    
    m_values["spent"] = str;

    wallet::write_order_position(m_order_position, m_values);

    if (m_time_smart)
    {
        m_values["timesmart"] = std::to_string(m_time_smart);
    }
    
    /**
     * Encode the base class.
     */
    transaction_merkle::encode(buffer);
    
    buffer.write_var_int(m_previous_transactions.size());
    
    for (auto & i : m_previous_transactions)
    {
        i.encode(buffer);
    }
    
    /**
     * If we are an (SPV) client set the block height as a value.
     */
    if (globals::instance().is_client_spv() == true)
    {
        auto block_height = spv_block_height();
        
        m_values["spv_block_height"] = std::to_string(block_height);
    }
    
    buffer.write_var_int(m_values.size());
    
    for (auto & i : m_values)
    {
        buffer.write_var_int(i.first.size());
        buffer.write_bytes(i.first.data(), i.first.size());
        buffer.write_var_int(i.second.size());
        buffer.write_bytes(i.second.data(), i.second.size());
    }
    
    buffer.write_var_int(m_order_form.size());
    
    for (auto & i : m_order_form)
    {
        buffer.write_var_int(i.first.size());
        buffer.write_bytes(i.first.data(), i.first.size());
        buffer.write_var_int(i.second.size());
        buffer.write_bytes(i.second.data(), i.second.size());
    }
    
    buffer.write_uint32(m_time_received_is_tx_time);
    buffer.write_uint32(m_time_received);
    buffer.write_uint8(m_is_from_me);
    buffer.write_uint8(is_spent);

    m_values.erase("fromaccount");
    m_values.erase("version");
    m_values.erase("spent");
    m_values.erase("n");
    m_values.erase("timesmart");
}