Package org.bitcoinj.core
Class TransactionOutput
java.lang.Object
org.bitcoinj.core.TransactionOutput
A TransactionOutput message contains a scriptPubKey that controls who is able to spend its value. It is a sub-part of the Transaction message.
Instances of this class are not safe for use by multiple threads.
- 
Field SummaryFields
- 
Constructor SummaryConstructorsConstructorDescriptionTransactionOutput(NetworkParameters params, Transaction parent, Coin value, byte[] scriptBytes) Deprecated.TransactionOutput(Transaction parent, Coin value, byte[] scriptBytes) TransactionOutput(Transaction parent, Coin value, Address to) Creates an output that sends 'value' to the given address (public key hash).TransactionOutput(Transaction parent, Coin value, ECKey to) Creates an output that sends 'value' to the given public key using a simple CHECKSIG script (no addresses).
- 
Method SummaryModifier and TypeMethodDescriptionbyte[]Deprecated.useserialize()Returns a copy of the output detached from its containing transaction, if need be.booleanintgetIndex()Gets the index of this output in the parent transaction, or throws if this output is freestanding.intDeprecated.UsemessageSize()Returns the minimum value for this output to be considered "not dust", i.e.getMinNonDustValue(Coin feePerKb) Gets the minimum value for a txout of this size to be considered non-dust by Bitcoin Core (and thus relayed).Returns a newTransactionOutPoint, which is essentially a structure pointing to this output.Returns the transaction that owns this output.intReturns the depth in blocks of the parent tx.Returns the transaction hash that owns this output.byte[]The backing script bytes which can be turned into a Script object.Returns the connected input.getValue()Returns the value of this output.inthashCode()booleanReturns whethermarkAsSpent(TransactionInput)has been called on this class.booleanisDust()Will this transaction be considered dust and not be relayable and mined by default miners?booleanisMine(TransactionBag transactionBag) Returns true if this output is to a key, or an address we have the keys for, in the wallet.booleanisMineOrWatched(TransactionBag transactionBag) Returns true if this output is to a key in the wallet or to an address/script we are watching.booleanisWatched(TransactionBag transactionBag) Returns true if this output is to a key, or an address we have the keys for, in the wallet.voidmarkAsSpent(TransactionInput input) Sets this objects availableForSpending flag to false and the spentBy pointer to the given input.voidResets the spent pointer / availableForSpending flag to null.intReturn the size of the serialized message.static TransactionOutputread(ByteBuffer payload, Transaction parentTransaction) Deserialize this transaction output from a given payload.byte[]Allocates a byte array and writes this transaction output into it.protected final voidsetParent(Transaction parent) voidSets the value of this output.toString()Returns a human-readable debug string.Returns a human-readable debug string.write(ByteBuffer buf) Write this transaction output into the given buffer.
- 
Field Details- 
parent
 
- 
- 
Constructor Details- 
TransactionOutputCreates an output that sends 'value' to the given address (public key hash). The amount should be created with something likeCoin.valueOf(int, int). Typically you would useTransaction.addOutput(Coin, Address)instead of creating a TransactionOutput directly.
- 
TransactionOutputCreates an output that sends 'value' to the given public key using a simple CHECKSIG script (no addresses). The amount should be created with something likeCoin.valueOf(int, int). Typically you would useTransaction.addOutput(Coin, ECKey)instead of creating an output directly.
- 
TransactionOutput
- 
TransactionOutput@Deprecated public TransactionOutput(NetworkParameters params, @Nullable Transaction parent, Coin value, byte[] scriptBytes) Deprecated.
 
- 
- 
Method Details- 
readpublic static TransactionOutput read(ByteBuffer payload, Transaction parentTransaction) throws BufferUnderflowException, ProtocolException Deserialize this transaction output from a given payload.- Parameters:
- payload- payload to deserialize from
- parentTransaction- parent transaction of the output
- Returns:
- read message
- Throws:
- BufferUnderflowException- if the read message extends beyond the remaining bytes of the payload
- ProtocolException
 
