Java Code Examples for jota.model.Transaction#getCurrentIndex()
The following examples show how to use
jota.model.Transaction#getCurrentIndex() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TangleInterface.java From qupla with Apache License 2.0 | 5 votes |
private static List<Transaction> orderTransactionsByIndex(List<Transaction> unordered) { Transaction[] ordered = new Transaction[unordered.size()]; for (Transaction transaction : unordered) { ordered[(int) transaction.getCurrentIndex()] = transaction; } return Arrays.asList(ordered); }
Example 2
Source File: GetAccountDataResponse.java From guarda-android-wallets with GNU General Public License v3.0 | 4 votes |
public GetAccountDataResponse(jota.dto.response.GetAccountDataResponse apiResponse) throws ArgumentException { attachedAddresses = apiResponse.getAddresses(); Collections.reverse(attachedAddresses); Bundle[] transferBundle = apiResponse.getTransfers(); if (transferBundle != null) { for (Bundle aTransferBundle : transferBundle) { totalValue = 0; for (Transaction trx : aTransferBundle.getTransactions()) { address = trx.getAddress(); persistence = trx.getPersistence(); value = trx.getValue(); if (value != 0 && attachedAddresses.contains(Checksum.addChecksum(address))) totalValue += value; if (trx.getCurrentIndex() == 0) { timestamp = trx.getAttachmentTimestamp() / 1000; tag = trx.getTag(); destinationAddress = address; hash = trx.getHash(); } // check if sent transaction if (attachedAddresses.contains(Checksum.addChecksum(address))) { boolean isRemainder = (trx.getCurrentIndex() == trx.getLastIndex()) && trx.getLastIndex() != 0; if (value < 0 && !isRemainder) { if (addresses.contains(new Address(Checksum.addChecksum(address), false))) addresses.remove(new Address(Checksum.addChecksum(address), false)); if (!addresses.contains(new Address(Checksum.addChecksum(address), true))) addresses.add(new Address(Checksum.addChecksum(address), true)); } else { if (!addresses.contains(new Address(Checksum.addChecksum(address), true)) && !addresses.contains(new Address(Checksum.addChecksum(address), false))) addresses.add(new Address(Checksum.addChecksum(address), false)); } } } transfers.add(new Transfer(timestamp, destinationAddress, hash, persistence, totalValue, message, tag)); } // sort the addresses final Map<String, Integer> map = new HashMap<>(); for (int i = 0; i < attachedAddresses.toArray().length; ++i) map.put(attachedAddresses.get(i), i); Collections.sort(addresses, new Comparator<Address>() { @Override public int compare(Address add1, Address add2) { return map.get(add1.getAddress()) - map.get(add2.getAddress()); } }); Collections.sort(transfers); //Don't know why, but in ver. 1.5.5 correct balance = value, before it was apiResponse.getBalance() setBalance(value); setDuration(apiResponse.getDuration()); } }
Example 3
Source File: GetAccountDataResponse.java From android-wallet-app with GNU General Public License v3.0 | 4 votes |
public GetAccountDataResponse(jota.dto.response.GetAccountDataResponse apiResponse) throws ArgumentException { attachedAddresses = apiResponse.getAddresses(); Collections.reverse(attachedAddresses); Bundle[] transferBundle = apiResponse.getTransfers(); if (transferBundle != null) { for (Bundle aTransferBundle : transferBundle) { totalValue = 0; for (Transaction trx : aTransferBundle.getTransactions()) { address = trx.getAddress(); persistence = trx.getPersistence(); value = trx.getValue(); if (value != 0 && attachedAddresses.contains(Checksum.addChecksum(address))) totalValue += value; if (trx.getCurrentIndex() == 0) { timestamp = trx.getAttachmentTimestamp() / 1000; tag = trx.getTag(); destinationAddress = address; hash = trx.getHash(); } // check if sent transaction if (attachedAddresses.contains(Checksum.addChecksum(address))) { boolean isRemainder = (trx.getCurrentIndex() == trx.getLastIndex()) && trx.getLastIndex() != 0; if (value < 0 && !isRemainder) { if (addresses.contains(new Address(Checksum.addChecksum(address), false))) addresses.remove(new Address(Checksum.addChecksum(address), false)); if (!addresses.contains(new Address(Checksum.addChecksum(address), true))) addresses.add(new Address(Checksum.addChecksum(address), true)); } else { if (!addresses.contains(new Address(Checksum.addChecksum(address), true)) && !addresses.contains(new Address(Checksum.addChecksum(address), false))) addresses.add(new Address(Checksum.addChecksum(address), false)); } } } transfers.add(new Transfer(timestamp, destinationAddress, hash, persistence, totalValue, message, tag)); } // sort the addresses final Map<String, Integer> map = new HashMap<>(); for (int i = 0; i < attachedAddresses.toArray().length; ++i) map.put(attachedAddresses.get(i), i); Collections.sort(addresses, new Comparator<Address>() { @Override public int compare(Address add1, Address add2) { return map.get(add1.getAddress()) - map.get(add2.getAddress()); } }); Collections.sort(transfers); setBalance(apiResponse.getBalance()); setDuration(apiResponse.getDuration()); } }