Skip to content

Commit

Permalink
#1702 improve code quality
Browse files Browse the repository at this point in the history
  • Loading branch information
olehnikolaiev committed Nov 8, 2023
1 parent 582b526 commit ea694fc
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions libethereum/Precompiled.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -747,21 +747,19 @@ static bool isCallToHistoricData( const std::string& callData ) {
return boost::algorithm::starts_with( callData, "skaleConfig.sChain.nodes." );

Check warning on line 747 in libethereum/Precompiled.cpp

View check run for this annotation

Codecov / codecov/patch

libethereum/Precompiled.cpp#L747

Added line #L747 was not covered by tests
}

static std::pair< std::string, unsigned > parseHistoricFieldReuqest( std::string callData ) {
static std::pair< std::string, unsigned > parseHistoricFieldRequest( std::string callData ) {
std::vector< std::string > splitted;
boost::split( splitted, callData, boost::is_any_of( "." ) );

Check warning on line 752 in libethereum/Precompiled.cpp

View check run for this annotation

Codecov / codecov/patch

libethereum/Precompiled.cpp#L750-L752

Added lines #L750 - L752 were not covered by tests
// first 3 elements are skaleConfig, sChain, nodes - it was checked before
unsigned id = std::stoul( splitted[3] );
unsigned id = std::stoul( splitted.at( 3 ) );
std::string fieldName;
boost::trim_if( splitted[4], []( char c ) { return c == '\0'; } );
if ( splitted[4] == "id" ) {
fieldName = "id";
} else if ( splitted[4] == "schainIndex" ) {
fieldName = "schainIndex";
} else if ( splitted[4] == "owner" ) {
fieldName = "owner";
boost::trim_if( splitted.at( 4 ), []( char c ) { return c == '\0'; } );
std::set< std::string > allowedValues{ "id", "schainIndex", "owner" };
fieldName = splitted.at( 4 );
if ( allowedValues.count( fieldName ) ) {
return { fieldName, id };

Check warning on line 760 in libethereum/Precompiled.cpp

View check run for this annotation

Codecov / codecov/patch

libethereum/Precompiled.cpp#L754-L760

Added lines #L754 - L760 were not covered by tests
} else {
fieldName = "unknown field";
BOOST_THROW_EXCEPTION( std::runtime_error( "Unknown field:" + fieldName ) );

Check warning on line 762 in libethereum/Precompiled.cpp

View check run for this annotation

Codecov / codecov/patch

libethereum/Precompiled.cpp#L762

Added line #L762 was not covered by tests
}
return { fieldName, id };
}
Expand Down Expand Up @@ -807,7 +805,7 @@ ETH_REGISTER_PRECOMPILED( getConfigVariableUint256 )( bytesConstRef _in ) {

std::string field;

Check warning on line 806 in libethereum/Precompiled.cpp

View check run for this annotation

Codecov / codecov/patch

libethereum/Precompiled.cpp#L806

Added line #L806 was not covered by tests
unsigned id;
std::tie( field, id ) = parseHistoricFieldReuqest( rawName );
std::tie( field, id ) = parseHistoricFieldRequest( rawName );
if ( field == "id" ) {
strValue = g_skaleHost->getHistoricNodeId( id );
} else if ( field == "schainIndex" ) {
Expand Down Expand Up @@ -881,7 +879,7 @@ ETH_REGISTER_PRECOMPILED( getConfigVariableAddress )( bytesConstRef _in ) {

std::string field;

Check warning on line 880 in libethereum/Precompiled.cpp

View check run for this annotation

Codecov / codecov/patch

libethereum/Precompiled.cpp#L880

Added line #L880 was not covered by tests
unsigned id;
std::tie( field, id ) = parseHistoricFieldReuqest( rawName );
std::tie( field, id ) = parseHistoricFieldRequest( rawName );
if ( field == "owner" ) {
strValue = g_skaleHost->getHistoricNodeOwner( id );

Check warning on line 884 in libethereum/Precompiled.cpp

View check run for this annotation

Codecov / codecov/patch

libethereum/Precompiled.cpp#L882-L884

Added lines #L882 - L884 were not covered by tests
} else {
Expand Down

0 comments on commit ea694fc

Please sign in to comment.