From fc7fb86cd20fad30ea1bc6f9de42d1e83aa2a27a Mon Sep 17 00:00:00 2001 From: Vikram Rajkumar Date: Mon, 6 Jul 2015 14:41:31 -0400 Subject: [PATCH] Temporarily allow import BTS address/pubkey prefixes; #17 --- libraries/chain/address.cpp | 8 ++++++ .../chain/include/graphene/chain/types.hpp | 3 +++ libraries/chain/types.cpp | 25 +++++++++++++++++++ 3 files changed, 36 insertions(+) diff --git a/libraries/chain/address.cpp b/libraries/chain/address.cpp index cb83a226..8ac6a127 100644 --- a/libraries/chain/address.cpp +++ b/libraries/chain/address.cpp @@ -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 v = fc::from_base58( base58str.substr( prefix.size() ) ); memcpy( (char*)addr._hash, v.data(), std::min( 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; diff --git a/libraries/chain/include/graphene/chain/types.hpp b/libraries/chain/include/graphene/chain/types.hpp index 170909d3..1e502df7 100644 --- a/libraries/chain/include/graphene/chain/types.hpp +++ b/libraries/chain/include/graphene/chain/types.hpp @@ -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 diff --git a/libraries/chain/types.cpp b/libraries/chain/types.cpp index 0dc3978c..bef1bba1 100644 --- a/libraries/chain/types.cpp +++ b/libraries/chain/types.cpp @@ -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(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;