-
Notifications
You must be signed in to change notification settings - Fork 51
/
blockchain.go
48 lines (38 loc) · 1.21 KB
/
blockchain.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
package keeper
import (
"time"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/hyperledger/burrow/execution/errors"
"github.com/shentufoundation/shentu/v2/x/cvm/types"
)
// Blockchain implements the blockchain interface from burrow to make state queries.
type Blockchain struct {
ctx sdk.Context
k Keeper
}
// NewBlockChain returns the pointer to a new BlockChain type data.
func NewBlockChain(ctx sdk.Context, k Keeper) Blockchain {
return Blockchain{
ctx: ctx,
k: k,
}
}
// LastBlockHeight returns the last block height of the chain.
func (bc Blockchain) LastBlockHeight() uint64 {
return uint64(bc.ctx.BlockHeight())
}
// LastBlockTime return the unix Time type for the last block.
func (bc Blockchain) LastBlockTime() time.Time {
return bc.ctx.BlockHeader().Time
}
// BlockHash returns the block's hash at the provided height.
func (bc Blockchain) BlockHash(height uint64) ([]byte, error) {
if height > uint64(bc.ctx.BlockHeight()) {
return nil, errors.Codes.InvalidBlockNumber
}
return bc.ctx.KVStore(bc.k.key).Get(types.BlockHashStoreKey(int64(height))), nil
}
// BlockHash returns the block's hash at the provided height.
func (bc Blockchain) ChainID() string {
return bc.ctx.ChainID()
}