MCPcopy Create free account
hub / github.com/DeAI-Artist/Linkis / ExampleHTTP_batching

Function ExampleHTTP_batching

rpc/client/examples_test.go:69–138  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

67}
68
69func ExampleHTTP_batching() {
70 // Start a tendermint node (and kvstore) in the background to test against
71 app := kvstore.NewApplication(cfg.GetDefaultDBDir())
72 node := rpctest.StartTendermint(app, rpctest.SuppressStdout, rpctest.RecreateConfig)
73
74 // Create our RPC client
75 rpcAddr := rpctest.GetConfig().RPC.ListenAddress
76 c, err := rpchttp.New(rpcAddr, "/websocket")
77 if err != nil {
78 log.Fatal(err)
79 }
80
81 defer rpctest.StopTendermint(node)
82
83 // Create our two transactions
84 k1 := []byte("firstName")
85 v1 := []byte("satoshi")
86 tx1 := append(k1, append([]byte("="), v1...)...)
87
88 k2 := []byte("lastName")
89 v2 := []byte("nakamoto")
90 tx2 := append(k2, append([]byte("="), v2...)...)
91
92 txs := [][]byte{tx1, tx2}
93
94 // Create a new batch
95 batch := c.NewBatch()
96
97 // Queue up our transactions
98 for _, tx := range txs {
99 // Broadcast the transaction and wait for it to commit (rather use
100 // c.BroadcastTxSync though in production).
101 if _, err := batch.BroadcastTxCommit(context.Background(), tx); err != nil {
102 log.Fatal(err) //nolint:gocritic
103 }
104 }
105
106 // Send the batch of 2 transactions
107 if _, err := batch.Send(context.Background()); err != nil {
108 log.Fatal(err)
109 }
110
111 // Now let's query for the original results as a batch
112 keys := [][]byte{k1, k2}
113 for _, key := range keys {
114 if _, err := batch.ABCIQuery(context.Background(), "/key", key); err != nil {
115 log.Fatal(err)
116 }
117 }
118
119 // Send the 2 queries and keep the results
120 results, err := batch.Send(context.Background())
121 if err != nil {
122 log.Fatal(err)
123 }
124
125 // Each result in the returned list is the deserialized result of each
126 // respective ABCIQuery response

Callers

nothing calls this directly

Calls 5

NewApplicationFunction · 0.92
NewBatchMethod · 0.80
BroadcastTxCommitMethod · 0.65
SendMethod · 0.65
ABCIQueryMethod · 0.65

Tested by

no test coverage detected