github.com/okex/exchain@v1.8.0/libs/tendermint/rpc/core/ibc_adapter.go (about) 1 package core 2 3 import ( 4 ctypes "github.com/okex/exchain/libs/tendermint/rpc/core/types" 5 rpctypes "github.com/okex/exchain/libs/tendermint/rpc/jsonrpc/types" 6 "github.com/okex/exchain/libs/tendermint/types" 7 //coretypes "github.com/tendermint/tendermint/rpc/core/types" 8 ) 9 10 func CommitIBC(ctx *rpctypes.Context, heightPtr *int64) (*ctypes.IBCResultCommit, error) { 11 height, err := getHeight(env.BlockStore.Height(), heightPtr) 12 if err != nil { 13 return nil, err 14 } 15 16 blockMeta := env.BlockStore.LoadBlockMeta(height) 17 if blockMeta == nil { 18 return nil, nil 19 } 20 header := blockMeta.Header 21 22 // If the next block has not been committed yet, 23 // use a non-canonical commit 24 if height == env.BlockStore.Height() { 25 commit := env.BlockStore.LoadSeenCommit(height) 26 return ConvResultCommitTOIBC(ctypes.NewResultCommit(&header, commit, false)), nil 27 } 28 // Return the canonical commit (comes from the block at height+1) 29 commit := env.BlockStore.LoadBlockCommit(height) 30 return ConvResultCommitTOIBC(ctypes.NewResultCommit(&header, commit, true)), nil 31 } 32 33 func CM40Block(ctx *rpctypes.Context, heightPtr *int64) (*ctypes.CM40ResultBlock, error) { 34 height, err := getHeight(env.BlockStore.Height(), heightPtr) 35 if err != nil { 36 return nil, err 37 } 38 39 block := env.BlockStore.LoadBlock(height) 40 blockMeta := env.BlockStore.LoadBlockMeta(height) 41 42 if blockMeta == nil { 43 return &ctypes.CM40ResultBlock{BlockID: ConvBlockID2CM40BlockID(types.BlockID{}), Block: ConvBlock2CM40Block(block)}, nil 44 } 45 ret := &ctypes.CM40ResultBlock{BlockID: ConvBlockID2CM40BlockID(blockMeta.BlockID), Block: ConvBlock2CM40Block(block)} 46 return ret, nil 47 }