ex_wire v0.1.1 ExWire.Packet.Status

Status messages establish a proper Eth Wire connection, and verify the two clients are compatable.

**Status** [`+0x00`: `P`, `protocolVersion`: `P`, `networkId`: `P`, `td`: `P`, `bestHash`: `B_32`, `genesisHash`: `B_32`]

Inform a peer of its current ethereum state. This message should be sent after the initial
handshake and prior to any ethereum related messages.

* `protocolVersion` is one of:
  * `0x00` for PoC-1;
  * `0x01` for PoC-2;
  * `0x07` for PoC-3;
  * `0x09` for PoC-4.
  * `0x17` for PoC-5.
  * `0x1c` for PoC-6.
  * `61` for PV61
  * `62` for PV62
  * `63` for PV63
* `networkId`: 0=Olympic (disused), 1=Frontier (mainnet), 2=Morden (disused), 3=Ropsten (testnet), 4=Rinkeby
* `td`: Total Difficulty of the best chain. Integer, as found in block header.
* `bestHash`: The hash of the best (i.e. highest TD) known block.
* `genesisHash`: The hash of the Genesis block.

Link to this section Summary

Functions

Given an RLP-encoded Status packet from Eth Wire Protocol, decodes into a Status packet

Handles a Status message

Given a Status packet, serializes for transport over Eth Wire Protocol

Link to this section Types

Link to this type t()
t() :: %ExWire.Packet.Status{best_hash: binary, block_number: integer, genesis_hash: binary, manifest_hash: binary, network_id: integer, protocol_version: integer, total_difficulty: integer}

Link to this section Functions

Link to this function deserialize(rlp)
deserialize(ExRLP.t) :: t

Given an RLP-encoded Status packet from Eth Wire Protocol, decodes into a Status packet.

Note: we will decode warp’s manifest_hash and block_number, if given.

Examples

iex> ExWire.Packet.Status.deserialize([<<0x63>>, <<3>>, <<10>>, <<5>>, <<4>>])
%ExWire.Packet.Status{protocol_version: 0x63, network_id: 3, total_difficulty: 10, best_hash: <<5>>, genesis_hash: <<4>>}

iex> ExWire.Packet.Status.deserialize([<<0x63>>, <<3>>, <<10>>, <<5>>, <<4>>, <<11>>, <<11>>])
%ExWire.Packet.Status{protocol_version: 0x63, network_id: 3, total_difficulty: 10, best_hash: <<5>>, genesis_hash: <<4>>, manifest_hash: <<11>>, block_number: 11}

Handles a Status message.

We should decide whether or not we want to continue communicating with this peer. E.g. do our network and protocol versions match?

Examples

iex> %ExWire.Packet.Status{protocol_version: 63, network_id: 3, total_difficulty: 10, best_hash: <<5>>, genesis_hash: <<4>>}
...> |> ExWire.Packet.Status.handle()
:ok

# Test a peer with an incompatible version
iex> %ExWire.Packet.Status{protocol_version: 555, network_id: 3, total_difficulty: 10, best_hash: <<5>>, genesis_hash: <<4>>}
...> |> ExWire.Packet.Status.handle()
{:disconnect, :useless_peer}
Link to this function serialize(packet)
serialize(t) :: ExRLP.t

Given a Status packet, serializes for transport over Eth Wire Protocol.

Examples

iex> %ExWire.Packet.Status{protocol_version: 0x63, network_id: 3, total_difficulty: 10, best_hash: <<5>>, genesis_hash: <<4>>}
...> |> ExWire.Packet.Status.serialize
[0x63, 3, 10, <<5>>, <<4>>]