Search in sources :

Example 1 with Transfer

use of jota.model.Transfer in project run-wallet-android by runplay.

the class AutoNudger method main.

public static void main(String[] args) {
    try {
        String protocol = "";
        String host = "";
        String port = "";
        IotaAPI api = new IotaAPI.Builder().localPoW(new PearlDiverLocalPoW()).protocol(protocol).host(host).port(port).build();
        System.out.println("AutoNudger connecting to host " + api.getHost() + " Port: " + api.getPort() + " Protocol: " + api.getProtocol());
        GetNodeInfoResponse response = api.getNodeInfo();
        String seed1 = "VEEMLFEYESWZPGXPQLV9GPUVFWTBYXZNSDPXKLLQUQTGFVXRNWKJLDCBAAQKVEWWCDLXU9BGRTR9QCMS9";
        long counter = 0;
        double avgTxTime = 0;
        long totalTxTime = 0;
        while (1 == 1) {
            long yourmilliseconds = System.currentTimeMillis();
            SimpleDateFormat sdf = new SimpleDateFormat("MMM dd,yyyy HH:mm:ss");
            Date resultdate = new Date(yourmilliseconds);
            System.out.println("---------------------------------------------------------------------------------------------------------------");
            System.out.println("LatestMilestoneIndex " + response.getLatestMilestoneIndex() + " LatestSolidSubtangleMilestoneIndex " + response.getLatestSolidSubtangleMilestoneIndex());
            System.out.println("Tips " + response.getTips());
            Random r = new Random();
            String alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ9";
            String addrString = "WONKYTONKY9HELLO9WORLD";
            StringBuilder stringBuilder = new StringBuilder();
            String finalString = stringBuilder.toString();
            for (int i = 0; i < 59; i++) {
                stringBuilder.append(alphabet.charAt(r.nextInt(alphabet.length())));
            }
            // addrString +=
            // "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";
            addrString += stringBuilder.toString();
            String address = Checksum.addChecksum(addrString);
            // System.out.println(address);
            List<Transfer> transfers = new ArrayList<>();
            transfers.add(new Transfer(address, 0, TEST_MESSAGE, TEST_TAG));
            System.out.println("new Address : " + address);
            SendTransferResponse str = api.sendTransfer(seed1, 2, DEPTH, MIN_WEIGHT_MAGNITUDE, transfers, null, null, false, false);
            if (str.getSuccessfully() != null && str.getSuccessfully().length > 0)
                System.out.println("success? " + str.getSuccessfully()[0]);
            else
                System.out.println("success? " + "false");
            counter++;
            System.out.println("Counter tx's: " + counter);
            yourmilliseconds = System.currentTimeMillis();
            Date resultdate2 = new Date(yourmilliseconds);
            System.out.println(sdf.format(resultdate2));
            long seconds = (resultdate2.getTime() - resultdate.getTime()) / 1000;
            totalTxTime += seconds;
            avgTxTime = totalTxTime / counter;
            System.out.println("last tx time: " + seconds + " sec");
            System.out.println("average tx time: " + avgTxTime + " sec");
        }
    } catch (ArgumentException e) {
        Log.e("SPA", "" + e.getMessage());
    }
}
Also used : SendTransferResponse(jota.dto.response.SendTransferResponse) IotaAPI(jota.IotaAPI) ArrayList(java.util.ArrayList) Date(java.util.Date) PearlDiverLocalPoW(cfb.pearldiver.PearlDiverLocalPoW) Random(java.util.Random) Transfer(jota.model.Transfer) GetNodeInfoResponse(jota.dto.response.GetNodeInfoResponse) ArgumentException(jota.error.ArgumentException) SimpleDateFormat(java.text.SimpleDateFormat)

Example 2 with Transfer

use of jota.model.Transfer in project isf-jclient by mikrohash.

the class IotaAPI method sendSpam.

public void sendSpam() throws ArgumentException {
    ArrayList<Transfer> transfers = new ArrayList<Transfer>();
    String message = UploadDataManager.getNextData();
    transfers.add(new Transfer(AddressManager.getSpamAddress(), 0, message, SpamThread.getTag()));
    List<Input> inputs = new ArrayList<Input>();
    List<String> trytes = prepareTransfers("", SECURITY, transfers, null, inputs, false);
    GetTransactionsToApproveResponse txs = TipPool.getTransactionsToApprove();
    while (txs == null) txs = NodeManager.getTransactionsToApprove(NodeManager.getRotatedAPI());
    final GetAttachToTangleResponse res = attachToTangle(txs.getTrunkTransaction(), txs.getBranchTransaction(), MIN_WEIGHT_MAGNITUDE, trytes.toArray(new String[trytes.size()]));
    TxBroadcaster.queueTrytes(res);
}
Also used : Input(jota.model.Input) GetAttachToTangleResponse(jota.dto.response.GetAttachToTangleResponse) Transfer(jota.model.Transfer) ArrayList(java.util.ArrayList) GetTransactionsToApproveResponse(jota.dto.response.GetTransactionsToApproveResponse)

Example 3 with Transfer

use of jota.model.Transfer 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;
}
Also used : SendTransferResponse(run.wallet.iota.api.responses.SendTransferResponse) Address(run.wallet.iota.model.Address) NotificationManager(android.app.NotificationManager) Bundle(android.os.Bundle) NetworkError(run.wallet.iota.api.responses.error.NetworkError) Activity(android.app.Activity) ApiResponse(run.wallet.iota.api.responses.ApiResponse) ArgumentException(jota.error.ArgumentException) SendTransferRequest(run.wallet.iota.api.requests.SendTransferRequest) Input(jota.model.Input) Transfer(jota.model.Transfer) ArgumentException(jota.error.ArgumentException) KeyReuseDetectedDialog(run.wallet.iota.ui.dialog.KeyReuseDetectedDialog)

Example 4 with Transfer

use of jota.model.Transfer in project run-wallet-android by runplay.

the class MessageSendRequest method prepareTransfer.

public List<Transfer> prepareTransfer() {
    List<Transfer> transfers = new ArrayList<>();
    String usetag = keyid + SeedRandomGenerator.generateNewSeed().substring(0, 24);
    String encMessage = Utils.encryptMessageForTransfer(message, usetag, "");
    Transfer transfer = new Transfer(address, Long.valueOf(value), encMessage, usetag);
    transfers.add(transfer);
    return transfers;
}
Also used : Transfer(jota.model.Transfer) ArrayList(java.util.ArrayList)

Aggregations

Transfer (jota.model.Transfer)4 ArrayList (java.util.ArrayList)3 ArgumentException (jota.error.ArgumentException)2 Input (jota.model.Input)2 Activity (android.app.Activity)1 NotificationManager (android.app.NotificationManager)1 Bundle (android.os.Bundle)1 PearlDiverLocalPoW (cfb.pearldiver.PearlDiverLocalPoW)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1 Random (java.util.Random)1 IotaAPI (jota.IotaAPI)1 GetAttachToTangleResponse (jota.dto.response.GetAttachToTangleResponse)1 GetNodeInfoResponse (jota.dto.response.GetNodeInfoResponse)1 GetTransactionsToApproveResponse (jota.dto.response.GetTransactionsToApproveResponse)1 SendTransferResponse (jota.dto.response.SendTransferResponse)1 SendTransferRequest (run.wallet.iota.api.requests.SendTransferRequest)1 ApiResponse (run.wallet.iota.api.responses.ApiResponse)1 SendTransferResponse (run.wallet.iota.api.responses.SendTransferResponse)1 NetworkError (run.wallet.iota.api.responses.error.NetworkError)1