Search in sources :

Example 1 with FindTransactionResponse

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

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

Example 3 with FindTransactionResponse

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();
}
Also used : FindTransactionResponse(jota.dto.response.FindTransactionResponse)

Aggregations

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