Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Finish APIs for Transaction, Query, and a lot of internal classes #503

Merged
merged 9 commits into from
Sep 19, 2023
Merged
4 changes: 4 additions & 0 deletions sdk/examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ set(ACCOUNT_CREATE_WITH_HTS_EXAMPLE_NAME ${PROJECT_NAME}-account-create-with-hts
set(ACCOUNT_CREATION_WAYS_EXAMPLE_NAME ${PROJECT_NAME}-account-creation-ways-example)
set(AUTO_CREATE_ACCOUNT_TRANSFER_TRANSACTION_EXAMPLE_NAME ${PROJECT_NAME}-auto-create-account-transfer-transaction-example)
set(CONSENSUS_PUB_SUB_EXAMPLE_NAME ${PROJECT_NAME}-consensus-pub-sub-example)
set(CONSENSUS_PUB_SUB_CHUNKED_EXAMPLE_NAME ${PROJECT_NAME}-consensus-pub-sub-chunked-example)
set(CREATE_ACCOUNT_EXAMPLE_NAME ${PROJECT_NAME}-create-account-example)
set(CREATE_SIMPLE_CONTRACT_EXAMPLE_NAME ${PROJECT_NAME}-create-simple-contract-example)
set(CREATE_STATEFUL_CONTRACT_EXAMPLE_NAME ${PROJECT_NAME}-create-stateful-contract-example)
Expand Down Expand Up @@ -33,6 +34,7 @@ add_executable(${ACCOUNT_CREATE_WITH_HTS_EXAMPLE_NAME} AccountCreateWithHtsExamp
add_executable(${ACCOUNT_CREATION_WAYS_EXAMPLE_NAME} AccountCreationWaysExample.cc)
add_executable(${AUTO_CREATE_ACCOUNT_TRANSFER_TRANSACTION_EXAMPLE_NAME} AutoCreateAccountTransferTransactionExample.cc)
add_executable(${CONSENSUS_PUB_SUB_EXAMPLE_NAME} ConsensusPubSubExample.cc)
add_executable(${CONSENSUS_PUB_SUB_CHUNKED_EXAMPLE_NAME} ConsensusPubSubChunkedExample.cc)
add_executable(${CREATE_ACCOUNT_EXAMPLE_NAME} CreateAccountExample.cc)
add_executable(${CREATE_SIMPLE_CONTRACT_EXAMPLE_NAME} CreateSimpleContractExample.cc)
add_executable(${CREATE_STATEFUL_CONTRACT_EXAMPLE_NAME} CreateStatefulContractExample.cc)
Expand Down Expand Up @@ -80,6 +82,7 @@ target_link_libraries(${ACCOUNT_CREATE_WITH_HTS_EXAMPLE_NAME} PUBLIC ${PROJECT_N
target_link_libraries(${ACCOUNT_CREATION_WAYS_EXAMPLE_NAME} PUBLIC ${PROJECT_NAME})
target_link_libraries(${AUTO_CREATE_ACCOUNT_TRANSFER_TRANSACTION_EXAMPLE_NAME} PUBLIC ${PROJECT_NAME})
target_link_libraries(${CONSENSUS_PUB_SUB_EXAMPLE_NAME} PUBLIC ${PROJECT_NAME})
target_link_libraries(${CONSENSUS_PUB_SUB_CHUNKED_EXAMPLE_NAME} PUBLIC ${PROJECT_NAME})
target_link_libraries(${CREATE_ACCOUNT_EXAMPLE_NAME} PUBLIC ${PROJECT_NAME})
target_link_libraries(${CREATE_SIMPLE_CONTRACT_EXAMPLE_NAME} PUBLIC ${PROJECT_NAME})
target_link_libraries(${CREATE_STATEFUL_CONTRACT_EXAMPLE_NAME} PUBLIC ${PROJECT_NAME})
Expand Down Expand Up @@ -112,6 +115,7 @@ install(TARGETS
${ACCOUNT_CREATION_WAYS_EXAMPLE_NAME}
${AUTO_CREATE_ACCOUNT_TRANSFER_TRANSACTION_EXAMPLE_NAME}
${CONSENSUS_PUB_SUB_EXAMPLE_NAME}
${CONSENSUS_PUB_SUB_CHUNKED_EXAMPLE_NAME}
${CREATE_ACCOUNT_EXAMPLE_NAME}
${CREATE_SIMPLE_CONTRACT_EXAMPLE_NAME}
${CREATE_STATEFUL_CONTRACT_EXAMPLE_NAME}
Expand Down
279 changes: 279 additions & 0 deletions sdk/examples/ConsensusPubSubChunkedExample.cc

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions sdk/main/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@ add_library(${PROJECT_NAME} STATIC
src/TransferTransaction.cc
src/WrappedTransaction.cc

src/impl/BaseNetwork.cc
src/impl/BaseNode.cc
src/impl/BaseNodeAddress.cc
src/impl/DerivationPathUtils.cc
src/impl/Endpoint.cc
src/impl/DurationConverter.cc
Expand Down
44 changes: 23 additions & 21 deletions sdk/main/include/AccountAllowanceApproveTransaction.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,15 @@ class AccountAllowanceApproveTransaction : public Transaction<AccountAllowanceAp
*/
explicit AccountAllowanceApproveTransaction(const proto::TransactionBody& transactionBody);

/**
* Construct from a map of TransactionIds to node account IDs and their respective Transaction protobuf objects.
*
* @param transactions The map of TransactionIds to node account IDs and their respective Transaction protobuf
* objects.
*/
explicit AccountAllowanceApproveTransaction(
const std::map<TransactionId, std::map<AccountId, proto::Transaction>>& transactions);

/**
* Add an Hbar allowance to this AccountAllowanceApproveTransaction.
*
Expand Down Expand Up @@ -179,33 +188,21 @@ class AccountAllowanceApproveTransaction : public Transaction<AccountAllowanceAp

private:
friend class WrappedTransaction;

/**
* Derived from Executable. Construct a Transaction protobuf object from this AccountAllowanceApproveTransaction
* object.
*
* @param client The Client trying to construct this AccountAllowanceApproveTransaction.
* @param node The Node to which this AccountAllowanceApproveTransaction will be sent. This is unused.
* @return A Transaction protobuf object filled with this AccountAllowanceApproveTransaction object's data.
* @throws UninitializedException If the input client has no operator with which to sign this
* AccountAllowanceApproveTransaction.
*/
[[nodiscard]] proto::Transaction makeRequest(const Client& client,
const std::shared_ptr<internal::Node>& /*node*/) const override;

/**
* Derived from Executable. Submit this AccountAllowanceApproveTransaction to a Node.
* Derived from Executable. Submit a Transaction protobuf object which contains this
* AccountAllowanceApproveTransaction's data to a Node.
*
* @param client The Client submitting this AccountAllowanceApproveTransaction.
* @param deadline The deadline for submitting this AccountAllowanceApproveTransaction.
* @param node Pointer to the Node to which this AccountAllowanceApproveTransaction should be submitted.
* @param response Pointer to the TransactionResponse protobuf object that gRPC should populate with the response
* information from the gRPC server.
* @param request The Transaction protobuf object to submit.
* @param node The Node to which to submit the request.
* @param deadline The deadline for submitting the request.
* @param response Pointer to the ProtoResponseType object that gRPC should populate with the response information
* from the gRPC server.
* @return The gRPC status of the submission.
*/
[[nodiscard]] grpc::Status submitRequest(const Client& client,
const std::chrono::system_clock::time_point& deadline,
[[nodiscard]] grpc::Status submitRequest(const proto::Transaction& request,
const std::shared_ptr<internal::Node>& node,
const std::chrono::system_clock::time_point& deadline,
proto::TransactionResponse* response) const override;
/**
* Derived from Transaction. Build and add the AccountAllowanceApproveTransaction protobuf representation to the
Expand All @@ -215,6 +212,11 @@ class AccountAllowanceApproveTransaction : public Transaction<AccountAllowanceAp
*/
void addToBody(proto::TransactionBody& body) const override;

/**
* Initialize this AccountAllowanceApproveTransaction from its source TransactionBody protobuf object.
*/
void initFromSourceTransactionBody();

/**
* Build a CryptoApproveAllowanceTransactionBody protobuf object from this AccountAllowanceApproveTransaction object.
*
Expand Down
47 changes: 26 additions & 21 deletions sdk/main/include/AccountAllowanceDeleteTransaction.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
#include "TokenNftAllowance.h"
#include "Transaction.h"

#include <vector>

namespace proto
{
class CryptoDeleteAllowanceTransactionBody;
Expand All @@ -31,6 +33,7 @@ class TransactionBody;

namespace Hedera
{
class AccountId;
class NftId;
}

Expand All @@ -55,6 +58,15 @@ class AccountAllowanceDeleteTransaction : public Transaction<AccountAllowanceDel
*/
explicit AccountAllowanceDeleteTransaction(const proto::TransactionBody& transactionBody);

/**
* Construct from a map of TransactionIds to node account IDs and their respective Transaction protobuf objects.
*
* @param transactions The map of TransactionIds to node account IDs and their respective Transaction protobuf
* objects.
*/
explicit AccountAllowanceDeleteTransaction(
const std::map<TransactionId, std::map<AccountId, proto::Transaction>>& transactions);

/**
* Remove all NFT allowances from an account.
*
Expand All @@ -77,33 +89,21 @@ class AccountAllowanceDeleteTransaction : public Transaction<AccountAllowanceDel

private:
friend class WrappedTransaction;

/**
* Derived from Executable. Construct a Transaction protobuf object from this AccountAllowanceDeleteTransaction
* object.
*
* @param client The Client trying to construct this AccountAllowanceDeleteTransaction.
* @param node The Node to which this AccountAllowanceDeleteTransaction will be sent. This is unused.
* @return A Transaction protobuf object filled with this AccountAllowanceDeleteTransaction object's data.
* @throws UninitializedException If the input client has no operator with which to sign this
* AccountAllowanceApproveTransaction.
*/
[[nodiscard]] proto::Transaction makeRequest(const Client& client,
const std::shared_ptr<internal::Node>& /*node*/) const override;

/**
* Derived from Executable. Submit this AccountAllowanceDeleteTransaction to a Node.
* Derived from Executable. Submit a Transaction protobuf object which contains this
* AccountAllowanceDeleteTransaction's data to a Node.
*
* @param client The Client submitting this AccountAllowanceDeleteTransaction.
* @param deadline The deadline for submitting this AccountAllowanceDeleteTransaction.
* @param node Pointer to the Node to which this AccountAllowanceDeleteTransaction should be submitted.
* @param response Pointer to the TransactionResponse protobuf object that gRPC should populate with the response
* information from the gRPC server.
* @param request The Transaction protobuf object to submit.
* @param node The Node to which to submit the request.
* @param deadline The deadline for submitting the request.
* @param response Pointer to the ProtoResponseType object that gRPC should populate with the response information
* from the gRPC server.
* @return The gRPC status of the submission.
*/
[[nodiscard]] grpc::Status submitRequest(const Client& client,
const std::chrono::system_clock::time_point& deadline,
[[nodiscard]] grpc::Status submitRequest(const proto::Transaction& request,
const std::shared_ptr<internal::Node>& node,
const std::chrono::system_clock::time_point& deadline,
proto::TransactionResponse* response) const override;
/**
* Derived from Transaction. Build and add the AccountAllowanceDeleteTransaction protobuf representation to the
Expand All @@ -113,6 +113,11 @@ class AccountAllowanceDeleteTransaction : public Transaction<AccountAllowanceDel
*/
void addToBody(proto::TransactionBody& body) const override;

/**
* Initialize this AccountAllowanceDeleteTransaction from its source TransactionBody protobuf object.
*/
void initFromSourceTransactionBody();

/**
* Build a CryptoDeleteAllowanceTransactionBody protobuf object from this AccountAllowanceDeleteTransaction object.
*
Expand Down
56 changes: 30 additions & 26 deletions sdk/main/include/AccountBalanceQuery.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,16 +77,6 @@ class AccountBalanceQuery : public Query<AccountBalanceQuery, AccountBalance>
[[nodiscard]] inline std::optional<ContractId> getContractId() { return mContractId; }

private:
/**
* Derived from Executable. Construct a Query protobuf object from this AccountBalanceQuery object.
*
* @param client The Client trying to construct this AccountBalanceQuery. This is unused.
* @param node The Node to which this AccountBalanceQuery will be sent. This is unused.
* @return A Query protobuf object filled with this AccountBalanceQuery object's data.
*/
[[nodiscard]] proto::Query makeRequest(const Client& /*client*/,
const std::shared_ptr<internal::Node>& /*node*/) const override;

/**
* Derived from Executable. Construct an AccountBalance object from a Response protobuf object.
*
Expand All @@ -96,28 +86,42 @@ class AccountBalanceQuery : public Query<AccountBalanceQuery, AccountBalance>
[[nodiscard]] AccountBalance mapResponse(const proto::Response& response) const override;

/**
* Derived from Executable. Get the status response code for a submitted AccountBalanceQuery from a Response protobuf
* object.
* Derived from Executable. Submit a Query protobuf object which contains this AccountBalanceQuery's data to a Node.
*
* @param response The Response protobuf object from which to grab the AccountBalanceQuery status response code.
* @return The AccountBalanceQuery status response code of the input Response protobuf object.
*/
[[nodiscard]] Status mapResponseStatus(const proto::Response& response) const override;

/**
* Derived from Executable. Submit this AccountBalanceQuery to a Node.
*
* @param client The Client submitting this AccountBalanceQuery.
* @param deadline The deadline for submitting this AccountBalanceQuery.
* @param node Pointer to the Node to which this AccountBalanceQuery should be submitted.
* @param response Pointer to the Response protobuf object that gRPC should populate with the response information
* @param request The Query protobuf object to submit.
* @param node The Node to which to submit the request.
* @param deadline The deadline for submitting the request.
* @param response Pointer to the ProtoResponseType object that gRPC should populate with the response information
* from the gRPC server.
* @return The gRPC status of the submission.
*/
[[nodiscard]] grpc::Status submitRequest(const Client& client,
const std::chrono::system_clock::time_point& deadline,
[[nodiscard]] grpc::Status submitRequest(const proto::Query& request,
const std::shared_ptr<internal::Node>& node,
const std::chrono::system_clock::time_point& deadline,
proto::Response* response) const override;
/**
* Derived from Query. Build a Query protobuf object with this AccountBalanceQuery's data, with the input QueryHeader
* protobuf object.
*
* @param header A pointer to the QueryHeader protobuf object to add to the Query protobuf object.
* @return The constructed Query protobuf object.
*/
[[nodiscard]] proto::Query buildRequest(proto::QueryHeader* header) const override;

/**
* Derived from Query. Get the ResponseHeader protobuf object from the input Response protobuf object.
*
* @param response The Response protobuf object from which to get the ResponseHeader protobuf object.
* @return The ResponseHeader protobuf object of the input Response protobuf object for this derived Query.
*/
[[nodiscard]] proto::ResponseHeader mapResponseHeader(const proto::Response& response) const override;

/**
* Derived from Query. Does this AccountBalanceQuery require payment?
*
* @return \c FALSE, AccountBalanceQuery is free.
*/
[[nodiscard]] inline bool isPaymentRequired() const override { return false; }

/**
* The ID of the account of which this query should get the balance.
Expand Down
43 changes: 23 additions & 20 deletions sdk/main/include/AccountCreateTransaction.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,15 @@ class AccountCreateTransaction : public Transaction<AccountCreateTransaction>
*/
explicit AccountCreateTransaction(const proto::TransactionBody& transactionBody);

/**
* Construct from a map of TransactionIds to node account IDs and their respective Transaction protobuf objects.
*
* @param transactions The map of TransactionIds to node account IDs and their respective Transaction protobuf
* objects.
*/
explicit AccountCreateTransaction(
const std::map<TransactionId, std::map<AccountId, proto::Transaction>>& transactions);

/**
* Set the key for the new account. The key that must sign each transfer out of the account. If
* mReceiverSignatureRequired is true, then it must also sign any transfer into the account.
Expand Down Expand Up @@ -259,30 +268,19 @@ class AccountCreateTransaction : public Transaction<AccountCreateTransaction>
friend class WrappedTransaction;

/**
* Derived from Executable. Construct a Transaction protobuf object from this AccountCreateTransaction object.
* Derived from Executable. Submit a Transaction protobuf object which contains this AccountCreateTransaction's data
* to a Node.
*
* @param client The Client trying to construct this AccountCreateTransaction.
* @param node The Node to which this AccountCreateTransaction will be sent. This is unused.
* @return A Transaction protobuf object filled with this AccountCreateTransaction object's data.
* @throws UninitializedException If the input client has no operator with which to sign this
* AccountAllowanceApproveTransaction.
*/
[[nodiscard]] proto::Transaction makeRequest(const Client& client,
const std::shared_ptr<internal::Node>& /*node*/) const override;

/**
* Derived from Executable. Submit this AccountCreateTransaction to a Node.
*
* @param client The Client submitting this AccountCreateTransaction.
* @param deadline The deadline for submitting this AccountCreateTransaction.
* @param node Pointer to the Node to which this AccountCreateTransaction should be submitted.
* @param response Pointer to the TransactionResponse protobuf object that gRPC should populate with the response
* information from the gRPC server.
* @param request The Transaction protobuf object to submit.
* @param node The Node to which to submit the request.
* @param deadline The deadline for submitting the request.
* @param response Pointer to the ProtoResponseType object that gRPC should populate with the response information
* from the gRPC server.
* @return The gRPC status of the submission.
*/
[[nodiscard]] grpc::Status submitRequest(const Client& client,
const std::chrono::system_clock::time_point& deadline,
[[nodiscard]] grpc::Status submitRequest(const proto::Transaction& request,
const std::shared_ptr<internal::Node>& node,
const std::chrono::system_clock::time_point& deadline,
proto::TransactionResponse* response) const override;
/**
* Derived from Transaction. Build and add the AccountCreateTransaction protobuf representation to the Transaction
Expand All @@ -292,6 +290,11 @@ class AccountCreateTransaction : public Transaction<AccountCreateTransaction>
*/
void addToBody(proto::TransactionBody& body) const override;

/**
* Initialize this AccountCreateTransaction from its source TransactionBody protobuf object.
*/
void initFromSourceTransactionBody();

/**
* Build a CryptoCreateTransactionBody protobuf object from this AccountCreateTransaction object.
*
Expand Down
Loading
Loading