From 33d385db5fcd5c95ef96344d741a631831a80fd2 Mon Sep 17 00:00:00 2001 From: sowle Date: Mon, 27 Apr 2020 14:52:31 +0300 Subject: [PATCH] auditability: basic structures, serialization, helpers (WIP) --- src/currency_core/currency_basic.h | 109 ++++++++++++++++-- .../currency_boost_serialization.h | 21 ++++ src/currency_core/currency_format_utils.cpp | 2 +- src/currency_core/currency_format_utils.h | 21 ++++ 4 files changed, 140 insertions(+), 13 deletions(-) diff --git a/src/currency_core/currency_basic.h b/src/currency_core/currency_basic.h index 74f5c824..20199fad 100644 --- a/src/currency_core/currency_basic.h +++ b/src/currency_core/currency_basic.h @@ -15,7 +15,7 @@ #include #include #include -#include +#include #include #include @@ -58,9 +58,9 @@ namespace currency /* */ /************************************************************************/ - //since structure used in blockchain as a key accessor, then be sure that there is no padding inside +//since structure used in blockchain as a key accessor, then be sure that there is no padding inside #pragma pack(push, 1) - struct account_public_address + struct account_public_address_old { crypto::public_key spend_public_key; crypto::public_key view_public_key; @@ -70,13 +70,73 @@ namespace currency FIELD(view_public_key) END_SERIALIZE() - BEGIN_KV_SERIALIZE_MAP() - KV_SERIALIZE_VAL_POD_AS_BLOB_FORCE(spend_public_key) - KV_SERIALIZE_VAL_POD_AS_BLOB_FORCE(view_public_key) - END_KV_SERIALIZE_MAP() + BEGIN_KV_SERIALIZE_MAP() + KV_SERIALIZE_VAL_POD_AS_BLOB_FORCE(spend_public_key) + KV_SERIALIZE_VAL_POD_AS_BLOB_FORCE(view_public_key) + END_KV_SERIALIZE_MAP() }; #pragma pack(pop) + +#define ACCOUNT_PUBLIC_ADDRESS_SERIZALIZATION_VER 1 + +#define ACCOUNT_PUBLIC_ADDRESS_FLAG_AUDITABLE 0x01 // auditable address + +//since structure used in blockchain as a key accessor, then be sure that there is no padding inside +#pragma pack(push, 1) + struct account_public_address + { + /*account_public_address() + {} + + account_public_address(const account_public_address_old& rhs) + : version(ACCOUNT_PUBLIC_ADDRESS_SERIZALIZATION_VER) + , flags(0) + , spend_public_key(rhs.spend_public_key) + , view_public_key(rhs.view_public_key) + {}*/ + + uint8_t version; + uint8_t flags; + crypto::public_key spend_public_key; + crypto::public_key view_public_key; + + DEFINE_SERIALIZATION_VERSION(ACCOUNT_PUBLIC_ADDRESS_SERIZALIZATION_VER) + BEGIN_SERIALIZE_OBJECT() + VERSION_ENTRY(version) + FIELD(flags) + FIELD(spend_public_key) + FIELD(view_public_key) + if (version > ACCOUNT_PUBLIC_ADDRESS_SERIZALIZATION_VER) + return true; // backward compartibility + END_SERIALIZE() + + BEGIN_KV_SERIALIZE_MAP() + KV_SERIALIZE(version) // is it necessary? + KV_SERIALIZE(flags) + KV_SERIALIZE_VAL_POD_AS_BLOB_FORCE(spend_public_key) + KV_SERIALIZE_VAL_POD_AS_BLOB_FORCE(view_public_key) + END_KV_SERIALIZE_MAP() + + static account_public_address from_old(const account_public_address_old& rhs) + { + account_public_address result = AUTO_VAL_INIT(result); + result.spend_public_key = rhs.spend_public_key; + result.view_public_key = rhs.view_public_key; + return result; + } + + account_public_address_old to_old() const + { + account_public_address_old result = AUTO_VAL_INIT(result); + result.spend_public_key = spend_public_key; + result.view_public_key = view_public_key; + return result; + } + }; +#pragma pack(pop) + + const static account_public_address null_pub_addr = AUTO_VAL_INIT(null_pub_addr); typedef std::vector ring_signature; @@ -224,9 +284,30 @@ namespace currency END_SERIALIZE() }; + struct tx_payer_old + { + account_public_address_old acc_addr; + + BEGIN_SERIALIZE() + FIELD(acc_addr) + END_SERIALIZE() + }; + struct tx_payer { - account_public_address acc_addr; + tx_payer() = default; + tx_payer(const tx_payer_old& old) : acc_addr(account_public_address::from_old(old.acc_addr)) {} + + account_public_address acc_addr{}; + + BEGIN_SERIALIZE() + FIELD(acc_addr) + END_SERIALIZE() + }; + + struct tx_receiver_old + { + account_public_address_old acc_addr; BEGIN_SERIALIZE() FIELD(acc_addr) @@ -235,7 +316,10 @@ namespace currency struct tx_receiver { - account_public_address acc_addr; + tx_receiver() = default; + tx_receiver(const tx_receiver_old& old) : acc_addr(account_public_address::from_old(old.acc_addr)) {} + + account_public_address acc_addr{}; BEGIN_SERIALIZE() FIELD(acc_addr) @@ -388,9 +472,10 @@ namespace currency END_SERIALIZE() }; - typedef boost::mpl::vector< - tx_service_attachment, tx_comment, tx_payer, tx_receiver, tx_derivation_hint, std::string, tx_crypto_checksum, etc_tx_time, etc_tx_details_unlock_time, etc_tx_details_expiration_time, + typedef boost::mpl::vector20< + tx_service_attachment, tx_comment, tx_payer_old, tx_receiver_old, tx_derivation_hint, std::string, tx_crypto_checksum, etc_tx_time, etc_tx_details_unlock_time, etc_tx_details_expiration_time, etc_tx_details_flags, crypto::public_key, extra_attachment_info, extra_alias_entry, extra_user_data, extra_padding, etc_tx_uint16_t, etc_tx_details_unlock_time2 + , tx_payer, tx_receiver//, extra_alias_entry > all_payload_types; typedef boost::make_variant_over::type payload_items_v; @@ -602,7 +687,7 @@ SET_VARIANT_TAGS(currency::transaction, 5, "tx"); SET_VARIANT_TAGS(currency::block, 6, "block"); //attachment_v definitions SET_VARIANT_TAGS(currency::tx_comment, 7, "comment"); -SET_VARIANT_TAGS(currency::tx_payer, 8, "payer"); +SET_VARIANT_TAGS(currency::tx_payer_old, 8, "payer"); SET_VARIANT_TAGS(std::string, 9, "string"); SET_VARIANT_TAGS(currency::tx_crypto_checksum, 10, "checksum"); SET_VARIANT_TAGS(currency::tx_derivation_hint, 11, "derivation_hint"); diff --git a/src/currency_core/currency_boost_serialization.h b/src/currency_core/currency_boost_serialization.h index 99928b7a..e940ec11 100644 --- a/src/currency_core/currency_boost_serialization.h +++ b/src/currency_core/currency_boost_serialization.h @@ -29,10 +29,18 @@ namespace boost template inline void serialize(Archive &a, currency::account_public_address &x, const boost::serialization::version_type ver) { + a & x.version; + a & x.flags; a & x.spend_public_key; a & x.view_public_key; } + template + inline void serialize(Archive &a, currency::account_public_address_old &x, const boost::serialization::version_type ver) + { + a & x.spend_public_key; + a & x.view_public_key; + } template inline void serialize(Archive &a, currency::txout_to_key &x, const boost::serialization::version_type ver) @@ -90,11 +98,24 @@ namespace boost a & x.comment; } + template + inline void serialize(Archive &a, currency::tx_payer_old &x, const boost::serialization::version_type ver) + { + a & x.acc_addr; + } + template inline void serialize(Archive &a, currency::tx_payer &x, const boost::serialization::version_type ver) { a & x.acc_addr; } + + template + inline void serialize(Archive &a, currency::tx_receiver_old &x, const boost::serialization::version_type ver) + { + a & x.acc_addr; + } + template inline void serialize(Archive &a, currency::tx_receiver &x, const boost::serialization::version_type ver) { diff --git a/src/currency_core/currency_format_utils.cpp b/src/currency_core/currency_format_utils.cpp index feeab899..2c87a385 100644 --- a/src/currency_core/currency_format_utils.cpp +++ b/src/currency_core/currency_format_utils.cpp @@ -2026,7 +2026,7 @@ namespace currency //--------------------------------------------------------------- bool is_showing_sender_addres(const transaction& tx) { - return have_type_in_variant_container(tx.attachment); + return have_type_in_variant_container(tx.attachment) || have_type_in_variant_container(tx.attachment); } //--------------------------------------------------------------- bool is_mixin_tx(const transaction& tx) diff --git a/src/currency_core/currency_format_utils.h b/src/currency_core/currency_format_utils.h index 48441033..abe217ab 100644 --- a/src/currency_core/currency_format_utils.h +++ b/src/currency_core/currency_format_utils.h @@ -27,6 +27,7 @@ #include "blockchain_storage_basic.h" #include "currency_format_utils_blocks.h" #include "currency_format_utils_transactions.h" +#include "core_runtime_config.h" // ------ get_tx_type_definition ------------- @@ -589,6 +590,26 @@ namespace currency return boost::apply_visitor(input_amount_getter(), v); } //--------------------------------------------------------------- + template + void create_and_add_tx_payer_to_container_from_address(container_t& container, const account_public_address& addr, uint64_t top_block_height, const core_runtime_config& crc) + { + if (top_block_height > crc.hard_fork_02_starts_after_height) + { + // after hardfork 2 + tx_payer result = AUTO_VAL_INIT(result); + result.acc_addr = addr; + container.push_back(result); + } + else + { + // before hardfork 2 + tx_payer_old result = AUTO_VAL_INIT(result); + result.acc_addr = addr.to_old(); + container.push_back(result); + } + } + //--------------------------------------------------------------- + //--------------------------------------------------------------- std::ostream& operator <<(std::ostream& o, const ref_by_id& r); //--------------------------------------------------------------- #ifndef ANDROID_BUILD