Search in sources :

Example 1 with GetAccountDataResponse

use of run.wallet.iota.api.responses.GetAccountDataResponse in project run-wallet-android by runplay.

the class GetAccountDataRequestHandler method handle.

@Override
public ApiResponse handle(ApiRequest inrequest) {
    GetAccountDataRequest request = (GetAccountDataRequest) inrequest;
    GetTransferResponse gtr = null;
    StopWatch stopWatch = new StopWatch();
    NodeInfoResponse nodeInfo = Store.getNodeInfo();
    Wallet wallet = Store.getWallet(context, request.getSeed());
    if (wallet != null && nodeInfo != null) {
        List<Address> alreadyAddress = Store.getAddresses(context, request.getSeed());
        List<Address> usingAddress = Store.getDisplayAddresses(alreadyAddress);
        List<Address> checkAddress = new ArrayList<>();
        if (request.getIfSingleAddressOrNull() != null) {
            Address address = Store.isAlreadyAddress(request.getIfSingleAddressOrNull(), alreadyAddress);
            if (address != null) {
                checkAddress.add(address);
            }
        } else {
            for (Address add : usingAddress) {
                if (!add.isUsed() || (add.isUsed() && (add.getPendingValue() != 0 || add.getValue() != 0))) {
                    if (request.isForce() || nodeInfo.getLatestMilestoneIndex() != add.getLastMilestone()) {
                        checkAddress.add(add);
                    }
                }
            }
        }
        if (!checkAddress.isEmpty()) {
            try {
                List<String> checkAddressString = new ArrayList<>();
                List<String> checkAddressBal = new ArrayList<>();
                for (Address addr : checkAddress) {
                    checkAddressBal.add(addr.getAddress());
                }
                GetBalancesResponse gbal = apiProxy.getBalances(100, checkAddressBal);
                for (int i = 0; i < gbal.getBalances().length; i++) {
                    Address addr = checkAddress.get(i);
                    long gotBalance = Sf.toLong(gbal.getBalances()[i]);
                    if (addr.getValue() != gotBalance || addr.getPendingValue() != 0) {
                        addr.setValue(gotBalance);
                        checkAddressString.add(addr.getAddress());
                    }
                }
                if (!checkAddressString.isEmpty()) {
                    Bundle[] bundles = apiProxy.bundlesFromAddresses(checkAddressString.toArray(new String[checkAddressString.size()]), true);
                    gtr = GetTransferResponse.create(bundles, stopWatch.getElapsedTimeMili());
                }
                List<Transfer> transfers = new ArrayList<>();
                if (gtr != null && gtr.getTransfers().length > 0) {
                    List<Transfer> alreadyTransfer = Store.getTransfers(context, request.getSeed());
                    Audit.bundlePopulateTransfers(gtr.getTransfers(), transfers, alreadyAddress);
                    if (request.getIfSingleAddressOrNull() != null) {
                        Audit.setTransfersToAddresses(request.getSeed(), transfers, alreadyAddress, wallet, alreadyTransfer);
                    } else {
                        Audit.setTransfersToAddresses(request.getSeed(), transfers, alreadyAddress, wallet, alreadyTransfer);
                    }
                    Audit.processNudgeAttempts(context, request.getSeed(), transfers);
                    Store.updateAccountData(context, request.getSeed(), wallet, transfers, alreadyAddress);
                }
                if (request.getIfSingleAddressOrNull() == null) {
                    WalletAddressesFragment.setShouldRefresh(true);
                    WalletTransfersFragment.setShouldRefresh(true);
                    List<String> checkOthersString = new ArrayList<>();
                    for (Address address : checkAddress) {
                        if (!checkAddressString.contains(address.getAddress()))
                            checkOthersString.add(address.getAddress());
                    }
                    if (!checkOthersString.isEmpty()) {
                        Bundle[] bundles = apiProxy.bundlesFromAddresses(checkOthersString.toArray(new String[checkOthersString.size()]), true);
                        gtr = GetTransferResponse.create(bundles, stopWatch.getElapsedTimeMili());
                    }
                    if (gtr != null && gtr.getTransfers().length > 0) {
                        transfers = new ArrayList<>();
                        List<Transfer> alreadyTransfer = Store.getTransfers(context, request.getSeed());
                        Audit.bundlePopulateTransfers(gtr.getTransfers(), transfers, alreadyAddress);
                        if (request.getIfSingleAddressOrNull() != null) {
                            Audit.setTransfersToAddresses(request.getSeed(), transfers, alreadyAddress, wallet, alreadyTransfer);
                        } else {
                            Audit.setTransfersToAddresses(request.getSeed(), transfers, alreadyAddress, wallet, alreadyTransfer);
                        }
                        Audit.processNudgeAttempts(context, request.getSeed(), transfers);
                        Store.updateAccountData(context, request.getSeed(), wallet, transfers, alreadyAddress);
                    }
                }
            } catch (Exception e) {
                Log.e("ERR066", "ERROR: " + e.getMessage());
            }
        }
        AppService.setFastMode();
        return new GetAccountDataResponse();
    }
    return new ApiResponse();
}
Also used : GetBalancesResponse(jota.dto.response.GetBalancesResponse) GetTransferResponse(jota.dto.response.GetTransferResponse) Address(run.wallet.iota.model.Address) Wallet(run.wallet.iota.model.Wallet) Bundle(jota.model.Bundle) NodeInfoResponse(run.wallet.iota.api.responses.NodeInfoResponse) ArrayList(java.util.ArrayList) ArgumentException(jota.error.ArgumentException) ApiResponse(run.wallet.iota.api.responses.ApiResponse) StopWatch(jota.utils.StopWatch) GetAccountDataResponse(run.wallet.iota.api.responses.GetAccountDataResponse) GetAccountDataRequest(run.wallet.iota.api.requests.GetAccountDataRequest) Transfer(run.wallet.iota.model.Transfer)

