mirror of
https://github.com/gosticks/iota.flash.js-java-wrapper.git
synced 2025-10-16 11:45:40 +00:00
Fixed not storing outputs and transactions missing.
This commit is contained in:
parent
5aeda2b172
commit
f572d831e0
@ -57,17 +57,12 @@ public class IotaFlashBridge {
|
||||
V8Array params = V8ObjectUtils.toV8Array(engine, paramsList);
|
||||
|
||||
V8Object retV8 = multisig.executeObjectFunction("composeAddress", params);
|
||||
|
||||
// Parse return values from JS into Java world.
|
||||
Map<String, ? super Object> resultMap = V8ObjectUtils.toMap(retV8);
|
||||
// Parse result into Java Obj.
|
||||
String addr = (String) resultMap.get("address");
|
||||
int secSum = (Integer) resultMap.get("securitySum");
|
||||
Multisig ret = new Multisig(addr, secSum);
|
||||
// Create multisig.
|
||||
Multisig multisig = V8Converter.multisigAddressFromV8Object(retV8);
|
||||
|
||||
params.release();
|
||||
retV8.release();
|
||||
return ret;
|
||||
return multisig;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -121,7 +116,7 @@ public class IotaFlashBridge {
|
||||
* @param transfers array of all transfers (value, address) pairs
|
||||
* @return
|
||||
*/
|
||||
public static ArrayList<Transfer> prepare(ArrayList<String> settlementAddresses, ArrayList<Double> deposits, int index, ArrayList<Transfer> transfers) {
|
||||
public static ArrayList<Transfer> prepare(List<String> settlementAddresses, List<Double> deposits, int index, List<Transfer> transfers) {
|
||||
|
||||
// Now put all params into JS ready array.
|
||||
List<Object> params = new ArrayList<>();
|
||||
@ -142,7 +137,7 @@ public class IotaFlashBridge {
|
||||
* @param deposits
|
||||
* @return
|
||||
*/
|
||||
public static ArrayList<Transfer> close(ArrayList<String> settlementAddresses, ArrayList<Double> deposits) {
|
||||
public static ArrayList<Transfer> close(List<String> settlementAddresses, List<Double> deposits) {
|
||||
V8Array saJS = V8ObjectUtils.toV8Array(engine, settlementAddresses);
|
||||
// Deposits
|
||||
V8Array depositsJS = V8ObjectUtils.toV8Array(engine, deposits);
|
||||
@ -170,18 +165,18 @@ public class IotaFlashBridge {
|
||||
*/
|
||||
public static ArrayList<Bundle> compose(int balance,
|
||||
List<Double> deposits,
|
||||
ArrayList<Bundle> outputs,
|
||||
Map<String, Integer> outputs,
|
||||
Multisig root,
|
||||
Multisig remainderAddress,
|
||||
ArrayList<Bundle> history,
|
||||
ArrayList<Transfer> transfers,
|
||||
List<Bundle> history,
|
||||
List<Transfer> transfers,
|
||||
boolean close) {
|
||||
// Create params.
|
||||
// Now put all params into JS ready array.
|
||||
List<Object> params = new ArrayList<Object>();
|
||||
params.add(balance);
|
||||
params.add(V8ObjectUtils.toV8Array(engine, deposits));
|
||||
params.add(V8Converter.bundleListToV8Array(engine, outputs));
|
||||
params.add(V8ObjectUtils.toV8Object(engine, outputs));
|
||||
params.add(V8Converter.multisigToV8Object(engine, root));
|
||||
params.add(V8Converter.multisigToV8Object(engine, remainderAddress));
|
||||
params.add(V8Converter.bundleListToV8Array(engine, history));
|
||||
|
||||
@ -1,33 +1,29 @@
|
||||
package iotaFlashWrapper.Model;
|
||||
|
||||
import iotaFlashWrapper.Helpers;
|
||||
import iotaFlashWrapper.V8Converter;
|
||||
import jota.model.Transaction;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class Bundle extends jota.model.Bundle {
|
||||
private List<Transaction> wrappedTransactions = new ArrayList<>();
|
||||
|
||||
public Bundle(List<Transaction> transactions) {
|
||||
super((ArrayList<jota.model.Transaction>) (ArrayList<? extends jota.model.Transaction>) transactions, transactions.size());
|
||||
super(transactions, transactions.size());
|
||||
}
|
||||
|
||||
public Bundle() {
|
||||
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: getWrappedTransactions()) {
|
||||
for (Transaction t: getTransactions()) {
|
||||
out += t.toString();
|
||||
out += "\n";
|
||||
}
|
||||
@ -38,7 +34,7 @@ public class Bundle extends jota.model.Bundle {
|
||||
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();
|
||||
bundleTrytes[(bundleTrytes.length - 1) - i] = transactions.get(i).toTrytes();
|
||||
}
|
||||
|
||||
return bundleTrytes;
|
||||
@ -53,16 +49,16 @@ public class Bundle extends jota.model.Bundle {
|
||||
|
||||
public List<Object> toArrayList() {
|
||||
List<Object> bundleList = new ArrayList<Object>();
|
||||
for (Transaction b: getWrappedTransactions()) {
|
||||
bundleList.add(b.toMap());
|
||||
for (Transaction tx: getTransactions()) {
|
||||
bundleList.add(V8Converter.transactionToMap(tx));
|
||||
}
|
||||
return bundleList;
|
||||
}
|
||||
|
||||
public Bundle clone() {
|
||||
ArrayList<Transaction> clonedTransactions = new ArrayList<>();
|
||||
for (Transaction t: getWrappedTransactions()) {
|
||||
clonedTransactions.add(t.clone());
|
||||
for (Transaction tx: getTransactions()) {
|
||||
clonedTransactions.add(Helpers.cloneTransaction(tx));
|
||||
}
|
||||
return new Bundle(clonedTransactions);
|
||||
}
|
||||
|
||||
@ -1,27 +1,30 @@
|
||||
package iotaFlashWrapper.Model;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import com.eclipsesource.v8.utils.V8ObjectUtils;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class FlashObject {
|
||||
int signersCount = 2;
|
||||
int balance;
|
||||
ArrayList<String> settlementAddresses;
|
||||
ArrayList<Double> deposits;
|
||||
ArrayList<Bundle> outputs = new ArrayList<Bundle>();
|
||||
ArrayList<Bundle> transfers = new ArrayList<Bundle>();
|
||||
List<String> settlementAddresses;
|
||||
List<Double> deposits;
|
||||
Map<String, Integer> outputs = new HashMap<>();
|
||||
List<Bundle> transfers = new ArrayList<Bundle>();
|
||||
Multisig root;
|
||||
Multisig remainderAddress;
|
||||
|
||||
|
||||
public FlashObject(int signersCount, int balance, ArrayList<Double> deposits) {
|
||||
public FlashObject(int signersCount, int balance, double[] deposits) {
|
||||
this.signersCount = signersCount;
|
||||
this.balance = balance;
|
||||
this.deposits = deposits;
|
||||
this.deposits = new ArrayList<>();
|
||||
for (double deposit : deposits){
|
||||
this.deposits.add(deposit);
|
||||
}
|
||||
}
|
||||
|
||||
public FlashObject(int signersCount, int balance, ArrayList<String> settlementAddresses, ArrayList<Double> deposits, ArrayList<Bundle> outputs, ArrayList<Bundle> transfers, Multisig root, Multisig remainderAddress) {
|
||||
public FlashObject(int signersCount, int balance, List<String> settlementAddresses, List<Double> deposits, Map<String, Integer> outputs, List<Bundle> transfers, Multisig root, Multisig remainderAddress) {
|
||||
this.signersCount = signersCount;
|
||||
this.balance = balance;
|
||||
this.settlementAddresses = settlementAddresses;
|
||||
@ -32,35 +35,6 @@ public class FlashObject {
|
||||
this.remainderAddress = remainderAddress;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
String out = "";
|
||||
out += "signersCount: " + signersCount + "\n";
|
||||
out += "balance: " + balance + "\n";
|
||||
out += "settlementAddresses: " + "\n";
|
||||
for (String b: settlementAddresses) {
|
||||
out += "\t" + b + "\n";
|
||||
}
|
||||
out += "deposits: " + "\n";
|
||||
for (double b: deposits) {
|
||||
out += "\t" + b + "\n";
|
||||
}
|
||||
|
||||
out += "outputs: " + "\n";
|
||||
for (Bundle b: outputs) {
|
||||
out += "\t" + b.toString() + "\n";
|
||||
}
|
||||
|
||||
out += "transfers: " + "\n";
|
||||
for (Bundle b: transfers) {
|
||||
out += "\t" + b.toString() + "\n";
|
||||
}
|
||||
out += "remainderAddress: " + remainderAddress.toString() + "\n";
|
||||
out += "root: " + root.toString() + "\n";
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
public Map<String, Object> toMap() {
|
||||
Map<String, Object> objectMap = new HashMap<>();
|
||||
objectMap.put("signersCount", signersCount);
|
||||
@ -69,17 +43,14 @@ public class FlashObject {
|
||||
objectMap.put("remainderAddress", remainderAddress.toMap());
|
||||
objectMap.put("settlementAddresses", getSettlementAddresses());
|
||||
|
||||
ArrayList<Object> outputMap = new ArrayList<>();
|
||||
for (Bundle b: outputs) {
|
||||
outputMap.add(b.toMap());
|
||||
}
|
||||
objectMap.put("outputs", outputMap);
|
||||
// Wrap outputs inside an array.
|
||||
objectMap.put("outputs", getOutputs());
|
||||
|
||||
objectMap.put("deposits", getDeposits());
|
||||
|
||||
ArrayList<Object> transfersMap = new ArrayList<>();
|
||||
for (Bundle b: transfers) {
|
||||
outputMap.add(b.toMap());
|
||||
for (Bundle b: getTransfers()) {
|
||||
transfersMap.add(b.toArrayList());
|
||||
}
|
||||
objectMap.put("transfers", transfersMap);
|
||||
return objectMap;
|
||||
@ -98,15 +69,15 @@ public class FlashObject {
|
||||
return root;
|
||||
}
|
||||
|
||||
public ArrayList<Double> getDeposits() {
|
||||
public List<Double> getDeposits() {
|
||||
return deposits;
|
||||
}
|
||||
|
||||
public ArrayList<Bundle> getOutputs() {
|
||||
public Map<String, Integer> getOutputs() {
|
||||
return outputs;
|
||||
}
|
||||
|
||||
public ArrayList<Bundle> getTransfers() {
|
||||
public List<Bundle> getTransfers() {
|
||||
return transfers;
|
||||
}
|
||||
|
||||
@ -126,7 +97,7 @@ public class FlashObject {
|
||||
this.settlementAddresses = settlementAddresses;
|
||||
}
|
||||
|
||||
public ArrayList<String> getSettlementAddresses() {
|
||||
public List<String> getSettlementAddresses() {
|
||||
return settlementAddresses;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,4 +1,37 @@
|
||||
package iotaFlashWrapper.Model;
|
||||
|
||||
public class GeneratedSeed {
|
||||
private String address;
|
||||
private String seed;
|
||||
private long amount;
|
||||
|
||||
public GeneratedSeed(String address, String seed, long amount) {
|
||||
this.address = address;
|
||||
this.seed = seed;
|
||||
this.amount = amount;
|
||||
}
|
||||
|
||||
public String getAddress() {
|
||||
return address;
|
||||
}
|
||||
|
||||
public void setAddress(String address) {
|
||||
this.address = address;
|
||||
}
|
||||
|
||||
public String getSeed() {
|
||||
return seed;
|
||||
}
|
||||
|
||||
public void setSeed(String seed) {
|
||||
this.seed = seed;
|
||||
}
|
||||
|
||||
public long getAmount() {
|
||||
return amount;
|
||||
}
|
||||
|
||||
public void setAmount(long amount) {
|
||||
this.amount = amount;
|
||||
}
|
||||
}
|
||||
|
||||
@ -5,6 +5,7 @@ import com.eclipsesource.v8.V8Array;
|
||||
import com.eclipsesource.v8.V8Object;
|
||||
import com.eclipsesource.v8.utils.V8ObjectUtils;
|
||||
import iotaFlashWrapper.Model.*;
|
||||
import jota.model.Transaction;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
@ -41,7 +42,8 @@ public class V8Converter {
|
||||
}
|
||||
|
||||
public static V8Object flashObjectToV8Object(V8 engine, FlashObject flash) {
|
||||
return V8ObjectUtils.toV8Object(engine, flash.toMap());
|
||||
Map <String, Object> flashMap = flash.toMap();
|
||||
return V8ObjectUtils.toV8Object(engine, flashMap);
|
||||
}
|
||||
|
||||
public static FlashObject flashObjectFromV8Object(V8Object input) {
|
||||
@ -64,18 +66,18 @@ public class V8Converter {
|
||||
}
|
||||
}
|
||||
ArrayList<Bundle> transfers = bundleListFromArrayList((ArrayList<Object>) inputMap.get("transfers"));
|
||||
ArrayList<Bundle> outputs = bundleListFromArrayList((ArrayList<Object>) inputMap.get("outputs"));
|
||||
Map<String, Integer> outputs = (Map<String, Integer>) inputMap.get("outputs");
|
||||
|
||||
return new FlashObject(singersCount, balance, settlementAddresses, deposits, outputs, transfers, root, remainderAddress);
|
||||
}
|
||||
|
||||
public static V8Array bundleListToV8Array(V8 engine, ArrayList<Bundle> bundles) {
|
||||
public static V8Array bundleListToV8Array(V8 engine, List<Bundle> bundles) {
|
||||
|
||||
List<Object> bundleTmp = new ArrayList<Object>();
|
||||
for (Bundle b: bundles) {
|
||||
List<Object> transactions = new ArrayList<Object>();
|
||||
for (jota.model.Transaction tx: b.getTransactions()) {
|
||||
transactions.add(((Transaction) tx).toMap());
|
||||
transactions.add(transactionToMap((Transaction) tx));
|
||||
}
|
||||
bundleTmp.add(transactions);
|
||||
}
|
||||
@ -142,7 +144,7 @@ public class V8Converter {
|
||||
continue;
|
||||
} else {
|
||||
for (Object transactionMap: (ArrayList<Object>) bundle) {
|
||||
b.getWrappedTransactions().add(transactionFromObject(transactionMap));
|
||||
b.getTransactions().add(transactionFromObject(transactionMap));
|
||||
}
|
||||
}
|
||||
bundles.add(b);
|
||||
@ -246,7 +248,7 @@ public class V8Converter {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static V8Array transferListToV8Array(V8 engine, ArrayList<Transfer> transfers) {
|
||||
public static V8Array transferListToV8Array(V8 engine, List<Transfer> transfers) {
|
||||
List<Object> transferObj = new ArrayList<Object>();
|
||||
for (Transfer t: transfers) {
|
||||
transferObj.add(t.toMap());
|
||||
@ -256,12 +258,34 @@ public class V8Converter {
|
||||
|
||||
public static V8Array transactionListToV8Array(V8 engine, ArrayList<Transaction> transactions) {
|
||||
List<Object> transfersObj = new ArrayList<Object>();
|
||||
for (Transaction t: transactions) {
|
||||
transfersObj.add(t.toMap());
|
||||
for (Transaction tx: transactions) {
|
||||
transfersObj.add(transactionToMap(tx));
|
||||
}
|
||||
return V8ObjectUtils.toV8Array(engine, transfersObj);
|
||||
}
|
||||
|
||||
public static Map<String, Object> transactionToMap(jota.model.Transaction transaction) {
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
if (transaction.getHash() != null && !transaction.getHash().equals("")) {
|
||||
map.put("hash", transaction.getHash());
|
||||
}
|
||||
map.put("signatureMessageFragment", transaction.getSignatureFragments());
|
||||
map.put("address", transaction.getAddress());
|
||||
map.put("value", transaction.getValue());
|
||||
map.put("obsoleteTag", transaction.getObsoleteTag());
|
||||
map.put("currentIndex", transaction.getCurrentIndex());
|
||||
map.put("timestamp", transaction.getTimestamp());
|
||||
map.put("lastIndex", transaction.getLastIndex());
|
||||
map.put("bundle", transaction.getBundle());
|
||||
map.put("trunkTransaction", transaction.getTrunkTransaction());
|
||||
map.put("branchTransaction", transaction.getBranchTransaction());
|
||||
map.put("nonce", transaction.getNonce());
|
||||
map.put("attachmentTimestamp", String.valueOf(transaction.getAttachmentTimestamp()));
|
||||
map.put("tag", transaction.getTag());
|
||||
map.put("attachmentTimestampLowerBound", String.valueOf(transaction.getAttachmentTimestampLowerBound()));
|
||||
map.put("attachmentTimestampUpperBound", String.valueOf(transaction.getAttachmentTimestampUpperBound()));
|
||||
return map;
|
||||
}
|
||||
|
||||
public static Transaction transactionFromObject(Object input) {
|
||||
Map<String, Object> bundleData = (Map<String, Object>) input;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user