|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.google.bitcoin.core.Message
com.google.bitcoin.core.Transaction
public class Transaction
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.
It implements TWO serialization protocols - the BitCoin proprietary format which is identical to the C++ implementation and is used for reading/writing transactions to the wire and for hashing. It also implements Java serialization which is used for the wallet. This allows us to easily add extra fields used for our own accounting or UI purposes.
Nested Class Summary | |
---|---|
static class |
Transaction.SigHash
These constants are a part of a scriptSig signature on the inputs. |
Field Summary |
---|
Fields inherited from class com.google.bitcoin.core.Message |
---|
bytes, cursor, MAX_SIZE, offset, params, protocolVersion |
Constructor Summary | |
---|---|
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. |
Method Summary | |
---|---|
void |
addInput(TransactionOutput from)
Adds an input to this transaction that imports value from the given output. |
void |
addOutput(TransactionOutput to)
Adds the given output to this transaction. |
void |
bitcoinSerializeToStream(OutputStream stream)
Serializes this message to the provided stream. |
boolean |
equals(Object other)
|
Sha256Hash |
getHash()
Returns the transaction hash as you see them in the block explorer. |
String |
getHashAsString()
|
List<TransactionInput> |
getInputs()
Returns a read-only list of the inputs of this transaction. |
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. |
int |
hashCode()
|
boolean |
isCoinBase()
A coinbase transaction is one that creates a new coin. |
void |
signInputs(Transaction.SigHash hashType,
Wallet wallet)
Once a transaction has some inputs and outputs added, the signatures in the inputs can be calculated. |
String |
toString()
|
boolean |
verifyInput(int inputIndex,
Transaction connectedTx)
Given a named input and the transaction output it connects to, runs the script formed from the concatenation of the input and output scripts, returning true if the link is valid. |
Methods inherited from class com.google.bitcoin.core.Message |
---|
bitcoinSerialize |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public Transaction(NetworkParameters params, byte[] payloadBytes) throws ProtocolException
ProtocolException
public Transaction(NetworkParameters params, byte[] payload, int offset) throws ProtocolException
ProtocolException
Method Detail |
---|
public List<TransactionInput> getInputs()
public Sha256Hash getHash()
public String getHashAsString()
public BigInteger getValueSentToMe(Wallet wallet)
public BigInteger getValueSentFromMe(Wallet wallet) throws ScriptException
ScriptException
public boolean isCoinBase()
public String toString()
toString
in class Object
public void addInput(TransactionOutput from)
public void addOutput(TransactionOutput to)
public void signInputs(Transaction.SigHash hashType, Wallet wallet) throws ScriptException
This method is similar to SignatureHash in script.cpp
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.
ScriptException
public boolean verifyInput(int inputIndex, Transaction connectedTx) throws ScriptException
WARNING: NOT FINISHED
inputIndex
- Which input to verify.connectedTx
- The Transaction that the input is connected to.
ScriptException
public void bitcoinSerializeToStream(OutputStream stream) throws IOException
Message
IOException
public boolean equals(Object other)
equals
in class Object
public int hashCode()
hashCode
in class Object
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |