use of jota.dto.response.FindTransactionResponse in project run-wallet-android by runplay.
the class MessageFirstLoadRequestHandler method handle.
@Override
public ApiResponse handle(ApiRequest request) {
try {
// Log.e("FIRST-TIME-MSG","called");
StopWatch stopWatch = new StopWatch();
MessageFirstLoadRequest firstLoadRequest = (MessageFirstLoadRequest) request;
GetTransferResponse gtr = null;
List<Address> allAddresses = new ArrayList<>();
int start = 0;
final int addcount = 5;
while (true) {
GetNewAddressResponse gnr = apiProxy.getNewAddress(String.valueOf(Store.getSeedRaw(context, MsgStore.getSeed())), firstLoadRequest.getSecurity(), start, false, start + addcount, true);
for (String add : gnr.getAddresses()) {
// Log.e("FIRST-TIME-MSG","CALC ADDRESS: "+allAddresses+" -- "+stopWatch.getElapsedTimeSecs());
final FindTransactionResponse tr = apiProxy.findTransactionsByAddresses(add);
Address newaddress = new Address(add, false, true);
if (tr.getHashes().length == 0) {
newaddress.setAttached(false);
}
allAddresses.add(newaddress);
}
int countempty = 0;
for (int i = allAddresses.size() - 1; i >= 0 && i >= allAddresses.size() - 4; i--) {
if (!allAddresses.get(i).isAttached()) {
countempty++;
}
}
if (countempty >= 2) {
break;
}
start += addcount;
}
List<String> transactionaddresses = new ArrayList<>();
for (Address add : allAddresses) {
if (add.isAttached())
transactionaddresses.add(add.getAddress());
}
if (!transactionaddresses.isEmpty()) {
try {
Bundle[] bundles = apiProxy.bundlesFromAddresses(transactionaddresses.toArray(new String[transactionaddresses.size()]), true);
gtr = GetTransferResponse.create(bundles, stopWatch.getElapsedTimeMili());
} catch (Exception e) {
Log.e("FIRST-LOAD-MSG", "ex: " + e.getMessage());
}
} else {
gtr = GetTransferResponse.create(new Bundle[] {}, stopWatch.getElapsedTimeMili());
}
List<Transfer> transfers = new ArrayList<>();
long seedTotal = 0;
Wallet wallet = new Wallet(MsgStore.getSeed().id, seedTotal, System.currentTimeMillis());
// Audit.setTransfersToAddresses(firstLoadRequest.getSeed(),gtr,transfers,allAddresses,wallet);
MsgStore.updateMessageData(context, wallet, transfers, allAddresses);
// AppService.generateMessageNewAddress(context);
// if()
} catch (ArgumentException e) {
Log.e("FIRST-TIME-MSG", "ex: " + e.getMessage());
return new NetworkError();
}
return new ApiResponse();
}
use of jota.dto.response.FindTransactionResponse 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();
}
use of jota.dto.response.FindTransactionResponse in project isf-jclient by mikrohash.
the class NodeManager method findTransactionsByAddress.
public static String[] findTransactionsByAddress(String address) {
int api = getAPI();
String[] addresses = { address };
FindTransactionResponse findTransactionResponse = null;
while (findTransactionResponse == null) {
try {
findTransactionResponse = apis[api].findTransactionsByAddresses(addresses);
} catch (Throwable e) {
api = handleThrowableFromIotaAPI(String.format(R.STR.getString("nodes_action_check_address"), address), e, api);
}
}
return findTransactionResponse.getHashes();
}
Aggregations