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.

48 lines
939 B

  1. package main
  2. import (
  3. "context"
  4. "encoding/binary"
  5. "time"
  6. //"encoding/hex"
  7. "fmt"
  8. rpcclient "github.com/tendermint/tendermint/rpc/lib/client"
  9. cmn "github.com/tendermint/tmlibs/common"
  10. )
  11. func main() {
  12. wsc := rpcclient.NewWSClient("127.0.0.1:46657", "/websocket")
  13. _, err := wsc.Start()
  14. if err != nil {
  15. cmn.Exit(err.Error())
  16. }
  17. defer wsc.Stop()
  18. // Read a bunch of responses
  19. go func() {
  20. for {
  21. _, ok := <-wsc.ResultsCh
  22. if !ok {
  23. break
  24. }
  25. //fmt.Println("Received response", string(wire.JSONBytes(res)))
  26. }
  27. }()
  28. // Make a bunch of requests
  29. buf := make([]byte, 32)
  30. for i := 0; ; i++ {
  31. binary.BigEndian.PutUint64(buf, uint64(i))
  32. //txBytes := hex.EncodeToString(buf[:n])
  33. fmt.Print(".")
  34. err = wsc.Call(context.TODO(), "broadcast_tx", map[string]interface{}{"tx": buf[:8]})
  35. if err != nil {
  36. cmn.Exit(err.Error())
  37. }
  38. if i%1000 == 0 {
  39. fmt.Println(i)
  40. }
  41. time.Sleep(time.Microsecond * 1000)
  42. }
  43. }