Search in sources :

Example 1 with GetNewAddressRequest

use of run.wallet.iota.api.requests.GetNewAddressRequest in project run-wallet-android by runplay.

the class GetNewAddressRequestHandler method handle.

@Override
public ApiResponse handle(ApiRequest request) {
    ApiResponse response;
    GetNewAddressRequest gnr = ((GetNewAddressRequest) request);
    List<Address> alreadyAddress = Store.getAddresses(context, gnr.getSeed());
    gnr.setIndex(alreadyAddress.size());
    try {
        jota.dto.response.GetNewAddressResponse resp = apiProxy.getNewAddress(String.valueOf(Store.getSeedRaw(context, gnr.getSeed())), gnr.getSecurity(), alreadyAddress.size(), gnr.isChecksum(), 1, gnr.isReturnAll());
        /*
            jota.dto.response.GetNewAddressResponse resp=apiProxy.getNewAddress(((GetNewAddressRequest) request).getSeedValue(),
                    ((GetNewAddressRequest) request).getSecurity(),
                    ((GetNewAddressRequest) request).getIndex(),
                    ((GetNewAddressRequest) request).isChecksum(),
                    ((GetNewAddressRequest) request).getTotal(),
                    ((GetNewAddressRequest) request).isReturnAll());
            */
        response = new GetNewAddressResponse(gnr.getSeed(), resp);
        Store.addAddress(context, gnr, (GetNewAddressResponse) response);
        AppService.auditAddresses(context, gnr.getSeed());
    // SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context.getApplicationContext());
    // if (prefs.getBoolean(Constants.PREFERENCES_LOCAL_POW, true)
    // && !((GetNewAddressResponse) response).getAddresses().isEmpty()) {
    // AppService.attachNewAddress(context,((GetNewAddressRequest) request).getSeed(),((GetNewAddressResponse) response).getAddresses().get(0));
    // }
    } catch (ArgumentException e) {
        response = new NetworkError();
    }
    return response;
}
Also used : GetNewAddressResponse(run.wallet.iota.api.responses.GetNewAddressResponse) Address(run.wallet.iota.model.Address) GetNewAddressRequest(run.wallet.iota.api.requests.GetNewAddressRequest) NetworkError(run.wallet.iota.api.responses.error.NetworkError) ArgumentException(jota.error.ArgumentException) ApiResponse(run.wallet.iota.api.responses.ApiResponse)

Example 2 with GetNewAddressRequest

use of run.wallet.iota.api.requests.GetNewAddressRequest in project run-wallet-android by runplay.

the class NudgeRequestHandlerOld method doNudge.

