forked from BytomDAO/bytom
/
infrastructure.go
38 lines (32 loc) · 1.03 KB
/
infrastructure.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
package contract
import (
"github.com/hyper-fi/bytom/protocol/bc"
"github.com/hyper-fi/bytom/protocol/bc/types"
)
type Infrastructure struct {
Chain ChainService
Repository Repository
}
func NewInfrastructure(chain ChainService, repository Repository) *Infrastructure {
return &Infrastructure{Chain: chain, Repository: repository}
}
type ChainService interface {
BestChain() (uint64, bc.Hash)
FinalizedHeight() uint64
GetBlockByHash(*bc.Hash) (*types.Block, error)
GetBlockByHeight(uint64) (*types.Block, error)
BlockWaiter(height uint64) <-chan struct{}
}
type ChainStatus struct {
BlockHeight uint64 `json:"block_height"`
BlockHash bc.Hash `json:"block_hash"`
}
type Repository interface {
GetInstance(traceID string) (*Instance, error)
LoadInstances() ([]*Instance, error)
SaveInstances(instances []*Instance) error
SaveInstancesWithStatus(instances []*Instance, blockHeight uint64, blockHash bc.Hash) error
RemoveInstance(traceID string)
GetChainStatus() *ChainStatus
SaveChainStatus(status *ChainStatus) error
}