diff --git a/examples/build.gradle b/examples/build.gradle index d58d7369a..1fcc3e5e8 100644 --- a/examples/build.gradle +++ b/examples/build.gradle @@ -15,6 +15,7 @@ task runAllExamples { .filter { it.name.endsWith('Example.java') } .map { it.name.replaceAll('\\.java$', '') } .filter { !it.equals('ValidateChecksumExample') } // disabled this example, because it needs user input (but it WORKS) + .filter { !it.equals('ZeroTokenOperationsExample') } // doesn't work with hedera-local-node .filter { !it.equals('SolidityPrecompileExample') } // doesn't work with hedera-local-node .filter { !it.equals('ConsensusPubSubChunkedExample') } // doesn't work on CI .toList() diff --git a/examples/src/main/java/ContractHelper.java b/examples/src/main/java/ContractHelper.java index 4592625f2..af8a31eae 100644 --- a/examples/src/main/java/ContractHelper.java +++ b/examples/src/main/java/ContractHelper.java @@ -187,22 +187,18 @@ public ContractHelper executeSteps( .setValidateStatus(false) .getRecord(client); - try { - if (record.receipt.status != Status.SUCCESS) { - throw new Exception("transaction receipt yielded unsuccessful response code " + record.receipt.status); - } - ContractFunctionResult functionResult = Objects.requireNonNull(record.contractFunctionResult); - System.out.println("gas used: " + functionResult.gasUsed); - if (getResultValidator(stepIndex).apply(functionResult)) { - System.out.println("step " + stepIndex + " completed, and returned valid result. (TransactionId \"" + record.transactionId + "\")"); - } else { - throw new Exception("returned invalid result"); - } - } catch (Throwable error) { - System.out.println("Error occurred in step " + stepIndex + ": " + error.getMessage()); - System.out.println("Transaction record: " + record); - break; + if (record.receipt.status != Status.SUCCESS) { + throw new Exception("transaction receipt yielded unsuccessful response code " + record.receipt.status); } + ContractFunctionResult functionResult = Objects.requireNonNull(record.contractFunctionResult); + System.out.println("gas used: " + functionResult.gasUsed); + if (getResultValidator(stepIndex).apply(functionResult)) { + System.out.println("step " + stepIndex + " completed, and returned valid result. (TransactionId \"" + record.transactionId + "\")"); + } else { + throw new Exception("returned invalid result"); + } + + break; } return this; } diff --git a/examples/src/main/java/ContractNoncesExample.java b/examples/src/main/java/ContractNoncesExample.java index 19a00e102..f260fce9a 100644 --- a/examples/src/main/java/ContractNoncesExample.java +++ b/examples/src/main/java/ContractNoncesExample.java @@ -54,7 +54,7 @@ private ContractNoncesExample() { } public static void main(String[] args) - throws TimeoutException, PrecheckStatusException, ReceiptStatusException, InterruptedException { + throws Exception { Client client = ClientHelper.forName(HEDERA_NETWORK); // Defaults the operator account ID and key such that all generated transactions will be paid for @@ -90,8 +90,7 @@ public static void main(String[] args) .getReceipt(client); if (contractDeleteResult.status != Status.SUCCESS) { - System.out.println("error deleting contract: " + contractDeleteResult.status); - return; + throw new Exception("error deleting contract: " + contractDeleteResult.status); } System.out.println("Contract successfully deleted"); } diff --git a/examples/src/main/java/CreateAccountWithAliasExample.java b/examples/src/main/java/CreateAccountWithAliasExample.java index af7f3fb8e..e4e49def1 100644 --- a/examples/src/main/java/CreateAccountWithAliasExample.java +++ b/examples/src/main/java/CreateAccountWithAliasExample.java @@ -24,7 +24,7 @@ private CreateAccountWithAliasExample() { - Sign the `AccountCreateTransaction` transaction with the new private key - Get the `AccountInfo` and show that the account has contractAccountId */ - public static void main(String[] args) throws PrecheckStatusException, TimeoutException, InterruptedException { + public static void main(String[] args) throws Exception { Client client = ClientHelper.forName(HEDERA_NETWORK); // Defaults the operator account ID and key such that all generated transactions will be paid for @@ -85,7 +85,7 @@ public static void main(String[] args) throws PrecheckStatusException, TimeoutEx if (accountInfo.contractAccountId != null) { System.out.println("The new account has alias " + accountInfo.contractAccountId); } else { - System.out.println("The new account doesn't have alias"); + throw new Exception("The new account doesn't have alias"); } } } diff --git a/examples/src/main/java/CreateSimpleContractExample.java b/examples/src/main/java/CreateSimpleContractExample.java index 81ab1a144..d0d2a0b5b 100644 --- a/examples/src/main/java/CreateSimpleContractExample.java +++ b/examples/src/main/java/CreateSimpleContractExample.java @@ -57,7 +57,7 @@ private CreateSimpleContractExample() { } public static void main(String[] args) - throws PrecheckStatusException, IOException, TimeoutException, ReceiptStatusException, InterruptedException { + throws Exception { String byteCodeHex = ContractHelper.getBytecodeHex("hello_world.json"); Client client = ClientHelper.forName(HEDERA_NETWORK); @@ -122,8 +122,7 @@ public static void main(String[] args) .getReceipt(client); if (contractDeleteResult.status != Status.SUCCESS) { - System.out.println("error deleting contract: " + contractDeleteResult.status); - return; + throw new Exception("error deleting contract: " + contractDeleteResult.status); } System.out.println("Contract successfully deleted"); } diff --git a/examples/src/main/java/CreateStatefulContractExample.java b/examples/src/main/java/CreateStatefulContractExample.java index 5272bc5a5..72cdcd0a8 100644 --- a/examples/src/main/java/CreateStatefulContractExample.java +++ b/examples/src/main/java/CreateStatefulContractExample.java @@ -57,7 +57,7 @@ private CreateStatefulContractExample() { } public static void main(String[] args) - throws PrecheckStatusException, TimeoutException, IOException, ReceiptStatusException, InterruptedException { + throws Exception { String byteCodeHex = ContractHelper.getBytecodeHex("stateful.json"); Client client = ClientHelper.forName(HEDERA_NETWORK); @@ -105,8 +105,7 @@ public static void main(String[] args) .execute(client); if (contractCallResult.errorMessage != null) { - System.out.println("error calling contract: " + contractCallResult.errorMessage); - return; + throw new Exception("error calling contract: " + contractCallResult.errorMessage); } String message = contractCallResult.getString(0); @@ -132,8 +131,7 @@ public static void main(String[] args) .execute(client); if (contractUpdateResult.errorMessage != null) { - System.out.println("error calling contract: " + contractUpdateResult.errorMessage); - return; + throw new Exception("error calling contract: " + contractUpdateResult.errorMessage); } String message2 = contractUpdateResult.getString(0); diff --git a/examples/src/main/java/ScheduleIdenticalTransactionExample.java b/examples/src/main/java/ScheduleIdenticalTransactionExample.java index 5dee05d1b..537aa98d7 100644 --- a/examples/src/main/java/ScheduleIdenticalTransactionExample.java +++ b/examples/src/main/java/ScheduleIdenticalTransactionExample.java @@ -56,7 +56,7 @@ private ScheduleIdenticalTransactionExample() { } public static void main(String[] args) - throws PrecheckStatusException, TimeoutException, ReceiptStatusException, InterruptedException { + throws Exception { Client client = ClientHelper.forName(HEDERA_NETWORK); // Defaults the operator account ID and key such that all generated transactions will be paid for @@ -151,8 +151,7 @@ public static void main(String[] args) } if (!scheduleID.equals(Objects.requireNonNull(loopReceipt.scheduleId))) { - System.out.println("invalid generated schedule id, expected " + scheduleID + ", got " + loopReceipt.scheduleId); - return; + throw new Exception("invalid generated schedule id, expected " + scheduleID + ", got " + loopReceipt.scheduleId); } // If the status return by the receipt is related to already created, execute a schedule sign transaction @@ -167,8 +166,7 @@ public static void main(String[] args) .setTransactionId(signTransaction.transactionId) .execute(client); if (signReceipt.status != Status.SUCCESS && signReceipt.status != Status.SCHEDULE_ALREADY_EXECUTED) { - System.out.println("Bad status while getting receipt of schedule sign with operator " + operatorId + ": " + signReceipt.status); - return; + throw new Exception("Bad status while getting receipt of schedule sign with operator " + operatorId + ": " + signReceipt.status); } } } diff --git a/examples/src/main/java/ScheduledTransferExample.java b/examples/src/main/java/ScheduledTransferExample.java index 0386fb629..645501db5 100644 --- a/examples/src/main/java/ScheduledTransferExample.java +++ b/examples/src/main/java/ScheduledTransferExample.java @@ -52,7 +52,7 @@ private ScheduledTransferExample() { } public static void main(String[] args) - throws TimeoutException, PrecheckStatusException, ReceiptStatusException, InterruptedException { + throws Exception { Client client = ClientHelper.forName(HEDERA_NETWORK); // Defaults the operator account ID and key such that all generated transactions will be paid for @@ -169,9 +169,7 @@ public static void main(String[] args) System.out.println("The scheduled transfer transaction from Bob's POV:"); System.out.println(scheduledTransfer); } else { - System.out.println("The scheduled transaction was not a transfer transaction."); - System.out.println("Something has gone horribly wrong. Crashing..."); - System.exit(-1); + throw new Exception("The scheduled transaction was not a transfer transaction."); } new ScheduleSignTransaction()