Module: Bitcoin::Message

Defined in:
lib/bitcoin/message.rb,
lib/bitcoin/message/tx.rb,
lib/bitcoin/message/inv.rb,
lib/bitcoin/message/addr.rb,
lib/bitcoin/message/base.rb,
lib/bitcoin/message/ping.rb,
lib/bitcoin/message/pong.rb,
lib/bitcoin/message/block.rb,
lib/bitcoin/message/error.rb,
lib/bitcoin/message/reject.rb,
lib/bitcoin/message/addr_v2.rb,
lib/bitcoin/message/cfilter.rb,
lib/bitcoin/message/headers.rb,
lib/bitcoin/message/ver_ack.rb,
lib/bitcoin/message/version.rb,
lib/bitcoin/message/get_addr.rb,
lib/bitcoin/message/get_data.rb,
lib/bitcoin/message/mem_pool.rb,
lib/bitcoin/message/block_txn.rb,
lib/bitcoin/message/cf_parser.rb,
lib/bitcoin/message/cfcheckpt.rb,
lib/bitcoin/message/cfheaders.rb,
lib/bitcoin/message/inventory.rb,
lib/bitcoin/message/not_found.rb,
lib/bitcoin/message/fee_filter.rb,
lib/bitcoin/message/filter_add.rb,
lib/bitcoin/message/get_blocks.rb,
lib/bitcoin/message/send_cmpct.rb,
lib/bitcoin/message/cmpct_block.rb,
lib/bitcoin/message/filter_load.rb,
lib/bitcoin/message/get_headers.rb,
lib/bitcoin/message/filter_clear.rb,
lib/bitcoin/message/get_cfilters.rb,
lib/bitcoin/message/merkle_block.rb,
lib/bitcoin/message/network_addr.rb,
lib/bitcoin/message/prefilled_tx.rb,
lib/bitcoin/message/send_addr_v2.rb,
lib/bitcoin/message/send_headers.rb,
lib/bitcoin/message/get_block_txn.rb,
lib/bitcoin/message/get_cfcheckpt.rb,
lib/bitcoin/message/get_cfheaders.rb,
lib/bitcoin/message/headers_parser.rb,
lib/bitcoin/message/block_transactions.rb,
lib/bitcoin/message/inventories_parser.rb,
lib/bitcoin/message/header_and_short_ids.rb,
lib/bitcoin/message/block_transaction_request.rb

Defined Under Namespace

Modules: CFParser, HeadersParser, InventoriesParser Classes: Addr, AddrV2, Base, Block, BlockTransactionRequest, BlockTransactions, BlockTxn, CFCheckpt, CFHeaders, CFilter, CmpctBlock, Error, FeeFilter, FilterAdd, FilterClear, FilterLoad, GetAddr, GetBlockTxn, GetBlocks, GetCFCheckpt, GetCFHeaders, GetCFilters, GetData, GetHeaders, HeaderAndShortIDs, Headers, Inv, Inventory, MemPool, MerkleBlock, NetworkAddr, NotFound, Ping, Pong, PrefilledTx, Reject, SendAddrV2, SendCmpct, SendHeaders, Tx, VerAck, Version

Constant Summary collapse

USER_AGENT =
"/bitcoinrb:#{Bitcoin::VERSION}/"
SERVICE_FLAGS =
{
    none: 0,
    network: 1 << 0,  # the node is capable of serving the block chain. It is currently set by all Bitcoin Core node, and is unset by SPV clients or other peers that just want network services but don't provide them.
    # getutxo: 1 << 1, # BIP-64. not implemented in Bitcoin Core.
    bloom: 1 << 2,    # the node is capable and willing to handle bloom-filtered connections. Bitcoin Core node used to support this by default, without advertising this bit, but no longer do as of protocol version 70011 (= NO_BLOOM_VERSION)
    witness: 1 << 3,  # the node can be asked for blocks and transactions including witness data.
    # xthin: 1 << 4 # support Xtreme Thinblocks. not implemented in Bitcoin Core
}
DEFAULT_SERVICE_FLAGS =

DEFAULT_SERVICE_FLAGS = SERVICE_FLAGS | SERVICE_FLAGS | SERVICE_FLAGS

SERVICE_FLAGS[:none] | SERVICE_FLAGS[:witness]
DEFAULT_STOP_HASH =
"00"*32
VERSION =

the protocol version.

