ZuInnoTe / hadoopcryptoledger

Hadoop Crypto Ledger - Analyzing CryptoLedgers, such as Bitcoin Blockchain, on Big Data platforms, such as Hadoop/Spark/Flink/Hive
Apache License 2.0
141 stars 51 forks source link

Add methods to calculate block hash, merkle root. #71

Closed phelps-sg closed 3 years ago

phelps-sg commented 3 years ago

The class org.zuinnote.hadoop.bitcoin.format.common.Block does not have methods to calculate the block hash. Calculating the block hash also requires calculation of the Merkle root, which is also not implemented. Without this functionality it is not possible to determine the height of a block.

jornfranke commented 3 years ago

This class is just a POJO. BitcoinUtil contains methods to calculate hashes and there would be the right place. Hence, I suggest to add them to the class BitcoinUtil

This makes the class more lightweight for analytics in Big Data platform. For example, if you have one million blocks you want to avoid that they contain the function for calculating the hash 1 million times. It reduces the memory footprint significantly.

phelps-sg commented 3 years ago
jornfranke commented 3 years ago

I propose for compatibility reasons we can start as I suggested - as this is already now the case for other methods calculating hashes. One can later see it if it is worth to do a breaking change and do it differently. Standard encapsulation principles are not violated by neither of the approaches.

phelps-sg commented 3 years ago

Standard encapsulation principles are not violated by neither of the approaches.

This is simply not true. Encapsulation literally means bundling data with the operations that operate on that data. See the 'Bundling data and methods' section of https://www.infoworld.com/article/2075271/encapsulation-is-not-information-hiding.html.

jornfranke commented 3 years ago

Please do not work on any issues before it has been agreed and discussed. Otherwise we cannot accept pull requests.