com.google.bitcoin.core
Class Transaction

java.lang.Object
  extended by com.google.bitcoin.core.Message
      extended by com.google.bitcoin.core.ChildMessage
          extended by com.google.bitcoin.core.Transaction
All Implemented Interfaces:
Serializable

public class Transaction
extends ChildMessage
implements Serializable

A transaction represents the movement of coins from some addresses to some other addresses. It can also represent the minting of new coins. A Transaction object corresponds to the equivalent in the Bitcoin C++ implementation.

Transactions are the fundamental atoms of Bitcoin and have many powerful features. Read "Working with transactions" in the documentation to learn more about how to use this class.

All Bitcoin transactions are at risk of being reversed, though the risk is much less than with traditional payment systems. Transactions have confidence levels, which help you decide whether to trust a transaction or not. Whether to trust a transaction is something that needs to be decided on a case by case basis - a rule that makes sense for selling MP3s might not make sense for selling cars, or accepting payments from a family member. If you are building a wallet, how to present confidence to your users is something to consider carefully.

See Also:
Serialized Form

Nested Class Summary
static class Transaction.Purpose
          This enum describes the underlying reason the transaction was created.
static class Transaction.SigHash
          These constants are a part of a scriptSig signature on the inputs.
 
Nested classes/interfaces inherited from class com.google.bitcoin.core.Message
Message.LazyParseException
 
Field Summary
static int LOCKTIME_THRESHOLD
          Threshold for lockTime: below this value it is interpreted as block number, otherwise as timestamp.
static int MAX_STANDARD_TX_SIZE
          How many bytes a transaction can be before it won't be relayed anymore.
static BigInteger MIN_NONDUST_OUTPUT
          Any standard (ie pay-to-address) output smaller than this value (in satoshis) will most likely be rejected by the network.
static BigInteger REFERENCE_DEFAULT_MIN_TX_FEE
          If fee is lower than this value (in satoshis), a default reference client will treat it as if there were no fee.
static byte SIGHASH_ANYONECANPAY_VALUE
           
 
Fields inherited from class com.google.bitcoin.core.Message
bytes, checksum, cursor, length, MAX_SIZE, offset, params, parsed, parseLazy, parseRetain, protocolVersion, recached, UNKNOWN_LENGTH
 
Constructor Summary
Transaction(NetworkParameters params)
           
Transaction(NetworkParameters params, byte[] payloadBytes)
          Creates a transaction from the given serialized bytes, eg, from a block or a tx network message.
Transaction(NetworkParameters params, byte[] payload, int offset)
          Creates a transaction by reading payload starting from offset bytes in.
Transaction(NetworkParameters params, byte[] msg, int offset, Message parent, boolean parseLazy, boolean parseRetain, int length)
          Creates a transaction by reading payload starting from offset bytes in.
Transaction(NetworkParameters params, byte[] msg, Message parent, boolean parseLazy, boolean parseRetain, int length)
          Creates a transaction by reading payload starting from offset bytes in.
Transaction(NetworkParameters params, int version, Sha256Hash hash)
           
 
Method Summary
 void addBlockAppearance(Sha256Hash blockHash, int relativityOffset)
           
 TransactionInput addInput(TransactionInput input)
          Adds an input directly, with no checking that it's valid.
 TransactionInput addInput(TransactionOutput from)
          Adds an input to this transaction that imports value from the given output.
 TransactionOutput addOutput(BigInteger value, Address address)
          Creates an output based on the given address and value, adds it to this transaction, and returns the new output.
 TransactionOutput addOutput(BigInteger value, ECKey pubkey)
          Creates an output that pays to the given pubkey directly (no address) with the given value, adds it to this transaction, and returns the new output.
 TransactionOutput addOutput(BigInteger value, Script script)
          Creates an output that pays to the given script.
 TransactionOutput addOutput(TransactionOutput to)
          Adds the given output to this transaction.
 TransactionInput addSignedInput(TransactionOutPoint prevOut, Script scriptPubKey, ECKey sigKey)
          Same as addSignedInput(TransactionOutPoint, com.google.bitcoin.script.Script, ECKey, com.google.bitcoin.core.Transaction.SigHash, boolean) but defaults to Transaction.SigHash.ALL and "false" for the anyoneCanPay flag.
 TransactionInput addSignedInput(TransactionOutPoint prevOut, Script scriptPubKey, ECKey sigKey, Transaction.SigHash sigHash, boolean anyoneCanPay)
          Adds a new and fully signed input for the given parameters.