- 
getScriptPubKey- Throws:
- ScriptException
 
- 
writeWrite this transaction output into the given buffer.- Parameters:
- buf- buffer to write into
- Returns:
- the buffer
- Throws:
- BufferOverflowException- if the output doesn't fit the remaining buffer
 
- 
serializepublic byte[] serialize()Allocates a byte array and writes this transaction output into it.- Returns:
- byte array containing the transaction output
 
- 
bitcoinSerializeDeprecated.useserialize()
- 
messageSizepublic int messageSize()Return the size of the serialized message. Note that if the message was deserialized from a payload, this size can differ from the size of the original payload.- Returns:
- size of the serialized message in bytes
 
- 
getMessageSizeDeprecated.UsemessageSize()
- 
getValueReturns the value of this output. This is the amount of currency that the destination address receives.
- 
setValueSets the value of this output.
- 
getIndexpublic int getIndex()Gets the index of this output in the parent transaction, or throws if this output is freestanding. Iterates over the parents list to discover this.
- 
isDustpublic boolean isDust()Will this transaction be considered dust and not be relayable and mined by default miners?- Returns:
- true if this output is dust
 
- 
getMinNonDustValueGets the minimum value for a txout of this size to be considered non-dust by Bitcoin Core (and thus relayed). See: CTxOut::IsDust() in Bitcoin Core. You probably should use getMinNonDustValue()which uses a safe fee-per-kb by default.- Parameters:
- feePerKb- The fee required per kilobyte. Note that this is the same as Bitcoin Core's -minrelaytxfee * 3
 
- 
getMinNonDustValueReturns the minimum value for this output to be considered "not dust", i.e. the transaction will be relayable and mined by default miners.
- 
markAsSpentSets this objects availableForSpending flag to false and the spentBy pointer to the given input. If the input is null, it means this output was signed over to somebody else rather than one of our own keys.- Throws:
- IllegalStateException- if the transaction was already marked as spent.
 
- 
markAsUnspentpublic void markAsUnspent()Resets the spent pointer / availableForSpending flag to null.
- 
isAvailableForSpendingpublic boolean isAvailableForSpending()Returns whethermarkAsSpent(TransactionInput)has been called on this class. AWalletwill mark a transaction output as spent once it sees a transaction input that is connected to it. Note that this flag can be false when an output has in fact been spent according to the rest of the network if the spending transaction wasn't downloaded yet, and it can be marked as spent when in reality the rest of the network believes it to be unspent if the signature or script connecting to it was not actually valid.
- 
getScriptBytespublic byte[] getScriptBytes()The backing script bytes which can be turned into a Script object.- Returns:
- the scriptBytes
 
- 
isMineOrWatchedReturns true if this output is to a key in the wallet or to an address/script we are watching.
- 
isWatchedReturns true if this output is to a key, or an address we have the keys for, in the wallet.
- 
isMineReturns true if this output is to a key, or an address we have the keys for, in the wallet.
- 
toStringReturns a human-readable debug string.
- 
toStringReturns a human-readable debug string.- Parameters:
- network- if provided, addresses (of that network) will be printed for standard scripts
- Returns:
- debug string
 
- 
getSpentByReturns the connected input.
- 
getParentTransactionReturns the transaction that owns this output.
- 
getParentTransactionHashReturns the transaction hash that owns this output.
- 
getParentTransactionDepthInBlockspublic int getParentTransactionDepthInBlocks()Returns the depth in blocks of the parent tx.If the transaction appears in the top block, the depth is one. If it's anything else (pending, dead, unknown) then -1. - Returns:
- The tx depth or -1.
 
- 
getOutPointForReturns a newTransactionOutPoint, which is essentially a structure pointing to this output. Requires that this output is not detached.
- 
duplicateDetachedReturns a copy of the output detached from its containing transaction, if need be.
- 
setParent
- 
equals
- 
hashCodepublic int hashCode()
 
- 
TransactionOutput(Transaction, Coin, byte[])