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