public static ApiResponse doNudge(RunIotaAPI apiProxy, Context context, ApiRequest inrequest) {
    ApiResponse response;
    int notificationId = Utils.createNewID();
    // int notificationId = Utils.createNewID();
    NudgeRequest request = (NudgeRequest) inrequest;
    // NotificationHelper.requestNotification(context, R.drawable.send_white, context.getString(R.string.notification_replay_bundle_request_title), notificationId);
    Transfer nudgeMe = request.getTransfer();
    try {
        List<Address> alreadyAddress = Store.getAddresses(context, request.getSeed());
        String useAddress = null;
        Address fullAddress = null;
        List<Address> emptyAttached = Store.getEmptyAttached(alreadyAddress);
        // allows up to 5 pre hidden addresses
        int max = Store.getAutoAttach() + 5;
        if (emptyAttached.size() <= max) {
            GetNewAddressRequest gnr = new GetNewAddressRequest(request.getSeed());
            gnr.setIndex(alreadyAddress.size());
            final GetNewAddressResponse gna = apiProxy.getNewAddress(String.valueOf(Store.getSeedRaw(context, request.getSeed())), gnr.getSecurity(), alreadyAddress.size(), gnr.isChecksum(), 1, gnr.isReturnAll());
            run.wallet.iota.api.responses.GetNewAddressResponse gnar = new run.wallet.iota.api.responses.GetNewAddressResponse(request.getSeed(), gna);
            Store.addAddress(context, gnr, gnar);
            alreadyAddress = Store.getAddresses(context, request.getSeed());
            useAddress = gnar.getAddresses().get(0);
            fullAddress = Store.isAlreadyAddress(useAddress, alreadyAddress);
        } else {
            fullAddress = emptyAttached.get(0);
            useAddress = fullAddress.getAddress();
        }
        // useAddress=nudgeMe
        // }
        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, fullAddress.getIndex(), fullAddress.getSecurity(), 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) {
                    Transfer transfer = new Transfer(useAddress, 0, "RUN9NUDGE9HASH9" + nudgeMe.getHash() + "9END", RunIotaAPI.NUDGE_TAG);
                    transfer.setHash(gotHash);
                    transfer.setTimestamp(System.currentTimeMillis());
                    if (nodeInfo != null) {
                        transfer.setMilestoneCreated(nodeInfo.getLatestMilestoneIndex());
                    }
                    transfers.add(transfer);
                    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;
            }
        }
        // if(nresp==null) {
        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 : GetNewAddressResponse(jota.dto.response.GetNewAddressResponse) Address(run.wallet.iota.model.Address) GetNewAddressRequest(run.wallet.iota.api.requests.GetNewAddressRequest) ArrayList(java.util.ArrayList) NudgeResponse(run.wallet.iota.api.responses.NudgeResponse) ApiResponse(run.wallet.iota.api.responses.ApiResponse) ArgumentException(jota.error.ArgumentException) Wallet(run.wallet.iota.model.Wallet) NudgeRequest(run.wallet.iota.api.requests.NudgeRequest) NetworkError(run.wallet.iota.api.responses.error.NetworkError) RunSendTransferResponse(jota.dto.response.RunSendTransferResponse) Transfer(run.wallet.iota.model.Transfer)

Example 3 with GetNewAddressRequest

use of run.wallet.iota.api.requests.GetNewAddressRequest in project run-wallet-android by runplay.

the class AppService method generateNewAddress.

public static void generateNewAddress(Context context, Seeds.Seed seed) {
    if (Validator.isValidCaller() && seed != null) {
        TaskManager rt = new TaskManager(SERVICE);
        GetNewAddressRequest gtr = new GetNewAddressRequest(seed);
        runTask(rt, gtr);
    }
}
Also used : TaskManager(run.wallet.iota.api.TaskManager) GetNewAddressRequest(run.wallet.iota.api.requests.GetNewAddressRequest)

Example 4 with GetNewAddressRequest

use of run.wallet.iota.api.requests.GetNewAddressRequest in project run-wallet-android by runplay.

the class UiManager method displayInfoBar.

