com.hedera.hashgraph.sdk.AccountRecordsQuery Maven / Gradle / Ivy
/*-
*
* Hedera Java SDK
*
* Copyright (C) 2020 - 2023 Hedera Hashgraph, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.hedera.hashgraph.sdk;
import com.hedera.hashgraph.sdk.proto.CryptoGetAccountRecordsQuery;
import com.hedera.hashgraph.sdk.proto.CryptoServiceGrpc;
import com.hedera.hashgraph.sdk.proto.QueryHeader;
import com.hedera.hashgraph.sdk.proto.Response;
import com.hedera.hashgraph.sdk.proto.ResponseHeader;
import io.grpc.MethodDescriptor;
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
/**
* Get all the records for an account for any transfers into it and out of it,
* that were above the threshold, during the last 25 hours.
*/
public final class AccountRecordsQuery extends Query, AccountRecordsQuery> {
@Nullable
private AccountId accountId = null;
/**
* Constructor.
*/
public AccountRecordsQuery() {
}
/**
* Extract the account id.
*
* @return the account id
*/
@Nullable
public AccountId getAccountId() {
return accountId;
}
/**
* Sets the account ID for which the records should be retrieved.
*
* @param accountId The AccountId to be set
* @return {@code this}
*/
public AccountRecordsQuery setAccountId(AccountId accountId) {
Objects.requireNonNull(accountId);
this.accountId = accountId;
return this;
}
@Override
void validateChecksums(Client client) throws BadEntityIdException {
if (accountId != null) {
accountId.validateChecksum(client);
}
}
@Override
void onMakeRequest(com.hedera.hashgraph.sdk.proto.Query.Builder queryBuilder, QueryHeader header) {
var builder = CryptoGetAccountRecordsQuery.newBuilder();
if (accountId != null) {
builder.setAccountID(accountId.toProtobuf());
}
queryBuilder.setCryptoGetAccountRecords(builder.setHeader(header));
}
@Override
ResponseHeader mapResponseHeader(Response response) {
return response.getCryptoGetAccountRecords().getHeader();
}
@Override
QueryHeader mapRequestHeader(com.hedera.hashgraph.sdk.proto.Query request) {
return request.getCryptoGetAccountRecords().getHeader();
}
@Override
List mapResponse(Response response, AccountId nodeId, com.hedera.hashgraph.sdk.proto.Query request) {
var rawTransactionRecords = response.getCryptoGetAccountRecords().getRecordsList();
var transactionRecords = new ArrayList(rawTransactionRecords.size());
for (var record : rawTransactionRecords) {
transactionRecords.add(TransactionRecord.fromProtobuf(record));
}
return transactionRecords;
}
@Override
MethodDescriptor getMethodDescriptor() {
return CryptoServiceGrpc.getGetAccountRecordsMethod();
}
}