Skip to content

Commit

Permalink
Merge pull request petertodd#38
Browse files Browse the repository at this point in the history
9b00e4b Fixing bug where to_bytes clobbers testnet params. (Ethan Heilman)

 [ yapified by gitreformat (github/ghtdak) on Mon Nov 30 21:11:40 2015 ]
  • Loading branch information
petertodd committed Jan 1, 2015
2 parents c5235b4 + 5e7ea80 commit a0d1205
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions bitcoin/messages.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (C) 2012-2014 The python-bitcoinlib developers
# Copyright (C) 2012-2015 The python-bitcoinlib developers
#
# This file is part of python-bitcoinlib.
#
Expand Down 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 @@ -52,11 +52,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 @@ -75,13 +75,14 @@ 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:
raise ValueError("Invalid message start '%s', expected '%s'" %
(b2x(recvbuf[:4]), b2x(params.MESSAGE_START)))
if recvbuf[:4] != bitcoin.params.MESSAGE_START:
raise ValueError(
"Invalid message start '%s', expected '%s'" %
(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 a0d1205

Please sign in to comment.