protected  void bitcoinSerializeToStream(OutputStream stream)
          Serializes this message to the provided stream.
protected static int calcLength(byte[] buf, int offset)
           
 TransactionSignature calculateSignature(int inputIndex, ECKey key, org.spongycastle.crypto.params.KeyParameter aesKey, byte[] connectedPubKeyScript, Transaction.SigHash hashType, boolean anyoneCanPay)
          Calculates a signature that is valid for being inserted into the input at the given position.
 TransactionSignature calculateSignature(int inputIndex, ECKey key, Script connectedPubKeyScript, Transaction.SigHash hashType, boolean anyoneCanPay)
          Calculates a signature that is valid for being inserted into the input at the given position.
 void clearInputs()
          Removes all the inputs from this transaction.
 void clearOutputs()
          Removes all the inputs from this transaction.
 boolean equals(Object other)
           
 Date estimateLockTime(AbstractBlockChain chain)
          Returns either the lock time as a date, if it was specified in seconds, or an estimate based on the time in the current head block if it was specified as a block time.
 Map<Sha256Hash,Integer> getAppearsInHashes()
          Returns a map of block [hashes] which contain the transaction mapped to relativity counters, or null if this transaction doesn't have that data because it's not stored in the wallet or because it has never appeared in a block.
 TransactionConfidence getConfidence()
           
 Sha256Hash getHash()
          Returns the transaction hash as you see them in the block explorer.
 String getHashAsString()
           
 TransactionInput getInput(int index)
           
 List<TransactionInput> getInputs()
          Returns an unmodifiable view of all inputs.
 long getLockTime()
          Transactions can have an associated lock time, specified either as a block height or in seconds since the UNIX epoch.
 int getOptimalEncodingMessageSize()
           
 TransactionOutput getOutput(int index)
           
 List<TransactionOutput> getOutputs()
          Returns an unmodifiable view of all outputs.
 Transaction.Purpose getPurpose()
          Returns the purpose for which this transaction was created.
 int getSigOpCount()
          Gets the count of regular SigOps in this transactions
 Date getUpdateTime()
          Returns the earliest time at which the transaction was seen (broadcast or included into the chain), or the epoch if that information isn't available.
 BigInteger getValue(Wallet wallet)
          Returns the difference of getValueSentFromMe(Wallet) and getValueSentToMe(Wallet).
 BigInteger getValueSentFromMe(Wallet wallet)
          Calculates the sum of the inputs that are spending coins with keys in the wallet.
 BigInteger getValueSentToMe(Wallet wallet)
          Calculates the sum of the outputs that are sending coins to a key in the wallet.
 long getVersion()
           
 boolean hasConfidence()
          Check if the transaction has a known confidence
 int hashCode()
           
 Sha256Hash hashForSignature(int inputIndex, byte[] connectedScript, byte sigHashType)
          This is required for signatures which use a sigHashType which cannot be represented using SigHash and anyoneCanPay See transaction c99c49da4c38af669dea436d3e73780dfdb6c1ecf9958baa52960e8baee30e73, which has sigHashType 0
 Sha256Hash hashForSignature(int inputIndex, byte[] connectedScript, Transaction.SigHash type, boolean anyoneCanPay)
          Calculates a signature hash, that is, a hash of a simplified form of the transaction.
 Sha256Hash hashForSignature(int inputIndex, Script connectedScript, Transaction.SigHash type, boolean anyoneCanPay)
          Calculates a signature hash, that is, a hash of a simplified form of the transaction.
 boolean isAnyOutputSpent()
          Returns true if any of the outputs is marked as spent.
 boolean isCoinBase()
          A coinbase transaction is one that creates a new coin.
 boolean isEveryOutputSpent()
          Returns true if every output is marked as spent.
 boolean isEveryOwnedOutputSpent(Wallet wallet)
          Returns false if this transaction has at least one output that is owned by the given wallet and unspent, true otherwise.
 boolean isFinal(int height, long blockTimeSeconds)
          Returns true if this transaction is considered finalized and can be placed in a block.
 boolean isMature()
          A transaction is mature if it is either a building coinbase tx that is as deep or deeper than the required coinbase depth, or a non-coinbase tx.
 boolean isPending()
          Convenience wrapper around getConfidence().getConfidenceType()
 boolean isTimeLocked()
          A transaction is time locked if at least one of its inputs is non-final and it has a lock time
