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