Search in sources :

Example 6 with Address

use of run.wallet.iota.model.Address 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 7 with Address

use of run.wallet.iota.model.Address 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 8 with Address

use of run.wallet.iota.model.Address 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 9 with Address

use of run.wallet.iota.model.Address 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 10 with Address

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

Address (run.wallet.iota.model.Address)23 ArrayList (java.util.ArrayList)10 Transfer (run.wallet.iota.model.Transfer)9 ApiResponse (run.wallet.iota.api.responses.ApiResponse)8 ArgumentException (jota.error.ArgumentException)7 NetworkError (run.wallet.iota.api.responses.error.NetworkError)6 Wallet (run.wallet.iota.model.Wallet)6 LinearLayout (android.widget.LinearLayout)5 TextView (android.widget.TextView)5 TransferTransaction (run.wallet.iota.model.TransferTransaction)5 GetNewAddressResponse (jota.dto.response.GetNewAddressResponse)4 Bundle (jota.model.Bundle)4 Paint (android.graphics.Paint)3 GetBalancesResponse (jota.dto.response.GetBalancesResponse)3 GetTransferResponse (jota.dto.response.GetTransferResponse)3 StopWatch (jota.utils.StopWatch)3 GetNewAddressRequest (run.wallet.iota.api.requests.GetNewAddressRequest)3 NudgeTransfer (run.wallet.iota.model.NudgeTransfer)3 SharedPreferences (android.content.SharedPreferences)2 Bundle (android.os.Bundle)2