void checkpoint_sync::encode(data_buffer & buffer) { buffer.write_var_int(m_message.size()); buffer.write_bytes( reinterpret_cast<char *>(&m_message[0]), m_message.size() ); buffer.write_var_int(m_signature.size()); buffer.write_bytes( reinterpret_cast<char *>(&m_signature[0]), m_signature.size() ); }
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. */ }
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()); } }
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 ); }
bool incentive_vote::sign(data_buffer & buffer) { auto ret = false; /** * Calculate the hash of the nonce hash. */ auto digest = hash::sha256d( m_hash_nonce.digest(), sha256::digest_length ); /** * Hash the encoded message buffer. */ sha256 hash_value = sha256::from_digest(&digest[0]); if (incentive::instance().sign(hash_value, m_signature) == 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() ); log_debug( "Incentive vote signed value (" << hash_value.to_string().substr(0, 8) << ")." ); ret = true; } else { log_error("Incentive vote failed to sign value."); } return ret; }
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); } }
bool incentive_answer::sign(data_buffer & buffer) { auto ret = false; /** * Hash the encoded message buffer. */ sha256 hash_value = m_public_key.get_hash(); if (incentive::instance().sign(hash_value, m_signature) == 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() ); log_debug( "Incentive answer signed value (" << hash_value.to_string().substr(0, 8) << ")." ); ret = true; } else { log_error("Incentive answer failed to sign value."); } return ret; }
void transaction_out::encode(data_buffer & buffer) const { /** * Write the value. */ buffer.write_int64(m_value); /** * Write the m_script_public_key size var_int. */ buffer.write_var_int(m_script_public_key.size()); if (m_script_public_key.size() > 0) { /** * Write the m_script_public_key. */ buffer.write_bytes( reinterpret_cast<const char *> (&m_script_public_key[0]), m_script_public_key.size() ); } }
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 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); } }
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); } }
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"); }