Skip to content

Commit

Permalink
Added MintTokens public function
Browse files Browse the repository at this point in the history
  • Loading branch information
EduMenges committed Sep 10, 2024
1 parent dd8ef18 commit ffa30ed
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 38 deletions.
80 changes: 42 additions & 38 deletions src/GeniusSDK.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,49 +37,49 @@ class JsonError : public boost::exception
namespace
{
outcome::result<DevConfig_st, JsonError> ReadDevConfigFromJSON( const std::string &base_path )
{
std::ifstream file( base_path + "dev_config.json" );
if ( !file.is_open() )
{
return outcome::failure( JsonError( "Configuration file \"dev_config.json\" not found on " + base_path ) );
}
DevConfig_st config_from_file = {};
std::stringstream buffer;
buffer << file.rdbuf();
std::string jsonStr = buffer.str();
std::ifstream file( base_path + "dev_config.json" );
if ( !file.is_open() )
{
return outcome::failure( JsonError( "Configuration file \"dev_config.json\" not found on " + base_path ) );
}
DevConfig_st config_from_file = {};
std::stringstream buffer;
buffer << file.rdbuf();
std::string jsonStr = buffer.str();

rapidjson::Document document;
rapidjson::ParseResult parseResult = document.Parse( jsonStr.c_str() );
rapidjson::Document document;
rapidjson::ParseResult parseResult = document.Parse( jsonStr.c_str() );
if ( parseResult == nullptr )
{
return outcome::failure( JsonError( "Parse error " ) );
}
{
return outcome::failure( JsonError( "Parse error " ) );
}

if ( !document.HasMember( "Address" ) || !document["Address"].IsString() )
{
return outcome::failure( JsonError( "Missing or invalid 'Address'" ) );
}
if ( !document.HasMember( "Cut" ) || !document["Cut"].IsDouble() )
{
return outcome::failure( JsonError( "Missing or invalid 'Cut'" ) );
}
if ( !document.HasMember( "TokenValue" ) || !document["TokenValue"].IsDouble() )
{
return outcome::failure( JsonError( "Missing or invalid 'TokenValue'" ) );
}
if ( !document.HasMember( "TokenID" ) || !document["TokenID"].IsInt() )
{
return outcome::failure( JsonError( "Missing or invalid 'TokenID'" ) );
}
if ( !document.HasMember( "Address" ) || !document["Address"].IsString() )
{
return outcome::failure( JsonError( "Missing or invalid 'Address'" ) );
}
if ( !document.HasMember( "Cut" ) || !document["Cut"].IsDouble() )
{
return outcome::failure( JsonError( "Missing or invalid 'Cut'" ) );
}
if ( !document.HasMember( "TokenValue" ) || !document["TokenValue"].IsDouble() )
{
return outcome::failure( JsonError( "Missing or invalid 'TokenValue'" ) );
}
if ( !document.HasMember( "TokenID" ) || !document["TokenID"].IsInt() )
{
return outcome::failure( JsonError( "Missing or invalid 'TokenID'" ) );
}

strncpy( config_from_file.Addr, document["Address"].GetString(), document["Address"].GetStringLength() );
config_from_file.Cut = document["Cut"].GetDouble();
config_from_file.TokenValueInGNUS = document["TokenValue"].GetDouble();
config_from_file.TokenID = document["TokenID"].GetInt();
strncpy( config_from_file.BaseWritePath, base_path.data(), base_path.size() );
strncpy( config_from_file.Addr, document["Address"].GetString(), document["Address"].GetStringLength() );
config_from_file.Cut = document["Cut"].GetDouble();
config_from_file.TokenValueInGNUS = document["TokenValue"].GetDouble();
config_from_file.TokenID = document["TokenID"].GetInt();
strncpy( config_from_file.BaseWritePath, base_path.data(), base_path.size() );

return outcome::success( config_from_file );
}
return outcome::success( config_from_file );
}

GeniusMatrix matrix_from_vector_of_vector( const std::vector<std::vector<uint8_t>> &vec )
{
Expand All @@ -97,7 +97,7 @@ namespace
return matrix;
}

std::shared_ptr<sgns::GeniusNode> GeniusNodeInstance;
std::shared_ptr<sgns::GeniusNode> GeniusNodeInstance;
}

const char *GeniusSDKInit( const char *base_path )
Expand Down Expand Up @@ -147,3 +147,7 @@ void GeniusSDKFreeTransactions( GeniusMatrix matrix )
free( matrix.ptr );
}

void GeniusSDKMintTokens( uint64_t amount )
{
GeniusNodeInstance->MintTokens( amount );
}
1 change: 1 addition & 0 deletions src/GeniusSDK.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ GNUS_VISIBILITY_DEFAULT void GeniusSDKProcess( const ImagePath_t path, Pa
GNUS_VISIBILITY_DEFAULT uint64_t GeniusSDKGetBalance();
GNUS_VISIBILITY_DEFAULT GeniusMatrix GeniusSDKGetTransactions();
GNUS_VISIBILITY_DEFAULT void GeniusSDKFreeTransactions( GeniusMatrix matrix );
GNUS_VISIBILITY_DEFAULT void GeniusSDKMintTokens( uint64_t amount );

GNUS_EXPORT_END

Expand Down

0 comments on commit ffa30ed

Please sign in to comment.