public class TransactionOutput extends ChildMessage implements Serializable
Message.LazyParseException
bytes, checksum, cursor, length, MAX_SIZE, offset, params, parsed, parseLazy, parseRetain, protocolVersion, recached, UNKNOWN_LENGTH
Constructor and Description |
---|
TransactionOutput(NetworkParameters params,
Transaction parent,
BigInteger value,
Address to)
Creates an output that sends 'value' to the given address (public key hash).
|
TransactionOutput(NetworkParameters params,
Transaction parent,
BigInteger value,
byte[] scriptBytes) |
TransactionOutput(NetworkParameters params,
Transaction parent,
BigInteger value,
ECKey to)
Creates an output that sends 'value' to the given public key using a simple CHECKSIG script (no addresses).
|
TransactionOutput(NetworkParameters params,
Transaction parent,
byte[] payload,
int offset)
Deserializes a transaction output message.
|
TransactionOutput(NetworkParameters params,
Transaction parent,
byte[] msg,
int offset,
boolean parseLazy,
boolean parseRetain)
Deserializes a transaction output message.
|
Modifier and Type | Method and Description |
---|---|
protected void |
bitcoinSerializeToStream(OutputStream stream)
Serializes this message to the provided stream.
|
BigInteger |
getMinNonDustValue()
Returns the minimum value for this output to be considered "not dust", i.e.
|
BigInteger |
getMinNonDustValue(BigInteger feePerKbRequired)
Gets the minimum value for a txout of this size to be considered non-dust by a reference client
(and thus relayed).
|
Transaction |
getParentTransaction()
Returns the transaction that owns this output, or throws NullPointerException if unowned.
|
byte[] |
getScriptBytes()
The backing script bytes which can be turned into a Script object.
|
Script |
getScriptPubKey() |
TransactionInput |
getSpentBy()
Returns the connected input.
|
BigInteger |
getValue()
Returns the value of this output in nanocoins.
|
boolean |
isAvailableForSpending()
Returns whether
markAsSpent(TransactionInput) has been called on this class. |
boolean |
isMine(Wallet wallet)
Returns true if this output is to a key, or an address we have the keys for, in the wallet.
|
boolean |
isMineOrWatched(Wallet wallet)
Returns true if this output is to a key in the wallet or to an address/script we are watching.
|
boolean |
isWatched(Wallet wallet)
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 |
parseLite()
Perform the most minimal parse possible to calculate the length of the message.
|
void |
setValue(BigInteger value)
Sets the value of this output in nanocoins.
|
String |
toString()
Returns a human readable debug string.
|
adjustLength, adjustLength, setParent, unCache
bitcoinSerialize, bitcoinSerialize, ensureParsed, getHash, getMessageSize, getParams, isCached, isParsed, isRecached, maybeParse, unsafeBitcoinSerialize
public TransactionOutput(NetworkParameters params, @Nullable Transaction parent, byte[] payload, int offset) throws ProtocolException
ProtocolException
public TransactionOutput(NetworkParameters params, Transaction parent, byte[] msg, int offset, boolean parseLazy, boolean parseRetain) throws ProtocolException
params
- NetworkParameters object.msg
- Bitcoin protocol formatted byte array containing message content.offset
- The location of the first msg byte within the array.parseLazy
- Whether to perform a full parse immediately or delay until a read is requested.parseRetain
- Whether to retain the backing byte array for quick reserialization.
If true and the backing byte array is invalidated due to modification of a field then
the cached bytes may be repopulated and retained if the message is serialized again in the future.ProtocolException
public TransactionOutput(NetworkParameters params, Transaction parent, BigInteger value, Address to)
Utils.toNanoCoins(int, int)
. Typically you would use
Transaction.addOutput(java.math.BigInteger, Address)
instead of creating a TransactionOutput directly.public TransactionOutput(NetworkParameters params, Transaction parent, BigInteger value, ECKey to)
Utils.toNanoCoins(int, int)
. Typically you would use
Transaction.addOutput(java.math.BigInteger, ECKey)
instead of creating an output directly.public TransactionOutput(NetworkParameters params, Transaction parent, BigInteger value, byte[] scriptBytes)
public Script getScriptPubKey() throws ScriptException
ScriptException
protected void parseLite() throws ProtocolException
Message
parseLite
in class Message
ProtocolException
protected void bitcoinSerializeToStream(OutputStream stream) throws IOException
Message
IOException
public BigInteger getValue()
public void setValue(BigInteger value)
public BigInteger getMinNonDustValue(BigInteger feePerKbRequired)
Gets the minimum value for a txout of this size to be considered non-dust by a reference client (and thus relayed). See: CTxOut::IsDust() in the reference client. 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.
feePerKbRequired
- The fee required per kilobyte. Note that this is the same as the reference client's -minrelaytxfee * 3
If you want a safe default, use Transaction.REFERENCE_DEFAULT_MIN_TX_FEE
*3public BigInteger 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(Wallet wallet)
public boolean isWatched(Wallet wallet)
public boolean isMine(Wallet wallet)
public String toString()
public TransactionInput getSpentBy()
public Transaction getParentTransaction()
Copyright © 2014. All rights reserved.