use of run.wallet.iota.api.responses.NodeInfoResponse in project run-wallet-android by runplay.
the class GetAccountDataRequestHandler method handle.
@Override
public ApiResponse handle(ApiRequest inrequest) {
GetAccountDataRequest request = (GetAccountDataRequest) inrequest;
GetTransferResponse gtr = null;
StopWatch stopWatch = new StopWatch();
NodeInfoResponse nodeInfo = Store.getNodeInfo();
Wallet wallet = Store.getWallet(context, request.getSeed());
if (wallet != null && nodeInfo != null) {
List<Address> alreadyAddress = Store.getAddresses(context, request.getSeed());
List<Address> usingAddress = Store.getDisplayAddresses(alreadyAddress);
List<Address> checkAddress = new ArrayList<>();
if (request.getIfSingleAddressOrNull() != null) {
Address address = Store.isAlreadyAddress(request.getIfSingleAddressOrNull(), alreadyAddress);
if (address != null) {
checkAddress.add(address);
}
} else {
for (Address add : usingAddress) {
if (!add.isUsed() || (add.isUsed() && (add.getPendingValue() != 0 || add.getValue() != 0))) {
if (request.isForce() || nodeInfo.getLatestMilestoneIndex() != add.getLastMilestone()) {
checkAddress.add(add);
}
}
}
}
if (!checkAddress.isEmpty()) {
try {
List<String> checkAddressString = new ArrayList<>();
List<String> checkAddressBal = new ArrayList<>();
for (Address addr : checkAddress) {
checkAddressBal.add(addr.getAddress());
}
GetBalancesResponse gbal = apiProxy.getBalances(100, checkAddressBal);
for (int i = 0; i < gbal.getBalances().length; i++) {
Address addr = checkAddress.get(i);
long gotBalance = Sf.toLong(gbal.getBalances()[i]);
if (addr.getValue() != gotBalance || addr.getPendingValue() != 0) {
addr.setValue(gotBalance);
checkAddressString.add(addr.getAddress());
}
}
if (!checkAddressString.isEmpty()) {
Bundle[] bundles = apiProxy.bundlesFromAddresses(checkAddressString.toArray(new String[checkAddressString.size()]), true);
gtr = GetTransferResponse.create(bundles, stopWatch.getElapsedTimeMili());
}
List<Transfer> transfers = new ArrayList<>();
if (gtr != null && gtr.getTransfers().length > 0) {
List<Transfer> alreadyTransfer = Store.getTransfers(context, request.getSeed());
Audit.bundlePopulateTransfers(gtr.getTransfers(), transfers, alreadyAddress);
if (request.getIfSingleAddressOrNull() != null) {
Audit.setTransfersToAddresses(request.getSeed(), transfers, alreadyAddress, wallet, alreadyTransfer);
} else {
Audit.setTransfersToAddresses(request.getSeed(), transfers, alreadyAddress, wallet, alreadyTransfer);
}
Audit.processNudgeAttempts(context, request.getSeed(), transfers);
Store.updateAccountData(context, request.getSeed(), wallet, transfers, alreadyAddress);
}
if (request.getIfSingleAddressOrNull() == null) {
WalletAddressesFragment.setShouldRefresh(true);
WalletTransfersFragment.setShouldRefresh(true);
List<String> checkOthersString = new ArrayList<>();
for (Address address : checkAddress) {
if (!checkAddressString.contains(address.getAddress()))
checkOthersString.add(address.getAddress());
}
if (!checkOthersString.isEmpty()) {
Bundle[] bundles = apiProxy.bundlesFromAddresses(checkOthersString.toArray(new String[checkOthersString.size()]), true);
gtr = GetTransferResponse.create(bundles, stopWatch.getElapsedTimeMili());
}
if (gtr != null && gtr.getTransfers().length > 0) {
transfers = new ArrayList<>();
List<Transfer> alreadyTransfer = Store.getTransfers(context, request.getSeed());
Audit.bundlePopulateTransfers(gtr.getTransfers(), transfers, alreadyAddress);
if (request.getIfSingleAddressOrNull() != null) {
Audit.setTransfersToAddresses(request.getSeed(), transfers, alreadyAddress, wallet, alreadyTransfer);
} else {
Audit.setTransfersToAddresses(request.getSeed(), transfers, alreadyAddress, wallet, alreadyTransfer);
}
Audit.processNudgeAttempts(context, request.getSeed(), transfers);
Store.updateAccountData(context, request.getSeed(), wallet, transfers, alreadyAddress);
}
}
} catch (Exception e) {
Log.e("ERR066", "ERROR: " + e.getMessage());
}
}
AppService.setFastMode();
return new GetAccountDataResponse();
}
return new ApiResponse();
}
use of run.wallet.iota.api.responses.NodeInfoResponse in project run-wallet-android by runplay.
the class NetworkNodeInfoFragment method setAdapter.
private void setAdapter() {
NodeInfoResponse nir = Store.getNodeInfo();
Activity activity = getActivity();
if (activity != null && nir != null) {
swipeRefreshLayout.setRefreshing(false);
SimpleDateFormat df = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss", Locale.getDefault());
nodeInfos = new ArrayList<>();
nodeInfos.add(new NodeInfo(activity.getString(R.string.info_app_name), nir.getAppName()));
nodeInfos.add(new NodeInfo(getString(R.string.info_app_version), nir.getAppVersion()));
nodeInfos.add(new NodeInfo(getString(R.string.info_jre_version), nir.getJreVersion()));
nodeInfos.add(new NodeInfo(getString(R.string.info_max_processors), nir.getJreAvailableProcessors() + ""));
nodeInfos.add(new NodeInfo(getString(R.string.info_free_memory), Formatter.formatShortFileSize(getActivity(), nir.getJreFreeMemory())));
nodeInfos.add(new NodeInfo(getString(R.string.info_max_memory), Formatter.formatShortFileSize(getActivity(), nir.getJreMaxMemory())));
nodeInfos.add(new NodeInfo(getString(R.string.info_total_memory), Formatter.formatShortFileSize(getActivity(), nir.getJreTotalMemory())));
nodeInfos.add(new NodeInfo(getString(R.string.info_latest_milestone), nir.getLatestMilestone()));
nodeInfos.add(new NodeInfo(getString(R.string.info_latest_milestone_index), nir.getLatestMilestoneIndex()));
nodeInfos.add(new NodeInfo(getString(R.string.info_latest_milestone_solid_subtangle), nir.getLatestSolidSubtangleMilestone()));
nodeInfos.add(new NodeInfo(getString(R.string.info_latest_milestone_solid_subtangle_index), nir.getLatestSolidSubtangleMilestoneIndex()));
nodeInfos.add(new NodeInfo(getString(R.string.info_neighbors), nir.getNeighbors()));
nodeInfos.add(new NodeInfo(getString(R.string.info_packets_queue_size), nir.getPacketsQueueSize()));
nodeInfos.add(new NodeInfo(getString(R.string.info_time), df.format(new Date(nir.getTime()))));
nodeInfos.add(new NodeInfo(getString(R.string.info_tips), nir.getTips()));
nodeInfos.add(new NodeInfo(getString(R.string.info_transactions_to_request), nir.getTransactionsToRequest()));
updateChart(nir.getTips(), nir.getTransactionsToRequest());
NodeInfoListAdapter nodeInfoListAdapter = new NodeInfoListAdapter(getActivity(), R.layout.item_node_info, nodeInfos);
Utils.fixListView(list, swipeRefreshLayout);
list.setAdapter(nodeInfoListAdapter);
nodeAddress.setText(Store.getNode().getName());
if (nir.isSyncOk()) {
nodeActive.setImageResource(R.drawable.node_tick_grey);
} else {
nodeActive.setImageResource(R.drawable.indicator_offline);
}
}
}
use of run.wallet.iota.api.responses.NodeInfoResponse in project run-wallet-android by runplay.
the class NodesListAdapter method onBindViewHolder.
@Override
public void onBindViewHolder(NodeViewHolder holder, int position) {
int adapterPosition = holder.getAdapterPosition();
Nodes.Node node = getItem(adapterPosition);
// Log.e("NODESVIEW","pos: "+adapterPosition);
if (node != null) {
Nodes.Node currentnode = Store.getNode();
NodeInfoResponse currentInfo = Store.getNodeInfo();
holder.nodeAddress.setText(node.getName());
holder.lastSyncStatus.setImageResource(R.drawable.node_off);
holder.statusView.setImageResource(R.drawable.node_off);
Cal cal = new Cal(node.lastused);
holder.lastDate.setText(cal.friendlyReadDate());
holder.itemBackground.setBackgroundColor(B.getColor(context, R.color.white));
holder.lastSyncStatus.setImageResource(R.drawable.node_off);
if (node.deadcount > 2) {
holder.itemView.setBackgroundColor(B.getColor(context, R.color.grey));
holder.lastDate.setText(R.string.menu_node_dead);
} else {
if (currentnode != null) {
if (currentnode.ip.equals(node.ip)) {
holder.itemBackground.setBackgroundColor(B.getColor(context, R.color.flatGreen));
holder.statusView.setImageResource(R.drawable.node_live);
if (currentInfo != null && currentInfo.getSyncVal() > 1) {
holder.lastDate.setText(context.getString(R.string.messages_not_fully_synced_yet));
}
}
} else {
// Log.e("CNODe","is null");
}
}
holder.syncValue.setText(node.syncVal + "");
if (node.syncVal == 0) {
holder.lastSyncStatus.setImageResource(R.drawable.node_live);
} else {
holder.lastSyncStatus.setImageResource(R.drawable.node_tick_grey);
}
// holder.nodeName.setText(node.name);
holder.nodePort.setText("" + node.port);
holder.nodeProtocol.setText(node.protocol);
}
}
use of run.wallet.iota.api.responses.NodeInfoResponse in project run-wallet-android by runplay.
the class AddNodesListAdapter method onBindViewHolder.
@Override
public void onBindViewHolder(NodeViewHolder holder, int position) {
int adapterPosition = holder.getAdapterPosition();
Nodes.Node node = getItem(adapterPosition);
// Log.e("NODESVIEW","pos: "+adapterPosition);
if (node != null) {
if (node.ip.contains(".runplay.com") || node.ip.contains(".runpg.com")) {
holder.nodeAddress.setText(Constants.DISPLAY_RUNIOTA_NODE_NAME + position + Constants.DISPLAY_RUNIOTA_NODE_NAME_END);
} else {
holder.nodeAddress.setText(node.ip);
}
holder.extras.setVisibility(View.GONE);
Nodes.Node currentnode = Store.getNode();
NodeInfoResponse currentInfo = Store.getNodeInfo();
holder.lastSyncStatus.setImageResource(R.drawable.node_off);
holder.statusView.setImageResource(R.drawable.node_off);
Cal cal = new Cal(node.lastused);
holder.lastDate.setText(cal.friendlyReadDate());
holder.itemView.setBackgroundColor(B.getColor(context, R.color.white));
holder.nodePort.setText("" + node.port);
holder.nodeProtocol.setText(node.protocol);
}
}
use of run.wallet.iota.api.responses.NodeInfoResponse in project run-wallet-android by runplay.
the class NodeInfoRequestHandler method getNodeInfo.
public static NodeInfoResponse getNodeInfo(RunIotaAPI apiProxy, Context context) {
NodeInfoResponse info = null;
Nodes.Node cnode = Store.getNode();
boolean trynew = false;
try {
// Log.e("GETNODE",cnode.ip);
info = new NodeInfoResponse(apiProxy.getNodeInfo());
} catch (Exception e) {
}
if (info == null) {
cnode.deadcount += 1;
Store.updateNode(context, cnode);
trynew = true;
Store.addFailedNodeAttempt();
} else {
cnode.deadcount = 0;
if (info.isSyncOk()) {
long sval = info.getLatestMilestoneIndex() - info.getLatestSolidSubtangleMilestoneIndex();
if (sval > 1) {
cnode.syncVal = sval;
trynew = true;
} else {
cnode.syncVal = 0;
}
} else {
if (info.isSyncLoading()) {
cnode.syncVal = 100;
} else {
cnode.syncVal = info.getLatestMilestoneIndex() - info.getLatestSolidSubtangleMilestoneIndex();
}
trynew = true;
}
cnode.lastused = System.currentTimeMillis();
// Log.e("NODE","TRY SYNC: "+cnode.ip+" - "+cnode.syncVal);
Store.updateNode(context, cnode);
}
// Log.e("NODE","sync val: "+trynew+" - "+Store.getFailedNodeAttempt());
if (trynew && Store.getFailedNodeAttempt() < 5) {
Nodes.Node trynode = Store.getNextNode();
// Log.e("NODE","CHECK ANOTHER: "+trynode.ip);
if (!trynode.ip.equals(cnode.ip)) {
Store.changeNode(trynode);
// Log.e("NODE","NOT SYNCHED TRY ANOTHER: "+trynode.ip);
AppService.getNodeInfo(context);
}
}
return info;
}
Aggregations