main.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. package main
  2. import (
  3. "database/sql"
  4. "encoding/json"
  5. "log"
  6. "math/big"
  7. "sync-block/collector"
  8. "sync-block/er"
  9. "sync-block/eth"
  10. "sync-block/util"
  11. "github.com/ybbus/jsonrpc/v2"
  12. )
  13. var db *sql.DB
  14. var rpc jsonrpc.RPCClient
  15. func main() {
  16. log.SetFlags(log.Lshortfile)
  17. //var err error
  18. db = util.ConnectDb("13.124.2.254", "weberp_db", "nb7X94raSds", "weberp_db")
  19. //
  20. rpc = jsonrpc.NewClient("http://3.38.62.211:8545")
  21. //log.Println(get("0x0fc6349b4733b01cc3194839eb57d3854ad01a8b473299fc6b564f4294604732"))
  22. eth, err := eth.New("http://3.38.62.211:8545", nil)
  23. er.Check(err)
  24. c := collector.New(db, eth, 1000)
  25. _ = c
  26. log.Println(c.Process(41, 42))
  27. return
  28. no, err := eth.GetLastBlockNumber()
  29. log.Println(no.Uint64())
  30. er.Check(err)
  31. log.Println(get("0x0fc6349b4733b01cc3194839eb57d3854ad01a8b473299fc6b564f4294604732"))
  32. v := new(big.Int)
  33. v, _ = v.SetString("1bc16d674ec800000", 16)
  34. log.Println(v.String())
  35. return
  36. }
  37. func get(tx string) error {
  38. args := make([]interface{}, 0)
  39. args = append(args, tx)
  40. args = append(args, map[string]interface {
  41. }{
  42. "tracer": "callTracer",
  43. "reexec": 712585 - 672922 + 20,
  44. })
  45. resp, _ := rpc.Call("debug_traceTransaction", args)
  46. data, _ := json.Marshal(resp.Result)
  47. log.Println(string(data))
  48. return resp.Error
  49. }