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/wtxid_relay.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/send_tx_rcncl.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, SendTxRcncl, Tx, VerAck, Version, WTXIDRelay

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,
    wtxid_relay: 70016
}
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:



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
147
148
149
150
151
152
153
# File 'lib/bitcoin/message.rb', line 89

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