15
15
import java .util .*;
16
16
import java .util .stream .Collectors ;
17
17
18
- import static jota .utils .Constants .*;
19
-
20
18
21
19
/**
22
20
* IotaAPI Builder. Usage:
@@ -139,7 +137,7 @@ public GetNewAddressResponse generateNewAddresses(String seed, int security, boo
139
137
*/
140
138
public GetNewAddressResponse generateNewAddresses (String seed , int security , boolean checksum , int index , int amount , boolean addSpendAddresses ) throws ArgumentException {
141
139
if ((!InputValidator .isValidSeed (seed ))) {
142
- throw new IllegalStateException (INVALID_SEED_INPUT_ERROR );
140
+ throw new IllegalStateException (Constants . INVALID_SEED_INPUT_ERROR );
143
141
}
144
142
145
143
StopWatch stopWatch = new StopWatch ();
@@ -177,7 +175,7 @@ public GetNewAddressResponse generateNewAddresses(String seed, int security, boo
177
175
*/
178
176
public GetNewAddressResponse getAddressesUnchecked (String seed , int security , boolean checksum , int index , int amount ) throws ArgumentException {
179
177
if ((!InputValidator .isValidSeed (seed ))) {
180
- throw new IllegalStateException (INVALID_SEED_INPUT_ERROR );
178
+ throw new IllegalStateException (Constants . INVALID_SEED_INPUT_ERROR );
181
179
}
182
180
183
181
StopWatch stopWatch = new StopWatch ();
@@ -202,11 +200,11 @@ public GetTransferResponse getTransfers(String seed, int security, Integer start
202
200
203
201
// validate seed
204
202
if ((!InputValidator .isValidSeed (seed ))) {
205
- throw new IllegalStateException (INVALID_SEED_INPUT_ERROR );
203
+ throw new IllegalStateException (Constants . INVALID_SEED_INPUT_ERROR );
206
204
}
207
205
208
206
if (start > end || end > (start + 500 )) {
209
- throw new ArgumentException (INVALID_INPUT_ERROR );
207
+ throw new ArgumentException (Constants . INVALID_INPUT_ERROR );
210
208
}
211
209
212
210
StopWatch stopWatch = new StopWatch ();
@@ -264,7 +262,7 @@ public Bundle[] bundlesFromAddresses(String[] addresses, final Boolean inclusion
264
262
if (tailTxArray .length != 0 && inclusionStates ) {
265
263
gisr = getLatestInclusion (tailTxArray );
266
264
if (gisr == null || gisr .getStates () == null || gisr .getStates ().length == 0 ) {
267
- throw new IllegalStateException (GET_INCLUSION_STATE_RESPONSE_ERROR );
265
+ throw new IllegalStateException (Constants . GET_INCLUSION_STATE_RESPONSE_ERROR );
268
266
}
269
267
}
270
268
final GetInclusionStateResponse finalInclusionStates = gisr ;
@@ -289,7 +287,7 @@ public void perform(String param) {
289
287
}
290
288
// If error returned from getBundle, simply ignore it because the bundle was most likely incorrect
291
289
} catch (ArgumentException e ) {
292
- log .warn (GET_BUNDLE_RESPONSE_ERROR );
290
+ log .warn (Constants . GET_BUNDLE_RESPONSE_ERROR );
293
291
}
294
292
}
295
293
});
@@ -312,7 +310,7 @@ public void perform(String param) {
312
310
public BroadcastTransactionsResponse storeAndBroadcast (final String ... trytes ) throws ArgumentException {
313
311
314
312
if (!InputValidator .isArrayOfAttachedTrytes (trytes )) {
315
- throw new ArgumentException (INVALID_TRYTES_INPUT_ERROR );
313
+ throw new ArgumentException (Constants . INVALID_TRYTES_INPUT_ERROR );
316
314
}
317
315
318
316
try {
@@ -363,7 +361,7 @@ public List<Transaction> sendTrytes(final String[] trytes, final int depth, fina
363
361
public List <Transaction > findTransactionsObjectsByHashes (String [] hashes ) throws ArgumentException {
364
362
365
363
if (!InputValidator .isArrayOfHashes (hashes )) {
366
- throw new IllegalStateException (INVALID_HASHES_INPUT_ERROR );
364
+ throw new IllegalStateException (Constants . INVALID_HASHES_INPUT_ERROR );
367
365
}
368
366
369
367
final GetTrytesResponse trytesResponse = getTrytes (hashes );
@@ -462,16 +460,16 @@ public List<String> prepareTransfers(String seed, int security, final List<Trans
462
460
463
461
// validate seed
464
462
if ((!InputValidator .isValidSeed (seed ))) {
465
- throw new IllegalStateException (INVALID_SEED_INPUT_ERROR );
463
+ throw new IllegalStateException (Constants . INVALID_SEED_INPUT_ERROR );
466
464
}
467
465
468
466
if (!InputValidator .isValidSecurityLevel (security )) {
469
- throw new ArgumentException (INVALID_SECURITY_LEVEL_INPUT_ERROR );
467
+ throw new ArgumentException (Constants . INVALID_SECURITY_LEVEL_INPUT_ERROR );
470
468
}
471
469
472
470
// Input validation of transfers object
473
471
if (!InputValidator .isTransfersCollectionValid (transfers )) {
474
- throw new ArgumentException (INVALID_TRANSFERS_INPUT_ERROR );
472
+ throw new ArgumentException (Constants . INVALID_TRANSFERS_INPUT_ERROR );
475
473
}
476
474
477
475
// Create a new bundle
@@ -590,7 +588,7 @@ public List<String> prepareTransfers(String seed, int security, final List<Trans
590
588
591
589
// Return not enough balance error
592
590
if (totalValue > totalBalance ) {
593
- throw new IllegalStateException (NOT_ENOUGH_BALANCE_ERROR );
591
+ throw new IllegalStateException (Constants . NOT_ENOUGH_BALANCE_ERROR );
594
592
}
595
593
596
594
return addRemainder (seed , security , confirmedInputs , bundle , tag , totalValue , remainder , signatureFragments );
@@ -638,17 +636,17 @@ public GetBalancesAndFormatResponse getInputs(String seed, int security, int sta
638
636
639
637
// validate the seed
640
638
if ((!InputValidator .isValidSeed (seed ))) {
641
- throw new IllegalStateException (INVALID_SEED_INPUT_ERROR );
639
+ throw new IllegalStateException (Constants . INVALID_SEED_INPUT_ERROR );
642
640
}
643
641
644
642
if (!InputValidator .isValidSecurityLevel (security )) {
645
- throw new ArgumentException (INVALID_SECURITY_LEVEL_INPUT_ERROR );
643
+ throw new ArgumentException (Constants . INVALID_SECURITY_LEVEL_INPUT_ERROR );
646
644
}
647
645
648
646
// If start value bigger than end, return error
649
647
// or if difference between end and start is bigger than 500 keys
650
648
if ((start > end && end > 0 ) || end > (start + 500 )) {
651
- throw new IllegalStateException (INVALID_INPUT_ERROR );
649
+ throw new IllegalStateException (Constants . INVALID_INPUT_ERROR );
652
650
}
653
651
654
652
StopWatch stopWatch = new StopWatch ();
@@ -695,7 +693,7 @@ public GetBalancesAndFormatResponse getInputs(String seed, int security, int sta
695
693
public GetBalancesAndFormatResponse getBalanceAndFormat (final List <String > addresses , final List <String > tips , long threshold , int start , StopWatch stopWatch , int security ) throws ArgumentException , IllegalStateException {
696
694
697
695
if (!InputValidator .isValidSecurityLevel (security )) {
698
- throw new ArgumentException (INVALID_SECURITY_LEVEL_INPUT_ERROR );
696
+ throw new ArgumentException (Constants . INVALID_SECURITY_LEVEL_INPUT_ERROR );
699
697
}
700
698
701
699
GetBalancesResponse getBalancesResponse = getBalances (100 , addresses , tips );
@@ -730,7 +728,7 @@ public GetBalancesAndFormatResponse getBalanceAndFormat(final List<String> addre
730
728
if (thresholdReached ) {
731
729
return GetBalancesAndFormatResponse .create (inputs , totalBalance , stopWatch .getElapsedTimeMili ());
732
730
}
733
- throw new IllegalStateException (NOT_ENOUGH_BALANCE_ERROR );
731
+ throw new IllegalStateException (Constants . NOT_ENOUGH_BALANCE_ERROR );
734
732
}
735
733
736
734
/**
@@ -744,18 +742,18 @@ public GetBalancesAndFormatResponse getBalanceAndFormat(final List<String> addre
744
742
public GetBundleResponse getBundle (String transaction ) throws ArgumentException {
745
743
746
744
if (!InputValidator .isHash (transaction )) {
747
- throw new ArgumentException (INVALID_HASHES_INPUT_ERROR );
745
+ throw new ArgumentException (Constants . INVALID_HASHES_INPUT_ERROR );
748
746
}
749
747
750
748
StopWatch stopWatch = new StopWatch ();
751
749
752
750
Bundle bundle = traverseBundle (transaction , null , new Bundle ());
753
751
if (bundle == null ) {
754
- throw new ArgumentException (INVALID_BUNDLE_ERROR );
752
+ throw new ArgumentException (Constants . INVALID_BUNDLE_ERROR );
755
753
}
756
754
757
755
if (!BundleValidator .isBundle (bundle )){
758
- throw new ArgumentException (INVALID_BUNDLE_ERROR );
756
+ throw new ArgumentException (Constants . INVALID_BUNDLE_ERROR );
759
757
}
760
758
761
759
return GetBundleResponse .create (bundle .getTransactions (), stopWatch .getElapsedTimeMili ());
@@ -778,11 +776,11 @@ public GetBundleResponse getBundle(String transaction) throws ArgumentException
778
776
*/
779
777
public GetAccountDataResponse getAccountData (String seed , int security , int index , boolean checksum , int total , boolean returnAll , int start , int end , boolean inclusionStates , long threshold ) throws ArgumentException {
780
778
if (!InputValidator .isValidSecurityLevel (security )) {
781
- throw new ArgumentException (INVALID_SECURITY_LEVEL_INPUT_ERROR );
779
+ throw new ArgumentException (Constants . INVALID_SECURITY_LEVEL_INPUT_ERROR );
782
780
}
783
781
784
782
if (start > end || end > (start + 1000 )) {
785
- throw new ArgumentException (INVALID_INPUT_ERROR );
783
+ throw new ArgumentException (Constants . INVALID_INPUT_ERROR );
786
784
}
787
785
788
786
StopWatch stopWatch = new StopWatch ();
@@ -849,7 +847,7 @@ public Boolean checkWereAddressSpentFrom(String address) throws ArgumentExceptio
849
847
public ReplayBundleResponse replayBundle (String tailTransactionHash , int depth , int minWeightMagnitude , String reference ) throws ArgumentException {
850
848
851
849
if (!InputValidator .isHash (tailTransactionHash )) {
852
- throw new ArgumentException (INVALID_TAIL_HASH_INPUT_ERROR );
850
+ throw new ArgumentException (Constants . INVALID_TAIL_HASH_INPUT_ERROR );
853
851
}
854
852
855
853
StopWatch stopWatch = new StopWatch ();
@@ -951,16 +949,16 @@ public Bundle traverseBundle(String trunkTx, String bundleHash, Bundle bundle) t
951
949
if (gtr != null ) {
952
950
953
951
if (gtr .getTrytes ().length == 0 ) {
954
- throw new ArgumentException (INVALID_BUNDLE_ERROR );
952
+ throw new ArgumentException (Constants . INVALID_BUNDLE_ERROR );
955
953
}
956
954
957
955
Transaction trx = new Transaction (gtr .getTrytes ()[0 ], customCurl .clone ());
958
956
if (trx .getBundle () == null ) {
959
- throw new ArgumentException (INVALID_TRYTES_INPUT_ERROR );
957
+ throw new ArgumentException (Constants . INVALID_TRYTES_INPUT_ERROR );
960
958
}
961
959
// If first transaction to search is not a tail, return error
962
960
if (bundleHash == null && trx .getCurrentIndex () != 0 ) {
963
- throw new ArgumentException (INVALID_TAIL_HASH_INPUT_ERROR );
961
+ throw new ArgumentException (Constants . INVALID_TAIL_HASH_INPUT_ERROR );
964
962
}
965
963
// If no bundle hash, define it
966
964
if (bundleHash == null ) {
@@ -983,7 +981,7 @@ public Bundle traverseBundle(String trunkTx, String bundleHash, Bundle bundle) t
983
981
// Continue traversing with new trunkTx
984
982
return traverseBundle (trunkTx , bundleHash , bundle );
985
983
} else {
986
- throw new ArgumentException (GET_TRYTES_RESPONSE_ERROR );
984
+ throw new ArgumentException (Constants . GET_TRYTES_RESPONSE_ERROR );
987
985
}
988
986
}
989
987
@@ -1058,21 +1056,21 @@ public List<Transaction> initiateTransfer(int securitySum, String inputAddress,
1058
1056
List <Transfer > transfers , List <Transaction > tips ,
1059
1057
boolean testMode ) throws ArgumentException {
1060
1058
if (securitySum < Constants .MIN_SECURITY_LEVEL ) {
1061
- throw new ArgumentException (INVALID_SECURITY_LEVEL_INPUT_ERROR );
1059
+ throw new ArgumentException (Constants . INVALID_SECURITY_LEVEL_INPUT_ERROR );
1062
1060
}
1063
1061
1064
1062
// validate input address
1065
1063
if (!InputValidator .isAddress (inputAddress ))
1066
- throw new ArgumentException (INVALID_ADDRESSES_INPUT_ERROR );
1064
+ throw new ArgumentException (Constants . INVALID_ADDRESSES_INPUT_ERROR );
1067
1065
1068
1066
// validate remainder address
1069
1067
if (remainderAddress != null && !InputValidator .isAddress (remainderAddress )) {
1070
- throw new ArgumentException (INVALID_ADDRESSES_INPUT_ERROR );
1068
+ throw new ArgumentException (Constants . INVALID_ADDRESSES_INPUT_ERROR );
1071
1069
}
1072
1070
1073
1071
// Input validation of transfers object
1074
1072
if (!InputValidator .isTransfersCollectionValid (transfers )) {
1075
- throw new ArgumentException (INVALID_TRANSFERS_INPUT_ERROR );
1073
+ throw new ArgumentException (Constants . INVALID_TRANSFERS_INPUT_ERROR );
1076
1074
}
1077
1075
1078
1076
// Create a new bundle
@@ -1185,7 +1183,7 @@ public List<Transaction> initiateTransfer(int securitySum, String inputAddress,
1185
1183
}
1186
1184
// Return not enough balance error
1187
1185
if (totalValue > totalBalance ) {
1188
- throw new IllegalStateException (NOT_ENOUGH_BALANCE_ERROR );
1186
+ throw new IllegalStateException (Constants . NOT_ENOUGH_BALANCE_ERROR );
1189
1187
}
1190
1188
1191
1189
// If there is a remainder value
@@ -1196,7 +1194,7 @@ public List<Transaction> initiateTransfer(int securitySum, String inputAddress,
1196
1194
1197
1195
// Remainder bundle entry if necessary
1198
1196
if (remainderAddress == null ) {
1199
- throw new IllegalStateException (NO_REMAINDER_ADDRESS_ERROR );
1197
+ throw new IllegalStateException (Constants . NO_REMAINDER_ADDRESS_ERROR );
1200
1198
}
1201
1199
1202
1200
bundle .addEntry (1 , remainderAddress , remainder , tag , timestamp );
@@ -1207,7 +1205,7 @@ public List<Transaction> initiateTransfer(int securitySum, String inputAddress,
1207
1205
1208
1206
return bundle .getTransactions ();
1209
1207
} else {
1210
- throw new RuntimeException (INVALID_VALUE_TRANSFER_ERROR );
1208
+ throw new RuntimeException (Constants . INVALID_VALUE_TRANSFER_ERROR );
1211
1209
}
1212
1210
1213
1211
}
@@ -1322,7 +1320,7 @@ public List<String> addRemainder(final String seed,
1322
1320
totalTransferValue -= thisBalance ;
1323
1321
}
1324
1322
}
1325
- throw new IllegalStateException (NOT_ENOUGH_BALANCE_ERROR );
1323
+ throw new IllegalStateException (Constants . NOT_ENOUGH_BALANCE_ERROR );
1326
1324
}
1327
1325
1328
1326
/**
@@ -1348,7 +1346,7 @@ public boolean isPromotable(Transaction tail) throws ArgumentException {
1348
1346
public boolean isPromotable (String tail ) throws ArgumentException {
1349
1347
GetTrytesResponse transaction = getTrytes (tail );
1350
1348
if (0 == transaction .getTrytes ().length ) {
1351
- throw new ArgumentException (TRANSACTION_NOT_FOUND );
1349
+ throw new ArgumentException (Constants . TRANSACTION_NOT_FOUND );
1352
1350
}
1353
1351
1354
1352
return isPromotable (new Transaction (transaction .getTrytes ()[0 ]));
0 commit comments