use of run.wallet.iota.api.requests.MessageFirstLoadRequest 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 run.wallet.iota.api.requests.MessageFirstLoadRequest in project run-wallet-android by runplay.
the class AppService method runMessageFirstLoad.
public static void runMessageFirstLoad(Context context) {
if (Validator.isValidCaller() && Store.getCurrentSeed() != null && MsgStore.getSeed() == null) {
TaskManager rt = new TaskManager(SERVICE);
MsgStore.createSeed(SERVICE);
MessageFirstLoadRequest gtr = new MessageFirstLoadRequest();
runMessageTask(rt, gtr);
}
}
Aggregations