Class UTXOsMessage
- java.lang.Object
-
- org.bitcoinj.core.Message
-
- org.bitcoinj.core.UTXOsMessage
-
public class UTXOsMessage extends Message
Message representing a list of unspent transaction outputs ("utxos"), returned in response to sending a
GetUTXOsMessage
("getutxos"). Note that both this message and the query that generates it are not supported by Bitcoin Core. An implementation is available in Bitcoin XT, a patch set on top of Core. Thus if you want to use it, you must find some XT peers to connect to. This can be done using aHttpDiscovery
class combined with an HTTP/Cartographer seed.The getutxos/utxos protocol is defined in BIP 65. In that document you can find a discussion of the security of this protocol (briefly, there is none). Because the data found in this message is not authenticated it should be used carefully. Places where it can be useful are if you're querying your own trusted node, if you're comparing answers from multiple nodes simultaneously and don't believe there is a MITM on your connection, or if you're only using the returned data as a UI hint and it's OK if the data is occasionally wrong. Bear in mind that the answer can be wrong even in the absence of malicious intent just through the nature of querying an ever changing data source: the UTXO set may be updated by a new transaction immediately after this message is returned.
Instances of this class are not safe for use by multiple threads.
-
-
Field Summary
Fields Modifier and Type Field Description static long
MEMPOOL_HEIGHT
This is a special sentinel value that can appear in the heights field if the given tx is in the mempool.-
Fields inherited from class org.bitcoinj.core.Message
cursor, length, MAX_SIZE, offset, params, payload, recached, serializer, UNKNOWN_LENGTH
-
-
Constructor Summary
Constructors Constructor Description UTXOsMessage(NetworkParameters params, byte[] payloadBytes)
UTXOsMessage(NetworkParameters params, java.util.List<TransactionOutput> outputs, long[] heights, Sha256Hash chainHead, long height)
Provide an array of output objects, with nulls indicating that the output was missing.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
bitcoinSerializeToStream(java.io.OutputStream stream)
Serializes this message to the provided stream.boolean
equals(java.lang.Object o)
long[]
getHeights()
Returns the block heights of each output returned in getOutputs(), or MEMPOOL_HEIGHT if not confirmed yet.byte[]
getHitMap()
Returns a bit map indicating which of the queried outputs were found in the UTXO set.java.util.List<TransactionOutput>
getOutputs()
Returns the list of outputs that matched the query.int
hashCode()
protected void
parse()
java.lang.String
toString()
-
Methods inherited from class org.bitcoinj.core.Message
adjustLength, bitcoinSerialize, bitcoinSerialize, getHash, getMessageSize, getParams, hasMoreBytes, isCached, isRecached, readByte, readByteArray, readBytes, readHash, readInt64, readStr, readUint32, readUint64, readVarInt, readVarInt, setSerializer, unCache, unsafeBitcoinSerialize
-
-
-
-
Constructor Detail
-
UTXOsMessage
public UTXOsMessage(NetworkParameters params, byte[] payloadBytes)
-
UTXOsMessage
public UTXOsMessage(NetworkParameters params, java.util.List<TransactionOutput> outputs, long[] heights, Sha256Hash chainHead, long height)
Provide an array of output objects, with nulls indicating that the output was missing. The bitset will be calculated from this.
-
-
Method Detail
-
bitcoinSerializeToStream
protected void bitcoinSerializeToStream(java.io.OutputStream stream) throws java.io.IOException
Description copied from class:Message
Serializes this message to the provided stream. If you just want the raw bytes use bitcoinSerialize().- Overrides:
bitcoinSerializeToStream
in classMessage
- Throws:
java.io.IOException
-
parse
protected void parse() throws ProtocolException
- Specified by:
parse
in classMessage
- Throws:
ProtocolException
-
getHitMap
public byte[] getHitMap()
Returns a bit map indicating which of the queried outputs were found in the UTXO set.
-
getOutputs
public java.util.List<TransactionOutput> getOutputs()
Returns the list of outputs that matched the query.
-
getHeights
public long[] getHeights()
Returns the block heights of each output returned in getOutputs(), or MEMPOOL_HEIGHT if not confirmed yet.
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
-