diff --git a/README.md b/README.md
index 88d7e04..7cacdfa 100644
--- a/README.md
+++ b/README.md
@@ -12,7 +12,7 @@ If you have any ideas please submit a request (I am totally not a Java guy so...
- [x] updateLeafToRoot
- [x] getDigest
-#### Model.Transfer
+#### com.flashwifi.flashwrapper.Model.Transfer
- [x] prepare
- [x] compose
- [x] close (needs testing)
@@ -28,7 +28,7 @@ If you have any ideas please submit a request (I am totally not a Java guy so...
1. Clone repo
2. Update maven ressources
3. That's it.
-4. You can run a test transaction by running the main func in the Main Class.
+4. You can run a test transaction by running the main func in the com.flashwifi.flashwrapper.Main Class.
diff --git a/iotaflashlibjswrapper.iml b/iotaflashlibjswrapper.iml
index 94d5fa5..f96270c 100644
--- a/iotaflashlibjswrapper.iml
+++ b/iotaflashlibjswrapper.iml
@@ -12,7 +12,7 @@
-
+
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index d240599..eb3f783 100644
--- a/pom.xml
+++ b/pom.xml
@@ -21,11 +21,13 @@
j2v8_macosx_x86_64
4.6.0
+
com.github.iotaledger
iota~lib~java
- v0.9.10
+ 0.9.10
+
com.google.code.gson
@@ -37,13 +39,10 @@
-
1.8
1.8
-
UTF-8
UTF-8
-
\ No newline at end of file
diff --git a/res/iota.flash.helper.js b/res/iota.flash.helper.js
new file mode 100644
index 0000000..f8e7f41
--- /dev/null
+++ b/res/iota.flash.helper.js
@@ -0,0 +1,13 @@
+var Helper = {
+ applyTransfers: function(flash, bundles) {
+ iotaFlash.transfer.applyTransfers(
+ flash.root,
+ flash.deposits,
+ flash.outputs,
+ flash.remainderAddress,
+ flash.transfers,
+ bundles
+ )
+ return flash
+ }
+}
diff --git a/res/iota.flash.js b/res/iota.flash.js
index b155739..e29a861 100644
--- a/res/iota.flash.js
+++ b/res/iota.flash.js
@@ -10297,6 +10297,7 @@ function close(settlement, deposits) {
* @param {array} transfers
*/
function applyTransfers(root, deposit, outputs, remainder, history, transfers) {
+
if (transfers.filter(transfer =>
transfer.filter(tx => tx.value < 0)
.filter(tx => !IOTACrypto.utils.validateSignatures(transfer, tx.address))
diff --git a/src/main/java/Helpers.java b/src/main/java/com/flashwifi/flashwrapper/Helpers.java
similarity index 84%
rename from src/main/java/Helpers.java
rename to src/main/java/com/flashwifi/flashwrapper/Helpers.java
index 40f3960..25dfab5 100644
--- a/src/main/java/Helpers.java
+++ b/src/main/java/com/flashwifi/flashwrapper/Helpers.java
@@ -1,4 +1,7 @@
-import Model.*;
+package com.flashwifi.flashwrapper;
+
+import com.flashwifi.flashwrapper.Model.*;
+
import java.util.ArrayList;
import java.util.List;
@@ -7,7 +10,6 @@ import java.util.stream.Collectors;
public class Helpers {
public static ArrayList createTransaction(UserObject user, ArrayList transfers, boolean shouldClose) {
CreateTransactionHelperObject toUse = IotaFlashBridge.updateLeafToRoot(user.getFlash().getRoot());
-
if (toUse.getGenerate() != 0) {
// TODO: tell the server to gen new address.
System.out.println("No more addresses in channel.");
@@ -72,14 +74,16 @@ public class Helpers {
}
public static void applyTransfers(UserObject user, ArrayList bundles) {
- IotaFlashBridge.applayTransfers(
- user.getFlash().getRoot(),
- user.getFlash().getDeposits(),
- user.getFlash().getOutputs(),
- user.getFlash().getRemainderAddress(),
- user.getFlash().getTransfers(),
- bundles
- );
+ FlashObject flash = IotaFlashBridge.applyTransfersToUser(user, bundles);
+ user.setFlash(flash);
+ // com.flashwifi.flashwrapper.IotaFlashBridge.applyTransfers(
+// user.getFlash().getRoot(),
+// user.getFlash().getDeposits(),
+// user.getFlash().getOutputs(),
+// user.getFlash().getRemainderAddress(),
+// user.getFlash().getTransfers(),
+// bundles
+// );
}
public static ArrayList clone(ArrayList bundles) {
diff --git a/src/main/java/IotaFlashBridge.java b/src/main/java/com/flashwifi/flashwrapper/IotaFlashBridge.java
similarity index 89%
rename from src/main/java/IotaFlashBridge.java
rename to src/main/java/com/flashwifi/flashwrapper/IotaFlashBridge.java
index ee1143c..df757bf 100644
--- a/src/main/java/IotaFlashBridge.java
+++ b/src/main/java/com/flashwifi/flashwrapper/IotaFlashBridge.java
@@ -1,4 +1,6 @@
-import Model.*;
+package com.flashwifi.flashwrapper;
+
+import com.flashwifi.flashwrapper.Model.*;
import com.eclipsesource.v8.*;
import com.eclipsesource.v8.utils.V8ObjectUtils;
@@ -13,9 +15,11 @@ import java.util.Map;
public class IotaFlashBridge {
private static String iotaLibPath = "res/iota.flash.js";
+ private static String iotaHelperLibPath = "res/iota.flash.helper.js";
private static V8 engine;
private static V8Object transfer;
private static V8Object multisig;
+ private static V8Object helper;
public static void boot() throws IOException {
String file = readFile(iotaLibPath, Charset.defaultCharset());
@@ -23,10 +27,12 @@ public class IotaFlashBridge {
engine = V8.createV8Runtime();
// Eval lib into current v8 context.
engine.executeVoidScript(file);
+ engine.executeVoidScript(readFile(iotaHelperLibPath, Charset.defaultCharset()));
multisig = (V8Object) engine.executeScript("iotaFlash.multisig");
transfer = (V8Object) engine.executeScript("iotaFlash.transfer");
+ helper = (V8Object) engine.executeScript("Helper");
- Model.Console console = new Model.Console();
+ com.flashwifi.flashwrapper.Model.Console console = new com.flashwifi.flashwrapper.Model.Console();
V8Object v8Console = new V8Object(engine);
engine.add("console", v8Console);
v8Console.registerJavaMethod(console, "log", "log", new Class>[] { String.class });
@@ -61,6 +67,8 @@ public class IotaFlashBridge {
int secSum = (Integer) resultMap.get("securitySum");
MultisigAddress ret = new MultisigAddress(addr, secSum);
+ params.release();
+ retV8.release();
return ret;
}
@@ -250,7 +258,7 @@ public class IotaFlashBridge {
* @param signedBundles
* @return
*/
- public static void applayTransfers(MultisigAddress root,
+ public static void applyTransfers(MultisigAddress root,
ArrayList deposits,
ArrayList outputs,
MultisigAddress remainderAddress,
@@ -268,6 +276,20 @@ public class IotaFlashBridge {
transfer.executeFunction("applyTransfers", V8ObjectUtils.toV8Array(engine, params));
}
+ public static FlashObject applyTransfersToUser(UserObject user, ArrayList signedBundles) {
+ List