Example 2 with GetAccountDataResponse

use of run.wallet.iota.api.responses.GetAccountDataResponse in project run-wallet-android by runplay.

the class RefreshUsedAddressesHandler method checkUsedAddressForSeed.

private GetAccountDataResponse checkUsedAddressForSeed(Seeds.Seed seed, boolean report) {
    Wallet wallet = Store.getWallet(context, seed);
    if (wallet != null) {
        List<Address> alreadyAddress = Store.getAddresses(context, seed);
        GetTransferResponse gtr = null;
        StopWatch stopWatch = new StopWatch();
        List<Address> checkAddress = new ArrayList<>();
        for (Address tmp : alreadyAddress) {
            if (tmp.isUsed() && tmp.getValue() == 0) {
                checkAddress.add(tmp);
            }
        }
        if (!checkAddress.isEmpty()) {
            try {
                List<String> checkAddressString = new ArrayList<>();
                List<String> checkAddressBal = new ArrayList<>();
                for (Address addr : checkAddress) {
                    checkAddressBal.add(addr.getAddress());
                }
                GetBalancesResponse gbal = apiProxy.getBalances(100, checkAddressBal);
                for (int i = 0; i < gbal.getBalances().length; i++) {
                    Address addr = checkAddress.get(i);
                    long gotBalance = Sf.toLong(gbal.getBalances()[i]);
                    if (gotBalance != 0 || addr.getPendingValue() != 0) {
                        addr.setValue(gotBalance);
                        checkAddressString.add(addr.getAddress());
                    }
                    if (report) {
                        if (gotBalance > 0) {
                            Store.setUsedAddressCheckResult(context.getString(R.string.usedAddressNoOk) + " " + IotaToText.convertRawIotaAmountToDisplayText(gotBalance, true));
                        } else {
                            Store.setUsedAddressCheckResult(context.getString(R.string.usedAddressOk));
                        }
                    }
                }
                if (!checkAddressString.isEmpty()) {
                    Bundle[] bundles = apiProxy.bundlesFromAddresses(checkAddressString.toArray(new String[checkAddressString.size()]), true);
                    gtr = GetTransferResponse.create(bundles, stopWatch.getElapsedTimeMili());
                }
                List<Transfer> transfers = new ArrayList<>();
                if (gtr != null && gtr.getTransfers().length > 0) {
                    List<Transfer> alreadyTransfer = Store.getTransfers(context, seed);
                    Audit.bundlePopulateTransfers(gtr.getTransfers(), transfers, alreadyAddress);
                    Audit.setTransfersToAddresses(seed, transfers, alreadyAddress, wallet, alreadyTransfer);
                    Audit.processNudgeAttempts(context, seed, transfers);
                    Store.updateAccountData(context, seed, wallet, transfers, alreadyAddress);
                }
            } catch (Exception e) {
                Log.e("ERR066", "ERROR: " + e.getMessage());
            }
        }
    }
    return new GetAccountDataResponse();
}
Also used : GetBalancesResponse(jota.dto.response.GetBalancesResponse) GetTransferResponse(jota.dto.response.GetTransferResponse) Address(run.wallet.iota.model.Address) Wallet(run.wallet.iota.model.Wallet) Bundle(jota.model.Bundle) ArrayList(java.util.ArrayList) StopWatch(jota.utils.StopWatch) GetAccountDataResponse(run.wallet.iota.api.responses.GetAccountDataResponse) Transfer(run.wallet.iota.model.Transfer)

Aggregations

ArrayList (java.util.ArrayList)2 GetBalancesResponse (jota.dto.response.GetBalancesResponse)2 GetTransferResponse (jota.dto.response.GetTransferResponse)2 Bundle (jota.model.Bundle)2 StopWatch (jota.utils.StopWatch)2 GetAccountDataResponse (run.wallet.iota.api.responses.GetAccountDataResponse)2 Address (run.wallet.iota.model.Address)2 Transfer (run.wallet.iota.model.Transfer)2 Wallet (run.wallet.iota.model.Wallet)2 ArgumentException (jota.error.ArgumentException)1 GetAccountDataRequest (run.wallet.iota.api.requests.GetAccountDataRequest)1 ApiResponse (run.wallet.iota.api.responses.ApiResponse)1 NodeInfoResponse (run.wallet.iota.api.responses.NodeInfoResponse)1