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