Class: BitcoinNode::Protocol::Message
- Inherits:
-
Object
- Object
- BitcoinNode::Protocol::Message
- Defined in:
- lib/bitcoin_node/protocol.rb
Instance Attribute Summary collapse
-
#command ⇒ Object
readonly
Returns the value of attribute command.
Class Method Summary collapse
Instance Method Summary collapse
- #bytesize ⇒ Object
-
#initialize(payload) ⇒ Message
constructor
A new instance of Message.
- #raw ⇒ Object
Constructor Details
Instance Attribute Details
#command ⇒ Object (readonly)
Returns the value of attribute command.
48 49 50 |
# File 'lib/bitcoin_node/protocol.rb', line 48 def command @command end |
Class Method Details
.validate(raw_message) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/bitcoin_node/protocol.rb', line 68 def self.validate() network, command, expected_length, checksum = Header.unpack() raw_payload = [Header::SIZE...(Header::SIZE + expected_length)] if (actual = raw_payload.bytesize) < expected_length raise BN::P::IncompleteMessageError.new("Incomplete message (missing #{expected_length - actual} bytes)") elsif checksum != BN::Protocol.digest(raw_payload)[0...4] raise BN::P::InvalidChecksumError.new("Invalid checksum on command #{command}") else [raw_payload, command] end end |
Instance Method Details
#bytesize ⇒ Object
64 65 66 |
# File 'lib/bitcoin_node/protocol.rb', line 64 def bytesize raw.bytesize end |
#raw ⇒ Object
56 57 58 59 60 61 62 |
# File 'lib/bitcoin_node/protocol.rb', line 56 def raw @raw ||= begin [Header.build_from(@payload).raw, @payload.raw] .join .force_encoding('binary') end end |