public boolean isOutputAvailable(int index) { checkIndex(index); if (trimmedOutputs == null) { return index < super.getOutputs().size(); } else { return trimmedOutputs.containsKey(index); } }
/** * Gets the index of this output in the parent transaction, or throws if this output is free standing. Iterates * over the parents list to discover this. */ public int getIndex() { List<TransactionOutput> outputs = getParentTransaction().getOutputs(); for (int i = 0; i < outputs.size(); i++) { if (outputs.get(i) == this) return i; } throw new IllegalStateException("Output linked to wrong parent transaction?"); }
/** * Gets the index of this output in the parent transaction, or throws if this output is free standing. Iterates * over the parents list to discover this. */ public int getIndex() { List<TransactionOutput> outputs = getParentTransaction().getOutputs(); for (int i = 0; i < outputs.size(); i++) { if (outputs.get(i) == this) return i; } throw new IllegalStateException("Output linked to wrong parent transaction?"); }
public List<TransactionOutput> getOutputs(boolean includeEmptyOutputs) { if (tx instanceof TrimmedTransaction) { return ((TrimmedTransaction) tx).getOutputs(includeEmptyOutputs); } else { return tx.getOutputs(); } }
private long getNumberOfOutputs() { if (tx instanceof TrimmedTransaction) { return ((TrimmedTransaction) tx).getNumberOfOutputs(); } else { return tx.getOutputs().size(); } }
public List<TransactionOutput> getOutputs(boolean includeEmptyOutputs) { if (tx instanceof TrimmedTransaction) { return ((TrimmedTransaction) tx).getOutputs(includeEmptyOutputs); } else { return tx.getOutputs(); } }
private long getNumberOfOutputs() { if (tx instanceof TrimmedTransaction) { return ((TrimmedTransaction) tx).getNumberOfOutputs(); } else { return tx.getOutputs().size(); } }
/** * Gets the index of this output in the parent transaction, or throws if this output is free standing. Iterates * over the parents list to discover this. */ public int getIndex() { List<TransactionOutput> outputs = getParentTransaction().getOutputs(); for (int i = 0; i < outputs.size(); i++) { if (outputs.get(i) == this) return i; } throw new IllegalStateException("Output linked to wrong parent transaction?"); }
/** * Gets the index of this output in the parent transaction, or throws if this output is free standing. Iterates * over the parents list to discover this. */ public int getIndex() { List<TransactionOutput> outputs = getParentTransaction().getOutputs(); for (int i = 0; i < outputs.size(); i++) { if (outputs.get(i) == this) return i; } throw new IllegalStateException("Output linked to wrong parent transaction?"); }
public boolean isOutputAvailable(int index) { checkIndex(index); if (trimmedOutputs == null) { return index < super.getOutputs().size(); } else { return trimmedOutputs.containsKey(index); } }
/** * Locates the referenced output from the given pool of transactions. * * @return The TransactionOutput or null if the transactions map doesn't contain the referenced tx. */ @Nullable TransactionOutput getConnectedOutput(Map<Sha256Hash, Transaction> transactions) { Transaction tx = transactions.get(outpoint.getHash()); if (tx == null) return null; return tx.getOutputs().get((int) outpoint.getIndex()); }
/** * Locates the referenced output from the given pool of transactions. * * @return The TransactionOutput or null if the transactions map doesn't contain the referenced tx. */ @Nullable TransactionOutput getConnectedOutput(Map<Sha256Hash, Transaction> transactions) { Transaction tx = transactions.get(outpoint.getHash()); if (tx == null) return null; return tx.getOutputs().get((int) outpoint.getIndex()); }
/** * Locates the referenced output from the given pool of transactions. * * @return The TransactionOutput or null if the transactions map doesn't contain the referenced tx. */ @Nullable TransactionOutput getConnectedOutput(Map<Sha256Hash, Transaction> transactions) { Transaction tx = transactions.get(outpoint.getHash()); if (tx == null) return null; return tx.getOutputs().get((int) outpoint.getIndex()); }
public void addAnchorOutputToAnchor () { List<TransactionOutput> outputList = new ArrayList<>(); outputList.add(new TransactionOutput( Constants.getNetwork(), null, Coin.valueOf(channelStatus.amountClient + channelStatus.amountServer), getAnchorScript().getProgram())); outputList.addAll(anchorTx.getOutputs()); Transaction tx = new Transaction(Constants.getNetwork()); anchorTx.getInputs().stream().forEach(tx::addInput); outputList.stream().forEach(tx::addOutput); this.anchorTx = tx; }
@Override public Optional<MessageEvent> signTx(Transaction tx) { return sendMessage( TrezorMessage.SignTx .newBuilder() .setCoinName("Bitcoin") .setInputsCount(tx.getInputs().size()) .setOutputsCount(tx.getOutputs().size()) .build() ); }
@Override public Optional<MessageEvent> signTx(Transaction tx) { return sendMessage( KeepKeyMessage.SignTx .newBuilder() .setCoinName("Bitcoin") .setInputsCount(tx.getInputs().size()) .setOutputsCount(tx.getOutputs().size()) .build() ); }
private void basicSanityChecks(Wallet wallet, Transaction t, Address destination) throws VerificationException { assertEquals("Wrong number of tx inputs", 1, t.getInputs().size()); assertEquals("Wrong number of tx outputs",2, t.getOutputs().size()); assertEquals(destination, t.getOutput(0).getScriptPubKey().getToAddress(PARAMS)); assertEquals(wallet.currentChangeAddress(), t.getOutputs().get(1).getScriptPubKey().getToAddress(PARAMS)); assertEquals(valueOf(0, 50), t.getOutputs().get(1).getValue()); // Check the script runs and signatures verify. t.getInputs().get(0).verify(); }
@Test public void sendRequestP2PKHTest() { SendRequest req = SendRequest.to(OTHER_ADDRESS, SATOSHI.multiply(12)); assertEquals(OTHER_ADDRESS, req.tx.getOutputs().get(0).getScriptPubKey().getToAddress(PARAMS)); }
@Test public void sendRequestP2PKTest() { ECKey key = new ECKey(); SendRequest req = SendRequest.to(PARAMS, key, SATOSHI.multiply(12)); assertArrayEquals(key.getPubKey(), req.tx.getOutputs().get(0).getScriptPubKey().getPubKey()); }
@Test public void testOptimalEncodingMessageSize() { Transaction tx = new Transaction(PARAMS); int length = tx.length; // add basic transaction input, check the length tx.addOutput(new TransactionOutput(PARAMS, null, Coin.COIN, ADDRESS)); length += getCombinedLength(tx.getOutputs()); // add basic output, check the length length += getCombinedLength(tx.getInputs()); // optimal encoding size should equal the length we just calculated assertEquals(tx.getOptimalEncodingMessageSize(), length); }