def get_locator(self): """ Get a block locator object to give our remote peer when fetching headers/merkle blocks. """ locator = CBlockLocator() parent = self.get_block_id(self.get_height()) def rollback(parent, n): for i in range(n): parent = self._get_parent(parent) return parent step = -1 start = 0 height = self.get_height() while (True): if start >= 10: step *= 2 start = 0 locator.vHave.append(lx(parent)) parent = rollback(parent, abs(step)) start += 1 height += step if height <= self._get_starting_height() + abs(step): break return locator
class msg_getheaders(MsgSerializable): command = b"getheaders" def __init__(self, protover=PROTO_VERSION): super(msg_getheaders, self).__init__(protover) self.locator = CBlockLocator() self.hashstop = b'\x00'*32 @classmethod def msg_deser(cls, f, protover=PROTO_VERSION): c = cls() c.locator = CBlockLocator.stream_deserialize(f) c.hashstop = ser_read(f, 32) return c def msg_ser(self, f): self.locator.stream_serialize(f) f.write(self.hashstop) def __repr__(self): return "msg_getheaders(locator=%s hashstop=%s)" % (repr(self.locator), b2x(self.hashstop))
class msg_getheaders(MsgSerializable): command = b"getheaders" def __init__(self, protover=PROTO_VERSION): super(msg_getheaders, self).__init__(protover) self.locator = CBlockLocator() self.hashstop = b"\x00" * 32 @classmethod def msg_deser(cls, f, protover=PROTO_VERSION): c = cls() c.locator = CBlockLocator.stream_deserialize(f) c.hashstop = ser_read(f, 32) return c def msg_ser(self, f): self.locator.stream_serialize(f) f.write(self.hashstop) def __repr__(self): return "msg_getheaders(locator=%s hashstop=%s)" % (repr(self.locator), b2x(self.hashstop))
def send_getheaders(self, block_hash_string): locator = CBlockLocator() locator.vHave = [lx(block_hash_string)] msg = msg_getheaders() msg.locator = locator self.send_message(msg)
def msg_deser(cls, f, protover=PROTO_VERSION): c = cls() c.locator = CBlockLocator.stream_deserialize(f) c.hashstop = ser_read(f, 32) return c
def __init__(self, protover=PROTO_VERSION): super(msg_getheaders, self).__init__(protover) self.locator = CBlockLocator() self.hashstop = b'\x00'*32
def __init__(self, protover=PROTO_VERSION): super(msg_getheaders, self).__init__(protover) self.locator = CBlockLocator() self.hashstop = b"\x00" * 32