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.

47 lines
920 B

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