mirror of
https://github.com/gosticks/iota.flash.js-java-wrapper.git
synced 2025-10-16 11:45:40 +00:00
added error loggings and minor tweaks
This commit is contained in:
parent
5e9b74bbfe
commit
e197850967
@ -38,7 +38,6 @@ public class Helpers {
|
||||
* @param transfers
|
||||
* @param toUse Transaction helper object
|
||||
* @param user
|
||||
* @param shouldClose
|
||||
* @return
|
||||
*/
|
||||
public static ArrayList<Bundle> createTransaction(ArrayList<Transfer> transfers, CreateTransactionHelperObject toUse, UserObject user) {
|
||||
@ -55,6 +54,11 @@ public class Helpers {
|
||||
user.getUserIndex(),
|
||||
transfers
|
||||
);
|
||||
|
||||
if (newTransfers == null) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
// Compose the transaction. This may also add some management transactions (moving remainder tokens.)
|
||||
bundles = IotaFlashBridge.compose(
|
||||
flash.getBalance(),
|
||||
@ -302,7 +306,6 @@ public class Helpers {
|
||||
return attachedBundles;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* creates a new iota instace with the defined url and mode (testnet or not)
|
||||
* if api instance available the just return it
|
||||
|
||||
@ -126,8 +126,14 @@ public class IotaFlashBridge {
|
||||
params.add(V8Converter.transferListToV8Array(engine, transfers));
|
||||
|
||||
// Call js function.
|
||||
V8Array ret = transfer.executeArrayFunction("prepare", V8ObjectUtils.toV8Array(engine, params));
|
||||
return V8Converter.transferListFromV8Array(ret);
|
||||
try {
|
||||
V8Array ret = transfer.executeArrayFunction("prepare", V8ObjectUtils.toV8Array(engine, params));
|
||||
return V8Converter.transferListFromV8Array(ret);
|
||||
} catch (V8ScriptExecutionException exception) {
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -144,7 +144,7 @@ public class Main {
|
||||
ArrayList<Bundle> confirmedTransfers;
|
||||
|
||||
// Try to make 10 transfers.
|
||||
for (int i = 0; i < 4; i++) {
|
||||
for (int i = 0; i < 2; i++) {
|
||||
|
||||
// Create transaction helper and check if we need to add nodes
|
||||
CreateTransactionHelperObject helper = Helpers.getTransactionHelper(oneFlash.getFlash().getRoot());
|
||||
@ -252,13 +252,7 @@ public class Main {
|
||||
Helpers.applyTransfers(signedBundlesOne, oneFlash);
|
||||
Helpers.applyTransfers(signedBundlesTwo, twoFlash);
|
||||
|
||||
System.out.println("[INFO] Channel closed!");
|
||||
|
||||
// TODO: find why there is a internal bundle at the start. But only the last one should be used.
|
||||
List<Bundle> closeBundles = new ArrayList<>();
|
||||
closeBundles.add(signedBundlesOne.get(signedBundlesOne.size() - 1));
|
||||
|
||||
List<Bundle> attachedBundles = Helpers.POWClosedBundle(signedBundlesOne, 5, 10);
|
||||
List<Bundle> attachedBundles = Helpers.POWClosedBundle(signedBundlesOne, 4, 13);
|
||||
|
||||
System.out.println("[INFO] Attached bundles" + attachedBundles.toString());
|
||||
}
|
||||
|
||||
@ -0,0 +1,21 @@
|
||||
package iotaFlashWrapper.Model;
|
||||
|
||||
public class FlashLibJSException extends Exception {
|
||||
|
||||
public enum FlashLibJSExceptionType {
|
||||
INSUFFICIENT_FUNDS, UNKNOWN
|
||||
}
|
||||
|
||||
|
||||
private FlashLibJSExceptionType type = FlashLibJSExceptionType.UNKNOWN;
|
||||
|
||||
public FlashLibJSException(String string) {
|
||||
if (string.contains(FlashLibJSExceptionType.INSUFFICIENT_FUNDS.name())) {
|
||||
this.type = FlashLibJSExceptionType.INSUFFICIENT_FUNDS;
|
||||
}
|
||||
}
|
||||
|
||||
public FlashLibJSExceptionType getType() {
|
||||
return type;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user