-
Notifications
You must be signed in to change notification settings - Fork 11
/
block.go
68 lines (55 loc) 路 3.2 KB
/
block.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
// SPDX-FileCopyrightText: 2024 PK Lab AG <contact@pklab.io>
// SPDX-License-Identifier: MIT
package storage
import (
"context"
"time"
pkgTypes "github.com/celenium-io/celestia-indexer/pkg/types"
"github.com/celenium-io/celestia-indexer/internal/storage/types"
"github.com/dipdup-net/indexer-sdk/pkg/storage"
"github.com/uptrace/bun"
)
//go:generate mockgen -source=$GOFILE -destination=mock/$GOFILE -package=mock -typed
type IBlock interface {
storage.Table[*Block]
Last(ctx context.Context) (Block, error)
ByIdWithRelations(ctx context.Context, id uint64) (Block, error)
ByHeight(ctx context.Context, height pkgTypes.Level) (Block, error)
ByHeightWithStats(ctx context.Context, height pkgTypes.Level) (Block, error)
ByHash(ctx context.Context, hash []byte) (Block, error)
ByProposer(ctx context.Context, proposerId uint64, limit, offset int) ([]Block, error)
ListWithStats(ctx context.Context, limit, offset uint64, order storage.SortOrder) ([]*Block, error)
Time(ctx context.Context, height pkgTypes.Level) (time.Time, error)
}
// Block -
type Block struct {
bun.BaseModel `bun:"table:block" comment:"Table with celestia blocks."`
Id uint64 `bun:",pk,notnull,autoincrement" comment:"Unique internal identity"`
Height pkgTypes.Level `bun:"height" comment:"The number (height) of this block" stats:"func:min max,filterable"`
Time time.Time `bun:"time,pk,notnull" comment:"The time of block" stats:"func:min max,filterable"`
VersionBlock uint64 `bun:"version_block" comment:"Block version"`
VersionApp uint64 `bun:"version_app" comment:"App version"`
MessageTypes types.MsgTypeBits `bun:"message_types,type:bit(74)" comment:"Bit mask with containing messages"`
Hash pkgTypes.Hex `bun:"hash" comment:"Block hash"`
ParentHash pkgTypes.Hex `bun:"parent_hash" comment:"Hash of parent block"`
LastCommitHash pkgTypes.Hex `bun:"last_commit_hash" comment:"Last commit hash"`
DataHash pkgTypes.Hex `bun:"data_hash" comment:"Data hash"`
ValidatorsHash pkgTypes.Hex `bun:"validators_hash" comment:"Validators hash"`
NextValidatorsHash pkgTypes.Hex `bun:"next_validators_hash" comment:"Next validators hash"`
ConsensusHash pkgTypes.Hex `bun:"consensus_hash" comment:"Consensus hash"`
AppHash pkgTypes.Hex `bun:"app_hash" comment:"App hash"`
LastResultsHash pkgTypes.Hex `bun:"last_results_hash" comment:"Last results hash"`
EvidenceHash pkgTypes.Hex `bun:"evidence_hash" comment:"Evidence hash"`
ProposerId uint64 `bun:"proposer_id,nullzero" comment:"Proposer internal id"`
ChainId string `bun:"-"` // internal field for filling state
ProposerAddress string `bun:"-"` // internal field for proposer
BlockSignatures []BlockSignature `bun:"-"` // internal field for block signature
Txs []Tx `bun:"rel:has-many"`
Events []Event `bun:"rel:has-many"`
Stats BlockStats `bun:"rel:has-one,join:height=height"`
Proposer Validator `bun:"rel:belongs-to"`
}
// TableName -
func (Block) TableName() string {
return "block"
}