Skip to content

Commit

Permalink
Fixing bug where to_bytes clobbers testnet params.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ethan Heilman committed Dec 31, 2014
1 parent df1adeb commit 9b00e4b
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions bitcoin/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
from bitcoin.core import *
from bitcoin.core.serialize import *
from bitcoin.net import *
from bitcoin import MainParams
import bitcoin

MSG_TX = 1
MSG_BLOCK = 2
Expand All @@ -51,11 +51,11 @@ def msg_ser(self, f):
def msg_deser(cls, f, protover=PROTO_VERSION):
raise NotImplementedError

def to_bytes(self, params=MainParams()):
def to_bytes(self):
f = _BytesIO()
self.msg_ser(f)
body = f.getvalue()
res = params.MESSAGE_START
res = bitcoin.params.MESSAGE_START
res += self.command
res += b"\x00" * (12 - len(self.command))
res += struct.pack(b"<I", len(body))
Expand All @@ -74,13 +74,13 @@ def from_bytes(cls, b, protover=PROTO_VERSION):
return MsgSerializable.stream_deserialize(f, protover=protover)

@classmethod
def stream_deserialize(cls, f, params=MainParams(), protover=PROTO_VERSION):
def stream_deserialize(cls, f, protover=PROTO_VERSION):
recvbuf = ser_read(f, 4 + 12 + 4 + 4)

# check magic
if recvbuf[:4] != params.MESSAGE_START:
if recvbuf[:4] != bitcoin.params.MESSAGE_START:
raise ValueError("Invalid message start '%s', expected '%s'" %
(b2x(recvbuf[:4]), b2x(params.MESSAGE_START)))
(b2x(recvbuf[:4]), b2x(bitcoin.params.MESSAGE_START)))

# remaining header fields: command, msg length, checksum
command = recvbuf[4:4+12].split(b"\x00", 1)[0]
Expand Down

0 comments on commit 9b00e4b

Please sign in to comment.