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

Refactor static methods getTransactionHash() and getTransactionHashSegwit() in BitcoinUtil as non-static methods of Transaction #80

Closed phelps-sg closed 3 years ago

phelps-sg commented 3 years ago

The methods getTransactionHash() and getTransactionHashSegwit() in BitcoinUtil are methods that operate on instances of Transaction and therefore should be non-static methods of Transaction in order to adhere to good principles of OO design, viz. encapsulation, whereby operations that work on specific data are bundled together with those data. As discussed in issue #71, Java methods do not incur a per-instance memory overhead. If compatibility is an issue, then BitcoinUtil can be refactored as:

public class BitcoinUtil {

  /**
    * @deprecated   Use transaction.getTransactionHash().
    */
  public static byte[] getTransactionHash(BitcoinTransaction transaction) {
    return transaction.getTransactionHash();
  }
}