diff --git a/lightwallet-client-lib/src/main/java/co/electriccoin/lightwallet/client/internal/BlockingLightWalletClientImpl.kt b/lightwallet-client-lib/src/main/java/co/electriccoin/lightwallet/client/internal/BlockingLightWalletClientImpl.kt index bc20a10e..c1814ec5 100644 --- a/lightwallet-client-lib/src/main/java/co/electriccoin/lightwallet/client/internal/BlockingLightWalletClientImpl.kt +++ b/lightwallet-client-lib/src/main/java/co/electriccoin/lightwallet/client/internal/BlockingLightWalletClientImpl.kt @@ -82,8 +82,9 @@ internal class BlockingLightWalletClientImpl private constructor( } override fun submitTransaction(spendTransaction: ByteArray): Response { - if (spendTransaction.isEmpty()) { - return Response.Failure.Client.SubmitEmptyTransaction() + require(spendTransaction.isNotEmpty()) { + "${Constants.ILLEGAL_ARGUMENT_EXCEPTION_MESSAGE} Failed to submit transaction because it was empty, so " + + "this request was ignored on the client-side." // NON-NLS } return try { val request = @@ -100,8 +101,9 @@ internal class BlockingLightWalletClientImpl private constructor( } override fun fetchTransaction(txId: ByteArray): Response { - if (txId.isEmpty()) { - return Response.Failure.Client.NullIdTransaction() + require(txId.isNotEmpty()) { + "${Constants.ILLEGAL_ARGUMENT_EXCEPTION_MESSAGE} Failed to start fetching the transaction with null " + + "transaction ID, so this request was ignored on the client-side." // NON-NLS } return try { val request = Service.TxFilter.newBuilder().setHash(ByteString.copyFrom(txId)).build() diff --git a/lightwallet-client-lib/src/main/java/co/electriccoin/lightwallet/client/internal/CoroutineLightWalletClientImpl.kt b/lightwallet-client-lib/src/main/java/co/electriccoin/lightwallet/client/internal/CoroutineLightWalletClientImpl.kt index fd32c16d..e2859322 100644 --- a/lightwallet-client-lib/src/main/java/co/electriccoin/lightwallet/client/internal/CoroutineLightWalletClientImpl.kt +++ b/lightwallet-client-lib/src/main/java/co/electriccoin/lightwallet/client/internal/CoroutineLightWalletClientImpl.kt @@ -84,8 +84,9 @@ internal class CoroutineLightWalletClientImpl private constructor( } override suspend fun submitTransaction(spendTransaction: ByteArray): Response { - if (spendTransaction.isEmpty()) { - return Response.Failure.Client.SubmitEmptyTransaction() + require(spendTransaction.isNotEmpty()) { + "${Constants.ILLEGAL_ARGUMENT_EXCEPTION_MESSAGE} Failed to submit transaction because it was empty, so " + + "this request was ignored on the client-side." // NON-NLS } return try { val request = @@ -102,10 +103,10 @@ internal class CoroutineLightWalletClientImpl private constructor( } override suspend fun fetchTransaction(txId: ByteArray): Response { - if (txId.isEmpty()) { - return Response.Failure.Client.NullIdTransaction() + require(txId.isNotEmpty()) { + "${Constants.ILLEGAL_ARGUMENT_EXCEPTION_MESSAGE} Failed to start fetching the transaction with null " + + "transaction ID, so this request was ignored on the client-side." // NON-NLS } - return try { val request = Service.TxFilter.newBuilder().setHash(ByteString.copyFrom(txId)).build() diff --git a/lightwallet-client-lib/src/main/java/co/electriccoin/lightwallet/client/model/Response.kt b/lightwallet-client-lib/src/main/java/co/electriccoin/lightwallet/client/model/Response.kt index 6da41c88..643d98e9 100644 --- a/lightwallet-client-lib/src/main/java/co/electriccoin/lightwallet/client/model/Response.kt +++ b/lightwallet-client-lib/src/main/java/co/electriccoin/lightwallet/client/model/Response.kt @@ -1,13 +1,5 @@ package co.electriccoin.lightwallet.client.model -internal const val SUBMIT_EMPTY_TRANSACTION_ERROR_CODE = 3000 -internal const val SUBMIT_EMPTY_TRANSACTION_ERROR_DESCRIPTION = "Failed to submit transaction because it was empty, " + - "so this request was ignored on the client-side." // NON-NLS - -internal const val NULL_TRANSACTION_ID_ERROR_CODE = 3001 -internal const val NULL_TRANSACTION_ID_ERROR_DESCRIPTION = "Failed to start fetching the transaction with null " + - "transaction ID, so this request was ignored on the client-side." // NON-NLS - internal const val CONNECTION_ERROR_CODE = 3100 internal const val CONNECTION_ERROR_DESCRIPTION = "Missing internet connection." // NON-NLS @@ -103,20 +95,6 @@ sealed class Response { */ class Canceled(code: Int, description: String?) : Client(code, description) - /** - * The operation of submitting a transaction failed due to an empty transaction used. - */ - class SubmitEmptyTransaction( - description: String? = SUBMIT_EMPTY_TRANSACTION_ERROR_DESCRIPTION - ) : Client(SUBMIT_EMPTY_TRANSACTION_ERROR_CODE, description) - - /** - * The operation of fetching a transaction failed due to a null ID used. - */ - class NullIdTransaction( - description: String? = NULL_TRANSACTION_ID_ERROR_DESCRIPTION - ) : Client(NULL_TRANSACTION_ID_ERROR_CODE, description) - override fun toString(): String { return "Client Error(code='$code', description='$description')" // NON-NLS } diff --git a/sdk-lib/src/main/java/cash/z/ecc/android/sdk/internal/transaction/PersistentTransactionManager.kt b/sdk-lib/src/main/java/cash/z/ecc/android/sdk/internal/transaction/PersistentTransactionManager.kt index 67f0e3d2..f72dcdb1 100644 --- a/sdk-lib/src/main/java/cash/z/ecc/android/sdk/internal/transaction/PersistentTransactionManager.kt +++ b/sdk-lib/src/main/java/cash/z/ecc/android/sdk/internal/transaction/PersistentTransactionManager.kt @@ -215,8 +215,7 @@ internal class PersistentTransactionManager( ) else -> { twig("submitting transaction with memo: ${tx.memo} amount: ${tx.value}", -1) - val response = service.submitTransaction(tx.raw) - when (response) { + when (val response = service.submitTransaction(tx.raw)) { is Response.Success -> { twig("SUCCESS: submit transaction completed with response: ${response.result}") safeUpdate("updating submitted transaction (hadError: false)", -1) {