mirror of
https://github.com/gosticks/iota.lib.java.git
synced 2026-10-04 05:26:59 +00:00
added getBundle, traverseBundle, bundleFromAddresses - pls test & verify
This commit is contained in:
@@ -1,9 +1,6 @@
|
||||
package jota.utils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -43,8 +40,58 @@ public class IotaAPIUtils {
|
||||
return address;
|
||||
}
|
||||
|
||||
public static List<String> signInputsAndReturn(final String seed,
|
||||
final List<Input> inputs,
|
||||
public static List<String> addRemainder(final String seed,
|
||||
final List<Input> inputs,
|
||||
final Bundle bundle,
|
||||
final String tag,
|
||||
final long totalValue,
|
||||
final String remainderAddress,
|
||||
final List<String> signatureFragments) {
|
||||
for (int i = 0; i < inputs.size(); i++) {
|
||||
long thisBalance = inputs.get(i).getBalance();
|
||||
long totalTransferValue = totalValue;
|
||||
long toSubtract = 0 - thisBalance;
|
||||
long timestamp = (new Date()).getTime();
|
||||
|
||||
// Add input as bundle entry
|
||||
bundle.addEntry(2, inputs.get(i).getAddress(), toSubtract, tag, timestamp);
|
||||
// If there is a remainder value
|
||||
// Add extra output to send remaining funds to
|
||||
|
||||
if (thisBalance >= totalTransferValue) {
|
||||
long remainder = thisBalance - totalTransferValue;
|
||||
|
||||
// If user has provided remainder address
|
||||
// Use it to send remaining funds to
|
||||
if (remainder > 0 && remainderAddress != null) {
|
||||
// Remainder bundle entry
|
||||
bundle.addEntry(1, remainderAddress, remainder, tag, timestamp);
|
||||
// Final function for signing inputs
|
||||
return signInputsAndReturn(seed, inputs, bundle, signatureFragments);
|
||||
} else if (remainder > 0) {
|
||||
// Generate a new Address by calling getNewAddress
|
||||
String address = newAddress(seed, 0, false);
|
||||
// Remainder bundle entry
|
||||
bundle.addEntry(1, address, remainder, tag, timestamp);
|
||||
// Final function for signing inputs
|
||||
return signInputsAndReturn(seed, inputs, bundle, signatureFragments);
|
||||
} else {
|
||||
// If there is no remainder, do not add transaction to bundle
|
||||
// simply sign and return
|
||||
return signInputsAndReturn(seed, inputs, bundle, signatureFragments);
|
||||
}
|
||||
|
||||
// If multiple inputs provided, subtract the totalTransferValue by
|
||||
// the inputs balance
|
||||
} else {
|
||||
totalTransferValue -= thisBalance;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public static List<String> signInputsAndReturn(final String seed,
|
||||
final List<Input> inputs,
|
||||
final Bundle bundle,
|
||||
final List<String> signatureFragments) {
|
||||
bundle.finalize();
|
||||
|
||||
Reference in New Issue
Block a user