Search in sources :

Example 6 with Transfer

use of run.wallet.iota.model.Transfer in project run-wallet-android by runplay.

the class NudgeRequestHandler method doNudge.

public static ApiResponse doNudge(RunIotaAPI apiProxy, Context context, ApiRequest inrequest) {
    ApiResponse response;
    int notificationId = Utils.createNewID();
    NudgeRequest request = (NudgeRequest) inrequest;
    Transfer nudgeMe = request.getTransfer();
    try {
        List<Address> alreadyAddress = Store.getAddresses(context, request.getSeed());
        // String useAddress="RUN9IOTA9WALLET9NUDGE9PROMOTE9TRANSFER9ADDRESSRUN9IOTA9WALLET9NUDGE9PROMOTE9TRANS";
        String random = SeedRandomGenerator.generateNewSeed();
        String useAddress = "RUN9IOTA9WALLET9NUDGE9PROMOTE9TRANSFER99" + Sf.restrictLength(random, 41);
        NudgeResponse nresp = null;
        if (useAddress != null) {
            List<Transfer> transfers = new ArrayList<>();
            List<Transfer> alreadyTransfers = Store.getTransfers(context, request.getSeed());
            Transfer already = Store.isAlreadyTransfer(nudgeMe.getHash(), alreadyTransfers);
            if (already != null) {
                RunSendTransferResponse rstr = apiProxy.sendNudgeTransfer(String.valueOf(Store.getSeedRaw(context, request.getSeed())), nudgeMe.getHash(), useAddress, 1, 2, request.getDepth(), request.getMinWeightMagnitude());
                nresp = new NudgeResponse(rstr);
                String gotHash = null;
                if (nresp != null && nresp.getSuccessfully()) {
                    gotHash = nresp.getHashes().get(0);
                    already.addNudgeHash(gotHash);
                } else {
                    already.addNudgeHash("Failed nudge");
                }
                jota.dto.response.GetNodeInfoResponse nodeInfo = apiProxy.getNodeInfo();
                if (nodeInfo != null) {
                    already.setMilestone(nodeInfo.getLatestMilestoneIndex());
                }
                if (gotHash != null) {
                    Wallet wallet = Store.getWallet(context, request.getSeed());
                    Audit.setTransfersToAddresses(request.getSeed(), transfers, alreadyAddress, wallet, alreadyTransfers);
                    Audit.processNudgeAttempts(context, request.getSeed(), transfers);
                    Store.updateAccountData(context, request.getSeed(), wallet, transfers, alreadyAddress);
                }
                if (!AppService.isAppStarted()) {
                    NotificationHelper.responseNotification(context, R.drawable.nudge_orange, context.getString(R.string.notification_nudge_succeeded_title), notificationId);
                } else {
                    NotificationHelper.vibrate(context);
                }
                return nresp;
            }
        }
        NetworkError error = new NetworkError();
        error.setErrorType(NetworkErrorType.INVALID_HASH_ERROR);
        return error;
    } catch (ArgumentException e) {
        Log.e("NUDGE", "error: " + e.getMessage());
        NetworkError error = new NetworkError();
        error.setErrorType(NetworkErrorType.INVALID_HASH_ERROR);
        response = error;
    }
    return response;
}
Also used : Address(run.wallet.iota.model.Address) Wallet(run.wallet.iota.model.Wallet) ArrayList(java.util.ArrayList) NudgeRequest(run.wallet.iota.api.requests.NudgeRequest) NetworkError(run.wallet.iota.api.responses.error.NetworkError) NudgeResponse(run.wallet.iota.api.responses.NudgeResponse) ApiResponse(run.wallet.iota.api.responses.ApiResponse) RunSendTransferResponse(jota.dto.response.RunSendTransferResponse) Transfer(run.wallet.iota.model.Transfer) ArgumentException(jota.error.ArgumentException)

Example 7 with Transfer

use of run.wallet.iota.model.Transfer 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)

Example 8 with Transfer

use of run.wallet.iota.model.Transfer in project run-wallet-android by runplay.

