You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

70 lines
1.6 KiB

  1. package main
  2. import (
  3. "fmt"
  4. "github.com/btcsuite/btcd/chaincfg/chainhash"
  5. "github.com/btcsuite/btcrpcclient"
  6. )
  7. func explore(client *btcrpcclient.Client, blockHash string) {
  8. for blockHash != "" {
  9. //generate hash from string
  10. bh, err := chainhash.NewHashFromStr(blockHash)
  11. check(err)
  12. fmt.Print("blockHash: ")
  13. fmt.Println(bh)
  14. block, err := client.GetBlockVerbose(bh)
  15. check(err)
  16. fmt.Print("height: ")
  17. fmt.Println(block.Height)
  18. fmt.Print("rawTx: ")
  19. fmt.Println(block.RawTx)
  20. fmt.Print("Tx: ")
  21. fmt.Println(block.Tx)
  22. fmt.Print("Time: ")
  23. fmt.Println(block.Time)
  24. fmt.Print("Confirmations: ")
  25. fmt.Println(block.Confirmations)
  26. fmt.Print("Fee: ")
  27. th, err := chainhash.NewHashFromStr(block.Tx[0])
  28. check(err)
  29. tx, err := client.GetRawTransactionVerbose(th)
  30. check(err)
  31. var totalFee float64
  32. for _, Vo := range tx.Vout {
  33. totalFee = totalFee + Vo.Value
  34. }
  35. fmt.Print("totalFee: ")
  36. fmt.Print(totalFee)
  37. fmt.Println(" FAIR")
  38. //for each Tx, get the Tx value
  39. var totalAmount float64
  40. for k, txHash := range block.Tx {
  41. //first Tx is the Fee
  42. //after first Tx is the Sent Amount
  43. if k > 0 {
  44. th, err := chainhash.NewHashFromStr(txHash)
  45. check(err)
  46. fmt.Print("tx hash: ")
  47. fmt.Println(th)
  48. tx, err := client.GetRawTransactionVerbose(th)
  49. check(err)
  50. for _, Vo := range tx.Vout {
  51. totalAmount = totalAmount + Vo.Value
  52. }
  53. fmt.Print("totalAmount: ")
  54. fmt.Print(totalAmount)
  55. fmt.Println(" FAIR")
  56. }
  57. }
  58. fmt.Println("-----")
  59. //set the next block
  60. blockHash = block.NextHash
  61. }
  62. fmt.Println("reached the end of blockchain")
  63. }