use of run.wallet.iota.api.requests.MessageSendRequest in project run-wallet-android by runplay.
the class AppService method sendMessageToAddress.
public static void sendMessageToAddress(Context context, Seeds.Seed seed, String toAddress, String amountIOTA, String message, String tag) {
if (Validator.isValidCaller() && Store.getCurrentSeed() != null) {
TaskManager rt = new TaskManager(SERVICE);
MessageSendRequest tir = new MessageSendRequest(seed, toAddress, message, tag);
runMessageTask(rt, tir);
}
}
use of run.wallet.iota.api.requests.MessageSendRequest in project run-wallet-android by runplay.
the class MessageSendRequestHandler method handle.
@Override
public ApiResponse handle(ApiRequest request) {
int notificationId = Utils.createNewID();
ApiResponse response;
Log.e("IotaMsg", "MessageSendRequestHandler handle: " + request.toString());
// if we generate a new address the tag == address
if (((MessageSendRequest) request).getValue().equals("0") && ((MessageSendRequest) request).getTag().equals(Constants.NEW_ADDRESS_TAG)) {
NotificationHelper.requestNotification(context, R.drawable.ic_add, context.getString(R.string.notification_attaching_new_address_request_title), notificationId);
} else {
NotificationHelper.requestNotification(context, R.drawable.ic_fab_send, context.getString(R.string.notification_send_transfer_request_title), notificationId);
}
try {
response = new MessageSendResponse(context, ((MessageSendRequest) request).getSeed(), apiProxy.sendTransfer(String.valueOf(Store.getSeedRaw(context, ((MessageSendRequest) request).getSeed())), ((MessageSendRequest) request).getSecurity(), ((MessageSendRequest) request).getDepth(), ((MessageSendRequest) request).getMinWeightMagnitude(), ((MessageSendRequest) request).prepareTransfer(), // inputs
null, // remainder address
null, false, true));
} catch (ArgumentException | IllegalAccessError e) {
NetworkError error = new NetworkError();
Log.e("IotaMsg", "MessageSendRequestHandler exception: " + e.getMessage());
NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
if (mNotificationManager != null) {
Log.e("IotaMsg", "MessageSendRequestHandler exception: 1");
mNotificationManager.cancel(notificationId);
}
if (e instanceof ArgumentException) {
Log.e("IotaMsg", "MessageSendRequestHandler exception: 2: " + ((ArgumentException) e).getMessage());
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 (e instanceof IllegalAccessError) {
Log.e("IotaMsg", "MessageSendRequestHandler exception: 3: " + ((IllegalAccessError) e).getMessage());
error.setErrorType(NetworkErrorType.ACCESS_ERROR);
if (((MessageSendRequest) request).getTag().equals(Constants.NEW_ADDRESS_TAG))
NotificationHelper.responseNotification(context, R.drawable.ic_error, context.getString(R.string.notification_address_attach_to_tangle_blocked_title), notificationId);
else
NotificationHelper.responseNotification(context, R.drawable.ic_error, context.getString(R.string.notification_transfer_attach_to_tangle_blocked_title), notificationId);
} else {
Log.e("IotaMsg", "MessageSendRequestHandler exception: 4");
if (error.getErrorType() != NetworkErrorType.KEY_REUSE_ERROR) {
error.setErrorType(NetworkErrorType.NETWORK_ERROR);
}
if (((MessageSendRequest) request).getValue().equals("0") && ((MessageSendRequest) request).getTag().equals(Constants.NEW_ADDRESS_TAG)) {
NotificationHelper.responseNotification(context, R.drawable.ic_address, context.getString(R.string.notification_attaching_new_address_response_failed_title), notificationId);
} else {
NotificationHelper.responseNotification(context, R.drawable.ic_fab_send, context.getString(R.string.notification_send_transfer_response_failed_title), notificationId);
}
}
Log.e("IotaMsg", "MessageSendRequestHandler exception: " + error.toString());
response = error;
}
if (response instanceof SendTransferResponse && ((MessageSendRequest) request).getValue().equals("0") && ((MessageSendRequest) request).getTag().equals(Constants.NEW_ADDRESS_TAG)) {
Log.e("IotaMsg", "MessageSendRequestHandler instanceof SendTransferResponse");
if (Arrays.asList(((SendTransferResponse) response).getSuccessfully()).contains(true))
NotificationHelper.responseNotification(context, R.drawable.ic_address, context.getString(R.string.notification_attaching_new_address_response_succeeded_title), notificationId);
else
NotificationHelper.responseNotification(context, R.drawable.ic_address, context.getString(R.string.notification_attaching_new_address_response_failed_title), notificationId);
} else if (response instanceof SendTransferResponse) {
Log.e("IotaMsg", "MessageSendRequestHandler instanceof SendTransferResponse2");
if (Arrays.asList(((SendTransferResponse) response).getSuccessfully()).contains(true))
NotificationHelper.responseNotification(context, R.drawable.ic_fab_send, context.getString(R.string.notification_send_transfer_response_succeeded_title), notificationId);
else
NotificationHelper.responseNotification(context, R.drawable.ic_fab_send, context.getString(R.string.notification_send_transfer_response_failed_title), notificationId);
}
return response;
}
Aggregations