-
Notifications
You must be signed in to change notification settings - Fork 2
/
routes.go
656 lines (551 loc) · 19.8 KB
/
routes.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
package rpc_server
import (
"errors"
"fmt"
"sort"
"time"
"github.com/cometbft/cometbft/libs/bytes"
cmtmath "github.com/cometbft/cometbft/libs/math"
cmtquery "github.com/cometbft/cometbft/libs/pubsub/query"
"github.com/cometbft/cometbft/p2p"
abcitypes "github.com/cometbft/cometbft/abci/types"
ctypes "github.com/cometbft/cometbft/rpc/core/types"
rpc "github.com/cometbft/cometbft/rpc/jsonrpc/server"
rpctypes "github.com/cometbft/cometbft/rpc/jsonrpc/types"
"github.com/cometbft/cometbft/types"
"github.com/cometbft/cometbft/version"
"github.com/informalsystems/CometMock/cometmock/abci_client"
"github.com/informalsystems/CometMock/cometmock/utils"
)
const (
defaultPerPage = 30
maxPerPage = 100
)
var Routes = map[string]*rpc.RPCFunc{
// websocket
"subscribe": rpc.NewWSRPCFunc(Subscribe, "query"),
"unsubscribe": rpc.NewWSRPCFunc(Unsubscribe, "query"),
"unsubscribe_all": rpc.NewWSRPCFunc(UnsubscribeAll, ""),
// info API
"health": rpc.NewRPCFunc(Health, ""),
"status": rpc.NewRPCFunc(Status, ""),
"validators": rpc.NewRPCFunc(Validators, "height,page,per_page"),
"block": rpc.NewRPCFunc(Block, "height", rpc.Cacheable("height")),
"consensus_params": rpc.NewRPCFunc(ConsensusParams, "height", rpc.Cacheable("height")),
// "header": rpc.NewRPCFunc(Header, "height", rpc.Cacheable("height")), // not available in 0.34.x
"commit": rpc.NewRPCFunc(Commit, "height", rpc.Cacheable("height")),
"block_results": rpc.NewRPCFunc(BlockResults, "height", rpc.Cacheable("height")),
"tx": rpc.NewRPCFunc(Tx, "hash,prove", rpc.Cacheable()),
"tx_search": rpc.NewRPCFunc(TxSearch, "query,prove,page,per_page,order_by"),
"block_search": rpc.NewRPCFunc(BlockSearch, "query,page,per_page,order_by"),
// tx broadcast API
"broadcast_tx_commit": rpc.NewRPCFunc(BroadcastTxCommit, "tx"),
"broadcast_tx_sync": rpc.NewRPCFunc(BroadcastTxSync, "tx"),
"broadcast_tx_async": rpc.NewRPCFunc(BroadcastTxAsync, "tx"),
// abci API
"abci_query": rpc.NewRPCFunc(ABCIQuery, "path,data,height,prove"),
"abci_info": rpc.NewRPCFunc(ABCIInfo, ""),
// cometmock specific API
"advance_blocks": rpc.NewRPCFunc(AdvanceBlocks, "num_blocks"),
"set_signing_status": rpc.NewRPCFunc(SetSigningStatus, "private_key_address,status"),
"advance_time": rpc.NewRPCFunc(AdvanceTime, "duration_in_seconds"),
"cause_double_sign": rpc.NewRPCFunc(CauseDoubleSign, "private_key_address"),
"cause_light_client_attack": rpc.NewRPCFunc(CauseLightClientAttack, "private_key_address,misbehaviour_type"),
}
type ResultCauseLightClientAttack struct{}
func CauseLightClientAttack(ctx *rpctypes.Context, privateKeyAddress, misbehaviourType string) (*ResultCauseLightClientAttack, error) {
err := abci_client.GlobalClient.CauseLightClientAttack(privateKeyAddress, misbehaviourType)
return &ResultCauseLightClientAttack{}, err
}
type ResultCauseDoubleSign struct{}
func CauseDoubleSign(ctx *rpctypes.Context, privateKeyAddress string) (*ResultCauseDoubleSign, error) {
err := abci_client.GlobalClient.CauseDoubleSign(privateKeyAddress)
return &ResultCauseDoubleSign{}, err
}
type ResultAdvanceTime struct {
NewTime time.Time `json:"new_time"`
}
// AdvanceTime advances the block time by the given duration.
// This API is specific to CometMock.
func AdvanceTime(ctx *rpctypes.Context, duration_in_seconds time.Duration) (*ResultAdvanceTime, error) {
if duration_in_seconds < 0 {
return nil, errors.New("duration to advance time by must be greater than 0")
}
res := abci_client.GlobalClient.TimeHandler.AdvanceTime(duration_in_seconds * time.Second)
return &ResultAdvanceTime{res}, nil
}
type ResultSetSigningStatus struct {
NewSigningStatusMap map[string]bool `json:"new_signing_status_map"`
}
func SetSigningStatus(ctx *rpctypes.Context, privateKeyAddress string, status string) (*ResultSetSigningStatus, error) {
if status != "down" && status != "up" {
return nil, errors.New("status must be either `up` to have the validator sign, or `down` to have the validator not sign")
}
err := abci_client.GlobalClient.SetSigningStatus(privateKeyAddress, status == "up")
return &ResultSetSigningStatus{
NewSigningStatusMap: abci_client.GlobalClient.GetSigningStatusMap(),
}, err
}
type ResultAdvanceBlocks struct{}
// AdvanceBlocks advances the block height by numBlocks, running empty blocks.
// This API is specific to CometMock.
func AdvanceBlocks(ctx *rpctypes.Context, numBlocks int) (*ResultAdvanceBlocks, error) {
if numBlocks < 1 {
return nil, errors.New("num_blocks must be greater than 0")
}
err := abci_client.GlobalClient.RunEmptyBlocks(numBlocks)
if err != nil {
return nil, err
}
return &ResultAdvanceBlocks{}, nil
}
// BlockSearch searches for a paginated set of blocks matching BeginBlock and
// EndBlock event search criteria.
func BlockSearch(
ctx *rpctypes.Context,
query string,
pagePtr, perPagePtr *int,
orderBy string,
) (*ctypes.ResultBlockSearch, error) {
q, err := cmtquery.New(query)
if err != nil {
return nil, err
}
results, err := abci_client.GlobalClient.BlockIndex.Search(ctx.Context(), q)
if err != nil {
return nil, err
}
// sort results (must be done before pagination)
switch orderBy {
case "desc", "":
sort.Slice(results, func(i, j int) bool { return results[i] > results[j] })
case "asc":
sort.Slice(results, func(i, j int) bool { return results[i] < results[j] })
default:
return nil, errors.New("expected order_by to be either `asc` or `desc` or empty")
}
// paginate results
totalCount := len(results)
perPage := validatePerPage(perPagePtr)
page, err := validatePage(pagePtr, perPage, totalCount)
if err != nil {
return nil, err
}
skipCount := validateSkipCount(page, perPage)
pageSize := cmtmath.MinInt(perPage, totalCount-skipCount)
apiResults := make([]*ctypes.ResultBlock, 0, pageSize)
for i := skipCount; i < skipCount+pageSize; i++ {
block, err := abci_client.GlobalClient.Storage.GetBlock(results[i])
if err != nil {
return nil, err
}
if block != nil {
if err != nil {
return nil, err
}
blockId, err := utils.GetBlockIdFromBlock(block)
if err != nil {
return nil, err
}
apiResults = append(apiResults, &ctypes.ResultBlock{
Block: block,
BlockID: *blockId,
})
}
}
return &ctypes.ResultBlockSearch{Blocks: apiResults, TotalCount: totalCount}, nil
}
// Tx allows you to query the transaction results. `nil` could mean the
// transaction is in the mempool, invalidated, or was not sent in the first
// place.
// More: https://docs.tendermint.com/v0.34/rpc/#/Info/tx
func Tx(ctx *rpctypes.Context, hash []byte, prove bool) (*ctypes.ResultTx, error) {
txIndexer := abci_client.GlobalClient.TxIndex
r, err := txIndexer.Get(hash)
if err != nil {
return nil, err
}
if r == nil {
return nil, fmt.Errorf("tx (%X) not found", hash)
}
height := r.Height
index := r.Index
var proof types.TxProof
if prove {
block, err := abci_client.GlobalClient.Storage.GetBlock(height)
if err != nil {
return nil, err
}
proof = block.Data.Txs.Proof(int(index)) // XXX: overflow on 32-bit machines
}
return &ctypes.ResultTx{
Hash: hash,
Height: height,
Index: index,
TxResult: r.Result,
Tx: r.Tx,
Proof: proof,
}, nil
}
// TxSearch allows you to query for multiple transactions results. It returns a
// list of transactions (maximum ?per_page entries) and the total count.
// More: https://docs.tendermint.com/v0.34/rpc/#/Info/tx_search
func TxSearch(
ctx *rpctypes.Context,
query string,
prove bool,
pagePtr, perPagePtr *int,
orderBy string,
) (*ctypes.ResultTxSearch, error) {
if len(query) > maxQueryLength {
return nil, errors.New("maximum query length exceeded")
}
q, err := cmtquery.New(query)
if err != nil {
return nil, err
}
results, err := abci_client.GlobalClient.TxIndex.Search(ctx.Context(), q)
if err != nil {
return nil, err
}
// sort results (must be done before pagination)
switch orderBy {
case "desc":
sort.Slice(results, func(i, j int) bool {
if results[i].Height == results[j].Height {
return results[i].Index > results[j].Index
}
return results[i].Height > results[j].Height
})
case "asc", "":
sort.Slice(results, func(i, j int) bool {
if results[i].Height == results[j].Height {
return results[i].Index < results[j].Index
}
return results[i].Height < results[j].Height
})
default:
return nil, errors.New("expected order_by to be either `asc` or `desc` or empty")
}
// paginate results
totalCount := len(results)
perPage := validatePerPage(perPagePtr)
page, err := validatePage(pagePtr, perPage, totalCount)
if err != nil {
return nil, err
}
skipCount := validateSkipCount(page, perPage)
pageSize := cmtmath.MinInt(perPage, totalCount-skipCount)
apiResults := make([]*ctypes.ResultTx, 0, pageSize)
for i := skipCount; i < skipCount+pageSize; i++ {
r := results[i]
var proof types.TxProof
if prove {
block, err := abci_client.GlobalClient.Storage.GetBlock(r.Height)
if err != nil {
return nil, err
}
proof = block.Data.Txs.Proof(int(r.Index)) // XXX: overflow on 32-bit machines
}
apiResults = append(apiResults, &ctypes.ResultTx{
Hash: types.Tx(r.Tx).Hash(),
Height: r.Height,
Index: r.Index,
TxResult: r.Result,
Tx: r.Tx,
Proof: proof,
})
}
return &ctypes.ResultTxSearch{Txs: apiResults, TotalCount: totalCount}, nil
}
func getHeight(latestHeight int64, heightPtr *int64) (int64, error) {
if heightPtr != nil {
height := *heightPtr
if height <= 0 {
return 0, fmt.Errorf("height must be greater than 0, but got %d", height)
}
if height > latestHeight {
return 0, fmt.Errorf("height %d must be less than or equal to the current blockchain height %d",
height, latestHeight)
}
return height, nil
}
return latestHeight, nil
}
// // Header gets block header at a given height.
// // If no height is provided, it will fetch the latest header.
// // More: https://docs.cometbft.com/v0.37/rpc/#/Info/header
// func Header(ctx *rpctypes.Context, heightPtr *int64) (*ctypes.ResultHeader, error) {
// height, err := getHeight(abci_client.GlobalClient.LastBlock.Height, heightPtr)
// if err != nil {
// return nil, err
// }
// block, err := abci_client.GlobalClient.Storage.GetBlock(height)
// if err != nil {
// return nil, err
// }
// return &ctypes.ResultHeader{Header: &block.Header}, nil
// }
// Commit gets block commit at a given height.
// If no height is provided, it will fetch the commit for the latest block.
// More: https://docs.cometbft.com/main/rpc/#/Info/commit
func Commit(ctx *rpctypes.Context, heightPtr *int64) (*ctypes.ResultCommit, error) {
height, err := getHeight(abci_client.GlobalClient.LastBlock.Height, heightPtr)
if err != nil {
return nil, err
}
commit, err := abci_client.GlobalClient.Storage.GetCommit(height)
if err != nil {
return nil, err
}
block, err := abci_client.GlobalClient.Storage.GetBlock(height)
if err != nil {
return nil, err
}
return ctypes.NewResultCommit(&block.Header, commit, true), nil
}
// ConsensusParams gets the consensus parameters at the given block height.
// If no height is provided, it will fetch the latest consensus params.
// More: https://docs.cometbft.com/v0.37/rpc/#/Info/consensus_params
func ConsensusParams(ctx *rpctypes.Context, heightPtr *int64) (*ctypes.ResultConsensusParams, error) {
height, err := getHeight(abci_client.GlobalClient.LastBlock.Height, heightPtr)
if err != nil {
return nil, err
}
stateForHeight, err := abci_client.GlobalClient.Storage.GetState(height)
if err != nil {
return nil, err
}
consensusParams := stateForHeight.ConsensusParams
return &ctypes.ResultConsensusParams{
BlockHeight: height,
ConsensusParams: consensusParams,
}, nil
}
// Status returns CometBFT status including node info, pubkey, latest block
// hash, app hash, block height and time.
// More: https://docs.cometbft.com/v0.37/rpc/#/Info/status
func Status(ctx *rpctypes.Context) (*ctypes.ResultStatus, error) {
// return status as if we are the first validator
curState := abci_client.GlobalClient.CurState
validator := curState.Validators.Validators[0]
nodeInfo := p2p.DefaultNodeInfo{
DefaultNodeID: p2p.PubKeyToID(validator.PubKey),
Network: abci_client.GlobalClient.CurState.ChainID,
Other: p2p.DefaultNodeInfoOther{
TxIndex: "on",
},
Version: "0.38.0",
ProtocolVersion: p2p.NewProtocolVersion(
version.P2PProtocol, // global
curState.Version.Consensus.Block,
curState.Version.Consensus.App,
),
}
syncInfo := ctypes.SyncInfo{
LatestBlockHash: abci_client.GlobalClient.LastBlock.Hash(),
LatestAppHash: abci_client.GlobalClient.LastBlock.AppHash,
LatestBlockHeight: abci_client.GlobalClient.LastBlock.Height,
LatestBlockTime: abci_client.GlobalClient.CurState.LastBlockTime,
CatchingUp: false,
}
validatorInfo := ctypes.ValidatorInfo{
Address: validator.Address,
PubKey: validator.PubKey,
VotingPower: validator.VotingPower,
}
result := &ctypes.ResultStatus{
NodeInfo: nodeInfo,
SyncInfo: syncInfo,
ValidatorInfo: validatorInfo,
}
return result, nil
}
// Health gets node health. Returns empty result (200 OK) on success, no
// response - in case of an error.
func Health(ctx *rpctypes.Context) (*ctypes.ResultHealth, error) {
return &ctypes.ResultHealth{}, nil
}
// CURRENTLY UNSUPPORTED - THIS IS BECAUSE IT IS DISCOURAGED TO USE THIS BY COMETBFT
// needs some major changes to work with ABCI++
// BroadcastTxCommit broadcasts a transaction,
// and wait until it is included in a block and and comitted.
// In our case, this means running a block with just the the transition,
// then return.
func BroadcastTxCommit(ctx *rpctypes.Context, tx types.Tx) (*ctypes.ResultBroadcastTxCommit, error) {
return nil, errors.New("BroadcastTxCommit is currently not supported. Try BroadcastTxSync or BroadcastTxAsync instead")
}
// BroadcastTxSync would normally broadcast a transaction and wait until it gets the result from CheckTx.
// In our case, we run a block with just the transition in it,
// then return.
func BroadcastTxSync(ctx *rpctypes.Context, tx types.Tx) (*ctypes.ResultBroadcastTx, error) {
abci_client.GlobalClient.Logger.Info(
"BroadcastTxSync called", "tx", tx)
resBroadcastTx, err := BroadcastTx(&tx)
if err != nil {
return nil, err
}
return &ctypes.ResultBroadcastTx{
Code: resBroadcastTx.CheckTx.Code,
Data: resBroadcastTx.CheckTx.Data,
Log: resBroadcastTx.CheckTx.Log,
Hash: resBroadcastTx.Hash,
Codespace: resBroadcastTx.CheckTx.Codespace,
}, nil
}
// BroadcastTxAsync would normally broadcast a transaction and return immediately.
// In our case, we always include the transition in the next block, and return when that block is committed.
// ResultBroadcastTx is empty, since we do not return the result of CheckTx nor DeliverTx.
func BroadcastTxAsync(ctx *rpctypes.Context, tx types.Tx) (*ctypes.ResultBroadcastTx, error) {
abci_client.GlobalClient.Logger.Info(
"BroadcastTxAsync called", "tx", tx)
_, err := BroadcastTx(&tx)
if err != nil {
return nil, err
}
return &ctypes.ResultBroadcastTx{}, nil
}
func BroadcastTx(tx *types.Tx) (*ctypes.ResultBroadcastTxCommit, error) {
abci_client.GlobalClient.Logger.Info(
"BroadcastTxs called", "tx", tx)
txBytes := []byte(*tx)
checkTxResponse, err := abci_client.GlobalClient.SendCheckTx(abcitypes.CheckTxType_New, &txBytes)
if err != nil {
return nil, err
}
abci_client.GlobalClient.QueueTx(*tx)
if abci_client.GlobalClient.AutoIncludeTx {
go abci_client.GlobalClient.RunBlock()
}
return &ctypes.ResultBroadcastTxCommit{
CheckTx: *checkTxResponse,
Hash: tx.Hash(),
Height: abci_client.GlobalClient.CurState.LastBlockHeight,
}, err
}
func ABCIInfo(ctx *rpctypes.Context) (*ctypes.ResultABCIInfo, error) {
abci_client.GlobalClient.Logger.Info(
"ABCIInfo called")
response, err := abci_client.GlobalClient.SendAbciInfo()
return &ctypes.ResultABCIInfo{Response: *response}, err
}
func ABCIQuery(
ctx *rpctypes.Context,
path string,
data bytes.HexBytes,
height int64,
prove bool,
) (*ctypes.ResultABCIQuery, error) {
abci_client.GlobalClient.Logger.Info(
"ABCIQuery called", "path", "data", "height", "prove", path, data, height, prove)
response, err := abci_client.GlobalClient.SendAbciQuery(data, path, height, prove)
if err != nil {
return nil, err
}
abci_client.GlobalClient.Logger.Info(
"Response to ABCI query", response.String())
return &ctypes.ResultABCIQuery{Response: *response}, err
}
func Validators(ctx *rpctypes.Context, heightPtr *int64, pagePtr, perPagePtr *int) (*ctypes.ResultValidators, error) {
height, err := getHeight(abci_client.GlobalClient.LastBlock.Height, heightPtr)
if err != nil {
return nil, err
}
pastState, err := abci_client.GlobalClient.Storage.GetState(height)
if err != nil {
return nil, err
}
validators := pastState.Validators
totalCount := len(validators.Validators)
perPage := validatePerPage(perPagePtr)
page, err := validatePage(pagePtr, perPage, totalCount)
if err != nil {
return nil, err
}
skipCount := validateSkipCount(page, perPage)
v := validators.Validators[skipCount : skipCount+cmtmath.MinInt(perPage, totalCount-skipCount)]
return &ctypes.ResultValidators{
BlockHeight: height,
Validators: v,
Count: len(v),
Total: totalCount,
}, nil
}
// validatePage is adapted from https://github.com/cometbft/cometbft/blob/9267594e0a17c01cc4a97b399ada5eaa8a734db5/rpc/core/env.go#L107
func validatePage(pagePtr *int, perPage, totalCount int) (int, error) {
if perPage < 1 {
panic(fmt.Sprintf("zero or negative perPage: %d", perPage))
}
if pagePtr == nil { // no page parameter
return 1, nil
}
pages := ((totalCount - 1) / perPage) + 1
if pages == 0 {
pages = 1 // one page (even if it's empty)
}
page := *pagePtr
if page <= 0 || page > pages {
return 1, fmt.Errorf("page should be within [1, %d] range, given %d", pages, page)
}
return page, nil
}
// validatePerPage is adapted from https://github.com/cometbft/cometbft/blob/9267594e0a17c01cc4a97b399ada5eaa8a734db5/rpc/core/env.go#L128
func validatePerPage(perPagePtr *int) int {
if perPagePtr == nil { // no per_page parameter
return defaultPerPage
}
perPage := *perPagePtr
if perPage < 1 {
return defaultPerPage
} else if perPage > maxPerPage {
return maxPerPage
}
return perPage
}
// validateSkipCount is adapted from https://github.com/cometbft/cometbft/blob/9267594e0a17c01cc4a97b399ada5eaa8a734db5/rpc/core/env.go#L171
func validateSkipCount(page, perPage int) int {
skipCount := (page - 1) * perPage
if skipCount < 0 {
return 0
}
return skipCount
}
func Block(ctx *rpctypes.Context, heightPtr *int64) (*ctypes.ResultBlock, error) {
height, err := getHeight(abci_client.GlobalClient.LastBlock.Height, heightPtr)
if err != nil {
return nil, err
}
block, err := abci_client.GlobalClient.Storage.GetBlock(height)
if err != nil {
return nil, err
}
blockID, err := utils.GetBlockIdFromBlock(block)
if err != nil {
return nil, err
}
return &ctypes.ResultBlock{BlockID: *blockID, Block: block}, nil
}
// BlockResults gets ABCIResults at a given height.
// If no height is provided, it will fetch results for the latest block.
//
// Results are for the height of the block containing the txs.
// Thus response.results.deliver_tx[5] is the results of executing
// getBlock(h).Txs[5]
// More: https://docs.cometbft.com/v0.37/rpc/#/Info/block_results
func BlockResults(ctx *rpctypes.Context, heightPtr *int64) (*ctypes.ResultBlockResults, error) {
height, err := getHeight(abci_client.GlobalClient.LastBlock.Height, heightPtr)
if err != nil {
return nil, err
}
results, err := abci_client.GlobalClient.Storage.GetResponses(height)
if err != nil {
return nil, err
}
return &ctypes.ResultBlockResults{
Height: height,
TxsResults: results.TxResults,
FinalizeBlockEvents: results.Events,
ValidatorUpdates: results.ValidatorUpdates,
ConsensusParamUpdates: results.ConsensusParamUpdates,
}, nil
}