Add Message#cmd_sym as a convenience method
This commit is contained in:
@@ -398,6 +398,11 @@ module BtcWireProto
|
|||||||
uint32 :payload_len
|
uint32 :payload_len
|
||||||
uint32 :checksum, :onlyif => :has_checksum?
|
uint32 :checksum, :onlyif => :has_checksum?
|
||||||
|
|
||||||
|
def cmd_sym
|
||||||
|
c = command.strip
|
||||||
|
c == "" ? nil : c.to_sym
|
||||||
|
end
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
||||||
# version and verack messages don't have a checksum. The rest do.
|
# version and verack messages don't have a checksum. The rest do.
|
||||||
@@ -421,6 +426,10 @@ module BtcWireProto
|
|||||||
|
|
||||||
message_hdr :header
|
message_hdr :header
|
||||||
|
|
||||||
|
def cmd_sym
|
||||||
|
header ? header.cmd_sym : nil
|
||||||
|
end
|
||||||
|
|
||||||
choice :payload, :selection => :payload_choice do
|
choice :payload, :selection => :payload_choice do
|
||||||
version "version"
|
version "version"
|
||||||
addr_pre31402 "addr_pre31402"
|
addr_pre31402 "addr_pre31402"
|
||||||
|
@@ -235,6 +235,11 @@ describe ::BtcWireProto do
|
|||||||
m.payload.selection.should == "version"
|
m.payload.selection.should == "version"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "should have a :version command symbol" do
|
||||||
|
m = Message::new(:header => {:command => 'version'})
|
||||||
|
m.cmd_sym.should == :version
|
||||||
|
end
|
||||||
|
|
||||||
it "should parse binary data correctly" do
|
it "should parse binary data correctly" do
|
||||||
m = Message::read(binary(%w{
|
m = Message::read(binary(%w{
|
||||||
F9 BE B4 D9 76 65 72 73 69 6F 6E 00 00 00 00 00 55 00 00
|
F9 BE B4 D9 76 65 72 73 69 6F 6E 00 00 00 00 00 55 00 00
|
||||||
@@ -265,6 +270,11 @@ describe ::BtcWireProto do
|
|||||||
m = Message.new(:header => {:command => "verack"})
|
m = Message.new(:header => {:command => "verack"})
|
||||||
m.payload.selection.should == "null"
|
m.payload.selection.should == "null"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "should have a :verack command symbol" do
|
||||||
|
m = Message.new(:header => {:command => "verack"})
|
||||||
|
m.cmd_sym.should == :verack
|
||||||
|
end
|
||||||
|
|
||||||
it "should parse the binary data correctly" do
|
it "should parse the binary data correctly" do
|
||||||
m = Message::read(binary(%w{
|
m = Message::read(binary(%w{
|
||||||
|
Reference in New Issue
Block a user