public static void displayInfoBar(Activity context, LinearLayout forView) {
    makeElements(context);
    forView.setBackgroundColor(B.getColor(context, AppTheme.getPrimaryDark()));
    try {
        List<ApiRequest> attaching = AppService.getRunningTasks();
        List<LinearLayout> processing = new ArrayList<>();
        if (!attaching.isEmpty()) {
            Seeds.Seed currentSeed = Store.getCurrentSeed();
            for (ApiRequest req : attaching) {
                if (req instanceof SendTransferRequest) {
                    SendTransferRequest str = (SendTransferRequest) req;
                    if (str.getSeed().id.equals(currentSeed.id)) {
                        if (str.getValue() == 0) {
                            processing.add(createProcessRunningPod(context, R.drawable.tran_white, context.getString(R.string.info_new_attach), 0));
                        } else {
                            processing.add(createProcessRunningPod(context, R.drawable.send_white, context.getString(R.string.info_transfer), str.getValue()));
                        }
                    }
                } else if (req instanceof GetAccountDataRequest) {
                    GetAccountDataRequest request = (GetAccountDataRequest) req;
                    if (request.getSeed().id.equals(currentSeed.id)) {
                        processing.add(createProcessRunningPod(context, R.drawable.refresh_white, context.getString(R.string.info_refresh), 0));
                    }
                } else if (req instanceof GetNewAddressRequest) {
                    GetNewAddressRequest request = (GetNewAddressRequest) req;
                    if (request.getSeed().id.equals(currentSeed.id)) {
                        processing.add(createProcessRunningPod(context, R.drawable.tran_white, context.getString(R.string.info_new_address), 0));
                    }
                } else if (req instanceof GetFirstLoadRequest) {
                    GetFirstLoadRequest request = (GetFirstLoadRequest) req;
                    if (request.getSeed().id.equals(currentSeed.id)) {
                        processing.add(createProcessRunningPod(context, R.drawable.refresh_white, context.getString(R.string.info_first_load), 0));
                    }
                } else if (req instanceof AuditAddressesRequest) {
                    AuditAddressesRequest request = (AuditAddressesRequest) req;
                    if (request.getSeed().id.equals(currentSeed.id)) {
                        processing.add(createProcessRunningPod(context, R.drawable.refresh_white, context.getString(R.string.info_audit), 0));
                    }
                } else if (req instanceof ReplayBundleRequest) {
                    ReplayBundleRequest request = (ReplayBundleRequest) req;
                    if (request.getSeed().id.equals(currentSeed.id)) {
                        processing.add(createProcessRunningPod(context, R.drawable.send_white, context.getString(R.string.info_resend), 0));
                    }
                } else if (req instanceof NudgeRequest) {
                    NudgeRequest request = (NudgeRequest) req;
                    if (request.getSeed().id.equals(currentSeed.id)) {
                        processing.add(createProcessRunningPod(context, R.drawable.send_white, context.getString(R.string.info_nudge), 0));
                    }
                } else if (req instanceof AutoNudgeRequest) {
                    // if(request.getSeed().id.equals(currentSeed.id)) {
                    processing.add(createProcessRunningPod(context, R.drawable.send_white, context.getString(R.string.auto), 0));
                // }
                } else if (req instanceof RefreshUsedAddressesRequest) {
                    // if(request.getSeed().id.equals(currentSeed.id)) {
                    processing.add(createProcessRunningPod(context, R.drawable.send_white, context.getString(R.string.info_audit), 0));
                // }
                }
            }
        }
        forView.removeAllViews();
        if (!processing.isEmpty()) {
            for (LinearLayout addview : processing) {
                forView.addView(addview);
            }
            forView.canScrollHorizontally(View.LAYOUT_DIRECTION_LTR);
            if (forView.getVisibility() != View.VISIBLE) {
                forView.setVisibility(View.VISIBLE);
                AnimationUtils.loadAnimation(context, R.anim.slide_in_from_bottom);
            }
        } else if (Store.getUsedAddressCheckResult() != null) {
            Snackbar.make(forView, Store.getUsedAddressCheckResult(), Snackbar.LENGTH_LONG).show();
            Store.setUsedAddressCheckResult(null);
        } else if (Store.getCurrentSeed().warnUsed) {
            SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
            boolean showused = prefs.getBoolean(Constants.PREFERENCES_SHOW_USED, true);
            TextView messy = new TextView(context);
            if (showused) {
                messy.setText(context.getString(R.string.usedAddressWarn));
            } else {
                messy.setText(context.getString(R.string.usedAddressSettings));
            }
            messy.setTextColor(Color.WHITE);
            messy.setPadding(30, 30, 30, 30);
            messy.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    Intent settings = new Intent(context, SettingsActivity.class);
                    context.startActivityForResult(settings, 0);
                }
            });
            forView.addView(messy);
            forView.canScrollHorizontally(View.LAYOUT_DIRECTION_LTR);
            if (forView.getVisibility() != View.VISIBLE) {
                AnimationUtils.loadAnimation(context, R.anim.slide_in_from_bottom);
            }
        } else {
            SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context.getApplicationContext());
            if (prefs.getBoolean(Constants.PREFERENCES_SHOW_CANCELLED, true) && !prefs.getBoolean(Constants.PREFERENCES_SHOW_ATTACH, true) && Store.getTransfers().size() > 15) {
                int count = prefs.getInt(Constants.PREF_MSG_MESSY, 0);
                if (count < 2) {
                    TextView messy = new TextView(context);
                    messy.setText(context.getString(R.string.message_messy_view));
                    messy.setTextColor(Color.WHITE);
                    messy.setPadding(30, 30, 30, 30);
                    // messy.setText
                    messy.setOnClickListener(new View.OnClickListener() {

                        @Override
                        public void onClick(View v) {
                            Intent settings = new Intent(context, SettingsActivity.class);
                            context.startActivityForResult(settings, 0);
                        }
                    });
                    forView.addView(messy);
                    forView.canScrollHorizontally(View.LAYOUT_DIRECTION_LTR);
                    if (forView.getVisibility() != View.VISIBLE) {
                        AnimationUtils.loadAnimation(context, R.anim.slide_in_from_bottom);
                    }
                    prefs.edit().putInt(Constants.PREF_MSG_MESSY, ++count).commit();
                }
            } else {
                AnimationUtils.loadAnimation(context, R.anim.slide_out_to_bottom);
            }
        }
    } catch (Exception e) {
    }
}
Also used : Seeds(run.wallet.iota.model.Seeds) GetNewAddressRequest(run.wallet.iota.api.requests.GetNewAddressRequest) ArrayList(java.util.ArrayList) AuditAddressesRequest(run.wallet.iota.api.requests.AuditAddressesRequest) ApiRequest(run.wallet.iota.api.requests.ApiRequest) RefreshUsedAddressesRequest(run.wallet.iota.api.requests.RefreshUsedAddressesRequest) SendTransferRequest(run.wallet.iota.api.requests.SendTransferRequest) TextView(android.widget.TextView) SharedPreferences(android.content.SharedPreferences) AutoNudgeRequest(run.wallet.iota.api.requests.AutoNudgeRequest) NudgeRequest(run.wallet.iota.api.requests.NudgeRequest) Intent(android.content.Intent) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) GetAccountDataRequest(run.wallet.iota.api.requests.GetAccountDataRequest) ReplayBundleRequest(run.wallet.iota.api.requests.ReplayBundleRequest) LinearLayout(android.widget.LinearLayout) AutoNudgeRequest(run.wallet.iota.api.requests.AutoNudgeRequest) SettingsActivity(run.wallet.iota.ui.activity.SettingsActivity) GetFirstLoadRequest(run.wallet.iota.api.requests.GetFirstLoadRequest)

