MCPcopy Create free account
hub / github.com/tendermint/tendermint / ExampleHTTP_batching

Function ExampleHTTP_batching

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

Source from the content-addressed store, hash-verified

77}
78
79func ExampleHTTP_batching() {
80 ctx, cancel := context.WithCancel(context.Background())
81 defer cancel()
82
83 // Start a tendermint node (and kvstore) in the background to test against
84 app := kvstore.NewApplication()
85 conf, err := rpctest.CreateConfig("ExampleHTTP_batching")
86 if err != nil {
87 log.Fatal(err)
88 }
89
90 _, closer, err := rpctest.StartTendermint(ctx, conf, app, rpctest.SuppressStdout)
91 if err != nil {
92 log.Fatal(err)
93 }
94 defer func() { _ = closer(ctx) }()
95
96 rpcAddr := conf.RPC.ListenAddress
97 c, err := rpchttp.New(rpcAddr)
98 if err != nil {
99 log.Fatal(err)
100 }
101
102 // Create our two transactions
103 k1 := []byte("firstName")
104 v1 := []byte("satoshi")
105 tx1 := append(k1, append([]byte("="), v1...)...)
106
107 k2 := []byte("lastName")
108 v2 := []byte("nakamoto")
109 tx2 := append(k2, append([]byte("="), v2...)...)
110
111 txs := [][]byte{tx1, tx2}
112
113 // Create a new batch
114 batch := c.NewBatch()
115
116 // Queue up our transactions
117 for _, tx := range txs {
118 // Broadcast the transaction and wait for it to commit (rather use
119 // c.BroadcastTxSync though in production).
120 if _, err := batch.BroadcastTxCommit(context.Background(), tx); err != nil {
121 log.Fatal(err)
122 }
123 }
124
125 // Send the batch of 2 transactions
126 if _, err := batch.Send(context.Background()); err != nil {
127 log.Fatal(err)
128 }
129
130 // Now let's query for the original results as a batch
131 keys := [][]byte{k1, k2}
132 for _, key := range keys {
133 if _, err := batch.ABCIQuery(context.Background(), "/key", key); err != nil {
134 log.Fatal(err)
135 }
136 }

Callers

nothing calls this directly

Calls 6

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

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…