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

Cannot find Transaction hash #44

Closed cakcora closed 6 years ago

cakcora commented 6 years ago

Hi,

Thanks a lot for developing this library. I was going through blocks and transactions contained within them. When I tried to get hashes of transactions, I could not find them. By hash i mean the tx id: d77435177fe87b96d8e751221bfd1dfba9dc23e0cd521df59ed1725dba2c74f3 as in https://blockchain.info/tx/d77435177fe87b96d8e751221bfd1dfba9dc23e0cd521df59ed1725dba2c74f3

My code is stuck at this point:

val noOfTransactionPair = bitcoinBlocksRDD.map(e => {
      val txList = new ListBuffer[(String,Int,Int)]()
      val blk: BitcoinBlock = e._2
      val transactions: util.List[BitcoinTransaction] = blk.getTransactions
      for(x<-0 to transactions.size()-1){
        val transaction: BitcoinTransaction = transactions.get(x)
       **transaction.getTxHash** //this does not exist?
        txList+=((blk.getTime.toString, transaction.getListOfInputs.size, transaction.getListOfOutputs.size()))
      }

      txList
    }) 

Please let me know what i am missing.

jornfranke commented 6 years ago

Hi, thank you,

See information here: https://github.com/ZuInnoTe/hadoopcryptoledger/wiki/Useful-Utility-functions:

I hope it helps.

Best regards

cakcora commented 6 years ago

Thank you Jorn for your reply. This library will be very useful; we should write a tutorial about it. Here is the final code

val noOfTransactionPair = bitcoinBlocksRDD.map(e => {
      val txList = new ListBuffer[(String,String,Int,Int)]()
      val blk: BitcoinBlock = e._2

      val transactions: util.List[BitcoinTransaction] = blk.getTransactions
      for(x<-0 to transactions.size()-1){
        val transaction: BitcoinTransaction = transactions.get(x)
        val hash:String = BitcoinUtil.convertByteArrayToHexString(BitcoinUtil.reverseByteArray(BitcoinUtil.getTransactionHash(transaction)))
        txList+=((hash,blk.getTime.toString,transaction.getListOfInputs.size,transaction.getListOfOutputs.size()))
        println(hash)
      }

      txList.toList
    })