From 46488d4356b93fc29ce0f52347504ab64fa96f13 Mon Sep 17 00:00:00 2001 From: vyzo Date: Sat, 11 Mar 2023 17:55:48 +0200 Subject: [PATCH] abstract ChainStore interface --- chain/index/msgindex.go | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/chain/index/msgindex.go b/chain/index/msgindex.go index c5bce4915..a48d6deef 100644 --- a/chain/index/msgindex.go +++ b/chain/index/msgindex.go @@ -18,8 +18,16 @@ import ( "github.com/filecoin-project/lotus/chain/types" ) +// chain store interface; we could use store.ChainStore directly, +// but this simplifies unit testing. +type ChainStore interface { + SubscribeHeadChanges(f store.ReorgNotifee) +} + +var _ ChainStore = (*store.ChainStore)(nil) + type msgIndex struct { - cs *store.ChainStore + cs ChainStore db *sql.DB } @@ -36,7 +44,7 @@ var ( coalesceMergeInterval = 100 * time.Millisecond ) -func NewMsgIndex(basePath string, cs *store.ChainStore) (MsgIndex, error) { +func NewMsgIndex(basePath string, cs ChainStore) (MsgIndex, error) { var ( mkdb bool dbPath string @@ -113,7 +121,7 @@ func createTables(db *sql.DB) error { return errors.New("TODO: index.createTables") } -func reconcileIndex(db *sql.DB, cs *store.ChainStore) error { +func reconcileIndex(db *sql.DB, cs ChainStore) error { // TODO return errors.New("TODO: index.reconcileIndex") }