3333from bitcoin .core import *
3434from bitcoin .core .serialize import *
3535from bitcoin .net import *
36- import bitcoin
36+ from bitcoin import MainParams
3737
3838MSG_TX = 1
3939MSG_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 ):
54+ def to_bytes (self , params = MainParams () ):
5555 f = _BytesIO ()
5656 self .msg_ser (f )
5757 body = f .getvalue ()
58- res = bitcoin . params .MESSAGE_START
58+ res = 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 , protover = PROTO_VERSION ):
77+ def stream_deserialize (cls , f , params = MainParams (), protover = PROTO_VERSION ):
7878 recvbuf = ser_read (f , 4 + 12 + 4 + 4 )
7979
8080 # check magic
81- if recvbuf [:4 ] != bitcoin . params .MESSAGE_START :
81+ if recvbuf [:4 ] != params .MESSAGE_START :
8282 raise ValueError ("Invalid message start '%s', expected '%s'" %
83- (b2x (recvbuf [:4 ]), b2x (bitcoin . params .MESSAGE_START )))
83+ (b2x (recvbuf [:4 ]), b2x (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