Skip to content

Fixing bug where to_bytes clobbers testnet params. #38

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 1, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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