Search in sources :

Example 1 with ApiResponse

use of run.wallet.iota.api.responses.ApiResponse in project run-wallet-android by runplay.

the class BasicApiProvider method processRequest.

@Override
public ApiResponse processRequest(ApiRequest apiRequest) {
    ApiResponse response = null;
    try {
        if (useRequestHandlerMap.containsKey(apiRequest.getClass())) {
            RequestHandler requestHandler = useRequestHandlerMap.get(apiRequest.getClass());
            response = requestHandler.handle(apiRequest);
        }
    } catch (IllegalAccessError e) {
        NetworkError error = new NetworkError();
        error.setErrorType(NetworkErrorType.ACCESS_ERROR);
        response = error;
        Log.e("ERR-B-API1", "" + e.getMessage());
    } catch (Exception e) {
        Log.e("ERR-B-API2", e.toString() + " -- " + e.getMessage());
        response = new NetworkError();
    }
    return response == null ? new NetworkError() : response;
}
Also used : RequestHandler(run.wallet.iota.api.handler.RequestHandler) WebGetExchangeRatesHistoryRequestHandler(run.wallet.iota.api.handler.WebGetExchangeRatesHistoryRequestHandler) WebGetExchangeRatesRequestHandler(run.wallet.iota.api.handler.WebGetExchangeRatesRequestHandler) NetworkError(run.wallet.iota.api.responses.error.NetworkError) ApiResponse(run.wallet.iota.api.responses.ApiResponse)

Example 2 with ApiResponse

use of run.wallet.iota.api.responses.ApiResponse in project run-wallet-android by runplay.

the class BasicRequestTask method doInBackground.

@Override
protected ApiResponse doInBackground(ApiRequest... params) {
    Context context = this.context.get();
    if (context != null) {
        start = new Date();
        ApiRequest apiRequest = params[0];
        tag = apiRequest.getClass().getCanonicalName();
        BasicApiProvider basicApi = new BasicApiProvider(context);
        ApiResponse response = basicApi.processRequest(apiRequest);
        return response;
    }
    // TaskManager.removeTask(tag);
    return null;
}
Also used : Context(android.content.Context) ApiRequest(run.wallet.iota.api.requests.ApiRequest) Date(java.util.Date) ApiResponse(run.wallet.iota.api.responses.ApiResponse)

Example 3 with ApiResponse

use of run.wallet.iota.api.responses.ApiResponse in project run-wallet-android by runplay.

the class IotaMessageApiProvider method processRequest.

@Override
public ApiResponse processRequest(ApiRequest apiRequest) {
    ApiResponse response = null;
    try {
        // Log.e("IotaMessageApiProvider", "");
        if (this.requestHandlerMap.containsKey(apiRequest.getClass())) {
            // Log.e("IotaMessageApiProvider", "requesting");
            RequestHandler requestHandler = this.requestHandlerMap.get(apiRequest.getClass());
            response = requestHandler.handle(apiRequest);
        }
    } catch (IllegalAccessError e) {
        NetworkError error = new NetworkError();
        error.setErrorType(NetworkErrorType.ACCESS_ERROR);
        response = error;
    // Log.e("IotaMessageApi ERR",""+e.getMessage());
    } catch (Exception e) {
        Log.e("ERR-API", "ex: " + e.getMessage());
        response = new NetworkError();
    }
    return response == null ? new NetworkError() : response;
}
Also used : MessageFirstLoadRequestHandler(run.wallet.iota.api.handler.MessageFirstLoadRequestHandler) RequestHandler(run.wallet.iota.api.handler.RequestHandler) MessageSendRequestHandler(run.wallet.iota.api.handler.MessageSendRequestHandler) MessageNewAddressRequestHandler(run.wallet.iota.api.handler.MessageNewAddressRequestHandler) NetworkError(run.wallet.iota.api.responses.error.NetworkError) ApiResponse(run.wallet.iota.api.responses.ApiResponse)

Example 4 with ApiResponse

use of run.wallet.iota.api.responses.ApiResponse in project run-wallet-android by runplay.

the class GetAccountDataRequestHandler method handle.

