├── .editorconfig ├── .gitmodules ├── addressbook ├── mainnet.pb ├── testnet.pb └── previewnet.pb ├── .github ├── dependabot.yml └── workflows │ └── flow-pull-request-checks.yaml ├── .env.sample ├── src ├── CMakeLists.txt ├── sdk │ ├── main │ │ ├── include │ │ │ ├── impl │ │ │ │ ├── version.h.in │ │ │ │ ├── TLSBehavior.h │ │ │ │ ├── PublicKeyImpl.h │ │ │ │ ├── MirrorNodeContractCallQuery.h │ │ │ │ ├── MirrorNodeContractEstimateGasQuery.h │ │ │ │ ├── openssl_utils │ │ │ │ │ ├── EC_GROUP.h │ │ │ │ │ ├── EVP_PKEY.h │ │ │ │ │ ├── EVP_PKEY_CTX.h │ │ │ │ │ ├── EVP_MD.h │ │ │ │ │ ├── BN_CTX.h │ │ │ │ │ ├── EC_POINT.h │ │ │ │ │ ├── ECDSA_SIG.h │ │ │ │ │ ├── EVP_MD_CTX.h │ │ │ │ │ ├── OSSL_LIB_CTX.h │ │ │ │ │ └── OSSL_DECODER_CTX.h │ │ │ │ ├── PrivateKeyImpl.h │ │ │ │ ├── DurationConverter.h │ │ │ │ ├── ASN1Object.h │ │ │ │ ├── HttpClient.h │ │ │ │ ├── HexConverter.h │ │ │ │ ├── DerivationPathUtils.h │ │ │ │ ├── ASN1ED25519PublicKey.h │ │ │ │ ├── ASN1ED25519PrivateKey.h │ │ │ │ ├── MirrorNodeRouter.h │ │ │ │ └── ASN1ECKey.h │ │ │ ├── SubscriptionHandle.h │ │ │ ├── exceptions │ │ │ │ ├── OpenSSLException.h │ │ │ │ ├── BadKeyException.h │ │ │ │ ├── UninitializedException.h │ │ │ │ ├── BadMnemonicException.h │ │ │ │ ├── IllegalStateException.h │ │ │ │ ├── UnsupportedOperationException.h │ │ │ │ ├── MaxAttemptsExceededException.h │ │ │ │ ├── MaxQueryPaymentExceededException.h │ │ │ │ ├── ReceiptStatusException.h │ │ │ │ ├── BadEntityIdException.h │ │ │ │ └── PrecheckStatusException.h │ │ │ ├── TopicMessageChunk.h │ │ │ ├── TokenSupplyType.h │ │ │ ├── TokenKeyValidation.h │ │ │ ├── IPv4Address.h │ │ │ ├── CustomFeeBase.h │ │ │ ├── EthereumTransactionData.h │ │ │ ├── FeeAssessmentMethod.h │ │ │ ├── TokenType.h │ │ │ ├── FeeDataType.h │ │ │ └── Key.h │ │ └── src │ │ │ ├── SubscriptionHandle.cc │ │ │ ├── TopicMessageChunk.cc │ │ │ ├── impl │ │ │ ├── MirrorNodeRouter.cc │ │ │ ├── DurationConverter.cc │ │ │ ├── DerivationPathUtils.cc │ │ │ ├── MirrorNode.cc │ │ │ ├── ASN1ECPrivateKey.cc │ │ │ ├── ASN1ED25519PrivateKey.cc │ │ │ ├── ASN1ED25519PublicKey.cc │ │ │ ├── MirrorNodeContractCallQuery.cc │ │ │ ├── HieroCertificateVerifier.cc │ │ │ ├── ASN1ECKey.cc │ │ │ └── MirrorNodeContractEstimateGasQuery.cc │ │ │ ├── TokenSupplyType.cc │ │ │ ├── TokenType.cc │ │ │ ├── CustomFeeBase.cc │ │ │ ├── EthereumTransactionData.cc │ │ │ ├── TokenKeyValidation.cc │ │ │ ├── Key.cc │ │ │ ├── HbarAllowance.cc │ │ │ ├── IPv4Address.cc │ │ │ ├── PendingAirdropRecord.cc │ │ │ ├── NodeAddressBook.cc │ │ │ ├── TokenRejectFlow.cc │ │ │ ├── ProxyStaker.cc │ │ │ ├── LedgerId.cc │ │ │ ├── ExchangeRates.cc │ │ │ ├── TokenAssociation.cc │ │ │ ├── FeeSchedules.cc │ │ │ ├── FreezeType.cc │ │ │ ├── Endpoint.cc │ │ │ ├── AccountBalance.cc │ │ │ ├── FileInfoQuery.cc │ │ │ └── TokenInfoQuery.cc │ ├── tests │ │ ├── CMakeLists.txt │ │ ├── integration │ │ │ ├── AddressBookQueryIntegrationTests.cc │ │ │ ├── NetworkVersionInfoQueryIntegrationTests.cc │ │ │ ├── AccountStakersQueryIntegrationTests.cc │ │ │ ├── BaseIntegrationTest.cc │ │ │ ├── PrngTransactionIntegrationTests.cc │ │ │ ├── JSONIntegrationTests.cc │ │ │ ├── HttpClientIntegrationTests.cc │ │ │ ├── TransactionRecordQueryIntegrationTests.cc │ │ │ ├── TransactionReceiptQueryIntegrationTests.cc │ │ │ └── FreezeTransactionIntegrationTests.cc │ │ └── unit │ │ │ ├── TokenInfoQueryUnitTests.cc │ │ │ ├── TopicInfoQueryUnitTests.cc │ │ │ ├── FileInfoQueryUnitTests.cc │ │ │ ├── TokenNftInfoQueryUnitTests.cc │ │ │ ├── FileContentsQueryUnitTests.cc │ │ │ ├── ScheduleInfoQueryUnitTests.cc │ │ │ ├── AccountInfoQueryUnitTests.cc │ │ │ ├── ContractInfoQueryUnitTests.cc │ │ │ ├── ContractByteCodeQueryUnitTests.cc │ │ │ ├── BaseUnitTest.cc │ │ │ ├── FeeAssessmentMethodUnitTests.cc │ │ │ ├── AccountBalanceUnitTests.cc │ │ │ ├── AccountRecordsQueryUnitTests.cc │ │ │ ├── TransactionRecordQueryUnitTests.cc │ │ │ ├── TransactionReceiptQueryUnitTests.cc │ │ │ ├── TransactionResponseUnitTests.cc │ │ │ ├── NodeDeleteTransactionUnitTests.cc │ │ │ ├── AccountRecordsUnitTests.cc │ │ │ ├── TokenTypeUnitTests.cc │ │ │ ├── ProxyStakerUnitTests.cc │ │ │ ├── TokenSupplyTypeUnitTests.cc │ │ │ ├── BaseUnitTest.h │ │ │ ├── PrngTransactionUnitTests.cc │ │ │ ├── EthereumFlowUnitTests.cc │ │ │ ├── FileDeleteTransactionUnitTests.cc │ │ │ ├── TokenPauseTransactionUnitTests.cc │ │ │ └── AddressBookQueryUnitTests.cc │ ├── examples │ │ ├── VersionExample.cpp │ │ ├── precompile-example │ │ │ ├── IPrngSystemContract.sol │ │ │ ├── PrngSystemContract.sol │ │ │ ├── ExpiryHelper.sol │ │ │ └── KeyHelper.sol │ │ ├── GetAddressBookExample.cpp │ │ ├── GetAccountBalanceExample.cpp │ │ ├── PrngExample.cpp │ │ ├── InitializeClientWithMirrorNodeAddressBookExample.cpp │ │ ├── GeneratePrivateKeyFromSpecificMnemonicExample.cpp │ │ ├── GenerateKeyExample.cpp │ │ ├── GetAccountInfoExample.cpp │ │ ├── CreateTopicExample.cpp │ │ ├── DeleteFileExample.cpp │ │ ├── GetFileContentsExample.cpp │ │ └── ScheduleNetworkUpdateExample.cpp │ └── CMakeLists.txt └── tck │ ├── CMakeLists.txt │ ├── src │ ├── json │ │ ├── JsonUtils.cc │ │ └── JsonRpcException.cc │ └── sdk │ │ └── SdkClient.cc │ └── include │ ├── file │ └── FileService.h │ ├── json │ └── JsonErrorType.h │ ├── sdk │ ├── params │ │ └── ResetParams.h │ └── SdkClient.h │ ├── account │ └── params │ │ ├── allowance │ │ ├── HbarAllowanceParams.h │ │ └── TokenAllowanceParams.h │ │ ├── TransferCryptoParams.h │ │ ├── ApproveAllowanceParams.h │ │ └── DeleteAllowanceParams.h │ ├── token │ └── params │ │ ├── PauseTokenParams.h │ │ ├── DeleteTokenParams.h │ │ └── UnpauseTokenParams.h │ └── key │ └── KeyService.h ├── config └── local_node.json ├── SystemLibraries.cmake ├── run_examples.sh ├── .clang-tidy ├── run_examples.bat ├── proto └── service-external-proto │ └── sdk │ └── transaction_list.proto ├── vcpkg.json ├── CMakeLists.txt └── MAINTAINERS.md /.editorconfig: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "vcpkg"] 2 | path = vcpkg 3 | url = https://github.com/microsoft/vcpkg 4 | -------------------------------------------------------------------------------- /addressbook/mainnet.pb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hiero-ledger/hiero-sdk-cpp/HEAD/addressbook/mainnet.pb -------------------------------------------------------------------------------- /addressbook/testnet.pb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hiero-ledger/hiero-sdk-cpp/HEAD/addressbook/testnet.pb -------------------------------------------------------------------------------- /addressbook/previewnet.pb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hiero-ledger/hiero-sdk-cpp/HEAD/addressbook/previewnet.pb -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: "github-actions" 4 | directory: "/" 5 | schedule: 6 | interval: "daily" 7 | open-pull-requests-limit: 10 -------------------------------------------------------------------------------- /.env.sample: -------------------------------------------------------------------------------- 1 | OPERATOR_KEY= 2 | OPERATOR_ID= 3 | HIERO_NETWORK= 4 | CONFIG_FILE= 5 | PASSPHRASE= 6 | -------------------------------------------------------------------------------- /src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(sdk) 2 | # Optional TCK build 3 | option(BUILD_TCK "Build the TCK tests" OFF) 4 | 5 | if(BUILD_TCK) 6 | message(STATUS "Including TCK tests in the build.") 7 | add_subdirectory(tck) 8 | else() 9 | message(STATUS "TCK tests are not included in the build.") 10 | endif() 11 | -------------------------------------------------------------------------------- /config/local_node.json: -------------------------------------------------------------------------------- 1 | { 2 | "network": { 3 | "0.0.3": "127.0.0.1:50211" 4 | }, 5 | "mirrorNetwork": [ 6 | "127.0.0.1:5600" 7 | ], 8 | "operator": { 9 | "accountId": "0.0.2", 10 | "privateKey": "302e020100300506032b65700422042091132178e72057a1d7528025956fe39b0b847f200ab59b2fdd367017f3087137" 11 | } 12 | } -------------------------------------------------------------------------------- /src/sdk/main/include/impl/version.h.in: -------------------------------------------------------------------------------- 1 | #ifndef VERSION_H 2 | #define VERSION_H 3 | 4 | #define PROJECT_VERSION_MAJOR @PROJECT_VERSION_MAJOR@ 5 | #define PROJECT_VERSION_MINOR @PROJECT_VERSION_MINOR@ 6 | #define PROJECT_VERSION_PATCH @PROJECT_VERSION_PATCH@ 7 | #define PROJECT_VERSION_STRING "@PROJECT_VERSION@" 8 | #define PROJECT_DESCRIPTION "@PROJECT_DESCRIPTION@" 9 | 10 | #endif // VERSION_H 11 | -------------------------------------------------------------------------------- /src/sdk/tests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | if (APPLE OR WIN32) 2 | include(FetchContent) 3 | FetchContent_Declare(googletest 4 | GIT_REPOSITORY https://github.com/google/googletest.git 5 | GIT_TAG release-1.12.1) 6 | 7 | set(INSTALL_GTEST OFF CACHE BOOL "" FORCE) 8 | FetchContent_MakeAvailable(googletest) 9 | include(googletest) 10 | else () 11 | find_package(GTest REQUIRED) 12 | endif () 13 | 14 | add_subdirectory(unit) 15 | add_subdirectory(integration) 16 | -------------------------------------------------------------------------------- /src/sdk/examples/VersionExample.cpp: -------------------------------------------------------------------------------- 1 | #include "version.h" 2 | #include 3 | 4 | int main() 5 | { 6 | std::cout << "Project Description: "; 7 | std::cout << PROJECT_DESCRIPTION << std::endl; 8 | std::cout << "Project Software Version: "; 9 | std::cout << PROJECT_VERSION_MAJOR << "." << PROJECT_VERSION_MINOR << "." << PROJECT_VERSION_PATCH << std::endl; 10 | std::cout << "Project Version String: "; 11 | std::cout << PROJECT_VERSION_STRING << std::endl; 12 | 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /src/sdk/main/src/SubscriptionHandle.cc: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | #include "SubscriptionHandle.h" 3 | 4 | namespace Hiero 5 | { 6 | //----- 7 | SubscriptionHandle::~SubscriptionHandle() 8 | { 9 | unsubscribe(); 10 | } 11 | 12 | //----- 13 | void SubscriptionHandle::unsubscribe() const 14 | { 15 | mUnsubscribeFunc(); 16 | } 17 | 18 | //----- 19 | void SubscriptionHandle::setOnUnsubscribe(const std::function& onUnsubscribe) 20 | { 21 | mUnsubscribeFunc = onUnsubscribe; 22 | } 23 | 24 | } // namespace Hiero 25 | -------------------------------------------------------------------------------- /.github/workflows/flow-pull-request-checks.yaml: -------------------------------------------------------------------------------- 1 | name: PR Checks 2 | on: 3 | workflow_dispatch: 4 | pull_request: 5 | types: 6 | - opened 7 | - reopened 8 | - synchronize 9 | - closed 10 | 11 | defaults: 12 | run: 13 | shell: bash 14 | 15 | concurrency: 16 | group: pr-checks-${{ github.workflow }}-${{ github.head_ref || github.run_id }} 17 | cancel-in-progress: true 18 | 19 | permissions: 20 | contents: read 21 | 22 | jobs: 23 | build: 24 | name: Code 25 | uses: ./.github/workflows/zxc-build-library.yaml 26 | -------------------------------------------------------------------------------- /SystemLibraries.cmake: -------------------------------------------------------------------------------- 1 | 2 | if(NOT WIN32) 3 | if(NOT DEFINED RESOLV_LIBRARY) 4 | find_library(RESOLV_LIBRARY resolv) 5 | endif() 6 | 7 | add_library(sys::resolv STATIC IMPORTED) 8 | set_target_properties(sys::resolv PROPERTIES IMPORTED_LOCATION ${RESOLV_LIBRARY}) 9 | endif() 10 | 11 | if(APPLE) 12 | if(NOT DEFINED OSX_CORE_FOUNDATION) 13 | find_library(OSX_CORE_FOUNDATION CoreFoundation) 14 | endif() 15 | 16 | if(NOT DEFINED OSX_CF_NETWORK) 17 | find_library(OSX_CF_NETWORK CFNetwork) 18 | endif() 19 | endif() 20 | -------------------------------------------------------------------------------- /src/sdk/examples/precompile-example/IPrngSystemContract.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | pragma solidity >=0.4.9 <0.9.0; 3 | 4 | // This file was copied from github.com/hashgraph/hedera-smart-contracts on Aug 31 2022 5 | 6 | interface IPrngSystemContract { 7 | // Generates a 256-bit pseudorandom seed using the first 256-bits of running hash of n-3 transaction record. 8 | // Users can generate a pseudorandom number in a specified range using the seed by (integer value of seed % range) 9 | function getPseudorandomSeed() external returns (bytes32); 10 | } 11 | -------------------------------------------------------------------------------- /src/sdk/main/include/impl/TLSBehavior.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | #ifndef HIERO_SDK_CPP_IMPL_TLS_BEHAVIOR_H_ 3 | #define HIERO_SDK_CPP_IMPL_TLS_BEHAVIOR_H_ 4 | 5 | namespace Hiero::internal 6 | { 7 | /** 8 | * Enum representing different modes of network communication. 9 | */ 10 | enum class TLSBehavior 11 | { 12 | /** 13 | * Communicate only in the clear 14 | */ 15 | DISABLE, 16 | /** 17 | * Require TLS connection 18 | */ 19 | REQUIRE 20 | }; 21 | 22 | } // namespace Hiero::internal 23 | 24 | #endif // HIERO_SDK_CPP_IMPL_TLS_BEHAVIOR_H_ 25 | -------------------------------------------------------------------------------- /src/sdk/main/include/impl/PublicKeyImpl.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | #ifndef HIERO_SDK_CPP_IMPL_PUBLIC_KEY_IMPL_H_ 3 | #define HIERO_SDK_CPP_IMPL_PUBLIC_KEY_IMPL_H_ 4 | 5 | #include "PublicKey.h" 6 | #include "impl/openssl_utils/EVP_PKEY.h" 7 | 8 | namespace Hiero 9 | { 10 | /** 11 | * The implementation of the PublicKey object. 12 | */ 13 | struct PublicKey::PublicKeyImpl 14 | { 15 | /** 16 | * The wrapped OpenSSL key object. 17 | */ 18 | internal::OpenSSLUtils::EVP_PKEY mKey; 19 | }; 20 | } // namespace Hiero 21 | 22 | #endif // HIERO_SDK_CPP_IMPL_PUBLIC_KEY_IMPL_H_ 23 | -------------------------------------------------------------------------------- /src/tck/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(TCK_SERVER_NAME ${PROJECT_NAME}-tck) 2 | add_executable(${TCK_SERVER_NAME} 3 | src/account/AccountService.cc 4 | src/file/FileService.cc 5 | src/json/JsonRpcException.cc 6 | src/json/JsonUtils.cc 7 | src/key/KeyService.cc 8 | src/sdk/SdkClient.cc 9 | src/token/TokenService.cc 10 | src/main.cc 11 | src/TckServer.cc) 12 | 13 | target_link_libraries(${TCK_SERVER_NAME} ${PROJECT_NAME}) 14 | 15 | target_include_directories(${TCK_SERVER_NAME} PRIVATE include) 16 | 17 | install(TARGETS ${TCK_SERVER_NAME} RUNTIME DESTINATION tck) 18 | -------------------------------------------------------------------------------- /src/sdk/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Optional Examples build 2 | option(BUILD_EXAMPLES "Build the example builds" OFF) 3 | 4 | if(BUILD_EXAMPLES) 5 | message(STATUS "Including examples in the build.") 6 | add_subdirectory(examples) 7 | else() 8 | message(STATUS "Examples are not included in the build.") 9 | endif() 10 | add_subdirectory(main) 11 | # Optional Tests build 12 | option(BUILD_TESTS "Build the test suite" OFF) 13 | 14 | if(BUILD_TESTS) 15 | message(STATUS "Including tests in the build.") 16 | add_subdirectory(tests) 17 | else() 18 | message(STATUS "Tests are not included in the build.") 19 | endif() 20 | -------------------------------------------------------------------------------- /run_examples.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Script should be executed from project root 4 | # Directory containing executable files 5 | EXECUTABLES_DIRECTORY="build_folder_with_exec_binaries" 6 | 7 | if [ -d "$EXECUTABLES_DIRECTORY" ]; then 8 | echo "$EXECUTABLES_DIRECTORY does exist." 9 | fi 10 | 11 | # Iterate over all executables in the directory 12 | for file in "$EXECUTABLES_DIRECTORY"/*; do 13 | if [ -x "$file" ]; then 14 | echo "Running $file..." 15 | 16 | # Execute the binary executable without additional arguments 17 | "$file" 18 | 19 | echo "Done" 20 | fi 21 | done 22 | -------------------------------------------------------------------------------- /src/tck/src/json/JsonUtils.cc: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | #include "json/JsonUtils.h" 3 | 4 | #include 5 | #include 6 | 7 | namespace Hiero::TCK 8 | { 9 | //----- 10 | bool hasKeyType(const nlohmann::json& request, std::string_view key, nlohmann::json::value_t type) 11 | { 12 | return request.contains(key) && request.at(key).type() == type; 13 | } 14 | 15 | //----- 16 | bool hasValidId(const nlohmann::json& request) 17 | { 18 | return request.contains("id") && (request["id"].is_number() || request["id"].is_string() || request["id"].is_null()); 19 | } 20 | 21 | } // namespace Hiero::TCK 22 | -------------------------------------------------------------------------------- /src/sdk/tests/integration/AddressBookQueryIntegrationTests.cc: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | #include "AddressBookQuery.h" 3 | #include "BaseIntegrationTest.h" 4 | #include "FileId.h" 5 | #include "NodeAddressBook.h" 6 | 7 | #include 8 | 9 | using namespace Hiero; 10 | 11 | class AddressBookQueryIntegrationTests : public BaseIntegrationTest 12 | { 13 | }; 14 | 15 | //----- 16 | TEST_F(AddressBookQueryIntegrationTests, ExecuteAddressBookQuery) 17 | { 18 | // Given / When / Then 19 | EXPECT_NO_THROW(const NodeAddressBook nodeAddressBook = 20 | AddressBookQuery().setFileId(FileId::ADDRESS_BOOK).execute(getTestClient())); 21 | } 22 | -------------------------------------------------------------------------------- /src/sdk/tests/integration/NetworkVersionInfoQueryIntegrationTests.cc: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | #include "BaseIntegrationTest.h" 3 | #include "NetworkVersionInfo.h" 4 | #include "NetworkVersionInfoQuery.h" 5 | #include "TransactionReceipt.h" 6 | 7 | #include 8 | 9 | using namespace Hiero; 10 | 11 | class NetworkVersionInfoQueryIntegrationTests : public BaseIntegrationTest 12 | { 13 | }; 14 | 15 | //----- 16 | TEST_F(NetworkVersionInfoQueryIntegrationTests, ExecuteNetworkVersionInfoQuery) 17 | { 18 | // Given / When / Then 19 | EXPECT_NO_THROW(const NetworkVersionInfo networkVersionInfo = NetworkVersionInfoQuery().execute(getTestClient())); 20 | } 21 | -------------------------------------------------------------------------------- /.clang-tidy: -------------------------------------------------------------------------------- 1 | # Generated from CLion Inspection settings 2 | --- 3 | Checks: '-*, 4 | cert-dcl21-cpp, 5 | cert-dcl58-cpp, 6 | cert-err34-c, 7 | cert-err52-cpp, 8 | cert-err60-cpp, 9 | cert-flp30-c, 10 | cert-msc50-cpp, 11 | cert-msc51-cpp, 12 | cert-str34-c, 13 | google-default-arguments, 14 | google-explicit-constructor, 15 | google-runtime-operator, 16 | hicpp-exception-baseclass, 17 | hicpp-multiway-paths-covered, 18 | mpi-buffer-deref, 19 | mpi-type-mismatch, 20 | openmp-use-default-none, 21 | portability-simd-intrinsics, 22 | bugprone-*, 23 | clang-analyzer-*, 24 | cppcoreguidelines-*, 25 | misc-*, 26 | modernize-*, 27 | performance-*, 28 | readability-*, 29 | -modernize-use-trailing-return-type' -------------------------------------------------------------------------------- /run_examples.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | REM Script should be executed from project root 4 | REM Directory containing executable files 5 | set EXECUTABLES_DIRECTORY=build_folder_with_exec_binaries 6 | 7 | if exist %EXECUTABLES_DIRECTORY% ( 8 | echo %EXECUTABLES_DIRECTORY% does exist. 9 | 10 | REM Iterate over all executables in the directory 11 | for %%f in (%EXECUTABLES_DIRECTORY%\*.exe) do ( 12 | if exist "%%f" ( 13 | echo Running %%f... 14 | 15 | REM Execute the binary executable without additional arguments 16 | "%%f" 17 | 18 | echo Done 19 | ) 20 | ) 21 | ) else ( 22 | echo %EXECUTABLES_DIRECTORY% does not exist. 23 | ) 24 | 25 | pause 26 | -------------------------------------------------------------------------------- /src/sdk/tests/unit/TokenInfoQueryUnitTests.cc: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | #include "TokenInfoQuery.h" 3 | 4 | #include 5 | 6 | using namespace Hiero; 7 | 8 | class TokenInfoQueryUnitTests : public ::testing::Test 9 | { 10 | protected: 11 | [[nodiscard]] inline const TokenId& getTestTokenId() const { return mTestTokenId; } 12 | 13 | private: 14 | const TokenId mTestTokenId = TokenId(1ULL); 15 | }; 16 | 17 | //----- 18 | TEST_F(TokenInfoQueryUnitTests, GetSetTokenId) 19 | { 20 | // Given 21 | TokenInfoQuery query; 22 | 23 | // When 24 | query.setTokenId(getTestTokenId()); 25 | 26 | // Then 27 | EXPECT_EQ(query.getTokenId(), getTestTokenId()); 28 | } 29 | -------------------------------------------------------------------------------- /src/sdk/tests/unit/TopicInfoQueryUnitTests.cc: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | #include "TopicInfoQuery.h" 3 | 4 | #include 5 | 6 | using namespace Hiero; 7 | 8 | class TopicInfoQueryUnitTests : public ::testing::Test 9 | { 10 | protected: 11 | [[nodiscard]] inline const TopicId& getTestTopicId() const { return mTestTopicId; } 12 | 13 | private: 14 | const TopicId mTestTopicId = TopicId(1ULL); 15 | }; 16 | 17 | //----- 18 | TEST_F(TopicInfoQueryUnitTests, GetSetTopicId) 19 | { 20 | // Given 21 | TopicInfoQuery query; 22 | 23 | // When 24 | query.setTopicId(getTestTopicId()); 25 | 26 | // Then 27 | EXPECT_EQ(query.getTopicId(), getTestTopicId()); 28 | } 29 | -------------------------------------------------------------------------------- /src/sdk/main/src/TopicMessageChunk.cc: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | #include "TopicMessageChunk.h" 3 | #include "impl/TimestampConverter.h" 4 | #include "impl/Utilities.h" 5 | 6 | #include 7 | 8 | namespace Hiero 9 | { 10 | //----- 11 | TopicMessageChunk::TopicMessageChunk(const com::hedera::mirror::api::proto::ConsensusTopicResponse& proto) 12 | : mConsensusTimestamp(internal::TimestampConverter::fromProtobuf(proto.consensustimestamp())) 13 | , mContentSize(proto.message().size()) 14 | , mRunningHash(internal::Utilities::stringToByteVector(proto.runninghash())) 15 | , mSequenceNumber(proto.sequencenumber()) 16 | { 17 | } 18 | 19 | } // namespace Hiero 20 | -------------------------------------------------------------------------------- /src/sdk/main/src/impl/MirrorNodeRouter.cc: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | #include "impl/MirrorNodeRouter.h" 3 | #include "impl/Utilities.h" 4 | 5 | #include 6 | #include 7 | 8 | namespace Hiero::internal::MirrorNodeGateway 9 | { 10 | //----- 11 | std::string MirrorNodeRouter::getRoute(std::string_view queryType) const 12 | { 13 | std::string queryRoute; 14 | auto route = routes.find(queryType.data()); 15 | if (route != routes.end()) 16 | { 17 | queryRoute = route->second; 18 | } 19 | else 20 | { 21 | throw std::runtime_error("Route not found in the routes map"); 22 | } 23 | return queryRoute; 24 | } 25 | } // namespace Hiero::internal::MirrorNodeGateway -------------------------------------------------------------------------------- /src/sdk/tests/unit/FileInfoQueryUnitTests.cc: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | #include "FileInfo.h" 3 | #include "FileInfoQuery.h" 4 | 5 | #include 6 | 7 | using namespace Hiero; 8 | 9 | class FileInfoQueryUnitTests : public ::testing::Test 10 | { 11 | protected: 12 | [[nodiscard]] inline const FileId& getTestFileId() const { return mTestFileId; } 13 | 14 | private: 15 | const FileId mTestFileId = FileId(1ULL); 16 | }; 17 | 18 | //----- 19 | TEST_F(FileInfoQueryUnitTests, GetSetFileId) 20 | { 21 | // Given 22 | FileInfoQuery query; 23 | 24 | // When 25 | query.setFileId(getTestFileId()); 26 | 27 | // Then 28 | EXPECT_EQ(query.getfileId(), getTestFileId()); 29 | } 30 | -------------------------------------------------------------------------------- /src/sdk/tests/unit/TokenNftInfoQueryUnitTests.cc: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | #include "TokenNftInfoQuery.h" 3 | 4 | #include 5 | 6 | using namespace Hiero; 7 | 8 | class TokenNftInfoQueryUnitTests : public ::testing::Test 9 | { 10 | protected: 11 | [[nodiscard]] inline const NftId& getTestNftId() const { return mTestNftId; } 12 | 13 | private: 14 | const NftId mTestNftId = NftId(TokenId(1ULL, 2ULL, 3ULL), 4ULL); 15 | }; 16 | 17 | //----- 18 | TEST_F(TokenNftInfoQueryUnitTests, GetSetNftId) 19 | { 20 | // Given 21 | TokenNftInfoQuery query; 22 | 23 | // When 24 | query.setNftId(getTestNftId()); 25 | 26 | // Then 27 | EXPECT_EQ(query.getNftId(), getTestNftId()); 28 | } 29 | -------------------------------------------------------------------------------- /src/sdk/main/src/impl/DurationConverter.cc: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | #include "impl/DurationConverter.h" 3 | 4 | #include 5 | 6 | namespace Hiero::internal::DurationConverter 7 | { 8 | //---- 9 | std::chrono::seconds fromProtobuf(const proto::Duration& duration) 10 | { 11 | return std::chrono::seconds(duration.seconds()); 12 | } 13 | 14 | //----- 15 | proto::Duration* toProtobuf(const std::chrono::system_clock::duration& duration) 16 | { 17 | auto proto = std::make_unique(); 18 | proto->set_seconds(std::chrono::duration_cast(duration).count()); 19 | return proto.release(); 20 | } 21 | 22 | } // namespace Hiero::internal::DurationConverter 23 | -------------------------------------------------------------------------------- /src/sdk/tests/unit/FileContentsQueryUnitTests.cc: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | #include "FileContentsQuery.h" 3 | #include "FileId.h" 4 | 5 | #include 6 | 7 | using namespace Hiero; 8 | 9 | class FileContentsQueryUnitTests : public ::testing::Test 10 | { 11 | protected: 12 | [[nodiscard]] inline const FileId& getTestFileId() const { return mTestFileId; } 13 | 14 | private: 15 | const FileId mTestFileId = FileId(1ULL); 16 | }; 17 | 18 | //----- 19 | TEST_F(FileContentsQueryUnitTests, GetSetFileId) 20 | { 21 | // Given 22 | FileContentsQuery query; 23 | 24 | // When 25 | query.setFileId(getTestFileId()); 26 | 27 | // Then 28 | EXPECT_EQ(query.getFileId(), getTestFileId()); 29 | } 30 | -------------------------------------------------------------------------------- /src/sdk/tests/unit/ScheduleInfoQueryUnitTests.cc: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | #include "ScheduleInfoQuery.h" 3 | 4 | #include 5 | 6 | using namespace Hiero; 7 | 8 | class ScheduleInfoQueryUnitTests : public ::testing::Test 9 | { 10 | protected: 11 | [[nodiscard]] inline const ScheduleId& getTestScheduleId() const { return mTestScheduleId; } 12 | 13 | private: 14 | const ScheduleId mTestScheduleId = ScheduleId(1ULL); 15 | }; 16 | 17 | //----- 18 | TEST_F(ScheduleInfoQueryUnitTests, GetSetScheduleId) 19 | { 20 | // Given 21 | ScheduleInfoQuery query; 22 | 23 | // When 24 | query.setScheduleId(getTestScheduleId()); 25 | 26 | // Then 27 | EXPECT_EQ(query.getScheduleId(), getTestScheduleId()); 28 | } 29 | -------------------------------------------------------------------------------- /src/sdk/main/include/impl/MirrorNodeContractCallQuery.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | #ifndef HIERO_SDK_CPP_MIRROR_NODE_CONTRACT_CALL_QUERY_H_ 3 | #define HIERO_SDK_CPP_MIRROR_NODE_CONTRACT_CALL_QUERY_H_ 4 | 5 | #include "impl/MirrorNodeContractQuery.h" 6 | 7 | namespace Hiero 8 | { 9 | class MirrorNodeContractCallQuery : public MirrorNodeContractQuery 10 | { 11 | public: 12 | /** 13 | * Executes the Mirror Node query. 14 | * 15 | * @param client The Client object used for network access. 16 | * @return The result of the execution in string format. 17 | */ 18 | [[nodiscard]] std::string execute(const Client& client) override; 19 | }; 20 | } // namespace Hiero 21 | 22 | #endif // HIERO_SDK_CPP_MIRROR_NODE_CONTRACT_CALL_QUERY_H_ -------------------------------------------------------------------------------- /src/sdk/tests/unit/AccountInfoQueryUnitTests.cc: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | #include "AccountId.h" 3 | #include "AccountInfoQuery.h" 4 | 5 | #include 6 | 7 | using namespace Hiero; 8 | 9 | class AccountInfoQueryUnitTests : public ::testing::Test 10 | { 11 | protected: 12 | [[nodiscard]] inline const AccountId& getTestAccountId() const { return mTestAccountId; } 13 | 14 | private: 15 | const AccountId mTestAccountId = AccountId(1ULL); 16 | }; 17 | 18 | //----- 19 | TEST_F(AccountInfoQueryUnitTests, GetSetAccountId) 20 | { 21 | // Given 22 | AccountInfoQuery query; 23 | 24 | // When 25 | query.setAccountId(getTestAccountId()); 26 | 27 | // Then 28 | EXPECT_EQ(query.getAccountId(), getTestAccountId()); 29 | } 30 | -------------------------------------------------------------------------------- /proto/service-external-proto/sdk/transaction_list.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package proto; 4 | 5 | option java_package = "com.hedera.hashgraph.sdk.proto"; 6 | option java_multiple_files = true; 7 | 8 | import "services/transaction.proto"; 9 | 10 | /** 11 | * A simple protobuf wrapper to store a list of transactions. This is used by 12 | * `Transaction.[from|to]Bytes()` in the SDKs. The reason the SDK needs a list of transactions is 13 | * because it holds onto a transaction per node. So if a transaction is to be submitted to nodes 3 14 | * and 4 the SDK Transaction type would contain a list of 2 protobuf transactions, one for node 3 15 | * and one for node 4. 16 | */ 17 | message TransactionList { 18 | repeated Transaction transaction_list = 1; 19 | } 20 | -------------------------------------------------------------------------------- /src/sdk/tests/integration/AccountStakersQueryIntegrationTests.cc: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | #include "AccountStakersQuery.h" 3 | #include "BaseIntegrationTest.h" 4 | #include "ProxyStaker.h" 5 | #include "exceptions/PrecheckStatusException.h" 6 | 7 | #include 8 | 9 | using namespace Hiero; 10 | 11 | class AccountStakersQueryIntegrationTests : public BaseIntegrationTest 12 | { 13 | }; 14 | 15 | //----- 16 | TEST_F(AccountStakersQueryIntegrationTests, ExecuteAccountStakersQuery) 17 | { 18 | // Given / When / Then 19 | EXPECT_THROW(const AccountStakers accountStakers = 20 | AccountStakersQuery().setAccountId(AccountId(2ULL)).execute(getTestClient()), 21 | PrecheckStatusException); // NOT_SUPPORTED 22 | } 23 | -------------------------------------------------------------------------------- /src/sdk/examples/precompile-example/PrngSystemContract.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | 3 | // This file was copied from github.com/hashgraph/hedera-smart-contracts on Aug 31 2022 4 | 5 | import "./IPrngSystemContract.sol"; 6 | 7 | contract PrngSystemContract { 8 | // Prng system contract address with ContractID 0.0.361 9 | address constant PRECOMPILE_ADDRESS = address(0x169); 10 | 11 | function getPseudorandomSeed() external returns (bytes32 seedBytes) { 12 | (bool success, bytes memory result) = PRECOMPILE_ADDRESS.call( 13 | abi.encodeWithSelector(IPrngSystemContract.getPseudorandomSeed.selector)); 14 | require(success, "PRNG system call failed"); 15 | seedBytes = abi.decode(result, (bytes32)); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/sdk/tests/unit/ContractInfoQueryUnitTests.cc: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | #include "ContractId.h" 3 | #include "ContractInfoQuery.h" 4 | 5 | #include 6 | 7 | using namespace Hiero; 8 | 9 | class ContractInfoQueryUnitTests : public ::testing::Test 10 | { 11 | protected: 12 | [[nodiscard]] inline const ContractId& getTestContractId() const { return mTestContractId; } 13 | 14 | private: 15 | const ContractId mTestContractId = ContractId(1ULL); 16 | }; 17 | 18 | //----- 19 | TEST_F(ContractInfoQueryUnitTests, GetSetContractId) 20 | { 21 | // Given 22 | ContractInfoQuery query; 23 | 24 | // When 25 | query.setContractId(getTestContractId()); 26 | 27 | // Then 28 | EXPECT_EQ(query.getContractId(), getTestContractId()); 29 | } 30 | -------------------------------------------------------------------------------- /src/sdk/main/include/impl/MirrorNodeContractEstimateGasQuery.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | #ifndef HIERO_SDK_CPP_MIRROR_NODE_CONTRACT_ESTIMATE_GAS_QUERY_H_ 3 | #define HIERO_SDK_CPP_MIRROR_NODE_CONTRACT_ESTIMATE_GAS_QUERY_H_ 4 | 5 | #include "impl/MirrorNodeContractQuery.h" 6 | 7 | namespace Hiero 8 | { 9 | class MirrorNodeContractEstimateGasQuery : public MirrorNodeContractQuery 10 | { 11 | public: 12 | /** 13 | * Executes the Mirror Node query. 14 | * 15 | * @param client The Client object used for network access. 16 | * @return The result of the execution in string format. 17 | */ 18 | [[nodiscard]] std::string execute(const Client& client) override; 19 | }; 20 | } // namespace Hiero 21 | 22 | #endif // HIERO_SDK_CPP_MIRROR_NODE_CONTRACT_ESTIMATE_GAS_QUERY_H_ -------------------------------------------------------------------------------- /src/sdk/tests/unit/ContractByteCodeQueryUnitTests.cc: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | #include "ContractByteCodeQuery.h" 3 | #include "ContractId.h" 4 | 5 | #include 6 | 7 | using namespace Hiero; 8 | 9 | class ContractByteCodeQueryUnitTests : public ::testing::Test 10 | { 11 | protected: 12 | [[nodiscard]] inline const ContractId& getTestContractId() const { return mTestContractId; } 13 | 14 | private: 15 | const ContractId mTestContractId = ContractId(1ULL); 16 | }; 17 | 18 | //----- 19 | TEST_F(ContractByteCodeQueryUnitTests, GetSetContractId) 20 | { 21 | // Given 22 | ContractByteCodeQuery query; 23 | 24 | // When 25 | query.setContractId(getTestContractId()); 26 | 27 | // Then 28 | EXPECT_EQ(query.getContractId(), getTestContractId()); 29 | } 30 | -------------------------------------------------------------------------------- /src/sdk/tests/unit/BaseUnitTest.cc: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | #include "BaseUnitTest.h" 3 | 4 | namespace Hiero 5 | { 6 | //----- 7 | void BaseUnitTest::SetUp() 8 | { 9 | // Set up the test Client mock with a default operator account ID and private key. 10 | mClientMock = Client::forNetwork({ 11 | { "0.client.mock.com:50211", AccountId(3ULL) }, 12 | { "1.client.mock.com:50211", AccountId(4ULL) } 13 | }); 14 | mClientMock.setMirrorNetwork({ { "0.mirror.mock.com:5551" } }); 15 | mClientMock.setOperator(mOperatorMockAccountId, mOperatorMockPrivateKey); 16 | 17 | // Set up a mock TransactionId with a valid start time. 18 | mTransactionIdMock = TransactionId::withValidStart(mOperatorMockAccountId, std::chrono::system_clock::now()); 19 | } 20 | 21 | } // namespace Hiero 22 | -------------------------------------------------------------------------------- /src/sdk/tests/unit/FeeAssessmentMethodUnitTests.cc: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | #include "FeeAssessmentMethod.h" 3 | 4 | #include 5 | 6 | using namespace Hiero; 7 | 8 | class FeeAssessmentMethodUnitTests : public ::testing::Test 9 | { 10 | }; 11 | 12 | //----- 13 | TEST_F(FeeAssessmentMethodUnitTests, FeeAssessmentMethodToString) 14 | { 15 | // Given / When / Then 16 | ASSERT_TRUE(gFeeAssessmentMethodToString.find(FeeAssessmentMethod::INCLUSIVE) != gFeeAssessmentMethodToString.end()); 17 | ASSERT_TRUE(gFeeAssessmentMethodToString.find(FeeAssessmentMethod::EXCLUSIVE) != gFeeAssessmentMethodToString.end()); 18 | EXPECT_EQ(gFeeAssessmentMethodToString.at(FeeAssessmentMethod::INCLUSIVE), "INCLUSIVE"); 19 | EXPECT_EQ(gFeeAssessmentMethodToString.at(FeeAssessmentMethod::EXCLUSIVE), "EXCLUSIVE"); 20 | } -------------------------------------------------------------------------------- /src/sdk/examples/GetAddressBookExample.cpp: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | #include "AddressBookQuery.h" 3 | #include "Client.h" 4 | #include "FileId.h" 5 | #include "NodeAddressBook.h" 6 | 7 | #include 8 | 9 | using namespace Hiero; 10 | 11 | int main(int argc, char** argv) 12 | { 13 | // Create a client for the Hiero network of which to get the address book. 14 | Client client = Client::forTestnet(); 15 | 16 | // Query for the address book using the client. 17 | const NodeAddressBook nodeAddressBook = AddressBookQuery().setFileId(FileId::ADDRESS_BOOK).execute(client); 18 | 19 | // Print off the received addresses contained in the address book. 20 | for (const auto& nodeAddress : nodeAddressBook.getNodeAddresses()) 21 | { 22 | std::cout << nodeAddress.toString() << std::endl; 23 | } 24 | 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /src/sdk/examples/precompile-example/ExpiryHelper.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | pragma solidity >=0.5.0 <0.9.0; 3 | pragma experimental ABIEncoderV2; 4 | 5 | // This file was copied from github.com/hashgraph/hedera-smart-contracts on Aug 31 2022 6 | 7 | import "./HederaTokenService.sol"; 8 | import "./FeeHelper.sol"; 9 | 10 | contract ExpiryHelper is FeeHelper { 11 | 12 | function createAutoRenewExpiry( 13 | address autoRenewAccount, 14 | uint32 autoRenewPeriod 15 | ) internal view returns (IHederaTokenService.Expiry memory expiry) { 16 | expiry.autoRenewAccount = autoRenewAccount; 17 | expiry.autoRenewPeriod = autoRenewPeriod; 18 | } 19 | 20 | function createSecondExpiry(uint32 second) internal view returns (IHederaTokenService.Expiry memory expiry) { 21 | expiry.second = second; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/tck/src/json/JsonRpcException.cc: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | #include "json/JsonRpcException.h" 3 | #include "json/JsonErrorType.h" 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | namespace Hiero::TCK 10 | { 11 | //----- 12 | JsonRpcException::JsonRpcException(JsonErrorType code, std::string_view message) noexcept 13 | : mCode(code) 14 | , mMessage(message) 15 | , mData(nullptr) 16 | , mError(std::to_string(static_cast(code)) + ": " + mMessage) 17 | { 18 | } 19 | 20 | //----- 21 | JsonRpcException::JsonRpcException(JsonErrorType code, std::string_view message, nlohmann::json data) noexcept 22 | : mCode(code) 23 | , mMessage(message) 24 | , mData(std::move(data)) 25 | , mError(std::to_string(static_cast(code)) + ": " + mMessage + ", data: " + mData.dump()) 26 | { 27 | } 28 | 29 | } // namespace Hiero::TCK 30 | -------------------------------------------------------------------------------- /src/sdk/main/include/impl/openssl_utils/EC_GROUP.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | #ifndef HIERO_SDK_CPP_IMPL_OPENSSL_UTILS_EC_GROUP_H_ 3 | #define HIERO_SDK_CPP_IMPL_OPENSSL_UTILS_EC_GROUP_H_ 4 | 5 | #include "impl/openssl_utils/OpenSSLObjectWrapper.h" 6 | 7 | #include 8 | 9 | namespace Hiero::internal::OpenSSLUtils 10 | { 11 | /** 12 | * Wrapper class for the OpenSSL EC_GROUP object. 13 | */ 14 | class EC_GROUP : public OpenSSLObjectWrapper<::EC_GROUP> 15 | { 16 | public: 17 | /** 18 | * Construct with the input EC_GROUP, its EC_GROUP_free deleter, and its EC_GROUP_dup copier. 19 | * 20 | * @param ecGroup The EC_GROUP OpenSSL object to wrap. 21 | */ 22 | explicit EC_GROUP(::EC_GROUP* ecGroup) 23 | : OpenSSLObjectWrapper(ecGroup, &EC_GROUP_free, &EC_GROUP_dup) 24 | { 25 | } 26 | }; 27 | 28 | } // namespace Hiero::internal::OpenSSLUtils 29 | 30 | #endif // HIERO_SDK_CPP_IMPL_OPENSSL_UTILS_EC_GROUP_H_ -------------------------------------------------------------------------------- /vcpkg.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "hiero-sdk-cpp", 3 | "version-string": "0.1.0", 4 | "builtin-baseline": "ce613c41372b23b1f51333815feb3edd87ef8a8b", 5 | "dependencies": [ 6 | { 7 | "name": "openssl", 8 | "version>=": "3.2.0#2" 9 | }, 10 | { 11 | "name": "pthreads", 12 | "version>=": "3.0.0#11" 13 | }, 14 | { 15 | "name": "zlib", 16 | "version>=": "1.2.12" 17 | }, 18 | { 19 | "name": "protobuf", 20 | "version>=": "3.21.6" 21 | }, 22 | { 23 | "name": "grpc", 24 | "version>=": "1.49.0" 25 | }, 26 | { 27 | "name": "nlohmann-json" 28 | }, 29 | { 30 | "name": "expat" 31 | }, 32 | { 33 | "name": "apr", 34 | "version>=": "1.7.4" 35 | }, 36 | { 37 | "name": "apr-util", 38 | "version>=": "1.6.1#8" 39 | }, 40 | { 41 | "name": "cpp-httplib", 42 | "version>=": "0.14.1" 43 | } 44 | ] 45 | } -------------------------------------------------------------------------------- /src/sdk/tests/unit/AccountBalanceUnitTests.cc: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | #include "AccountBalance.h" 3 | 4 | #include 5 | #include 6 | 7 | using namespace Hiero; 8 | 9 | class AccountBalanceUnitTests : public ::testing::Test 10 | { 11 | protected: 12 | [[nodiscard]] inline const Hbar& getTestBalance() const { return mBalance; } 13 | 14 | private: 15 | const Hbar mBalance = Hbar(100LL); 16 | }; 17 | 18 | //----- 19 | TEST_F(AccountBalanceUnitTests, DeserializeAccountBalanceFromProtobuf) 20 | { 21 | // Given 22 | proto::CryptoGetAccountBalanceResponse testProtoAccountBalance; 23 | testProtoAccountBalance.set_balance(static_cast(getTestBalance().toTinybars())); 24 | 25 | // When 26 | const AccountBalance accountBalance = AccountBalance::fromProtobuf(testProtoAccountBalance); 27 | 28 | // Then 29 | EXPECT_EQ(accountBalance.mBalance, getTestBalance()); 30 | } -------------------------------------------------------------------------------- /src/sdk/main/src/TokenSupplyType.cc: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | #include "TokenSupplyType.h" 3 | 4 | #include 5 | 6 | namespace Hiero 7 | { 8 | //----- 9 | const std::unordered_map gProtobufTokenSupplyTypeToTokenSupplyType = { 10 | {proto::TokenSupplyType::INFINITE, TokenSupplyType::INFINITE}, 11 | { proto::TokenSupplyType::FINITE, TokenSupplyType::FINITE } 12 | }; 13 | 14 | //----- 15 | const std::unordered_map gTokenSupplyTypeToProtobufTokenSupplyType = { 16 | {TokenSupplyType::INFINITE, proto::TokenSupplyType::INFINITE}, 17 | { TokenSupplyType::FINITE, proto::TokenSupplyType::FINITE } 18 | }; 19 | 20 | //----- 21 | const std::unordered_map gTokenSupplyTypeToString = { 22 | {TokenSupplyType::INFINITE, "INFINITE"}, 23 | { TokenSupplyType::FINITE, "FINITE" } 24 | }; 25 | 26 | } // namespace Hiero 27 | -------------------------------------------------------------------------------- /src/sdk/tests/unit/AccountRecordsQueryUnitTests.cc: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | #include "AccountRecordsQuery.h" 3 | 4 | #include 5 | 6 | using namespace Hiero; 7 | 8 | class AccountRecordsQueryUnitTests : public ::testing::Test 9 | { 10 | protected: 11 | [[nodiscard]] inline const AccountId& getTestAccountId() const { return mTestAccountId; } 12 | 13 | private: 14 | const AccountId mTestAccountId = AccountId(1ULL); 15 | }; 16 | 17 | //----- 18 | TEST_F(AccountRecordsQueryUnitTests, ConstructAccountRecordsQuery) 19 | { 20 | // Given / When 21 | AccountRecordsQuery query; 22 | 23 | // Then 24 | EXPECT_EQ(query.getAccountId(), AccountId()); 25 | } 26 | 27 | //----- 28 | TEST_F(AccountRecordsQueryUnitTests, SetAccountId) 29 | { 30 | // Given 31 | AccountRecordsQuery query; 32 | 33 | // When 34 | query.setAccountId(getTestAccountId()); 35 | 36 | // Then 37 | EXPECT_EQ(query.getAccountId(), getTestAccountId()); 38 | } 39 | -------------------------------------------------------------------------------- /src/tck/include/file/FileService.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | #ifndef HIERO_TCK_CPP_FILE_SERVICE_H_ 3 | #define HIERO_TCK_CPP_FILE_SERVICE_H_ 4 | 5 | #include 6 | 7 | namespace Hiero::TCK::FileService 8 | { 9 | /** 10 | * Forward declarations. 11 | */ 12 | struct CreateFileParams; 13 | struct UpdateFileParams; 14 | 15 | /** 16 | * Create a file. 17 | * 18 | * @param params The parameters to use to create a file. 19 | * @return A JSON response containing the created file ID and the status of the file creation. 20 | */ 21 | nlohmann::json createFile(const CreateFileParams& params); 22 | 23 | /** 24 | * Update a file. 25 | * 26 | * @param params The parameters to use to update a file. 27 | * @return A JSON response containing the status of the file update. 28 | */ 29 | nlohmann::json updateFile(const UpdateFileParams& params); 30 | 31 | } // namespace Hiero::TCK::FileService 32 | 33 | #endif // HIERO_TCK_CPP_FILE_SERVICE_H_ -------------------------------------------------------------------------------- /src/sdk/main/src/TokenType.cc: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | #include "TokenType.h" 3 | 4 | #include 5 | 6 | namespace Hiero 7 | { 8 | //----- 9 | const std::unordered_map gProtobufTokenTypeToTokenType = { 10 | {proto::TokenType::FUNGIBLE_COMMON, TokenType::FUNGIBLE_COMMON }, 11 | { proto::TokenType::NON_FUNGIBLE_UNIQUE, TokenType::NON_FUNGIBLE_UNIQUE} 12 | }; 13 | 14 | //----- 15 | const std::unordered_map gTokenTypeToProtobufTokenType = { 16 | {TokenType::FUNGIBLE_COMMON, proto::TokenType::FUNGIBLE_COMMON }, 17 | { TokenType::NON_FUNGIBLE_UNIQUE, proto::TokenType::NON_FUNGIBLE_UNIQUE} 18 | }; 19 | 20 | //----- 21 | const std::unordered_map gTokenTypeToString = { 22 | {TokenType::FUNGIBLE_COMMON, "FUNGIBLE_COMMON" }, 23 | { TokenType::NON_FUNGIBLE_UNIQUE, "NON_FUNGIBLE_UNIQUE"} 24 | }; 25 | 26 | } // namespace Hiero 27 | -------------------------------------------------------------------------------- /src/sdk/main/include/impl/PrivateKeyImpl.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | #ifndef HIERO_SDK_CPP_IMPL_PRIVATE_KEY_IMPL_H_ 3 | #define HIERO_SDK_CPP_IMPL_PRIVATE_KEY_IMPL_H_ 4 | 5 | #include "PrivateKey.h" 6 | #include "impl/openssl_utils/EVP_PKEY.h" 7 | 8 | #include 9 | #include 10 | 11 | namespace Hiero 12 | { 13 | /** 14 | * The implementation of the PrivateKey object. 15 | */ 16 | struct PrivateKey::PrivateKeyImpl 17 | { 18 | /** 19 | * The wrapped OpenSSL key object. 20 | */ 21 | internal::OpenSSLUtils::EVP_PKEY mKey; 22 | 23 | /** 24 | * The chain code. If this is empty, then this PrivateKey will not support derivation. 25 | */ 26 | std::vector mChainCode; 27 | 28 | /** 29 | * A pointer to the PublicKey object that corresponds to this PrivateKey. 30 | */ 31 | std::shared_ptr mPublicKey = nullptr; 32 | }; 33 | 34 | } // namespace Hiero 35 | 36 | #endif // HIERO_SDK_CPP_IMPL_PRIVATE_KEY_IMPL_H_ 37 | -------------------------------------------------------------------------------- /src/sdk/main/src/CustomFeeBase.cc: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | #include "CustomFeeBase.h" 3 | #include "CustomFixedFee.h" 4 | #include "CustomFractionalFee.h" 5 | #include "CustomRoyaltyFee.h" 6 | 7 | #include 8 | 9 | namespace Hiero 10 | { 11 | //----- 12 | template 13 | FeeType& CustomFeeBase::setFeeCollectorAccountId(const AccountId& accountId) 14 | { 15 | mFeeCollectorAccountId = accountId; 16 | return static_cast(*this); 17 | } 18 | 19 | //----- 20 | template 21 | FeeType& CustomFeeBase::setAllCollectorsAreExempt(bool exempt) 22 | { 23 | mAllCollectorsAreExempt = exempt; 24 | return static_cast(*this); 25 | } 26 | 27 | /** 28 | * Explicit template instantiations 29 | */ 30 | template class CustomFeeBase; 31 | template class CustomFeeBase; 32 | template class CustomFeeBase; 33 | 34 | } // namespace Hiero 35 | -------------------------------------------------------------------------------- /src/sdk/main/src/EthereumTransactionData.cc: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | #include "EthereumTransactionData.h" 3 | #include "EthereumTransactionDataEip1559.h" 4 | #include "EthereumTransactionDataLegacy.h" 5 | #include "impl/RLPItem.h" 6 | 7 | namespace Hiero 8 | { 9 | //----- 10 | EthereumTransactionData::EthereumTransactionData(std::vector callData) 11 | : mCallData(std::move(callData)) 12 | { 13 | } 14 | 15 | //----- 16 | std::unique_ptr EthereumTransactionData::fromBytes(const std::vector& bytes) 17 | { 18 | RLPItem rlpItem; 19 | rlpItem.read(bytes); 20 | 21 | if (rlpItem.isType(RLPItem::RLPType::LIST_TYPE)) 22 | { 23 | return std::make_unique(EthereumTransactionDataLegacy::fromBytes(bytes)); 24 | } 25 | else 26 | { 27 | return std::make_unique(EthereumTransactionDataEip1559::fromBytes(bytes)); 28 | } 29 | } 30 | 31 | } // namespace Hiero 32 | -------------------------------------------------------------------------------- /src/sdk/main/src/impl/DerivationPathUtils.cc: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | #include "impl/DerivationPathUtils.h" 3 | 4 | #include 5 | #include 6 | 7 | namespace Hiero::internal::DerivationPathUtils 8 | { 9 | //----- 10 | bool isHardenedChildIndex(uint32_t index) 11 | { 12 | return index >> 31 == 0x1; 13 | } 14 | 15 | //----- 16 | uint32_t getHardenedIndex(uint32_t index) 17 | { 18 | if (isHardenedChildIndex(index)) 19 | { 20 | throw std::invalid_argument("Index is already hardened"); 21 | } 22 | 23 | return ~(UINT32_MAX >> 1) | index; 24 | } 25 | 26 | //----- 27 | std::vector indexToBigEndianArray(uint32_t childIndex) 28 | { 29 | std::vector indexVector; 30 | for (int byteIndex = 3; byteIndex >= 0; --byteIndex) 31 | { 32 | indexVector.push_back(std::byte((childIndex >> (byteIndex << 3)) & 0xFF)); 33 | } 34 | 35 | return indexVector; 36 | } 37 | 38 | } // namespace Hiero::internal::DerivationPathUtils 39 | -------------------------------------------------------------------------------- /src/sdk/tests/unit/TransactionRecordQueryUnitTests.cc: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | #include "TransactionId.h" 3 | #include "TransactionRecordQuery.h" 4 | 5 | #include 6 | 7 | using namespace Hiero; 8 | 9 | class TransactionRecordQueryUnitTests : public ::testing::Test 10 | { 11 | protected: 12 | [[nodiscard]] inline const AccountId& getTestAccountId() const { return mTestAccountId; } 13 | [[nodiscard]] inline const TransactionId& getTestTransactionId() const { return mTestTransactionId; } 14 | 15 | private: 16 | const AccountId mTestAccountId = AccountId(10ULL); 17 | const TransactionId mTestTransactionId = TransactionId::generate(mTestAccountId); 18 | }; 19 | 20 | TEST_F(TransactionRecordQueryUnitTests, SetTransactionId) 21 | { 22 | TransactionRecordQuery query; 23 | const TransactionId transactionId = TransactionId::generate(getTestAccountId()); 24 | query.setTransactionId(transactionId); 25 | EXPECT_EQ(query.getTransactionId(), transactionId); 26 | } -------------------------------------------------------------------------------- /src/sdk/tests/unit/TransactionReceiptQueryUnitTests.cc: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | #include "TransactionId.h" 3 | #include "TransactionReceiptQuery.h" 4 | 5 | #include 6 | 7 | using namespace Hiero; 8 | 9 | class TransactionReceiptQueryUnitTests : public ::testing::Test 10 | { 11 | protected: 12 | [[nodiscard]] inline const AccountId& getTestAccountId() const { return mTestAccountId; } 13 | [[nodiscard]] inline const TransactionId& getTestTransactionId() const { return mTestTransactionId; } 14 | 15 | private: 16 | const AccountId mTestAccountId = AccountId(10ULL); 17 | const TransactionId mTestTransactionId = TransactionId::generate(mTestAccountId); 18 | }; 19 | 20 | TEST_F(TransactionReceiptQueryUnitTests, SetTransactionId) 21 | { 22 | TransactionReceiptQuery query; 23 | const TransactionId transactionId = TransactionId::generate(getTestAccountId()); 24 | query.setTransactionId(transactionId); 25 | EXPECT_EQ(query.getTransactionId(), transactionId); 26 | } 27 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.15...3.24) 2 | project(hiero-sdk-cpp VERSION 0.41.0 DESCRIPTION "Hiero SDK C++" LANGUAGES CXX) 3 | 4 | set(CMAKE_CXX_STANDARD 17) 5 | set(CMAKE_CXX_STANDARD_REQUIRED ON) 6 | 7 | if (MSVC) 8 | add_compile_options(/bigobj) 9 | endif() 10 | 11 | set(CMAKE_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX}/${CMAKE_BUILD_TYPE}/${CMAKE_HOST_SYSTEM_NAME}/${CMAKE_HOST_SYSTEM_PROCESSOR}) 12 | 13 | set(Protobuf_USE_STATIC_LIBS ON) 14 | 15 | set(gRPC_SSL_PROVIDER package) 16 | 17 | find_package(OpenSSL REQUIRED) 18 | find_package(ZLIB REQUIRED) 19 | find_package(Protobuf CONFIG REQUIRED) 20 | find_package(gRPC CONFIG REQUIRED) 21 | find_package(re2 CONFIG REQUIRED) 22 | find_package(absl CONFIG REQUIRED) 23 | find_package(Threads REQUIRED) 24 | find_package(nlohmann_json CONFIG REQUIRED) 25 | find_package(EXPAT CONFIG REQUIRED) 26 | 27 | include(FetchContent) 28 | include(SystemLibraries.cmake) 29 | include(HieroApi.cmake) 30 | 31 | enable_testing() 32 | 33 | add_subdirectory(src) 34 | -------------------------------------------------------------------------------- /src/sdk/main/include/SubscriptionHandle.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | #ifndef HIERO_SDK_CPP_SUBSCRIPTION_HANDLE_H_ 3 | #define HIERO_SDK_CPP_SUBSCRIPTION_HANDLE_H_ 4 | 5 | #include 6 | #include 7 | 8 | namespace Hiero 9 | { 10 | class SubscriptionHandle 11 | { 12 | public: 13 | /** 14 | * Destructor unsubscribes. 15 | */ 16 | ~SubscriptionHandle(); 17 | 18 | /** 19 | * Unsubscribe from the subscription this SubscriptionHandle is holding. 20 | */ 21 | void unsubscribe() const; 22 | 23 | /** 24 | * Set the function to run when unsubscribing. 25 | * 26 | * @param onUnsubscribe The function to run when unsubscribing. 27 | */ 28 | void setOnUnsubscribe(const std::function& onUnsubscribe); 29 | 30 | private: 31 | /** 32 | * The function to run when attempting to unsubscribe. 33 | */ 34 | std::function mUnsubscribeFunc; 35 | }; 36 | 37 | } // namespace Hiero 38 | 39 | #endif // HIERO_SDK_CPP_SUBSCRIPTION_HANDLE_H_ 40 | -------------------------------------------------------------------------------- /src/sdk/main/src/impl/MirrorNode.cc: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | #include "impl/MirrorNode.h" 3 | #include "impl/BaseNodeAddress.h" 4 | 5 | namespace Hiero::internal 6 | { 7 | //----- 8 | MirrorNode::MirrorNode(const BaseNodeAddress& address) 9 | : BaseNode(address) 10 | { 11 | } 12 | 13 | //----- 14 | MirrorNode::MirrorNode(std::string_view address) 15 | : BaseNode(BaseNodeAddress::fromString(address)) 16 | { 17 | } 18 | 19 | //----- 20 | void MirrorNode::initializeStubs() 21 | { 22 | if (!mConsensusStub) 23 | { 24 | mConsensusStub = com::hedera::mirror::api::proto::ConsensusService::NewStub(getChannel()); 25 | } 26 | 27 | if (!mNetworkStub) 28 | { 29 | mNetworkStub = com::hedera::mirror::api::proto::NetworkService::NewStub(getChannel()); 30 | } 31 | } 32 | 33 | //----- 34 | void MirrorNode::closeStubs() 35 | { 36 | mConsensusStub = nullptr; 37 | mNetworkStub = nullptr; 38 | } 39 | 40 | } // namespace Hiero::internal 41 | -------------------------------------------------------------------------------- /src/sdk/main/include/impl/openssl_utils/EVP_PKEY.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | #ifndef HIERO_SDK_CPP_IMPL_OPENSSL_UTILS_EVP_PKEY_H_ 3 | #define HIERO_SDK_CPP_IMPL_OPENSSL_UTILS_EVP_PKEY_H_ 4 | 5 | #include "impl/openssl_utils/OpenSSLObjectWrapper.h" 6 | 7 | #include 8 | 9 | namespace Hiero::internal::OpenSSLUtils 10 | { 11 | /** 12 | * Wrapper class for the OpenSSL EVP_PKEY object. 13 | */ 14 | class EVP_PKEY : public OpenSSLObjectWrapper<::EVP_PKEY, decltype(&EVP_PKEY_dup)> 15 | { 16 | public: 17 | EVP_PKEY() = default; 18 | 19 | /** 20 | * Construct with the input EVP_PKEY, its EVP_PKEY_free deleter function, and its EVP_PKEY_dup copier function. 21 | * 22 | * @param evpPkey The EVP_PKEY OpenSSL object to wrap. 23 | */ 24 | explicit EVP_PKEY(::EVP_PKEY* evpPkey) 25 | : OpenSSLObjectWrapper(evpPkey, &EVP_PKEY_free, &EVP_PKEY_dup) 26 | { 27 | } 28 | }; 29 | 30 | } // namespace Hiero::internal::OpenSSLUtils 31 | 32 | #endif // HIERO_SDK_CPP_IMPL_OPENSSL_UTILS_EVP_PKEY_H_ 33 | -------------------------------------------------------------------------------- /src/sdk/main/include/impl/openssl_utils/EVP_PKEY_CTX.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | #ifndef HIERO_SDK_CPP_IMPL_OPENSSL_UTILS_EVP_PKEY_CTX_H_ 3 | #define HIERO_SDK_CPP_IMPL_OPENSSL_UTILS_EVP_PKEY_CTX_H_ 4 | 5 | #include "impl/openssl_utils/OpenSSLObjectWrapper.h" 6 | 7 | #include 8 | 9 | namespace Hiero::internal::OpenSSLUtils 10 | { 11 | /** 12 | * Wrapper class for the OpenSSL EVP_PKEY_CTX object. 13 | */ 14 | class EVP_PKEY_CTX : public OpenSSLObjectWrapper<::EVP_PKEY_CTX> 15 | { 16 | public: 17 | /** 18 | * Construct with the input EVP_PKEY_CTX, its EVP_PKEY_CTX_free deleter function, and its EVP_PKEY_CTX_dup copier 19 | * function. 20 | * 21 | * @param evpPkeyCtx The EVP_PKEY_CTX OpenSSL object to wrap. 22 | */ 23 | explicit EVP_PKEY_CTX(::EVP_PKEY_CTX* evpPkeyCtx) 24 | : OpenSSLObjectWrapper(evpPkeyCtx, &EVP_PKEY_CTX_free, &EVP_PKEY_CTX_dup) 25 | { 26 | } 27 | }; 28 | 29 | } // namespace Hiero::internal::OpenSSLUtils 30 | 31 | #endif // HIERO_SDK_CPP_IMPL_OPENSSL_UTILS_EVP_PKEY_CTX_H_ 32 | -------------------------------------------------------------------------------- /src/sdk/tests/unit/TransactionResponseUnitTests.cc: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | #include "TransactionResponse.h" 3 | 4 | #include 5 | #include 6 | 7 | using namespace Hiero; 8 | 9 | class TransactionResponseUnitTests : public ::testing::Test 10 | { 11 | }; 12 | 13 | //----- 14 | TEST_F(TransactionResponseUnitTests, ContructTransactionResponse) 15 | { 16 | // Given 17 | const AccountId accountId(1ULL); 18 | const std::chrono::system_clock::time_point now = std::chrono::system_clock::now(); 19 | const TransactionId transactionId = TransactionId::withValidStart(accountId, now); 20 | const std::vector hash = { std::byte(0x00), std::byte(0x01), std::byte(0x02) }; 21 | 22 | // When 23 | const TransactionResponse transactionResponse(accountId, transactionId, hash); 24 | 25 | // Then 26 | EXPECT_EQ(transactionResponse.mNodeId, accountId); 27 | EXPECT_EQ(transactionResponse.mTransactionHash, hash); 28 | EXPECT_EQ(transactionResponse.mTransactionId, transactionId); 29 | } 30 | -------------------------------------------------------------------------------- /src/sdk/main/include/exceptions/OpenSSLException.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | #ifndef HIERO_SDK_CPP_OPENSSL_EXCEPTION_H_ 3 | #define HIERO_SDK_CPP_OPENSSL_EXCEPTION_H_ 4 | 5 | #include 6 | #include 7 | 8 | namespace Hiero 9 | { 10 | /** 11 | * Exception that encompasses all unrecoverable OpenSSL errors. 12 | */ 13 | class OpenSSLException : public std::exception 14 | { 15 | public: 16 | /** 17 | * Construct with a message. 18 | * 19 | * @param msg The error message to further describe this exception. 20 | */ 21 | explicit OpenSSLException(std::string_view msg) 22 | : mError(msg) 23 | { 24 | } 25 | 26 | /** 27 | * Get the descriptor message for this error. 28 | * 29 | * @return The descriptor message for this error. 30 | */ 31 | [[nodiscard]] const char* what() const noexcept override { return mError.data(); }; 32 | 33 | private: 34 | /** 35 | * Descriptive error message. 36 | */ 37 | std::string_view mError; 38 | }; 39 | 40 | } // namespace Hiero 41 | 42 | #endif // HIERO_SDK_CPP_OPENSSL_EXCEPTION_H_ 43 | -------------------------------------------------------------------------------- /src/tck/include/json/JsonErrorType.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | #ifndef HIERO_TCK_CPP_JSON_ERROR_TYPE_H_ 3 | #define HIERO_TCK_CPP_JSON_ERROR_TYPE_H_ 4 | 5 | namespace Hiero::TCK 6 | { 7 | /** 8 | * Enum used to describe an error seen while handling a JSON RPC request. 9 | */ 10 | enum class JsonErrorType : short 11 | { 12 | /** 13 | * Invalid JSON was received by the server. An error occurred on the server while parsing the JSON text. 14 | */ 15 | PARSE_ERROR = -32700, 16 | /** 17 | * The JSON sent is not a valid request object. 18 | */ 19 | INVALID_REQUEST = -32600, 20 | /** 21 | * The method does not exist/is not available. 22 | */ 23 | METHOD_NOT_FOUND = -32601, 24 | /** 25 | * Invalid method parameter(s). 26 | */ 27 | INVALID_PARAMS = -32602, 28 | /** 29 | * Internal JSON-RPC error. 30 | */ 31 | INTERNAL_ERROR = -32603, 32 | /** 33 | * The Hiero C++ SDK failed to execute the JSON request. 34 | */ 35 | HIERO_ERROR = -32001 36 | }; 37 | 38 | } // namespace Hiero::TCK 39 | 40 | #endif // HIERO_TCK_CPP_JSON_ERROR_TYPE_H_ 41 | -------------------------------------------------------------------------------- /src/tck/include/sdk/params/ResetParams.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | #ifndef HIERO_TCK_CPP_RESET_PARAMS_H_ 3 | #define HIERO_TCK_CPP_RESET_PARAMS_H_ 4 | 5 | #include 6 | 7 | namespace Hiero::TCK::SdkClient 8 | { 9 | /** 10 | * Struct to hold the arguments for a `reset` JSON-RPC method call. It takes no arguments 11 | */ 12 | struct ResetParams 13 | { 14 | }; 15 | 16 | } // namespace Hiero::TCK::SdkClient 17 | 18 | namespace nlohmann 19 | { 20 | /** 21 | * JSON serializer template specialization required to convert ResetParams arguments properly. 22 | */ 23 | template<> 24 | struct [[maybe_unused]] adl_serializer 25 | { 26 | /** 27 | * Convert a JSON object to a ResetParams. 28 | * 29 | * @param jsonFrom The JSON object with which to fill the ResetParams. 30 | * @param params The ResetParams to fill with the JSON object. 31 | */ 32 | static void from_json(const json&, Hiero::TCK::SdkClient::ResetParams&) {} 33 | }; 34 | 35 | } // namespace nlohmann 36 | 37 | #endif // HIERO_TCK_CPP_RESET_PARAMS_H_ 38 | -------------------------------------------------------------------------------- /src/sdk/main/include/exceptions/BadKeyException.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | #ifndef HIERO_SDK_CPP_BAD_KEY_EXCEPTION_H_ 3 | #define HIERO_SDK_CPP_BAD_KEY_EXCEPTION_H_ 4 | 5 | #include 6 | #include 7 | 8 | namespace Hiero 9 | { 10 | /** 11 | * Exception that is thrown when a key could not be realized from a given input. 12 | */ 13 | class BadKeyException : public std::exception 14 | { 15 | public: 16 | /** 17 | * Construct with a message. 18 | * 19 | * @param msg The error message to further describe this exception. 20 | */ 21 | explicit BadKeyException(std::string_view msg) 22 | : mError(msg) 23 | { 24 | } 25 | 26 | /** 27 | * Get the descriptor message for this error. 28 | * 29 | * @return The descriptor message for this error. 30 | */ 31 | [[nodiscard]] const char* what() const noexcept override { return mError.data(); }; 32 | 33 | private: 34 | /** 35 | * Descriptive error message. 36 | */ 37 | std::string_view mError; 38 | }; 39 | 40 | } // namespace Hiero 41 | 42 | #endif // HIERO_SDK_CPP_BAD_KEY_EXCEPTION_H_ 43 | -------------------------------------------------------------------------------- /src/sdk/main/src/impl/ASN1ECPrivateKey.cc: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | 3 | #include "exceptions/BadKeyException.h" 4 | 5 | #include "impl/ASN1ECPrivateKey.h" 6 | #include "impl/HexConverter.h" 7 | 8 | namespace Hiero::internal::asn1 9 | { 10 | ASN1ECPrivateKey::ASN1ECPrivateKey(const std::vector& bytes) 11 | { 12 | if (bytes.size() >= MAX_ENCRYPTED_KEY_LENGHT) 13 | { 14 | throw BadKeyException("Over maximum possible input bytes for EC Key!"); 15 | } 16 | else 17 | { 18 | decode(bytes); 19 | } 20 | } 21 | 22 | std::vector ASN1ECPrivateKey::getKey() const 23 | { 24 | std::vector privateKey = get(OCTET_STRING); 25 | if (privateKey.size() < EC_KEY_LENGTH) 26 | { 27 | throw BadKeyException("Data not decoded properly for input PEM/DER EC KEY bytes!"); 28 | } 29 | if (privateKey.size() > EC_KEY_LENGTH) // remove redundant padded bytes if any 30 | { 31 | privateKey = std::vector(privateKey.end() - EC_KEY_LENGTH, privateKey.end()); 32 | } 33 | 34 | return privateKey; 35 | } 36 | 37 | } // namespace Hiero::internal:asn1 38 | -------------------------------------------------------------------------------- /src/sdk/main/src/impl/ASN1ED25519PrivateKey.cc: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | 3 | #include "exceptions/BadKeyException.h" 4 | 5 | #include "impl/ASN1ED25519PrivateKey.h" 6 | #include "impl/HexConverter.h" 7 | 8 | namespace Hiero::internal::asn1 9 | { 10 | ASN1ED25519PrivateKey::ASN1ED25519PrivateKey(const std::vector& bytes) 11 | { 12 | if (bytes.size() >= MAX_ENCRYPTED_KEY_LENGHT) 13 | { 14 | throw BadKeyException("Over maximum possible input bytes for EC Key!"); 15 | } 16 | else 17 | { 18 | decode(bytes); 19 | } 20 | } 21 | 22 | std::vector ASN1ED25519PrivateKey::getKey() const 23 | { 24 | std::vector privateKey = get(OCTET_STRING); 25 | if (privateKey.empty()) 26 | { 27 | throw BadKeyException("Data not decoded properly for input PEM/DER EC KEY bytes!"); 28 | } 29 | if (privateKey.size() > EC_KEY_LENGTH) // remove redundant padded bytes if any 30 | { 31 | privateKey = std::vector(privateKey.end() - EC_KEY_LENGTH, privateKey.end()); 32 | } 33 | 34 | return privateKey; 35 | } 36 | 37 | } // namespace Hiero::internal:asn1 38 | -------------------------------------------------------------------------------- /src/sdk/main/src/impl/ASN1ED25519PublicKey.cc: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | 3 | #include "exceptions/BadKeyException.h" 4 | 5 | #include "impl/ASN1ED25519PublicKey.h" 6 | #include "impl/HexConverter.h" 7 | 8 | namespace Hiero::internal::asn1 9 | { 10 | ASN1ED25519PublicKey::ASN1ED25519PublicKey(const std::vector& bytes) 11 | { 12 | if (bytes.size() >= MAX_ENCRYPTED_KEY_LENGHT) 13 | { 14 | throw BadKeyException("Over maximum possible input bytes for EC Key!"); 15 | } 16 | else 17 | { 18 | decode(bytes); 19 | } 20 | } 21 | 22 | std::vector ASN1ED25519PublicKey::getKey() const 23 | { 24 | std::vector publicKey = get(BIT_STRING); 25 | if (publicKey.size() < EC_KEY_LENGTH) 26 | { 27 | throw BadKeyException("Data not decoded properly for input PEM/DER EC KEY bytes!"); 28 | } 29 | if (publicKey.size() > EC_KEY_LENGTH) // remove redundant padded bytes if any 30 | { 31 | publicKey = std::vector(publicKey.end() - EC_KEY_LENGTH, publicKey.end()); 32 | } 33 | 34 | return publicKey; 35 | } 36 | 37 | } // namespace Hiero::internal:asn1 38 | -------------------------------------------------------------------------------- /src/sdk/main/src/TokenKeyValidation.cc: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | #include "TokenKeyValidation.h" 3 | 4 | #include 5 | 6 | namespace Hiero 7 | { 8 | //----- 9 | const std::unordered_map 10 | gProtobufTokenKeyValidationToTokenKeyValidation = { 11 | {proto::TokenKeyValidation::FULL_VALIDATION, TokenKeyValidation::FULL_VALIDATION}, 12 | { proto::TokenKeyValidation::NO_VALIDATION, TokenKeyValidation::NO_VALIDATION } 13 | }; 14 | 15 | //----- 16 | const std::unordered_map 17 | gTokenKeyValidationToProtobufTokenKeyValidation = { 18 | {TokenKeyValidation::FULL_VALIDATION, proto::TokenKeyValidation::FULL_VALIDATION}, 19 | { TokenKeyValidation::NO_VALIDATION, proto::TokenKeyValidation::NO_VALIDATION } 20 | }; 21 | 22 | //----- 23 | const std::unordered_map gTokenKeyValidationToString = { 24 | {TokenKeyValidation::FULL_VALIDATION, "FULL_VALIDATION"}, 25 | { TokenKeyValidation::NO_VALIDATION, "NO_VALIDATION" } 26 | }; 27 | } // namespace Hiero -------------------------------------------------------------------------------- /src/sdk/main/include/exceptions/UninitializedException.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | #ifndef HIERO_SDK_CPP_UNINITIALIZED_EXCEPTION_H_ 3 | #define HIERO_SDK_CPP_UNINITIALIZED_EXCEPTION_H_ 4 | 5 | #include 6 | #include 7 | 8 | namespace Hiero 9 | { 10 | /** 11 | * Exception that encompasses all unrecoverable OpenSSL errors. 12 | */ 13 | class UninitializedException : public std::exception 14 | { 15 | public: 16 | /** 17 | * Construct with a message. 18 | * 19 | * @param msg The error message to further describe this exception. 20 | */ 21 | explicit UninitializedException(std::string_view msg) 22 | : mError(msg) 23 | { 24 | } 25 | 26 | /** 27 | * Get the descriptor message for this error. 28 | * 29 | * @return The descriptor message for this error. 30 | */ 31 | [[nodiscard]] const char* what() const noexcept override { return mError.data(); }; 32 | 33 | private: 34 | /** 35 | * Descriptive error message. 36 | */ 37 | std::string_view mError; 38 | }; 39 | 40 | } // namespace Hiero 41 | 42 | #endif // HIERO_SDK_CPP_UNINITIALIZED_EXCEPTION_H_ 43 | -------------------------------------------------------------------------------- /src/sdk/main/include/exceptions/BadMnemonicException.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | #ifndef HIERO_SDK_CPP_BAD_MNEMONIC_EXCEPTION_H_ 3 | #define HIERO_SDK_CPP_BAD_MNEMONIC_EXCEPTION_H_ 4 | 5 | #include 6 | #include 7 | 8 | namespace Hiero 9 | { 10 | /** 11 | * Exception that is thrown when a key could not be realized from a given input. 12 | */ 13 | class BadMnemonicException : public std::exception 14 | { 15 | public: 16 | /** 17 | * Construct with a message. 18 | * 19 | * @param msg The error message to further describe this exception. 20 | */ 21 | explicit BadMnemonicException(std::string_view msg) 22 | : mError(msg) 23 | { 24 | } 25 | 26 | /** 27 | * Get the descriptor message for this error. 28 | * 29 | * @return The descriptor message for this error. 30 | */ 31 | [[nodiscard]] const char* what() const noexcept override { return mError.data(); }; 32 | 33 | private: 34 | /** 35 | * Descriptive error message. 36 | */ 37 | std::string_view mError; 38 | }; 39 | 40 | } // namespace Hiero 41 | 42 | #endif // HIERO_SDK_CPP_BAD_MNEMONIC_EXCEPTION_H_ 43 | -------------------------------------------------------------------------------- /src/sdk/tests/unit/NodeDeleteTransactionUnitTests.cc: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | #include "ED25519PrivateKey.h" 3 | #include "NodeDeleteTransaction.h" 4 | 5 | #include 6 | #include 7 | 8 | using namespace Hiero; 9 | 10 | class NodeDeleteTransactionUnitTests : public ::testing::Test 11 | { 12 | protected: 13 | NodeDeleteTransaction transaction; 14 | }; 15 | 16 | //----- 17 | TEST_F(NodeDeleteTransactionUnitTests, ConstructNodeDeleteTransactionFromTransactionBodyProtobuf) 18 | { 19 | // Given 20 | proto::TransactionBody transactionBody; 21 | aproto::NodeDeleteTransactionBody* body = transactionBody.mutable_nodedelete(); 22 | 23 | body->set_node_id(1); 24 | 25 | // When 26 | NodeDeleteTransaction nodeDeleteTransaction(transactionBody); 27 | 28 | // Then 29 | ASSERT_EQ(nodeDeleteTransaction.getNodeId(), 1); 30 | } 31 | 32 | //----- 33 | TEST_F(NodeDeleteTransactionUnitTests, SetAndGetNodeId) 34 | { 35 | // Given 36 | uint64_t nodeId = 3; 37 | 38 | // When 39 | transaction.setNodeId(nodeId); 40 | 41 | // Then 42 | ASSERT_EQ(transaction.getNodeId(), nodeId); 43 | } -------------------------------------------------------------------------------- /src/sdk/main/include/impl/DurationConverter.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | #ifndef HIERO_SDK_CPP_IMPL_DURATION_CONVERTER_H_ 3 | #define HIERO_SDK_CPP_IMPL_DURATION_CONVERTER_H_ 4 | 5 | #include 6 | #include 7 | 8 | namespace proto 9 | { 10 | class Duration; 11 | } 12 | 13 | namespace Hiero::internal::DurationConverter 14 | { 15 | /** 16 | * Get the duration in seconds represented by a Duration protobuf object. 17 | * 18 | * @param duration The Duration protobuf object from which to get the duration. 19 | * @return The duration in seconds of the input Duration protobuf object. 20 | */ 21 | std::chrono::seconds fromProtobuf(const proto::Duration& duration); 22 | 23 | /** 24 | * Create a Duration protobuf object from a generic duration. 25 | * 26 | * @param duration The duration object from which to create a Duration protobuf object. 27 | * @return A pointer to the created Duration protobuf object. 28 | */ 29 | proto::Duration* toProtobuf(const std::chrono::system_clock::duration& duration); 30 | 31 | } // namespace Hiero::internal::DurationConverter 32 | 33 | #endif // HIERO_SDK_CPP_IMPL_DURATION_CONVERTER_H_ 34 | -------------------------------------------------------------------------------- /src/sdk/main/include/exceptions/IllegalStateException.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | #ifndef HIERO_SDK_CPP_ILLEGAL_STATE_EXCEPTION_H_ 3 | #define HIERO_SDK_CPP_ILLEGAL_STATE_EXCEPTION_H_ 4 | 5 | #include 6 | #include 7 | 8 | namespace Hiero 9 | { 10 | /** 11 | * Exception that is thrown when an action is attempted when an object is not in the correct state for said action. 12 | */ 13 | class IllegalStateException : public std::exception 14 | { 15 | public: 16 | /** 17 | * Construct with a message. 18 | * 19 | * @param msg The error message to further describe this exception. 20 | */ 21 | explicit IllegalStateException(std::string_view msg) 22 | : mError(msg) 23 | { 24 | } 25 | 26 | /** 27 | * Get the descriptor message for this error. 28 | * 29 | * @return The descriptor message for this error. 30 | */ 31 | [[nodiscard]] const char* what() const noexcept override { return mError.data(); }; 32 | 33 | private: 34 | /** 35 | * Descriptive error message. 36 | */ 37 | std::string_view mError; 38 | }; 39 | 40 | } // namespace Hiero 41 | 42 | #endif // HIERO_SDK_CPP_ILLEGAL_STATE_EXCEPTION_H_ 43 | -------------------------------------------------------------------------------- /src/sdk/main/include/impl/openssl_utils/EVP_MD.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | #ifndef HIERO_SDK_CPP_IMPL_OPENSSL_UTILS_EVP_MD_H_ 3 | #define HIERO_SDK_CPP_IMPL_OPENSSL_UTILS_EVP_MD_H_ 4 | 5 | #include "impl/openssl_utils/OpenSSLObjectWrapper.h" 6 | 7 | #include 8 | 9 | namespace Hiero::internal::OpenSSLUtils 10 | { 11 | /** 12 | * Wrapper class for the OpenSSL EVP_MD object. 13 | */ 14 | class EVP_MD : public OpenSSLObjectWrapper<::EVP_MD> 15 | { 16 | public: 17 | /** 18 | * No custom copier provided by OpenSSL for EVP_MD. 19 | */ 20 | ~EVP_MD() override = default; 21 | EVP_MD(const EVP_MD&) = delete; 22 | EVP_MD& operator=(const EVP_MD&) = delete; 23 | EVP_MD(EVP_MD&&) = default; 24 | EVP_MD& operator=(EVP_MD&&) = default; 25 | 26 | /** 27 | * Construct with the input EVP_MD and its EVP_MD_free deleter function. 28 | * 29 | * @param evpMd The EVP_MD OpenSSL object to wrap. 30 | */ 31 | explicit EVP_MD(::EVP_MD* evpMd) 32 | : OpenSSLObjectWrapper(evpMd, &EVP_MD_free) 33 | { 34 | } 35 | }; 36 | 37 | } // namespace Hiero::internal::OpenSSLUtils 38 | 39 | #endif // HIERO_SDK_CPP_IMPL_OPENSSL_UTILS_EVP_MD_H_ 40 | -------------------------------------------------------------------------------- /src/sdk/main/include/exceptions/UnsupportedOperationException.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | #ifndef HIERO_SDK_CPP_UNSUPPORTED_OPERATION_EXCEPTION_H_ 3 | #define HIERO_SDK_CPP_UNSUPPORTED_OPERATION_EXCEPTION_H_ 4 | 5 | #include 6 | #include 7 | 8 | namespace Hiero 9 | { 10 | /** 11 | * Exception that encompasses trying to execute any unsupported operation. 12 | */ 13 | class UnsupportedOperationException : public std::exception 14 | { 15 | public: 16 | /** 17 | * Construct with a message. 18 | * 19 | * @param msg The error message to further describe this exception. 20 | */ 21 | explicit UnsupportedOperationException(std::string_view msg) 22 | : mError(msg) 23 | { 24 | } 25 | 26 | /** 27 | * Get the descriptor message for this error. 28 | * 29 | * @return The descriptor message for this error. 30 | */ 31 | [[nodiscard]] const char* what() const noexcept override { return mError.data(); }; 32 | 33 | private: 34 | /** 35 | * Descriptive error message. 36 | */ 37 | std::string_view mError; 38 | }; 39 | 40 | } // namespace Hiero 41 | 42 | #endif // HIERO_SDK_CPP_UNSUPPORTED_OPERATION_EXCEPTION_H_ 43 | -------------------------------------------------------------------------------- /src/sdk/main/include/impl/openssl_utils/BN_CTX.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | #ifndef HIERO_SDK_CPP_IMPL_OPENSSL_UTILS_BN_CTX_H_ 3 | #define HIERO_SDK_CPP_IMPL_OPENSSL_UTILS_BN_CTX_H_ 4 | 5 | #include "impl/openssl_utils/OpenSSLObjectWrapper.h" 6 | 7 | #include 8 | 9 | namespace Hiero::internal::OpenSSLUtils 10 | { 11 | /** 12 | * Wrapper class for the OpenSSL BN_CTX object. 13 | */ 14 | class BN_CTX : public OpenSSLObjectWrapper<::BN_CTX> 15 | { 16 | public: 17 | /** 18 | * No custom copier provided by OpenSSL for BN_CTX, so copying is disallowed. 19 | */ 20 | ~BN_CTX() override = default; 21 | BN_CTX(const BN_CTX&) = delete; 22 | BN_CTX& operator=(const BN_CTX&) = delete; 23 | BN_CTX(BN_CTX&&) = default; 24 | BN_CTX& operator=(BN_CTX&&) = default; 25 | 26 | /** 27 | * Construct with the input BN_CTX and its BN_CTX_free deleter function. 28 | * 29 | * @param bnCtx The BN_CTX OpenSSL object to wrap. 30 | */ 31 | explicit BN_CTX(::BN_CTX* bnCtx) 32 | : OpenSSLObjectWrapper(bnCtx, &BN_CTX_free) 33 | { 34 | } 35 | }; 36 | 37 | } // namespace Hiero::internal::OpenSSLUtils 38 | 39 | #endif // HIERO_SDK_CPP_IMPL_OPENSSL_UTILS_BN_CTX_H_ -------------------------------------------------------------------------------- /src/sdk/examples/GetAccountBalanceExample.cpp: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | #include "AccountBalance.h" 3 | #include "AccountBalanceQuery.h" 4 | #include "Client.h" 5 | #include "ECDSAsecp256k1PrivateKey.h" 6 | 7 | #include 8 | #include 9 | 10 | using namespace Hiero; 11 | 12 | int main(int argc, char** argv) 13 | { 14 | dotenv::init(); 15 | const AccountId operatorAccountId = AccountId::fromString(std::getenv("OPERATOR_ID")); 16 | 17 | // Get a client for the Hiero testnet 18 | Client client = Client::forTestnet(); 19 | 20 | // Because AccountBalanceQuery is a free query, we can make it without setting an operator on the client. 21 | const AccountBalance accountBalance = AccountBalanceQuery().setAccountId(operatorAccountId).execute(client); 22 | 23 | std::cout << "Balance of account " << operatorAccountId.toString() << " is " << accountBalance.mBalance.toString() 24 | << std::endl; 25 | 26 | std::cout << "Token balances of account" << std::endl; 27 | for (auto tokenBalance : accountBalance.mTokens) 28 | { 29 | std::cout << tokenBalance.first.toString() << ": " << tokenBalance.second << std::endl; 30 | } 31 | 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /src/sdk/examples/PrngExample.cpp: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | #include "Client.h" 3 | #include "ECDSAsecp256k1PrivateKey.h" 4 | #include "PrngTransaction.h" 5 | #include "TransactionRecord.h" 6 | #include "TransactionResponse.h" 7 | 8 | #include 9 | #include 10 | 11 | using namespace Hiero; 12 | 13 | int main(int argc, char** argv) 14 | { 15 | dotenv::init(); 16 | const AccountId operatorAccountId = AccountId::fromString(std::getenv("OPERATOR_ID")); 17 | const std::shared_ptr operatorPrivateKey = 18 | ECDSAsecp256k1PrivateKey::fromString(std::getenv("OPERATOR_KEY")); 19 | 20 | // Get a client for the Hiero testnet, and set the operator account ID and key such that all generated transactions 21 | // will be paid for by this account and be signed by this key. 22 | Client client = Client::forTestnet(); 23 | client.setOperator(operatorAccountId, operatorPrivateKey); 24 | 25 | // Get a random number between 0 and 100. 26 | const TransactionRecord txRecord = PrngTransaction().setRange(100).execute(client).getRecord(client); 27 | std::cout << "Randomly generated number: " << txRecord.mPrngNumber.value() << std::endl; 28 | 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /src/sdk/tests/unit/AccountRecordsUnitTests.cc: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | #include "AccountRecords.h" 3 | 4 | #include 5 | #include 6 | 7 | using namespace Hiero; 8 | 9 | class AccountRecordsUnitTests : public ::testing::Test 10 | { 11 | protected: 12 | [[nodiscard]] inline const AccountId& getTestAccountId() const { return mTestAccountId; } 13 | 14 | private: 15 | const AccountId mTestAccountId = AccountId(3ULL); 16 | }; 17 | 18 | //----- 19 | TEST_F(AccountRecordsUnitTests, DeserializeAccountRecordsFromProtobuf) 20 | { 21 | // Given 22 | proto::CryptoGetAccountRecordsResponse accountRecordsResponse; 23 | accountRecordsResponse.set_allocated_accountid(getTestAccountId().toProtobuf().release()); 24 | accountRecordsResponse.add_records(); 25 | accountRecordsResponse.add_records(); 26 | 27 | // When 28 | const AccountRecords accountRecords = AccountRecords::fromProtobuf(accountRecordsResponse); 29 | 30 | // Then 31 | EXPECT_EQ(accountRecords.mAccountId, getTestAccountId()); 32 | // Don't bother testing records data as that's already tested in TransactionRecordTest 33 | EXPECT_EQ(accountRecords.mRecords.size(), 2); 34 | } -------------------------------------------------------------------------------- /src/sdk/main/include/exceptions/MaxAttemptsExceededException.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | #ifndef HIERO_SDK_CPP_MAX_ATTEMPTS_EXCEEDED_EXCEPTION_H_ 3 | #define HIERO_SDK_CPP_MAX_ATTEMPTS_EXCEEDED_EXCEPTION_H_ 4 | 5 | #include 6 | #include 7 | 8 | namespace Hiero 9 | { 10 | /** 11 | * Exception that is thrown when a processing exceeds its maximum number of attempts to submit a request to a network. 12 | */ 13 | class MaxAttemptsExceededException : public std::exception 14 | { 15 | public: 16 | /** 17 | * Construct with a message. 18 | * 19 | * @param msg The error message to further describe this exception. 20 | */ 21 | explicit MaxAttemptsExceededException(std::string_view msg) 22 | : mError(msg) 23 | { 24 | } 25 | 26 | /** 27 | * Get the descriptor message for this error. 28 | * 29 | * @return The descriptor message for this error. 30 | */ 31 | [[nodiscard]] const char* what() const noexcept override { return mError.data(); }; 32 | 33 | private: 34 | /** 35 | * Descriptive error message. 36 | */ 37 | std::string_view mError; 38 | }; 39 | 40 | } // namespace Hiero 41 | 42 | #endif // HIERO_SDK_CPP_MAX_ATTEMPTS_EXCEEDED_EXCEPTION_H_ 43 | -------------------------------------------------------------------------------- /src/sdk/main/include/impl/openssl_utils/EC_POINT.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | #ifndef HIERO_SDK_CPP_IMPL_OPENSSL_UTILS_EC_POINT_H_ 3 | #define HIERO_SDK_CPP_IMPL_OPENSSL_UTILS_EC_POINT_H_ 4 | 5 | #include "impl/openssl_utils/OpenSSLObjectWrapper.h" 6 | 7 | #include 8 | 9 | namespace Hiero::internal::OpenSSLUtils 10 | { 11 | /** 12 | * Wrapper class for the OpenSSL EC_POINT object. 13 | */ 14 | class EC_POINT : public OpenSSLObjectWrapper<::EC_POINT> 15 | { 16 | public: 17 | /** 18 | * No custom copier provided by OpenSSL for EC_POINT. 19 | */ 20 | ~EC_POINT() override = default; 21 | EC_POINT(const EC_POINT&) = delete; 22 | EC_POINT& operator=(const EC_POINT&) = delete; 23 | EC_POINT(EC_POINT&&) = default; 24 | EC_POINT& operator=(EC_POINT&&) = default; 25 | 26 | /** 27 | * Construct with the input EC_POINT and its EC_POINT_free deleter function. 28 | * 29 | * @param ecPoint The EC_POINT OpenSSL object to wrap. 30 | */ 31 | explicit EC_POINT(::EC_POINT* ecPoint) 32 | : OpenSSLObjectWrapper(ecPoint, &EC_POINT_free) 33 | { 34 | } 35 | }; 36 | 37 | } // namespace Hiero::internal::OpenSSLUtils 38 | 39 | #endif // HIERO_SDK_CPP_IMPL_OPENSSL_UTILS_EC_POINT_H_ 40 | -------------------------------------------------------------------------------- /src/sdk/main/include/exceptions/MaxQueryPaymentExceededException.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | #ifndef HIERO_SDK_CPP_MAX_QUERY_PAYMENT_EXCEEDED_EXCEPTION_H_ 3 | #define HIERO_SDK_CPP_MAX_QUERY_PAYMENT_EXCEEDED_EXCEPTION_H_ 4 | 5 | #include 6 | #include 7 | 8 | namespace Hiero 9 | { 10 | /** 11 | * Exception that is thrown when the cost to execute a Query is larger than the maximum allowed amount. 12 | */ 13 | class MaxQueryPaymentExceededException : public std::exception 14 | { 15 | public: 16 | /** 17 | * Construct with a message. 18 | * 19 | * @param msg The error message to further describe this exception. 20 | */ 21 | explicit MaxQueryPaymentExceededException(std::string_view msg) 22 | : mError(msg) 23 | { 24 | } 25 | 26 | /** 27 | * Get the descriptor message for this error. 28 | * 29 | * @return The descriptor message for this error. 30 | */ 31 | [[nodiscard]] const char* what() const noexcept override { return mError.data(); }; 32 | 33 | private: 34 | /** 35 | * Descriptive error message. 36 | */ 37 | std::string_view mError; 38 | }; 39 | 40 | } // namespace Hiero 41 | 42 | #endif // HIERO_SDK_CPP_MAX_QUERY_PAYMENT_EXCEEDED_EXCEPTION_H_ 43 | -------------------------------------------------------------------------------- /src/sdk/main/include/impl/openssl_utils/ECDSA_SIG.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | #ifndef HIERO_SDK_CPP_IMPL_OPENSSL_UTILS_ECDSA_SIG_H_ 3 | #define HIERO_SDK_CPP_IMPL_OPENSSL_UTILS_ECDSA_SIG_H_ 4 | 5 | #include "impl/openssl_utils/OpenSSLObjectWrapper.h" 6 | 7 | #include 8 | 9 | namespace Hiero::internal::OpenSSLUtils 10 | { 11 | /** 12 | * Wrapper class for the OpenSSL ECDSA_SIG object. 13 | */ 14 | class ECDSA_SIG : public OpenSSLObjectWrapper<::ECDSA_SIG> 15 | { 16 | public: 17 | /** 18 | * No custom copier provided by OpenSSL for ECDSA_SIG. 19 | */ 20 | ~ECDSA_SIG() override = default; 21 | ECDSA_SIG(const ECDSA_SIG&) = delete; 22 | ECDSA_SIG& operator=(const ECDSA_SIG&) = delete; 23 | ECDSA_SIG(ECDSA_SIG&&) = default; 24 | ECDSA_SIG& operator=(ECDSA_SIG&&) = default; 25 | 26 | /** 27 | * Construct with the input ECDSA_SIG and its ECDSA_SIG_free deleter function. 28 | * 29 | * @param ecdsaSig The ECDSA_SIG OpenSSL object to wrap. 30 | */ 31 | explicit ECDSA_SIG(::ECDSA_SIG* ecdsaSig) 32 | : OpenSSLObjectWrapper(ecdsaSig, &ECDSA_SIG_free) 33 | { 34 | } 35 | }; 36 | 37 | } // namespace Hiero::internal::OpenSSLUtils 38 | 39 | #endif // HIERO_SDK_CPP_IMPL_OPENSSL_UTILS_ECDSA_SIG_H_ 40 | -------------------------------------------------------------------------------- /src/sdk/main/include/impl/openssl_utils/EVP_MD_CTX.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | #ifndef HIERO_SDK_CPP_IMPL_OPENSSL_UTILS_EVP_MD_CTX_H_ 3 | #define HIERO_SDK_CPP_IMPL_OPENSSL_UTILS_EVP_MD_CTX_H_ 4 | 5 | #include "impl/openssl_utils/OpenSSLObjectWrapper.h" 6 | 7 | #include 8 | 9 | namespace Hiero::internal::OpenSSLUtils 10 | { 11 | /** 12 | * Wrapper class for the OpenSSL EVP_MD_CTX object. 13 | */ 14 | class EVP_MD_CTX : public OpenSSLObjectWrapper<::EVP_MD_CTX> 15 | { 16 | public: 17 | /** 18 | * No custom copier provided by OpenSSL for EVP_MD_CTX. 19 | */ 20 | ~EVP_MD_CTX() override = default; 21 | EVP_MD_CTX(const EVP_MD_CTX&) = delete; 22 | EVP_MD_CTX& operator=(const EVP_MD_CTX&) = delete; 23 | EVP_MD_CTX(EVP_MD_CTX&&) = default; 24 | EVP_MD_CTX& operator=(EVP_MD_CTX&&) = default; 25 | 26 | /** 27 | * Construct with the input EVP_MD_CTX and its EVP_MD_CTX_free deleter function. 28 | * 29 | * @param evpMdCtx The EVP_MD_CTX OpenSSL object to wrap. 30 | */ 31 | explicit EVP_MD_CTX(::EVP_MD_CTX* evpMdCtx) 32 | : OpenSSLObjectWrapper(evpMdCtx, &EVP_MD_CTX_free) 33 | { 34 | } 35 | }; 36 | 37 | } // namespace Hiero::internal::OpenSSLUtils 38 | 39 | #endif // HIERO_SDK_CPP_IMPL_OPENSSL_UTILS_EVP_MD_CTX_H_ 40 | -------------------------------------------------------------------------------- /src/sdk/main/include/impl/openssl_utils/OSSL_LIB_CTX.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | #ifndef HIERO_SDK_CPP_IMPL_OPENSSL_UTILS_OSSL_LIB_CTX_H_ 3 | #define HIERO_SDK_CPP_IMPL_OPENSSL_UTILS_OSSL_LIB_CTX_H_ 4 | 5 | #include "impl/openssl_utils/OpenSSLObjectWrapper.h" 6 | 7 | #include 8 | 9 | namespace Hiero::internal::OpenSSLUtils 10 | { 11 | /** 12 | * Wrapper class for the OpenSSL OSSL_LIB_CTX object. 13 | */ 14 | class OSSL_LIB_CTX : public OpenSSLObjectWrapper<::OSSL_LIB_CTX> 15 | { 16 | public: 17 | /** 18 | * No custom copier provided by OpenSSL for OSSL_LIB_CTX. 19 | */ 20 | ~OSSL_LIB_CTX() override = default; 21 | OSSL_LIB_CTX(const OSSL_LIB_CTX&) = delete; 22 | OSSL_LIB_CTX& operator=(const OSSL_LIB_CTX&) = delete; 23 | OSSL_LIB_CTX(OSSL_LIB_CTX&&) = default; 24 | OSSL_LIB_CTX& operator=(OSSL_LIB_CTX&&) = default; 25 | 26 | /** 27 | * Construct with the input OSSL_LIB_CTX and its OSSL_LIB_CTX_free deleter function. 28 | * 29 | * @param osslLibCtx The OSSL_LIB_CTX OpenSSL object to wrap. 30 | */ 31 | explicit OSSL_LIB_CTX(::OSSL_LIB_CTX* osslLibCtx) 32 | : OpenSSLObjectWrapper(osslLibCtx, &OSSL_LIB_CTX_free) 33 | { 34 | } 35 | }; 36 | 37 | } // namespace Hiero::internal::OpenSSLUtils 38 | 39 | #endif // HIERO_SDK_CPP_IMPL_OPENSSL_UTILS_OSSL_LIB_CTX_H_ 40 | -------------------------------------------------------------------------------- /src/sdk/main/include/impl/ASN1Object.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | #ifndef HIERO_SDK_CPP_IMPL_ASN1_OBJECT_H_ 3 | #define HIERO_SDK_CPP_IMPL_ASN1_OBJECT_H_ 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | namespace Hiero::internal::asn1 10 | { 11 | 12 | /** 13 | * Constants for ASN.1 standard. 14 | */ 15 | constexpr std::byte INTEGER = std::byte(0x02); 16 | constexpr std::byte BIT_STRING = std::byte(0x03); 17 | constexpr std::byte OCTET_STRING = std::byte(0x04); 18 | constexpr std::byte OBJECT_IDENTIFIER = std::byte(0x06); 19 | constexpr std::byte SEQUENCE = std::byte(0x30); 20 | 21 | /** 22 | * @class ASN1Object 23 | * Abstract base class for ASN.1 objects. 24 | */ 25 | class ASN1Object 26 | { 27 | protected: 28 | /** 29 | * Get the ASN.1 object's value in bytes. 30 | * 31 | * @param tag The ASN.1 tag of the object. 32 | * @return The object's value in bytes. 33 | */ 34 | virtual const std::vector get(const std::byte tag) const = 0; 35 | 36 | /** 37 | * Decode the ASN.1 object from a vector of bytes. 38 | * 39 | * @param data The vector of bytes containing the ASN.1 object's data. 40 | */ 41 | virtual void decode(const std::vector& data) = 0; 42 | }; 43 | 44 | } // namespace Hiero::internal::asn1 45 | 46 | #endif // HIERO_SDK_CPP_IMPL_ASN1_OBJECT_H_ -------------------------------------------------------------------------------- /src/sdk/tests/integration/BaseIntegrationTest.cc: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | #include "BaseIntegrationTest.h" 3 | #include "AccountId.h" 4 | #include "Client.h" 5 | #include "ED25519PrivateKey.h" 6 | #include "impl/Utilities.h" 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | using json = nlohmann::json; 15 | using namespace std; 16 | 17 | namespace Hiero 18 | { 19 | //----- 20 | void BaseIntegrationTest::SetUp() 21 | { 22 | mClient = Client::fromConfigFile((filesystem::current_path() / "local_node.json").string()); 23 | mClient.setNetworkUpdatePeriod(std::chrono::seconds(360)); 24 | 25 | mFileContent = internal::Utilities::stringToByteVector( 26 | json::parse(std::ifstream(std::filesystem::current_path() / "hello_world.json", std::ios::in))["object"] 27 | .get()); 28 | } 29 | 30 | //----- 31 | void BaseIntegrationTest::setTestClientOperator(const AccountId& accountId, 32 | const std::shared_ptr& privateKey) 33 | { 34 | mClient.setOperator(accountId, privateKey); 35 | } 36 | 37 | //----- 38 | void BaseIntegrationTest::setDefaultTestClientOperator() 39 | { 40 | setTestClientOperator(mDefaultTestAccountId, mDefaultTestPrivateKey); 41 | } 42 | 43 | } // namespace Hiero 44 | -------------------------------------------------------------------------------- /src/sdk/main/include/impl/HttpClient.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | #ifndef HIERO_SDK_CPP_IMPL_HTTP_CLIENT_H_ 3 | #define HIERO_SDK_CPP_IMPL_HTTP_CLIENT_H_ 4 | 5 | #ifndef CPPHTTPLIB_OPENSSL_SUPPORT 6 | #define CPPHTTPLIB_OPENSSL_SUPPORT 7 | #endif 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | namespace Hiero::internal::HttpClient 14 | { 15 | /** 16 | * Fetches data from the specified URL using the provided RPC method. 17 | * @param url The URL to fetch data from. 18 | * @param rpcMethod The RPC method. 19 | * @return The response data as a string. 20 | */ 21 | [[nodiscard]] std::string invokeRPC(std::string_view url, std::string_view rpcMethod); 22 | 23 | /** 24 | * Create a GET or POST request. Can be further extended for supporting other HTTP methods or handle more advanced 25 | * scenarios as needed. 26 | * @param url The URL to which to submit the request. 27 | * @param httpMethod The HTTP method. 28 | * @param requestBody The HTTP request body. 29 | * @return The response data as a string. 30 | */ 31 | [[nodiscard]] std::string invokeREST(std::string_view url, 32 | std::string_view httpMethod = "GET", 33 | std::string_view requestBody = ""); 34 | 35 | } // namespace Hiero::internal 36 | 37 | #endif // HIERO_SDK_CPP_IMPL_HTTP_CLIENT_H_ -------------------------------------------------------------------------------- /src/sdk/main/include/TopicMessageChunk.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | #ifndef HIERO_SDK_CPP_TOPIC_MESSAGE_CHUNK_H_ 3 | #define HIERO_SDK_CPP_TOPIC_MESSAGE_CHUNK_H_ 4 | 5 | #include "TransactionId.h" 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | namespace com::hedera::mirror::api::proto 12 | { 13 | class ConsensusTopicResponse; 14 | } 15 | 16 | namespace Hiero 17 | { 18 | /** 19 | * A chunk of a topic message. 20 | */ 21 | class TopicMessageChunk 22 | { 23 | public: 24 | TopicMessageChunk() = default; 25 | 26 | /** 27 | * Construct from a ConsensusTopicResponse protobuf object. 28 | * 29 | * @param proto The ConsensusTopicResponse protobuf object. 30 | */ 31 | explicit TopicMessageChunk(const com::hedera::mirror::api::proto::ConsensusTopicResponse& proto); 32 | 33 | /** 34 | * The consensus timestamp of this topic message chunk. 35 | */ 36 | std::chrono::system_clock::time_point mConsensusTimestamp; 37 | 38 | /** 39 | * The size of this chunk's content. 40 | */ 41 | uint64_t mContentSize = 0ULL; 42 | 43 | /** 44 | * The running hash of this chunk. 45 | */ 46 | std::vector mRunningHash; 47 | 48 | /** 49 | * The sequence number of this chunk. 50 | */ 51 | uint64_t mSequenceNumber = 0ULL; 52 | }; 53 | 54 | } // namespace Hiero 55 | 56 | #endif // HIERO_SDK_CPP_TOPIC_MESSAGE_CHUNK_H_ 57 | -------------------------------------------------------------------------------- /src/sdk/main/include/impl/openssl_utils/OSSL_DECODER_CTX.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | #ifndef HIERO_SDK_CPP_IMPL_OPENSSL_UTILS_OSSL_DECODER_CTX_H_ 3 | #define HIERO_SDK_CPP_IMPL_OPENSSL_UTILS_OSSL_DECODER_CTX_H_ 4 | 5 | #include "impl/openssl_utils/OpenSSLObjectWrapper.h" 6 | 7 | #include 8 | 9 | namespace Hiero::internal::OpenSSLUtils 10 | { 11 | /** 12 | * Wrapper class for the OpenSSL OSSL_DECODER_CTX object. 13 | */ 14 | class OSSL_DECODER_CTX : public OpenSSLObjectWrapper<::OSSL_DECODER_CTX> 15 | { 16 | public: 17 | /** 18 | * No custom copier provided by OpenSSL for OSSL_LIB_CTX. 19 | */ 20 | ~OSSL_DECODER_CTX() override = default; 21 | OSSL_DECODER_CTX(const OSSL_DECODER_CTX&) = delete; 22 | OSSL_DECODER_CTX& operator=(const OSSL_DECODER_CTX&) = delete; 23 | OSSL_DECODER_CTX(OSSL_DECODER_CTX&&) = default; 24 | OSSL_DECODER_CTX& operator=(OSSL_DECODER_CTX&&) = default; 25 | 26 | /** 27 | * Construct with the input OSSL_DECODER_CTX and its OSSL_DECODER_CTX_free deleter function. 28 | * 29 | * @param osslDecoderCtx The OSSL_DECODER_CTX OpenSSL object to wrap. 30 | */ 31 | explicit OSSL_DECODER_CTX(::OSSL_DECODER_CTX* osslDecoderCtx) 32 | : OpenSSLObjectWrapper(osslDecoderCtx, &OSSL_DECODER_CTX_free) 33 | { 34 | } 35 | }; 36 | 37 | } // namespace Hiero::internal::OpenSSLUtils 38 | 39 | #endif // HIERO_SDK_CPP_IMPL_OPENSSL_UTILS_OSSL_DECODER_CTX_H_ 40 | -------------------------------------------------------------------------------- /src/sdk/main/src/impl/MirrorNodeContractCallQuery.cc: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | #include "impl/MirrorNodeContractCallQuery.h" 3 | #include "impl/MirrorNetwork.h" 4 | #include "impl/MirrorNodeGateway.h" 5 | 6 | #include "exceptions/IllegalStateException.h" 7 | 8 | namespace Hiero 9 | { 10 | 11 | std::string MirrorNodeContractCallQuery::execute(const Client& client) 12 | { 13 | if (!getContractEvmAddress().has_value()) 14 | { 15 | populateContractEvmAddress(client); 16 | } 17 | 18 | const json contractCallResult = 19 | internal::MirrorNodeGateway::MirrorNodeQuery(client.getClientMirrorNetwork()->getNetwork()[0], 20 | { "call" }, 21 | internal::MirrorNodeGateway::CONTRACT_INFO_QUERY, 22 | toJson().dump(), 23 | "POST"); 24 | 25 | if (!contractCallResult.contains("result")) 26 | { 27 | throw IllegalStateException("No result was found for the contract call."); 28 | } 29 | std::string callResult = contractCallResult["result"].dump(); 30 | // json dump returns strings in dquotes, so we need to trim first and last characters 31 | callResult = callResult.substr(1, callResult.length() - 2); 32 | // trim 0x 33 | callResult = callResult.substr(2); 34 | 35 | return callResult; 36 | } 37 | 38 | } // namespace Hiero -------------------------------------------------------------------------------- /src/sdk/tests/unit/TokenTypeUnitTests.cc: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | #include "TokenType.h" 3 | 4 | #include 5 | #include 6 | 7 | using namespace Hiero; 8 | 9 | class TokenTypeUnitTests : public ::testing::Test 10 | { 11 | }; 12 | 13 | //----- 14 | TEST_F(TokenTypeUnitTests, ProtobufTokenTypeToTokenType) 15 | { 16 | // Given / When / Then 17 | ASSERT_TRUE(gProtobufTokenTypeToTokenType.find(proto::TokenType::FUNGIBLE_COMMON) != 18 | gProtobufTokenTypeToTokenType.end()); 19 | ASSERT_TRUE(gProtobufTokenTypeToTokenType.find(proto::TokenType::NON_FUNGIBLE_UNIQUE) != 20 | gProtobufTokenTypeToTokenType.end()); 21 | EXPECT_EQ(TokenType::FUNGIBLE_COMMON, gProtobufTokenTypeToTokenType.at(proto::TokenType::FUNGIBLE_COMMON)); 22 | EXPECT_EQ(TokenType::NON_FUNGIBLE_UNIQUE, gProtobufTokenTypeToTokenType.at(proto::TokenType::NON_FUNGIBLE_UNIQUE)); 23 | } 24 | 25 | //----- 26 | TEST_F(TokenTypeUnitTests, TokenTypeToString) 27 | { 28 | // Given / When / Then 29 | ASSERT_TRUE(gTokenTypeToString.find(TokenType::FUNGIBLE_COMMON) != gTokenTypeToString.end()); 30 | ASSERT_TRUE(gTokenTypeToString.find(TokenType::NON_FUNGIBLE_UNIQUE) != gTokenTypeToString.end()); 31 | EXPECT_STRCASEEQ(gTokenTypeToString.at(TokenType::FUNGIBLE_COMMON), "FUNGIBLE_COMMON"); 32 | EXPECT_STRCASEEQ(gTokenTypeToString.at(TokenType::NON_FUNGIBLE_UNIQUE), "NON_FUNGIBLE_UNIQUE"); 33 | } 34 | -------------------------------------------------------------------------------- /src/sdk/main/src/impl/HieroCertificateVerifier.cc: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | #include "impl/HieroCertificateVerifier.h" 3 | #include "impl/HexConverter.h" 4 | #include "impl/Utilities.h" 5 | #include "impl/openssl_utils/OpenSSLUtils.h" 6 | 7 | #include 8 | 9 | namespace Hiero::internal 10 | { 11 | //----- 12 | HieroCertificateVerifier::HieroCertificateVerifier(std::vector certificateHash) 13 | : mExpectedHash(std::move(certificateHash)) 14 | { 15 | } 16 | 17 | //----- 18 | bool HieroCertificateVerifier::Verify(grpc::experimental::TlsCustomVerificationCheckRequest* request, 19 | std::function, 20 | grpc::Status* sync_status) 21 | { 22 | if (const grpc::string_ref grpcCertificateChain = request->peer_cert_full_chain(); 23 | mExpectedHash == 24 | OpenSSLUtils::computeSHA384(internal::Utilities::stringToByteVector(grpcCertificateChain.data()))) 25 | { 26 | *sync_status = grpc::Status(grpc::StatusCode::UNAUTHENTICATED, 27 | "Hash of node certificate chain doesn't match hash contained in address book"); 28 | } 29 | else 30 | { 31 | *sync_status = grpc::Status(grpc::StatusCode::OK, "Certificate chain hash matches expected"); 32 | } 33 | 34 | // always true, since this is called synchronously 35 | return true; 36 | } 37 | 38 | } // namespace Hiero::internal 39 | -------------------------------------------------------------------------------- /src/sdk/examples/InitializeClientWithMirrorNodeAddressBookExample.cpp: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | #include "AccountCreateTransaction.h" 3 | #include "Client.h" 4 | #include "ECDSAsecp256k1PrivateKey.h" 5 | #include "TransactionReceipt.h" 6 | #include "TransactionResponse.h" 7 | 8 | #include 9 | #include 10 | 11 | using namespace Hiero; 12 | 13 | int main(int argc, char** argv) 14 | { 15 | dotenv::init(); 16 | const AccountId operatorAccountId = AccountId::fromString(std::getenv("OPERATOR_ID")); 17 | const std::shared_ptr operatorPrivateKey = 18 | ECDSAsecp256k1PrivateKey::fromString(std::getenv("OPERATOR_KEY")); 19 | 20 | // Initialize the client with the testnet mirror node. This will also get the address book from the mirror node and 21 | // use it to populate the Client's consensus network. 22 | Client client = Client::forMirrorNetwork({ "testnet.mirrornode.hedera.com:443" }); 23 | client.setOperator(operatorAccountId, operatorPrivateKey); 24 | 25 | // Attempt to execute a transaction. 26 | TransactionReceipt txReceipt = AccountCreateTransaction() 27 | .setKeyWithoutAlias(ECDSAsecp256k1PrivateKey::generatePrivateKey()) 28 | .execute(client) 29 | .getReceipt(client); 30 | std::cout << "Created account " << txReceipt.mAccountId->toString() << std::endl; 31 | 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /src/sdk/main/src/impl/ASN1ECKey.cc: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | 3 | #include "exceptions/BadKeyException.h" 4 | 5 | #include "impl/ASN1ECKey.h" 6 | #include "impl/HexConverter.h" 7 | 8 | namespace Hiero::internal::asn1 9 | { 10 | void ASN1ECKey::decode(const std::vector& bytes) 11 | { 12 | int currentByteIndex = 0; 13 | while (currentByteIndex < bytes.size() - 1) 14 | { 15 | const std::byte asn1Tag = bytes[currentByteIndex++]; 16 | const int asn1TagSize = static_cast(bytes[currentByteIndex++]); 17 | 18 | if (currentByteIndex + asn1TagSize > bytes.size()) 19 | { 20 | throw BadKeyException("Bad PEM/DER EC KEY bytes data!"); 21 | } 22 | // Ignore sequence as ASN1 for EC Key is in basic format 23 | if (asn1Tag != SEQUENCE) 24 | { 25 | std::vector asn1DataAtTag(bytes.begin() + currentByteIndex, 26 | bytes.begin() + currentByteIndex + asn1TagSize); 27 | currentByteIndex += asn1TagSize; 28 | 29 | asn1KeyData.insert({ asn1Tag, asn1DataAtTag }); 30 | } 31 | } 32 | } 33 | 34 | const std::vector ASN1ECKey::get(const std::byte tag) const 35 | { 36 | auto entry = asn1KeyData.find(tag); 37 | if (entry != asn1KeyData.end()) 38 | return entry->second; 39 | else 40 | throw BadKeyException("Data not decoded properly for input PEM/DER EC KEY bytes!"); 41 | } 42 | 43 | } // namespace Hiero::internal:asn1 44 | -------------------------------------------------------------------------------- /src/sdk/main/src/Key.cc: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | #include "Key.h" 3 | #include "ContractId.h" 4 | #include "ECDSAsecp256k1PublicKey.h" 5 | #include "ED25519PublicKey.h" 6 | #include "KeyList.h" 7 | #include "impl/Utilities.h" 8 | 9 | #include 10 | 11 | namespace Hiero 12 | { 13 | //----- 14 | std::unique_ptr Key::fromProtobuf(const proto::Key& key) 15 | { 16 | switch (key.key_case()) 17 | { 18 | case proto::Key::KeyCase::kContractID: 19 | return std::make_unique(ContractId::fromProtobuf(key.contractid())); 20 | case proto::Key::KeyCase::kEd25519: 21 | return ED25519PublicKey::fromBytes(internal::Utilities::stringToByteVector(key.ed25519())); 22 | case proto::Key::KeyCase::kECDSASecp256K1: 23 | return ECDSAsecp256k1PublicKey::fromBytes(internal::Utilities::stringToByteVector(key.ecdsa_secp256k1())); 24 | case proto::Key::KeyCase::kKeyList: 25 | return std::make_unique(KeyList::fromProtobuf(key.keylist())); 26 | case proto::Key::KeyCase::kThresholdKey: 27 | return std::make_unique(KeyList::fromProtobuf(key.thresholdkey())); 28 | default: 29 | throw std::invalid_argument("Key protobuf case not recognized"); 30 | } 31 | } 32 | 33 | //----- 34 | std::vector Key::toBytes() const 35 | { 36 | return internal::Utilities::stringToByteVector(toProtobufKey()->SerializeAsString()); 37 | } 38 | 39 | } // namespace Hiero 40 | -------------------------------------------------------------------------------- /src/tck/include/account/params/allowance/HbarAllowanceParams.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | #ifndef HIERO_TCK_CPP_HBAR_ALLOWANCE_PARAMS_H_ 3 | #define HIERO_TCK_CPP_HBAR_ALLOWANCE_PARAMS_H_ 4 | 5 | #include "json/JsonUtils.h" 6 | 7 | #include 8 | #include 9 | 10 | namespace Hiero::TCK::AccountService 11 | { 12 | /** 13 | * Struct that contains the parameters of an Hbar allowance. 14 | */ 15 | struct HbarAllowanceParams 16 | { 17 | /** 18 | * The amount of Hbar to allowance. 19 | */ 20 | std::string mAmount; 21 | }; 22 | 23 | } // namespace Hiero::TCK::AccountService 24 | 25 | namespace nlohmann 26 | { 27 | /** 28 | * JSON serializer template specialization required to convert HbarAllowanceParams arguments properly. 29 | */ 30 | template<> 31 | struct [[maybe_unused]] adl_serializer 32 | { 33 | /** 34 | * Convert a JSON object to a HbarAllowanceParams. 35 | * 36 | * @param jsonFrom The JSON object with which to fill the HbarAllowanceParams. 37 | * @param params The HbarAllowanceParams to fill with the JSON object. 38 | */ 39 | static void from_json(const json& jsonFrom, Hiero::TCK::AccountService::HbarAllowanceParams& params) 40 | { 41 | params.mAmount = Hiero::TCK::getRequiredJsonParameter(jsonFrom, "amount"); 42 | } 43 | }; 44 | 45 | } // namespace nlohmann 46 | 47 | #endif // HIERO_TCK_CPP_HBAR_ALLOWANCE_PARAMS_H_ 48 | -------------------------------------------------------------------------------- /src/sdk/main/include/TokenSupplyType.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | #ifndef HIERO_SDK_CPP_TOKEN_SUPPLY_TYPE_H_ 3 | #define HIERO_SDK_CPP_TOKEN_SUPPLY_TYPE_H_ 4 | 5 | #include 6 | #include 7 | 8 | namespace proto 9 | { 10 | enum TokenSupplyType : int; 11 | } 12 | 13 | namespace Hiero 14 | { 15 | /** 16 | * Possible token supply types (IWA Compatibility). Indicates how many tokens can have during its lifetime. 17 | */ 18 | enum class TokenSupplyType 19 | { 20 | /** 21 | * Indicates that tokens have an upper bound of std::numeric_limit::max(). 22 | */ 23 | INFINITE, 24 | /** 25 | * Indicates that tokens have an upper bound of maxSupply, provided on token creation. 26 | */ 27 | FINITE 28 | }; 29 | 30 | /** 31 | * Map of protobuf TokenSupplyTypes to the corresponding TokenSupplyType. 32 | */ 33 | extern const std::unordered_map gProtobufTokenSupplyTypeToTokenSupplyType; 34 | 35 | /** 36 | * Map of TokenSupplyTypes to the corresponding protobuf TokenSupplyType. 37 | */ 38 | extern const std::unordered_map gTokenSupplyTypeToProtobufTokenSupplyType; 39 | 40 | /** 41 | * Map of TokenSupplyType to its corresponding string. 42 | */ 43 | [[maybe_unused]] extern const std::unordered_map gTokenSupplyTypeToString; 44 | 45 | } // namespace Hiero 46 | 47 | #endif // HIERO_SDK_CPP_TOKEN_SUPPLY_TYPE_H_ 48 | -------------------------------------------------------------------------------- /src/sdk/tests/unit/ProxyStakerUnitTests.cc: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | #include "ProxyStaker.h" 3 | 4 | #include 5 | #include 6 | 7 | using namespace Hiero; 8 | 9 | class ProxyStakerUnitTests : public ::testing::Test 10 | { 11 | protected: 12 | [[nodiscard]] inline const AccountId& getTestAccountId() const { return mTestAccountId; } 13 | [[nodiscard]] inline const Hbar& getTestAmount() const { return mTestAmount; } 14 | 15 | private: 16 | const AccountId mTestAccountId = AccountId(1ULL, 2ULL, 3ULL); 17 | const Hbar mTestAmount = Hbar(4LL); 18 | }; 19 | 20 | //----- 21 | TEST_F(ProxyStakerUnitTests, ConstructWithValues) 22 | { 23 | // Given / When 24 | const ProxyStaker proxyStaker(getTestAccountId(), getTestAmount().toTinybars()); 25 | 26 | // Then 27 | EXPECT_EQ(proxyStaker.mAccountId, getTestAccountId()); 28 | EXPECT_EQ(proxyStaker.mAmount, getTestAmount()); 29 | } 30 | 31 | //----- 32 | TEST_F(ProxyStakerUnitTests, FromProtobuf) 33 | { 34 | // Given 35 | proto::ProxyStaker protoProxyStaker; 36 | protoProxyStaker.set_allocated_accountid(getTestAccountId().toProtobuf().release()); 37 | protoProxyStaker.set_amount(getTestAmount().toTinybars()); 38 | 39 | // When 40 | const ProxyStaker proxyStaker = ProxyStaker::fromProtobuf(protoProxyStaker); 41 | 42 | // Then 43 | EXPECT_EQ(proxyStaker.mAccountId, getTestAccountId()); 44 | EXPECT_EQ(proxyStaker.mAmount, getTestAmount()); 45 | } 46 | -------------------------------------------------------------------------------- /src/sdk/main/include/TokenKeyValidation.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | #ifndef HIERO_SDK_CPP_TOKEN_KEY_VALIDATION_TYPE_H_ 3 | #define HIERO_SDK_CPP_TOKEN_KEY_VALIDATION_TYPE_H_ 4 | 5 | #include 6 | #include 7 | 8 | namespace proto 9 | { 10 | enum TokenKeyValidation : int; 11 | } 12 | 13 | namespace Hiero 14 | { 15 | /** 16 | * Types of validation strategies for token keys. 17 | */ 18 | enum class TokenKeyValidation 19 | { 20 | /** 21 | * Currently the default behaviour. It will perform all token key validations. 22 | */ 23 | FULL_VALIDATION, 24 | 25 | /** 26 | * Perform no validations at all for all passed token keys. 27 | */ 28 | NO_VALIDATION 29 | }; 30 | 31 | /** 32 | * Map of protobuf TokenKeyValidation to the corresponding TokenKeyValidation. 33 | */ 34 | extern const std::unordered_map 35 | gProtobufTokenKeyValidationToTokenKeyValidation; 36 | 37 | /** 38 | * Map of TokenKeyValidation to the corresponding protobuf TokenKeyValidation. 39 | */ 40 | extern const std::unordered_map 41 | gTokenKeyValidationToProtobufTokenKeyValidation; 42 | 43 | /** 44 | * Map of TokenKeyValidation to its corresponding string. 45 | */ 46 | [[maybe_unused]] extern const std::unordered_map gTokenKeyValidationToString; 47 | 48 | } // namespace Hiero 49 | 50 | #endif // HIERO_SDK_CPP_TOKEN_KEY_VALIDATION_TYPE_H_ 51 | -------------------------------------------------------------------------------- /src/sdk/main/src/impl/MirrorNodeContractEstimateGasQuery.cc: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | #include "impl/MirrorNodeContractEstimateGasQuery.h" 3 | #include "impl/MirrorNetwork.h" 4 | #include "impl/MirrorNodeGateway.h" 5 | 6 | #include "exceptions/IllegalStateException.h" 7 | 8 | namespace Hiero 9 | { 10 | 11 | std::string MirrorNodeContractEstimateGasQuery::execute(const Client& client) 12 | { 13 | setEstimate(true); 14 | 15 | if (!getContractEvmAddress().has_value()) 16 | { 17 | populateContractEvmAddress(client); 18 | } 19 | 20 | const json contractCallResult = 21 | internal::MirrorNodeGateway::MirrorNodeQuery(client.getClientMirrorNetwork()->getNetwork()[0], 22 | { "call" }, 23 | internal::MirrorNodeGateway::CONTRACT_INFO_QUERY, 24 | toJson().dump(), 25 | "POST"); 26 | 27 | if (!contractCallResult.contains("result")) 28 | { 29 | throw IllegalStateException("No result was found for the gas estimation."); 30 | } 31 | std::string estimatedGas = contractCallResult["result"].dump(); 32 | // json dump returns strings in dquotes, so we need to trim first and last characters 33 | estimatedGas = estimatedGas.substr(1, estimatedGas.length() - 2); 34 | // trim 0x 35 | estimatedGas = estimatedGas.substr(2); 36 | 37 | return estimatedGas; 38 | } 39 | 40 | } // namespace Hiero -------------------------------------------------------------------------------- /src/sdk/tests/integration/PrngTransactionIntegrationTests.cc: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | #include "BaseIntegrationTest.h" 3 | #include "PrngTransaction.h" 4 | #include "TransactionRecord.h" 5 | #include "TransactionResponse.h" 6 | 7 | #include 8 | 9 | using namespace Hiero; 10 | 11 | class PrngTransactionIntegrationTests : public BaseIntegrationTest 12 | { 13 | }; 14 | 15 | //----- 16 | TEST_F(PrngTransactionIntegrationTests, ExecutePrngTransactionNoRange) 17 | { 18 | // Given / When 19 | TransactionResponse txResponse; 20 | ASSERT_NO_THROW(txResponse = PrngTransaction().execute(getTestClient())); 21 | 22 | // Then 23 | TransactionRecord txRecord; 24 | ASSERT_NO_THROW(txRecord = txResponse.getRecord(getTestClient())); 25 | 26 | EXPECT_FALSE(txRecord.mPrngBytes.empty()); 27 | EXPECT_FALSE(txRecord.mPrngNumber.has_value()); 28 | } 29 | 30 | //----- 31 | TEST_F(PrngTransactionIntegrationTests, ExecutePrngTransactionRange) 32 | { 33 | // Given 34 | const int range = 100; 35 | 36 | // When 37 | TransactionResponse txResponse; 38 | ASSERT_NO_THROW(txResponse = PrngTransaction().setRange(range).execute(getTestClient())); 39 | 40 | // Then 41 | TransactionRecord txRecord; 42 | ASSERT_NO_THROW(txRecord = txResponse.getRecord(getTestClient())); 43 | 44 | EXPECT_TRUE(txRecord.mPrngBytes.empty()); 45 | EXPECT_TRUE(txRecord.mPrngNumber.has_value()); 46 | EXPECT_GE(txRecord.mPrngNumber.value(), 0); 47 | EXPECT_LE(txRecord.mPrngNumber.value(), range); 48 | } 49 | -------------------------------------------------------------------------------- /src/sdk/tests/unit/TokenSupplyTypeUnitTests.cc: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | #include "TokenSupplyType.h" 3 | 4 | #include 5 | #include 6 | 7 | using namespace Hiero; 8 | 9 | class TokenSupplyTypeUnitTests : public ::testing::Test 10 | { 11 | }; 12 | 13 | //----- 14 | TEST_F(TokenSupplyTypeUnitTests, ProtobufTokenSupplyTypeToTokenSupplyType) 15 | { 16 | // Given / When / Then 17 | ASSERT_TRUE(gProtobufTokenSupplyTypeToTokenSupplyType.find(proto::TokenSupplyType::INFINITE) != 18 | gProtobufTokenSupplyTypeToTokenSupplyType.end()); 19 | ASSERT_TRUE(gProtobufTokenSupplyTypeToTokenSupplyType.find(proto::TokenSupplyType::FINITE) != 20 | gProtobufTokenSupplyTypeToTokenSupplyType.end()); 21 | EXPECT_EQ(TokenSupplyType::INFINITE, gProtobufTokenSupplyTypeToTokenSupplyType.at(proto::TokenSupplyType::INFINITE)); 22 | EXPECT_EQ(TokenSupplyType::FINITE, gProtobufTokenSupplyTypeToTokenSupplyType.at(proto::TokenSupplyType::FINITE)); 23 | } 24 | 25 | //----- 26 | TEST_F(TokenSupplyTypeUnitTests, TokenSupplyTypeToString) 27 | { 28 | // Given / When / Then 29 | ASSERT_TRUE(gTokenSupplyTypeToString.find(TokenSupplyType::INFINITE) != gTokenSupplyTypeToString.end()); 30 | ASSERT_TRUE(gTokenSupplyTypeToString.find(TokenSupplyType::FINITE) != gTokenSupplyTypeToString.end()); 31 | EXPECT_STRCASEEQ(gTokenSupplyTypeToString.at(TokenSupplyType::INFINITE), "INFINITE"); 32 | EXPECT_STRCASEEQ(gTokenSupplyTypeToString.at(TokenSupplyType::FINITE), "FINITE"); 33 | } 34 | -------------------------------------------------------------------------------- /src/sdk/main/include/impl/HexConverter.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | #ifndef HIERO_SDK_CPP_IMPL_HEX_CONVERTER_H_ 3 | #define HIERO_SDK_CPP_IMPL_HEX_CONVERTER_H_ 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | namespace Hiero::internal::HexConverter 10 | { 11 | /** 12 | * Convert an array of bytes to a hex string. 13 | * 14 | * @param bytes The bytes from which to get the hex string. 15 | * @return A string containing the hex values of the input byte array. 16 | * @throws OpenSSLException If OpenSSL is unable to convert the input bytes to hex. 17 | */ 18 | std::string bytesToHex(const std::vector& bytes); 19 | 20 | /** 21 | * Convert a hex string to the array of bytes it represents. 22 | * 23 | * @param hex The hex string to convert to a byte array. 24 | * @return The byte array containing the values of the input hex string. 25 | * @throws OpenSSLException If OpenSSL is unable to convert the input string to a byte array. 26 | */ 27 | std::vector hexToBytes(std::string_view hex); 28 | 29 | /** 30 | * Convert a Base64-encoded string to a hexadecimal string. 31 | * 32 | * This function takes a Base64-encoded string as input and returns a hexadecimal 33 | * string. 34 | * 35 | * @param base64 The Base64-encoded string to convert. 36 | * @return The hexadecimal representation of the input. 37 | */ 38 | std::string base64ToHex(std::string_view base64); 39 | 40 | } // namespace Hiero::internal::HexConverter 41 | 42 | #endif // HIERO_SDK_CPP_IMPL_HEX_CONVERTER_H_ 43 | -------------------------------------------------------------------------------- /src/sdk/main/src/HbarAllowance.cc: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | #include "HbarAllowance.h" 3 | 4 | #include 5 | 6 | namespace Hiero 7 | { 8 | //----- 9 | HbarAllowance::HbarAllowance(AccountId owner, AccountId spender, const Hbar& amount) 10 | : mOwnerAccountId(std::move(owner)) 11 | , mSpenderAccountId(std::move(spender)) 12 | , mAmount(amount) 13 | { 14 | } 15 | 16 | //----- 17 | HbarAllowance HbarAllowance::fromProtobuf(const proto::CryptoAllowance& proto) 18 | { 19 | HbarAllowance allowance; 20 | 21 | if (proto.has_owner()) 22 | { 23 | allowance.mOwnerAccountId = AccountId::fromProtobuf(proto.owner()); 24 | } 25 | 26 | if (proto.has_spender()) 27 | { 28 | allowance.mSpenderAccountId = AccountId::fromProtobuf(proto.spender()); 29 | } 30 | 31 | allowance.mAmount = Hbar(proto.amount(), HbarUnit::TINYBAR()); 32 | return allowance; 33 | } 34 | 35 | //----- 36 | void HbarAllowance::validateChecksums(const Client& client) const 37 | { 38 | mOwnerAccountId.validateChecksum(client); 39 | mSpenderAccountId.validateChecksum(client); 40 | } 41 | 42 | //----- 43 | std::unique_ptr HbarAllowance::toProtobuf() const 44 | { 45 | auto proto = std::make_unique(); 46 | proto->set_allocated_owner(mOwnerAccountId.toProtobuf().release()); 47 | proto->set_allocated_spender(mSpenderAccountId.toProtobuf().release()); 48 | proto->set_amount(mAmount.toTinybars()); 49 | return proto; 50 | } 51 | 52 | } // namespace Hiero 53 | -------------------------------------------------------------------------------- /src/sdk/main/src/IPv4Address.cc: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | #include "IPv4Address.h" 3 | #include "exceptions/IllegalStateException.h" 4 | 5 | #include 6 | 7 | namespace Hiero 8 | { 9 | //----- 10 | IPv4Address IPv4Address::fromBytes(const std::vector& bytes) 11 | { 12 | if (bytes.size() != 4) 13 | { 14 | throw std::invalid_argument("Incorrect byte array size, should be 4 bytes but is " + std::to_string(bytes.size())); 15 | } 16 | 17 | IPv4Address iPv4Address; 18 | 19 | for (const auto& byte : bytes) 20 | { 21 | iPv4Address.mAddress.push_back(byte); 22 | } 23 | return iPv4Address; 24 | } 25 | 26 | //----- 27 | std::vector IPv4Address::toBytes() const 28 | { 29 | return mAddress; 30 | } 31 | 32 | //----- 33 | std::string IPv4Address::toString() const 34 | { 35 | if (mAddress.size() != 4) 36 | { 37 | throw IllegalStateException("Incorrect byte array size, should be 4 bytes but is " + 38 | std::to_string(mAddress.size())); 39 | } 40 | else 41 | { 42 | return std::to_string(std::to_integer(mAddress.at(0))) + '.' + 43 | std::to_string(std::to_integer(mAddress.at(1))) + '.' + 44 | std::to_string(std::to_integer(mAddress.at(2))) + '.' + 45 | std::to_string(std::to_integer(mAddress.at(3))); 46 | } 47 | } 48 | 49 | //----- 50 | bool IPv4Address::isEmpty() const 51 | { 52 | return mAddress.empty(); 53 | } 54 | 55 | } // namespace Hiero 56 | -------------------------------------------------------------------------------- /src/sdk/main/src/PendingAirdropRecord.cc: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | #include "PendingAirdropRecord.h" 3 | #include "PendingAirdropId.h" 4 | 5 | #include 6 | #include 7 | 8 | namespace Hiero 9 | { 10 | //----- 11 | PendingAirdropRecord::PendingAirdropRecord(PendingAirdropId pendingAirdropId, uint64_t amount) 12 | : mPendingAirdropId(pendingAirdropId) 13 | , mAmount(amount) 14 | { 15 | } 16 | 17 | //----- 18 | PendingAirdropRecord PendingAirdropRecord::fromProtobuf(const proto::PendingAirdropRecord& proto) 19 | { 20 | PendingAirdropRecord pendingAirdropRecord; 21 | 22 | pendingAirdropRecord.mPendingAirdropId = PendingAirdropId::fromProtobuf(proto.pending_airdrop_id()); 23 | pendingAirdropRecord.mAmount = proto.pending_airdrop_value().amount(); 24 | 25 | return pendingAirdropRecord; 26 | } 27 | 28 | //----- 29 | std::unique_ptr PendingAirdropRecord::toProtobuf() const 30 | { 31 | auto proto = std::make_unique(); 32 | 33 | proto->set_allocated_pending_airdrop_id(mPendingAirdropId.toProtobuf().release()); 34 | 35 | auto value = std::make_unique(); 36 | value->set_amount(mAmount); 37 | 38 | proto->set_allocated_pending_airdrop_value(value.release()); 39 | 40 | return proto; 41 | } 42 | 43 | //----- 44 | std::string PendingAirdropRecord::toString() const 45 | { 46 | return mPendingAirdropId.toString() + " " + std::to_string(mAmount); 47 | } 48 | 49 | } // namespace Hiero -------------------------------------------------------------------------------- /src/sdk/main/src/NodeAddressBook.cc: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | #include "NodeAddressBook.h" 3 | #include "impl/Utilities.h" 4 | 5 | #include 6 | 7 | namespace Hiero 8 | { 9 | //----- 10 | NodeAddressBook NodeAddressBook::fromProtobuf(const proto::NodeAddressBook& proto) 11 | { 12 | NodeAddressBook nodeAddressBook; 13 | for (int i = 0; i < proto.nodeaddress_size(); ++i) 14 | { 15 | nodeAddressBook.mNodeAddresses.push_back(NodeAddress::fromProtobuf(proto.nodeaddress(i))); 16 | } 17 | 18 | return nodeAddressBook; 19 | } 20 | 21 | //----- 22 | NodeAddressBook NodeAddressBook::fromBytes(const std::vector& bytes) 23 | { 24 | proto::NodeAddressBook addressBook; 25 | addressBook.ParseFromArray(bytes.data(), static_cast(bytes.size())); 26 | return fromProtobuf(addressBook); 27 | } 28 | 29 | //----- 30 | std::unique_ptr NodeAddressBook::toProtobuf() const 31 | { 32 | auto proto = std::make_unique(); 33 | for (const NodeAddress& address : mNodeAddresses) 34 | { 35 | *proto->add_nodeaddress() = *address.toProtobuf(); 36 | } 37 | 38 | return proto; 39 | } 40 | 41 | //----- 42 | std::vector NodeAddressBook::toBytes() const 43 | { 44 | return internal::Utilities::stringToByteVector(toProtobuf()->SerializeAsString()); 45 | } 46 | 47 | //----- 48 | NodeAddressBook& NodeAddressBook::setNodeAddresses(const std::vector& addresses) 49 | { 50 | mNodeAddresses = addresses; 51 | return *this; 52 | } 53 | 54 | } // namespace Hiero 55 | -------------------------------------------------------------------------------- /src/sdk/tests/unit/BaseUnitTest.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | #ifndef HIERO_SDK_CPP_BASE_UNIT_TEST_H_ 3 | #define HIERO_SDK_CPP_BASE_UNIT_TEST_H_ 4 | 5 | #include "AccountId.h" 6 | #include "Client.h" 7 | #include "ED25519PrivateKey.h" 8 | #include "PrivateKey.h" 9 | #include "TransactionId.h" 10 | 11 | #include 12 | #include 13 | 14 | namespace Hiero 15 | { 16 | 17 | class BaseUnitTest : public testing::Test 18 | { 19 | protected: 20 | /** Get the test Client mock used in unit tests. 21 | * 22 | * @return The test Client mock. 23 | */ 24 | [[nodiscard]] inline const Client& getTestClientMock() const { return mClientMock; } 25 | 26 | /** Get a transaction ID with a valid start time. 27 | * 28 | * @return A TransactionId with a valid start time. 29 | */ 30 | [[nodiscard]] inline const TransactionId& getTestTransactionIdMock() const { return mTransactionIdMock; } 31 | 32 | /** Set up the test environment. 33 | * 34 | * This method is called before each test case to initialize the test Client and file content. 35 | */ 36 | void SetUp() override; 37 | 38 | private: 39 | Client mClientMock; 40 | TransactionId mTransactionIdMock; 41 | const AccountId mOperatorMockAccountId = AccountId::fromString("0.0.2"); 42 | const std::shared_ptr mOperatorMockPrivateKey = ED25519PrivateKey::fromString( 43 | "302e020100300506032b65700422042091132178e72057a1d7528025956fe39b0b847f200ab59b2fdd367017f3087137"); 44 | }; 45 | 46 | } // namespace Hiero 47 | 48 | #endif // HIERO_SDK_CPP_BASE_UNIT_TEST_H_ -------------------------------------------------------------------------------- /src/sdk/tests/integration/JSONIntegrationTests.cc: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | using json = nlohmann::json; 8 | 9 | class JSONIntegrationTests : public ::testing::Test 10 | { 11 | protected: 12 | [[nodiscard]] inline const std::string getPathToJSON() const { return mFilePath.string(); } 13 | 14 | private: 15 | const std::filesystem::path mFilePath = (std::filesystem::current_path() / "local_node.json").string(); 16 | }; 17 | 18 | // Tests JSON parsing of a configuration file for the Local Node. 19 | TEST_F(JSONIntegrationTests, ParseJSONConfig) 20 | { 21 | // Given 22 | std::string testPathToJSON = getPathToJSON(); 23 | std::ifstream testInputFile(testPathToJSON, std::ios::in); 24 | 25 | try 26 | { 27 | // When 28 | json jsonData = json::parse(testInputFile); 29 | 30 | // Then 31 | EXPECT_FALSE(jsonData.empty()); 32 | EXPECT_FALSE(jsonData["network"].empty()); 33 | EXPECT_FALSE(jsonData["network"]["0.0.3"].empty()); 34 | EXPECT_TRUE(jsonData["network"]["0.0.3"].is_string()); 35 | EXPECT_FALSE(jsonData["operator"].empty()); 36 | EXPECT_FALSE(jsonData["operator"]["accountId"].empty()); 37 | EXPECT_TRUE(jsonData["operator"]["accountId"].is_string()); 38 | EXPECT_FALSE(jsonData["operator"]["privateKey"].empty()); 39 | EXPECT_TRUE(jsonData["operator"]["privateKey"].is_string()); 40 | } 41 | catch (json::parse_error& error) 42 | { 43 | EXPECT_TRUE(false); 44 | } 45 | 46 | testInputFile.close(); 47 | } -------------------------------------------------------------------------------- /src/sdk/main/include/IPv4Address.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | #ifndef HIERO_SDK_CPP_IPV4_ADDRESS_H_ 3 | #define HIERO_SDK_CPP_IPV4_ADDRESS_H_ 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | namespace Hiero 11 | { 12 | /** 13 | * An IPv4 address (without port). 14 | */ 15 | class IPv4Address 16 | { 17 | public: 18 | /** 19 | * Construct an IPv4Address object from a byte array. 20 | * 21 | * @param bytes The byte array from which to construct an IPv4Address. 22 | * @return The constructed IPv4Address object. 23 | * @throws std::invalid_argument If an IPv4Address could not be realized from the input bytes. 24 | */ 25 | [[nodiscard]] static IPv4Address fromBytes(const std::vector& bytes); 26 | 27 | /** 28 | * Get the byte array representation of this IPv4Address. 29 | * 30 | * @return The byte array representation of this IPv4Address. 31 | */ 32 | [[nodiscard]] std::vector toBytes() const; 33 | 34 | /** 35 | * Get the string representation of this IPv4Address. 36 | * 37 | * @return The string representation of this IPv4Address. 38 | */ 39 | [[nodiscard]] std::string toString() const; 40 | 41 | /** 42 | * Check if the IPV4Address is empty. 43 | * 44 | * @return The boolean representation of an IPV4Address empty state. 45 | */ 46 | [[nodiscard]] bool isEmpty() const; 47 | 48 | private: 49 | /** 50 | * The four octets of the address. 51 | */ 52 | std::vector mAddress; 53 | }; 54 | 55 | } // namespace Hiero 56 | 57 | #endif // HIERO_SDK_CPP_IPV4_ADDRESS_H_ 58 | -------------------------------------------------------------------------------- /src/sdk/main/include/impl/DerivationPathUtils.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | #ifndef HIERO_SDK_CPP_IMPL_DERIVATION_PATH_UTILS_H_ 3 | #define HIERO_SDK_CPP_IMPL_DERIVATION_PATH_UTILS_H_ 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | /** 10 | * Utility functions dealing with wallet derivation paths, as described in BIP32, BIP44, and SLIP10. 11 | */ 12 | namespace Hiero::internal::DerivationPathUtils 13 | { 14 | /** 15 | * Check if an index falls into the "unhardened" or "hardened" category. 16 | * Unhardened: [0, 2147483647]; Hardened: [2147483648, UINT32_MAX] 17 | * 18 | * @param index The index to check. 19 | * @return \c TRUE if the index is in the hardened range, otherwise \c FALSE. 20 | */ 21 | bool isHardenedChildIndex(uint32_t index); 22 | 23 | /** 24 | * Convert an index into its hardened counterpart (e.g. 0 -> 2147483648, 1-> 2147483649, etc.). 25 | * 26 | * @param index The index of which to get the hardened counterpart. 27 | * @return The hardened index. 28 | * @throws std::invalid_argument If the index is already hardened. 29 | */ 30 | uint32_t getHardenedIndex(uint32_t index); 31 | 32 | /** 33 | * Converts a uint32_t index into a big endian byte array (direct implementation of ser32 function from BIP 32) 34 | * 35 | * @param childIndex The index to convert to a big endian byte array. 36 | * @return The big endian byte array representing the child index. 37 | */ 38 | std::vector indexToBigEndianArray(uint32_t childIndex); 39 | 40 | }; // namespace Hiero::internal::DerivationPathUtils 41 | 42 | #endif // HIERO_SDK_CPP_IMPL_DERIVATION_PATH_UTILS_H_ 43 | -------------------------------------------------------------------------------- /src/sdk/tests/integration/HttpClientIntegrationTests.cc: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | 3 | #include "BaseIntegrationTest.h" 4 | #include "impl/HttpClient.h" 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | using json = nlohmann::json; 12 | using namespace Hiero; 13 | 14 | class HttpClientIntegrationTests : public BaseIntegrationTest 15 | { 16 | protected: 17 | [[nodiscard]] inline const std::string& getURL() const { return mUrl; } 18 | [[nodiscard]] inline const std::string& getJsonMirrorNetworkTag() const { return mJsonMirrorNetworkTag; } 19 | [[nodiscard]] inline const std::string& getAccountIdStr() const { return mAccountIdStr; } 20 | 21 | private: 22 | const std::string mUrl = "http://127.0.0.1:5551/api/v1/accounts/"; 23 | const std::string mJsonMirrorNetworkTag = "mirrorNetwork"; 24 | const std::string mAccountIdStr = "0.0.2"; 25 | }; 26 | 27 | //----- 28 | TEST_F(HttpClientIntegrationTests, GETAccountFromLocalMirrorNode) 29 | { 30 | // Given 31 | const std::string& mirrorNetworkTag = getJsonMirrorNetworkTag(); 32 | const std::string& accountIdStr = getAccountIdStr(); 33 | std::string mUrl(getURL()); 34 | mUrl += accountIdStr; 35 | 36 | // When 37 | std::string response; 38 | ASSERT_NO_THROW(response = internal::HttpClient::invokeREST(mUrl, "GET")); 39 | 40 | // Then 41 | json responseData = json::parse(response); 42 | 43 | ASSERT_FALSE(responseData.empty()); 44 | EXPECT_FALSE(responseData["account"].empty()); 45 | EXPECT_FALSE(responseData["created_timestamp"].empty()); 46 | 47 | EXPECT_EQ(responseData["account"], accountIdStr); 48 | } 49 | -------------------------------------------------------------------------------- /src/tck/include/account/params/allowance/TokenAllowanceParams.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | #ifndef HIERO_TCK_CPP_TOKEN_ALLOWANCE_PARAMS_H_ 3 | #define HIERO_TCK_CPP_TOKEN_ALLOWANCE_PARAMS_H_ 4 | 5 | #include "json/JsonUtils.h" 6 | 7 | #include 8 | #include 9 | 10 | namespace Hiero::TCK::AccountService 11 | { 12 | /** 13 | * Struct that contains the parameters of a token allowance. 14 | */ 15 | struct TokenAllowanceParams 16 | { 17 | /** 18 | * The ID of the token being allowanced. 19 | */ 20 | std::string mTokenId; 21 | 22 | /** 23 | * The amount of the token to allowance. 24 | */ 25 | std::string mAmount; 26 | }; 27 | 28 | } // namespace Hiero::TCK::AccountService 29 | 30 | namespace nlohmann 31 | { 32 | /** 33 | * JSON serializer template specialization required to convert TokenAllowanceParams arguments properly. 34 | */ 35 | template<> 36 | struct [[maybe_unused]] adl_serializer 37 | { 38 | /** 39 | * Convert a JSON object to a TokenAllowanceParams. 40 | * 41 | * @param jsonFrom The JSON object with which to fill the TokenAllowanceParams. 42 | * @param params The TokenAllowanceParams to fill with the JSON object. 43 | */ 44 | static void from_json(const json& jsonFrom, Hiero::TCK::AccountService::TokenAllowanceParams& params) 45 | { 46 | params.mTokenId = Hiero::TCK::getRequiredJsonParameter(jsonFrom, "tokenId"); 47 | params.mAmount = Hiero::TCK::getRequiredJsonParameter(jsonFrom, "amount"); 48 | } 49 | }; 50 | 51 | } // namespace nlohmann 52 | 53 | #endif // HIERO_TCK_CPP_ALLOWANCE_PARAMS_H_ 54 | -------------------------------------------------------------------------------- /src/sdk/examples/GeneratePrivateKeyFromSpecificMnemonicExample.cpp: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | #include "MnemonicBIP39.h" 3 | #include "PrivateKey.h" 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | using namespace Hiero; 10 | 11 | int main(int argc, char** argv) 12 | { 13 | dotenv::init(); 14 | 15 | const std::vector& words = { "soccer", "loan", "bomb", "yard", "accuse", "doctor", 16 | "man", "mean", "lawn", "wing", "swift", "bread" }; 17 | 18 | // Generate and print a 12-word BIP39 mnemonic 19 | MnemonicBIP39 mnemonicBip39 = MnemonicBIP39::initializeBIP39Mnemonic(words); 20 | std::cout << "12-word MnemonicBIP39 used for generation: " << std::endl; 21 | for (const std::string& word : words) 22 | { 23 | std::cout << word << " "; 24 | } 25 | std::cout << std::endl; 26 | 27 | // Generate and print a ED25519PrivateKey and ECDSAsecp256k1PrivateKey from the mnemonic with no passphrase 28 | std::unique_ptr ed25519PrivateKey = mnemonicBip39.toStandardEd25519PrivateKey(); 29 | 30 | // Sample string of a key generated with the same mnemonic 31 | std::string_view javaOutputDerKey = 32 | "302E020100300506032B657004220420BA36ED3F60E3DA30B5DB6215461FAFFC2FCD066F385FD2261F74AB4E174E4591"; 33 | 34 | // See if keys generated by mnemonic are the same with a generation of another SDK 35 | std::cout << "[C++] Generated ED25519PrivateKey from mnemonic: " << ed25519PrivateKey->toStringDer() << std::endl; 36 | std::cout << "[Java] Generated ED25519PrivateKey from mnemonic: " << javaOutputDerKey << std::endl; 37 | 38 | return 0; 39 | } 40 | -------------------------------------------------------------------------------- /src/tck/include/sdk/SdkClient.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | #ifndef HIERO_TCK_CPP_SDK_CLIENT_H_ 3 | #define HIERO_TCK_CPP_SDK_CLIENT_H_ 4 | 5 | #include 6 | 7 | #include 8 | #include 9 | 10 | namespace Hiero::TCK::SdkClient 11 | { 12 | /** 13 | * Forward declarations. 14 | */ 15 | struct ResetParams; 16 | struct SetupParams; 17 | 18 | /** 19 | * The default amount of time the SdkClient should wait for a gRPC request. 20 | */ 21 | constexpr static std::chrono::seconds DEFAULT_TCK_REQUEST_TIMEOUT = std::chrono::seconds(30); 22 | 23 | /** 24 | * Reset the SDK client. 25 | * 26 | * @return The JSON response. 27 | */ 28 | nlohmann::json reset(const ResetParams& params); 29 | 30 | /** 31 | * Setup the SDK client. 32 | * 33 | * @param operatorAccountId The ID of the operator account to use. 34 | * @param operatorPrivateKey The private key of the operator to use. 35 | * @param nodeIp The IP of the node with which the Client should communicate. 36 | * @param nodeAccountId The ID of the node account running the node with which this Client should communicate. 37 | * @param mirrorNetworkIp The IP of the mirror node with which the Client should communicate. 38 | * @return The JSON response. 39 | */ 40 | nlohmann::json setup(const SetupParams& params); 41 | 42 | /** 43 | * Get the Hiero C++ SDK client this SdkClient is using to execute requests. 44 | * 45 | * @return Reference to the Hiero C++ SDK client this SdkClient is using to execute requests. 46 | */ 47 | [[nodiscard]] const Client& getClient(); 48 | 49 | } // namespace Hiero::TCK::SdkClient 50 | 51 | #endif // HIERO_TCK_CPP_SDK_CLIENT_H_ 52 | -------------------------------------------------------------------------------- /src/sdk/tests/unit/PrngTransactionUnitTests.cc: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | #include "PrngTransaction.h" 3 | #include "exceptions/IllegalStateException.h" 4 | 5 | #include 6 | #include 7 | 8 | using namespace Hiero; 9 | 10 | class PrngTransactionUnitTests : public ::testing::Test 11 | { 12 | protected: 13 | [[nodiscard]] inline int getTestRange() const { return mTestRange; } 14 | 15 | private: 16 | const int mTestRange = 1; 17 | }; 18 | 19 | //----- 20 | TEST_F(PrngTransactionUnitTests, ConstructPrngTransactionFromTransactionBodyProtobuf) 21 | { 22 | // Given 23 | auto body = std::make_unique(); 24 | body->set_range(getTestRange()); 25 | 26 | proto::TransactionBody txBody; 27 | txBody.set_allocated_util_prng(body.release()); 28 | 29 | // When 30 | const PrngTransaction prngTransaction(txBody); 31 | 32 | // Then 33 | EXPECT_EQ(prngTransaction.getRange(), getTestRange()); 34 | } 35 | 36 | //----- 37 | TEST_F(PrngTransactionUnitTests, GetSetRange) 38 | { 39 | // Given 40 | PrngTransaction transaction; 41 | 42 | // When 43 | EXPECT_NO_THROW(transaction.setRange(getTestRange())); 44 | 45 | // Then 46 | EXPECT_EQ(transaction.getRange(), getTestRange()); 47 | } 48 | 49 | //----- 50 | TEST_F(PrngTransactionUnitTests, GetSetRangeFrozen) 51 | { 52 | // Given 53 | PrngTransaction transaction = 54 | PrngTransaction().setNodeAccountIds({ AccountId(1ULL) }).setTransactionId(TransactionId::generate(AccountId(1ULL))); 55 | ASSERT_NO_THROW(transaction.freeze()); 56 | 57 | // When / Then 58 | EXPECT_THROW(transaction.setRange(getTestRange()), IllegalStateException); 59 | } 60 | -------------------------------------------------------------------------------- /src/sdk/tests/integration/TransactionRecordQueryIntegrationTests.cc: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | #include "AccountCreateTransaction.h" 3 | #include "AccountDeleteTransaction.h" 4 | #include "BaseIntegrationTest.h" 5 | #include "Client.h" 6 | #include "ED25519PrivateKey.h" 7 | #include "TransactionId.h" 8 | #include "TransactionRecord.h" 9 | #include "TransactionRecordQuery.h" 10 | #include "TransactionResponse.h" 11 | #include "impl/Utilities.h" 12 | 13 | #include 14 | 15 | using namespace Hiero; 16 | 17 | class TransactionRecordQueryIntegrationTests : public BaseIntegrationTest 18 | { 19 | }; 20 | 21 | //----- 22 | TEST_F(TransactionRecordQueryIntegrationTests, CanGetTransactionRecord) 23 | { 24 | // Given 25 | const std::shared_ptr testPrivateKey = ED25519PrivateKey::generatePrivateKey(); 26 | const std::shared_ptr testPublicKey = testPrivateKey->getPublicKey(); 27 | 28 | TransactionResponse testTxResponse; 29 | ASSERT_NO_THROW(testTxResponse = 30 | AccountCreateTransaction().setKeyWithoutAlias(testPublicKey).execute(getTestClient())); 31 | 32 | // When / Then 33 | TransactionRecord txRecord; 34 | EXPECT_NO_THROW(txRecord = 35 | TransactionRecordQuery().setTransactionId(testTxResponse.mTransactionId).execute(getTestClient())); 36 | 37 | // Clean up 38 | ASSERT_NO_THROW(AccountDeleteTransaction() 39 | .setDeleteAccountId(txRecord.mReceipt->mAccountId.value()) 40 | .setTransferAccountId(AccountId(2ULL)) 41 | .freezeWith(&getTestClient()) 42 | .sign(testPrivateKey) 43 | .execute(getTestClient())); 44 | } -------------------------------------------------------------------------------- /src/sdk/examples/GenerateKeyExample.cpp: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | #include "ECDSAsecp256k1PrivateKey.h" 3 | #include "ED25519PrivateKey.h" 4 | #include "PrivateKey.h" 5 | #include "PublicKey.h" 6 | 7 | #include 8 | 9 | using namespace Hiero; 10 | 11 | int main(int argc, char** argv) 12 | { 13 | // Generate an ED25519 private 14 | const std::unique_ptr ed25519Key = ED25519PrivateKey::generatePrivateKey(); 15 | 16 | // Generate an ECDSA private 17 | const std::unique_ptr ecdsaKey = ECDSAsecp256k1PrivateKey::generatePrivateKey(); 18 | 19 | // Print the ED25519 private key and public key in RAW and DER encoded formats 20 | std::cout << "Generated ED25519PrivateKey Raw: " << ed25519Key->toStringRaw() << std::endl; 21 | std::cout << "Generated ED25519PrivateKey DER encoded: " << ed25519Key->toStringDer() << std::endl; 22 | std::cout << "Generated ED25519PublicKey Raw: " << ed25519Key->getPublicKey()->toStringRaw() << std::endl; 23 | std::cout << "Generated ED25519PublicKey DER encoded: " << ed25519Key->getPublicKey()->toStringDer() << std::endl; 24 | std::cout << "\n"; 25 | 26 | // Print the ECDSA private key and public key in RAW and DER encoded formats 27 | std::cout << "Generated ECDSAsecp256k1PrivateKey Raw: " << ecdsaKey->toStringRaw() << std::endl; 28 | std::cout << "Generated ECDSAsecp256k1PrivateKey DER encoded: " << ecdsaKey->toStringDer() << std::endl; 29 | std::cout << "Generated ECDSAsecp256k1PublicKey Raw: " << ecdsaKey->getPublicKey()->toStringRaw() << std::endl; 30 | std::cout << "Generated ECDSAsecp256k1PublicKey DER encoded: " << ecdsaKey->getPublicKey()->toStringDer() 31 | << std::endl; 32 | 33 | return 0; 34 | } 35 | -------------------------------------------------------------------------------- /src/sdk/main/include/CustomFeeBase.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | #ifndef HIERO_SDK_CPP_CUSTOM_FEE_BASE_H_ 3 | #define HIERO_SDK_CPP_CUSTOM_FEE_BASE_H_ 4 | 5 | #include "AccountId.h" 6 | #include "CustomFee.h" 7 | 8 | namespace Hiero 9 | { 10 | /** 11 | * Helper class to sit between CustomFee and its derived implementations. This is done so that CustomFee isn't required 12 | * to be a templated type. 13 | */ 14 | template 15 | class CustomFeeBase : public CustomFee 16 | { 17 | public: 18 | /** 19 | * Set the ID of the desired fee collector account. 20 | * 21 | * @param accountId The ID of the desired fee collector account. 22 | * @return A reference to this derived CustomFee object, with the newly-set fee collector account ID. 23 | */ 24 | FeeType& setFeeCollectorAccountId(const AccountId& accountId); 25 | 26 | /** 27 | * Set the fee collector exemption policy. 28 | * 29 | * @param exempt \c TRUE if fee collectors should be exempt from this CustomFee, otherwise \c FALSE. 30 | * @return A reference ot this derived CustomFee object, with the newly-set fee collector exemption policy. 31 | */ 32 | FeeType& setAllCollectorsAreExempt(bool exempt); 33 | 34 | protected: 35 | /** 36 | * Prevent public copying and moving to prevent slicing. Use the 'clone()' virtual method instead. 37 | */ 38 | CustomFeeBase() = default; 39 | CustomFeeBase(const CustomFeeBase&) = default; 40 | CustomFeeBase& operator=(const CustomFeeBase&) = default; 41 | CustomFeeBase(CustomFeeBase&&) noexcept = default; 42 | CustomFeeBase& operator=(CustomFeeBase&&) noexcept = default; 43 | }; 44 | 45 | } // namespace Hiero 46 | 47 | #endif // HIERO_SDK_CPP_CUSTOM_FEE_BASE_H_ 48 | -------------------------------------------------------------------------------- /src/sdk/main/src/TokenRejectFlow.cc: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | #include "TokenRejectFlow.h" 3 | #include "AccountId.h" 4 | #include "Client.h" 5 | #include "NftId.h" 6 | #include "TokenDissociateTransaction.h" 7 | #include "TokenId.h" 8 | #include "TokenRejectTransaction.h" 9 | #include "TransactionReceipt.h" 10 | #include "exceptions/UninitializedException.h" 11 | 12 | namespace Hiero 13 | { 14 | //----- 15 | TransactionResponse TokenRejectFlow::execute(const Client& client) 16 | { 17 | return execute(client, client.getRequestTimeout()); 18 | } 19 | 20 | //----- 21 | TransactionResponse TokenRejectFlow::execute(const Client& client, const std::chrono::system_clock::duration& timeout) 22 | { 23 | // Submit the TokenRejectTransaction. 24 | TransactionResponse txResponse = 25 | tokenRejectTransaction.freezeWith(&client).sign(mReceiverPrivateKey).execute(client, timeout); 26 | 27 | // Make sure the transaction reaches consensus. 28 | TransactionReceipt txReceipt = txResponse.getReceipt(client, timeout); 29 | 30 | // build dissociate vector from rejected nfts 31 | std::vector toDissociate; 32 | std::for_each(tokenRejectTransaction.getNfts().cbegin(), 33 | tokenRejectTransaction.getNfts().cend(), 34 | [&toDissociate](const NftId& nftId) { toDissociate.push_back(nftId.mTokenId); }); 35 | 36 | // Make sure the transaction reaches consensus. 37 | txReceipt = tokenDissociateTransaction.setTokenIds(toDissociate) 38 | .freezeWith(&client) 39 | .sign(mReceiverPrivateKey) 40 | .execute(client, timeout) 41 | .getReceipt(client, timeout); 42 | 43 | return txResponse; 44 | } 45 | 46 | } // namespace Hiero -------------------------------------------------------------------------------- /src/sdk/examples/GetAccountInfoExample.cpp: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | #include "AccountInfo.h" 3 | #include "AccountInfoQuery.h" 4 | #include "Client.h" 5 | #include "ECDSAsecp256k1PrivateKey.h" 6 | #include "PublicKey.h" 7 | 8 | #include 9 | #include 10 | 11 | using namespace Hiero; 12 | 13 | int main(int argc, char** argv) 14 | { 15 | dotenv::init(); 16 | const AccountId operatorAccountId = AccountId::fromString(std::getenv("OPERATOR_ID")); 17 | const std::shared_ptr operatorPrivateKey = 18 | ECDSAsecp256k1PrivateKey::fromString(std::getenv("OPERATOR_KEY")); 19 | 20 | // Get a client for the Hiero testnet, and set the operator account ID and key such that all generated transactions 21 | // will be paid for by this account and be signed by this key. 22 | Client client = Client::forTestnet(); 23 | client.setOperator(operatorAccountId, operatorPrivateKey); 24 | 25 | const AccountInfo accountInfo = 26 | AccountInfoQuery().setAccountId(client.getOperatorAccountId().value()).execute(client); 27 | 28 | std::cout << "Account key: " 29 | << std::dynamic_pointer_cast(accountInfo.mKey)->toStringRaw() << std::endl; 30 | std::cout << "Account receiver signature required: " << (accountInfo.mReceiverSignatureRequired ? "true" : "false") 31 | << std::endl; 32 | std::cout << "Account expiration time: " << accountInfo.mExpirationTime.time_since_epoch().count() 33 | << std::endl; 34 | 35 | std::cout << "Account token relationships: " << std::endl; 36 | for (auto tr : accountInfo.mTokenRelationships) 37 | { 38 | std::cout << tr.second.toString() << std::endl; 39 | } 40 | 41 | return 0; 42 | } 43 | -------------------------------------------------------------------------------- /src/sdk/main/src/ProxyStaker.cc: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | #include "ProxyStaker.h" 3 | #include "impl/Utilities.h" 4 | 5 | #include 6 | 7 | #include 8 | 9 | namespace Hiero 10 | { 11 | //----- 12 | ProxyStaker::ProxyStaker(AccountId accountId, int64_t amount) 13 | : mAccountId(std::move(accountId)) 14 | , mAmount(Hbar(amount, HbarUnit::TINYBAR())) 15 | { 16 | } 17 | 18 | //----- 19 | ProxyStaker ProxyStaker::fromProtobuf(const proto::ProxyStaker& proto) 20 | { 21 | return { AccountId::fromProtobuf(proto.accountid()), proto.amount() }; 22 | } 23 | 24 | //----- 25 | ProxyStaker ProxyStaker::fromBytes(const std::vector& bytes) 26 | { 27 | proto::ProxyStaker proto; 28 | proto.ParseFromArray(bytes.data(), static_cast(bytes.size())); 29 | return fromProtobuf(proto); 30 | } 31 | 32 | //----- 33 | std::unique_ptr ProxyStaker::toProtobuf() const 34 | { 35 | auto proto = std::make_unique(); 36 | proto->set_allocated_accountid(mAccountId.toProtobuf().release()); 37 | proto->set_amount(mAmount.toTinybars()); 38 | return proto; 39 | } 40 | 41 | //----- 42 | std::vector ProxyStaker::toBytes() const 43 | { 44 | return internal::Utilities::stringToByteVector(toProtobuf()->SerializeAsString()); 45 | } 46 | 47 | //----- 48 | std::string ProxyStaker::toString() const 49 | { 50 | nlohmann::json json; 51 | json["mAccountId"] = mAccountId.toString(); 52 | json["mAmount"] = mAmount.toString(); 53 | return json.dump(); 54 | } 55 | 56 | //----- 57 | std::ostream& operator<<(std::ostream& os, const ProxyStaker& staker) 58 | { 59 | os << staker.toString(); 60 | return os; 61 | } 62 | 63 | } // namespace Hiero 64 | -------------------------------------------------------------------------------- /src/sdk/main/src/LedgerId.cc: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | #include "LedgerId.h" 3 | #include "exceptions/OpenSSLException.h" 4 | #include "impl/HexConverter.h" 5 | 6 | #include 7 | 8 | namespace Hiero 9 | { 10 | //----- 11 | const LedgerId LedgerId::MAINNET = LedgerId({ std::byte(0x00) }); 12 | 13 | //----- 14 | const LedgerId LedgerId::TESTNET = LedgerId({ std::byte(0x01) }); 15 | 16 | //----- 17 | const LedgerId LedgerId::PREVIEWNET = LedgerId({ std::byte(0x02) }); 18 | 19 | //----- 20 | LedgerId::LedgerId(std::vector bytes) 21 | : mLedgerId(std::move(bytes)) 22 | { 23 | } 24 | 25 | //----- 26 | bool LedgerId::operator==(const LedgerId& other) const 27 | { 28 | return mLedgerId == other.mLedgerId; 29 | } 30 | 31 | //----- 32 | LedgerId LedgerId::fromString(std::string_view id) 33 | { 34 | if (id == "mainnet") 35 | { 36 | return MAINNET; 37 | } 38 | else if (id == "testnet") 39 | { 40 | return TESTNET; 41 | } 42 | else if (id == "previewnet") 43 | { 44 | return PREVIEWNET; 45 | } 46 | else 47 | { 48 | try 49 | { 50 | return LedgerId(internal::HexConverter::hexToBytes(id)); 51 | } 52 | catch (const OpenSSLException&) 53 | { 54 | throw std::invalid_argument("LedgerId cannot be realized from input hex-encoded string"); 55 | } 56 | } 57 | } 58 | 59 | //----- 60 | std::string LedgerId::toString() const 61 | { 62 | if (isMainnet()) 63 | { 64 | return "mainnet"; 65 | } 66 | else if (isTestnet()) 67 | { 68 | return "testnet"; 69 | } 70 | else if (isPreviewnet()) 71 | { 72 | return "previewnet"; 73 | } 74 | else 75 | { 76 | return internal::HexConverter::bytesToHex(mLedgerId); 77 | } 78 | } 79 | 80 | } // namespace Hiero 81 | -------------------------------------------------------------------------------- /src/sdk/main/include/EthereumTransactionData.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | #ifndef HIERO_SDK_CPP_ETHEREUM_TRANSACTION_DATA_H_ 3 | #define HIERO_SDK_CPP_ETHEREUM_TRANSACTION_DATA_H_ 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | namespace Hiero 11 | { 12 | /** 13 | * Wrapper class for Ethereum data. 14 | */ 15 | class EthereumTransactionData 16 | { 17 | public: 18 | EthereumTransactionData() = default; 19 | virtual ~EthereumTransactionData() = default; 20 | 21 | /** 22 | * Construct with call data. 23 | * 24 | * @param callData The call data. 25 | */ 26 | explicit EthereumTransactionData(std::vector callData); 27 | 28 | /** 29 | * Construct an EthereumTransactionData object from raw bytes. 30 | * 31 | * @param bytes The raw bytes of the ethereum data. 32 | * @return A pointer to the constructed EthereumTransactionData. 33 | */ 34 | [[nodiscard]] static std::unique_ptr fromBytes(const std::vector& bytes); 35 | 36 | /** 37 | * Serialize this EthereumTransactionData object into RLP-encoded bytes. 38 | * 39 | * @return The RLP-encoded serialized EthereumTransactionData. 40 | */ 41 | [[nodiscard]] virtual std::vector toBytes() const = 0; 42 | 43 | /** 44 | * Serialize this EthereumTransactionData object into a hex-encoded, RLP-encoded string. 45 | * 46 | * @return The hex-encoded, RLP-encoded EthereumTransactionData. 47 | */ 48 | [[nodiscard]] virtual std::string toString() const = 0; 49 | 50 | /** 51 | * The call data. 52 | */ 53 | std::vector mCallData; 54 | }; 55 | 56 | } // namespace Hiero 57 | 58 | #endif // HIERO_SDK_CPP_ETHEREUM_TRANSACTION_DATA_H_ 59 | -------------------------------------------------------------------------------- /src/sdk/main/include/impl/ASN1ED25519PublicKey.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | #ifndef HIERO_SDK_CPP_IMPL_ASN1_ED25519_PUBLIC_KEY_H_ 3 | #define HIERO_SDK_CPP_IMPL_ASN1_ED25519_PUBLIC_KEY_H_ 4 | 5 | #include "ASN1ECKey.h" 6 | 7 | namespace Hiero::internal::asn1 8 | { 9 | /** 10 | * The prefix bytes of a DER-encoded ED25519PublicKey. 11 | */ 12 | static inline const std::vector ASN1_EDPBK_PREFIX_BYTES = { 13 | std::byte(0x30), std::byte(0x2A), std::byte(0x30), std::byte(0x05), std::byte(0x06), std::byte(0x03), 14 | std::byte(0x2B), std::byte(0x65), std::byte(0x70), std::byte(0x03), std::byte(0x21), std::byte(0x00) 15 | }; 16 | 17 | // PEM Format prefix/suffix string 18 | constexpr std::string_view PEM_ECPBK_PREFIX_STRING = "-----BEGIN PUBLIC KEY-----"; 19 | constexpr std::string_view PEM_ECPBK_SUFFIX_STRING = "-----END PUBLIC KEY-----"; 20 | 21 | /** 22 | * @class ASN1ED25519PublicKey 23 | * @brief ASN.1 elliptic curve public key object. 24 | */ 25 | class ASN1ED25519PublicKey : public ASN1ECKey 26 | { 27 | public: 28 | /** 29 | * @brief Constructor for ASN.1 elliptic curve public key from a vector of bytes. 30 | * @param bytes The vector of bytes containing the ASN.1 key data. 31 | */ 32 | ASN1ED25519PublicKey(const std::vector& bytes); 33 | 34 | /** 35 | * @brief Get the key value associated with the ASN.1 elliptic curve public key. 36 | * @return The key as a vector of bytes. 37 | */ 38 | std::vector getKey() const override; 39 | 40 | private: 41 | /** 42 | * @brief Constructor for ASN.1 elliptic curve public key. 43 | */ 44 | ASN1ED25519PublicKey() = default; 45 | }; 46 | 47 | } // namespace Hiero::internal:asn1 48 | 49 | #endif // HIERO_SDK_CPP_IMPL_ASN1_ED25519_PUBLIC_KEY_H_ 50 | -------------------------------------------------------------------------------- /src/sdk/examples/CreateTopicExample.cpp: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | #include "Client.h" 3 | #include "ECDSAsecp256k1PrivateKey.h" 4 | #include "Status.h" 5 | #include "TopicCreateTransaction.h" 6 | #include "TopicId.h" 7 | #include "TopicMessageSubmitTransaction.h" 8 | #include "TransactionReceipt.h" 9 | #include "TransactionResponse.h" 10 | 11 | #include 12 | #include 13 | 14 | using namespace Hiero; 15 | 16 | int main(int argc, char** argv) 17 | { 18 | dotenv::init(); 19 | const AccountId operatorAccountId = AccountId::fromString(std::getenv("OPERATOR_ID")); 20 | const std::shared_ptr operatorPrivateKey = 21 | ECDSAsecp256k1PrivateKey::fromString(std::getenv("OPERATOR_KEY")); 22 | 23 | // Get a client for the Hiero testnet, and set the operator account ID and key such that all generated transactions 24 | // will be paid for by this account and be signed by this key. 25 | Client client = Client::forTestnet(); 26 | client.setOperator(operatorAccountId, operatorPrivateKey); 27 | 28 | // Create a new topic. 29 | const TopicId topicId = TopicCreateTransaction().execute(client).getReceipt(client).mTopicId.value(); 30 | std::cout << "Created new topic with ID " << topicId.toString() << std::endl; 31 | 32 | // Submit a message on this topic. 33 | std::cout << "Submitting message: " 34 | << gStatusToString.at(TopicMessageSubmitTransaction() 35 | .setTopicId(topicId) 36 | .setMessage("Hello world!") 37 | .execute(client) 38 | .getReceipt(client) 39 | .mStatus) 40 | << std::endl; 41 | 42 | return 0; 43 | } 44 | -------------------------------------------------------------------------------- /src/sdk/main/include/impl/ASN1ED25519PrivateKey.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | #ifndef HIERO_SDK_CPP_IMPL_ASN1_ED25519_PRIVATE_KEY_H_ 3 | #define HIERO_SDK_CPP_IMPL_ASN1_ED25519_PRIVATE_KEY_H_ 4 | 5 | #include "ASN1ECKey.h" 6 | 7 | namespace Hiero::internal::asn1 8 | { 9 | // The ASN.1 algorithm identifier prefix bytes for an EC ED25519PrivateKey 10 | const std::vector ASN1_EDPRK_PREFIX_BYTES = { 11 | std::byte(0x30), std::byte(0x2E), std::byte(0x02), std::byte(0x01), std::byte(0x00), std::byte(0x30), 12 | std::byte(0x05), std::byte(0x06), std::byte(0x03), std::byte(0x2B), std::byte(0x65), std::byte(0x70), 13 | std::byte(0x04), std::byte(0x22), std::byte(0x04), std::byte(0x20) 14 | }; 15 | 16 | // PEM Format prefix/suffix string EC ED25519 Key 17 | constexpr std::string_view PEM_EDPRK_PREFIX_STRING = "-----BEGIN PRIVATE KEY-----"; 18 | constexpr std::string_view PEM_EDPRK_SUFFIX_STRING = "-----END PRIVATE KEY-----"; 19 | 20 | /** 21 | * @class ASN1Key 22 | * @brief ASN.1 key object. 23 | */ 24 | class ASN1ED25519PrivateKey : public ASN1ECKey 25 | { 26 | public: 27 | /** 28 | * @brief Constructor for ASN.1 key from a vector of bytes. 29 | * 30 | * @param bytes The vector of bytes containing the ASN.1 key data. 31 | */ 32 | ASN1ED25519PrivateKey(const std::vector& bytes); 33 | 34 | /** 35 | * @brief Get the key value associated with the ASN.1 key. 36 | * 37 | * @return The key as a vector of bytes. 38 | */ 39 | std::vector getKey() const override; 40 | 41 | private: 42 | /** 43 | * @brief Constructor for ASN.1 key. 44 | */ 45 | ASN1ED25519PrivateKey() = default; 46 | }; 47 | 48 | } // namespace Hiero::internal:asn1 49 | 50 | #endif // HIERO_SDK_CPP_IMPL_ASN1_ED25519_PRIVATE_KEY_H_ 51 | -------------------------------------------------------------------------------- /src/sdk/main/include/FeeAssessmentMethod.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | #ifndef HIERO_SDK_CPP_FEE_ASSESSMENT_METHOD_H_ 3 | #define HIERO_SDK_CPP_FEE_ASSESSMENT_METHOD_H_ 4 | 5 | #include 6 | #include 7 | 8 | namespace Hiero 9 | { 10 | /** 11 | * An enumeration the describes how a fee should be assessed. 12 | */ 13 | enum class FeeAssessmentMethod 14 | { 15 | /** 16 | * If Alice is paying Bob and an INCLUSIVE fractional fee is collected to be sent to Charlie, the amount Alice 17 | * declares she will pay in the transfer transaction includes the fee amount. In other words, Bob receives the amount 18 | * that Alice intended to send minus the fee. 19 | */ 20 | INCLUSIVE, 21 | /** 22 | * If Alice is paying Bob, and an EXCLUSIVE fractional fee is collected to be sent to Charlie, the amount Alice 23 | * declares she will pay in the transfer transaction does not include the fee amount. In other words, Alice is charged 24 | * the fee in addition to the amount she intended to send to Bob. 25 | */ 26 | EXCLUSIVE 27 | }; 28 | 29 | /** 30 | * Map of FeeAssessmentMethod to its corresponding string. 31 | */ 32 | const std::unordered_map gFeeAssessmentMethodToString = { 33 | {FeeAssessmentMethod::INCLUSIVE, "INCLUSIVE"}, 34 | { FeeAssessmentMethod::EXCLUSIVE, "EXCLUSIVE"} 35 | }; 36 | 37 | /** 38 | * Map of FeeAssessmentMethod string representation to its corresponding enum value. 39 | */ 40 | [[maybe_unused]] const std::unordered_map gStringToFeeAssessmentMethod = { 41 | {"INCLUSIVE", FeeAssessmentMethod::INCLUSIVE}, 42 | { "EXCLUSIVE", FeeAssessmentMethod::EXCLUSIVE} 43 | }; 44 | 45 | } // namespace Hiero 46 | 47 | #endif // HIERO_SDK_CPP_FEE_ASSESSMENT_METHOD_H_ 48 | -------------------------------------------------------------------------------- /src/sdk/main/include/exceptions/ReceiptStatusException.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | #ifndef HIERO_SDK_CPP_RECEIPT_STATUS_EXCEPTION_H_ 3 | #define HIERO_SDK_CPP_RECEIPT_STATUS_EXCEPTION_H_ 4 | 5 | #include "Status.h" 6 | #include "TransactionId.h" 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | namespace Hiero 13 | { 14 | /** 15 | * Exception that is thrown when a TransactionReceipt contains a non-successful status (i.e. not Status::SUCCESS) and it 16 | * is configured to do so. 17 | */ 18 | class ReceiptStatusException : public std::exception 19 | { 20 | public: 21 | /** 22 | * Construct with the ID of the transaction that failed and its status. 23 | * 24 | * @param transactionId The ID of the transaction that failed. 25 | * @param status The status of the transaction. 26 | */ 27 | explicit ReceiptStatusException(const TransactionId& transactionId, Status status) 28 | : mTransactionId(transactionId) 29 | , mStatus(status) 30 | , mError("receipt for transaction " + mTransactionId.toString() + " raised status " + gStatusToString.at(mStatus)) 31 | { 32 | } 33 | 34 | /** 35 | * Get the descriptor message for this error. 36 | * 37 | * @return The descriptor message for this error. 38 | */ 39 | [[nodiscard]] const char* what() const noexcept override { return mError.c_str(); }; 40 | 41 | /** 42 | * The ID of the transaction that failed. 43 | */ 44 | TransactionId mTransactionId; 45 | 46 | /** 47 | * The status of the failed transaction. 48 | */ 49 | Status mStatus = Status::OK; 50 | 51 | /** 52 | * Descriptive error message. 53 | */ 54 | std::string mError; 55 | }; 56 | 57 | } // namespace Hiero 58 | 59 | #endif // HIERO_SDK_CPP_RECEIPT_STATUS_EXCEPTION_H_ 60 | -------------------------------------------------------------------------------- /src/tck/include/token/params/PauseTokenParams.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | #ifndef HIERO_TCK_CPP_PAUSE_TOKEN_PARAMS_H_ 3 | #define HIERO_TCK_CPP_PAUSE_TOKEN_PARAMS_H_ 4 | 5 | #include "common/CommonTransactionParams.h" 6 | #include "json/JsonUtils.h" 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | namespace Hiero::TCK::TokenService 13 | { 14 | /** 15 | * Struct to hold the arguments for a `pauseToken` JSON-RPC method call. 16 | */ 17 | struct PauseTokenParams 18 | { 19 | /** 20 | * The ID of the token to pause. 21 | */ 22 | std::optional mTokenId; 23 | 24 | /** 25 | * Any parameters common to all transaction types. 26 | */ 27 | std::optional mCommonTxParams; 28 | }; 29 | 30 | } // namespace Hiero::TCK::TokenService 31 | 32 | namespace nlohmann 33 | { 34 | /** 35 | * JSON serializer template specialization required to convert PauseTokenParams arguments properly. 36 | */ 37 | template<> 38 | struct [[maybe_unused]] adl_serializer 39 | { 40 | /** 41 | * Convert a JSON object to a PauseTokenParams. 42 | * 43 | * @param jsonFrom The JSON object with which to fill the PauseTokenParams. 44 | * @param params The PauseTokenParams to fill with the JSON object. 45 | */ 46 | static void from_json(const json& jsonFrom, Hiero::TCK::TokenService::PauseTokenParams& params) 47 | { 48 | params.mTokenId = Hiero::TCK::getOptionalJsonParameter(jsonFrom, "tokenId"); 49 | params.mCommonTxParams = 50 | Hiero::TCK::getOptionalJsonParameter(jsonFrom, "commonTransactionParams"); 51 | } 52 | }; 53 | 54 | } // namespace nlohmann 55 | 56 | #endif // HIERO_TCK_CPP_PAUSE_TOKEN_PARAMS_H_ 57 | -------------------------------------------------------------------------------- /src/tck/src/sdk/SdkClient.cc: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | #include 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | #include "sdk/SdkClient.h" 11 | #include "sdk/params/ResetParams.h" 12 | #include "sdk/params/SetupParams.h" 13 | 14 | namespace Hiero::TCK::SdkClient 15 | { 16 | namespace 17 | { 18 | // The Hiero C++ SDK Client the SdkClient will use to communicate with the network. 19 | Client mClient; 20 | } 21 | 22 | //----- 23 | nlohmann::json reset(const ResetParams&) 24 | { 25 | mClient.close(); 26 | return { 27 | {"status", "SUCCESS"} 28 | }; 29 | } 30 | 31 | //----- 32 | nlohmann::json setup(const SetupParams& params) 33 | { 34 | std::string clientType; 35 | 36 | if (params.nodeIp.has_value() && params.nodeAccountId.has_value() && params.mirrorNetworkIp.has_value()) 37 | { 38 | mClient = Client::forNetwork({ 39 | {params.nodeIp.value(), AccountId::fromString(params.nodeAccountId.value())} 40 | }); 41 | mClient.setMirrorNetwork({ params.mirrorNetworkIp.value() }); 42 | clientType = "custom"; 43 | } 44 | else 45 | { 46 | mClient = Client::forTestnet(); 47 | clientType = "testnet"; 48 | } 49 | 50 | mClient.setOperator(AccountId::fromString(params.operatorAccountId), 51 | PrivateKey::fromStringDer(params.operatorPrivateKey)); 52 | mClient.setRequestTimeout(DEFAULT_TCK_REQUEST_TIMEOUT); 53 | 54 | return { 55 | {"message", "Successfully setup " + clientType + " client."}, 56 | { "status", "SUCCESS" } 57 | }; 58 | } 59 | 60 | //----- 61 | const Client& getClient() 62 | { 63 | return mClient; 64 | } 65 | 66 | } // namespace Hiero::TCK::SdkClient 67 | -------------------------------------------------------------------------------- /src/tck/include/token/params/DeleteTokenParams.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | #ifndef HIERO_TCK_CPP_DELETE_TOKEN_PARAMS_H_ 3 | #define HIERO_TCK_CPP_DELETE_TOKEN_PARAMS_H_ 4 | 5 | #include "common/CommonTransactionParams.h" 6 | #include "json/JsonUtils.h" 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | namespace Hiero::TCK::TokenService 13 | { 14 | /** 15 | * Struct to hold the arguments for a `deleteToken` JSON-RPC method call. 16 | */ 17 | struct DeleteTokenParams 18 | { 19 | /** 20 | * The ID of the token to delete. 21 | */ 22 | std::optional mTokenId; 23 | 24 | /** 25 | * Any parameters common to all transaction types. 26 | */ 27 | std::optional mCommonTxParams; 28 | }; 29 | 30 | } // namespace Hiero::TCK::TokenService 31 | 32 | namespace nlohmann 33 | { 34 | /** 35 | * JSON serializer template specialization required to convert DeleteTokenParams arguments properly. 36 | */ 37 | template<> 38 | struct [[maybe_unused]] adl_serializer 39 | { 40 | /** 41 | * Convert a JSON object to a DeleteTokenParams. 42 | * 43 | * @param jsonFrom The JSON object with which to fill the DeleteTokenParams. 44 | * @param params The DeleteTokenParams to fill with the JSON object. 45 | */ 46 | static void from_json(const json& jsonFrom, Hiero::TCK::TokenService::DeleteTokenParams& params) 47 | { 48 | params.mTokenId = Hiero::TCK::getOptionalJsonParameter(jsonFrom, "tokenId"); 49 | params.mCommonTxParams = 50 | Hiero::TCK::getOptionalJsonParameter(jsonFrom, "commonTransactionParams"); 51 | } 52 | }; 53 | 54 | } // namespace nlohmann 55 | 56 | #endif // HIERO_TCK_CPP_DELETE_TOKEN_PARAMS_H_ 57 | -------------------------------------------------------------------------------- /src/tck/include/token/params/UnpauseTokenParams.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | #ifndef HIERO_TCK_CPP_UNPAUSE_TOKEN_PARAMS_H_ 3 | #define HIERO_TCK_CPP_UNPAUSE_TOKEN_PARAMS_H_ 4 | 5 | #include "common/CommonTransactionParams.h" 6 | #include "json/JsonUtils.h" 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | namespace Hiero::TCK::TokenService 13 | { 14 | /** 15 | * Struct to hold the arguments for a `unpauseToken` JSON-RPC method call. 16 | */ 17 | struct UnpauseTokenParams 18 | { 19 | /** 20 | * The ID of the token to unpause. 21 | */ 22 | std::optional mTokenId; 23 | 24 | /** 25 | * Any parameters common to all transaction types. 26 | */ 27 | std::optional mCommonTxParams; 28 | }; 29 | 30 | } // namespace Hiero::TCK::TokenService 31 | 32 | namespace nlohmann 33 | { 34 | /** 35 | * JSON serializer template specialization required to convert UnpauseTokenParams arguments properly. 36 | */ 37 | template<> 38 | struct [[maybe_unused]] adl_serializer 39 | { 40 | /** 41 | * Convert a JSON object to a UnpauseTokenParams. 42 | * 43 | * @param jsonFrom The JSON object with which to fill the UnpauseTokenParams. 44 | * @param params The PauseTokenParams to fill with the JSON object. 45 | */ 46 | static void from_json(const json& jsonFrom, Hiero::TCK::TokenService::UnpauseTokenParams& params) 47 | { 48 | params.mTokenId = Hiero::TCK::getOptionalJsonParameter(jsonFrom, "tokenId"); 49 | params.mCommonTxParams = 50 | Hiero::TCK::getOptionalJsonParameter(jsonFrom, "commonTransactionParams"); 51 | } 52 | }; 53 | 54 | } // namespace nlohmann 55 | 56 | #endif // HIERO_TCK_CPP_UNPAUSE_TOKEN_PARAMS_H_ -------------------------------------------------------------------------------- /src/sdk/main/src/ExchangeRates.cc: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | #include "ExchangeRates.h" 3 | #include "impl/Utilities.h" 4 | 5 | #include 6 | 7 | #include 8 | 9 | namespace Hiero 10 | { 11 | //----- 12 | ExchangeRates::ExchangeRates(const ExchangeRate& current, const ExchangeRate& next) 13 | : mCurrentRate(current) 14 | , mNextRate(next) 15 | { 16 | } 17 | 18 | //----- 19 | ExchangeRates ExchangeRates::fromProtobuf(const proto::ExchangeRateSet& proto) 20 | { 21 | return { ExchangeRate::fromProtobuf(proto.currentrate()), ExchangeRate::fromProtobuf(proto.nextrate()) }; 22 | } 23 | 24 | //----- 25 | ExchangeRates ExchangeRates::fromBytes(const std::vector& bytes) 26 | { 27 | proto::ExchangeRateSet proto; 28 | proto.ParseFromArray(bytes.data(), static_cast(bytes.size())); 29 | return fromProtobuf(proto); 30 | } 31 | 32 | //----- 33 | std::unique_ptr ExchangeRates::toProtobuf() const 34 | { 35 | auto proto = std::make_unique(); 36 | proto->set_allocated_currentrate(mCurrentRate.toProtobuf().release()); 37 | proto->set_allocated_nextrate(mNextRate.toProtobuf().release()); 38 | return proto; 39 | } 40 | 41 | //----- 42 | std::vector ExchangeRates::toBytes() const 43 | { 44 | return internal::Utilities::stringToByteVector(toProtobuf()->SerializeAsString()); 45 | } 46 | 47 | //----- 48 | std::string ExchangeRates::toString() const 49 | { 50 | nlohmann::json json; 51 | json["mCurrentRate"] = mCurrentRate.toString(); 52 | json["mNextRate"] = mNextRate.toString(); 53 | return json.dump(); 54 | } 55 | 56 | //----- 57 | std::ostream& operator<<(std::ostream& os, const ExchangeRates& rates) 58 | { 59 | os << rates.toString(); 60 | return os; 61 | } 62 | 63 | } // namespace Hiero 64 | -------------------------------------------------------------------------------- /src/sdk/main/src/TokenAssociation.cc: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | #include "TokenAssociation.h" 3 | #include "impl/Utilities.h" 4 | 5 | #include 6 | 7 | #include 8 | 9 | namespace Hiero 10 | { 11 | //----- 12 | TokenAssociation TokenAssociation::fromProtobuf(const proto::TokenAssociation& proto) 13 | { 14 | TokenAssociation tokenAssociation; 15 | 16 | if (proto.has_account_id()) 17 | { 18 | tokenAssociation.mAccountId = AccountId::fromProtobuf(proto.account_id()); 19 | } 20 | 21 | if (proto.has_token_id()) 22 | { 23 | tokenAssociation.mTokenId = TokenId::fromProtobuf(proto.token_id()); 24 | } 25 | 26 | return tokenAssociation; 27 | } 28 | 29 | //----- 30 | TokenAssociation TokenAssociation::fromBytes(const std::vector& bytes) 31 | { 32 | proto::TokenAssociation tokenAssociation; 33 | tokenAssociation.ParseFromArray(bytes.data(), static_cast(bytes.size())); 34 | return fromProtobuf(tokenAssociation); 35 | } 36 | 37 | //----- 38 | std::unique_ptr TokenAssociation::toProtobuf() const 39 | { 40 | auto tokenAssociation = std::make_unique(); 41 | tokenAssociation->set_allocated_account_id(mAccountId.toProtobuf().release()); 42 | tokenAssociation->set_allocated_token_id(mTokenId.toProtobuf().release()); 43 | return tokenAssociation; 44 | } 45 | 46 | //----- 47 | std::vector TokenAssociation::toBytes() const 48 | { 49 | return internal::Utilities::stringToByteVector(toProtobuf()->SerializeAsString()); 50 | } 51 | 52 | //----- 53 | std::string TokenAssociation::toString() const 54 | { 55 | nlohmann::json json; 56 | json["mAccountId"] = mAccountId.toString(); 57 | json["mTokenId"] = mTokenId.toString(); 58 | return json.dump(); 59 | } 60 | 61 | } // namespace Hiero -------------------------------------------------------------------------------- /src/sdk/examples/DeleteFileExample.cpp: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | #include "Client.h" 3 | #include "ECDSAsecp256k1PrivateKey.h" 4 | #include "FileCreateTransaction.h" 5 | #include "FileDeleteTransaction.h" 6 | #include "FileId.h" 7 | #include "Status.h" 8 | #include "TransactionReceipt.h" 9 | #include "TransactionResponse.h" 10 | #include "impl/Utilities.h" 11 | 12 | #include 13 | #include 14 | 15 | using namespace Hiero; 16 | 17 | int main(int argc, char** argv) 18 | { 19 | dotenv::init(); 20 | const AccountId operatorAccountId = AccountId::fromString(std::getenv("OPERATOR_ID")); 21 | const std::shared_ptr operatorPrivateKey = 22 | ECDSAsecp256k1PrivateKey::fromString(std::getenv("OPERATOR_KEY")); 23 | 24 | // Get a client for the Hiero testnet, and set the operator account ID and key such that all generated transactions 25 | // will be paid for by this account and be signed by this key. 26 | Client client = Client::forTestnet(); 27 | client.setOperator(operatorAccountId, operatorPrivateKey); 28 | 29 | // Create a new file. 30 | const FileId fileId = FileCreateTransaction() 31 | .setKeys({ client.getOperatorPublicKey() }) 32 | .setContents(internal::Utilities::stringToByteVector("Hiero is great!")) 33 | .execute(client) 34 | .getReceipt(client) 35 | .mFileId.value(); 36 | std::cout << "Created new file with ID " << fileId.toString() << std::endl; 37 | 38 | // Delete the newly-created file. 39 | const TransactionReceipt txReceipt = FileDeleteTransaction().setFileId(fileId).execute(client).getReceipt(client); 40 | std::cout << "Deleted file with response code: " << gStatusToString.at(txReceipt.mStatus) << std::endl; 41 | 42 | return 0; 43 | } 44 | -------------------------------------------------------------------------------- /src/sdk/main/include/impl/MirrorNodeRouter.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | #ifndef HIERO_SDK_CPP_MIRRORNODEROUTER_H 3 | #define HIERO_SDK_CPP_MIRRORNODEROUTER_H 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | /** 10 | * Namespace for the internal classes related to the Mirror Node Gateway. 11 | */ 12 | namespace Hiero::internal::MirrorNodeGateway 13 | { 14 | /** 15 | * Represents different mirror node query types. 16 | */ 17 | static const std::string& ACCOUNT_INFO_QUERY = "accountInfoQuery"; 18 | static const std::string& CONTRACT_INFO_QUERY = "contractInfoQuery"; 19 | static const std::string& TOKEN_RELATIONSHIPS_QUERY = "tokenRelationshipsQuery"; 20 | static const std::string& TOKEN_BALANCES_QUERY = "tokenBalancesQuery"; 21 | 22 | /** 23 | * Class responsible for routing requests to different mirror node routes. 24 | */ 25 | class MirrorNodeRouter 26 | { 27 | public: 28 | /** 29 | * Retrieves the route for a specific mirror node query type. 30 | * 31 | * @param queryType The type of the mirror node query (e.g., "accountInfoQuery"). 32 | * @return A string view representing the route for the specified mirror node query. 33 | */ 34 | [[nodiscard]] std::string getRoute(std::string_view queryType) const; 35 | 36 | private: 37 | /** 38 | * Internal mapping of mirror node query types to their respective routes. 39 | */ 40 | const std::unordered_map routes = { 41 | {ACCOUNT_INFO_QUERY, "/api/v1/accounts/$" }, 42 | { CONTRACT_INFO_QUERY, "/api/v1/contracts/$" }, 43 | { TOKEN_RELATIONSHIPS_QUERY, "/api/v1/accounts/$/tokens"}, 44 | { TOKEN_BALANCES_QUERY, "/api/v1/tokens/$/balances"} 45 | }; 46 | }; 47 | 48 | } // namespace Hiero::internal::MirrorNodeGateway 49 | 50 | #endif // HIERO_SDK_CPP_MIRRORNODEROUTER_H 51 | -------------------------------------------------------------------------------- /src/sdk/main/src/FeeSchedules.cc: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | #include "FeeSchedules.h" 3 | #include "impl/Utilities.h" 4 | 5 | #include 6 | 7 | #include 8 | 9 | namespace Hiero 10 | { 11 | //----- 12 | FeeSchedules FeeSchedules::fromProtobuf(const proto::CurrentAndNextFeeSchedule& proto) 13 | { 14 | FeeSchedules feeSchedules; 15 | 16 | if (proto.has_currentfeeschedule()) 17 | { 18 | feeSchedules.mCurrentFeeSchedule = FeeSchedule::fromProtobuf(proto.currentfeeschedule()); 19 | } 20 | 21 | if (proto.has_nextfeeschedule()) 22 | { 23 | feeSchedules.mNextFeeSchedule = FeeSchedule::fromProtobuf(proto.nextfeeschedule()); 24 | } 25 | 26 | return feeSchedules; 27 | } 28 | 29 | //----- 30 | FeeSchedules FeeSchedules::fromBytes(const std::vector& bytes) 31 | { 32 | proto::CurrentAndNextFeeSchedule proto; 33 | proto.ParseFromArray(bytes.data(), static_cast(bytes.size())); 34 | return fromProtobuf(proto); 35 | } 36 | 37 | //----- 38 | std::unique_ptr FeeSchedules::toProtobuf() const 39 | { 40 | auto proto = std::make_unique(); 41 | proto->set_allocated_currentfeeschedule(mCurrentFeeSchedule.toProtobuf().release()); 42 | proto->set_allocated_nextfeeschedule(mNextFeeSchedule.toProtobuf().release()); 43 | return proto; 44 | } 45 | 46 | //----- 47 | std::vector FeeSchedules::toBytes() const 48 | { 49 | return internal::Utilities::stringToByteVector(toProtobuf()->SerializeAsString()); 50 | } 51 | 52 | //----- 53 | std::string FeeSchedules::toString() const 54 | { 55 | nlohmann::json json; 56 | json["mCurrentFeeSchedule"] = mCurrentFeeSchedule.toString(); 57 | json["mNextFeeSchedule"] = mNextFeeSchedule.toString(); 58 | return json.dump(); 59 | } 60 | 61 | } // namespace Hiero 62 | -------------------------------------------------------------------------------- /src/sdk/examples/GetFileContentsExample.cpp: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | #include "Client.h" 3 | #include "ECDSAsecp256k1PrivateKey.h" 4 | #include "FileContentsQuery.h" 5 | #include "FileCreateTransaction.h" 6 | #include "FileId.h" 7 | #include "TransactionReceipt.h" 8 | #include "TransactionResponse.h" 9 | #include "impl/Utilities.h" 10 | 11 | #include 12 | #include 13 | 14 | using namespace Hiero; 15 | 16 | int main(int argc, char** argv) 17 | { 18 | dotenv::init(); 19 | const AccountId operatorAccountId = AccountId::fromString(std::getenv("OPERATOR_ID")); 20 | const std::shared_ptr operatorPrivateKey = 21 | ECDSAsecp256k1PrivateKey::fromString(std::getenv("OPERATOR_KEY")); 22 | 23 | // Get a client for the Hiero testnet, and set the operator account ID and key such that all generated transactions 24 | // will be paid for by this account and be signed by this key. 25 | Client client = Client::forTestnet(); 26 | client.setOperator(operatorAccountId, operatorPrivateKey); 27 | 28 | // Content to be stored in the file 29 | const std::vector contents = internal::Utilities::stringToByteVector("Hiero is great!"); 30 | 31 | // Create a new file with the contents 32 | FileId fileId = FileCreateTransaction() 33 | .setKeys({ client.getOperatorPublicKey() }) 34 | .setContents(contents) 35 | .execute(client) 36 | .getReceipt(client) 37 | .mFileId.value(); 38 | std::cout << "The created file ID is: " << fileId.toString() << std::endl; 39 | 40 | // Get the file contents 41 | FileContents fileContents = FileContentsQuery().setFileId(fileId).execute(client); 42 | std::cout << "The file contains the message: " << internal::Utilities::byteVectorToString(fileContents) << std::endl; 43 | 44 | return 0; 45 | } 46 | -------------------------------------------------------------------------------- /src/sdk/main/src/FreezeType.cc: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | #include "FreezeType.h" 3 | 4 | #include 5 | 6 | namespace Hiero 7 | { 8 | //----- 9 | const std::unordered_map gProtobufFreezeTypeToFreezeType = { 10 | {proto::FreezeType::UNKNOWN_FREEZE_TYPE, FreezeType::UNKNOWN_FREEZE_TYPE}, 11 | { proto::FreezeType::FREEZE_ONLY, FreezeType::FREEZE_ONLY }, 12 | { proto::FreezeType::PREPARE_UPGRADE, FreezeType::PREPARE_UPGRADE }, 13 | { proto::FreezeType::FREEZE_UPGRADE, FreezeType::FREEZE_UPGRADE }, 14 | { proto::FreezeType::FREEZE_ABORT, FreezeType::FREEZE_ABORT }, 15 | { proto::FreezeType::TELEMETRY_UPGRADE, FreezeType::TELEMETRY_UPGRADE }, 16 | }; 17 | 18 | //----- 19 | const std::unordered_map gFreezeTypeToProtobufFreezeType = { 20 | {FreezeType::UNKNOWN_FREEZE_TYPE, proto::FreezeType::UNKNOWN_FREEZE_TYPE}, 21 | { FreezeType::FREEZE_ONLY, proto::FreezeType::FREEZE_ONLY }, 22 | { FreezeType::PREPARE_UPGRADE, proto::FreezeType::PREPARE_UPGRADE }, 23 | { FreezeType::FREEZE_UPGRADE, proto::FreezeType::FREEZE_UPGRADE }, 24 | { FreezeType::FREEZE_ABORT, proto::FreezeType::FREEZE_ABORT }, 25 | { FreezeType::TELEMETRY_UPGRADE, proto::FreezeType::TELEMETRY_UPGRADE }, 26 | }; 27 | 28 | //----- 29 | const std::unordered_map gFreezeTypeToString = { 30 | {FreezeType::UNKNOWN_FREEZE_TYPE, "UNKNOWN_FREEZE_TYPE"}, 31 | { FreezeType::FREEZE_ONLY, "FREEZE_ONLY" }, 32 | { FreezeType::PREPARE_UPGRADE, "PREPARE_UPGRADE" }, 33 | { FreezeType::FREEZE_UPGRADE, "FREEZE_UPGRADE" }, 34 | { FreezeType::FREEZE_ABORT, "FREEZE_ABORT" }, 35 | { FreezeType::TELEMETRY_UPGRADE, "TELEMETRY_UPGRADE" }, 36 | }; 37 | 38 | } // namespace Hiero 39 | -------------------------------------------------------------------------------- /src/tck/include/key/KeyService.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | #ifndef HIERO_TCK_CPP_KEY_SERVICE_H_ 3 | #define HIERO_TCK_CPP_KEY_SERVICE_H_ 4 | 5 | #include 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | namespace Hiero::TCK::KeyService 13 | { 14 | /** 15 | * Forward declarations. 16 | */ 17 | struct GenerateKeyParams; 18 | 19 | /** 20 | * Enumeration of the possible types of Keys the SDK server can generate. 21 | */ 22 | enum class KeyType : unsigned char 23 | { 24 | ED25519_PRIVATE_KEY_TYPE, 25 | ED25519_PUBLIC_KEY_TYPE, 26 | ECDSA_SECP256k1_PRIVATE_KEY_TYPE, 27 | ECDSA_SECP256k1_PUBLIC_KEY_TYPE, 28 | LIST_KEY_TYPE, 29 | THRESHOLD_KEY_TYPE, 30 | EVM_ADDRESS_KEY_TYPE, 31 | KEY_TYPE_SIZE [[maybe_unused]] 32 | }; 33 | 34 | /** 35 | * Map of KeyTypes to their string representation. 36 | */ 37 | extern const std::unordered_map gStringToKeyType; 38 | 39 | /** 40 | * Map of KeyType string representations to KeyType. 41 | */ 42 | extern const std::unordered_map gKeyTypeToString; 43 | 44 | /** 45 | * Generate a Key. 46 | * 47 | * @param params The parameters to use to generate a key. 48 | * @return The JSON object which contains the generated key. 49 | */ 50 | nlohmann::json generateKey(const GenerateKeyParams& params); 51 | 52 | /** 53 | * Generate a Key from a key hex string. The string must be either the DER-encoding of an ED25519 or ECDSAsecp256k1 54 | * private or public key, or the serialized Key protobuf of a KeyList or ThresholdKey. 55 | * 56 | * @param key The hex string from which to get the Key. 57 | * @return The Key of the input hex string. 58 | */ 59 | std::shared_ptr getHieroKey(const std::string& key); 60 | 61 | } // namespace Hiero::TCK::KeyService 62 | 63 | #endif // HIERO_TCK_CPP_KEY_SERVICE_H_ 64 | -------------------------------------------------------------------------------- /src/sdk/main/include/TokenType.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | #ifndef HIERO_SDK_CPP_TOKEN_TYPE_H_ 3 | #define HIERO_SDK_CPP_TOKEN_TYPE_H_ 4 | 5 | #include 6 | #include 7 | 8 | namespace proto 9 | { 10 | enum TokenType : int; 11 | } 12 | 13 | namespace Hiero 14 | { 15 | /** 16 | * Possible token types (IWA Compatibility). 17 | * 18 | * Apart from fungible and non-fungible, tokens can have either a common or unique representation. This distinction 19 | * might seem subtle, but it is important when considering how tokens can be traced and if they can have isolated and 20 | * unique properties. 21 | */ 22 | enum class TokenType 23 | { 24 | /** 25 | * Interchangeable value with one another, where any quantity of them has the same value as another equal quantity if 26 | * they are in the same class. Share a single set of properties, not distinct from one another. Simply represented as 27 | * a balance or quantity to a given Hiero account. 28 | */ 29 | FUNGIBLE_COMMON, 30 | /** 31 | * Unique, not interchangeable with other tokens of the same type as they typically have different values. 32 | * Individually traced and can carry unique properties (e.g. serial number). 33 | */ 34 | NON_FUNGIBLE_UNIQUE 35 | }; 36 | 37 | /** 38 | * Map of protobuf TokenTypes to the corresponding TokenType. 39 | */ 40 | extern const std::unordered_map gProtobufTokenTypeToTokenType; 41 | 42 | /** 43 | * Map of TokenTypes to the corresponding protobuf TokenType. 44 | */ 45 | extern const std::unordered_map gTokenTypeToProtobufTokenType; 46 | 47 | /** 48 | * Map of TokenType to its corresponding string. 49 | */ 50 | [[maybe_unused]] extern const std::unordered_map gTokenTypeToString; 51 | 52 | } // namespace Hiero 53 | 54 | #endif // HIERO_SDK_CPP_TOKEN_TYPE_H_ 55 | -------------------------------------------------------------------------------- /src/sdk/main/src/Endpoint.cc: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | #include "Endpoint.h" 3 | #include "impl/Utilities.h" 4 | 5 | #include 6 | 7 | namespace Hiero 8 | { 9 | //----- 10 | Endpoint Endpoint::fromProtobuf(const proto::ServiceEndpoint& protoServiceEndpoint) 11 | { 12 | if (protoServiceEndpoint.ipaddressv4().empty()) 13 | { 14 | return Endpoint() 15 | .setDomainName(protoServiceEndpoint.domain_name()) 16 | .setPort(static_cast(protoServiceEndpoint.port())); 17 | } 18 | else 19 | { 20 | return Endpoint() 21 | .setAddress(IPv4Address::fromBytes(internal::Utilities::stringToByteVector(protoServiceEndpoint.ipaddressv4()))) 22 | .setPort(static_cast(protoServiceEndpoint.port())); 23 | } 24 | } 25 | 26 | //----- 27 | std::unique_ptr Endpoint::toProtobuf() const 28 | { 29 | auto proto = std::make_unique(); 30 | proto->set_ipaddressv4(internal::Utilities::byteVectorToString(mAddress.toBytes())); 31 | proto->set_port(static_cast(mPort)); 32 | proto->set_domain_name(mDomainName); 33 | return proto; 34 | } 35 | 36 | //----- 37 | std::string Endpoint::toString() const 38 | { 39 | if (!mAddress.isEmpty()) 40 | { 41 | return mAddress.toString() + ':' + std::to_string(mPort); 42 | } 43 | else 44 | { 45 | return mDomainName + ':' + std::to_string(mPort); 46 | } 47 | } 48 | 49 | //----- 50 | Endpoint& Endpoint::setAddress(const IPv4Address& address) 51 | { 52 | mAddress = address; 53 | return *this; 54 | } 55 | 56 | //----- 57 | Endpoint& Endpoint::setPort(unsigned int port) 58 | { 59 | mPort = port; 60 | return *this; 61 | } 62 | 63 | //----- 64 | Endpoint& Endpoint::setDomainName(std::string_view domainName) 65 | { 66 | mDomainName = domainName; 67 | return *this; 68 | } 69 | } // namespace Hiero 70 | -------------------------------------------------------------------------------- /src/sdk/main/include/FeeDataType.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | #ifndef HIERO_SDK_CPP_FEE_DATA_TYPE_H_ 3 | #define HIERO_SDK_CPP_FEE_DATA_TYPE_H_ 4 | 5 | #include 6 | #include 7 | 8 | namespace proto 9 | { 10 | enum SubType : int; 11 | } 12 | 13 | namespace Hiero 14 | { 15 | /** 16 | * Enumeration of fee data types. 17 | */ 18 | enum class FeeDataType 19 | { 20 | /** 21 | * The resource prices have no special scope. 22 | */ 23 | DEFAULT, 24 | /** 25 | * The resource prices are scoped to an operation on a fungible common token. 26 | */ 27 | TOKEN_FUNGIBLE_COMMON, 28 | /** 29 | * The resource prices are scoped to an operation on a non-fungible unique token. 30 | */ 31 | TOKEN_NON_FUNGIBLE_UNIQUE, 32 | /** 33 | * The resource prices are scoped to an operation on a fungible common token with a custom fee schedule. 34 | */ 35 | TOKEN_FUNGIBLE_COMMON_WITH_CUSTOM_FEES, 36 | /** 37 | * The resource prices are scoped to an operation on a non-fungible unique token with a custom fee schedule. 38 | */ 39 | TOKEN_NON_FUNGIBLE_UNIQUE_WITH_CUSTOM_FEES, 40 | /** 41 | * The resource prices are scoped to a ScheduleCreate containing a ContractCall. 42 | */ 43 | SCHEDULE_CREATE_CONTRACT_CALL 44 | }; 45 | 46 | /** 47 | * Map of protobuf SubTypes to their corresponding FeeDataTypes. 48 | */ 49 | extern const std::unordered_map gProtobufSubTypeToFeeDataType; 50 | 51 | /** 52 | * Map of FeeDataTypes to their corresponding protobuf SubTypes. 53 | */ 54 | extern const std::unordered_map gFeeDataTypeToProtobufSubType; 55 | 56 | /** 57 | * Map of FeeDataType to its corresponding string. 58 | */ 59 | [[maybe_unused]] extern const std::unordered_map gFeeDataTypeToString; 60 | 61 | } // namespace Hiero 62 | 63 | #endif // HIERO_SDK_CPP_FEE_DATA_TYPE_H_ 64 | -------------------------------------------------------------------------------- /src/sdk/tests/integration/TransactionReceiptQueryIntegrationTests.cc: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | #include "AccountCreateTransaction.h" 3 | #include "AccountDeleteTransaction.h" 4 | #include "BaseIntegrationTest.h" 5 | #include "ED25519PrivateKey.h" 6 | #include "TransactionId.h" 7 | #include "TransactionReceipt.h" 8 | #include "TransactionReceiptQuery.h" 9 | #include "TransactionRecord.h" 10 | #include "TransactionResponse.h" 11 | #include "exceptions/PrecheckStatusException.h" 12 | #include "impl/Utilities.h" 13 | 14 | #include 15 | 16 | using namespace Hiero; 17 | 18 | class TransactionReceiptQueryIntegrationTests : public BaseIntegrationTest 19 | { 20 | }; 21 | 22 | //----- 23 | TEST_F(TransactionReceiptQueryIntegrationTests, CanGetTransactionReceipt) 24 | { 25 | // Given 26 | const std::shared_ptr testPrivateKey = ED25519PrivateKey::generatePrivateKey(); 27 | const std::shared_ptr testPublicKey = testPrivateKey->getPublicKey(); 28 | 29 | TransactionResponse testTxResponse; 30 | ASSERT_NO_THROW(testTxResponse = 31 | AccountCreateTransaction().setKeyWithoutAlias(testPublicKey).execute(getTestClient())); 32 | 33 | // When / Then 34 | TransactionReceipt txReceipt; 35 | EXPECT_NO_THROW(txReceipt = 36 | TransactionReceiptQuery().setTransactionId(testTxResponse.mTransactionId).execute(getTestClient())); 37 | EXPECT_EQ(txReceipt.mTransactionId, testTxResponse.mTransactionId); 38 | 39 | // Clean up 40 | AccountId accountId; 41 | ASSERT_NO_THROW(accountId = txReceipt.mAccountId.value()); 42 | ASSERT_NO_THROW(AccountDeleteTransaction() 43 | .setDeleteAccountId(accountId) 44 | .setTransferAccountId(AccountId(2ULL)) 45 | .freezeWith(&getTestClient()) 46 | .sign(testPrivateKey) 47 | .execute(getTestClient())); 48 | } -------------------------------------------------------------------------------- /src/sdk/tests/unit/EthereumFlowUnitTests.cc: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | #include "AccountId.h" 3 | #include "Client.h" 4 | #include "ECDSAsecp256k1PrivateKey.h" 5 | #include "EthereumFlow.h" 6 | #include "FileId.h" 7 | #include "Hbar.h" 8 | #include "impl/HexConverter.h" 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | using namespace Hiero; 15 | 16 | class EthereumFlowUnitTests : public ::testing::Test 17 | { 18 | protected: 19 | void SetUp() override 20 | { 21 | mClient.setOperator(AccountId(), ECDSAsecp256k1PrivateKey::generatePrivateKey()); 22 | mTestEthereumData = internal::HexConverter::hexToBytes( 23 | "02f87082012a022f2f83018000947e3a9eaf9bcc39e2ffa38eb30bf7a93feacbc181880de0b6b3a" 24 | "7640000831234568001a0df48f2efd10421811de2bfb125ab75b2d3c44139c4642837fb1fccce91" 25 | "1fd479a01aaf7ae92bee896651dfc9d99ae422a296bf5d9f1ca49b2d96d82b79eb112d66"); 26 | } 27 | 28 | [[nodiscard]] inline const std::vector& getTestEthereumData() const { return mTestEthereumData; } 29 | [[nodiscard]] inline const Hbar& getTestMaxGasAllowance() const { return mTestMaxGasAllowance; } 30 | 31 | private: 32 | Client mClient; 33 | std::vector mTestEthereumData; 34 | const Hbar mTestMaxGasAllowance = Hbar(1LL); 35 | }; 36 | 37 | //----- 38 | TEST_F(EthereumFlowUnitTests, GetSetEthereumData) 39 | { 40 | // Given 41 | EthereumFlow flow; 42 | 43 | // When 44 | EXPECT_NO_THROW(flow.setEthereumData(getTestEthereumData())); 45 | 46 | // Then 47 | EXPECT_EQ(flow.getEthereumData()->toBytes(), getTestEthereumData()); 48 | } 49 | 50 | //----- 51 | TEST_F(EthereumFlowUnitTests, GetSetMaxGasAllowance) 52 | { 53 | // Given 54 | EthereumFlow flow; 55 | 56 | // When 57 | flow.setMaxGasAllowance(getTestMaxGasAllowance()); 58 | 59 | // Then 60 | EXPECT_EQ(flow.getMaxGasAllowance(), getTestMaxGasAllowance()); 61 | } 62 | -------------------------------------------------------------------------------- /src/sdk/tests/integration/FreezeTransactionIntegrationTests.cc: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | #include "BaseIntegrationTest.h" 3 | #include "Client.h" 4 | #include "ED25519PrivateKey.h" 5 | #include "FileCreateTransaction.h" 6 | #include "FileDeleteTransaction.h" 7 | #include "FileId.h" 8 | #include "FreezeTransaction.h" 9 | #include "PrivateKey.h" 10 | #include "TransactionReceipt.h" 11 | #include "TransactionResponse.h" 12 | 13 | #include 14 | 15 | using namespace Hiero; 16 | 17 | class FreezeTransactionIntegrationTests : public BaseIntegrationTest 18 | { 19 | }; 20 | 21 | //----- 22 | TEST_F(FreezeTransactionIntegrationTests, DISABLED_ExecuteFreezeTransaction) 23 | { 24 | // Given 25 | std::unique_ptr operatorKey; 26 | ASSERT_NO_THROW( 27 | operatorKey = ED25519PrivateKey::fromString( 28 | "302e020100300506032b65700422042091132178e72057a1d7528025956fe39b0b847f200ab59b2fdd367017f3087137")); 29 | 30 | FileId fileId; 31 | ASSERT_NO_THROW(fileId = FileCreateTransaction() 32 | .setKeys({ operatorKey->getPublicKey() }) 33 | .execute(getTestClient()) 34 | .getReceipt(getTestClient()) 35 | .mFileId.value()); 36 | 37 | // When / Then 38 | EXPECT_NO_THROW(const TransactionReceipt txReceipt = 39 | FreezeTransaction() 40 | .setFileId(fileId) 41 | .setStartTime(std::chrono::system_clock::now() + std::chrono::seconds(30)) 42 | .setFreezeType(FreezeType::FREEZE_ONLY) 43 | .execute(getTestClient()) 44 | .getReceipt(getTestClient())); 45 | 46 | // Clean up 47 | ASSERT_NO_THROW(const TransactionReceipt txReceipt = 48 | FileDeleteTransaction().setFileId(fileId).execute(getTestClient()).getReceipt(getTestClient())); 49 | } 50 | -------------------------------------------------------------------------------- /src/tck/include/account/params/TransferCryptoParams.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | #ifndef HIERO_TCK_CPP_TRANSFER_CRYPTO_PARAMS_H_ 3 | #define HIERO_TCK_CPP_TRANSFER_CRYPTO_PARAMS_H_ 4 | 5 | #include "common/CommonTransactionParams.h" 6 | #include "common/transfer/TransferParams.h" 7 | #include "json/JsonUtils.h" 8 | 9 | #include 10 | #include 11 | 12 | namespace Hiero::TCK::AccountService 13 | { 14 | /** 15 | * Struct to hold the arguments for a `transferCrypto` JSON-RPC method call. 16 | */ 17 | struct TransferCryptoParams 18 | { 19 | /** 20 | * The transfer information. 21 | */ 22 | std::optional> mTransfers; 23 | 24 | /** 25 | * Any parameters common to all transaction types. 26 | */ 27 | std::optional mCommonTxParams; 28 | }; 29 | 30 | } // namespace Hiero::TCK::AccountService 31 | 32 | namespace nlohmann 33 | { 34 | /** 35 | * JSON serializer template specialization required to convert TransferCryptoParams arguments properly. 36 | */ 37 | template<> 38 | struct [[maybe_unused]] adl_serializer 39 | { 40 | /** 41 | * Convert a JSON object to a TransferCryptoParams. 42 | * 43 | * @param jsonFrom The JSON object with which to fill the TransferCryptoParams. 44 | * @param params The TransferCryptoParams to fill with the JSON object. 45 | */ 46 | static void from_json(const json& jsonFrom, Hiero::TCK::AccountService::TransferCryptoParams& params) 47 | { 48 | params.mTransfers = 49 | Hiero::TCK::getOptionalJsonParameter>(jsonFrom, "transfers"); 50 | params.mCommonTxParams = 51 | Hiero::TCK::getOptionalJsonParameter(jsonFrom, "commonTransactionParams"); 52 | } 53 | }; 54 | 55 | } // namespace nlohmann 56 | 57 | #endif // HIERO_TCK_CPP_TRANSFER_CRYPTO_PARAMS_H_ 58 | -------------------------------------------------------------------------------- /src/sdk/examples/ScheduleNetworkUpdateExample.cpp: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | #include "AccountId.h" 3 | #include "Client.h" 4 | #include "ECDSAsecp256k1PrivateKey.h" 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | using namespace Hiero; 12 | 13 | int main(int argc, char** argv) 14 | { 15 | dotenv::init(); 16 | const AccountId operatorAccountId = AccountId::fromString(std::getenv("OPERATOR_ID")); 17 | const std::shared_ptr operatorPrivateKey = 18 | ECDSAsecp256k1PrivateKey::fromString(std::getenv("OPERATOR_KEY")); 19 | 20 | /* 21 | * Step 1: Initialize the client. 22 | * Note: By default, the first network address book update will be executed now 23 | * and subsequent updates will occur every 24 hours. 24 | * This is controlled by network update period, which defaults to 24 hours. 25 | */ 26 | Client client = Client::forTestnet(); 27 | 28 | const auto defaultNetworkUpdatePeriod = client.getNetworkUpdatePeriod(); 29 | std::cout << "The network update period is " << defaultNetworkUpdatePeriod.count() << " seconds" << std::endl; 30 | 31 | /* 32 | * Step 2: Change network update period to 1 hour 33 | */ 34 | const auto newNetworkUpdatePeriod = std::chrono::hours(1); 35 | client.setNetworkUpdatePeriod(newNetworkUpdatePeriod); 36 | std::cout << "Changed the network update period to " << defaultNetworkUpdatePeriod.count() << " hour" << std::endl; 37 | 38 | /* 39 | * Step 3: Wait for 1 hour 40 | */ 41 | std::cout << "Waiting for 1 hour..." << std::endl; 42 | std::this_thread::sleep_for(std::chrono::hours(1)); 43 | std::cout << "1 hour elapsed." << std::endl; 44 | 45 | /* 46 | * Step 4: Display client network 47 | */ 48 | for (const auto node : client.getNetwork()) 49 | { 50 | std::cout << "Node address: " << node.first << " Node account: " << node.second.toString() << std::endl; 51 | } 52 | 53 | return 0; 54 | } -------------------------------------------------------------------------------- /src/sdk/main/include/Key.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | #ifndef HIERO_SDK_CPP_KEY_H_ 3 | #define HIERO_SDK_CPP_KEY_H_ 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | namespace proto 10 | { 11 | class Key; 12 | } 13 | 14 | namespace Hiero 15 | { 16 | /** 17 | * A generic base class for the signing authority or key that entities in Hiero may have. 18 | */ 19 | class Key 20 | { 21 | public: 22 | virtual ~Key() = default; 23 | 24 | /** 25 | * Construct a Key object from a Key protobuf object. 26 | * 27 | * @param proto The Key protobuf object from which to create a Key object. 28 | * @return A pointer to the created PublicKey object. 29 | * @throws std::invalid_argument If the Key protobuf type is not recognized. 30 | */ 31 | [[nodiscard]] static std::unique_ptr fromProtobuf(const proto::Key& proto); 32 | 33 | /** 34 | * Create a clone of this Key object. 35 | * 36 | * @return A pointer to the created clone of this Key. 37 | */ 38 | [[nodiscard]] virtual std::unique_ptr clone() const = 0; 39 | 40 | /** 41 | * Construct a Key protobuf object from this Key object. 42 | * 43 | * @return A pointer to the created Key protobuf object filled with this Key object's data. 44 | */ 45 | [[nodiscard]] virtual std::unique_ptr toProtobufKey() const = 0; 46 | 47 | /** 48 | * Get the byte representation of this Key. 49 | * 50 | * @return The byte representation of this Key. 51 | */ 52 | [[nodiscard]] virtual std::vector toBytes() const; 53 | 54 | protected: 55 | Key() = default; 56 | 57 | /** 58 | * Prevent public copying and moving to prevent slicing. Use the 'clone()' virtual method instead. 59 | */ 60 | Key(const Key&) = default; 61 | Key& operator=(const Key&) = default; 62 | Key(Key&&) = default; 63 | Key& operator=(Key&&) = default; 64 | }; 65 | 66 | } // namespace Hiero 67 | 68 | #endif // HIERO_SDK_CPP_KEY_H_ 69 | -------------------------------------------------------------------------------- /MAINTAINERS.md: -------------------------------------------------------------------------------- 1 | # Maintainers 2 | 3 | The general handling of Maintainer rights and all groups in this GitHub org is done in the https://github.com/hiero-ledger/governance repository. 4 | 5 | ## Maintainer Scopes, GitHub Roles and GitHub Teams 6 | 7 | Maintainers are assigned the following scopes in this repository: 8 | 9 | | Scope | Definition | GitHub Role | GitHub Team | 10 | |---------------------|-----------------------------------|-------------|------------------------------| 11 | | project-maintainers | The Maintainers of the project | Maintain | `hiero-sdk-cpp-maintainers` | 12 | | tsc | The Hiero TSC | Maintain | `tsc` | 13 | | github-maintainers | The Maintainers of the github org | Maintain | `github-maintainers` | 14 | 15 | ## Active Maintainers 16 | 17 | 18 | 19 | | Name | GitHub ID | Scope | LFID | Discord ID | Email | Company Affiliation | 20 | |--------------- | ---------- | ----- | ---- | ----------- | ----- | ------------------- | 21 | | Rob Walworth | rwalworth | | | robborg | | Hashgraph | 22 | | Simi Hunjan | SimiHunjan | | | | | Hashgraph | 23 | | Georgi Stoykov | gsstoykov | | | glime_39042 | | LimeChain | 24 | 25 | 26 | ## Emeritus Maintainers 27 | 28 | | Name | GitHub ID | Scope | LFID | Discord ID | Email | Company Affiliation | 29 | |----- | --------- | ----- | ---- | ---------- | ----- | ------------------- | 30 | | | | | | | | | 31 | 32 | ## The Duties of a Maintainer 33 | 34 | Maintainers are expected to perform duties in alignment with **[Hiero-Ledger's defined maintainer guidelines](https://github.com/hiero-ledger/governance/blob/main/roles-and-groups.md#maintainers).** 35 | -------------------------------------------------------------------------------- /src/sdk/main/src/AccountBalance.cc: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | #include "AccountBalance.h" 3 | #include "impl/Utilities.h" 4 | 5 | #include 6 | 7 | #include 8 | 9 | namespace Hiero 10 | { 11 | //----- 12 | AccountBalance AccountBalance::fromProtobuf(const proto::CryptoGetAccountBalanceResponse& proto) 13 | { 14 | AccountBalance balance; 15 | balance.mBalance = Hbar(static_cast(proto.balance()), HbarUnit::TINYBAR()); 16 | 17 | for (auto it = proto.tokenbalances().begin(); it != proto.tokenbalances().end(); it++) 18 | { 19 | balance.mTokens.insert({ TokenId::fromProtobuf(it->tokenid()), it->balance() }); 20 | } 21 | 22 | return balance; 23 | } 24 | 25 | //----- 26 | AccountBalance AccountBalance::fromBytes(const std::vector& bytes) 27 | { 28 | proto::CryptoGetAccountBalanceResponse proto; 29 | proto.ParseFromArray(bytes.data(), static_cast(bytes.size())); 30 | return fromProtobuf(proto); 31 | } 32 | 33 | //----- 34 | std::unique_ptr AccountBalance::toProtobuf() const 35 | { 36 | auto proto = std::make_unique(); 37 | proto->set_balance(static_cast(mBalance.toTinybars())); 38 | return proto; 39 | } 40 | 41 | //----- 42 | std::vector AccountBalance::toBytes() const 43 | { 44 | return internal::Utilities::stringToByteVector(toProtobuf()->SerializeAsString()); 45 | } 46 | 47 | //----- 48 | std::string AccountBalance::toString() const 49 | { 50 | nlohmann::json json; 51 | json["mBalance"] = mBalance.toString(); 52 | 53 | for (const auto& pair : mTokens) 54 | { 55 | json[pair.first.toString()] = pair.second; 56 | } 57 | 58 | return json.dump(); 59 | } 60 | 61 | //----- 62 | std::ostream& operator<<(std::ostream& os, const AccountBalance& balance) 63 | { 64 | os << balance.toString(); 65 | return os; 66 | } 67 | 68 | } // namespace Hiero 69 | -------------------------------------------------------------------------------- /src/sdk/main/src/FileInfoQuery.cc: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | #include "FileInfoQuery.h" 3 | #include "FileInfo.h" 4 | #include "impl/Node.h" 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | namespace Hiero 12 | { 13 | //----- 14 | FileInfoQuery& FileInfoQuery::setFileId(const FileId& fileId) 15 | { 16 | mFileId = fileId; 17 | return *this; 18 | } 19 | 20 | //----- 21 | FileInfo FileInfoQuery::mapResponse(const proto::Response& response) const 22 | { 23 | return FileInfo::fromProtobuf(response.filegetinfo().fileinfo()); 24 | } 25 | 26 | //----- 27 | grpc::Status FileInfoQuery::submitRequest(const proto::Query& request, 28 | const std::shared_ptr& node, 29 | const std::chrono::system_clock::time_point& deadline, 30 | proto::Response* response) const 31 | { 32 | return node->submitQuery(proto::Query::QueryCase::kFileGetInfo, request, deadline, response); 33 | } 34 | 35 | //----- 36 | void FileInfoQuery::validateChecksums(const Client& client) const 37 | { 38 | mFileId.validateChecksum(client); 39 | } 40 | 41 | //----- 42 | proto::Query FileInfoQuery::buildRequest(proto::QueryHeader* header) const 43 | { 44 | auto fileGetInfoQuery = std::make_unique(); 45 | fileGetInfoQuery->set_allocated_header(header); 46 | fileGetInfoQuery->set_allocated_fileid(mFileId.toProtobuf().release()); 47 | 48 | proto::Query query; 49 | query.set_allocated_filegetinfo(fileGetInfoQuery.release()); 50 | return query; 51 | } 52 | 53 | //----- 54 | proto::ResponseHeader FileInfoQuery::mapResponseHeader(const proto::Response& response) const 55 | { 56 | saveCostFromHeader(response.filegetinfo().header()); 57 | return response.filegetinfo().header(); 58 | } 59 | 60 | } // namespace Hiero 61 | -------------------------------------------------------------------------------- /src/sdk/tests/unit/FileDeleteTransactionUnitTests.cc: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | #include "Client.h" 3 | #include "ED25519PrivateKey.h" 4 | #include "FileDeleteTransaction.h" 5 | #include "exceptions/IllegalStateException.h" 6 | 7 | #include 8 | #include 9 | 10 | using namespace Hiero; 11 | 12 | class FileDeleteTransactionUnitTests : public ::testing::Test 13 | { 14 | protected: 15 | [[nodiscard]] inline const FileId& getTestFileId() const { return mTestFileId; } 16 | 17 | private: 18 | const FileId mTestFileId = FileId(1ULL); 19 | }; 20 | 21 | //----- 22 | TEST_F(FileDeleteTransactionUnitTests, ConstructFileDeleteTransactionFromTransactionBodyProtobuf) 23 | { 24 | // Given 25 | auto body = std::make_unique(); 26 | body->set_allocated_fileid(getTestFileId().toProtobuf().release()); 27 | 28 | proto::TransactionBody txBody; 29 | txBody.set_allocated_filedelete(body.release()); 30 | 31 | // When 32 | const FileDeleteTransaction fileDeleteTransaction(txBody); 33 | 34 | // Then 35 | EXPECT_EQ(fileDeleteTransaction.getFileId(), getTestFileId()); 36 | } 37 | 38 | //----- 39 | TEST_F(FileDeleteTransactionUnitTests, GetSetFileId) 40 | { 41 | // Given 42 | FileDeleteTransaction transaction; 43 | 44 | // When 45 | EXPECT_NO_THROW(transaction.setFileId(getTestFileId())); 46 | 47 | // Then 48 | EXPECT_EQ(transaction.getFileId(), getTestFileId()); 49 | } 50 | 51 | //----- 52 | TEST_F(FileDeleteTransactionUnitTests, GetSetFileIdFrozen) 53 | { 54 | // Given 55 | FileDeleteTransaction transaction = FileDeleteTransaction() 56 | .setNodeAccountIds({ AccountId(1ULL) }) 57 | .setTransactionId(TransactionId::generate(AccountId(1ULL))); 58 | ASSERT_NO_THROW(transaction.freeze()); 59 | 60 | // When / Then 61 | EXPECT_THROW(transaction.setFileId(getTestFileId()), IllegalStateException); 62 | } 63 | -------------------------------------------------------------------------------- /src/sdk/main/include/exceptions/BadEntityIdException.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | #ifndef HIERO_SDK_CPP_BAD_ENTITY_ID_EXCEPTION_H_ 3 | #define HIERO_SDK_CPP_BAD_ENTITY_ID_EXCEPTION_H_ 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | namespace Hiero 10 | { 11 | /** 12 | * Exception that is thrown when a key could not be realized from a given input. 13 | */ 14 | class BadEntityIdException : public std::exception 15 | { 16 | public: 17 | /** 18 | * Construct with an entity, its expected checksum, and its calculated checksum. 19 | * 20 | * @param shard The shard of the entity. 21 | * @param realm The realm of the entity. 22 | * @param num The num of the entity. 23 | * @param expectedChecksum The checksum against which the calculated checksum was validated. 24 | * @param calculatedChecksum The checksum that was calculated of the input entity. 25 | */ 26 | explicit BadEntityIdException(uint64_t shard, 27 | uint64_t realm, 28 | uint64_t num, 29 | std::string_view expectedChecksum, 30 | std::string_view calculatedChecksum) 31 | : mError(std::string("Expected checksum ") + expectedChecksum.data() + " for entity " + std::to_string(shard) + 32 | '.' + std::to_string(realm) + '.' + std::to_string(num) + " does not match its calculated checksum " + 33 | calculatedChecksum.data()) 34 | { 35 | } 36 | 37 | /** 38 | * Get the descriptor message for this error. 39 | * 40 | * @return The descriptor message for this error. 41 | */ 42 | [[nodiscard]] const char* what() const noexcept override { return mError.data(); }; 43 | 44 | private: 45 | /** 46 | * Descriptive error message. 47 | */ 48 | std::string mError; 49 | }; 50 | 51 | } // namespace Hiero 52 | 53 | #endif // HIERO_SDK_CPP_BAD_ENTITY_ID_EXCEPTION_H_ 54 | -------------------------------------------------------------------------------- /src/sdk/main/include/exceptions/PrecheckStatusException.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | #ifndef HIERO_SDK_CPP_PRECHECK_STATUS_EXCEPTION_H_ 3 | #define HIERO_SDK_CPP_PRECHECK_STATUS_EXCEPTION_H_ 4 | 5 | #include "Status.h" 6 | #include "TransactionId.h" 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | namespace Hiero 13 | { 14 | /** 15 | * Exception that is thrown when a request has failed its pre-check. 16 | */ 17 | class PrecheckStatusException : public std::exception 18 | { 19 | public: 20 | /** 21 | * Construct with the ID of the transaction that failed and its status. 22 | * 23 | * @param transactionId The ID of the transaction that failed. 24 | * @param status The status of the transaction. 25 | */ 26 | explicit PrecheckStatusException(Status status, 27 | const std::optional& transactionId = std::optional()) 28 | : mTransactionId(transactionId) 29 | , mStatus(status) 30 | , mError(((transactionId.has_value()) ? "Hiero transaction " + transactionId->toString() + ' ' : "") + 31 | "failed precheck with status " + gStatusToString.at(mStatus)) 32 | { 33 | } 34 | 35 | /** 36 | * Get the descriptor message for this error. 37 | * 38 | * @return The descriptor message for this error. 39 | */ 40 | [[nodiscard]] const char* what() const noexcept override { return mError.data(); }; 41 | 42 | /** 43 | * The ID of the transaction that failed. This can be uninitialized if a query fails pre-check without an associated 44 | * payment transaction. 45 | */ 46 | std::optional mTransactionId; 47 | 48 | /** 49 | * The status of the failed transaction. 50 | */ 51 | Status mStatus = Status::OK; 52 | 53 | /** 54 | * Descriptive error message. 55 | */ 56 | std::string mError; 57 | }; 58 | 59 | } // namespace Hiero 60 | 61 | #endif // HIERO_SDK_CPP_PRECHECK_STATUS_EXCEPTION_H_ 62 | -------------------------------------------------------------------------------- /src/sdk/tests/unit/TokenPauseTransactionUnitTests.cc: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | #include "Client.h" 3 | #include "ECDSAsecp256k1PrivateKey.h" 4 | #include "TokenPauseTransaction.h" 5 | #include "exceptions/IllegalStateException.h" 6 | 7 | #include 8 | #include 9 | 10 | using namespace Hiero; 11 | 12 | class TokenPauseTransactionUnitTests : public ::testing::Test 13 | { 14 | protected: 15 | [[nodiscard]] inline const TokenId& getTestTokenId() const { return mTestTokenId; } 16 | 17 | private: 18 | const TokenId mTestTokenId = TokenId(1ULL); 19 | }; 20 | 21 | //----- 22 | TEST_F(TokenPauseTransactionUnitTests, ConstructTokenPauseTransactionFromTransactionBodyProtobuf) 23 | { 24 | // Given 25 | auto body = std::make_unique(); 26 | body->set_allocated_token(getTestTokenId().toProtobuf().release()); 27 | 28 | proto::TransactionBody txBody; 29 | txBody.set_allocated_token_pause(body.release()); 30 | 31 | // When 32 | const TokenPauseTransaction tokenPauseTransaction(txBody); 33 | 34 | // Then 35 | EXPECT_EQ(tokenPauseTransaction.getTokenId(), getTestTokenId()); 36 | } 37 | 38 | //----- 39 | TEST_F(TokenPauseTransactionUnitTests, GetSetTokenId) 40 | { 41 | // Given 42 | TokenPauseTransaction transaction; 43 | 44 | // When 45 | EXPECT_NO_THROW(transaction.setTokenId(getTestTokenId())); 46 | 47 | // Then 48 | EXPECT_EQ(transaction.getTokenId(), getTestTokenId()); 49 | } 50 | 51 | //----- 52 | TEST_F(TokenPauseTransactionUnitTests, GetSetTokenIdFrozen) 53 | { 54 | // Given 55 | TokenPauseTransaction transaction = TokenPauseTransaction() 56 | .setNodeAccountIds({ AccountId(1ULL) }) 57 | .setTransactionId(TransactionId::generate(AccountId(1ULL))); 58 | ASSERT_NO_THROW(transaction.freeze()); 59 | 60 | // When / Then 61 | EXPECT_THROW(transaction.setTokenId(getTestTokenId()), IllegalStateException); 62 | } -------------------------------------------------------------------------------- /src/sdk/main/include/impl/ASN1ECKey.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | #ifndef HIERO_SDK_CPP_IMPL_ASN1_EC_KEY_H_ 3 | #define HIERO_SDK_CPP_IMPL_ASN1_EC_KEY_H_ 4 | 5 | #include "ASN1Object.h" 6 | 7 | namespace Hiero::internal::asn1 8 | { 9 | constexpr size_t EC_KEY_LENGTH = 32; // bytes 10 | // more than this would be a malicious attempt 11 | constexpr size_t MAX_ENCRYPTED_KEY_LENGHT = 160; // bytes ~ 320 characters 12 | 13 | /** 14 | * @class ASN1Key 15 | * ASN.1 key object. 16 | */ 17 | class ASN1ECKey : public ASN1Object 18 | { 19 | public: 20 | /** 21 | * Get the key value associated with the ASN.1 key. 22 | * 23 | * @return The key as a vector of bytes. 24 | */ 25 | virtual std::vector getKey() const = 0; 26 | 27 | protected: 28 | /** 29 | * Decode ASN.1 data representing an Elliptic Curve Key. 30 | * 31 | * This method decodes basic ASN.1 data, extracting key data and storing it in the `asn1KeyData` map. 32 | * EC Keys in ASN1 format always follow a common structure: 33 | * 34 | * ECKey ::= SEQUENCE { 35 | * version INTEGER { ecPrivkeyVer1(1) } (ecPrivkeyVer1) OPTIONAL, 36 | * key STRING_DATA, 37 | * parameters [0] ECParameters {{ NamedCurve }} OPTIONAL, 38 | * otherKey [1] STRING_DATA OPTIONAL 39 | * } 40 | * 41 | * @param bytes The ASN.1-encoded data representing the Elliptic Curve Key. 42 | */ 43 | virtual void decode(const std::vector& bytes); 44 | 45 | /** 46 | * Get the value associated with the given ASN.1 tag. 47 | * 48 | * @param tag The ASN.1 tag. 49 | * @return The value associated with the tag as a vector of bytes. 50 | */ 51 | virtual const std::vector get(const std::byte tag) const; 52 | 53 | /** 54 | * A map to store ASN.1 key data with their associated tags. 55 | */ 56 | std::unordered_map> asn1KeyData; 57 | }; 58 | 59 | } // namespace Hiero::internal:asn1 60 | 61 | #endif // HIERO_SDK_CPP_IMPL_ASN1_EC_KEY_H_ 62 | -------------------------------------------------------------------------------- /src/tck/include/account/params/ApproveAllowanceParams.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | #ifndef HIERO_TCK_CPP_APPROVE_ALLOWANCE_PARAMS_H_ 3 | #define HIERO_TCK_CPP_APPROVE_ALLOWANCE_PARAMS_H_ 4 | 5 | #include "account/params/allowance/AllowanceParams.h" 6 | #include "common/CommonTransactionParams.h" 7 | #include "json/JsonUtils.h" 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | namespace Hiero::TCK::AccountService 14 | { 15 | /** 16 | * Struct to hold the arguments for a `approveAllowance` JSON-RPC method call. 17 | */ 18 | struct ApproveAllowanceParams 19 | { 20 | /** 21 | * The allowances to approve. 22 | */ 23 | std::vector mAllowances; 24 | 25 | /** 26 | * Any parameters common to all transaction types. 27 | */ 28 | std::optional mCommonTxParams; 29 | }; 30 | 31 | } // namespace Hiero::TCK::AccountService 32 | 33 | namespace nlohmann 34 | { 35 | /** 36 | * JSON serializer template specialization required to convert ApproveAllowanceParams arguments properly. 37 | */ 38 | template<> 39 | struct [[maybe_unused]] adl_serializer 40 | { 41 | /** 42 | * Convert a JSON object to a ApproveAllowanceParams. 43 | * 44 | * @param jsonFrom The JSON object with which to fill the ApproveAllowanceParams. 45 | * @param params The ApproveAllowanceParams to fill with the JSON object. 46 | */ 47 | static void from_json(const json& jsonFrom, Hiero::TCK::AccountService::ApproveAllowanceParams& params) 48 | { 49 | params.mAllowances = Hiero::TCK::getRequiredJsonParameter>( 50 | jsonFrom, "allowances"); 51 | params.mCommonTxParams = 52 | Hiero::TCK::getOptionalJsonParameter(jsonFrom, "commonTransactionParams"); 53 | } 54 | }; 55 | 56 | } // namespace nlohmann 57 | 58 | #endif // HIERO_TCK_CPP_APPROVE_ALLOWANCE_PARAMS_H_ 59 | -------------------------------------------------------------------------------- /src/sdk/main/src/TokenInfoQuery.cc: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | #include "TokenInfoQuery.h" 3 | #include "TokenInfo.h" 4 | #include "impl/Node.h" 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | namespace Hiero 12 | { 13 | //----- 14 | TokenInfoQuery& TokenInfoQuery::setTokenId(const TokenId& tokenId) 15 | { 16 | mTokenId = tokenId; 17 | return *this; 18 | } 19 | 20 | //----- 21 | TokenInfo TokenInfoQuery::mapResponse(const proto::Response& response) const 22 | { 23 | return TokenInfo::fromProtobuf(response.tokengetinfo().tokeninfo()); 24 | } 25 | 26 | //----- 27 | grpc::Status TokenInfoQuery::submitRequest(const proto::Query& request, 28 | const std::shared_ptr& node, 29 | const std::chrono::system_clock::time_point& deadline, 30 | proto::Response* response) const 31 | { 32 | return node->submitQuery(proto::Query::QueryCase::kTokenGetInfo, request, deadline, response); 33 | } 34 | 35 | //----- 36 | void TokenInfoQuery::validateChecksums(const Client& client) const 37 | { 38 | mTokenId.validateChecksum(client); 39 | } 40 | 41 | //----- 42 | proto::Query TokenInfoQuery::buildRequest(proto::QueryHeader* header) const 43 | { 44 | auto tokenGetInfoQuery = std::make_unique(); 45 | tokenGetInfoQuery->set_allocated_header(header); 46 | tokenGetInfoQuery->set_allocated_token(mTokenId.toProtobuf().release()); 47 | 48 | proto::Query query; 49 | query.set_allocated_tokengetinfo(tokenGetInfoQuery.release()); 50 | return query; 51 | } 52 | 53 | //----- 54 | proto::ResponseHeader TokenInfoQuery::mapResponseHeader(const proto::Response& response) const 55 | { 56 | saveCostFromHeader(response.tokengetinfo().header()); 57 | return response.tokengetinfo().header(); 58 | } 59 | 60 | } // namespace Hiero 61 | -------------------------------------------------------------------------------- /src/sdk/tests/unit/AddressBookQueryUnitTests.cc: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | #include "AddressBookQuery.h" 3 | 4 | #include 5 | 6 | using namespace Hiero; 7 | 8 | class AddressBookQueryUnitTests : public ::testing::Test 9 | { 10 | protected: 11 | [[nodiscard]] inline const FileId& getTestFileId() const { return mTestFileId; } 12 | [[nodiscard]] inline unsigned int getTestLimit() const { return mTestLimit; } 13 | [[nodiscard]] inline unsigned int getTestMaxAttempts() const { return mTestMaxAttempts; } 14 | [[nodiscard]] inline const std::chrono::system_clock::duration& getTestMaxBackoff() const { return mTestMaxBackoff; } 15 | 16 | private: 17 | const FileId mTestFileId = FileId(1ULL, 2ULL, 3ULL); 18 | const unsigned int mTestLimit = 4ULL; 19 | const unsigned int mTestMaxAttempts = 5ULL; 20 | const std::chrono::system_clock::duration mTestMaxBackoff = std::chrono::seconds(6ULL); 21 | }; 22 | 23 | //----- 24 | TEST_F(AddressBookQueryUnitTests, GetSetAccountId) 25 | { 26 | // Given 27 | AddressBookQuery query; 28 | 29 | // When 30 | query.setFileId(getTestFileId()); 31 | 32 | // Then 33 | EXPECT_EQ(query.getFileId(), getTestFileId()); 34 | } 35 | 36 | //----- 37 | TEST_F(AddressBookQueryUnitTests, GetSetLimit) 38 | { 39 | // Given 40 | AddressBookQuery query; 41 | 42 | // When 43 | query.setLimit(getTestLimit()); 44 | 45 | // Then 46 | EXPECT_EQ(query.getLimit(), getTestLimit()); 47 | } 48 | 49 | //----- 50 | TEST_F(AddressBookQueryUnitTests, GetSetMaxAttempts) 51 | { 52 | // Given 53 | AddressBookQuery query; 54 | 55 | // When 56 | query.setMaxAttempts(getTestMaxAttempts()); 57 | 58 | // Then 59 | EXPECT_EQ(query.getMaxAttempts(), getTestMaxAttempts()); 60 | } 61 | 62 | //----- 63 | TEST_F(AddressBookQueryUnitTests, GetSetMaxBackoff) 64 | { 65 | // Given 66 | AddressBookQuery query; 67 | 68 | // When 69 | query.setMaxBackoff(getTestMaxBackoff()); 70 | 71 | // Then 72 | EXPECT_EQ(query.getMaxBackoff(), getTestMaxBackoff()); 73 | } 74 | -------------------------------------------------------------------------------- /src/tck/include/account/params/DeleteAllowanceParams.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | #ifndef HIERO_TCK_CPP_DELETE_ALLOWANCE_PARAMS_H_ 3 | #define HIERO_TCK_CPP_DELETE_ALLOWANCE_PARAMS_H_ 4 | 5 | #include "account/params/allowance/RemoveAllowanceParams.h" 6 | #include "common/CommonTransactionParams.h" 7 | #include "json/JsonUtils.h" 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | namespace Hiero::TCK::AccountService 14 | { 15 | /** 16 | * Struct to hold the arguments for a `deleteAllowance` JSON-RPC method call. 17 | */ 18 | struct DeleteAllowanceParams 19 | { 20 | /** 21 | * The allowances to delete. 22 | */ 23 | std::vector mAllowances; 24 | 25 | /** 26 | * Any parameters common to all transaction types. 27 | */ 28 | std::optional mCommonTxParams; 29 | }; 30 | 31 | } // namespace Hiero::TCK::AccountService 32 | 33 | namespace nlohmann 34 | { 35 | /** 36 | * JSON serializer template specialization required to convert DeleteAllowanceParams arguments properly. 37 | */ 38 | template<> 39 | struct [[maybe_unused]] adl_serializer 40 | { 41 | /** 42 | * Convert a JSON object to a DeleteAllowanceParams. 43 | * 44 | * @param jsonFrom The JSON object with which to fill the DeleteAllowanceParams. 45 | * @param params The DeleteAllowanceParams to fill with the JSON object. 46 | */ 47 | static void from_json(const json& jsonFrom, Hiero::TCK::AccountService::DeleteAllowanceParams& params) 48 | { 49 | params.mAllowances = 50 | Hiero::TCK::getRequiredJsonParameter>( 51 | jsonFrom, "allowances"); 52 | params.mCommonTxParams = 53 | Hiero::TCK::getOptionalJsonParameter(jsonFrom, "commonTransactionParams"); 54 | } 55 | }; 56 | 57 | } // namespace nlohmann 58 | 59 | #endif // HIERO_TCK_CPP_DELETE_ALLOWANCE_PARAMS_H_ 60 | -------------------------------------------------------------------------------- /src/sdk/examples/precompile-example/KeyHelper.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | pragma solidity >=0.5.0 <0.9.0; 3 | pragma experimental ABIEncoderV2; 4 | 5 | // This file was copied from github.com/hashgraph/hedera-smart-contracts on Aug 31 2022 6 | 7 | import "./HederaTokenService.sol"; 8 | 9 | contract KeyHelper is HederaTokenService { 10 | 11 | uint constant INHERIT_ACCOUNT_KEY = 1; 12 | uint constant CONTRACT_ID_KEY = 2; 13 | uint constant ED25519_KEY = 3; 14 | uint constant ECDSA_SECPK2561K1_KEY = 4; 15 | uint constant DELEGATABLE_CONTRACT_ID_KEY = 5; 16 | 17 | function createSingleKey( 18 | uint keyType, 19 | uint keyValueType, 20 | bytes memory key 21 | ) internal view returns (IHederaTokenService.TokenKey memory tokenKey) { 22 | tokenKey = IHederaTokenService.TokenKey(keyType, createKeyValueType(keyValueType, key, address(0))); 23 | } 24 | 25 | function createSingleKey( 26 | uint keyType, 27 | uint keyValueType, 28 | address key 29 | ) internal view returns (IHederaTokenService.TokenKey memory tokenKey) { 30 | tokenKey = IHederaTokenService.TokenKey(keyType, createKeyValueType(keyValueType, "", key)); 31 | } 32 | 33 | function createKeyValueType( 34 | uint keyValueType, 35 | bytes memory key, 36 | address keyAddress 37 | ) internal view returns (IHederaTokenService.KeyValue memory keyValue) { 38 | if (keyValueType == INHERIT_ACCOUNT_KEY) { 39 | keyValue.inheritAccountKey = true; 40 | } else if (keyValueType == CONTRACT_ID_KEY) { 41 | keyValue.contractId = keyAddress; 42 | } else if (keyValueType == ED25519_KEY) { 43 | keyValue.ed25519 = key; 44 | } else if (keyValueType == ECDSA_SECPK2561K1_KEY) { 45 | keyValue.ECDSA_secp256k1 = key; 46 | } else if (keyValueType == DELEGATABLE_CONTRACT_ID_KEY) { 47 | keyValue.delegatableContractId = keyAddress; 48 | } 49 | } 50 | } 51 | --------------------------------------------------------------------------------