-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcomet.go
62 lines (50 loc) · 1.54 KB
/
comet.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
package gosm
import (
"context"
"fmt"
core_types "github.com/cometbft/cometbft/rpc/core/types"
comet_types "github.com/cometbft/cometbft/types"
)
func (c *RPCClient) CometLegacyEncoding() bool {
return c.cometLegacyEncoding
}
func (c *RPCClient) Block(ctx context.Context, height *int64) (*core_types.ResultBlock, error) {
if c.chainID == "pacific-1" {
return c.blockSei(ctx, height)
}
return c.rpcConn.Block(ctx, height)
}
func (c *RPCClient) blockSei(ctx context.Context, height *int64) (*core_types.ResultBlock, error) {
result := new(SeiResultBlock)
params := make(map[string]interface{})
params["height"] = height
_, err := c.rpcCaller.Call(ctx, "block", params, result)
if err != nil {
fmt.Println(result.BlockID)
return nil, err
}
return &core_types.ResultBlock{
BlockID: comet_types.BlockID{
Hash: result.BlockID.Hash,
PartSetHeader: result.BlockID.PartSetHeader,
},
Block: &comet_types.Block{
Header: result.Block.Header,
Data: result.Block.Data,
LastCommit: result.Block.LastCommit,
},
}, nil
}
type SeiResultBlock struct {
BlockID *comet_types.BlockID `json:"block_id"`
Block *SeiBlock `json:"block"`
}
type SeiBlock struct {
Header comet_types.Header `json:"header"`
Data comet_types.Data `json:"data"`
// Evidence comet_types.EvidenceData `json:"evidence"`
LastCommit *comet_types.Commit `json:"last_commit"`
}
func (c *RPCClient) BlockResults(ctx context.Context, height *int64) (*core_types.ResultBlockResults, error) {
return c.rpcConn.BlockResults(ctx, height)
}