public class TransactionInput extends ChildMessage
A transfer of coins from one address to another creates a transaction in which the outputs can be claimed by the recipient in the input of another transaction. You can imagine a transaction as being a module which is wired up to others, the inputs of one have to be wired to the outputs of another. The exceptions are coinbase transactions, which create new coins.
Instances of this class are not safe for use by multiple threads.
Modifier and Type | Class and Description |
---|---|
static class |
TransactionInput.ConnectionResult |
static class |
TransactionInput.ConnectMode |
Modifier and Type | Field and Description |
---|---|
static long |
NO_SEQUENCE
Magic sequence number that indicates there is no sequence number.
|
parent
cursor, length, MAX_SIZE, offset, params, payload, protocolVersion, recached, serializer, UNKNOWN_LENGTH
Constructor and Description |
---|
TransactionInput(NetworkParameters params,
Transaction parentTransaction,
byte[] scriptBytes)
Creates an input that connects to nothing - used only in creation of coinbase transactions.
|
TransactionInput(NetworkParameters params,
Transaction parentTransaction,
byte[] payload,
int offset)
Deserializes an input message.
|
TransactionInput(NetworkParameters params,
Transaction parentTransaction,
byte[] payload,
int offset,
MessageSerializer serializer)
Deserializes an input message.
|
TransactionInput(NetworkParameters params,
Transaction parentTransaction,
byte[] scriptBytes,
TransactionOutPoint outpoint) |
TransactionInput(NetworkParameters params,
Transaction parentTransaction,
byte[] scriptBytes,
TransactionOutPoint outpoint,
Coin value) |
Modifier and Type | Method and Description |
---|---|
protected void |
bitcoinSerializeToStream(OutputStream stream)
Serializes this message to the provided stream.
|
void |
clearScriptBytes()
Clear input scripts, e.g.
|
TransactionInput.ConnectionResult |
connect(Map<Sha256Hash,Transaction> transactions,
TransactionInput.ConnectMode mode)
Connects this input to the relevant output of the referenced transaction if it's in the given map.
|
void |
connect(TransactionOutput out)
Internal use only: connects this TransactionInput to the given output (updates pointers and spent flags)
|
TransactionInput.ConnectionResult |
connect(Transaction transaction,
TransactionInput.ConnectMode mode)
Connects this input to the relevant output of the referenced transaction.
|
boolean |
disconnect()
If this input is connected, check the output is connected back to this input and release it if so, making
it spendable once again.
|
TransactionInput |
duplicateDetached()
Returns a copy of the input detached from its containing transaction, if need be.
|
boolean |
equals(Object o) |
TransactionOutput |
getConnectedOutput()
Returns the connected output, assuming the input was connected with
connect(TransactionOutput) or variants at some point. |
RedeemData |
getConnectedRedeemData(KeyBag keyBag)
Alias for getOutpoint().getConnectedRedeemData(keyBag)
|
Transaction |
getConnectedTransaction()
Returns the connected transaction, assuming the input was connected with
connect(TransactionOutput) or variants at some point. |
Address |
getFromAddress()
Deprecated.
|
TransactionOutPoint |
getOutpoint() |
Transaction |
getParentTransaction() |
byte[] |
getScriptBytes()
The "script bytes" might not actually be a script.
|
Script |
getScriptSig()
Returns the script that is fed to the referenced output (scriptPubKey) script in order to satisfy it: usually
contains signatures and maybe keys, but can contain arbitrary data if the output script accepts it.
|
long |
getSequenceNumber()
Sequence numbers allow participants in a multi-party transaction signing protocol to create new versions of the
transaction independently of each other.
|
Coin |
getValue() |
int |
hashCode() |
boolean |
hasSequence() |
boolean |
isCoinBase()
Coinbase transactions have special inputs with hashes of zero.
|
boolean |
isOptInFullRBF()
Returns whether this input will cause a transaction to opt into the
full replace-by-fee semantics.
|
DefaultRiskAnalysis.RuleViolation |
isStandard()
Returns either RuleViolation.NONE if the input is standard, or which rule makes it non-standard if so.
|
protected void |
parse() |
void |
setScriptSig(Script scriptSig)
Set the given program as the scriptSig that is supposed to satisfy the connected output script.
|
void |
setSequenceNumber(long sequence)
Sequence numbers allow participants in a multi-party transaction signing protocol to create new versions of the
transaction independently of each other.
|
String |
toString()
Returns a human readable debug string.
|
void |
verify()
For a connected transaction, runs the script against the connected pubkey and verifies they are correct.
|
void |
verify(TransactionOutput output)
Verifies that this input can spend the given output.
|
adjustLength, adjustLength, setParent, unCache
bitcoinSerialize, bitcoinSerialize, getHash, getMessageSize, getParams, hasMoreBytes, isCached, isRecached, readByteArray, readBytes, readHash, readInt64, readStr, readUint32, readUint64, readVarInt, readVarInt, unsafeBitcoinSerialize
public static final long NO_SEQUENCE
public TransactionInput(NetworkParameters params, @Nullable Transaction parentTransaction, byte[] scriptBytes)
public TransactionInput(NetworkParameters params, @Nullable Transaction parentTransaction, byte[] scriptBytes, TransactionOutPoint outpoint)
public TransactionInput(NetworkParameters params, @Nullable Transaction parentTransaction, byte[] scriptBytes, TransactionOutPoint outpoint, @Nullable Coin value)
public TransactionInput(NetworkParameters params, @Nullable Transaction parentTransaction, byte[] payload, int offset) throws ProtocolException
ProtocolException
public TransactionInput(NetworkParameters params, Transaction parentTransaction, 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
protected void parse() throws ProtocolException
parse
in class Message
ProtocolException
protected void bitcoinSerializeToStream(OutputStream stream) throws IOException
Message
bitcoinSerializeToStream
in class Message
IOException
public boolean isCoinBase()
public Script getScriptSig() throws ScriptException
ScriptException
public void setScriptSig(Script scriptSig)
@Deprecated public Address getFromAddress() throws ScriptException
ScriptException
public long getSequenceNumber()
public void setSequenceNumber(long sequence)
public TransactionOutPoint getOutpoint()
public byte[] getScriptBytes()
public void clearScriptBytes()
public Transaction getParentTransaction()
@Nullable public Coin getValue()
@Nullable public RedeemData getConnectedRedeemData(KeyBag keyBag) throws ScriptException
public TransactionInput.ConnectionResult connect(Map<Sha256Hash,Transaction> transactions, TransactionInput.ConnectMode mode)
transactions
- Map of txhash->transaction.mode
- Whether to abort if there's a pre-existing connection or not.public TransactionInput.ConnectionResult connect(Transaction transaction, TransactionInput.ConnectMode mode)
transaction
- The transaction to try.mode
- Whether to abort if there's a pre-existing connection or not.public void connect(TransactionOutput out)
public boolean disconnect()
public boolean hasSequence()
public boolean isOptInFullRBF()
public void verify() throws VerificationException
ScriptException
- if the script did not verify.VerificationException
- If the outpoint doesn't match the given output.public void verify(TransactionOutput output) throws VerificationException
output
- the output that this input is supposed to spend.ScriptException
- If the script doesn't verify.VerificationException
- If the outpoint doesn't match the given output.@Nullable public TransactionOutput getConnectedOutput()
connect(TransactionOutput)
or variants at some point. If it wasn't connected, then
this method returns null.@Nullable public Transaction getConnectedTransaction()
connect(TransactionOutput)
or variants at some point. If it wasn't connected, then
this method returns null.public TransactionInput duplicateDetached()
public DefaultRiskAnalysis.RuleViolation isStandard()
Returns either RuleViolation.NONE if the input is standard, or which rule makes it non-standard if so. The "IsStandard" rules control whether the default Bitcoin Core client blocks relay of a tx / refuses to mine it, however, non-standard transactions can still be included in blocks and will be accepted as valid if so.
This method simply calls DefaultRiskAnalysis.isInputStandard(this).
Copyright © 2016. All rights reserved.