public class TransactionOutput extends ChildMessage
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.
parent
cursor, length, MAX_SIZE, offset, params, payload, protocolVersion, recached, serializer, UNKNOWN_LENGTH
Constructor and Description |
---|
TransactionOutput(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,
Address to)
Creates an output that sends 'value' to the given address (public key hash).
|
TransactionOutput(NetworkParameters params,
Transaction parent,
Coin value,
byte[] scriptBytes) |
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).
|
Modifier and Type | Method and Description |
---|---|
protected void |
bitcoinSerializeToStream(OutputStream stream)
Serializes this message to the provided stream.
|
TransactionOutput |
duplicateDetached()
Returns a copy of the output detached from its containing transaction, if need be.
|
boolean |
equals(Object o) |
Address |
getAddressFromP2PKHScript(NetworkParameters networkParameters)
If the output script pays to an address as in
P2PKH, return the address of the receiver, i.e., a base58 encoded hash of the public key in the script.
|
Address |
getAddressFromP2SH(NetworkParameters networkParameters)
If the output script pays to a redeem script, return the address of the redeem script as described by,
i.e., a base58 encoding of [one-byte version][20-byte hash][4-byte checksum], where the 20-byte hash refers to
the redeem script.
|
int |
getIndex()
Gets the index of this output in the parent transaction, or throws if this output is free standing.
|
Coin |
getMinNonDustValue()
Returns the minimum value for this output to be considered "not dust", i.e.
|
Coin |
getMinNonDustValue(Coin feePerKb)
Gets the minimum value for a txout of this size to be considered non-dust by Bitcoin Core
(and thus relayed).
|
TransactionOutPoint |
getOutPointFor()
Returns a new
TransactionOutPoint , which is essentially a structure pointing to this output. |
Transaction |
getParentTransaction()
Returns the transaction that owns this output.
|
int |
getParentTransactionDepthInBlocks()
Returns the depth in blocks of the parent tx.
|
Sha256Hash |
getParentTransactionHash()
Returns the transaction hash that owns this output.
|
byte[] |
getScriptBytes()
The backing script bytes which can be turned into a Script object.
|
Script |
getScriptPubKey() |
TransactionInput |
getSpentBy()
Returns the connected input.
|
Coin |
getValue()
Returns the value of this output.
|
int |
hashCode() |
boolean |
isAvailableForSpending()
Returns whether
markAsSpent(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 |
markAsUnspent()
Resets the spent pointer / availableForSpending flag to null.
|
protected void |
parse() |
void |
setValue(Coin value)
Sets the value of this output.
|
String |
toString()
Returns a human readable debug string.
|
adjustLength, adjustLength, setParent, unCache
bitcoinSerialize, bitcoinSerialize, getHash, getMessageSize, getParams, hasMoreBytes, isCached, isRecached, readByteArray, readBytes, readHash, readInt64, readStr, readUint32, readUint64, readVarInt, readVarInt, unsafeBitcoinSerialize
public TransactionOutput(NetworkParameters params, @Nullable Transaction parent, byte[] payload, int offset) throws ProtocolException
ProtocolException
public TransactionOutput(NetworkParameters params, @Nullable Transaction parent, byte[] payload, int offset, MessageSerializer serializer) throws ProtocolException
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.ProtocolException
public TransactionOutput(NetworkParameters params, @Nullable Transaction parent, Coin value, Address to)
Coin.valueOf(int, int)
. Typically you would use
Transaction.addOutput(Coin, Address)
instead of creating a TransactionOutput directly.public TransactionOutput(NetworkParameters params, @Nullable Transaction parent, Coin value, ECKey to)
Coin.valueOf(int, int)
. Typically you would use
Transaction.addOutput(Coin, ECKey)
instead of creating an output directly.public TransactionOutput(NetworkParameters params, @Nullable Transaction parent, Coin value, byte[] scriptBytes)
public Script getScriptPubKey() throws ScriptException
ScriptException
@Nullable public Address getAddressFromP2PKHScript(NetworkParameters networkParameters) throws ScriptException
If the output script pays to an address as in P2PKH, return the address of the receiver, i.e., a base58 encoded hash of the public key in the script.
networkParameters
- needed to specify an addressScriptException
@Nullable public Address getAddressFromP2SH(NetworkParameters networkParameters) throws ScriptException
If the output script pays to a redeem script, return the address of the redeem script as described by, i.e., a base58 encoding of [one-byte version][20-byte hash][4-byte checksum], where the 20-byte hash refers to the redeem script.
P2SH is described by BIP 16 and documented in the Bitcoin Developer Guide.
networkParameters
- needed to specify an addressScriptException
protected void parse() throws ProtocolException
parse
in class Message
ProtocolException
protected void bitcoinSerializeToStream(OutputStream stream) throws IOException
Message
bitcoinSerializeToStream
in class Message
IOException
public Coin getValue()
public void setValue(Coin value)
public int getIndex()
public boolean isDust()
public Coin getMinNonDustValue(Coin feePerKb)
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. The assumption is that any output that would consume more than a third of its value in fees is not something the Bitcoin system wants to deal with right now, so we call them "dust outputs" and they're made non standard. The choice of one third is somewhat arbitrary and may change in future.
You probably should use getMinNonDustValue()
which uses
a safe fee-per-kb by default.
feePerKb
- The fee required per kilobyte. Note that this is the same as Bitcoin Core's -minrelaytxfee * 3public Coin getMinNonDustValue()
Transaction.MIN_NONDUST_OUTPUT
.public void markAsSpent(TransactionInput input)
IllegalStateException
- if the transaction was already marked as spent.public void markAsUnspent()
public boolean isAvailableForSpending()
markAsSpent(TransactionInput)
has been called on this class. A
Wallet
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.public byte[] getScriptBytes()
public boolean isMineOrWatched(TransactionBag transactionBag)
public boolean isWatched(TransactionBag transactionBag)
public boolean isMine(TransactionBag transactionBag)
public String toString()
@Nullable public TransactionInput getSpentBy()
@Nullable public Transaction getParentTransaction()
@Nullable public Sha256Hash getParentTransactionHash()
public int getParentTransactionDepthInBlocks()
If the transaction appears in the top block, the depth is one. If it's anything else (pending, dead, unknown) then -1.
public TransactionOutPoint getOutPointFor()
TransactionOutPoint
, which is essentially a structure pointing to this output.
Requires that this output is not detached.public TransactionOutput duplicateDetached()
Copyright © 2016. All rights reserved.