@Override
public ApiResponse handle(ApiRequest inrequest) {
    GetAccountDataRequest request = (GetAccountDataRequest) inrequest;
    GetTransferResponse gtr = null;
    StopWatch stopWatch = new StopWatch();
    NodeInfoResponse nodeInfo = Store.getNodeInfo();
    Wallet wallet = Store.getWallet(context, request.getSeed());
    if (wallet != null && nodeInfo != null) {
        List<Address> alreadyAddress = Store.getAddresses(context, request.getSeed());
        List<Address> usingAddress = Store.getDisplayAddresses(alreadyAddress);
        List<Address> checkAddress = new ArrayList<>();
        if (request.getIfSingleAddressOrNull() != null) {
            Address address = Store.isAlreadyAddress(request.getIfSingleAddressOrNull(), alreadyAddress);
            if (address != null) {
                checkAddress.add(address);
            }
        } else {
            for (Address add : usingAddress) {
                if (!add.isUsed() || (add.isUsed() && (add.getPendingValue() != 0 || add.getValue() != 0))) {
                    if (request.isForce() || nodeInfo.getLatestMilestoneIndex() != add.getLastMilestone()) {
                        checkAddress.add(add);
                    }
                }
            }
        }
        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 (addr.getValue() != gotBalance || addr.getPendingValue() != 0) {
                        addr.setValue(gotBalance);
                        checkAddressString.add(addr.getAddress());
                    }
                }
                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, request.getSeed());
                    Audit.bundlePopulateTransfers(gtr.getTransfers(), transfers, alreadyAddress);
                    if (request.getIfSingleAddressOrNull() != null) {
                        Audit.setTransfersToAddresses(request.getSeed(), transfers, alreadyAddress, wallet, alreadyTransfer);
                    } else {
                        Audit.setTransfersToAddresses(request.getSeed(), transfers, alreadyAddress, wallet, alreadyTransfer);
                    }
                    Audit.processNudgeAttempts(context, request.getSeed(), transfers);
                    Store.updateAccountData(context, request.getSeed(), wallet, transfers, alreadyAddress);
                }
                if (request.getIfSingleAddressOrNull() == null) {
                    WalletAddressesFragment.setShouldRefresh(true);
                    WalletTransfersFragment.setShouldRefresh(true);
                    List<String> checkOthersString = new ArrayList<>();
                    for (Address address : checkAddress) {
                        if (!checkAddressString.contains(address.getAddress()))
                            checkOthersString.add(address.getAddress());
                    }
                    if (!checkOthersString.isEmpty()) {
                        Bundle[] bundles = apiProxy.bundlesFromAddresses(checkOthersString.toArray(new String[checkOthersString.size()]), true);
                        gtr = GetTransferResponse.create(bundles, stopWatch.getElapsedTimeMili());
                    }
                    if (gtr != null && gtr.getTransfers().length > 0) {
                        transfers = new ArrayList<>();
                        List<Transfer> alreadyTransfer = Store.getTransfers(context, request.getSeed());
                        Audit.bundlePopulateTransfers(gtr.getTransfers(), transfers, alreadyAddress);
                        if (request.getIfSingleAddressOrNull() != null) {
                            Audit.setTransfersToAddresses(request.getSeed(), transfers, alreadyAddress, wallet, alreadyTransfer);
                        } else {
                            Audit.setTransfersToAddresses(request.getSeed(), transfers, alreadyAddress, wallet, alreadyTransfer);
                        }
                        Audit.processNudgeAttempts(context, request.getSeed(), transfers);
                        Store.updateAccountData(context, request.getSeed(), wallet, transfers, alreadyAddress);
                    }
                }
            } catch (Exception e) {
                Log.e("ERR066", "ERROR: " + e.getMessage());
            }
        }
        AppService.setFastMode();
        return new GetAccountDataResponse();
    }
    return new ApiResponse();
}
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) NodeInfoResponse(run.wallet.iota.api.responses.NodeInfoResponse) ArrayList(java.util.ArrayList) ArgumentException(jota.error.ArgumentException) ApiResponse(run.wallet.iota.api.responses.ApiResponse) StopWatch(jota.utils.StopWatch) GetAccountDataResponse(run.wallet.iota.api.responses.GetAccountDataResponse) GetAccountDataRequest(run.wallet.iota.api.requests.GetAccountDataRequest) Transfer(run.wallet.iota.model.Transfer)

Example 5 with ApiResponse

use of run.wallet.iota.api.responses.ApiResponse 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)

Aggregations

ApiResponse (run.wallet.iota.api.responses.ApiResponse)20 NetworkError (run.wallet.iota.api.responses.error.NetworkError)13 ArgumentException (jota.error.ArgumentException)11 Address (run.wallet.iota.model.Address)8 ArrayList (java.util.ArrayList)6 Transfer (run.wallet.iota.model.Transfer)5 Wallet (run.wallet.iota.model.Wallet)4 Activity (android.app.Activity)3 Context (android.content.Context)3 Bundle (android.os.Bundle)3 GetNewAddressResponse (jota.dto.response.GetNewAddressResponse)3 StopWatch (jota.utils.StopWatch)3 RequestHandler (run.wallet.iota.api.handler.RequestHandler)3 ApiRequest (run.wallet.iota.api.requests.ApiRequest)3 GetNewAddressRequest (run.wallet.iota.api.requests.GetNewAddressRequest)3 NudgeRequest (run.wallet.iota.api.requests.NudgeRequest)3 NudgeResponse (run.wallet.iota.api.responses.NudgeResponse)3 NotificationManager (android.app.NotificationManager)2 Date (java.util.Date)2 FindTransactionResponse (jota.dto.response.FindTransactionResponse)2