TransactionOutput output = outputs.get(i); if (output.isMineOrWatched(this)) { OutPointOutput outPointOutput = new OutPointOutput(tx, i); utxoSet.put(outPointOutput.getOutPoint(), outPointOutput);
private OutPointOutput(CoinType type, TrimmedOutput output, boolean isGenerated) { this.type = type; this.output = ensureDetached(output); this.outPoint = output.getOutPointFor(); this.value = type.value(output.getValue()); this.isGenerated = isGenerated; }
@Override public int compare(OutPointOutput a, OutPointOutput b) { int depth1 = a.getDepthInBlocks(); int depth2 = b.getDepthInBlocks(); long aValue = a.getValueLong(); long bValue = b.getValueLong(); BigInteger aCoinDepth = BigInteger.valueOf(aValue).multiply(BigInteger.valueOf(depth1)); BigInteger bCoinDepth = BigInteger.valueOf(bValue).multiply(BigInteger.valueOf(depth2)); int c1 = bCoinDepth.compareTo(aCoinDepth); if (c1 != 0) return c1; // The "coin*days" destroyed are equal, sort by value alone to get the lowest transaction size. if (aValue != bValue) return aValue > bValue ? 1 : -1; // They are entirely equivalent (possibly pending) so sort by hash to ensure a total ordering. BigInteger aHash = a.getTxHash().toBigInteger(); BigInteger bHash = b.getTxHash().toBigInteger(); return aHash.compareTo(bHash); } });
private static Protos.UnspentOutput makeUTXOProto(OutPointOutput utxo) { Protos.UnspentOutput.Builder utxoBuilder = Protos.UnspentOutput.newBuilder(); utxoBuilder.setOutPointHash(ByteString.copyFrom(utxo.getTxHash().getBytes())); utxoBuilder.setOutPointIndex((int) utxo.getIndex()); utxoBuilder.setScriptBytes(ByteString.copyFrom(utxo.getScriptBytes())); utxoBuilder.setValue(utxo.getValueLong()); if (utxo.isGenerated()) utxoBuilder.setIsGenerated(true); return utxoBuilder.build(); }
for (TransactionOutput txo : tx.getOutputs()) { if (txo.isAvailableForSpending() && txo.isMineOrWatched(account)) { OutPointOutput utxo = new OutPointOutput(tx, txo.getIndex()); if (tx.getConfidenceType() == BUILDING) { utxo.setAppearedAtChainHeight(tx.getAppearedAtChainHeight()); utxo.setDepthInBlocks(tx.getDepthInBlocks()); account.unspentOutputs.put(utxo.getOutPoint(), utxo);
int index = (int) outPoint.getIndex(); if (spendingTx != null && spendingTx.isOutputAvailable(index)) { connected = new OutPointOutput(spendingTx, index); if (!connected.getOutput().isMineOrWatched(wallet)) continue; sent = sent.add(connected.getValue());
/** * Used when de-serializing the wallet */ void addUnspentOutput(OutPointOutput utxo) { lock.lock(); try { unspentOutputs.put(utxo.getOutPoint(), utxo); } finally { lock.unlock(); } }
private Map<TrimmedOutPoint, OutPointOutput> getDummyUtxoSet() throws AddressMalformedException, JSONException { final HashMap<TrimmedOutPoint, OutPointOutput> unspentOutputs = new HashMap<>(); for (int i = 0; i < statuses.length; i++) { BitAddress address = (BitAddress) DOGE.newAddress(addresses.get(i)); JSONArray utxoArray = new JSONArray(unspent[i]); for (int j = 0; j < utxoArray.length(); j++) { JSONObject utxoObject = utxoArray.getJSONObject(j); //"[{\"tx_hash\": \"ef74da273e8a77e2d60b707414fb7e0ccb35c7b1b936800a49fe953195b1799f\", \"tx_pos\": 11, \"value\": 500000000, \"height\": 160267}]", TrimmedOutPoint outPoint = new TrimmedOutPoint(DOGE, utxoObject.getInt("tx_pos"), new Sha256Hash(utxoObject.getString("tx_hash"))); TransactionOutput output = new TransactionOutput(DOGE, null, Coin.valueOf(utxoObject.getLong("value")), address); OutPointOutput utxo = new OutPointOutput(outPoint, output, false); unspentOutputs.put(outPoint, utxo); } } return unspentOutputs; }
tx.addInput(utxo.getInput());
for (OutPointOutput utxo : selection.gathered) { try { TransactionOutput output = utxo.getOutput(); Script script = output.getScriptPubKey(); ECKey key = null;
Set<TrimmedOutPoint> notPresentInStatus = new HashSet<>(); for (Map.Entry<TrimmedOutPoint, OutPointOutput> utxo : unspentOutputs.entrySet()) { if (BitAddressUtils.producesAddress(utxo.getValue().getScriptPubKey(), address)) { notPresentInStatus.add(utxo.getKey()); OutPointOutput utxo = new OutPointOutput(tx, outPoint.getIndex()); if (tx.getConfidenceType() == BUILDING) { utxo.setAppearedAtChainHeight(tx.getAppearedAtChainHeight()); utxo.setDepthInBlocks(tx.getDepthInBlocks()); unspentOutputs.put(utxo.getOutPoint(), utxo);
private void checkUnspentOutputs(Map<TrimmedOutPoint, OutPointOutput> expectedUtxoSet, WalletPocketHD pocket) { Map<TrimmedOutPoint, OutPointOutput> pocketUtxoSet = pocket.getUnspentOutputs(false); for (OutPointOutput utxo : expectedUtxoSet.values()) { assertEquals(utxo, pocketUtxoSet.get(utxo.getOutPoint())); } }
proto.getScriptBytes().toByteArray()); pocket.addUnspentOutput( new OutPointOutput(utxo, proto.getIsGenerated()));
TransactionInput input = tx.addInput(utxo.getInput());