diff --git a/libethereum/Precompiled.cpp b/libethereum/Precompiled.cpp index 5e0d05e63..4f59be395 100644 --- a/libethereum/Precompiled.cpp +++ b/libethereum/Precompiled.cpp @@ -675,7 +675,8 @@ ETH_REGISTER_PRECOMPILED( logTextMessage )( bytesConstRef _in ) { return { false, response }; // 1st false - means bad error occur } -static const std::list< std::string > g_listReadableConfigParts{ "skaleConfig.sChain.nodes." }; +static const std::list< std::string > g_listReadableConfigParts{ "sealEngine", + "skaleConfig.sChain.nodes." }; static bool stat_is_accessible_json_path( const std::string& strPath ) { if ( strPath.empty() ) @@ -720,10 +721,23 @@ static bytes stat_string_to_bytes_with_length( std::string& s ) { return rv; } -static dev::u256 statParseU256HexorDec( const std::string& strValue ) { +static dev::u256 stat_parse_u256_hex_or_dec( const std::string& strValue ) { if ( strValue.empty() ) return dev::u256( 0 ); - dev::u256 uValue( strValue.c_str() ); + const size_t cnt = strValue.length(); + if ( cnt >= 2 && strValue[0] == '0' && ( strValue[1] == 'x' || strValue[1] == 'X' ) ) { + dev::u256 uValue( strValue.c_str() ); + return uValue; + } + dev::u256 uValue = 0; + for ( size_t i = 0; i < cnt; ++i ) { + char chr = strValue[i]; + if ( !( '0' <= chr && chr <= '9' ) ) + throw std::runtime_error( "Bad u256 value \"" + strValue + "\" cannot be parsed" ); + int nDigit = int( chr - '0' ); + uValue *= 10; + uValue += nDigit; + } return uValue; } @@ -732,7 +746,7 @@ static bool isCallToHistoricData( const std::string& callData ) { return boost::algorithm::starts_with( callData, "skaleConfig.sChain.nodes." ); } -static std::pair< std::string, unsigned > parseHistoricFieldRequest( const std::string& callData ) { +static std::pair< std::string, unsigned > parseHistoricFieldReuqest( const std::string& callData ) { size_t numberLength = callData.find( ']' ) - callData.find( '[' ) - 1; unsigned id = std::stoul( callData.substr( callData.find( '[' ) + 1, numberLength ) ); std::string fieldName; @@ -769,7 +783,7 @@ ETH_REGISTER_PRECOMPILED( getConfigVariableUint256 )( bytesConstRef _in ) { std::string field; unsigned id; - std::tie( field, id ) = parseHistoricFieldRequest( rawName ); + std::tie( field, id ) = parseHistoricFieldReuqest( rawName ); if ( field == "id" ) { strValue = g_skaleHost->getHistoricNodeId( id ); } else if ( field == "schainIndex" ) { @@ -778,10 +792,18 @@ ETH_REGISTER_PRECOMPILED( getConfigVariableUint256 )( bytesConstRef _in ) { throw std::runtime_error( "Incorrect config field" ); } } else { - throw std::runtime_error( "Incorrect config field" ); + nlohmann::json joConfig = g_configAccesssor->getConfigJSON(); + nlohmann::json joValue = + skutils::json_config_file_accessor::stat_extract_at_path( joConfig, rawName ); + strValue = skutils::tools::trim_copy( + joValue.is_string() ? joValue.get< std::string >() : joValue.dump() ); } - dev::u256 uValue = statParseU256HexorDec( strValue ); + // dev::u256 uValue( strValue.c_str() ); + dev::u256 uValue = stat_parse_u256_hex_or_dec( strValue ); + // std::cout << "------------ Loaded config var \"" + // << rawName << "\" value is " << uValue + // << "\n"; bytes response = toBigEndian( uValue ); return { true, response }; } catch ( std::exception& ex ) { @@ -820,7 +842,7 @@ ETH_REGISTER_PRECOMPILED( getConfigVariableAddress )( bytesConstRef _in ) { std::string field; unsigned id; - std::tie( field, id ) = parseHistoricFieldRequest( rawName ); + std::tie( field, id ) = parseHistoricFieldReuqest( rawName ); if ( field == "owner" ) { strValue = g_skaleHost->getHistoricNodeOwner( id ); } else {