Example 5 with GetNewAddressRequest

use of run.wallet.iota.api.requests.GetNewAddressRequest in project run-wallet-android by runplay.

the class AuditAddressesRequestHandler method handle.

@Override
public ApiResponse handle(ApiRequest inrequest) {
    AuditAddressesRequest request = (AuditAddressesRequest) inrequest;
    // check less than 2, 1..iteself, and no others
    if (AppService.countSeedRunningTasks(request.getSeed()) < 2) {
        List<Address> addresses = Store.getAddresses(context, request.getSeed());
        List<Address> getaddresses = new ArrayList<>();
        if (!addresses.isEmpty()) {
            for (Address address : addresses) {
                if (!address.isAttached()) {
                    getaddresses.add(address);
                }
            }
        }
        if (!getaddresses.isEmpty()) {
            GetNodeInfoResponse info = apiProxy.getNodeInfo();
            if (info != null && info.getLatestMilestoneIndex() == info.getLatestSolidSubtangleMilestoneIndex()) {
                // List<String> addstr = new ArrayList<>();
                int count = 0;
                for (Address add : getaddresses) {
                    FindTransactionResponse tr1 = null;
                    try {
                        tr1 = apiProxy.findTransactionsByAddresses(add.getAddress());
                    } catch (Exception e) {
                    }
                    if (tr1 != null) {
                        if (tr1.getHashes().length == 0) {
                            AppService.attachNewAddress(context, request.getSeed(), add.getAddress());
                        } else {
                            add.setAttached(true);
                            Store.updateAddress(context, request.getSeed(), add);
                            AppService.refreshEvent();
                        }
                    // addstr.add(add.getAddress());
                    }
                    if (++count > 1 || tr1 == null)
                        ;
                    break;
                }
            }
        } else {
            int countemptyattached = 0;
            for (Address address : addresses) {
                if (address.isAttached() && address.getValue() == 0 && !address.isUsed() && !address.isPig()) {
                    countemptyattached++;
                }
            }
            Store.loadDefaults(context);
            int countmin = Store.getAutoAttach();
            if (countemptyattached < countmin) {
                // Log.e("AUDIT","Gen new address");
                try {
                    GetNewAddressRequest gnr = new GetNewAddressRequest(request.getSeed());
                    gnr.setIndex(addresses.size());
                    final GetNewAddressResponse gna = apiProxy.getNewAddress(String.valueOf(Store.getSeedRaw(context, request.getSeed())), gnr.getSecurity(), addresses.size(), gnr.isChecksum(), 1, gnr.isReturnAll());
                    run.wallet.iota.api.responses.GetNewAddressResponse gnar = new run.wallet.iota.api.responses.GetNewAddressResponse(request.getSeed(), gna);
                    Store.addAddress(context, gnr, gnar);
                    AppService.auditAddressesWithDelay(context, request.getSeed());
                } catch (Exception e) {
                }
            } else {
            // Log.e("AUDIT","no address need creating");
            }
        }
    } else {
    // Log.e("AUDIT","Called but skipped.. hopefully good");
    }
    return new ApiResponse();
}
Also used : FindTransactionResponse(jota.dto.response.FindTransactionResponse) GetNewAddressResponse(jota.dto.response.GetNewAddressResponse) Address(run.wallet.iota.model.Address) GetNewAddressRequest(run.wallet.iota.api.requests.GetNewAddressRequest) ArrayList(java.util.ArrayList) AuditAddressesRequest(run.wallet.iota.api.requests.AuditAddressesRequest) ApiResponse(run.wallet.iota.api.responses.ApiResponse) GetNodeInfoResponse(jota.dto.response.GetNodeInfoResponse)

