github.com/bytom/bytom@v1.1.2-0.20221014091027-bbcba3df6075/contract/infrastructure.go (about) 1 package contract 2 3 import ( 4 "github.com/bytom/bytom/protocol/bc" 5 "github.com/bytom/bytom/protocol/bc/types" 6 ) 7 8 type Infrastructure struct { 9 Chain ChainService 10 Repository Repository 11 } 12 13 func NewInfrastructure(chain ChainService, repository Repository) *Infrastructure { 14 return &Infrastructure{Chain: chain, Repository: repository} 15 } 16 17 type ChainService interface { 18 BestChain() (uint64, bc.Hash) 19 FinalizedHeight() uint64 20 GetBlockByHash(*bc.Hash) (*types.Block, error) 21 GetBlockByHeight(uint64) (*types.Block, error) 22 BlockWaiter(height uint64) <-chan struct{} 23 } 24 25 type ChainStatus struct { 26 BlockHeight uint64 `json:"block_height"` 27 BlockHash bc.Hash `json:"block_hash"` 28 } 29 30 type Repository interface { 31 GetInstance(traceID string) (*Instance, error) 32 LoadInstances() ([]*Instance, error) 33 SaveInstances(instances []*Instance) error 34 SaveInstancesWithStatus(instances []*Instance, blockHeight uint64, blockHash bc.Hash) error 35 RemoveInstance(traceID string) 36 GetChainStatus() *ChainStatus 37 SaveChainStatus(status *ChainStatus) error 38 }