Skip to content

Commit a0d1205

Browse files
committed
Merge pull request petertodd#38
9b00e4b Fixing bug where to_bytes clobbers testnet params. (Ethan Heilman) [ yapified by gitreformat (github/ghtdak) on Mon Nov 30 21:11:40 2015 ]
2 parents c5235b4 + 5e7ea80 commit a0d1205

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

bitcoin/messages.py

Lines changed: 9 additions & 8 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
@@ -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)