Search in sources :

Example 1 with MessageFirstLoadRequest

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();
}
Also used : GetNewAddressResponse(jota.dto.response.GetNewAddressResponse) FindTransactionResponse(jota.dto.response.FindTransactionResponse) GetTransferResponse(jota.dto.response.GetTransferResponse) Address(run.wallet.iota.model.Address) MessageFirstLoadRequest(run.wallet.iota.api.requests.MessageFirstLoadRequest) Bundle(jota.model.Bundle) Wallet(run.wallet.iota.model.Wallet) ArrayList(java.util.ArrayList) NetworkError(run.wallet.iota.api.responses.error.NetworkError) ArgumentException(jota.error.ArgumentException) ApiResponse(run.wallet.iota.api.responses.ApiResponse) StopWatch(jota.utils.StopWatch) Transfer(run.wallet.iota.model.Transfer) ArgumentException(jota.error.ArgumentException)

Example 2 with MessageFirstLoadRequest

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);
    }
}
Also used : TaskManager(run.wallet.iota.api.TaskManager) MessageFirstLoadRequest(run.wallet.iota.api.requests.MessageFirstLoadRequest)

Aggregations

MessageFirstLoadRequest (run.wallet.iota.api.requests.MessageFirstLoadRequest)2 ArrayList (java.util.ArrayList)1 FindTransactionResponse (jota.dto.response.FindTransactionResponse)1 GetNewAddressResponse (jota.dto.response.GetNewAddressResponse)1 GetTransferResponse (jota.dto.response.GetTransferResponse)1 ArgumentException (jota.error.ArgumentException)1 Bundle (jota.model.Bundle)1 StopWatch (jota.utils.StopWatch)1 TaskManager (run.wallet.iota.api.TaskManager)1 ApiResponse (run.wallet.iota.api.responses.ApiResponse)1 NetworkError (run.wallet.iota.api.responses.error.NetworkError)1 Address (run.wallet.iota.model.Address)1 Transfer (run.wallet.iota.model.Transfer)1 Wallet (run.wallet.iota.model.Wallet)1