def deserialize_IPv4_addr_from_version(cls, f): # addr fields in the version message do NOT have a timestamp services = bitcoinx.read_le_uint64(f.read) reserved = f.read(12) IPv4 = socket.inet_ntoa(f.read(4)) port = bitcoinx.read_le_uint16(f.read) return {'services': services, 'IPv4': IPv4, 'port': port}
def deserialize_version(cls, f): version = bitcoinx.read_le_int32(f.read) services = bitcoinx.read_le_uint64(f.read) timestamp = time.ctime(bitcoinx.read_le_int64(f.read)) addr_recv = cls.deserialize_IPv4_addr_from_version(f) addr_from = cls.deserialize_IPv4_addr_from_version(f) nonce = bitcoinx.read_le_uint64(f.read) user_agent = bitcoinx.packing.read_varbytes(f.read) start_height = bitcoinx.read_le_int32(f.read) v = {'version': version, 'services': services, 'timestamp': timestamp, 'addr_recv': addr_recv, 'addr_from': addr_from, 'nonce': nonce, 'user_agent': user_agent, 'start_height': start_height} return v
def deserialize_addr(cls, f): count = bitcoinx.read_varint(f.read) addresses = [] for i in range(count): timestamp = time.ctime(bitcoinx.read_le_uint32(f.read)) services = bitcoinx.read_le_uint64(f.read) reserved = f.read(12) # IPv6 IPv4 = socket.inet_ntoa(f.read(4)) port = bitcoinx.read_le_uint16(f.read) addresses.append({'timestamp': timestamp, 'services': services, 'IPv4': IPv4, 'port': port}) return addresses # count not returned by choice
def deserialize_pong(cls, f): nonce = bitcoinx.read_le_uint64(f.read) return nonce