protected  void parseLite()
          Perform the most minimal parse possible to calculate the length of the message.
static long parseLockTimeStr(String lockTimeStr)
          Parses the string either as a whole number of blocks, or if it contains slashes as a YYYY/MM/DD format date and returns the lock time in wire format.
 void setBlockAppearance(StoredBlock block, boolean bestChain, int relativityOffset)
          Puts the given block in the internal set of blocks in which this transaction appears.
 void setLockTime(long lockTime)
          Transactions can have an associated lock time, specified either as a block height or in seconds since the UNIX epoch.
 void setPurpose(Transaction.Purpose purpose)
          Marks the transaction as being created for the given purpose.
 void setUpdateTime(Date updatedAt)
           
 void signInputs(Transaction.SigHash hashType, Wallet wallet)
          Once a transaction has some inputs and outputs added, the signatures in the inputs can be calculated.
 void signInputs(Transaction.SigHash hashType, Wallet wallet, org.spongycastle.crypto.params.KeyParameter aesKey)
          Once a transaction has some inputs and outputs added, the signatures in the inputs can be calculated.
 String toString()
           
 String toString(AbstractBlockChain chain)
          A human readable version of the transaction useful for debugging.
protected  void unCache()
          To be called before any change of internal values including any setters.
 void verify()
          Checks the transaction contents for sanity, in ways that can be done in a standalone manner.
 
Methods inherited from class com.google.bitcoin.core.ChildMessage
adjustLength, adjustLength, setParent
 
Methods inherited from class com.google.bitcoin.core.Message
bitcoinSerialize, bitcoinSerialize, ensureParsed, getMessageSize, getParams, isCached, isParsed, isRecached, maybeParse, unsafeBitcoinSerialize
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

LOCKTIME_THRESHOLD

public static final int LOCKTIME_THRESHOLD
Threshold for lockTime: below this value it is interpreted as block number, otherwise as timestamp.

See Also:
Constant Field Values

MAX_STANDARD_TX_SIZE

public static final int MAX_STANDARD_TX_SIZE
How many bytes a transaction can be before it won't be relayed anymore. Currently 100kb.

See Also:
Constant Field Values

REFERENCE_DEFAULT_MIN_TX_FEE

public static final BigInteger REFERENCE_DEFAULT_MIN_TX_FEE
If fee is lower than this value (in satoshis), a default reference client will treat it as if there were no fee. Currently this is 10000 satoshis.


MIN_NONDUST_OUTPUT

public static final BigInteger MIN_NONDUST_OUTPUT
Any standard (ie pay-to-address) output smaller than this value (in satoshis) will most likely be rejected by the network. This is calculated by assuming a standard output will be 34 bytes, and then using the formula used in TransactionOutput.getMinNonDustValue(BigInteger). Currently it's 5460 satoshis.


SIGHASH_ANYONECANPAY_VALUE

public static final byte SIGHASH_ANYONECANPAY_VALUE
See Also:
Constant Field Values
Constructor Detail

Transaction

public Transaction(NetworkParameters params)

Transaction

public Transaction(NetworkParameters params,
                   int version,
                   Sha256Hash hash)

Transaction

public Transaction(NetworkParameters params,
                   byte[] payloadBytes)
            throws ProtocolException
Creates a transaction from the given serialized bytes, eg, from a block or a tx network message.

Throws:
ProtocolException

Transaction

public Transaction(NetworkParameters params,
                   byte[] payload,
                   int offset)
            throws ProtocolException
Creates a transaction by reading payload starting from offset bytes in. Length of a transaction is fixed.

Throws:
ProtocolException

Transaction

public Transaction(NetworkParameters params,
                   byte[] msg,
                   int offset,
                   @Nullable
                   Message parent,
                   boolean parseLazy,
                   boolean parseRetain,
                   int length)
            throws ProtocolException
Creates a transaction by reading payload starting from offset bytes in. Length of a transaction is fixed.

Parameters:
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.
length - The length of message if known. Usually this is provided when deserializing of the wire as the length will be provided as part of the header. If unknown then set to Message.UNKNOWN_LENGTH
Throws:
ProtocolException

Transaction

public Transaction(NetworkParameters params,
                   byte[] msg,
                   @Nullable
                   Message parent,
                   boolean parseLazy,
                   boolean parseRetain,
                   int length)
            throws ProtocolException
Creates a transaction by reading payload starting from offset bytes in. Length of a transaction is fixed.

Throws:
ProtocolException
Method Detail

getHash

public Sha256Hash getHash()
Returns the transaction hash as you see them in the block explorer.

Overrides:
getHash in class Message

getHashAsString

public String getHashAsString()

getValueSentToMe

public BigInteger getValueSentToMe(Wallet wallet)
Calculates the sum of the outputs that are sending coins to a key in the wallet.


getAppearsInHashes

@Nullable
public Map<Sha256Hash,Integer> getAppearsInHashes()
Returns a map of block [hashes] which contain the transaction mapped to relativity counters, or null if this transaction doesn't have that data because it's not stored in the wallet or because it has never appeared in a block.


isPending

public boolean isPending()
Convenience wrapper around getConfidence().getConfidenceType()

Returns:
true if this transaction hasn't been seen in any block yet.

setBlockAppearance

public void setBlockAppearance(StoredBlock block,
                               boolean bestChain,
                               int relativityOffset)

Puts the given block in the internal set of blocks in which this transaction appears. This is used by the wallet to ensure transactions that appear on side chains are recorded properly even though the block stores do not save the transaction data at all.

If there is a re-org this will be called once for each block that was previously seen, to update which block is the best chain. The best chain block is guaranteed to be called last. So this must be idempotent.

Sets updatedAt to be the earliest valid block time where this tx was seen.

Parameters:
block - The StoredBlock in which the transaction has appeared.
bestChain - whether to set the updatedAt timestamp from the block header (only if not already set)
relativityOffset - A number that disambiguates the order of transactions within a block.

addBlockAppearance

public void addBlockAppearance(Sha256Hash blockHash,
                               int relativityOffset)

getValueSentFromMe

public BigInteger getValueSentFromMe(Wallet wallet)
                              throws ScriptException
Calculates the sum of the inputs that are spending coins with keys in the wallet. This requires the transactions sending coins to those keys to be in the wallet. This method will not attempt to download the blocks containing the input transactions if the key is in the wallet but the transactions are not.

Returns:
sum in nanocoins.
Throws:
ScriptException

getValue

public BigInteger getValue(Wallet wallet)
                    throws ScriptException
Returns the difference of getValueSentFromMe(Wallet) and getValueSentToMe(Wallet).

Throws:
ScriptException

isEveryOutputSpent

public boolean isEveryOutputSpent()
Returns true if every output is marked as spent.


isAnyOutputSpent

public boolean isAnyOutputSpent()
Returns true if any of the outputs is marked as spent.


isEveryOwnedOutputSpent

public boolean isEveryOwnedOutputSpent(Wallet wallet)
Returns false if this transaction has at least one output that is owned by the given wallet and unspent, true otherwise.


getUpdateTime

public Date getUpdateTime()
Returns the earliest time at which the transaction was seen (broadcast or included into the chain), or the epoch if that information isn't available.


setUpdateTime

public void setUpdateTime(Date updatedAt)

unCache

protected void unCache()
Description copied from class: Message
To be called before any change of internal values including any setters. This ensures any cached byte array is removed after performing a lazy parse if necessary to ensure the object is fully populated.

Child messages of this object(e.g. Transactions belonging to a Block) will not have their internal byte caches invalidated unless they are also modified internally.

