jota.utils.Checksum Java Examples

The following examples show how to use jota.utils.Checksum. 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: NewTransferFragment.java    From android-wallet-app with GNU General Public License v3.0 5 votes vote down vote up
private boolean isValidAddress() {
    String address = addressEditText.getText().toString();
    try {
        //noinspection StatementWithEmptyBody
        if (Checksum.isAddressWithoutChecksum(address)) {
        }
    } catch (ArgumentException e) {
        addressEditTextInputLayout.setError(getString(R.string.messages_enter_txaddress_with_checksum));
        return false;
    }
    return true;
}
 
Example #2
Source File: NewTransferFragment.java    From android-wallet-app with GNU General Public License v3.0 5 votes vote down vote up
private String getAddress() {
    try {
        return Checksum.removeChecksum(addressEditText.getText().toString());
    } catch (ArgumentException e) {
        e.printStackTrace();
    }
    return "";
}
 
Example #3
Source File: GenerateQRCodeFragment.java    From android-wallet-app with GNU General Public License v3.0 5 votes vote down vote up
private boolean isValidAddress() {
    String address = addressEditText.getText().toString();
    try {
        //noinspection StatementWithEmptyBody
        if (Checksum.isAddressWithoutChecksum(address)) {
        }
    } catch (ArgumentException e) {
        addressEditTextInputLayout.setError(getString(R.string.messages_enter_txaddress_with_checksum));
        return false;
    }
    return true;
}
 
Example #4
Source File: GenerateQRCodeFragment.java    From android-wallet-app with GNU General Public License v3.0 5 votes vote down vote up
private String getAddress() {
    try {
        return Checksum.removeChecksum(addressEditText.getText().toString());
    } catch (ArgumentException e) {
        e.printStackTrace();
    }
    return "";
}
 
Example #5
Source File: GetAccountDataResponse.java    From guarda-android-wallets with GNU General Public License v3.0 4 votes vote down vote up
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 #6
Source File: GetAccountDataResponse.java    From android-wallet-app with GNU General Public License v3.0 4 votes vote down vote up
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());
        }
    }