class Bitcoin::Message::Inventory

inventory class. inventory is a part of message. bitcoin.org/en/developer-reference#term-inventory

Constants

MSG_BLOCK
MSG_CMPCT_BLOCK
MSG_FILTERED_BLOCK
MSG_FILTERED_WITNESS_BLOCK
MSG_TX
MSG_WITNESS_BLOCK
MSG_WITNESS_TX
SEGWIT_FLAG

Attributes

hash[RW]
identifier[RW]

Public Class Methods

new(identifier, hash) click to toggle source
# File lib/bitcoin/message/inventory.rb, line 20
def initialize(identifier, hash)
  raise Error, "invalid type identifier specified. identifier = #{identifier}" unless valid_identifier?(identifier)
  @identifier = identifier
  @hash = hash
end
parse_from_payload(payload) click to toggle source

parse inventory payload

# File lib/bitcoin/message/inventory.rb, line 27
def self.parse_from_payload(payload)
  raise Error, 'invalid inventory size.' if payload.bytesize != 36
  identifier = payload[0..4].unpack1('V')
  hash = payload[4..-1].bth # internal byte order
  new(identifier, hash)
end

Public Instance Methods

block?() click to toggle source
# File lib/bitcoin/message/inventory.rb, line 38
def block?
  [MSG_BLOCK, MSG_WITNESS_BLOCK, MSG_FILTERED_WITNESS_BLOCK].include?(identifier)
end
to_payload() click to toggle source
# File lib/bitcoin/message/inventory.rb, line 34
def to_payload
  [identifier].pack('V') << hash.htb
end

Private Instance Methods

valid_identifier?(identifier) click to toggle source
# File lib/bitcoin/message/inventory.rb, line 44
def valid_identifier?(identifier)
  [MSG_TX, MSG_BLOCK, MSG_FILTERED_BLOCK, MSG_CMPCT_BLOCK, MSG_WITNESS_TX,
   MSG_WITNESS_BLOCK, MSG_FILTERED_WITNESS_BLOCK].include?(identifier)
end