コード例 #1
0
 def validate_merkle_root(self):
     # reverse each item in self.tx_hashes
     hashes = [tx.hash()[::-1] for tx in self.txs]
     # compute the Merkle Root and reverse
     root = merkle_root(hashes)[::-1]
     # return whether self.merkle_root is the same
     return root == self.merkle_root
コード例 #2
0
 def validate_merkle_root(self):
     # We have to reverse each tx hash to be able to validate it first.
     hashes = [h[::-1] for h in self.tx_hashes]
     # We calculate the merkle root using the transaction hashes.
     # We need to reverse the result.
     calculated_merkle = merkle_root(hashes)[::-1]
     # Return the result of the comparison.
     return self.merkle_root == calculated_merkle
コード例 #3
0
 def validate_merkle_root(self):
     '''Gets the merkle root of the tx_hashes and checks that it's
     the same as the merkle root of this block.
     '''
     # reverse each item in self.tx_hashes
     hashes = [h[::-1] for h in self.tx_hashes]
     # compute the Merkle Root and reverse
     root = merkle_root(hashes)[::-1]
     # return whether self.merkle_root is the same
     return root == self.merkle_root
コード例 #4
0
 def validate_merkle_root(self):
     '''Gets the merkle root of the tx_hashes and checks that it's
     the same as the merkle root of this block.
     '''
     # reverse all the transaction hashes
     current_level = [x[::-1] for x in self.tx_hashes]
     # get the Merkle Root
     root = merkle_root(current_level)
     # check that this block's merkle root is the same as reverse of root
     return root[::-1] == self.merkle_root
コード例 #5
0
ファイル: block.py プロジェクト: TKChattoraj/btc_app
 def validate_merkle_root(self):
     '''Gets the merkle root of the tx_hashes and checks that it's
     the same as the merkle root of this block.
     '''
     tx_hashes_little_endian = [hash[::-1] for hash in self.tx_hashes]
     calculated_merkle_root = merkle_root(tx_hashes_little_endian)[::-1]
     if calculated_merkle_root == self.merkle_root:
         return True
     else:
         return False
コード例 #6
0
 def validate_merkle_root(self):
     '''Gets the merkle root of the tx_hashes and checks that it's
     the same as the merkle root of this block.
     '''
     tx_hashes = [tx[::-1] for tx in self.tx_hashes]
     root = merkle_root(tx_hashes)[::-1]
     return root == self.merkle_root
     # reverse each item in self.tx_hashes
     # compute the Merkle Root and reverse
     # return whether self.merkle_root is the same
     raise NotImplementedError
コード例 #7
0
 def validate_merkle_root(self):
     '''Gets the merkle root of the tx_hashes and checks that it's
     the same as the merkle root of this block.
     '''
     # reverse all the transaction hashes (self.tx_hashes)
     hashes = [h[::-1] for h in self.tx_hashes]
     # get the Merkle Root
     root = merkle_root(hashes)
     # reverse the Merkle Root
     # return whether self.merkle root is the same as
     # the reverse of the calculated merkle root
     return root[::-1] == self.merkle_root
コード例 #8
0
 def test_example_9(self):
     tx_hex_hashes = [
         '42f6f52f17620653dcc909e58bb352e0bd4bd1381e2955d19c00959a22122b2e',
         '94c3af34b9667bf787e1c6a0a009201589755d01d02fe2877cc69b929d2418d4',
         '959428d7c48113cb9149d0566bde3d46e98cf028053c522b8fa8f735241aa953',
         'a9f27b99d5d108dede755710d4a1ffa2c74af70b4ca71726fa57d68454e609a2',
         '62af110031e29de1efcad103b3ad4bec7bdcf6cb9c9f4afdd586981795516577',
         '766900590ece194667e9da2984018057512887110bf54fe0aa800157aec796ba',
         'e8270fb475763bc8d855cfe45ed98060988c1bdcad2ffc8364f783c98999a208',
     ]
     tx_hashes = [bytes.fromhex(x) for x in tx_hex_hashes]
     hashes = [h[::-1] for h in tx_hashes]
     self.assertEqual(
         merkle_root(hashes)[::-1].hex(),
         '654d6181e18e4ac4368383fdc5eead11bf138f9b7ac1e15334e4411b3c4797d9')