{
    headers: 31800,
    pong: 60001,
    bloom: 70011,
    send_headers: 70012,
    fee_filter: 70013,
    compact: 70014,
    compact_witness: 70015
}
NETWORK_ID =
{ipv4: 0x01, ipv6: 0x02, tor_v2: 0x03, tor_v3: 0x04, i2p: 0x05, cjdns: 0x06}
INTERNAL_IN_IPV6_PREFIX =
"fd6b:88c0:8724"

Class Method Summary collapse

Class Method Details

.decode(command, payload = nil) ⇒ Bitcoin::Message::

Decode P2P message.

Parameters:

  • command (String)

    P2P message command string.

  • payload (String) (defaults to: nil)

    P2P message payload with hex format..

Returns:



86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# File 'lib/bitcoin/message.rb', line 86

def decode(command, payload = nil)
  payload = payload.htb if payload
  case command
  when Bitcoin::Message::Version::COMMAND
    Bitcoin::Message::Version.parse_from_payload(payload)
  when Bitcoin::Message::VerAck::COMMAND
    Bitcoin::Message::VerAck.new
  when Bitcoin::Message::GetAddr::COMMAND
    Bitcoin::Message::GetAddr.new
  when Bitcoin::Message::Addr::COMMAND
    Bitcoin::Message::Addr.parse_from_payload(payload)
  when Bitcoin::Message::SendHeaders::COMMAND
    Bitcoin::Message::SendHeaders.new
  when Bitcoin::Message::FeeFilter::COMMAND
    Bitcoin::Message::FeeFilter.parse_from_payload(payload)
  when Bitcoin::Message::Ping::COMMAND
    Bitcoin::Message::Ping.parse_from_payload(payload)
  when Bitcoin::Message::Pong::COMMAND
    Bitcoin::Message::Pong.parse_from_payload(payload)
  when Bitcoin::Message::GetHeaders::COMMAND
    Bitcoin::Message::GetHeaders.parse_from_payload(payload)
  when Bitcoin::Message::Headers::COMMAND
    Bitcoin::Message::Headers.parse_from_payload(payload)
  when Bitcoin::Message::Block::COMMAND
    Bitcoin::Message::Block.parse_from_payload(payload)
  when Bitcoin::Message::Tx::COMMAND
    Bitcoin::Message::Tx.parse_from_payload(payload)
  when Bitcoin::Message::NotFound::COMMAND
    Bitcoin::Message::NotFound.parse_from_payload(payload)
  when Bitcoin::Message::MemPool::COMMAND
    Bitcoin::Message::MemPool.new
  when Bitcoin::Message::Reject::COMMAND
    Bitcoin::Message::Reject.parse_from_payload(payload)
  when Bitcoin::Message::SendCmpct::COMMAND
    Bitcoin::Message::SendCmpct.parse_from_payload(payload)
  when Bitcoin::Message::Inv::COMMAND
    Bitcoin::Message::Inv.parse_from_payload(payload)
  when Bitcoin::Message::MerkleBlock::COMMAND
    Bitcoin::Message::MerkleBlock.parse_from_payload(payload)
  when Bitcoin::Message::CmpctBlock::COMMAND
    Bitcoin::Message::CmpctBlock.parse_from_payload(payload)
  when Bitcoin::Message::GetData::COMMAND
    Bitcoin::Message::GetData.parse_from_payload(payload)
  when Bitcoin::Message::GetCFHeaders::COMMAND
    Bitcoin::Message::GetCFHeaders.parse_from_payload(payload)
  when Bitcoin::Message::GetCFilters::COMMAND
    Bitcoin::Message::GetCFilters.parse_from_payload(payload)
  when Bitcoin::Message::GetCFCheckpt::COMMAND
    Bitcoin::Message::GetCFCheckpt.parse_from_payload(payload)
  when Bitcoin::Message::CFCheckpt::COMMAND
    Bitcoin::Message::CFCheckpt.parse_from_payload(payload)
  when Bitcoin::Message::CFHeaders::COMMAND
    Bitcoin::Message::CFHeaders.parse_from_payload(payload)
  when Bitcoin::Message::CFilter::COMMAND
    Bitcoin::Message::CFilter.parse_from_payload(payload)
  when Bitcoin::Message::SendAddrV2::COMMAND
    Bitcoin::Message::SendAddrV2.new
  when Bitcoin::Message::AddrV2::COMMAND
    Bitcoin::Message::AddrV2.parse_from_payload(payload)
  end
end