Search in sources :

Example 21 with Address

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

the class Audit method processTransfersToAddresses.

private static ProcessResult processTransfersToAddresses(Seeds.Seed seed, List<Transfer> transfers, List<Address> allAddresses) {
    Collections.sort(transfers);
    Collections.reverse(transfers);
    HashMap<String, Transfer> completed = new HashMap<String, Transfer>();
    HashMap<String, Transfer> completedAddresses = new HashMap<String, Transfer>();
    for (Transfer transfer : transfers) {
        if (!transfer.getTransactions().isEmpty()) {
            String key = transfer.getValue() + transfer.getAddress();
            Transfer comp = completed.get(key);
            if (comp == null) {
                completed.put(key, transfer);
            } else {
                if (comp.isCompleted()) {
                    transfer.setMarkDoubleSpend(true);
                } else {
                    comp.setMarkDoubleSpend(true);
                    completed.put(key, transfer);
                }
            }
            if (transfer.isCompleted()) {
                transfer.setMarkDoubleAddress(false);
                transfer.setMarkDoubleSpend(false);
                if (transfer.getTimestampConfirmed() == 0)
                    transfer.setTimestampConfirmed(System.currentTimeMillis());
                for (TransferTransaction trans : transfer.getTransactions()) {
                    if (trans.getValue() < 0) {
                        // Log.e("AUDIT","comp address: "+trans.getValue()+" - "+trans.getAddress());
                        completedAddresses.put(trans.getAddress(), transfer);
                    }
                }
            }
        }
    }
    for (Transfer transfer : transfers) {
        if (!transfer.isCompleted() && !transfer.isMarkDoubleSpend()) {
            // Log.e("AUDIT","check: "+transfer.getValue()+" - "+transfer.getHash());
            List<String> testAddress = new ArrayList<>();
            for (TransferTransaction trans : transfer.getTransactions()) {
                if (trans.getValue() < 0) {
                    // Log.e("AUDIT","-address: "+trans.getValue()+" - "+trans.getAddress());
                    testAddress.add(trans.getAddress());
                }
            }
            if (!testAddress.isEmpty()) {
                for (String testadd : testAddress) {
                    Transfer completedOnTransfer = completedAddresses.get(testadd);
                    if (completedOnTransfer != null && !completedOnTransfer.getHash().equals(transfer.getHash())) {
                        Address tmpadd = Store.isAlreadyAddress(testadd, allAddresses);
                        if (tmpadd != null && tmpadd.getValue() == 0) {
                            // Log.e("AUDIT", "completedOnTransfer: " + completedOnTransfer.getValue() + " - " + completedOnTransfer.getAddress());
                            transfer.setMarkDoubleAddress(true);
                        }
                    }
                }
            }
        }
    }
    long seedTotalPendingIn = 0;
    long seedTotalPendingOut = 0;
    List<TransferTransaction> already = new ArrayList<>();
    for (Transfer transfer : transfers) {
        if (transfer.isCompleted()) {
            for (TransferTransaction trans : transfer.getTransactions()) {
                Address address = Store.isAlreadyAddress(trans.getAddress(), allAddresses);
                if (address != null) {
                    // address.setValue(address.getValue() + trans.getValue());
                    if (trans.getValue() < 0) {
                        address.setUsed(true);
                    }
                }
            }
        } else if (!transfer.isCompleted()) {
            if (transfer.isInternal() || (!transfer.isMarkDoubleSpend() && !transfer.isMarkDoubleAddress())) {
                for (TransferTransaction trans : transfer.getTransactions()) {
                    Address address = Store.isAlreadyAddress(trans.getAddress(), allAddresses);
                    if (address != null) {
                        address.setPendingValue(address.getPendingValue() + trans.getValue());
                        if (trans.getValue() < 0) {
                            seedTotalPendingOut += trans.getValue();
                        } else {
                            seedTotalPendingIn += trans.getValue();
                        }
                        already.add(trans);
                    }
                }
            }
        }
    }
    long seedTotal = 0;
    for (Address address : allAddresses) {
        seedTotal += address.getValue();
        if (address.getPendingValue() != 0 && !address.isPigUser()) {
            address.setPigInt(1);
        }
    }
    // Log.e("SEED-TOTAL",seedTotal+" - pending out: "+seedTotalPendingOut);
    ProcessResult result = new ProcessResult();
    result.seedTotal = seedTotal;
    result.seedTotalPendingIn = seedTotalPendingIn;
    result.seedTotalPendingOut = seedTotalPendingOut;
    return result;
}
Also used : Address(run.wallet.iota.model.Address) HashMap(java.util.HashMap) Transfer(run.wallet.iota.model.Transfer) NudgeTransfer(run.wallet.iota.model.NudgeTransfer) ArrayList(java.util.ArrayList) TransferTransaction(run.wallet.iota.model.TransferTransaction)