Overrides:
unCache in class ChildMessage

parseLite

protected void parseLite()
                  throws ProtocolException
Description copied from class: Message
Perform the most minimal parse possible to calculate the length of the message. This is only required for subclasses of ChildClass as root level messages will have their length passed into the constructor.

Implementations should adhere to the following contract: If parseLazy = true the 'length' field must be set before returning. If parseLazy = false the length field must be set either within the parseLite() method OR the parse() method. The overriding requirement is that length must be set to non UNKNOWN_MESSAGE value by the time the constructor exits.

Specified by:
parseLite in class Message
Throws:
ProtocolException

calcLength

protected static int calcLength(byte[] buf,
                                int offset)

getOptimalEncodingMessageSize

public int getOptimalEncodingMessageSize()

isCoinBase

public boolean isCoinBase()
A coinbase transaction is one that creates a new coin. They are the first transaction in each block and their value is determined by a formula that all implementations of Bitcoin share. In 2011 the value of a coinbase transaction is 50 coins, but in future it will be less. A coinbase transaction is defined not only by its position in a block but by the data in the inputs.


isMature

public boolean isMature()
A transaction is mature if it is either a building coinbase tx that is as deep or deeper than the required coinbase depth, or a non-coinbase tx.


toString

public String toString()
Overrides:
toString in class Object

toString

public String toString(@Nullable
                       AbstractBlockChain chain)
A human readable version of the transaction useful for debugging. The format is not guaranteed to be stable.

Parameters:
chain - If provided, will be used to estimate lock times (if set). Can be null.

clearInputs

public void clearInputs()
Removes all the inputs from this transaction. Note that this also invalidates the length attribute


addInput

public TransactionInput addInput(TransactionOutput from)
Adds an input to this transaction that imports value from the given output. Note that this input is NOT complete and after every input is added with addInput() and every output is added with addOutput(), signInputs() must be called to finalize the transaction and finish the inputs off. Otherwise it won't be accepted by the network. Returns the newly created input.


addInput

public TransactionInput addInput(TransactionInput input)
Adds an input directly, with no checking that it's valid. Returns the new input.


addSignedInput

public TransactionInput addSignedInput(TransactionOutPoint prevOut,
                                       Script scriptPubKey,
                                       ECKey sigKey,
                                       Transaction.SigHash sigHash,
                                       boolean anyoneCanPay)
                                throws ScriptException
Adds a new and fully signed input for the given parameters. Note that this method is not thread safe and requires external synchronization. Please refer to general documentation on Bitcoin scripting and contracts to understand the values of sigHash and anyoneCanPay: otherwise you can use the other form of this method that sets them to typical defaults.

Throws:
ScriptException - if the scriptPubKey is not a pay to address or pay to pubkey script.

addSignedInput

public TransactionInput addSignedInput(TransactionOutPoint prevOut,
                                       Script scriptPubKey,
                                       ECKey sigKey)
                                throws ScriptException
Same as addSignedInput(TransactionOutPoint, com.google.bitcoin.script.Script, ECKey, com.google.bitcoin.core.Transaction.SigHash, boolean) but defaults to Transaction.SigHash.ALL and "false" for the anyoneCanPay flag. This is normally what you want.

Throws:
ScriptException

clearOutputs

public void clearOutputs()
Removes all the inputs from this transaction. Note that this also invalidates the length attribute


addOutput

public TransactionOutput addOutput(TransactionOutput to)
Adds the given output to this transaction. The output must be completely initialized. Returns the given output.


addOutput

public TransactionOutput addOutput(BigInteger value,
                                   Address address)
Creates an output based on the given address and value, adds it to this transaction, and returns the new output.


addOutput

public TransactionOutput addOutput(BigInteger value,
                                   ECKey pubkey)
Creates an output that pays to the given pubkey directly (no address) with the given value, adds it to this transaction, and returns the new output.


addOutput

public TransactionOutput addOutput(BigInteger value,
                                   Script script)
Creates an output that pays to the given script. The address and key forms are specialisations of this method, you won't normally need to use it unless you're doing unusual things.


