Skip to content

Commit

Permalink
chore: format Java code
Browse files Browse the repository at this point in the history
Signed-off-by: Jendrik Johannes <[email protected]>
  • Loading branch information
jjohannes committed Oct 11, 2024
1 parent b65ebce commit 3da628a
Show file tree
Hide file tree
Showing 164 changed files with 8,998 additions and 8,212 deletions.
4 changes: 1 addition & 3 deletions examples/src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,9 @@
*/

module com.hedera.hashgraph.examples {
requires com.hedera.hashgraph.sdk;
// requires com.hedera.hashgraph.sdk.full;

requires com.google.gson;
requires com.hedera.hashgraph.sdk;
requires io.github.cdimascio.dotenv.java;

requires static java.annotation;
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
/*-
*
* Hedera Java SDK
*
* Copyright (C) 2020 - 2024 Hedera Hashgraph, LLC
/*
* Copyright (C) 2020-2024 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.
Expand All @@ -15,8 +12,8 @@
* 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.google.protobuf.ByteString;
Expand All @@ -28,19 +25,20 @@
import com.hedera.hashgraph.sdk.proto.TransactionResponse;
import io.grpc.MethodDescriptor;
import java.time.Duration;

import javax.annotation.Nullable;
import java.util.LinkedHashMap;
import java.util.Objects;
import javax.annotation.Nullable;

/**
* Create a new Hedera™ account.
*/
public final class AccountCreateTransaction extends Transaction<AccountCreateTransaction> {
@Nullable
private AccountId proxyAccountId = null;

@Nullable
private Key key = null;

private String accountMemo = "";
private Hbar initialBalance = new Hbar(0);
private boolean receiverSigRequired = false;
Expand Down Expand Up @@ -71,7 +69,9 @@ public AccountCreateTransaction() {
* @param txs Compound list of transaction id's list of (AccountId, Transaction) records
* @throws InvalidProtocolBufferException when there is an issue with the protobuf
*/
AccountCreateTransaction(LinkedHashMap<TransactionId, LinkedHashMap<AccountId, com.hedera.hashgraph.sdk.proto.Transaction>> txs) throws InvalidProtocolBufferException {
AccountCreateTransaction(
LinkedHashMap<TransactionId, LinkedHashMap<AccountId, com.hedera.hashgraph.sdk.proto.Transaction>> txs)
throws InvalidProtocolBufferException {
super(txs);
initFromTransactionBody();
}
Expand Down Expand Up @@ -392,12 +392,12 @@ public AccountCreateTransaction setAlias(String aliasEvmAddress) {
*/
CryptoCreateTransactionBody.Builder build() {
var builder = CryptoCreateTransactionBody.newBuilder()
.setInitialBalance(initialBalance.toTinybars())
.setReceiverSigRequired(receiverSigRequired)
.setAutoRenewPeriod(DurationConverter.toProtobuf(autoRenewPeriod))
.setMemo(accountMemo)
.setMaxAutomaticTokenAssociations(maxAutomaticTokenAssociations)
.setDeclineReward(declineStakingReward);
.setInitialBalance(initialBalance.toTinybars())
.setReceiverSigRequired(receiverSigRequired)
.setAutoRenewPeriod(DurationConverter.toProtobuf(autoRenewPeriod))
.setMemo(accountMemo)
.setMaxAutomaticTokenAssociations(maxAutomaticTokenAssociations)
.setDeclineReward(declineStakingReward);

if (proxyAccountId != null) {
builder.setProxyAccountID(proxyAccountId.toProtobuf());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
/*-
*
* Hedera Java SDK
*
* Copyright (C) 2020 - 2024 Hedera Hashgraph, LLC
/*
* Copyright (C) 2020-2024 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.
Expand All @@ -15,8 +12,8 @@
* 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.google.protobuf.BoolValue;
Expand All @@ -31,10 +28,9 @@
import io.grpc.MethodDescriptor;
import java.time.Duration;
import java.time.Instant;

import javax.annotation.Nullable;
import java.util.LinkedHashMap;
import java.util.Objects;
import javax.annotation.Nullable;

/**
* Change properties for the given account.
Expand All @@ -55,20 +51,28 @@
public final class AccountUpdateTransaction extends Transaction<AccountUpdateTransaction> {
@Nullable
private AccountId accountId = null;

@Nullable
private AccountId proxyAccountId = null;

@Nullable
private Key key = null;

@Nullable
private Instant expirationTime = null;

@Nullable
private Duration autoRenewPeriod = null;

@Nullable
private Boolean receiverSigRequired = null;

@Nullable
private String accountMemo = null;

@Nullable
private Integer maxAutomaticTokenAssociations = null;

@Nullable
private Key aliasKey;

Expand All @@ -84,16 +88,17 @@ public final class AccountUpdateTransaction extends Transaction<AccountUpdateTra
/**
* Constructor.
*/
public AccountUpdateTransaction() {
}
public AccountUpdateTransaction() {}

/**
* Constructor.
*
* @param txs Compound list of transaction id's list of (AccountId, Transaction) records
* @throws InvalidProtocolBufferException when there is an issue with the protobuf
*/
AccountUpdateTransaction(LinkedHashMap<TransactionId, LinkedHashMap<AccountId, com.hedera.hashgraph.sdk.proto.Transaction>> txs) throws InvalidProtocolBufferException {
AccountUpdateTransaction(
LinkedHashMap<TransactionId, LinkedHashMap<AccountId, com.hedera.hashgraph.sdk.proto.Transaction>> txs)
throws InvalidProtocolBufferException {
super(txs);
initFromTransactionBody();
}
Expand Down Expand Up @@ -485,7 +490,8 @@ void initFromTransactionBody() {
accountMemo = body.getMemo().getValue();
}
if (body.hasMaxAutomaticTokenAssociations()) {
maxAutomaticTokenAssociations = body.getMaxAutomaticTokenAssociations().getValue();
maxAutomaticTokenAssociations =
body.getMaxAutomaticTokenAssociations().getValue();
}

if (body.hasDeclineReward()) {
Expand Down Expand Up @@ -545,7 +551,8 @@ CryptoUpdateTransactionBody.Builder build() {
}

if (declineStakingReward != null) {
builder.setDeclineReward(BoolValue.newBuilder().setValue(declineStakingReward).build());
builder.setDeclineReward(
BoolValue.newBuilder().setValue(declineStakingReward).build());
}

return builder;
Expand Down
93 changes: 47 additions & 46 deletions sdk/src/main/java/com/hedera/hashgraph/sdk/AddressBookQuery.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
/*-
*
* Hedera Java SDK
*
* Copyright (C) 2020 - 2024 Hedera Hashgraph, LLC
/*
* Copyright (C) 2020-2024 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.
Expand All @@ -15,8 +12,8 @@
* 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.mirror.NetworkServiceGrpc;
Expand Down Expand Up @@ -46,26 +43,28 @@ public class AddressBookQuery {

@Nullable
private FileId fileId = null;

@Nullable
private Integer limit = null;

private int maxAttempts = 10;
private Duration maxBackoff = Duration.ofSeconds(8L);

/**
* Constructor.
*/
public AddressBookQuery() {
}
public AddressBookQuery() {}

private static boolean shouldRetry(Throwable throwable) {
if (throwable instanceof StatusRuntimeException statusRuntimeException) {
var code = statusRuntimeException.getStatus().getCode();
var description = statusRuntimeException.getStatus().getDescription();

return (code == io.grpc.Status.Code.UNAVAILABLE) ||
(code == io.grpc.Status.Code.RESOURCE_EXHAUSTED) ||
(code == Status.Code.INTERNAL && description != null && Executable.RST_STREAM.matcher(description)
.matches());
return (code == io.grpc.Status.Code.UNAVAILABLE)
|| (code == io.grpc.Status.Code.RESOURCE_EXHAUSTED)
|| (code == Status.Code.INTERNAL
&& description != null
&& Executable.RST_STREAM.matcher(description).matches());
}

return false;
Expand Down Expand Up @@ -169,10 +168,8 @@ public NodeAddressBook execute(Client client, Duration timeout) {
var deadline = Deadline.after(timeout.toMillis(), TimeUnit.MILLISECONDS);
for (int attempt = 1; true; attempt++) {
try {
var addressProtoIter = ClientCalls.blockingServerStreamingCall(
buildCall(client, deadline),
buildQuery()
);
var addressProtoIter =
ClientCalls.blockingServerStreamingCall(buildCall(client, deadline), buildQuery());
List<NodeAddress> addresses = new ArrayList<>();
while (addressProtoIter.hasNext()) {
addresses.add(NodeAddress.fromProtobuf(addressProtoIter.next()));
Expand Down Expand Up @@ -223,31 +220,31 @@ public CompletableFuture<NodeAddressBook> executeAsync(Client client, Duration t
void executeAsync(Client client, Deadline deadline, CompletableFuture<NodeAddressBook> returnFuture, int attempt) {
List<NodeAddress> addresses = new ArrayList<>();
ClientCalls.asyncServerStreamingCall(
buildCall(client, deadline),
buildQuery(),
new StreamObserver<com.hedera.hashgraph.sdk.proto.NodeAddress>() {
@Override
public void onNext(com.hedera.hashgraph.sdk.proto.NodeAddress addressProto) {
addresses.add(NodeAddress.fromProtobuf(addressProto));
}
buildCall(client, deadline),
buildQuery(),
new StreamObserver<com.hedera.hashgraph.sdk.proto.NodeAddress>() {
@Override
public void onNext(com.hedera.hashgraph.sdk.proto.NodeAddress addressProto) {
addresses.add(NodeAddress.fromProtobuf(addressProto));
}

@Override
public void onError(Throwable error) {
if (attempt >= maxAttempts || !shouldRetry(error)) {
LOGGER.error("Error attempting to get address book at FileId {}", fileId, error);
returnFuture.completeExceptionally(error);
return;
@Override
public void onError(Throwable error) {
if (attempt >= maxAttempts || !shouldRetry(error)) {
LOGGER.error("Error attempting to get address book at FileId {}", fileId, error);
returnFuture.completeExceptionally(error);
return;
}
warnAndDelay(attempt, error);
addresses.clear();
executeAsync(client, deadline, returnFuture, attempt + 1);
}
warnAndDelay(attempt, error);
addresses.clear();
executeAsync(client, deadline, returnFuture, attempt + 1);
}

@Override
public void onCompleted() {
returnFuture.complete(new NodeAddressBook().setNodeAddresses(addresses));
}
});
@Override
public void onCompleted() {
returnFuture.complete(new NodeAddressBook().setNodeAddresses(addresses));
}
});
}

/**
Expand All @@ -266,13 +263,14 @@ com.hedera.hashgraph.sdk.proto.mirror.AddressBookQuery buildQuery() {
return builder.build();
}

private ClientCall<com.hedera.hashgraph.sdk.proto.mirror.AddressBookQuery, com.hedera.hashgraph.sdk.proto.NodeAddress>
buildCall(Client client, Deadline deadline) {
private ClientCall<
com.hedera.hashgraph.sdk.proto.mirror.AddressBookQuery, com.hedera.hashgraph.sdk.proto.NodeAddress>
buildCall(Client client, Deadline deadline) {
try {
return client.mirrorNetwork.getNextMirrorNode().getChannel().newCall(
NetworkServiceGrpc.getGetNodesMethod(),
CallOptions.DEFAULT.withDeadline(deadline)
);
return client.mirrorNetwork
.getNextMirrorNode()
.getChannel()
.newCall(NetworkServiceGrpc.getGetNodesMethod(), CallOptions.DEFAULT.withDeadline(deadline));
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
Expand All @@ -281,8 +279,11 @@ com.hedera.hashgraph.sdk.proto.mirror.AddressBookQuery buildQuery() {
private void warnAndDelay(int attempt, Throwable error) {
var delay = Math.min(500 * (long) Math.pow(2, attempt), maxBackoff.toMillis());
LOGGER.warn(
"Error fetching address book at FileId {} during attempt #{}. Waiting {} ms before next attempt: {}",
fileId, attempt, delay, error.getMessage());
"Error fetching address book at FileId {} during attempt #{}. Waiting {} ms before next attempt: {}",
fileId,
attempt,
delay,
error.getMessage());

try {
Thread.sleep(delay);
Expand Down
Loading

0 comments on commit 3da628a

Please sign in to comment.