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.

114 lines
2.9 KiB

  1. package main
  2. import (
  3. "fmt"
  4. "strconv"
  5. "github.com/btcsuite/btcd/chaincfg/chainhash"
  6. "github.com/btcsuite/btcrpcclient"
  7. )
  8. func explore(client *btcrpcclient.Client, blockHash string) {
  9. var realBlocks int
  10. var nOrigin NodeModel
  11. nOrigin.Id = "origin"
  12. nOrigin.Label = "origin"
  13. nOrigin.Title = "origin"
  14. nOrigin.Group = "origin"
  15. nOrigin.Value = 1
  16. nOrigin.Shape = "dot"
  17. saveNode(nodeCollection, nOrigin)
  18. for blockHash != "" {
  19. //generate hash from string
  20. bh, err := chainhash.NewHashFromStr(blockHash)
  21. check(err)
  22. block, err := client.GetBlockVerbose(bh)
  23. check(err)
  24. if block.Height > 160 {
  25. for k, txHash := range block.Tx {
  26. if k > 0 {
  27. realBlocks++
  28. fmt.Print("Block Height: ")
  29. fmt.Print(block.Height)
  30. fmt.Print(", num of Tx: ")
  31. fmt.Print(k)
  32. fmt.Print("/")
  33. fmt.Println(len(block.Tx) - 1)
  34. th, err := chainhash.NewHashFromStr(txHash)
  35. check(err)
  36. tx, err := client.GetRawTransactionVerbose(th)
  37. check(err)
  38. var originAddresses []string
  39. var outputAddresses []string
  40. for _, Vo := range tx.Vout {
  41. //if Vo.Value > 0 {
  42. for _, outputAddr := range Vo.ScriptPubKey.Addresses {
  43. outputAddresses = append(outputAddresses, outputAddr)
  44. var n2 NodeModel
  45. n2.Id = outputAddr
  46. n2.Label = outputAddr
  47. n2.Title = outputAddr
  48. n2.Group = strconv.FormatInt(block.Height, 10)
  49. n2.Value = 1
  50. n2.Shape = "dot"
  51. saveNode(nodeCollection, n2)
  52. }
  53. //}
  54. }
  55. for _, Vi := range tx.Vin {
  56. th, err := chainhash.NewHashFromStr(Vi.Txid)
  57. check(err)
  58. txVi, err := client.GetRawTransactionVerbose(th)
  59. check(err)
  60. if len(txVi.Vout[Vi.Vout].ScriptPubKey.Addresses) > 0 {
  61. for _, originAddr := range txVi.Vout[Vi.Vout].ScriptPubKey.Addresses {
  62. originAddresses = append(originAddresses, originAddr)
  63. var n1 NodeModel
  64. n1.Id = originAddr
  65. n1.Label = originAddr
  66. n1.Title = originAddr
  67. n1.Group = string(block.Height)
  68. n1.Value = 1
  69. n1.Shape = "dot"
  70. saveNode(nodeCollection, n1)
  71. for _, outputAddr := range outputAddresses {
  72. var e EdgeModel
  73. e.From = originAddr
  74. e.To = outputAddr
  75. e.Label = txVi.Vout[Vi.Vout].Value
  76. e.Txid = tx.Txid
  77. e.Arrows = "to"
  78. e.BlockHeight = block.Height
  79. saveEdge(edgeCollection, e)
  80. //date analysis
  81. //dateAnalysis(e, tx.Time)
  82. //hour analysis
  83. hourAnalysis(e, tx.Time)
  84. }
  85. }
  86. } else {
  87. originAddresses = append(originAddresses, "origin")
  88. }
  89. }
  90. fmt.Print("originAddresses: ")
  91. fmt.Println(len(originAddresses))
  92. fmt.Print("outputAddresses: ")
  93. fmt.Println(len(outputAddresses))
  94. }
  95. }
  96. }
  97. //set the next block
  98. blockHash = block.NextHash
  99. }
  100. fmt.Print("realBlocks (blocks with Fee and Amount values): ")
  101. fmt.Println(realBlocks)
  102. fmt.Println("reached the end of blockchain")
  103. }