signInputs

public void signInputs(Transaction.SigHash hashType,
                       Wallet wallet)
                throws ScriptException
Once a transaction has some inputs and outputs added, the signatures in the inputs can be calculated. The signature is over the transaction itself, to prove the redeemer actually created that transaction, so we have to do this step last.

This method is similar to SignatureHash in script.cpp

Parameters:
hashType - This should always be set to SigHash.ALL currently. Other types are unused.
wallet - A wallet is required to fetch the keys needed for signing.
Throws:
ScriptException

signInputs

public void signInputs(Transaction.SigHash hashType,
                       Wallet wallet,
                       @Nullable
                       org.spongycastle.crypto.params.KeyParameter aesKey)
                throws ScriptException

Once a transaction has some inputs and outputs added, the signatures in the inputs can be calculated. The signature is over the transaction itself, to prove the redeemer actually created that transaction, so we have to do this step last.

Parameters:
hashType - This should always be set to SigHash.ALL currently. Other types are unused.
wallet - A wallet is required to fetch the keys needed for signing.
aesKey - The AES key to use to decrypt the key before signing. Null if no decryption is required.
Throws:
ScriptException

calculateSignature

public TransactionSignature calculateSignature(int inputIndex,
                                               ECKey key,
                                               @Nullable
                                               org.spongycastle.crypto.params.KeyParameter aesKey,
                                               byte[] connectedPubKeyScript,
                                               Transaction.SigHash hashType,
                                               boolean anyoneCanPay)
Calculates a signature that is valid for being inserted into the input at the given position. This is simply a wrapper around calling hashForSignature(int, byte[], com.google.bitcoin.core.Transaction.SigHash, boolean) followed by ECKey.sign(Sha256Hash, org.spongycastle.crypto.params.KeyParameter) and then returning a new TransactionSignature.

Parameters:
inputIndex - Which input to calculate the signature for, as an index.
key - The private key used to calculate the signature.
aesKey - If not null, this will be used to decrypt the key.
connectedPubKeyScript - Byte-exact contents of the scriptPubKey that is being satisified.
hashType - Signing mode, see the enum for documentation.
anyoneCanPay - Signing mode, see the SigHash enum for documentation.
Returns:
A newly calculated signature object that wraps the r, s and sighash components.

calculateSignature

public TransactionSignature calculateSignature(int inputIndex,
                                               ECKey key,
                                               Script connectedPubKeyScript,
                                               Transaction.SigHash hashType,
                                               boolean anyoneCanPay)
Calculates a signature that is valid for being inserted into the input at the given position. This is simply a wrapper around calling hashForSignature(int, byte[], com.google.bitcoin.core.Transaction.SigHash, boolean) followed by ECKey.sign(Sha256Hash) and then returning a new TransactionSignature.

Parameters:
inputIndex - Which input to calculate the signature for, as an index.
key - The private key used to calculate the signature.
connectedPubKeyScript - The scriptPubKey that is being satisified.
hashType - Signing mode, see the enum for documentation.
anyoneCanPay - Signing mode, see the SigHash enum for documentation.
Returns:
A newly calculated signature object that wraps the r, s and sighash components.

hashForSignature

public Sha256Hash hashForSignature(int inputIndex,
                                   byte[] connectedScript,
                                   Transaction.SigHash type,
                                   boolean anyoneCanPay)

Calculates a signature hash, that is, a hash of a simplified form of the transaction. How exactly the transaction is simplified is specified by the type and anyoneCanPay parameters.

You don't normally ever need to call this yourself. It will become more useful in future as the contracts features of Bitcoin are developed.

Parameters:
inputIndex - input the signature is being calculated for. Tx signatures are always relative to an input.
connectedScript - the bytes that should be in the given input during signing.
type - Should be SigHash.ALL
anyoneCanPay - should be false.

hashForSignature

public Sha256Hash hashForSignature(int inputIndex,
                                   Script connectedScript,
                                   Transaction.SigHash type,
                                   boolean anyoneCanPay)

Calculates a signature hash, that is, a hash of a simplified form of the transaction. How exactly the transaction is simplified is specified by the type and anyoneCanPay parameters.

