From 35d864e269c5b8a856308f535fa390f64741cd34 Mon Sep 17 00:00:00 2001 From: Nathan Hourt Date: Wed, 1 May 2019 12:50:00 -0500 Subject: [PATCH] Remove unused key types --- .../include/graphene/protocol/types.hpp | 48 ------- libraries/protocol/types.cpp | 128 ------------------ tests/tests/serialization_tests.cpp | 36 ----- 3 files changed, 212 deletions(-) diff --git a/libraries/protocol/include/graphene/protocol/types.hpp b/libraries/protocol/include/graphene/protocol/types.hpp index 020bebf0..260b904c 100644 --- a/libraries/protocol/include/graphene/protocol/types.hpp +++ b/libraries/protocol/include/graphene/protocol/types.hpp @@ -217,56 +217,12 @@ public: } }; -struct extended_public_key_type { - struct binary_key { - binary_key() = default; - uint32_t check = 0; - fc::ecc::extended_key_data data; - }; - - fc::ecc::extended_key_data key_data; - - extended_public_key_type(); - extended_public_key_type(const fc::ecc::extended_key_data& data); - extended_public_key_type(const fc::ecc::extended_public_key& extpubkey); - explicit extended_public_key_type(const std::string& base58str); - operator fc::ecc::extended_public_key() const; - explicit operator std::string() const; - friend bool operator == (const extended_public_key_type& p1, const fc::ecc::extended_public_key& p2); - friend bool operator == (const extended_public_key_type& p1, const extended_public_key_type& p2); - friend bool operator != (const extended_public_key_type& p1, const extended_public_key_type& p2); -}; - -struct extended_private_key_type { - struct binary_key { - binary_key() = default; - uint32_t check = 0; - fc::ecc::extended_key_data data; - }; - - fc::ecc::extended_key_data key_data; - - extended_private_key_type(); - extended_private_key_type(const fc::ecc::extended_key_data& data); - extended_private_key_type(const fc::ecc::extended_private_key& extprivkey); - explicit extended_private_key_type(const std::string& base58str); - operator fc::ecc::extended_private_key() const; - explicit operator std::string() const; - friend bool operator == (const extended_private_key_type& p1, const fc::ecc::extended_private_key& p); - friend bool operator == (const extended_private_key_type& p1, const extended_private_key_type& p); - friend bool operator != (const extended_private_key_type& p1, const extended_private_key_type& p); -}; - struct fee_schedule; } } // graphene::protocol namespace fc { void to_variant(const graphene::protocol::public_key_type& var, fc::variant& vo, uint32_t max_depth = 2); void from_variant(const fc::variant& var, graphene::protocol::public_key_type& vo, uint32_t max_depth = 2); -void to_variant(const graphene::protocol::extended_public_key_type& var, fc::variant& vo, uint32_t max_depth = 2); -void from_variant(const fc::variant& var, graphene::protocol::extended_public_key_type& vo, uint32_t max_depth = 2); -void to_variant(const graphene::protocol::extended_private_key_type& var, fc::variant& vo, uint32_t max_depth = 2); -void from_variant(const fc::variant& var, graphene::protocol::extended_private_key_type& vo, uint32_t max_depth = 2); template<> @@ -349,10 +305,6 @@ FC_REFLECT_TYPENAME(graphene::protocol::nft_id_type) FC_REFLECT(graphene::protocol::public_key_type, (key_data)) FC_REFLECT(graphene::protocol::public_key_type::binary_key, (data)(check)) -FC_REFLECT(graphene::protocol::extended_public_key_type, (key_data)) -FC_REFLECT(graphene::protocol::extended_public_key_type::binary_key, (check)(data)) -FC_REFLECT(graphene::protocol::extended_private_key_type, (key_data)) -FC_REFLECT(graphene::protocol::extended_private_key_type::binary_key, (check)(data)) FC_REFLECT_TYPENAME(graphene::protocol::share_type) FC_REFLECT(graphene::protocol::void_t,) diff --git a/libraries/protocol/types.cpp b/libraries/protocol/types.cpp index e07f7c64..355b7339 100644 --- a/libraries/protocol/types.cpp +++ b/libraries/protocol/types.cpp @@ -136,114 +136,6 @@ namespace graphene { namespace protocol { return p1.key_data != p2.key_data; } - // extended_public_key_type - - extended_public_key_type::extended_public_key_type():key_data(){}; - - extended_public_key_type::extended_public_key_type( const fc::ecc::extended_key_data& data ) - :key_data( data ){}; - - extended_public_key_type::extended_public_key_type( const fc::ecc::extended_public_key& extpubkey ) - { - key_data = extpubkey.serialize_extended(); - }; - - extended_public_key_type::extended_public_key_type( const std::string& base58str ) - { - std::string prefix( GRAPHENE_ADDRESS_PREFIX ); - - const size_t prefix_len = prefix.size(); - FC_ASSERT( base58str.size() > prefix_len ); - FC_ASSERT( base58str.substr( 0, prefix_len ) == prefix , "", ("base58str", base58str) ); - auto bin = fc::from_base58( base58str.substr( prefix_len ) ); - auto bin_key = fc::raw::unpack(bin); - FC_ASSERT( fc::ripemd160::hash( (char*)bin_key.data.data(), bin_key.data.size() )._hash[0].value() == bin_key.check ); - key_data = bin_key.data; - } - - extended_public_key_type::operator fc::ecc::extended_public_key() const - { - return fc::ecc::extended_public_key::deserialize( key_data ); - } - - extended_public_key_type::operator std::string() const - { - binary_key k; - k.data = key_data; - k.check = fc::ripemd160::hash( (char*)k.data.data(), k.data.size() )._hash[0].value(); - auto data = fc::raw::pack( k ); - return GRAPHENE_ADDRESS_PREFIX + fc::to_base58( data.data(), data.size() ); - } - - bool operator == ( const extended_public_key_type& p1, const fc::ecc::extended_public_key& p2) - { - return p1.key_data == p2.serialize_extended(); - } - - bool operator == ( const extended_public_key_type& p1, const extended_public_key_type& p2) - { - return p1.key_data == p2.key_data; - } - - bool operator != ( const extended_public_key_type& p1, const extended_public_key_type& p2) - { - return p1.key_data != p2.key_data; - } - - // extended_private_key_type - - extended_private_key_type::extended_private_key_type() = default; - - extended_private_key_type::extended_private_key_type( const fc::ecc::extended_key_data& data ) - :key_data( data ){}; - - extended_private_key_type::extended_private_key_type( const fc::ecc::extended_private_key& extprivkey ) - { - key_data = extprivkey.serialize_extended(); - }; - - extended_private_key_type::extended_private_key_type( const std::string& base58str ) - { - std::string prefix( GRAPHENE_ADDRESS_PREFIX ); - - const size_t prefix_len = prefix.size(); - FC_ASSERT( base58str.size() > prefix_len ); - FC_ASSERT( base58str.substr( 0, prefix_len ) == prefix , "", ("base58str", base58str) ); - auto bin = fc::from_base58( base58str.substr( prefix_len ) ); - auto bin_key = fc::raw::unpack(bin); - FC_ASSERT( fc::ripemd160::hash( (char*)bin_key.data.data(), bin_key.data.size() )._hash[0].value() == bin_key.check ); - key_data = bin_key.data; - } - - extended_private_key_type::operator fc::ecc::extended_private_key() const - { - return fc::ecc::extended_private_key::deserialize( key_data ); - } - - extended_private_key_type::operator std::string() const - { - binary_key k; - k.data = key_data; - k.check = fc::ripemd160::hash( (char*)k.data.data(), k.data.size() )._hash[0].value(); - auto data = fc::raw::pack( k ); - return GRAPHENE_ADDRESS_PREFIX + fc::to_base58( data.data(), data.size() ); - } - - bool operator == ( const extended_private_key_type& p1, const fc::ecc::extended_public_key& p2) - { - return p1.key_data == p2.serialize_extended(); - } - - bool operator == ( const extended_private_key_type& p1, const extended_private_key_type& p2) - { - return p1.key_data == p2.key_data; - } - - bool operator != ( const extended_private_key_type& p1, const extended_private_key_type& p2) - { - return p1.key_data != p2.key_data; - } - } } // graphene::protocol namespace fc @@ -259,26 +151,6 @@ namespace fc vo = graphene::protocol::public_key_type( var.as_string() ); } - void to_variant( const graphene::protocol::extended_public_key_type& var, fc::variant& vo, uint32_t max_depth ) - { - vo = std::string( var ); - } - - void from_variant( const fc::variant& var, graphene::protocol::extended_public_key_type& vo, uint32_t max_depth ) - { - vo = graphene::protocol::extended_public_key_type( var.as_string() ); - } - - void to_variant( const graphene::protocol::extended_private_key_type& var, fc::variant& vo, uint32_t max_depth ) - { - vo = std::string( var ); - } - - void from_variant( const fc::variant& var, graphene::protocol::extended_private_key_type& vo, uint32_t max_depth ) - { - vo = graphene::protocol::extended_private_key_type( var.as_string() ); - } - void from_variant( const fc::variant& var, std::shared_ptr& vo, uint32_t max_depth ) { // If it's null, just make a new one diff --git a/tests/tests/serialization_tests.cpp b/tests/tests/serialization_tests.cpp index 59e16f01..91085af4 100644 --- a/tests/tests/serialization_tests.cpp +++ b/tests/tests/serialization_tests.cpp @@ -86,42 +86,6 @@ BOOST_AUTO_TEST_CASE( json_tests ) } } -BOOST_AUTO_TEST_CASE( extended_private_key_type_test ) -{ - try - { - fc::ecc::extended_private_key key = fc::ecc::extended_private_key( fc::ecc::private_key::generate(), - fc::sha256(), - 0, 0, 0 ); - extended_private_key_type type = extended_private_key_type( key ); - std::string packed = std::string( type ); - extended_private_key_type unpacked = extended_private_key_type( packed ); - BOOST_CHECK( type == unpacked ); - } catch ( const fc::exception& e ) - { - edump((e.to_detail_string())); - throw; - } -} - -BOOST_AUTO_TEST_CASE( extended_public_key_type_test ) -{ - try - { - fc::ecc::extended_public_key key = fc::ecc::extended_public_key( fc::ecc::private_key::generate().get_public_key(), - fc::sha256(), - 0, 0, 0 ); - extended_public_key_type type = extended_public_key_type( key ); - std::string packed = std::string( type ); - extended_public_key_type unpacked = extended_public_key_type( packed ); - BOOST_CHECK( type == unpacked ); - } catch ( const fc::exception& e ) - { - edump((e.to_detail_string())); - throw; - } -} - BOOST_AUTO_TEST_CASE( extension_serialization_test ) { try