(self, locator, hash_stop, current_tip=None)
| 59 | # the headers -- perhaps we could keep a separate data structure |
| 60 | # to avoid this overhead. |
| 61 | def headers_for(self, locator, hash_stop, current_tip=None): |
| 62 | if current_tip is None: |
| 63 | current_tip = self.currentBlock |
| 64 | current_block_header = self.get_header(current_tip) |
| 65 | if current_block_header is None: |
| 66 | return None |
| 67 | |
| 68 | response = msg_headers() |
| 69 | headersList = [ current_block_header ] |
| 70 | maxheaders = 2000 |
| 71 | while (headersList[0].sha256 not in locator.vHave): |
| 72 | prevBlockHash = headersList[0].hashPrevBlock |
| 73 | prevBlockHeader = self.get_header(prevBlockHash) |
| 74 | if prevBlockHeader is not None: |
| 75 | headersList.insert(0, prevBlockHeader) |
| 76 | else: |
| 77 | break |
| 78 | headersList = headersList[:maxheaders] # truncate if we have too many |
| 79 | hashList = [x.sha256 for x in headersList] |
| 80 | index = len(headersList) |
| 81 | if (hash_stop in hashList): |
| 82 | index = hashList.index(hash_stop)+1 |
| 83 | response.headers = headersList[:index] |
| 84 | return response |
| 85 | |
| 86 | def add_block(self, block): |
| 87 | block.calc_sha256() |
no test coverage detected