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;
}
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;
}
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;
}
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();
}
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;
}
Aggregations