Class: Bitcoin::Message::Base
Overview
Base message class
Direct Known Subclasses
Addr, Block, BlockTxn, CmpctBlock, FeeFilter, FilterAdd, FilterClear, FilterLoad, GetAddr, GetBlockTxn, GetBlocks, GetData, GetHeaders, Headers, Inv, MemPool, MerkleBlock, NotFound, Ping, Pong, Reject, SendCmpct, SendHeaders, Tx, VerAck, Version
Constant Summary
Constants included from Util
Instance Method Summary collapse
-
#to_payload ⇒ Object
abstract method.
-
#to_pkt ⇒ Object
generate message header (binary format) bitcoin.org/en/developer-reference#message-headers.
Methods included from Util
byte_to_bit, calc_checksum, decode_base58_address, double_sha256, encode_base58_address, hash160, hmac_sha256, pack_boolean, pack_var_int, pack_var_string, sha256, unpack_boolean, unpack_var_int, unpack_var_int_from_io, unpack_var_string
Instance Method Details
#to_payload ⇒ Object
abstract method
21 22 23 |
# File 'lib/bitcoin/message/base.rb', line 21 def to_payload raise 'to_payload must be implemented in a child class.' end |
#to_pkt ⇒ Object
generate message header (binary format) bitcoin.org/en/developer-reference#message-headers
11 12 13 14 15 16 17 18 |
# File 'lib/bitcoin/message/base.rb', line 11 def to_pkt payload = to_payload magic = Bitcoin.chain_params.magic_head.htb command_name = self.class.const_get(:COMMAND, false).ljust(12, "\x00") payload_size = [payload.bytesize].pack('V') checksum = Bitcoin.double_sha256(payload)[0...4] magic << command_name << payload_size << checksum << payload end |