Exemple #1
0
 def sign_block(block, private):
     block_hash = block.get_hash()
     signature = Private.sign(block_hash, private)
     signed_block = SignedBlock()
     signed_block.set_block(block)
     signed_block.set_signature(signature)
     return signed_block
Exemple #2
0
    def sign_block(self, private):  #TODO move somewhere more approptiate
        block = Block()
        block.prev_hashes = [*self.get_top_blocks()]
        block.timestamp = int(datetime.datetime.now().timestamp())
        block.randoms = []

        block_hash = block.get_hash().digest()
        signature = private.sign(block_hash, 0)[
            0]  #for some reason it returns tuple with second item being None
        signed_block = SignedBlock()
        signed_block.set_block(block)
        signed_block.set_signature(signature)
        current_block_number = self.get_current_timeframe_block_number()
        self.add_signed_block(current_block_number, signed_block)
        print(block_hash.hex(), " was added to blockchain under number ",
              current_block_number)
        return signed_block