Temporarily allow import BTS address/pubkey prefixes; #17

This commit is contained in:
Vikram Rajkumar 2015-07-06 14:41:31 -04:00
parent 4a7cbaf610
commit fc7fb86cd2
3 changed files with 36 additions and 0 deletions

View file

@ -29,12 +29,20 @@ namespace graphene {
{
FC_ASSERT( is_valid( base58str ) );
std::string prefix( GRAPHENE_ADDRESS_PREFIX );
// TODO: This is temporary for testing
if( is_valid( base58str, "BTS" ) ) prefix = std::string( "BTS" );
std::vector<char> v = fc::from_base58( base58str.substr( prefix.size() ) );
memcpy( (char*)addr._hash, v.data(), std::min<size_t>( v.size()-4, sizeof( addr ) ) );
}
bool address::is_valid( const std::string& base58str, const std::string& prefix )
{
// TODO: This is temporary for testing
if( prefix == GRAPHENE_ADDRESS_PREFIX && is_valid( base58str, "BTS" ) )
return true;
const size_t prefix_len = prefix.size();
if( base58str.size() <= prefix_len )
return false;

View file

@ -422,6 +422,9 @@ namespace graphene { namespace chain {
friend bool operator == ( const public_key_type& p1, const fc::ecc::public_key& p2);
friend bool operator == ( const public_key_type& p1, const public_key_type& p2);
friend bool operator != ( const public_key_type& p1, const public_key_type& p2);
// TODO: This is temporary for testing
bool is_valid_v1( const std::string& base58str );
};
struct chain_parameters

View file

@ -38,6 +38,17 @@ namespace graphene { namespace chain {
// TODO: Refactor syntactic checks into static is_valid()
// to make public_key_type API more similar to address API
std::string prefix( GRAPHENE_ADDRESS_PREFIX );
// TODO: This is temporary for testing
try
{
if( is_valid_v1( base58str ) )
prefix = std::string( "BTS" );
}
catch( ... )
{
}
const size_t prefix_len = prefix.size();
FC_ASSERT( base58str.size() > prefix_len );
FC_ASSERT( base58str.substr( 0, prefix_len ) == prefix , "", ("base58str", base58str) );
@ -47,6 +58,20 @@ namespace graphene { namespace chain {
FC_ASSERT( fc::ripemd160::hash( key_data.data, key_data.size() )._hash[0] == bin_key.check );
};
// TODO: This is temporary for testing
bool public_key_type::is_valid_v1( const std::string& base58str )
{
std::string prefix( "BTS" );
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::ecc::public_key_data key_data = bin_key.data;
FC_ASSERT( fc::ripemd160::hash( key_data.data, key_data.size() )._hash[0] == bin_key.check );
return true;
}
public_key_type::operator fc::ecc::public_key_data() const
{
return key_data;