mirror of
https://github.com/gosticks/iota.flash.js-java-wrapper.git
synced 2025-10-16 11:45:40 +00:00
Added iota trytes conversion and transfer, merged some model objects with jota.model objects, small cleanup
This commit is contained in:
parent
dbf0958df8
commit
e1c731d3a2
@ -25,4 +25,5 @@ dependencies {
|
||||
//compile 'com.eclipsesource.j2v8:j2v8:4.8.0@aar'
|
||||
compile group: 'com.eclipsesource.j2v8', name: 'j2v8_macosx_x86_64', version:'4.6.0'
|
||||
compile group: 'com.google.code.gson', name: 'gson', version:'2.8.2'
|
||||
compile 'com.github.iotaledger:iota~lib~java:0.9.10'
|
||||
}
|
||||
|
||||
@ -1,12 +1,12 @@
|
||||
package iotaFlashWrapper;
|
||||
|
||||
import com.sun.org.apache.xpath.internal.operations.Mult;
|
||||
import iotaFlashWrapper.Model.*;
|
||||
import jota.IotaAPI;
|
||||
import jota.error.ArgumentException;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class Helpers {
|
||||
|
||||
@ -16,7 +16,7 @@ public class Helpers {
|
||||
* @param root multisig address at the top of the tree
|
||||
* @return Transaction object with address and number of addresses to create.
|
||||
*/
|
||||
public static CreateTransactionHelperObject getTransactionHelper(MultisigAddress root) {
|
||||
public static CreateTransactionHelperObject getTransactionHelper(Multisig root) {
|
||||
return IotaFlashBridge.updateLeafToRoot(root);
|
||||
}
|
||||
|
||||
@ -101,11 +101,11 @@ public class Helpers {
|
||||
* @param address
|
||||
* @return
|
||||
*/
|
||||
public static MultisigAddress getNewBranch(ArrayList<Digest> oneDigests, ArrayList<Digest> twoDigests, UserObject user, MultisigAddress address) {
|
||||
public static Multisig getNewBranch(ArrayList<Digest> oneDigests, ArrayList<Digest> twoDigests, UserObject user, Multisig address) {
|
||||
ArrayList<ArrayList<Digest>> userDigestList = new ArrayList<>();
|
||||
userDigestList.add(oneDigests);
|
||||
userDigestList.add(twoDigests);
|
||||
ArrayList<MultisigAddress> multisigs = getMultisigsForUser(userDigestList, user);
|
||||
ArrayList<Multisig> multisigs = getMultisigsForUser(userDigestList, user);
|
||||
|
||||
System.out.println("[INFO]: Adding to address " + address.getAddress());
|
||||
|
||||
@ -115,7 +115,7 @@ public class Helpers {
|
||||
}
|
||||
|
||||
// Clone the address to avoid overwriting params.
|
||||
MultisigAddress output = address.clone();
|
||||
Multisig output = address.clone();
|
||||
|
||||
// Add new multisigs to address.
|
||||
output.push(multisigs.get(0));
|
||||
@ -126,7 +126,7 @@ public class Helpers {
|
||||
|
||||
/**
|
||||
*
|
||||
* Digests and MultisigAddress creation
|
||||
* Digests and Multisig creation
|
||||
*
|
||||
*/
|
||||
|
||||
@ -163,10 +163,10 @@ public class Helpers {
|
||||
* @param currentUser
|
||||
* @return
|
||||
*/
|
||||
public static ArrayList<MultisigAddress> getMultisigsForUser(ArrayList<ArrayList<Digest>> allDigests, UserObject currentUser) {
|
||||
public static ArrayList<Multisig> getMultisigsForUser(ArrayList<ArrayList<Digest>> allDigests, UserObject currentUser) {
|
||||
|
||||
// Generate the first addresses
|
||||
ArrayList<MultisigAddress> multisigs = new ArrayList<MultisigAddress>();
|
||||
ArrayList<Multisig> multisigs = new ArrayList<Multisig>();
|
||||
|
||||
// Loop for all digests.
|
||||
for (int index = 0; index < allDigests.get(0).size(); index++) {
|
||||
@ -183,19 +183,19 @@ public class Helpers {
|
||||
}
|
||||
|
||||
// Create multisgAddr from digests.
|
||||
MultisigAddress multisigAddress = IotaFlashBridge.composeAddress(alignedDigests);
|
||||
Multisig multisig = IotaFlashBridge.composeAddress(alignedDigests);
|
||||
|
||||
// Get digests data for current user.
|
||||
Digest digest = allDigests.get(currentUser.getUserIndex()).get(index);
|
||||
|
||||
multisigAddress.setIndex(digest.getIndex());
|
||||
multisigAddress.setSigningIndex(currentUser.getUserIndex() * digest.getSecurity());
|
||||
multisigAddress.setSecuritySum(securitySum);
|
||||
multisigAddress.setSecurity(digest.getSecurity());
|
||||
multisig.setIndex(digest.getIndex());
|
||||
multisig.setSigningIndex(currentUser.getUserIndex() * digest.getSecurity());
|
||||
multisig.setSecuritySum(securitySum);
|
||||
multisig.setSecurity(digest.getSecurity());
|
||||
|
||||
System.out.println("Creating address " + multisigAddress.getAddress() + " index" + multisigAddress.getIndex() + " signingIndex: " + multisigAddress.getSigningIndex());
|
||||
System.out.println("Creating address " + multisig.getAddress() + " index" + multisig.getIndex() + " signingIndex: " + multisig.getSigningIndex());
|
||||
|
||||
multisigs.add(multisigAddress);
|
||||
multisigs.add(multisig);
|
||||
}
|
||||
|
||||
return multisigs;
|
||||
@ -205,22 +205,140 @@ public class Helpers {
|
||||
/**
|
||||
*
|
||||
* @param user
|
||||
* @param multisigAddress
|
||||
* @param multisig
|
||||
* @return
|
||||
*/
|
||||
public static MultisigAddress updateMultisigChildrenForUser(UserObject user, MultisigAddress multisigAddress) {
|
||||
public static Multisig updateMultisigChildrenForUser(UserObject user, Multisig multisig) {
|
||||
FlashObject flash = user.getFlash();
|
||||
MultisigAddress originAddress = flash.getRoot().find(multisigAddress.getAddress());
|
||||
Multisig originAddress = flash.getRoot().find(multisig.getAddress());
|
||||
if (originAddress != null) {
|
||||
|
||||
System.out.println("[INFO]: found address in user" + user.getUserIndex() + " data");
|
||||
originAddress.setChildren(multisigAddress.getChildren());
|
||||
originAddress.setBundles(multisigAddress.getBundles());
|
||||
originAddress.setSecurity(multisigAddress.getSecurity());
|
||||
originAddress.setChildren(multisig.getChildren());
|
||||
originAddress.setBundles(multisig.getBundles());
|
||||
originAddress.setSecurity(multisig.getSecurity());
|
||||
return originAddress;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void applyTransfers(ArrayList<Bundle> signedBundles, UserObject user) {
|
||||
// Apply transfers to User ONE
|
||||
FlashObject newFlash = IotaFlashBridge.applyTransfersToUser(user, signedBundles);
|
||||
|
||||
// Set new flash object to user
|
||||
user.setFlash(newFlash);
|
||||
|
||||
// Save latest channel bundles
|
||||
user.getBundles().addAll(signedBundles);
|
||||
}
|
||||
|
||||
|
||||
public static void sendTrytes(String[] trytes) {
|
||||
IotaAPI.Builder iota = new IotaAPI.Builder();
|
||||
try {
|
||||
iota.build().sendTrytes(trytes, 5, 10);
|
||||
} catch (ArgumentException exception) {
|
||||
System.out.println("[ERROR]: could not send trytes");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static void POWClosedBundle(List<Bundle> bundles) {
|
||||
for (Bundle b : bundles) {
|
||||
String[] trytes = b.toTrytesArray();
|
||||
sendTrytes(trytes);
|
||||
}
|
||||
}
|
||||
|
||||
//static async POWClosedBundle(bundles) {
|
||||
// try {
|
||||
// console.log('attachAndPOWClosedBundle', bundles)
|
||||
// bundles = Attach.getBundles(bundles)
|
||||
// var trytesPerBundle = []
|
||||
// for (var bundle of bundles) {
|
||||
// var trytes = Attach.bundleToTrytes(bundle)
|
||||
// trytesPerBundle.push(trytes)
|
||||
// }
|
||||
// console.log('closing room with trytes', trytesPerBundle)
|
||||
// var results = []
|
||||
// for (var trytes of trytesPerBundle) {
|
||||
// console.log(trytes)
|
||||
// if (isWindow()) {
|
||||
// curl.init()
|
||||
// curl.overrideAttachToTangle(iota)
|
||||
// }
|
||||
// var result = await Attach.sendTrytes(trytes)
|
||||
// results.push(result)
|
||||
// }
|
||||
// return results
|
||||
// } catch (e) {
|
||||
// return e
|
||||
// }
|
||||
// }
|
||||
// export class Attach {
|
||||
// static bundleToTrytes(bundle) {
|
||||
// var bundleTrytes = []
|
||||
// bundle.forEach(function(bundleTx) {
|
||||
// bundleTrytes.push(iota.utils.transactionTrytes(bundleTx))
|
||||
// })
|
||||
// return bundleTrytes.reverse()
|
||||
// }
|
||||
//
|
||||
// static async sendTrytes(trytes) {
|
||||
// return new Promise(function(resolve, reject) {
|
||||
// iota.api.sendTrytes(
|
||||
// trytes,
|
||||
// Presets.PROD ? 6 : 5,
|
||||
// Presets.PROD ? 15 : 10,
|
||||
// (e, r) => {
|
||||
// console.log('sendTrytes', e, r)
|
||||
// if (e !== null) {
|
||||
// reject(e)
|
||||
// } else {
|
||||
// resolve(r)
|
||||
// }
|
||||
// }
|
||||
// )
|
||||
// })
|
||||
// }
|
||||
//
|
||||
// static getBundles(bundles) {
|
||||
// var ret = []
|
||||
// for (var bundle of bundles) {
|
||||
// if (bundle !== null || bundle.value !== 0) {
|
||||
// ret.push(bundle)
|
||||
// }
|
||||
// }
|
||||
// return ret
|
||||
// }
|
||||
//
|
||||
// static async POWClosedBundle(bundles) {
|
||||
// try {
|
||||
// console.log('attachAndPOWClosedBundle', bundles)
|
||||
// bundles = Attach.getBundles(bundles)
|
||||
// var trytesPerBundle = []
|
||||
// for (var bundle of bundles) {
|
||||
// var trytes = Attach.bundleToTrytes(bundle)
|
||||
// trytesPerBundle.push(trytes)
|
||||
// }
|
||||
// console.log('closing room with trytes', trytesPerBundle)
|
||||
// var results = []
|
||||
// for (var trytes of trytesPerBundle) {
|
||||
// console.log(trytes)
|
||||
// if (isWindow()) {
|
||||
// curl.init()
|
||||
// curl.overrideAttachToTangle(iota)
|
||||
// }
|
||||
// var result = await Attach.sendTrytes(trytes)
|
||||
// results.push(result)
|
||||
// }
|
||||
// return results
|
||||
// } catch (e) {
|
||||
// return e
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
@ -7,14 +7,11 @@ import iotaFlashWrapper.Model.*;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static java.nio.file.Files.readAllBytes;
|
||||
|
||||
public class IotaFlashBridge {
|
||||
private static String iotaLibPath = "iota.flash.js";
|
||||
private static String iotaHelperLibPath = "iota.flash.helper.js";
|
||||
@ -47,7 +44,7 @@ public class IotaFlashBridge {
|
||||
* @param digests
|
||||
* @return
|
||||
*/
|
||||
public static MultisigAddress composeAddress(ArrayList<Digest> digests) {
|
||||
public static Multisig composeAddress(ArrayList<Digest> digests) {
|
||||
// Create js object for digest
|
||||
List<Object> list = new ArrayList<Object>();
|
||||
for (Digest digest: digests) {
|
||||
@ -66,7 +63,7 @@ public class IotaFlashBridge {
|
||||
// Parse result into Java Obj.
|
||||
String addr = (String) resultMap.get("address");
|
||||
int secSum = (Integer) resultMap.get("securitySum");
|
||||
MultisigAddress ret = new MultisigAddress(addr, secSum);
|
||||
Multisig ret = new Multisig(addr, secSum);
|
||||
|
||||
params.release();
|
||||
retV8.release();
|
||||
@ -101,7 +98,7 @@ public class IotaFlashBridge {
|
||||
*
|
||||
* @param root
|
||||
*/
|
||||
public static CreateTransactionHelperObject updateLeafToRoot(MultisigAddress root) {
|
||||
public static CreateTransactionHelperObject updateLeafToRoot(Multisig root) {
|
||||
Map<String, Object> map = root.toMap();
|
||||
// Create param list
|
||||
List<Object> paramsObj = new ArrayList<Object>();
|
||||
@ -111,7 +108,7 @@ public class IotaFlashBridge {
|
||||
V8Object ret = multisig.executeObjectFunction("updateLeafToRoot", params);
|
||||
int generate = ret.getInteger("generate");
|
||||
V8Object multisigObject = (V8Object) ret.getObject("multisig");
|
||||
MultisigAddress multisig = V8Converter.multisigAddressFromV8Object(multisigObject);
|
||||
Multisig multisig = V8Converter.multisigAddressFromV8Object(multisigObject);
|
||||
return new CreateTransactionHelperObject(generate, multisig);
|
||||
}
|
||||
|
||||
@ -174,8 +171,8 @@ public class IotaFlashBridge {
|
||||
public static ArrayList<Bundle> compose(int balance,
|
||||
List<Double> deposits,
|
||||
ArrayList<Bundle> outputs,
|
||||
MultisigAddress root,
|
||||
MultisigAddress remainderAddress,
|
||||
Multisig root,
|
||||
Multisig remainderAddress,
|
||||
ArrayList<Bundle> history,
|
||||
ArrayList<Transfer> transfers,
|
||||
boolean close) {
|
||||
@ -203,7 +200,7 @@ public class IotaFlashBridge {
|
||||
* @param bundles
|
||||
* @return
|
||||
*/
|
||||
public static ArrayList<Signature> sign(MultisigAddress root, String seed, ArrayList<Bundle> bundles) {
|
||||
public static ArrayList<Signature> sign(Multisig root, String seed, ArrayList<Bundle> bundles) {
|
||||
|
||||
// Create params.
|
||||
// Now put all params into JS ready array.
|
||||
@ -256,10 +253,10 @@ public class IotaFlashBridge {
|
||||
* @param signedBundles
|
||||
* @return
|
||||
*/
|
||||
public static void applyTransfers(MultisigAddress root,
|
||||
public static void applyTransfers(Multisig root,
|
||||
ArrayList<Integer> deposits,
|
||||
ArrayList<Bundle> outputs,
|
||||
MultisigAddress remainderAddress,
|
||||
Multisig remainderAddress,
|
||||
ArrayList<Bundle> transfers,
|
||||
ArrayList<Bundle> signedBundles) {
|
||||
// Construct Java params
|
||||
|
||||
@ -2,7 +2,7 @@ package iotaFlashWrapper;
|
||||
|
||||
import iotaFlashWrapper.Model.Bundle;
|
||||
import iotaFlashWrapper.Model.Digest;
|
||||
import iotaFlashWrapper.Model.MultisigAddress;
|
||||
import iotaFlashWrapper.Model.Multisig;
|
||||
import iotaFlashWrapper.Model.Transfer;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@ -10,17 +10,17 @@ import java.util.List;
|
||||
|
||||
public interface IotaFlashInterface {
|
||||
// Multisig
|
||||
public MultisigAddress composeAddress(ArrayList<Digest> digests);
|
||||
public Multisig composeAddress(ArrayList<Digest> digests);
|
||||
|
||||
public void updateLeafToRoot(MultisigAddress root);
|
||||
public void updateLeafToRoot(Multisig root);
|
||||
|
||||
// Transfer
|
||||
public Object prepare(ArrayList<String> settlementAddresses, ArrayList<Integer> deposits, int index, ArrayList<Transfer> transfers);
|
||||
public List<Object> compose(int balance, ArrayList<Integer> deposits, ArrayList<Transfer> outputs, MultisigAddress root, String remainderAddress, ArrayList<Bundle> history, ArrayList<Transfer> transfers, boolean close);
|
||||
public List<Object> compose(int balance, ArrayList<Integer> deposits, ArrayList<Transfer> outputs, Multisig root, String remainderAddress, ArrayList<Bundle> history, ArrayList<Transfer> transfers, boolean close);
|
||||
|
||||
public Digest getDigest(String seed, int index, int security);
|
||||
|
||||
public Object sign(MultisigAddress root, String seed, ArrayList<Bundle> bundles);
|
||||
public Object sign(Multisig root, String seed, ArrayList<Bundle> bundles);
|
||||
public Object appliedSignatures(ArrayList<Object> bundles, ArrayList<Object> signatures);
|
||||
public Object getDiff(ArrayList<Object> root,
|
||||
ArrayList<Object> remainder,
|
||||
|
||||
@ -1,11 +1,9 @@
|
||||
package iotaFlashWrapper;
|
||||
|
||||
import com.sun.org.apache.xpath.internal.operations.Mult;
|
||||
import iotaFlashWrapper.Model.*;
|
||||
import jota.utils.Checksum;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
||||
public class Main {
|
||||
@ -17,10 +15,10 @@ public class Main {
|
||||
// Run a test based on the flash example
|
||||
// Link: https://github.com/iotaledger/iota.flash.js/blob/master/examples/flash.js
|
||||
|
||||
String oneSeed = "USERONEUSERONEUSERONEUSERONEUSERONEUSERONEUSERONEUSERONEUSERONEUSERONEUSERONEUSER";
|
||||
String oneSettlement = "USERONE9ADDRESS9USERONE9ADDRESS9USERONE9ADDRESS9USERONE9ADDRESS9USERONE9ADDRESS9U";
|
||||
String twoSeed = "USERTWOUSERTWOUSERTWOUSERTWOUSERTWOUSERTWOUSERTWOUSERTWOUSERTWOUSERTWOUSERTWOUSER";
|
||||
String twoSettlement = "USERTWO9ADDRESS9USERTWO9ADDRESS9USERTWO9ADDRESS9USERTWO9ADDRESS9USERTWO9ADDRESS9U";
|
||||
String oneSeed = "GXGIIGUTA9MCRLFMVGLAYBENVGOCWNXRCBQNYGMQKOZRRNSICRPXGONVOUTIMOGLUWSETZSRSYRRSBABR";
|
||||
String oneSettlement = "SFAMPVUSPED9NZIVRDNOVSOLNQ9QHZVHDEWBPTYEJJC9QUMOSUQUQWL9BBENVVEFSCQCVBEXHGPACHRVX";
|
||||
String twoSeed = "GXGIIGUTA9MCRLFMVGLAYBENVGOCWNXRCBQNYGMQKOZRRNSIIIIXGONVUOTIMOGLUWSETZSRSYRRSBABR";
|
||||
String twoSettlement = "9ZPQTA9UPWFW9NHX9SJ9EYPYYGMMZUDZHHYTVHKZHXKBMOCNTDIKRWFVBMFYEUL9IBIALHHNYZWBOEJHA";
|
||||
|
||||
//////////////////////////////////
|
||||
// INITIAL CHANNEL CONDITIONS
|
||||
@ -32,17 +30,17 @@ public class Main {
|
||||
// Flash tree depth
|
||||
int TREE_DEPTH = 4;
|
||||
// Total channel Balance
|
||||
int CHANNEL_BALANCE = 2000;
|
||||
int CHANNEL_BALANCE = 200;
|
||||
// Users deposits
|
||||
ArrayList<Double> DEPOSITS = new ArrayList<>();
|
||||
DEPOSITS.add(1000.0);
|
||||
DEPOSITS.add(1000.0);
|
||||
DEPOSITS.add(100.0);
|
||||
DEPOSITS.add(100.0);
|
||||
// Setup users.
|
||||
FlashObject oneFlashObj = new FlashObject(SIGNERS_COUNT, CHANNEL_BALANCE, DEPOSITS);
|
||||
UserObject oneFlash = new UserObject(0, oneSeed, TREE_DEPTH, SECURITY, oneFlashObj);
|
||||
UserObject oneFlash = new UserObject(0, oneSeed, TREE_DEPTH, SECURITY, oneSettlement, oneFlashObj);
|
||||
|
||||
FlashObject twoFlashObj = new FlashObject(SIGNERS_COUNT, CHANNEL_BALANCE, DEPOSITS);
|
||||
UserObject twoFlash = new UserObject(1, twoSeed, TREE_DEPTH, SECURITY, twoFlashObj);
|
||||
UserObject twoFlash = new UserObject(1, twoSeed, TREE_DEPTH, SECURITY, twoSettlement, twoFlashObj);
|
||||
|
||||
// USER ONE
|
||||
ArrayList<Digest> oneDigests = Helpers.getDigestsForUser(oneFlash, TREE_DEPTH);
|
||||
@ -65,10 +63,10 @@ public class Main {
|
||||
***************************************/
|
||||
|
||||
// Create multisigs.
|
||||
ArrayList<MultisigAddress> oneMultisigs = Helpers.getMultisigsForUser(allUserDigests, oneFlash);
|
||||
ArrayList<Multisig> oneMultisigs = Helpers.getMultisigsForUser(allUserDigests, oneFlash);
|
||||
|
||||
// Set renainder address.
|
||||
MultisigAddress oneRemainderAddr = oneMultisigs.remove(0); //shiftCopyArray();
|
||||
Multisig oneRemainderAddr = oneMultisigs.remove(0); //shiftCopyArray();
|
||||
oneFlash.getFlash().setRemainderAddress(oneRemainderAddr);
|
||||
|
||||
// Build flash trees
|
||||
@ -84,9 +82,9 @@ public class Main {
|
||||
User one setup.
|
||||
***************************************/
|
||||
|
||||
ArrayList<MultisigAddress> twoMultisigs = Helpers.getMultisigsForUser(allUserDigests, twoFlash);
|
||||
ArrayList<Multisig> twoMultisigs = Helpers.getMultisigsForUser(allUserDigests, twoFlash);
|
||||
// Set user two remainder addr.
|
||||
MultisigAddress twoRemainderAddr = twoMultisigs.remove(0);
|
||||
Multisig twoRemainderAddr = twoMultisigs.remove(0);
|
||||
twoFlash.getFlash().setRemainderAddress(twoRemainderAddr);
|
||||
|
||||
// Build flash trees
|
||||
@ -98,7 +96,7 @@ public class Main {
|
||||
|
||||
|
||||
/***************************************
|
||||
Setup tettlements.
|
||||
Setup settlements.
|
||||
***************************************/
|
||||
|
||||
ArrayList<String> settlementAddresses = new ArrayList<>();
|
||||
@ -120,6 +118,17 @@ public class Main {
|
||||
|
||||
System.out.println("Channel Setup completed!");
|
||||
|
||||
|
||||
|
||||
/***************************************
|
||||
Root address of channel.
|
||||
***************************************/
|
||||
|
||||
String multisgFulladdr = Checksum.addChecksum(oneFlash.getFlash().getRoot().getAddress());
|
||||
|
||||
System.out.println("[ROOT ADDR]:" + multisgFulladdr);
|
||||
|
||||
|
||||
/***************************************
|
||||
Create transactions.
|
||||
***************************************/
|
||||
@ -132,7 +141,7 @@ public class Main {
|
||||
ArrayList<Bundle> confirmedTransfers;
|
||||
|
||||
// Try to make 10 transfers.
|
||||
for (int i = 0; i < 10; i++) {
|
||||
for (int i = 0; i < 9; i++) {
|
||||
|
||||
// Create transaction helper and check if we need to add nodes
|
||||
CreateTransactionHelperObject helper = Helpers.getTransactionHelper(oneFlash.getFlash().getRoot());
|
||||
@ -149,20 +158,20 @@ public class Main {
|
||||
ArrayList<Digest> newTwoDigests = Helpers.getNewBranchDigests(twoFlash, helper.getGenerate());
|
||||
|
||||
// Now we can create new multisig addresses
|
||||
MultisigAddress multisigAddressOne = Helpers.getNewBranch(newOneDigests, newTwoDigests, oneFlash, helper.getAddress());
|
||||
MultisigAddress multisigAddressTwo = Helpers.getNewBranch(newOneDigests, newTwoDigests, twoFlash, helper.getAddress());
|
||||
Multisig multisigOne = Helpers.getNewBranch(newOneDigests, newTwoDigests, oneFlash, helper.getAddress());
|
||||
Multisig multisigTwo = Helpers.getNewBranch(newOneDigests, newTwoDigests, twoFlash, helper.getAddress());
|
||||
|
||||
// Find the multisig with the address and append new address to children
|
||||
Helpers.updateMultisigChildrenForUser(oneFlash, multisigAddressOne);
|
||||
Helpers.updateMultisigChildrenForUser(twoFlash, multisigAddressTwo);
|
||||
Helpers.updateMultisigChildrenForUser(oneFlash, multisigOne);
|
||||
Helpers.updateMultisigChildrenForUser(twoFlash, multisigTwo);
|
||||
|
||||
// Set the updated multisig as origin of the transaction.
|
||||
helper.setAddress(multisigAddressOne);
|
||||
helper.setAddress(multisigOne);
|
||||
}
|
||||
|
||||
// Create transfers.
|
||||
ArrayList<Transfer> transfers = new ArrayList<>();
|
||||
transfers.add(new Transfer(twoSettlement, 20));
|
||||
transfers.add(new Transfer(twoSettlement, 10));
|
||||
|
||||
// Create a transaction from a transfer.
|
||||
suggestedTransfer = Helpers.createTransaction(transfers, helper, oneFlash, false);
|
||||
@ -180,10 +189,17 @@ public class Main {
|
||||
System.out.println("[INFO] Signing transfers.");
|
||||
ArrayList<Bundle> signedBundlesOne = IotaFlashBridge.appliedSignatures(suggestedTransfer, userTwoSignatures);
|
||||
ArrayList<Bundle> signedBundlesTwo = IotaFlashBridge.appliedSignatures(suggestedTransfer, userTwoSignatures);
|
||||
applyTransfers(signedBundlesOne, oneFlash);
|
||||
applyTransfers(signedBundlesTwo, twoFlash);
|
||||
Helpers.applyTransfers(signedBundlesOne, oneFlash);
|
||||
Helpers.applyTransfers(signedBundlesTwo, twoFlash);
|
||||
|
||||
System.out.println("Transaction Applied! Transactable tokens: " + getFlashDeposits(oneFlash));
|
||||
|
||||
double oneBalance = getBalanceOfUser(oneFlash);
|
||||
double twoBalance = getBalanceOfUser(twoFlash);
|
||||
|
||||
System.out.println("Deposits");
|
||||
System.out.println("User one:" + oneBalance + ", deposits: " + oneFlash.getFlash().getDeposits() );
|
||||
System.out.println("User two:" + twoBalance + ", deposits: " + oneFlash.getFlash().getDeposits());
|
||||
}
|
||||
|
||||
|
||||
@ -202,23 +218,25 @@ public class Main {
|
||||
ArrayList<Digest> newTwoDigests = Helpers.getNewBranchDigests(twoFlash, closeHelper.getGenerate());
|
||||
|
||||
// Now we can create new multisig addresses
|
||||
MultisigAddress multisigAddressOne = Helpers.getNewBranch(newOneDigests, newTwoDigests, oneFlash, closeHelper.getAddress());
|
||||
MultisigAddress multisigAddressTwo = Helpers.getNewBranch(newOneDigests, newTwoDigests, twoFlash, closeHelper.getAddress());
|
||||
Multisig multisigOne = Helpers.getNewBranch(newOneDigests, newTwoDigests, oneFlash, closeHelper.getAddress());
|
||||
Multisig multisigTwo = Helpers.getNewBranch(newOneDigests, newTwoDigests, twoFlash, closeHelper.getAddress());
|
||||
|
||||
// Find the multisig with the address and append new address to children
|
||||
Helpers.updateMultisigChildrenForUser(oneFlash, multisigAddressOne);
|
||||
Helpers.updateMultisigChildrenForUser(twoFlash, multisigAddressTwo);
|
||||
Helpers.updateMultisigChildrenForUser(oneFlash, multisigOne);
|
||||
Helpers.updateMultisigChildrenForUser(twoFlash, multisigTwo);
|
||||
|
||||
// Set the updated multisig as origin of the transaction.
|
||||
closeHelper.setAddress(multisigAddressOne);
|
||||
closeHelper.setAddress(multisigOne);
|
||||
|
||||
|
||||
}
|
||||
|
||||
System.out.println("[INFO] Closing channel...");
|
||||
|
||||
// Create transfers.
|
||||
ArrayList<Transfer> closeTransfers = new ArrayList<>();
|
||||
closeTransfers.add(new Transfer(oneSettlement, 0));
|
||||
closeTransfers.add(new Transfer(twoSettlement, 0));
|
||||
closeTransfers.add(new Transfer(oneSettlement, 5));
|
||||
closeTransfers.add(new Transfer(twoSettlement, 5));
|
||||
suggestedTransfer = Helpers.createTransaction(closeTransfers, closeHelper, oneFlash, true);
|
||||
|
||||
System.out.println("[INFO] Created transfer suggestion.");
|
||||
@ -234,24 +252,16 @@ public class Main {
|
||||
System.out.println("[INFO] Signing transfers.");
|
||||
ArrayList<Bundle> signedBundlesOne = IotaFlashBridge.appliedSignatures(suggestedTransfer, userTwoSignatures);
|
||||
ArrayList<Bundle> signedBundlesTwo = IotaFlashBridge.appliedSignatures(suggestedTransfer, userTwoSignatures);
|
||||
applyTransfers(signedBundlesOne, oneFlash);
|
||||
applyTransfers(signedBundlesTwo, twoFlash);
|
||||
Helpers.applyTransfers(signedBundlesOne, oneFlash);
|
||||
Helpers.applyTransfers(signedBundlesTwo, twoFlash);
|
||||
|
||||
System.out.println("[INFO] Channel closed!");
|
||||
|
||||
System.out.println("[INFO] Final address:" + signedBundlesOne.get(0));
|
||||
Helpers.POWClosedBundle(signedBundlesTwo);
|
||||
|
||||
// System.out.println("[INFO] Final address:" + Attach signedBundlesOne);
|
||||
}
|
||||
|
||||
public static void applyTransfers(ArrayList<Bundle> signedBundles, UserObject user) {
|
||||
// Apply transfers to User ONE
|
||||
FlashObject newFlash = IotaFlashBridge.applyTransfersToUser(user, signedBundles);
|
||||
|
||||
// Set new flash object to user
|
||||
user.setFlash(newFlash);
|
||||
|
||||
// Save latest channel bundles
|
||||
user.setBundles(signedBundles);
|
||||
}
|
||||
|
||||
public static double getFlashDeposits(UserObject user) {
|
||||
double sum = 0;
|
||||
@ -261,14 +271,21 @@ public class Main {
|
||||
return sum;
|
||||
}
|
||||
|
||||
public static double getBalanceOfUser(UserObject user) {
|
||||
double balance = 0.0;
|
||||
ArrayList<Bundle> transfers = user.getBundles();
|
||||
if (transfers.size() == 0) {
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
/**
|
||||
* acceptTransfer applies signatures of a
|
||||
* @param bundles half signed transfers
|
||||
* @param signatures signatures of the second user
|
||||
*/
|
||||
public static void acceptTransfer(ArrayList<Bundle> bundles, ArrayList<Signature> signatures, UserObject user) {
|
||||
ArrayList<Bundle> signedBundles = IotaFlashBridge.appliedSignatures(bundles, signatures);
|
||||
applyTransfers(signedBundles, user);
|
||||
for (Bundle bundle : transfers) {
|
||||
for (Transaction tx : bundle.getWrappedTransactions()) {
|
||||
if (tx.getAddress().equals(user.getAddress())) {
|
||||
balance += tx.getValue() / 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return balance;
|
||||
}
|
||||
}
|
||||
|
||||
@ -5,27 +5,45 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class Bundle {
|
||||
private ArrayList<Transaction> bundles;
|
||||
public class Bundle extends jota.model.Bundle {
|
||||
private List<Transaction> wrappedTransactions = new ArrayList<>();
|
||||
|
||||
public Bundle(ArrayList<Transaction> bundles) {
|
||||
this.bundles = bundles;
|
||||
public Bundle(List<Transaction> transactions) {
|
||||
super((ArrayList<jota.model.Transaction>) (ArrayList<? extends jota.model.Transaction>) transactions, transactions.size());
|
||||
}
|
||||
|
||||
public Bundle() {
|
||||
this.bundles = new ArrayList<>();
|
||||
super();
|
||||
}
|
||||
|
||||
public List<Transaction> getWrappedTransactions() {
|
||||
return wrappedTransactions;
|
||||
}
|
||||
|
||||
public void setWrappedTransactions(List<Transaction> wrappedTransactions) {
|
||||
this.wrappedTransactions = wrappedTransactions;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
String out = "";
|
||||
for (Transaction t: bundles) {
|
||||
for (Transaction t: getWrappedTransactions()) {
|
||||
out += t.toString();
|
||||
out += "\n";
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
public String[] toTrytesArray() {
|
||||
String[] bundleTrytes = new String[getTransactions().size()];
|
||||
List<jota.model.Transaction> transactions = getTransactions();
|
||||
for (int i = 0; i < bundleTrytes.length; i++) {
|
||||
bundleTrytes[i] = transactions.get(i).toTrytes();
|
||||
}
|
||||
|
||||
return bundleTrytes;
|
||||
}
|
||||
|
||||
public Map<String, Object> toMap() {
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
|
||||
@ -35,19 +53,15 @@ public class Bundle {
|
||||
|
||||
public List<Object> toArrayList() {
|
||||
List<Object> bundleList = new ArrayList<Object>();
|
||||
for (Transaction b: bundles) {
|
||||
for (Transaction b: getWrappedTransactions()) {
|
||||
bundleList.add(b.toMap());
|
||||
}
|
||||
return bundleList;
|
||||
}
|
||||
|
||||
public ArrayList<Transaction> getBundles() {
|
||||
return bundles;
|
||||
}
|
||||
|
||||
public Bundle clone() {
|
||||
public Bundle clone() {
|
||||
ArrayList<Transaction> clonedTransactions = new ArrayList<>();
|
||||
for (Transaction t: bundles) {
|
||||
for (Transaction t: getWrappedTransactions()) {
|
||||
clonedTransactions.add(t.clone());
|
||||
}
|
||||
return new Bundle(clonedTransactions);
|
||||
|
||||
@ -2,9 +2,9 @@ package iotaFlashWrapper.Model;
|
||||
|
||||
public class CreateTransactionHelperObject {
|
||||
private int generate = 0;
|
||||
private MultisigAddress address;
|
||||
private Multisig address;
|
||||
|
||||
public CreateTransactionHelperObject(int gen, MultisigAddress addr) {
|
||||
public CreateTransactionHelperObject(int gen, Multisig addr) {
|
||||
this.generate = gen;
|
||||
this.address = addr;
|
||||
}
|
||||
@ -13,11 +13,11 @@ public class CreateTransactionHelperObject {
|
||||
return generate;
|
||||
}
|
||||
|
||||
public MultisigAddress getAddress() {
|
||||
public Multisig getAddress() {
|
||||
return address;
|
||||
}
|
||||
|
||||
public void setAddress(MultisigAddress address) {
|
||||
public void setAddress(Multisig address) {
|
||||
this.address = address;
|
||||
}
|
||||
}
|
||||
@ -17,7 +17,6 @@ public class Digest {
|
||||
public int getIndex() {
|
||||
return index;
|
||||
}
|
||||
|
||||
public String getDigest() {
|
||||
return digest;
|
||||
}
|
||||
|
||||
@ -11,8 +11,8 @@ public class FlashObject {
|
||||
ArrayList<Double> deposits;
|
||||
ArrayList<Bundle> outputs = new ArrayList<Bundle>();
|
||||
ArrayList<Bundle> transfers = new ArrayList<Bundle>();
|
||||
MultisigAddress root;
|
||||
MultisigAddress remainderAddress;
|
||||
Multisig root;
|
||||
Multisig remainderAddress;
|
||||
|
||||
|
||||
public FlashObject(int signersCount, int balance, ArrayList<Double> deposits) {
|
||||
@ -21,7 +21,7 @@ public class FlashObject {
|
||||
this.deposits = deposits;
|
||||
}
|
||||
|
||||
public FlashObject(int signersCount, int balance, ArrayList<String> settlementAddresses, ArrayList<Double> deposits, ArrayList<Bundle> outputs, ArrayList<Bundle> transfers, MultisigAddress root, MultisigAddress remainderAddress) {
|
||||
public FlashObject(int signersCount, int balance, ArrayList<String> settlementAddresses, ArrayList<Double> deposits, ArrayList<Bundle> outputs, ArrayList<Bundle> transfers, Multisig root, Multisig remainderAddress) {
|
||||
this.signersCount = signersCount;
|
||||
this.balance = balance;
|
||||
this.settlementAddresses = settlementAddresses;
|
||||
@ -94,7 +94,7 @@ public class FlashObject {
|
||||
return balance;
|
||||
}
|
||||
|
||||
public MultisigAddress getRoot() {
|
||||
public Multisig getRoot() {
|
||||
return root;
|
||||
}
|
||||
|
||||
@ -110,15 +110,15 @@ public class FlashObject {
|
||||
return transfers;
|
||||
}
|
||||
|
||||
public void setRemainderAddress(MultisigAddress remainderAddress) {
|
||||
public void setRemainderAddress(Multisig remainderAddress) {
|
||||
this.remainderAddress = remainderAddress;
|
||||
}
|
||||
|
||||
public MultisigAddress getRemainderAddress() {
|
||||
public Multisig getRemainderAddress() {
|
||||
return remainderAddress;
|
||||
}
|
||||
|
||||
public void setRoot(MultisigAddress root) {
|
||||
public void setRoot(Multisig root) {
|
||||
this.root = root;
|
||||
}
|
||||
|
||||
|
||||
@ -3,7 +3,6 @@ package iotaFlashWrapper.Model;
|
||||
import com.eclipsesource.v8.V8;
|
||||
import com.eclipsesource.v8.V8Object;
|
||||
import com.eclipsesource.v8.utils.V8ObjectUtils;
|
||||
import com.sun.org.apache.xpath.internal.operations.Mult;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
@ -11,35 +10,35 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
public class MultisigAddress {
|
||||
public class Multisig {
|
||||
private String address;
|
||||
private int securitySum;
|
||||
private int index;
|
||||
private int signingIndex;
|
||||
private int security = 2;
|
||||
private ArrayList<MultisigAddress> children;
|
||||
private ArrayList<Multisig> children;
|
||||
private ArrayList<Bundle> bundles;
|
||||
|
||||
public MultisigAddress(String address, int securitySum) {
|
||||
public Multisig(String address, int securitySum) {
|
||||
this.address = address;
|
||||
this.securitySum = securitySum;
|
||||
this.children = new ArrayList<MultisigAddress>();
|
||||
this.children = new ArrayList<Multisig>();
|
||||
this.bundles = new ArrayList<Bundle>();
|
||||
}
|
||||
|
||||
public MultisigAddress(String address, int securitySum, ArrayList<MultisigAddress> children) {
|
||||
public Multisig(String address, int securitySum, ArrayList<Multisig> children) {
|
||||
this.address = address;
|
||||
this.securitySum = securitySum;
|
||||
this.children = children;
|
||||
this.bundles = new ArrayList<Bundle>();
|
||||
}
|
||||
|
||||
public MultisigAddress find(String address) {
|
||||
public Multisig find(String address) {
|
||||
if (getAddress().equals(address)) {
|
||||
return this;
|
||||
} else {
|
||||
for (MultisigAddress mult: getChildren()) {
|
||||
MultisigAddress result = mult.find(address);
|
||||
for (Multisig mult: getChildren()) {
|
||||
Multisig result = mult.find(address);
|
||||
if (result != null) {
|
||||
return result;
|
||||
}
|
||||
@ -48,8 +47,8 @@ public class MultisigAddress {
|
||||
return null;
|
||||
}
|
||||
|
||||
public MultisigAddress clone() {
|
||||
MultisigAddress output = new MultisigAddress(this.getAddress(), this.getSecuritySum());
|
||||
public Multisig clone() {
|
||||
Multisig output = new Multisig(this.getAddress(), this.getSecuritySum());
|
||||
|
||||
output.setSecurity(this.getSecurity());
|
||||
output.setIndex(this.getIndex());
|
||||
@ -62,19 +61,19 @@ public class MultisigAddress {
|
||||
output.setBundles(bundleCopy);
|
||||
|
||||
// Copy all children
|
||||
ArrayList<MultisigAddress> childrenCopy = new ArrayList<>();
|
||||
for (MultisigAddress child : this.getChildren()) {
|
||||
ArrayList<Multisig> childrenCopy = new ArrayList<>();
|
||||
for (Multisig child : this.getChildren()) {
|
||||
childrenCopy.add(child.clone());
|
||||
}
|
||||
output.setChildren(childrenCopy);
|
||||
return output;
|
||||
}
|
||||
|
||||
public void push(MultisigAddress addr) {
|
||||
public void push(Multisig addr) {
|
||||
children.add(addr);
|
||||
}
|
||||
|
||||
public ArrayList<MultisigAddress> getChildren() {
|
||||
public ArrayList<Multisig> getChildren() {
|
||||
return children;
|
||||
}
|
||||
|
||||
@ -93,7 +92,7 @@ public class MultisigAddress {
|
||||
this.address = address;
|
||||
}
|
||||
|
||||
public void setChildren(ArrayList<MultisigAddress> children) {
|
||||
public void setChildren(ArrayList<Multisig> children) {
|
||||
this.children = children;
|
||||
}
|
||||
|
||||
@ -137,7 +136,7 @@ public class MultisigAddress {
|
||||
map.put("signingIndex", getSigningIndex());
|
||||
map.put("security", security);
|
||||
List<Object> childrenList = new ArrayList<Object>();
|
||||
for (MultisigAddress ma: children) {
|
||||
for (Multisig ma: children) {
|
||||
childrenList.add(ma.toMap());
|
||||
}
|
||||
map.put("children", childrenList);
|
||||
@ -158,7 +157,7 @@ public class MultisigAddress {
|
||||
@Override
|
||||
public String toString() {
|
||||
String out = "{ \n address':'" + address + "' \n, securitySum:" + securitySum + "\n, signingIndex: " + signingIndex + " \n";
|
||||
for (MultisigAddress addr: children) {
|
||||
for (Multisig addr: children) {
|
||||
out += addr.toString();
|
||||
}
|
||||
return out;
|
||||
@ -8,56 +8,17 @@ import java.util.List;
|
||||
*
|
||||
* @author Adrian
|
||||
**/
|
||||
public class Signature {
|
||||
public class Signature extends jota.model.Signature {
|
||||
private int index;
|
||||
private String bundle;
|
||||
private String address;
|
||||
private List<String> signatureFragments;
|
||||
|
||||
/**
|
||||
* Initializes a new instance of the Signature class.
|
||||
*/
|
||||
public Signature() {
|
||||
this.signatureFragments = new ArrayList<>();
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the address.
|
||||
*
|
||||
* @return The address.
|
||||
*/
|
||||
public String getAddress() {
|
||||
return address;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the address.
|
||||
*
|
||||
* @param address The address.
|
||||
*/
|
||||
public void setAddress(String address) {
|
||||
this.address = address;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the signatureFragments.
|
||||
*
|
||||
* @return The signatureFragments.
|
||||
*/
|
||||
public List<String> getSignatureFragments() {
|
||||
return signatureFragments;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the signatureFragments.
|
||||
*
|
||||
* @param signatureFragments The signatureFragments.
|
||||
*/
|
||||
public void setSignatureFragments(List<String> signatureFragments) {
|
||||
this.signatureFragments = signatureFragments;
|
||||
}
|
||||
|
||||
|
||||
public int getIndex() {
|
||||
return index;
|
||||
}
|
||||
@ -79,10 +40,10 @@ public class Signature {
|
||||
String out = "{ \n" +
|
||||
" \tindex:" + index + ", " +
|
||||
" \n\tbundle: " + bundle + ", " +
|
||||
" \n\taddress:" + address + ",";
|
||||
" \n\taddress:" + getAddress() + ",";
|
||||
|
||||
out += "\n\t[ \n";
|
||||
for (String sf : signatureFragments) {
|
||||
for (String sf : getSignatureFragments()) {
|
||||
out += "\n\t" + sf + ",";
|
||||
}
|
||||
out += " ]";
|
||||
|
||||
@ -3,116 +3,78 @@ package iotaFlashWrapper.Model;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class Transaction {
|
||||
private String hash;
|
||||
private String signatureFragments;
|
||||
private String address;
|
||||
private long value;
|
||||
private String obsoleteTag;
|
||||
private long timestamp;
|
||||
private long currentIndex;
|
||||
private long lastIndex;
|
||||
private String bundle;
|
||||
private String trunkTransaction;
|
||||
private String branchTransaction;
|
||||
private String nonce;
|
||||
private Boolean persistence;
|
||||
private long attachmentTimestamp;
|
||||
private String tag;
|
||||
private long attachmentTimestampLowerBound;
|
||||
private long attachmentTimestampUpperBound;
|
||||
|
||||
public class Transaction extends jota.model.Transaction {
|
||||
|
||||
// Unsigned constructor
|
||||
public Transaction(String address, int value, String obsoleteTag, String tag, Integer timestamp) {
|
||||
this.address = address;
|
||||
this.value = value;
|
||||
this.obsoleteTag = obsoleteTag;
|
||||
this.tag = tag;
|
||||
this.timestamp = timestamp;
|
||||
public Transaction(String address, long value, String obsoleteTag, String tag, long timestamp) {
|
||||
super(address, value, tag, timestamp);
|
||||
}
|
||||
|
||||
public Transaction(String signatureFragments, Long currentIndex, Long lastIndex, String nonce,
|
||||
String hash, String obsoleteTag, Long timestamp, String trunkTransaction,
|
||||
String branchTransaction, String address, Long value, String bundle, String tag,
|
||||
Long attachmentTimestamp, Long attachmentTimestampLowerBound, Long attachmentTimestampUpperBound) {
|
||||
|
||||
this.hash = hash;
|
||||
this.obsoleteTag = obsoleteTag;
|
||||
this.signatureFragments = signatureFragments;
|
||||
this.address = address;
|
||||
this.value = value;
|
||||
this.timestamp = timestamp;
|
||||
this.currentIndex = currentIndex;
|
||||
this.lastIndex = lastIndex;
|
||||
this.bundle = bundle;
|
||||
this.trunkTransaction = trunkTransaction;
|
||||
this.branchTransaction = branchTransaction;
|
||||
this.tag = tag;
|
||||
this.attachmentTimestamp = attachmentTimestamp;
|
||||
this.attachmentTimestampLowerBound = attachmentTimestampLowerBound;
|
||||
this.attachmentTimestampUpperBound = attachmentTimestampUpperBound;
|
||||
this.nonce = nonce;
|
||||
}
|
||||
|
||||
|
||||
public String getSignatureFragments() {
|
||||
return signatureFragments;
|
||||
}
|
||||
|
||||
public void setSignatureFragments(String signatureFragments) {
|
||||
this.signatureFragments = signatureFragments;
|
||||
}
|
||||
|
||||
public long getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public String getAddress() {
|
||||
return address;
|
||||
super(
|
||||
signatureFragments,
|
||||
currentIndex,
|
||||
lastIndex,
|
||||
nonce,
|
||||
hash,
|
||||
obsoleteTag,
|
||||
timestamp,
|
||||
trunkTransaction,
|
||||
branchTransaction,
|
||||
address,
|
||||
value,
|
||||
bundle,
|
||||
tag,
|
||||
attachmentTimestamp,
|
||||
attachmentTimestampLowerBound,
|
||||
attachmentTimestampUpperBound
|
||||
);
|
||||
}
|
||||
|
||||
public Map<String, Object> toMap() {
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
if (hash != null && !hash.equals("")) {
|
||||
map.put("hash", hash);
|
||||
if (getHash() != null && !getHash().equals("")) {
|
||||
map.put("hash", getHash());
|
||||
}
|
||||
map.put("signatureMessageFragment", signatureFragments);
|
||||
map.put("address", address);
|
||||
map.put("value", value);
|
||||
map.put("obsoleteTag", obsoleteTag);
|
||||
map.put("currentIndex", currentIndex);
|
||||
map.put("timestamp", timestamp);
|
||||
map.put("lastIndex", lastIndex);
|
||||
map.put("bundle", bundle);
|
||||
map.put("trunkTransaction", trunkTransaction);
|
||||
map.put("branchTransaction", branchTransaction);
|
||||
map.put("nonce", nonce);
|
||||
map.put("attachmentTimestamp", String.valueOf(attachmentTimestamp));
|
||||
map.put("tag", tag);
|
||||
map.put("attachmentTimestampLowerBound", String.valueOf(attachmentTimestampLowerBound));
|
||||
map.put("attachmentTimestampUpperBound", String.valueOf(attachmentTimestampUpperBound));
|
||||
map.put("signatureMessageFragment", getSignatureFragments());
|
||||
map.put("address", getAddress());
|
||||
map.put("value", getValue());
|
||||
map.put("obsoleteTag", getObsoleteTag());
|
||||
map.put("currentIndex", getCurrentIndex());
|
||||
map.put("timestamp", getTimestamp());
|
||||
map.put("lastIndex", getLastIndex());
|
||||
map.put("bundle", getBundle());
|
||||
map.put("trunkTransaction", getTrunkTransaction());
|
||||
map.put("branchTransaction", getBranchTransaction());
|
||||
map.put("nonce", getNonce());
|
||||
map.put("attachmentTimestamp", String.valueOf(getAttachmentTimestamp()));
|
||||
map.put("tag", getTag());
|
||||
map.put("attachmentTimestampLowerBound", String.valueOf(getAttachmentTimestampLowerBound()));
|
||||
map.put("attachmentTimestampUpperBound", String.valueOf(getAttachmentTimestampUpperBound()));
|
||||
return map;
|
||||
}
|
||||
|
||||
public Transaction clone() {
|
||||
return new Transaction(
|
||||
this.signatureFragments,
|
||||
this.currentIndex,
|
||||
this.lastIndex,
|
||||
this.nonce,
|
||||
this.hash,
|
||||
this.obsoleteTag,
|
||||
this.timestamp,
|
||||
this.trunkTransaction,
|
||||
this.branchTransaction,
|
||||
this.address,
|
||||
this.value,
|
||||
this.bundle,
|
||||
this.tag,
|
||||
this.attachmentTimestamp,
|
||||
this.attachmentTimestampLowerBound,
|
||||
this.attachmentTimestampUpperBound
|
||||
this.getSignatureFragments(),
|
||||
this.getCurrentIndex(),
|
||||
this.getLastIndex(),
|
||||
this.getNonce(),
|
||||
this.getHash(),
|
||||
this.getObsoleteTag(),
|
||||
this.getTimestamp(),
|
||||
this.getTrunkTransaction(),
|
||||
this.getBranchTransaction(),
|
||||
this.getAddress(),
|
||||
this.getValue(),
|
||||
this.getBundle(),
|
||||
this.getTag(),
|
||||
this.getAttachmentTimestamp(),
|
||||
this.getAttachmentTimestampLowerBound(),
|
||||
this.getAttachmentTimestampUpperBound()
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@ -10,17 +10,19 @@ public class UserObject {
|
||||
private int index = 0;
|
||||
private int security;
|
||||
private int depth;
|
||||
private String address;
|
||||
private ArrayList<Bundle> bundles = new ArrayList<Bundle>();
|
||||
private ArrayList<Digest> partialDigests = new ArrayList<Digest>();
|
||||
private ArrayList<MultisigAddress> multisigDigests = new ArrayList<MultisigAddress>();
|
||||
private ArrayList<Multisig> multisigDigests = new ArrayList<Multisig>();
|
||||
private FlashObject flash;
|
||||
|
||||
public UserObject(int userID, String seed, int depth, int security, FlashObject flash) {
|
||||
public UserObject(int userID, String seed, int depth, int security, String address, FlashObject flash) {
|
||||
this.userIndex = userID;
|
||||
this.seed = seed;
|
||||
this.depth = depth;
|
||||
this.security = security;
|
||||
this.flash = flash;
|
||||
this.address = address;
|
||||
}
|
||||
|
||||
public int incrementIndex() {
|
||||
@ -49,7 +51,7 @@ public class UserObject {
|
||||
out += "\t" + d.toString() + "\n";
|
||||
}
|
||||
out += "multisigDigests: " + "\n";
|
||||
for (MultisigAddress m: multisigDigests) {
|
||||
for (Multisig m: multisigDigests) {
|
||||
out += "\t" + m.toString() + "\n";
|
||||
}
|
||||
out += "Flash: " + "\n";
|
||||
@ -92,7 +94,7 @@ public class UserObject {
|
||||
* Getters and Setters
|
||||
*/
|
||||
|
||||
public void setMultisigDigests(ArrayList<MultisigAddress> multisigDigests) {
|
||||
public void setMultisigDigests(ArrayList<Multisig> multisigDigests) {
|
||||
this.multisigDigests = multisigDigests;
|
||||
}
|
||||
|
||||
@ -108,7 +110,7 @@ public class UserObject {
|
||||
this.bundles = bundles;
|
||||
}
|
||||
|
||||
public ArrayList<MultisigAddress> getMultisigDigests() {
|
||||
public ArrayList<Multisig> getMultisigDigests() {
|
||||
return multisigDigests;
|
||||
}
|
||||
|
||||
@ -140,5 +142,12 @@ public class UserObject {
|
||||
return flash;
|
||||
}
|
||||
|
||||
public int getDepth() {
|
||||
return depth;
|
||||
}
|
||||
|
||||
public String getAddress() {
|
||||
return address;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -3,7 +3,6 @@ package iotaFlashWrapper;
|
||||
import com.eclipsesource.v8.V8;
|
||||
import com.eclipsesource.v8.V8Array;
|
||||
import com.eclipsesource.v8.V8Object;
|
||||
import com.eclipsesource.v8.V8ResultUndefined;
|
||||
import com.eclipsesource.v8.utils.V8ObjectUtils;
|
||||
import iotaFlashWrapper.Model.*;
|
||||
|
||||
@ -36,7 +35,7 @@ public class V8Converter {
|
||||
return signatures;
|
||||
}
|
||||
|
||||
public static V8Object multisigToV8Object(V8 engine, MultisigAddress multisig) {
|
||||
public static V8Object multisigToV8Object(V8 engine, Multisig multisig) {
|
||||
Map<String, Object> sigMapg = multisig.toMap();
|
||||
return V8ObjectUtils.toV8Object(engine, sigMapg);
|
||||
}
|
||||
@ -51,8 +50,8 @@ public class V8Converter {
|
||||
Integer singersCount = (Integer) inputMap.get("signersCount");
|
||||
Integer balance = (Integer) inputMap.get("balance");
|
||||
ArrayList<String> settlementAddresses = (ArrayList<String>) inputMap.get("settlementAddresses");
|
||||
MultisigAddress root = multisigAddressFromPropertyMap((Map<String, Object>) inputMap.get("root"));
|
||||
MultisigAddress remainderAddress = multisigAddressFromPropertyMap((Map<String, Object>) inputMap.get("remainderAddress"));
|
||||
Multisig root = multisigAddressFromPropertyMap((Map<String, Object>) inputMap.get("root"));
|
||||
Multisig remainderAddress = multisigAddressFromPropertyMap((Map<String, Object>) inputMap.get("remainderAddress"));
|
||||
ArrayList<Double> deposits = new ArrayList<>();
|
||||
if (inputMap.get("deposits") instanceof ArrayList) {
|
||||
Object depositEntry = inputMap.get("deposits");
|
||||
@ -75,8 +74,8 @@ public class V8Converter {
|
||||
List<Object> bundleTmp = new ArrayList<Object>();
|
||||
for (Bundle b: bundles) {
|
||||
List<Object> transactions = new ArrayList<Object>();
|
||||
for (Transaction t: b.getBundles()) {
|
||||
transactions.add(t.toMap());
|
||||
for (jota.model.Transaction tx: b.getTransactions()) {
|
||||
transactions.add(((Transaction) tx).toMap());
|
||||
}
|
||||
bundleTmp.add(transactions);
|
||||
}
|
||||
@ -112,7 +111,7 @@ public class V8Converter {
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static MultisigAddress multisigAddressFromV8Object(V8Object input) {
|
||||
public static Multisig multisigAddressFromV8Object(V8Object input) {
|
||||
if (input.isUndefined()) {
|
||||
System.out.println("[ERROR]: could not parse object");
|
||||
return null;
|
||||
@ -121,19 +120,19 @@ public class V8Converter {
|
||||
return multisigAddressFromPropertyMap(multiSigMap);
|
||||
}
|
||||
|
||||
public static MultisigAddress multisigAddressFromPropertyMap(Map<String, Object> propMap) {
|
||||
public static Multisig multisigAddressFromPropertyMap(Map<String, Object> propMap) {
|
||||
// Parse result into Java Obj.
|
||||
String addr = (String) propMap.get("address");
|
||||
int secSum = (Integer) propMap.get("securitySum");
|
||||
|
||||
ArrayList<MultisigAddress> children = new ArrayList<>();
|
||||
ArrayList<Multisig> children = new ArrayList<>();
|
||||
|
||||
for (Object child: (ArrayList<Object>) propMap.get("children")) {
|
||||
Map<String, ? super Object> childPropMap = (Map<String, ? super Object>) child;
|
||||
children.add(multisigAddressFromPropertyMap(childPropMap));
|
||||
}
|
||||
|
||||
MultisigAddress multisig = new MultisigAddress(addr, secSum, children);
|
||||
Multisig multisig = new Multisig(addr, secSum, children);
|
||||
|
||||
if (propMap.get("bundles") instanceof ArrayList) {
|
||||
ArrayList<Bundle> bundles = new ArrayList<>();
|
||||
@ -143,7 +142,7 @@ public class V8Converter {
|
||||
continue;
|
||||
} else {
|
||||
for (Object transactionMap: (ArrayList<Object>) bundle) {
|
||||
b.getBundles().add(transactionFromObject(transactionMap));
|
||||
b.getWrappedTransactions().add(transactionFromObject(transactionMap));
|
||||
}
|
||||
}
|
||||
bundles.add(b);
|
||||
|
||||
@ -10343,6 +10343,7 @@ function applyTransfers(root, deposit, outputs, remainder, history, transfers) {
|
||||
let remaining = deposit.reduce((a,b) => a+b, 0);
|
||||
let total = diff.filter(v => v.value > 0).reduce((acc,tx) => acc + tx.value, 0);
|
||||
if (total > remaining) {
|
||||
console.log("NO FUNDS")
|
||||
throw new Error(TransferErrors.INSUFFICIENT_FUNDS);
|
||||
}
|
||||
const depositTotal = deposit.reduce((acc, d) => acc + d, 0);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user