# Path: qa/rpc-tests/test_framework/util.py
# def hex_str_to_bytes(hex_str):
#     return unhexlify(hex_str.encode('ascii'))
# 
# def bytes_to_hex_str(byte_str):
#     return hexlify(byte_str).decode('ascii')


import struct
import socket
import asyncore
import time
import sys
import random
import hashlib
import logging
import copy
import bridgecoin_scrypt
from .util import hex_str_to_bytes, bytes_to_hex_str
from io import BytesIO
from codecs import encode
from threading import RLock
from threading import Thread
from test_framework.siphash import siphash256
                    self.got_message(t)
                else:
                    self.show_debug_msg("Unknown command: '" + command + "' " +
                                        repr(msg))
        except Exception as e:
            print('got_data:', repr(e))
            # import  traceback
            # traceback.print_tb(sys.exc_info()[2])

    def send_message(self, message, pushbuf=False):
        if self.state != "connected" and not pushbuf:
            raise IOError('Not connected, no pushbuf')
        self.show_debug_msg("Send %s" % repr(message))
        command = message.command
        data = message.serialize()
        tmsg = self.MAGIC_BYTES[self.network]
        tmsg += command
        tmsg += b"\x00" * (12 - len(command))
        tmsg += struct.pack("<I", len(data))
        if self.ver_send >= 209:
            th = sha256(data)
            h = sha256(th)
            tmsg += h[:4]
        tmsg += data
        with mininode_lock:
            self.sendbuf += tmsg
            self.last_sent = time.time()

    def got_message(self, message):
        if message.command == b"version":

# Path: qa/rpc-tests/test_framework/util.py
# def hex_str_to_bytes(hex_str):
#     return unhexlify(hex_str.encode('ascii'))
# 
# def bytes_to_hex_str(byte_str):
#     return hexlify(byte_str).decode('ascii')


# Path: qa/rpc-tests/test_framework/mininode.py
import struct
import socket
import asyncore
import time
import sys
import random
import hashlib
import logging
import copy
import bridgecoin_scrypt
from .util import hex_str_to_bytes, bytes_to_hex_str
from io import BytesIO
from codecs import encode
from threading import RLock
from threading import Thread
from test_framework.siphash import siphash256

                    self.got_message(t)
                else:
                    self.show_debug_msg("Unknown command: '" + command + "' " +
                                        repr(msg))
        except Exception as e:
            print('got_data:', repr(e))
            # import  traceback
            # traceback.print_tb(sys.exc_info()[2])

    def send_message(self, message, pushbuf=False):
        if self.state != "connected" and not pushbuf:
            raise IOError('Not connected, no pushbuf')
        self.show_debug_msg("Send %s" % repr(message))
        command = message.command
        data = message.serialize()
        tmsg = self.MAGIC_BYTES[self.network]
        tmsg += command
        tmsg += b"\x00" * (12 - len(command))
        tmsg += struct.pack("<I", len(data))
        if self.ver_send >= 209:
            th = sha256(data)
            h = sha256(th)
            tmsg += h[:4]
        tmsg += data
        with mininode_lock:
            self.sendbuf += tmsg
            self.last_sent = time.time()

    def got_message(self, message):
        if message.command == b"version":

            if message.nVersion <= BIP0031_VERSION: