Package org.bitcoinj.core
Class TransactionOutput
java.lang.Object
org.bitcoinj.core.Message
org.bitcoinj.core.ChildMessage
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 Summary
Fields inherited from class org.bitcoinj.core.ChildMessage
parent
Fields inherited from class org.bitcoinj.core.Message
cursor, length, MAX_SIZE, offset, params, payload, recached, serializer, UNKNOWN_LENGTH
-
Constructor Summary
ConstructorDescriptionTransactionOutput
(NetworkParameters params, Transaction parent, byte[] payload, int offset) Deserializes a transaction output message.TransactionOutput
(NetworkParameters params, Transaction parent, byte[] payload, int offset, MessageSerializer serializer) Deserializes a transaction output message.TransactionOutput
(NetworkParameters params, Transaction parent, Coin value, byte[] scriptBytes) TransactionOutput
(NetworkParameters params, Transaction parent, Coin value, Address to) Creates an output that sends 'value' to the given address (public key hash).TransactionOutput
(NetworkParameters params, 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 Summary
Modifier and TypeMethodDescriptionprotected void
bitcoinSerializeToStream
(OutputStream stream) Serializes this message to the provided stream.Returns a copy of the output detached from its containing transaction, if need be.boolean
Deprecated.getAddressFromP2SH
(NetworkParameters params) Deprecated.int
getIndex()
Gets the index of this output in the parent transaction, or throws if this output is free standing.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.int
Returns 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.int
hashCode()
boolean
Returns whethermarkAsSpent(TransactionInput)
has been called on this class.boolean
isDust()
Will this transaction be relayable and mined by default miners?boolean
isMine
(TransactionBag transactionBag) Returns true if this output is to a key, or an address we have the keys for, in the wallet.boolean
isMineOrWatched
(TransactionBag transactionBag) Returns true if this output is to a key in the wallet or to an address/script we are watching.boolean
isWatched
(TransactionBag transactionBag) Returns true if this output is to a key, or an address we have the keys for, in the wallet.void
markAsSpent
(TransactionInput input) Sets this objects availableForSpending flag to false and the spentBy pointer to the given input.void
Resets the spent pointer / availableForSpending flag to null.protected void
parse()
void
Sets the value of this output.toString()
Returns a human readable debug string.Methods inherited from class org.bitcoinj.core.ChildMessage
adjustLength, adjustLength, setParent, unCache
Methods inherited from class org.bitcoinj.core.Message
bitcoinSerialize, bitcoinSerialize, getHash, getMessageSize, getParams, hasMoreBytes, isCached, isRecached, readByte, readByteArray, readBytes, readHash, readInt64, readStr, readUint32, readUint64, readVarInt, readVarInt, setSerializer, unsafeBitcoinSerialize
-
Constructor Details
-
TransactionOutput
public TransactionOutput(NetworkParameters params, @Nullable Transaction parent, byte[] payload, int offset) throws ProtocolException Deserializes a transaction output message. This is usually part of a transaction message.- Throws:
ProtocolException
-
TransactionOutput
public TransactionOutput(NetworkParameters params, @Nullable Transaction parent, byte[] payload, int offset, MessageSerializer serializer) throws ProtocolException Deserializes a transaction output message. This is usually part of a transaction message.- Parameters:
params
- NetworkParameters object.payload
- Bitcoin protocol formatted byte array containing message content.offset
- The location of the first payload byte within the array.serializer
- the serializer to use for this message.- Throws:
ProtocolException
-
TransactionOutput
public TransactionOutput(NetworkParameters params, @Nullable Transaction parent, Coin value, Address to) Creates 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. -
TransactionOutput
public TransactionOutput(NetworkParameters params, @Nullable Transaction parent, Coin value, ECKey to) Creates 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
public TransactionOutput(NetworkParameters params, @Nullable Transaction parent, Coin value, byte[] scriptBytes)
-
-
Method Details
-
getScriptPubKey
- Throws:
ScriptException
-
getAddressFromP2PKHScript
@Nullable @Deprecated public LegacyAddress getAddressFromP2PKHScript(NetworkParameters params) throws ScriptException Deprecated.- Throws:
ScriptException
-
getAddressFromP2SH
@Nullable @Deprecated public LegacyAddress getAddressFromP2SH(NetworkParameters params) throws ScriptException Deprecated.- Throws:
ScriptException
-
parse
- Specified by:
parse
in classMessage
- Throws:
ProtocolException
-
bitcoinSerializeToStream
Description copied from class:Message
Serializes this message to the provided stream. If you just want the raw bytes use bitcoinSerialize().- Overrides:
bitcoinSerializeToStream
in classMessage
- Throws:
IOException
-
getValue
Returns the value of this output. This is the amount of currency that the destination address receives. -
setValue
Sets the value of this output. -
getIndex
public int getIndex()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. -
isDust
public boolean isDust()Will this transaction be relayable and mined by default miners? -
getMinNonDustValue
Gets 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
-
getMinNonDustValue
Returns the minimum value for this output to be considered "not dust", i.e. the transaction will be relayable and mined by default miners. -
markAsSpent
Sets 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.
-
markAsUnspent
public void markAsUnspent()Resets the spent pointer / availableForSpending flag to null. -
isAvailableForSpending
public boolean isAvailableForSpending()Returns whethermarkAsSpent(TransactionInput)
has been called on this class. AWallet
will 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. -
getScriptBytes
public byte[] getScriptBytes()The backing script bytes which can be turned into a Script object.- Returns:
- the scriptBytes
-
isMineOrWatched
Returns true if this output is to a key in the wallet or to an address/script we are watching. -
isWatched
Returns true if this output is to a key, or an address we have the keys for, in the wallet. -
isMine
Returns true if this output is to a key, or an address we have the keys for, in the wallet. -
toString
Returns a human readable debug string. -
getSpentBy
Returns the connected input. -
getParentTransaction
Returns the transaction that owns this output. -
getParentTransactionHash
Returns the transaction hash that owns this output. -
getParentTransactionDepthInBlocks
public 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.
-
getOutPointFor
Returns a newTransactionOutPoint
, which is essentially a structure pointing to this output. Requires that this output is not detached. -
duplicateDetached
Returns a copy of the output detached from its containing transaction, if need be. -
equals
-
hashCode
public int hashCode()
-