Search in sources :

Example 1 with StopWatch

use of jota.utils.StopWatch 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 StopWatch

use of jota.utils.StopWatch in project run-wallet-android by runplay.

the class GetBalanceAndFormatRequestHandler method handle.

@Override
public ApiResponse handle(ApiRequest request) {
    int notificationId = Utils.createNewID();
    ApiResponse response;
    try {
        StopWatch stopWatch = new StopWatch();
        // stopWatch.
        // Log.e("BALF","Getting balances and format");
        response = new GetBalanceAndFormatResponse(apiProxy.getBalanceAndFormat(((GetBalanceAndFormatRequest) request).addresses, 0L, 0, stopWatch, 0));
        List<Input> inputs = ((GetBalanceAndFormatResponse) response).getInputs();
    } catch (ArgumentException e) {
        NetworkError error = new NetworkError();
        if (e instanceof ArgumentException) {
            if (e.getMessage().contains("Sending to a used address.") || e.getMessage().contains("Private key reuse detect!")) {
                final Activity activity = (Activity) context;
                Bundle bundle = new Bundle();
                bundle.putString("error", e.getMessage());
                KeyReuseDetectedDialog dialog = new KeyReuseDetectedDialog();
                dialog.setArguments(bundle);
                dialog.show(activity.getFragmentManager(), null);
                error.setErrorType(NetworkErrorType.KEY_REUSE_ERROR);
            }
        }
        if (error.getErrorType() != NetworkErrorType.KEY_REUSE_ERROR) {
            error.setErrorType(NetworkErrorType.NETWORK_ERROR);
        }
        response = error;
    }
    return response;
}
Also used : Input(jota.model.Input) Bundle(android.os.Bundle) NetworkError(run.wallet.iota.api.responses.error.NetworkError) Activity(android.app.Activity) ArgumentException(jota.error.ArgumentException) KeyReuseDetectedDialog(run.wallet.iota.ui.dialog.KeyReuseDetectedDialog) ApiResponse(run.wallet.iota.api.responses.ApiResponse) StopWatch(jota.utils.StopWatch) GetBalanceAndFormatResponse(run.wallet.iota.api.responses.GetBalanceAndFormatResponse)

Example 3 with StopWatch

use of jota.utils.StopWatch in project run-wallet-android by runplay.

the class MessageFirstLoadRequestHandler method handle.

@Override
public ApiResponse handle(ApiRequest request) {
    try {
        // Log.e("FIRST-TIME-MSG","called");
        StopWatch stopWatch = new StopWatch();
        MessageFirstLoadRequest firstLoadRequest = (MessageFirstLoadRequest) request;
        GetTransferResponse gtr = null;
        List<Address> allAddresses = new ArrayList<>();
        int start = 0;
        final int addcount = 5;
        while (true) {
            GetNewAddressResponse gnr = apiProxy.getNewAddress(String.valueOf(Store.getSeedRaw(context, MsgStore.getSeed())), firstLoadRequest.getSecurity(), start, false, start + addcount, true);
            for (String add : gnr.getAddresses()) {
                // Log.e("FIRST-TIME-MSG","CALC ADDRESS: "+allAddresses+" -- "+stopWatch.getElapsedTimeSecs());
                final FindTransactionResponse tr = apiProxy.findTransactionsByAddresses(add);
                Address newaddress = new Address(add, false, true);
                if (tr.getHashes().length == 0) {
                    newaddress.setAttached(false);
                }
                allAddresses.add(newaddress);
            }
            int countempty = 0;
            for (int i = allAddresses.size() - 1; i >= 0 && i >= allAddresses.size() - 4; i--) {
                if (!allAddresses.get(i).isAttached()) {
                    countempty++;
                }
            }
            if (countempty >= 2) {
                break;
            }
            start += addcount;
        }
        List<String> transactionaddresses = new ArrayList<>();
        for (Address add : allAddresses) {
            if (add.isAttached())
                transactionaddresses.add(add.getAddress());
        }
        if (!transactionaddresses.isEmpty()) {
            try {
                Bundle[] bundles = apiProxy.bundlesFromAddresses(transactionaddresses.toArray(new String[transactionaddresses.size()]), true);
                gtr = GetTransferResponse.create(bundles, stopWatch.getElapsedTimeMili());
            } catch (Exception e) {
                Log.e("FIRST-LOAD-MSG", "ex: " + e.getMessage());
            }
        } else {
            gtr = GetTransferResponse.create(new Bundle[] {}, stopWatch.getElapsedTimeMili());
        }
        List<Transfer> transfers = new ArrayList<>();
        long seedTotal = 0;
        Wallet wallet = new Wallet(MsgStore.getSeed().id, seedTotal, System.currentTimeMillis());
        // Audit.setTransfersToAddresses(firstLoadRequest.getSeed(),gtr,transfers,allAddresses,wallet);
        MsgStore.updateMessageData(context, wallet, transfers, allAddresses);
    // AppService.generateMessageNewAddress(context);
    // if()
    } catch (ArgumentException e) {
        Log.e("FIRST-TIME-MSG", "ex: " + e.getMessage());
        return new NetworkError();
    }
    return new ApiResponse();
}
Also used : GetNewAddressResponse(jota.dto.response.GetNewAddressResponse) FindTransactionResponse(jota.dto.response.FindTransactionResponse) GetTransferResponse(jota.dto.response.GetTransferResponse) Address(run.wallet.iota.model.Address) MessageFirstLoadRequest(run.wallet.iota.api.requests.MessageFirstLoadRequest) Bundle(jota.model.Bundle) Wallet(run.wallet.iota.model.Wallet) ArrayList(java.util.ArrayList) NetworkError(run.wallet.iota.api.responses.error.NetworkError) ArgumentException(jota.error.ArgumentException) ApiResponse(run.wallet.iota.api.responses.ApiResponse) StopWatch(jota.utils.StopWatch) Transfer(run.wallet.iota.model.Transfer) ArgumentException(jota.error.ArgumentException)

Example 4 with StopWatch

use of jota.utils.StopWatch 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

StopWatch (jota.utils.StopWatch)4 ArrayList (java.util.ArrayList)3 GetTransferResponse (jota.dto.response.GetTransferResponse)3 ArgumentException (jota.error.ArgumentException)3 Bundle (jota.model.Bundle)3 ApiResponse (run.wallet.iota.api.responses.ApiResponse)3 Address (run.wallet.iota.model.Address)3 Transfer (run.wallet.iota.model.Transfer)3 Wallet (run.wallet.iota.model.Wallet)3 GetBalancesResponse (jota.dto.response.GetBalancesResponse)2 GetAccountDataResponse (run.wallet.iota.api.responses.GetAccountDataResponse)2 NetworkError (run.wallet.iota.api.responses.error.NetworkError)2 Activity (android.app.Activity)1 Bundle (android.os.Bundle)1 FindTransactionResponse (jota.dto.response.FindTransactionResponse)1 GetNewAddressResponse (jota.dto.response.GetNewAddressResponse)1 Input (jota.model.Input)1 GetAccountDataRequest (run.wallet.iota.api.requests.GetAccountDataRequest)1 MessageFirstLoadRequest (run.wallet.iota.api.requests.MessageFirstLoadRequest)1 GetBalanceAndFormatResponse (run.wallet.iota.api.responses.GetBalanceAndFormatResponse)1