protected TransactionSummary transform( Transaction tx, int time, int height, int blockChainHeight) { long value = 0; Address destAddress = null; for (TransactionOutput output : tx.outputs) { if (isMine(output.script)) { value += output.value; } else { destAddress = output.script.getAddress(_network); } } if (tx.isCoinbase()) { // For coinbase transactions there is nothing to subtract } else { for (TransactionInput input : tx.inputs) { // find parent output TransactionOutputEx funding = _backing.getParentTransactionOutput(input.outPoint); if (funding == null) { _logger.logError("Unable to find parent output for: " + input.outPoint); continue; } if (isMine(funding)) { value -= funding.value; } } } int confirmations; if (height == -1) { confirmations = 0; } else { confirmations = Math.max(0, blockChainHeight - height + 1); } // only track a destinationAddress if it is an outgoing transaction (i.e. send money to someone) // to prevent the user that he tries to return money to an address he got bitcoin from. if (value >= 0) { destAddress = null; } boolean isQueuedOutgoing = _backing.isOutgoingTransaction(tx.getHash()); return new TransactionSummary( tx.getHash(), value, time, height, confirmations, isQueuedOutgoing, com.google.common.base.Optional.fromNullable(destAddress)); }