All modules listed below are under the “protocoin” module.
Base class for the Fields. This class only implements the counter to keep the order of the fields on the serializer classes.
This method must read the stream data and then deserialize and return the deserialized content.
Returns: | the deserialized content |
---|---|
Parameters: | stream – stream of data to read |
This method should be implemented to parse the value parameter into the field internal representation.
Parameters: | value – value to be parsed |
---|
Serialize the internal representation and return the serialized data.
Returns: | the serialized data |
---|
A fixed length string field.
Example of use:
class MessageHeaderSerializer(Serializer):
model_class = MessageHeader
magic = fields.UInt32LEField()
command = fields.FixedStringField(12)
length = fields.UInt32LEField()
checksum = fields.UInt32LEField()
A hash type field.
The type of the inventories
An IPv4 address field without timestamp and reserved IPv6 space.
16-bit little-endian integer field.
32-bit little-endian integer field.
64-bit little-endian integer field.
A field used to serialize/deserialize a list of serializers.
Example of use:
class TxSerializer(Serializer):
model_class = Tx
version = fields.UInt32LEField()
tx_in = fields.ListField(TxInSerializer)
tx_out = fields.ListField(TxOutSerializer)
lock_time = fields.UInt32LEField()
The network magic values
A field used to nest another serializer.
Example of use:
class TxInSerializer(Serializer):
model_class = TxIn
previous_output = fields.NestedField(OutPointSerializer)
signature_script = fields.VariableStringField()
sequence = fields.UInt32LEField()
The protocol version
This is a base class for all fields that has only one value and their value can be represented by a Python struct datatype.
Example of use:
class UInt32LEField(PrimaryField):
datatype = "<I"
Deserialize the stream using the struct data type specified.
Parameters: | stream – the data stream |
---|
This method will set the internal value to the specified value.
Parameters: | value – the value to be set |
---|
Serialize the internal data and then return the serialized data.
The available services
16-bit big-endian unsigned integer field.
16-bit little-endian unsigned integer field.
32-bit little-endian unsigned integer field.
64-bit little-endian unsigned integer field.
A variable size integer field.
A variable length string field.
A vector of addresses.
Serializer for the addresses vector.
alias of AddressVector
The block message. This message contains all the transactions present in the block.
The header of the block.
This method will calculate the hash of the block.
The serializer for the block header.
alias of BlockHeader
The deserializer for the blocks.
GetData message command.
Serializer for the GetData command.
The header only vector.
Serializer for the block header vector.
alias of HeaderVector
The IPv4 Address (without timestamp).
Serializer for the IPv4Address.
alias of IPv4Address
The IPv4 Address with timestamp.
Serializer for the IPv4AddressTimestamp.
alias of IPv4AddressTimestamp
The Inventory representation.
Converts the inventory type to text representation.
The serializer for the Inventory.
A vector of inventories.
The serializer for the vector of inventories.
alias of InventoryVector
The mempool command.
The serializer for the mempool command.
The header of all bitcoin messages.
Serializer for the MessageHeader.
Calculate the checksum of the specified payload.
Parameters: | payload – The binary data payload. |
---|
alias of MessageHeader
NotFound command message.
Serializer for the NotFound message.
The OutPoint representation.
The OutPoint representation serializer.
The ping command, which should always be answered with a Pong.
The pong command, usually returned when a ping command arrives.
The main serializer class, inherit from this class to create custom serializers.
Example of use:
class VerAckSerializer(Serializer):
model_class = VerAck
This method will read the stream and then will deserialize the binary data information present on it.
Parameters: | stream – A file-like object (StringIO, file, socket, etc.) |
---|
This method will receive an object and then will serialize it according to the fields declared on the serializer.
Parameters: | obj – The object to serializer. |
---|
The serializer abstract base class.
The serializer meta class. This class will create an attribute called ‘_fields’ in each serializer with the ordered dict of fields present on the subclasses.
This method will construct an ordered dict with all the fields present on the serializer classes.
The main transaction representation, this object will contain all the inputs and outputs of the transaction.
The transaction input representation.
The transaction input serializer.
The transaction output.
The transaction output serializer.
The version acknowledge (verack) command.
The serializer for the verack command.
The version command.
The base class for a Bitcoin network client, this class implements utility functions to create your own class.
This method will close the socket stream.
This method will be called for every message before the message payload deserialization.
Parameters: |
|
---|
This method will be called for every sent message.
Parameters: |
|
---|
This is the main method of the client, it will enter in a receive/send loop.
This method is called inside the loop() method to receive a message from the stream (socket) and then deserialize it.
This method will serialize the message using the specified serializer and then it will send it to the socket stream.
Parameters: |
|
---|
This class implements all the protocol rules needed for a client to stay up in the network. It will handle the handshake rules as well answer the ping messages.
This method will handle the Ping message and then will answer every Ping message with a Pong message using the nonce received.
Parameters: |
|
---|
This method will handle the Version message and will send a VerAck message when it receives the Version message.
Parameters: |
|
---|
This method will implement the handshake of the Bitcoin protocol. It will send the Version message.