use of jota.model.Input 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.model.Input in project run-wallet-android by runplay.
the class RunIotaApiUtils method signInputsAndReturn.
public static List<String> signInputsAndReturn(final String seed, final List<Input> inputs, final Bundle bundle, final List<String> signatureFragments, ICurl curl) throws ArgumentException {
bundle.finalize(curl);
// Log.e("SIGN","add trytes "+signatureFragments.size());
bundle.addTrytes(signatureFragments);
// Log.e("SIGN","start: "+bundle.getTransactions().size());
for (int i = 0; i < bundle.getTransactions().size(); i++) {
// Log.e("SIGN","next: "+bundle.getTransactions().get(i).getValue());
if (bundle.getTransactions().get(i).getValue() < 0) {
String thisAddress = bundle.getTransactions().get(i).getAddress();
// Get the corresponding keyIndex of the address
int keyIndex = 0;
int keySecurity = 0;
for (Input input : inputs) {
if (input.getAddress().equals(thisAddress)) {
keyIndex = input.getKeyIndex();
keySecurity = input.getSecurity();
}
}
// Log.e("SIGN","address: "+thisAddress+" - sec: "+keySecurity+" - ind: "+keyIndex);
String bundleHash = bundle.getTransactions().get(i).getBundle();
// Get corresponding private key of address
int[] key = new Signing(curl).key(Converter.trits(seed), keyIndex, keySecurity);
// Log.e("SIGN","GO 1");
// First 6561 trits for the firstFragment
int[] firstFragment = Arrays.copyOfRange(key, 0, 6561);
// Log.e("SIGN","GO 2");
// Get the normalized bundle hash
int[] normalizedBundleHash = bundle.normalizedBundle(bundleHash);
// Log.e("SIGN","GO 3");
// First bundle fragment uses 27 trytes
int[] firstBundleFragment = Arrays.copyOfRange(normalizedBundleHash, 0, 27);
// Log.e("SIGN","GO 4");
// Calculate the new signatureFragment with the first bundle fragment
int[] firstSignedFragment = new Signing(curl).signatureFragment(firstBundleFragment, firstFragment);
// Log.e("SIGN","GO 5");
// Convert signature to trytes and assign the new signatureFragment
bundle.getTransactions().get(i).setSignatureFragments(Converter.trytes(firstSignedFragment));
// for each security level, add an additional signature
for (int j = 1; j < keySecurity; j++) {
// Same address as well as value = 0 (as we already spent the input)
if (bundle.getTransactions().get(i + j).getAddress().equals(thisAddress) && bundle.getTransactions().get(i + j).getValue() == 0) {
// Use the second 6562 trits
int[] secondFragment = Arrays.copyOfRange(key, 6561 * j, 6561 * (j + 1));
// The second 27 to 54 trytes of the bundle hash
int[] secondBundleFragment = Arrays.copyOfRange(normalizedBundleHash, 27 * j, 27 * (j + 1));
// Calculate the new signature
int[] secondSignedFragment = new Signing(curl).signatureFragment(secondBundleFragment, secondFragment);
// Convert signature to trytes and assign it again to this bundle entry
bundle.getTransactions().get(i + j).setSignatureFragments(Converter.trytes(secondSignedFragment));
}
}
}
}
List<String> bundleTrytes = new ArrayList<>();
// Convert all bundle entries into trytes
for (Transaction tx : bundle.getTransactions()) {
bundleTrytes.add(tx.toTrytes());
}
// Log.e("SIGN","FINISHED..............");
Collections.reverse(bundleTrytes);
return bundleTrytes;
}
use of jota.model.Input in project run-wallet-android by runplay.
the class SendTransferRequestHandler method handle.
@Override
public ApiResponse handle(ApiRequest request) {
int notificationId = Utils.createNewID();
ApiResponse response;
try {
List<Transfer> transfers = ((SendTransferRequest) request).prepareTransfers();
List<Input> inputs = null;
String remainder = null;
if (((SendTransferRequest) request).getFromAddresses() != null) {
inputs = new ArrayList<>();
for (Address address : ((SendTransferRequest) request).getFromAddresses()) {
Input inp = new Input(address.getAddress(), address.getValue(), address.getIndex(), address.getSecurity());
inputs.add(inp);
}
remainder = ((SendTransferRequest) request).getRemainder().getAddress();
}
try {
response = new SendTransferResponse(context, ((SendTransferRequest) request).getSeed(), apiProxy.sendTransfer(String.valueOf(Store.getSeedRaw(context, ((SendTransferRequest) request).getSeed())), ((SendTransferRequest) request).getSecurity(), ((SendTransferRequest) request).getDepth(), ((SendTransferRequest) request).getMinWeightMagnitude(), transfers, // inputs
inputs, // remainder address
remainder, true, false));
} catch (Exception e) {
// currently this just waits 10 seconds and re-tries
try {
wait(10000);
} catch (Exception ew) {
}
response = new SendTransferResponse(context, ((SendTransferRequest) request).getSeed(), apiProxy.sendTransfer(String.valueOf(Store.getSeedRaw(context, ((SendTransferRequest) request).getSeed())), ((SendTransferRequest) request).getSecurity(), ((SendTransferRequest) request).getDepth(), ((SendTransferRequest) request).getMinWeightMagnitude(), transfers, // inputs
inputs, // remainder address
remainder, true, false));
}
AppService.setFastMode();
} catch (ArgumentException | IllegalAccessError e) {
// Log.e("SNT","ex: "+e.getMessage());
NetworkError error = new NetworkError();
NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
if (mNotificationManager != null) {
mNotificationManager.cancel(notificationId);
}
if (e instanceof IllegalStateException) {
// 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 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 (e instanceof IllegalAccessError) {
error.setErrorType(NetworkErrorType.ACCESS_ERROR);
if (((SendTransferRequest) 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 {
if (error.getErrorType() != NetworkErrorType.KEY_REUSE_ERROR) {
error.setErrorType(NetworkErrorType.NETWORK_ERROR);
}
if (((SendTransferRequest) request).getValue() == 0 && ((SendTransferRequest) 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);
}
}
response = error;
}
if (response instanceof SendTransferResponse && ((SendTransferRequest) request).getValue() == 0 && ((SendTransferRequest) request).getTag().equals(Constants.NEW_ADDRESS_TAG)) {
} else if (response instanceof SendTransferResponse) {
if (Arrays.asList(((SendTransferResponse) response).getSuccessfully()).contains(true)) {
if (AppService.isAppStarted()) {
NotificationHelper.vibrate(context);
} else {
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