Search in sources :

Example 1 with ArgumentException

use of jota.error.ArgumentException in project run-wallet-android by runplay.

the class AddressSecurityChangeRequestHandler method handle.

@Override
public ApiResponse handle(ApiRequest request) {
    ApiResponse response;
    AddressSecurityChangeRequest gnr = ((AddressSecurityChangeRequest) request);
    try {
        jota.dto.response.GetNewAddressResponse resp = apiProxy.getNewAddress(gnr.getAddress().getAddress(), gnr.getSecurity(), gnr.getAddress().getIndex(), false, 1, true);
        // Log.e("ADDRES-SECURITY","has response: "+resp.getAddresses().get(0));
        response = new GetNewAddressResponse(gnr.getSeed(), resp);
        Store.updateAddressFromSecurity(context, gnr, (GetNewAddressResponse) response);
        return new AddressSecurityChangeResponse();
    } catch (ArgumentException e) {
        response = new NetworkError();
    }
    return response;
}
Also used : GetNewAddressResponse(run.wallet.iota.api.responses.GetNewAddressResponse) AddressSecurityChangeRequest(run.wallet.iota.api.requests.AddressSecurityChangeRequest) AddressSecurityChangeResponse(run.wallet.iota.api.responses.AddressSecurityChangeResponse) NetworkError(run.wallet.iota.api.responses.error.NetworkError) ArgumentException(jota.error.ArgumentException) ApiResponse(run.wallet.iota.api.responses.ApiResponse)

Example 2 with ArgumentException

use of jota.error.ArgumentException 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 ArgumentException

use of jota.error.ArgumentException 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 4 with ArgumentException

use of jota.error.ArgumentException in project run-wallet-android by runplay.

the class MessageNewAddressRequestHandler method handle.

@Override
public ApiResponse handle(ApiRequest request) {
    ApiResponse response;
    List<Address> addressList = MsgStore.getAddresses();
    try {
        jota.dto.response.GetNewAddressResponse resp = apiProxy.getNewAddress(String.valueOf(Store.getSeedRaw(context, ((MessageNewAddressRequest) request).getSeed())), ((MessageNewAddressRequest) request).getSecurity(), addressList.size(), ((MessageNewAddressRequest) request).isChecksum(), 1, ((MessageNewAddressRequest) request).isReturnAll());
        response = new MessageNewAddressResponse(resp);
    // Store.addAddress(context,((MessageNewAddressRequest) request).getSeed(),(MessageNewAddressResponse)response);
    } catch (ArgumentException e) {
        response = new NetworkError();
    }
    return response;
}
Also used : Address(run.wallet.iota.model.Address) MessageNewAddressResponse(run.wallet.iota.api.responses.MessageNewAddressResponse) NetworkError(run.wallet.iota.api.responses.error.NetworkError) ArgumentException(jota.error.ArgumentException) ApiResponse(run.wallet.iota.api.responses.ApiResponse)

Example 5 with ArgumentException

use of jota.error.ArgumentException 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)

Aggregations

ArgumentException (jota.error.ArgumentException)19 ApiResponse (run.wallet.iota.api.responses.ApiResponse)10 NetworkError (run.wallet.iota.api.responses.error.NetworkError)10 Address (run.wallet.iota.model.Address)6 ArrayList (java.util.ArrayList)4 Activity (android.app.Activity)3 Bundle (android.os.Bundle)3 Transfer (run.wallet.iota.model.Transfer)3 Wallet (run.wallet.iota.model.Wallet)3 KeyReuseDetectedDialog (run.wallet.iota.ui.dialog.KeyReuseDetectedDialog)3 NotificationManager (android.app.NotificationManager)2 GetNewAddressResponse (jota.dto.response.GetNewAddressResponse)2 RunSendTransferResponse (jota.dto.response.RunSendTransferResponse)2 Input (jota.model.Input)2 Transaction (jota.model.Transaction)2 Transfer (jota.model.Transfer)2 ICurl (jota.pow.ICurl)2 StopWatch (jota.utils.StopWatch)2 GetNewAddressRequest (run.wallet.iota.api.requests.GetNewAddressRequest)2 NudgeRequest (run.wallet.iota.api.requests.NudgeRequest)2