コード例 #9
0
 def test_exercise_9(self):
     want = '4297fb95a0168b959d1469410c7527da5d6243d99699e7d041b7f3916ba93301'
     tx_hex_hashes = [
         '42f6f52f17620653dcc909e58bb352e0bd4bd1381e2955d19c00959a22122b2e',
         '94c3af34b9667bf787e1c6a0a009201589755d01d02fe2877cc69b929d2418d4',
         '959428d7c48113cb9149d0566bde3d46e98cf028053c522b8fa8f735241aa953',
         'a9f27b99d5d108dede755710d4a1ffa2c74af70b4ca71726fa57d68454e609a2',
         '62af110031e29de1efcad103b3ad4bec7bdcf6cb9c9f4afdd586981795516577',
         '766900590ece194667e9da2984018057512887110bf54fe0aa800157aec796ba',
         'e8270fb475763bc8d855cfe45ed98060988c1bdcad2ffc8364f783c98999a208',
         '921b8cfd3e14bf41f028f0a3aa88c813d5039a2b1bceb12208535b0b43a5d09e',
         '15535864799652347cec66cba473f6d8291541238e58b2e03b046bc53cfe1321',
         '1c8af7c502971e67096456eac9cd5407aacf62190fc54188995666a30faf99f0',
         '3311f8acc57e8a3e9b68e2945fb4f53c07b0fa4668a7e5cda6255c21558c774d',
     ]
     tx_hashes = [bytes.fromhex(x) for x in tx_hex_hashes]
     hashes = [h[::-1] for h in tx_hashes]
     self.assertEqual(merkle_root(hashes)[::-1].hex(), want)
コード例 #10
0
 def test_merkle_root(self):
     hex_hashes = [
         'c117ea8ec828342f4dfb0ad6bd140e03a50720ece40169ee38bdc15d9eb64cf5',
         'c131474164b412e3406696da1ee20ab0fc9bf41c8f05fa8ceea7a08d672d7cc5',
         'f391da6ecfeed1814efae39e7fcb3838ae0b02c02ae7d0a5848a66947c0727b0',
         '3d238a92a94532b946c90e19c49351c763696cff3db400485b813aecb8a13181',
         '10092f2633be5f3ce349bf9ddbde36caa3dd10dfa0ec8106bce23acbff637dae',
         '7d37b3d54fa6a64869084bfd2e831309118b9e833610e6228adacdbd1b4ba161',
         '8118a77e542892fe15ae3fc771a4abfd2f5d5d5997544c3487ac36b5c85170fc',
         'dff6879848c2c9b62fe652720b8df5272093acfaa45a43cdb3696fe2466a3877',
         'b825c0745f46ac58f7d3759e6dc535a1fec7820377f24d4c2c6ad2cc55c0cb59',
         '95513952a04bd8992721e9b7e2937f1c04ba31e0469fbe615a78197f68f52b7c',
         '2e6d722e5e4dbdf2447ddecc9f7dabb8e299bae921c99ad5b0184cd9eb8e5908',
         'b13a750047bc0bdceb2473e5fe488c2596d7a7124b4e716fdd29b046ef99bbf0',
     ]
     tx_hashes = [unhexlify(x) for x in hex_hashes]
     want_hex_hash = 'acbcab8bcc1af95d8d563b77d24c3d19b18f1486383d75a5085c4e86c86beed6'
     want_hash = unhexlify(want_hex_hash)
     self.assertEqual(merkle_root(tx_hashes), want_hash)