Skip to content

Commit

Permalink
Added getter for transactions
Browse files Browse the repository at this point in the history
  • Loading branch information
EduMenges committed Sep 10, 2024
1 parent b20a739 commit dd8ef18
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 3 deletions.
38 changes: 36 additions & 2 deletions src/GeniusSDK.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ class JsonError : public boost::exception
std::string message;
};

static outcome::result<DevConfig_st, JsonError> ReadDevConfigFromJSON( const std::string &base_path )
namespace
{
outcome::result<DevConfig_st, JsonError> ReadDevConfigFromJSON( const std::string &base_path )
{
std::ifstream file( base_path + "dev_config.json" );
if ( !file.is_open() )
Expand All @@ -48,7 +50,7 @@ static outcome::result<DevConfig_st, JsonError> ReadDevConfigFromJSON( const std

rapidjson::Document document;
rapidjson::ParseResult parseResult = document.Parse( jsonStr.c_str() );
if ( !parseResult )
if ( parseResult == nullptr )
{
return outcome::failure( JsonError( "Parse error " ) );
}
Expand Down Expand Up @@ -79,7 +81,24 @@ static outcome::result<DevConfig_st, JsonError> ReadDevConfigFromJSON( const std
return outcome::success( config_from_file );
}

GeniusMatrix matrix_from_vector_of_vector( const std::vector<std::vector<uint8_t>> &vec )
{
uint64_t size = vec.size();

GeniusMatrix matrix = { size, reinterpret_cast<GeniusArray *>( malloc( size * sizeof( GeniusArray ) ) ) };

for ( uint64_t i = 0; i < size; i++ )
{
matrix.ptr[i] = GeniusArray{ vec[i].size(),
reinterpret_cast<uint8_t *>( malloc( vec[i].size() * sizeof( uint8_t ) ) ) };
memcpy( matrix.ptr[i].ptr, vec[i].data(), vec[i].size() * sizeof( uint8_t ) );
}

return matrix;
}

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

const char *GeniusSDKInit( const char *base_path )
{
Expand Down Expand Up @@ -113,3 +132,18 @@ uint64_t GeniusSDKGetBalance()
{
return GeniusNodeInstance->GetBalance();
}

GeniusMatrix GeniusSDKGetTransactions()
{
return matrix_from_vector_of_vector( GeniusNodeInstance->GetTransactions() );
}

void GeniusSDKFreeTransactions( GeniusMatrix matrix )
{
for ( uint64_t i = 0; i < matrix.size; ++i )
{
free( matrix.ptr[i].ptr );
}
free( matrix.ptr );
}

19 changes: 18 additions & 1 deletion src/GeniusSDK.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
extern "C" \
{
#define GNUS_EXPORT_END }
#else
#define GNUS_EXPORT_BEGIN
#define GNUS_EXPORT_END
#endif
#endif

Expand All @@ -26,13 +29,27 @@

GNUS_EXPORT_BEGIN

typedef struct
{
uint64_t size;
uint8_t *ptr;
} GeniusArray; ///< Struct to interop C++ vectors with C

typedef struct
{
uint64_t size;
GeniusArray *ptr;
} GeniusMatrix; ///< Struct to interop a matrix of C++ vectors in C

typedef char ImagePath_t[1024]; ///< ID/Path of the image to be processed
typedef uint64_t PayAmount_t; ///< Amount to be paid for the processing

GNUS_VISIBILITY_DEFAULT const char *GeniusSDKInit( const char *base_path );
GNUS_VISIBILITY_DEFAULT void GeniusSDKProcess( const ImagePath_t path, PayAmount_t amount );
GNUS_VISIBILITY_DEFAULT uint64_t GeniusSDKGetBalance();
GNUS_VISIBILITY_DEFAULT GeniusMatrix GeniusSDKGetTransactions();
GNUS_VISIBILITY_DEFAULT void GeniusSDKFreeTransactions( GeniusMatrix matrix );

GNUS_EXPORT_END

#endif //GENIUSSDK_H
#endif

0 comments on commit dd8ef18

Please sign in to comment.