Class Query<O,T extends Query<O,T>>
- Type Parameters:
O- The output type of the query.T- The type of the query itself. Used to enable chaining.
- Direct Known Subclasses:
AccountBalanceQuery,AccountInfoQuery,AccountRecordsQuery,ContractByteCodeQuery,ContractCallQuery,ContractInfoQuery,FileContentsQuery,FileInfoQuery,LiveHashQuery,NetworkVersionInfoQuery,ScheduleInfoQuery,TokenInfoQuery,TokenNftInfoQuery,TopicInfoQuery,TransactionReceiptQuery,TransactionRecordQuery
-
Nested Class Summary
Nested classes/interfaces inherited from class com.hedera.hashgraph.sdk.Executable
Executable.GrpcRequest -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected TransactionIdThe transaction IDprotected List<Transaction> List of payment transactionsFields inherited from class com.hedera.hashgraph.sdk.Executable
attemptedAllNodes, blockingUnaryCall, grpcDeadline, logger, maxAttempts, maxBackoff, minBackoff, nodeAccountIds, nodes, random, RST_STREAM -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionFetch the expected cost.Fetch the expected cost.getCostAsync(Client client) Fetch the expected cost asynchronously.getCostAsync(Client client, Duration timeout) Fetch the expected cost asynchronously.voidgetCostAsync(Client client, Duration timeout, BiConsumer<Hbar, Throwable> callback) Fetch the expected cost asynchronously.voidgetCostAsync(Client client, Duration timeout, Consumer<Hbar> onSuccess, Consumer<Throwable> onFailure) Fetch the expected cost asynchronously.voidgetCostAsync(Client client, BiConsumer<Hbar, Throwable> callback) Fetch the expected cost asynchronously.voidFetch the expected cost asynchronously.(package private) Client.OperatorgetOperatorFromClient(Client client) Retrieve the operator from the configured client.(package private) TransactiongetPaymentTransaction(int index) Retrieve the transaction at the given index.Extract the transaction id.(package private) TransactionId(package private) booleanDoes this query require a payment?(package private) final Query(package private) abstract QueryHeadermapRequestHeader(Query request) The derived class should access its request header and return.(package private) abstract ResponseHeadermapResponseHeader(Response response) The derived class should access its response header and return.(package private) StatusmapResponseStatus(Response response) (package private) void(package private) CompletableFuture<Void> onExecuteAsync(Client client) Note: This method requires API level 33 or higher.(package private) abstract voidonMakeRequest(Query.Builder queryBuilder, QueryHeader header) Called inmakeRequest()just before the query is built.setMaxQueryPayment(Hbar maxQueryPayment) Set the maximum payment allowable for this query.setPaymentTransactionId(TransactionId paymentTransactionId) Assign the transaction id.setQueryPayment(Hbar queryPayment) Set an explicit payment amount for this query.toString()(package private) abstract voidvalidateChecksums(Client client) Validate the checksums.Methods inherited from class com.hedera.hashgraph.sdk.Executable
advanceRequest, checkNodeAccountIds, execute, execute, executeAsync, executeAsync, executeAsync, executeAsync, executeAsync, executeAsync, getExecutionState, getGrpcRequest, getMaxAttempts, getMaxBackoff, getMaxRetry, getMethodDescriptor, getMinBackoff, getNodeAccountIds, getNodeForExecute, grpcDeadline, isBatchedAndNotBatchTransaction, logTransaction, mapResponse, mergeFromClient, setGrpcDeadline, setLogger, setMaxAttempts, setMaxBackoff, setMaxRetry, setMinBackoff, setNodeAccountIds, setNodesFromNodeAccountIds, setRequestListener, setResponseListener, shouldRetryExceptionally
-
Field Details
-
paymentTransactionId
The transaction ID -
paymentTransactions
List of payment transactions
-
-
Constructor Details
-
Query
Query()Constructor.
-
-
Method Details
-
setQueryPayment
Set an explicit payment amount for this query.The client will submit exactly this amount for the payment of this query. Hedera will not return any remainder.
- Parameters:
queryPayment- The explicit payment amount to set- Returns:
this
-
setMaxQueryPayment
Set the maximum payment allowable for this query.When a query is executed without an explicit
setQueryPayment(Hbar)call, the client will first request the cost of the given query from the node it will be submitted to and attach a payment for that amount from the operator account on the client.If the returned value is greater than this value, a
MaxQueryPaymentExceededExceptionwill be thrown fromExecutable.execute(Client)or returned in the second callback ofExecutable.executeAsync(Client, Consumer, Consumer).Set to 0 to disable automatic implicit payments.
- Parameters:
maxQueryPayment- The maximum payment amount to set- Returns:
this
-
getCost
Fetch the expected cost.- Parameters:
client- the client- Returns:
- the cost in hbar
- Throws:
TimeoutException- when the transaction times outPrecheckStatusException- when the precheck fails
-
getCost
public Hbar getCost(Client client, Duration timeout) throws TimeoutException, PrecheckStatusException Fetch the expected cost.- Parameters:
client- the clienttimeout- The timeout after which the execution attempt will be cancelled.- Returns:
- the cost in hbar
- Throws:
TimeoutException- when the transaction times outPrecheckStatusException- when the precheck fails
-
getCostAsync
Fetch the expected cost asynchronously.- Parameters:
client- the client- Returns:
- Future result of the cost in hbar
-
getCostAsync
Fetch the expected cost asynchronously.- Parameters:
client- the clienttimeout- The timeout after which the execution attempt will be cancelled.- Returns:
- Future result of the cost in hbar
-
getCostAsync
Fetch the expected cost asynchronously.- Parameters:
client- the clienttimeout- The timeout after which the execution attempt will be cancelled.callback- a BiConsumer which handles the result or error.
-
getCostAsync
Fetch the expected cost asynchronously.- Parameters:
client- the clientcallback- a BiConsumer which handles the result or error.
-
getCostAsync
public void getCostAsync(Client client, Duration timeout, Consumer<Hbar> onSuccess, Consumer<Throwable> onFailure) Fetch the expected cost asynchronously.- Parameters:
client- the clienttimeout- The timeout after which the execution attempt will be cancelled.onSuccess- a Consumer which consumes the result on success.onFailure- a Consumer which consumes the error on failure.
-
getCostAsync
Fetch the expected cost asynchronously.- Parameters:
client- the clientonSuccess- a Consumer which consumes the result on success.onFailure- a Consumer which consumes the error on failure.
-
isPaymentRequired
boolean isPaymentRequired()Does this query require a payment?- Returns:
- does this query require a payment
-
onMakeRequest
Called inmakeRequest()just before the query is built. The intent is for the derived class to assign their data variant to the query. -
mapResponseHeader
The derived class should access its response header and return. -
mapRequestHeader
The derived class should access its request header and return. -
validateChecksums
Validate the checksums.- Throws:
BadEntityIdException
-
getOperatorFromClient
Retrieve the operator from the configured client.- Parameters:
client- the configured client- Returns:
- the operator
-
onExecute
- Specified by:
onExecutein classExecutable<T extends Query<O,T>, Query, Response, O> - Throws:
TimeoutExceptionPrecheckStatusException
-
onExecuteAsync
Note: This method requires API level 33 or higher. It will not work on devices running API versions below 31 because it uses features introduced in API level 31 (Android 12).
*- Specified by:
onExecuteAsyncin classExecutable<T extends Query<O,T>, Query, Response, O>
-
getPaymentTransaction
Retrieve the transaction at the given index.- Parameters:
index- the index- Returns:
- the transaction
-
makeRequest
- Specified by:
makeRequestin classExecutable<T extends Query<O,T>, Query, Response, O>
-
mapResponseStatus
- Specified by:
mapResponseStatusin classExecutable<T extends Query<O,T>, Query, Response, O>
-
getTransactionIdInternal
- Specified by:
getTransactionIdInternalin classExecutable<T extends Query<O,T>, Query, Response, O>
-
getPaymentTransactionId
Extract the transaction id.- Returns:
- the transaction id
-
setPaymentTransactionId
Assign the transaction id.- Parameters:
paymentTransactionId- the transaction id- Returns:
this
-
toString
-