Example 22 with Address

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

the class WalletAddressesFragment method onResume.

@Override
public void onResume() {
    super.onResume();
    if (Store.getNodeInfo() == null)
        AppService.getNodeInfo(getActivity());
    setAdapter(true);
    attachingHandler.postDelayed(runAttaching, 500);
    if (Store.getCurrentWallet() == null) {
        // firstLoadPod.setVisibility(View.VISIBLE);
        firstLoad.postDelayed(runFirstLoad, 500);
    } else {
        firstLoadPod.setVisibility(View.GONE);
        confirmPod.setVisibility(View.GONE);
        emptyAddresses.setVisibility(View.GONE);
    }
    if (Store.getCurrentWallet() != null) {
        int countemptyattached = 0;
        for (Address address : Store.getAddresses()) {
            if (address.isAttached() && address.getValue() == 0 && !address.isUsed() && !address.isPig()) {
                countemptyattached++;
            }
        }
        int countmin = Store.getAutoAttach();
        if (countemptyattached < countmin) {
            AppService.auditAddresses(getActivity(), Store.getCurrentSeed());
        }
    }
}
Also used : Address(run.wallet.iota.model.Address)

Example 23 with Address

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

the class WalletTransfersFragment method setAdapterOld.

private void setAdapterOld(boolean force) {
    if (recyclerView != null) {
        if (adapter == null) {
            firstVis = 0;
            adapter = new WalletTransfersCardAdapter(getActivity(), force);
        } else {
            firstVis = recyclerView.getVerticalScrollbarPosition();
            if (force) {
                WalletTransfersCardAdapter.load(getActivity(), true);
            }
        }
        LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity());
        recyclerView.setLayoutManager(layoutManager);
        recyclerView.setAdapter(adapter);
        if (adapter.getItemCount() != 0) {
            emptyTransfers.setVisibility(View.GONE);
            firstLoadPod.setVisibility(View.GONE);
        } else {
            if (Store.getCurrentWallet() != null) {
                emptyTransfers.setVisibility(View.VISIBLE);
            }
        }
        filterBar.setVisibility(View.GONE);
        if (WalletTransfersCardAdapter.getFilterAddress() != null) {
            Address address = Store.isAlreadyAddress(WalletTransfersCardAdapter.getFilterAddress(), Store.getAddresses());
            if (address != null) {
                filterBar.setVisibility(View.VISIBLE);
                filterBar.setBackgroundColor(AppTheme.getColorPrimaryDark(getActivity()));
                IotaToText.IotaDisplayData data = IotaToText.getIotaDisplayData(address.getValue());
                filterAddress.setText(address.getAddress());
                filterId.setText(WalletTransfersCardAdapter.getFilterAddressId());
                filterBalance.setText(data.value);
                filterBalanceThird.setText(data.thirdDecimal);
                filterBalanceUnit.setText(data.unit);
            }
        }
        recyclerView.scrollToPosition(firstVis);
    }
}
Also used : Address(run.wallet.iota.model.Address) IotaToText(jota.utils.IotaToText) WalletTransfersCardAdapter(run.wallet.iota.ui.adapter.WalletTransfersCardAdapter) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager)

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