@Override public void onSuccess(ResultMessage result) { JSONArray resTxs = result.getResult(); ImmutableList.Builder<HistoryTx> historyTxs = ImmutableList.builder(); try { for (int i = 0; i < resTxs.length(); i++) { historyTxs.add(new HistoryTx(resTxs.getJSONObject(i))); } } catch (JSONException e) { onFailure(e); return; } listener.onTransactionHistory(status, historyTxs.build()); }
private HashSet<Sha256Hash> fillTransactions(Iterable<? extends HistoryTx> txs) { HashSet<Sha256Hash> transactionHashes = new HashSet<>(); for (HistoryTx tx : txs) { transactionHashes.add(tx.getTxHash()); } return transactionHashes; }
private void checkTxConfirmation(HistoryTx historyTx, BitTransaction tx) { checkState(lock.isHeldByCurrentThread(), "Lock is held by another thread"); int height = historyTx.getHeight(); TransactionConfidence.ConfidenceType confidence = tx.getConfidenceType(); if (height > 0) { switch (confidence) { case BUILDING: // If the height is the same, don't do anything if (tx.getAppearedAtChainHeight() == historyTx.getHeight()) { break; } case PENDING: setAppearedAtChainHeight(tx, height, true); maybeUpdateBlockDepth(tx, true); maybeMovePool(tx); break; case DEAD: case UNKNOWN: default: throw new RuntimeException("Unsupported confidence type: " + tx.getConfidenceType().name()); } } }
public static List<HistoryTx> historyFromArray(JSONArray jsonArray) throws JSONException { ImmutableList.Builder<HistoryTx> list = ImmutableList.builder(); for (int i = 0; i < jsonArray.length(); i++) { list.add(new HistoryTx(jsonArray.getJSONObject(i))); } return list.build(); }
private HashMap<AbstractAddress, ArrayList<HistoryTx>> getDummyHistoryTXs() throws AddressMalformedException, JSONException { HashMap<AbstractAddress, ArrayList<HistoryTx>> htxs = new HashMap<>(40); for (int i = 0; i < statuses.length; i++) { JSONArray jsonArray = new JSONArray(history[i]); ArrayList<HistoryTx> list = new ArrayList<>(); for (int j = 0; j < jsonArray.length(); j++) { list.add(new HistoryTx(jsonArray.getJSONObject(j))); } htxs.put(DOGE.newAddress(addresses.get(i)), list); } return htxs; }
private void applyHistoryState(AddressStatus status, HashMap<Sha256Hash, BitTransaction> txs) { checkState(lock.isHeldByCurrentThread(), "Lock is held by another thread"); checkState(!status.isHistoryTxStateApplied(), "History tx state already applied"); // Update confirmation status if necessary for (HistoryTx historyTx : status.getHistoryTxs()) { BitTransaction tx = checkNotNull(txs.get(historyTx.getTxHash())); checkTxConfirmation(historyTx, tx); } status.setHistoryTxStateApplied(true); if (status.canCommitStatus()) commitAddressStatus(status); }
private void fetchTransactions(List<? extends ServerClient.HistoryTx> txes) { checkState(lock.isHeldByCurrentThread(), "Lock is held by another thread"); for (ServerClient.HistoryTx tx : txes) { fetchTransactionIfNeeded(tx.getTxHash()); } }