Skip to content

Commit 5e7ea80

Browse files
author
Ethan Heilman
committed
Fixing bug where to_bytes clobbers testnet params.
[ yapified by gitreformat (github/ghtdak) on Mon Nov 30 21:11:38 2015 ]
1 parent c5235b4 commit 5e7ea80

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

bitcoin/messages.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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
@@ -52,11 +52,11 @@ def msg_ser(self, f):
5252
def msg_deser(cls, f, protover=PROTO_VERSION):
5353
raise NotImplementedError
5454

55-
def to_bytes(self, params=MainParams()):
55+
def to_bytes(self):
5656
f = _BytesIO()
5757
self.msg_ser(f)
5858
body = f.getvalue()
59-
res = params.MESSAGE_START
59+
res = bitcoin.params.MESSAGE_START
6060
res += self.command
6161
res += b"\x00" * (12 - len(self.command))
6262
res += struct.pack(b"<I", len(body))
@@ -75,13 +75,14 @@ def from_bytes(cls, b, protover=PROTO_VERSION):
7575
return MsgSerializable.stream_deserialize(f, protover=protover)
7676

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

8181
# check magic
82-
if recvbuf[:4] != params.MESSAGE_START:
83-
raise ValueError("Invalid message start '%s', expected '%s'" %
84-
(b2x(recvbuf[:4]), b2x(params.MESSAGE_START)))
82+
if recvbuf[:4] != bitcoin.params.MESSAGE_START:
83+
raise ValueError(
84+
"Invalid message start '%s', expected '%s'" %
85+
(b2x(recvbuf[:4]), b2x(bitcoin.params.MESSAGE_START)))
8586

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

0 commit comments

Comments
 (0)