def BN(self, data): # request for block (n) """Block(n) Sends the nth block from mainchain. :return: """ if int(data) <= self.factory.chain.m_blockheight(): logger.info( '<<<Sending block number %s %s bytes to node: %s', int(data), len( helper.json_bytestream( self.factory.chain.m_get_block(int(data)))), self.transport.getPeer().host) self.transport.write( self.wrap_message( 'BK', helper.json_bytestream_bk( self.factory.chain.m_get_block(int(data))))) else: if int(data) >= self.factory.chain.m_blockheight(): logger.info( 'BN for a blockheight greater than local chain length..') else: logger.info( 'BN request without valid block number %s - closing connection', str(data)) self.transport.loseConnection() return
def LB(self): # request for last block to be sent """ Last BLock Sends the last block from the main chain. :return: """ logger.info('<<<Sending last block %s %s bytes to node %s', self.factory.chain.m_blockheight(), str(len(helper.json_bytestream(self.factory.chain.m_get_last_block()))), self.transport.getPeer().host) self.transport.write(self.wrap_message('BK', helper.json_bytestream_bk(self.factory.chain.m_get_last_block()))) return
def send_block_to_peers(self, block): # logger.info('<<<Transmitting block: ', block.blockheader.headerhash) extra_data = { 'stake_selector': block.transactions[0].txto, 'blocknumber': block.blockheader.blocknumber, 'prev_headerhash': block.blockheader.prev_blockheaderhash } if block.blockheader.blocknumber > 1: extra_data['reveal_hash'] = block.blockheader.reveal_hash extra_data['vote_hash'] = block.blockheader.vote_hash self.register_and_broadcast('BK', block.blockheader.headerhash, json_bytestream_bk(block), extra_data) return
def send_block_to_peers(self, block, peer_identity=None): # logger.info(('<<<Transmitting block: ', block.blockheader.headerhash)) self.register_and_broadcast('BK', block.blockheader.headerhash, json_bytestream_bk(block)) return