Skip to content

Commit

Permalink
Merge pull request #11 from GeniusVentures/get-blocks
Browse files Browse the repository at this point in the history
Get blocks, get cost, transaction hashes and chain id values for mints.
  • Loading branch information
itsafuu authored Dec 2, 2024
2 parents b203cec + 221ae2b commit de08205
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 8 deletions.
10 changes: 9 additions & 1 deletion cmake/CommonBuildParameters.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,15 @@ if(APPLE)
set(Vulkan_LIBRARY "${THIRDPARTY_BUILD_DIR}/moltenvk/build/lib/MoltenVK.xcframework")
endif()
endif()
find_package(Vulkan REQUIRED)
find_package(Vulkan)

if(NOT TARGET Vulkan::Vulkan)
if(NOT DEFINED $ENV{VULKAN_SDK})
set(ENV{VULKAN_SDK} "${THIRDPARTY_BUILD_DIR}/Vulkan-Loader")
endif()

find_package(Vulkan REQUIRED)
endif()
if(SHARED_LIB_BUILD)
set(LIB_TYPE SHARED)
else()
Expand Down
36 changes: 32 additions & 4 deletions src/GeniusSDK.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include "account/GeniusNode.hpp"
#include <algorithm>
#include <base/buffer.hpp>
#include <boost/multiprecision/cpp_int/import_export.hpp>
#include <memory>
#include <rapidjson/document.h>
Expand Down Expand Up @@ -100,6 +101,22 @@ namespace
return matrix;
}

GeniusMatrix matrix_from_buffer( const std::vector<sgns::base::Buffer> &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;
}

Expand Down Expand Up @@ -128,9 +145,9 @@ const char *GeniusSDKInit( const char *base_path, const char *eth_private_key )
return ret_val.c_str();
}

void GeniusSDKProcess( const ImagePath_t path, const PayAmount_t amount )
void GeniusSDKProcess( const JsonData_t jsondata )
{
GeniusNodeInstance->ProcessImage( std::string{ path }, amount );
GeniusNodeInstance->ProcessImage( std::string{ jsondata } );
}

uint64_t GeniusSDKGetBalance()
Expand All @@ -152,9 +169,15 @@ void GeniusSDKFreeTransactions( GeniusMatrix matrix )
free( matrix.ptr );
}

void GeniusSDKMintTokens( uint64_t amount )
GeniusMatrix GeniusSDKGetBlocks()
{
auto blocks = GeniusNodeInstance->GetBlocks();
return matrix_from_buffer( blocks );
}

void GeniusSDKMintTokens( uint64_t amount, const char *transaction_hash, const char *chain_id )
{
GeniusNodeInstance->MintTokens( amount );
GeniusNodeInstance->MintTokens( amount, transaction_hash, chain_id );
}

GeniusAddress GeniusSDKGetAddress()
Expand All @@ -174,3 +197,8 @@ bool GeniusSDKTransferTokens( uint64_t amount, GeniusAddress *dest )

return GeniusNodeInstance->TransferFunds( amount, destination );
}

uint64_t GeniusSDKGetCost( const JsonData_t jsondata )
{
return GeniusNodeInstance->GetProcessCost( jsondata );
}
8 changes: 5 additions & 3 deletions src/GeniusSDK.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,19 @@ typedef struct
char address[2 + 256 / 4 + 1];
} GeniusAddress;

typedef char ImagePath_t[1024]; ///< ID/Path of the image to be processed
typedef char JsonData_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, const char *eth_private_key );
GNUS_VISIBILITY_DEFAULT void GeniusSDKProcess( const ImagePath_t path, PayAmount_t amount );
GNUS_VISIBILITY_DEFAULT void GeniusSDKProcess( const JsonData_t jsondata );
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_VISIBILITY_DEFAULT GeniusMatrix GeniusSDKGetBlocks();
GNUS_VISIBILITY_DEFAULT void GeniusSDKMintTokens( uint64_t amount, const char *transaction_hash, const char *chain_id );
GNUS_VISIBILITY_DEFAULT GeniusAddress GeniusSDKGetAddress();
GNUS_VISIBILITY_DEFAULT bool GeniusSDKTransferTokens( uint64_t amount, GeniusAddress *dest );
GNUS_VISIBILITY_DEFAULT uint64_t GeniusSDKGetCost( const JsonData_t jsondata );

GNUS_EXPORT_END

Expand Down

0 comments on commit de08205

Please sign in to comment.