Search in sources :

Example 1 with RunSendTransferResponse

use of jota.dto.response.RunSendTransferResponse 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 2 with RunSendTransferResponse

use of jota.dto.response.RunSendTransferResponse 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)

Aggregations

ArrayList (java.util.ArrayList)2 RunSendTransferResponse (jota.dto.response.RunSendTransferResponse)2 ArgumentException (jota.error.ArgumentException)2 NudgeRequest (run.wallet.iota.api.requests.NudgeRequest)2 ApiResponse (run.wallet.iota.api.responses.ApiResponse)2 NudgeResponse (run.wallet.iota.api.responses.NudgeResponse)2 NetworkError (run.wallet.iota.api.responses.error.NetworkError)2 Address (run.wallet.iota.model.Address)2 Transfer (run.wallet.iota.model.Transfer)2 Wallet (run.wallet.iota.model.Wallet)2 GetNewAddressResponse (jota.dto.response.GetNewAddressResponse)1 GetNewAddressRequest (run.wallet.iota.api.requests.GetNewAddressRequest)1