Skip to content

Commit

Permalink
Remove unused key types
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanielhourt committed May 1, 2019
1 parent 81b126f commit 6d51696
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 212 deletions.
48 changes: 0 additions & 48 deletions libraries/protocol/include/graphene/protocol/types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,56 +202,12 @@ class pubkey_comparator {
}
};

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<>
Expand Down Expand Up @@ -304,10 +260,6 @@ FC_REFLECT_TYPENAME(graphene::protocol::htlc_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,)
Expand Down
128 changes: 0 additions & 128 deletions libraries/protocol/types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,114 +88,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<binary_key>(bin);
FC_ASSERT( fc::ripemd160::hash( bin_key.data.data, bin_key.data.size() )._hash[0] == 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( k.data.data, k.data.size() )._hash[0];
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<binary_key>(bin);
FC_ASSERT( fc::ripemd160::hash( bin_key.data.data, bin_key.data.size() )._hash[0] == 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( k.data.data, k.data.size() )._hash[0];
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
Expand All @@ -211,26 +103,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<const graphene::protocol::fee_schedule>& vo,
uint32_t max_depth ) {
// If it's null, just make a new one
Expand Down
36 changes: 0 additions & 36 deletions tests/tests/serialization_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 6d51696

Please sign in to comment.