Skip to content

Commit 0fc7123

Browse files
committed
Merge pull request #38
9b00e4b Fixing bug where to_bytes clobbers testnet params. (Ethan Heilman)
2 parents df1adeb + 9b00e4b commit 0fc7123

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

bitcoin/messages.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (C) 2012-2014 The python-bitcoinlib developers
1+
# Copyright (C) 2012-2015 The python-bitcoinlib developers
22
#
33
# This file is part of python-bitcoinlib.
44
#
@@ -33,7 +33,7 @@
3333
from bitcoin.core import *
3434
from bitcoin.core.serialize import *
3535
from bitcoin.net import *
36-
from bitcoin import MainParams
36+
import bitcoin
3737

3838
MSG_TX = 1
3939
MSG_BLOCK = 2
@@ -51,11 +51,11 @@ def msg_ser(self, f):
5151
def msg_deser(cls, f, protover=PROTO_VERSION):
5252
raise NotImplementedError
5353

54-
def to_bytes(self, params=MainParams()):
54+
def to_bytes(self):
5555
f = _BytesIO()
5656
self.msg_ser(f)
5757
body = f.getvalue()
58-
res = params.MESSAGE_START
58+
res = bitcoin.params.MESSAGE_START
5959
res += self.command
6060
res += b"\x00" * (12 - len(self.command))
6161
res += struct.pack(b"<I", len(body))
@@ -74,13 +74,13 @@ def from_bytes(cls, b, protover=PROTO_VERSION):
7474
return MsgSerializable.stream_deserialize(f, protover=protover)
7575

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

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

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

0 commit comments

Comments
 (0)