Class: Bitcoin::Message::Base

Inherits:
Object
  • Object
show all
Extended by:
Util
Includes:
Util
Defined in:
lib/bitcoin/message/base.rb

Overview

Base message class

Constant Summary

Constants included from Util

Util::DIGEST_NAME_SHA256

Instance Method Summary collapse

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_payloadObject

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_pktObject

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