Package org.bitcoinj.core
Class BitcoinSerializer
java.lang.Object
org.bitcoinj.core.MessageSerializer
org.bitcoinj.core.BitcoinSerializer
Methods to serialize and de-serialize messages to the Bitcoin network format as defined in the protocol specification.
To be able to serialize and deserialize new Message subclasses the following criteria needs to be met.
- The proper Class instance needs to be mapped to its message name in the names variable below
- There needs to be a constructor matching: NetworkParameters params, byte[] payload
- Message.bitcoinSerializeToStream() needs to be properly subclassed
-
Nested Class Summary
Nested Classes -
Constructor Summary
ConstructorsConstructorDescriptionBitcoinSerializer(Network network) Constructs a BitcoinSerializer with the given behavior.BitcoinSerializer(Network network, int protocolVersion) Constructs a BitcoinSerializer with the given behavior.BitcoinSerializer(NetworkParameters params) Deprecated.BitcoinSerializer(NetworkParameters params, int protocolVersion) Deprecated. -
Method Summary
Modifier and TypeMethodDescriptionReads a message from the given ByteBuffer and returns it.Deserializes only the header in case packet meta data is needed before decoding the payload.Deserialize payload only.Deprecated.intGet the protocol version of this serializer.makeAddressV1Message(ByteBuffer payload) Make an address message from the payload.makeAddressV2Message(ByteBuffer payload) Make an address message from the payload.makeBlock(ByteBuffer payload) Make a block from the payload.makeBloomFilter(ByteBuffer payload) Make an filter message from the payload.makeFilteredBlock(ByteBuffer payload) Make a filtered block from the payload.makeInventoryMessage(ByteBuffer payload) Make an inventory message from the payload.makeTransaction(ByteBuffer payload) Make a transaction from the payload.voidvoidserialize(String name, byte[] message, OutputStream out) Writes message to the output stream.voidserialize(Message message, OutputStream out) Writes message to the output stream.withProtocolVersion(int protocolVersion) Create a new serializer with a specific protocol version.
-
Constructor Details
-
BitcoinSerializer
Deprecated.Constructs a BitcoinSerializer with the given behavior.- Parameters:
params- networkParams used to determine packetMagic
-
BitcoinSerializer
Constructs a BitcoinSerializer with the given behavior.- Parameters:
network- used to determine packetMagic
-
BitcoinSerializer
Deprecated.Constructs a BitcoinSerializer with the given behavior.- Parameters:
params- networkParams used to determine packetMagicprotocolVersion- the protocol version to use
-
BitcoinSerializer
Constructs a BitcoinSerializer with the given behavior.- Parameters:
network- used to determine packetMagicprotocolVersion- the protocol version to use
-
-
Method Details
-
withProtocolVersion
Description copied from class:MessageSerializerCreate a new serializer with a specific protocol version. Mainly used to disable segwit when parsing transactions.- Specified by:
withProtocolVersionin classMessageSerializer
-
getProtocolVersion
public int getProtocolVersion()Description copied from class:MessageSerializerGet the protocol version of this serializer.- Specified by:
getProtocolVersionin classMessageSerializer
-
serialize
Writes message to the output stream.- Specified by:
serializein classMessageSerializer- Throws:
IOException
-
serialize
Writes message to the output stream.- Specified by:
serializein classMessageSerializer- Throws:
IOException
-
deserialize
Reads a message from the given ByteBuffer and returns it.- Specified by:
deserializein classMessageSerializer- Throws:
ProtocolExceptionIOException
-
deserializeHeader
public BitcoinSerializer.BitcoinPacketHeader deserializeHeader(ByteBuffer in) throws ProtocolException, IOException Deserializes only the header in case packet meta data is needed before decoding the payload. This method assumes you have already called seekPastMagicBytes()- Specified by:
deserializeHeaderin classMessageSerializer- Throws:
ProtocolExceptionIOException
-
deserializePayload
public Message deserializePayload(BitcoinSerializer.BitcoinPacketHeader header, ByteBuffer in) throws ProtocolException, BufferUnderflowException Deserialize payload only. You must provide a header, typically obtained by callingdeserializeHeader(java.nio.ByteBuffer).- Specified by:
deserializePayloadin classMessageSerializer- Throws:
ProtocolExceptionBufferUnderflowException
-
getParameters
Deprecated.Get the network parameters for this serializer. -
makeAddressV1Message
Make an address message from the payload. Extension point for alternative serialization format support.- Specified by:
makeAddressV1Messagein classMessageSerializer- Throws:
ProtocolException
-
makeAddressV2Message
Make an address message from the payload. Extension point for alternative serialization format support.- Specified by:
makeAddressV2Messagein classMessageSerializer- Throws:
ProtocolException
-
makeBlock
Make a block from the payload. Extension point for alternative serialization format support.- Specified by:
makeBlockin classMessageSerializer- Throws:
ProtocolException
-
makeBloomFilter
Make an filter message from the payload. Extension point for alternative serialization format support.- Specified by:
makeBloomFilterin classMessageSerializer- Throws:
ProtocolException
-
makeFilteredBlock
Make a filtered block from the payload. Extension point for alternative serialization format support.- Specified by:
makeFilteredBlockin classMessageSerializer- Throws:
ProtocolException
-
makeInventoryMessage
Make an inventory message from the payload. Extension point for alternative serialization format support.- Specified by:
makeInventoryMessagein classMessageSerializer- Throws:
ProtocolException
-
makeTransaction
Make a transaction from the payload. Extension point for alternative serialization format support.- Specified by:
makeTransactionin classMessageSerializer- Throws:
ProtocolException
-
seekPastMagicBytes
- Specified by:
seekPastMagicBytesin classMessageSerializer- Throws:
BufferUnderflowException
-