the class Audit method populateTxToTransfers.

public static void populateTxToTransfers(List<Transaction> inTransactions, NodeInfoResponse nodeInfo, List<Transfer> transfers, List<Address> allAddresses) {
    long totalValueTransfer = 0;
    long timestamp = 0;
    String address = "";
    String hash = "";
    Boolean persistence = false;
    long value = 0;
    String tag = Constants.NEW_TRANSFER_TAG;
    String destinationAddress = "";
    List<TransferTransaction> transactions = new ArrayList<>();
    List<TransferTransaction> othertransactions = new ArrayList<>();
    String message = defmessage;
    for (Transaction trx : inTransactions) {
        try {
            tag = trx.getTag();
            address = trx.getAddress();
            persistence = trx.getPersistence();
            value = trx.getValue();
            Address hasAddress = Store.isAlreadyAddress(address, allAddresses);
            if (hasAddress != null) {
                hasAddress.setAttached(true);
            }
            if (value != 0 && hasAddress != null) {
                transactions.add(new TransferTransaction(hasAddress.getAddress(), value));
                totalValueTransfer += value;
            } else if (value != 0) {
                othertransactions.add(new TransferTransaction(trx.getAddress(), value));
            }
            if (trx.getCurrentIndex() == 0) {
                message = Utils.removeTrailingNines(trx.getSignatureFragments());
                timestamp = trx.getAttachmentTimestamp();
                destinationAddress = address;
                hash = trx.getHash();
            }
            if (hasAddress != null) {
                boolean isRemainder = (trx.getCurrentIndex() == trx.getLastIndex()) && trx.getLastIndex() != 0;
                if (value < 0 && !isRemainder) {
                    hasAddress.setUsed(true);
                } else {
                    // hasAddress.setUsed(false);
                    hasAddress.setAttached(true);
                }
            }
        } catch (Exception e) {
            Log.e("AUDIT", "exception: " + e.getMessage());
        }
    }
    Transfer addtransfer = new Transfer(timestamp, destinationAddress, hash, persistence, totalValueTransfer, message, tag);
    if (nodeInfo != null) {
        addtransfer.setMilestone(nodeInfo.getLatestMilestoneIndex());
        addtransfer.setMilestoneCreated(nodeInfo.getLatestMilestoneIndex());
    }
    addtransfer.setTransactions(transactions);
    addtransfer.setOtherTransactions(othertransactions);
    transfers.add(addtransfer);
}
Also used : TransferTransaction(run.wallet.iota.model.TransferTransaction) Transaction(jota.model.Transaction) Address(run.wallet.iota.model.Address) ArrayList(java.util.ArrayList) Transfer(run.wallet.iota.model.Transfer) NudgeTransfer(run.wallet.iota.model.NudgeTransfer) TransferTransaction(run.wallet.iota.model.TransferTransaction)

Example 9 with Transfer

use of run.wallet.iota.model.Transfer in project run-wallet-android by runplay.

the class Audit method processNudgeAttempts.

public static void processNudgeAttempts(Context context, Seeds.Seed seed, List<Transfer> transfers) {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
    int nudgeAttempts = Sf.toInt(prefs.getString(Constants.PREF_TRANSFER_NUDGE_ATTEMPTS, "" + Constants.PREF_TRANSFER_NUDGE_ATTEMPTS_VALUE));
    Collections.reverse(transfers);
    List<NudgeTransfer> alreadyNudge = Store.getNudgeTransfers();
    Map<String, Boolean> completedLookup = new HashMap<>();
    for (Transfer transfer : transfers) {
        if (transfer.isCompleted()) {
            completedLookup.put(transfer.getValue() + "" + transfer.getAddress(), true);
        }
    }
    for (Transfer transfer : transfers) {
        if (!transfer.isCompleted() && completedLookup.get(transfer.getValue() + "" + transfer.getAddress()) == null) {
            if (transfer.getValue() <= 0 && !transfer.isMarkDoubleAddress() && !transfer.isMarkDoubleSpend() && !transfer.getTransactions().isEmpty() && transfer.getNudgeCount() < nudgeAttempts) {
                Store.addIfNoNudgeTransfer(context, seed, transfer);
            }
        } else if (transfer.isCompleted()) {
            for (NudgeTransfer nudge : alreadyNudge) {
                if (transfer.getHash().equals(nudge.transfer.getHash())) {
                    List<NudgeTransfer> remove = new ArrayList<>();
                    remove.add(nudge);
                    Store.removeNudgeTransfer(context, remove);
                }
            }
        }
    }
    Store.saveNudgeTransfers(context);
    Collections.reverse(transfers);
}
Also used : SharedPreferences(android.content.SharedPreferences) HashMap(java.util.HashMap) NudgeTransfer(run.wallet.iota.model.NudgeTransfer) Transfer(run.wallet.iota.model.Transfer) NudgeTransfer(run.wallet.iota.model.NudgeTransfer) ArrayList(java.util.ArrayList) List(java.util.List)

Example 10 with Transfer

use of run.wallet.iota.model.Transfer in project run-wallet-android by runplay.

the class Audit method setTransfersToAddresses.

public static void setTransfersToAddresses(Seeds.Seed seed, List<Transfer> transfers, List<Address> allAddresses, Wallet wallet, List<Transfer> addinTransfers) {
    for (Address add : allAddresses) {
        if (add.getValue() != 0 || add.getPendingValue() != 0)
            add.setUsed(false);
        // add.setValue(0);
        add.setPendingValue(0);
        if (!add.isPigUser()) {
            add.setPigInt(0);
        }
    }
    if (addinTransfers != null) {
        List<Transfer> allTransfers = new ArrayList<>();
        for (Transfer tran : addinTransfers) {
            Transfer already = Store.isAlreadyTransfer(tran, transfers);
            if (already == null) {
                allTransfers.add(tran);
            } else {
                already.setLastDoubleCheck(tran.getLastDoubleCheck());
                already.setMilestone(tran.getMilestone());
                already.setMilestoneCreated(tran.getMilestoneCreated());
                already.setNudgeHashes(tran.getNudgeHashes());
            }
        }
        transfers.addAll(allTransfers);
    }
    if (!transfers.isEmpty()) {
        ProcessResult result = processTransfersToAddresses(seed, transfers, allAddresses);
        Collections.sort(transfers);
        wallet.setBalance(result.seedTotal);
        wallet.setBalancePendingIn(result.seedTotalPendingIn);
        wallet.setBalancePendingOut(result.seedTotalPendingOut);
    }
    wallet.setLastUpdate(System.currentTimeMillis());
}
Also used : Address(run.wallet.iota.model.Address) Transfer(run.wallet.iota.model.Transfer) NudgeTransfer(run.wallet.iota.model.NudgeTransfer) ArrayList(java.util.ArrayList)

Aggregations

Transfer (run.wallet.iota.model.Transfer)15 ArrayList (java.util.ArrayList)13 Address (run.wallet.iota.model.Address)9 Wallet (run.wallet.iota.model.Wallet)6 ApiResponse (run.wallet.iota.api.responses.ApiResponse)5 NudgeTransfer (run.wallet.iota.model.NudgeTransfer)5 TransferTransaction (run.wallet.iota.model.TransferTransaction)5 SharedPreferences (android.content.SharedPreferences)4 HashMap (java.util.HashMap)4 ArgumentException (jota.error.ArgumentException)4 Bundle (jota.model.Bundle)4 GetBalancesResponse (jota.dto.response.GetBalancesResponse)3 GetNewAddressResponse (jota.dto.response.GetNewAddressResponse)3 GetTransferResponse (jota.dto.response.GetTransferResponse)3 StopWatch (jota.utils.StopWatch)3 NudgeRequest (run.wallet.iota.api.requests.NudgeRequest)3 NudgeResponse (run.wallet.iota.api.responses.NudgeResponse)3 NetworkError (run.wallet.iota.api.responses.error.NetworkError)3 ClipData (android.content.ClipData)2 ClipboardManager (android.content.ClipboardManager)2