예제 #1
0
파일: block.py 프로젝트: CeON/pmpi
    def mine(self):
        unmined_raw = self.unmined_raw()
        assert 0 < self.difficulty < 256
        target = ((1 << 256 - self.difficulty) - 1).to_bytes(32, 'big')

        self.padding = 0

        while double_sha(unmined_raw) > target:
            self.padding += 1
            unmined_raw = unmined_raw[:-4] + self.padding.to_bytes(4, 'big')

        self.__checksum = double_sha(self.unmined_raw())
예제 #2
0
파일: test_block.py 프로젝트: CeON/pmpi
    def test_4_wrong_previous_block(self):
        self.blocks[0].previous_block_rev = BlockRev.from_id(double_sha(b'something'))
        self.blocks[0].mine()
        sign_object(self.public_key, self.private_key, self.blocks[0])

        with self.assertRaisesRegex(Block.ChainError, "previous_block_rev does not exist"):
            self.blocks[0].verify()
예제 #3
0
파일: abstract.py 프로젝트: CeON/pmpi
 def id(self):
     if self.requires_signature_verification or self.__id is None:
         self.__id = double_sha(self.raw())
     return self.__id
예제 #4
0
파일: test_block.py 프로젝트: CeON/pmpi
 def test_wrong_checksum(self):
     self.block._Block__checksum = double_sha(b'something')
     with self.assertRaisesRegex(Block.VerifyError, "wrong checksum"):
         self.block.unsigned_raw()
예제 #5
0
파일: block.py 프로젝트: CeON/pmpi
 def is_checksum_correct(self):
     """
     Check if checksum is correct.
     """
     return self.__checksum == double_sha(self.unmined_raw())