Aggregations

GetNewAddressRequest (run.wallet.iota.api.requests.GetNewAddressRequest)5 ArrayList (java.util.ArrayList)3 ApiResponse (run.wallet.iota.api.responses.ApiResponse)3 Address (run.wallet.iota.model.Address)3 GetNewAddressResponse (jota.dto.response.GetNewAddressResponse)2 ArgumentException (jota.error.ArgumentException)2 AuditAddressesRequest (run.wallet.iota.api.requests.AuditAddressesRequest)2 NudgeRequest (run.wallet.iota.api.requests.NudgeRequest)2 NetworkError (run.wallet.iota.api.responses.error.NetworkError)2 Intent (android.content.Intent)1 SharedPreferences (android.content.SharedPreferences)1 View (android.view.View)1 ImageView (android.widget.ImageView)1 LinearLayout (android.widget.LinearLayout)1 TextView (android.widget.TextView)1 FindTransactionResponse (jota.dto.response.FindTransactionResponse)1 GetNodeInfoResponse (jota.dto.response.GetNodeInfoResponse)1 RunSendTransferResponse (jota.dto.response.RunSendTransferResponse)1 TaskManager (run.wallet.iota.api.TaskManager)1 ApiRequest (run.wallet.iota.api.requests.ApiRequest)1