class Tapyrus::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/tapyrus/message/inventory.rb, line 19 def initialize(identifier, hash) unless valid_identifier?(identifier) raise Error, "invalid type identifier specified. identifier = #{identifier}" end @identifier = identifier @hash = hash end
parse_from_payload(payload)
click to toggle source
parse inventory payload
# File lib/tapyrus/message/inventory.rb, line 28 def self.parse_from_payload(payload) raise Error, 'invalid inventory size.' if payload.bytesize != 36 identifier = payload[0..4].unpack('V').first hash = payload[4..-1].bth # internal byte order new(identifier, hash) end
Public Instance Methods
block?()
click to toggle source
# File lib/tapyrus/message/inventory.rb, line 39 def block? [MSG_BLOCK, MSG_WITNESS_BLOCK, MSG_FILTERED_WITNESS_BLOCK].include?(identifier) end
to_payload()
click to toggle source
# File lib/tapyrus/message/inventory.rb, line 35 def to_payload [identifier].pack('V') << hash.htb end
Private Instance Methods
valid_identifier?(identifier)
click to toggle source
# File lib/tapyrus/message/inventory.rb, line 45 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