You don't normally ever need to call this yourself. It will become more useful in future as the contracts features of Bitcoin are developed.

Parameters:
inputIndex - input the signature is being calculated for. Tx signatures are always relative to an input.
connectedScript - the script that should be in the given input during signing.
type - Should be SigHash.ALL
anyoneCanPay - should be false.

hashForSignature

public Sha256Hash hashForSignature(int inputIndex,
                                   byte[] connectedScript,
                                   byte sigHashType)
This is required for signatures which use a sigHashType which cannot be represented using SigHash and anyoneCanPay See transaction c99c49da4c38af669dea436d3e73780dfdb6c1ecf9958baa52960e8baee30e73, which has sigHashType 0


bitcoinSerializeToStream

protected void bitcoinSerializeToStream(OutputStream stream)
                                 throws IOException
Description copied from class: Message
Serializes this message to the provided stream. If you just want the raw bytes use bitcoinSerialize().

Throws:
IOException

getLockTime

public long getLockTime()
Transactions can have an associated lock time, specified either as a block height or in seconds since the UNIX epoch. A transaction is not allowed to be confirmed by miners until the lock time is reached, and since Bitcoin 0.8+ a transaction that did not end its lock period (non final) is considered to be non standard and won't be relayed or included in the memory pool either.


setLockTime

public void setLockTime(long lockTime)
Transactions can have an associated lock time, specified either as a block height or in seconds since the UNIX epoch. A transaction is not allowed to be confirmed by miners until the lock time is reached, and since Bitcoin 0.8+ a transaction that did not end its lock period (non final) is considered to be non standard and won't be relayed or included in the memory pool either.


getVersion

public long getVersion()
Returns:
the version

getInputs

public List<TransactionInput> getInputs()
Returns an unmodifiable view of all inputs.


getOutputs

public List<TransactionOutput> getOutputs()
Returns an unmodifiable view of all outputs.


getInput

public TransactionInput getInput(int index)
Returns:
the given transaction: same as getInputs().get(index).

getOutput

public TransactionOutput getOutput(int index)

getConfidence

public TransactionConfidence getConfidence()

hasConfidence

public boolean hasConfidence()
Check if the transaction has a known confidence


equals

public boolean equals(Object other)
Overrides:
equals in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object

getSigOpCount

public int getSigOpCount()
                  throws ScriptException
Gets the count of regular SigOps in this transactions

Throws:
ScriptException

verify

public void verify()
            throws VerificationException
Checks the transaction contents for sanity, in ways that can be done in a standalone manner. Does not perform all checks on a transaction such as whether the inputs are already spent.

Throws:
VerificationException

isTimeLocked

public boolean isTimeLocked()

A transaction is time locked if at least one of its inputs is non-final and it has a lock time

To check if this transaction is final at a given height and time, see isFinal(int, long)


isFinal

public boolean isFinal(int height,
                       long blockTimeSeconds)

Returns true if this transaction is considered finalized and can be placed in a block. Non-finalized transactions won't be included by miners and can be replaced with newer versions using sequence numbers. This is useful in certain types of contracts, such as micropayment channels.

Note that currently the replacement feature is disabled in the Satoshi client and will need to be re-activated before this functionality is useful.


parseLockTimeStr

public static long parseLockTimeStr(String lockTimeStr)
                             throws ParseException
Parses the string either as a whole number of blocks, or if it contains slashes as a YYYY/MM/DD format date and returns the lock time in wire format.

Throws:
ParseException

estimateLockTime

public Date estimateLockTime(AbstractBlockChain chain)
Returns either the lock time as a date, if it was specified in seconds, or an estimate based on the time in the current head block if it was specified as a block time.


getPurpose

public Transaction.Purpose getPurpose()
Returns the purpose for which this transaction was created. See the javadoc for Transaction.Purpose for more information on the point of this field and what it can be.


setPurpose

public void setPurpose(Transaction.Purpose purpose)
Marks the transaction as being created for the given purpose. See the javadoc for Transaction.Purpose for more information on the point of this field and what it can be.



Copyright © 2014. All rights reserved.