Search in sources :

Example 1 with GetNodeInfoResponse

use of jota.dto.response.GetNodeInfoResponse 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 GetNodeInfoResponse

use of jota.dto.response.GetNodeInfoResponse in project run-wallet-android by runplay.

the class AuditAddressesRequestHandler method handle.

@Override
public ApiResponse handle(ApiRequest inrequest) {
    AuditAddressesRequest request = (AuditAddressesRequest) inrequest;
    // check less than 2, 1..iteself, and no others
    if (AppService.countSeedRunningTasks(request.getSeed()) < 2) {
        List<Address> addresses = Store.getAddresses(context, request.getSeed());
        List<Address> getaddresses = new ArrayList<>();
        if (!addresses.isEmpty()) {
            for (Address address : addresses) {
                if (!address.isAttached()) {
                    getaddresses.add(address);
                }
            }
        }
        if (!getaddresses.isEmpty()) {
            GetNodeInfoResponse info = apiProxy.getNodeInfo();
            if (info != null && info.getLatestMilestoneIndex() == info.getLatestSolidSubtangleMilestoneIndex()) {
                // List<String> addstr = new ArrayList<>();
                int count = 0;
                for (Address add : getaddresses) {
                    FindTransactionResponse tr1 = null;
                    try {
                        tr1 = apiProxy.findTransactionsByAddresses(add.getAddress());
                    } catch (Exception e) {
                    }
                    if (tr1 != null) {
                        if (tr1.getHashes().length == 0) {
                            AppService.attachNewAddress(context, request.getSeed(), add.getAddress());
                        } else {
                            add.setAttached(true);
                            Store.updateAddress(context, request.getSeed(), add);
                            AppService.refreshEvent();
                        }
                    // addstr.add(add.getAddress());
                    }
                    if (++count > 1 || tr1 == null)
                        ;
                    break;
                }
            }
        } else {
            int countemptyattached = 0;
            for (Address address : addresses) {
                if (address.isAttached() && address.getValue() == 0 && !address.isUsed() && !address.isPig()) {
                    countemptyattached++;
                }
            }
            Store.loadDefaults(context);
            int countmin = Store.getAutoAttach();
            if (countemptyattached < countmin) {
                // Log.e("AUDIT","Gen new address");
                try {
                    GetNewAddressRequest gnr = new GetNewAddressRequest(request.getSeed());
                    gnr.setIndex(addresses.size());
                    final GetNewAddressResponse gna = apiProxy.getNewAddress(String.valueOf(Store.getSeedRaw(context, request.getSeed())), gnr.getSecurity(), addresses.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);
                    AppService.auditAddressesWithDelay(context, request.getSeed());
                } catch (Exception e) {
                }
            } else {
            // Log.e("AUDIT","no address need creating");
            }
        }
    } else {
    // Log.e("AUDIT","Called but skipped.. hopefully good");
    }
    return new ApiResponse();
}
Also used : FindTransactionResponse(jota.dto.response.FindTransactionResponse) GetNewAddressResponse(jota.dto.response.GetNewAddressResponse) Address(run.wallet.iota.model.Address) GetNewAddressRequest(run.wallet.iota.api.requests.GetNewAddressRequest) ArrayList(java.util.ArrayList) AuditAddressesRequest(run.wallet.iota.api.requests.AuditAddressesRequest) ApiResponse(run.wallet.iota.api.responses.ApiResponse) GetNodeInfoResponse(jota.dto.response.GetNodeInfoResponse)

Aggregations

ArrayList (java.util.ArrayList)2 GetNodeInfoResponse (jota.dto.response.GetNodeInfoResponse)2 PearlDiverLocalPoW (cfb.pearldiver.PearlDiverLocalPoW)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1 Random (java.util.Random)1 IotaAPI (jota.IotaAPI)1 FindTransactionResponse (jota.dto.response.FindTransactionResponse)1 GetNewAddressResponse (jota.dto.response.GetNewAddressResponse)1 SendTransferResponse (jota.dto.response.SendTransferResponse)1 ArgumentException (jota.error.ArgumentException)1 Transfer (jota.model.Transfer)1 AuditAddressesRequest (run.wallet.iota.api.requests.AuditAddressesRequest)1 GetNewAddressRequest (run.wallet.iota.api.requests.GetNewAddressRequest)1 ApiResponse (run.wallet.iota.api.responses.ApiResponse)1 Address (run.wallet.iota.model.Address)1