Test out the Version message
This commit is contained in:
@@ -44,11 +44,11 @@ module BtcWireProto
|
||||
# Comprehensive list of known networks. The hex values are what you see in
|
||||
# MessageHdr#magic and the symbols are their known friendly names.
|
||||
NETWORKS = {
|
||||
:main => 0xF9BEB4D9,
|
||||
0xF9BEB4D9 => :main,
|
||||
:testnet => 0xDAB5BFFA,
|
||||
0xDAB5BFFA => :testnet,
|
||||
|
||||
:testnet => 0xFABFB5DA,
|
||||
0xFABFB5DA => :testnet
|
||||
:main => 0xD9B4BEF9,
|
||||
0xD9B4BEF9 => :main
|
||||
}
|
||||
|
||||
# Comprehensive list of known inventory vector types.
|
||||
@@ -392,7 +392,7 @@ module BtcWireProto
|
||||
# version and verack messages don't have a checksum. The rest do.
|
||||
# @return[Boolean] does this message header have a checksum field or not?
|
||||
def has_checksum?
|
||||
command != "version" && command != "verack"
|
||||
!%w|version verack|.include?(command.strip)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -430,26 +430,25 @@ module BtcWireProto
|
||||
# Works out what the payload looks like based on the MessageHdr struct
|
||||
# and (potentially) the version
|
||||
def payload_choice
|
||||
puts header.command
|
||||
return header.command if %w{
|
||||
cmd = header.command.to_s.strip
|
||||
return cmd if %w{
|
||||
version inv getdata getblocks getheaders tx block headers alert
|
||||
}.include?(header.command)
|
||||
}.include?(cmd)
|
||||
|
||||
# We can't parse these yet, and so we don't know where in the stream the
|
||||
# next message starts. So all we can do is throw an error
|
||||
raise NotImplementedError.new(
|
||||
"Received unsupported command #{header.command}"
|
||||
) if %w|checkorder submitorder|.include?(header.command)
|
||||
"Received unsupported command #{cmd}"
|
||||
) if %w|checkorder submitorder|.include?(cmd)
|
||||
|
||||
# These commands don't have any payloads
|
||||
return "null" if %w|verack getaddr ping|.include?(header.command) ||
|
||||
header.command == ""
|
||||
return "null" if %w|verack getaddr ping|.include?(cmd) || cmd == ""
|
||||
|
||||
# Payload has two forms, depending on protocol version. Ugh.
|
||||
return (@version < 31402 ? "addr_pre31402" : "addr_from31402") if
|
||||
header.command == "addr"
|
||||
cmd == "addr"
|
||||
|
||||
raise NotImplementedError.new("Unknown command: #{header.command.inspect}")
|
||||
raise NotImplementedError.new("Unknown command: #{cmd}")
|
||||
end
|
||||
|
||||
end
|
||||
|
Reference in New Issue
Block a user