From 272db602e455c96bae9aa5f22b10faf71253a138 Mon Sep 17 00:00:00 2001 From: Patrick O'Grady Date: Tue, 27 Oct 2020 10:02:28 -0700 Subject: [PATCH] Break apart coin storage helper --- indexer/coin_storage_helper.go | 23 +++++++++++++++++++++++ indexer/indexer.go | 16 +++++----------- 2 files changed, 28 insertions(+), 11 deletions(-) create mode 100644 indexer/coin_storage_helper.go diff --git a/indexer/coin_storage_helper.go b/indexer/coin_storage_helper.go new file mode 100644 index 0000000..90f407e --- /dev/null +++ b/indexer/coin_storage_helper.go @@ -0,0 +1,23 @@ +package indexer + +import ( + "context" + + "github.com/coinbase/rosetta-sdk-go/storage" + "github.com/coinbase/rosetta-sdk-go/types" +) + +var _ storage.CoinStorageHelper = (*CoinStorageHelper)(nil) + +type CoinStorageHelper struct { + b *storage.BlockStorage +} + +// CurrentBlockIdentifier returns the current head block identifier +// and is used to comply with the CoinStorageHelper interface. +func (h *CoinStorageHelper) CurrentBlockIdentifier( + ctx context.Context, + transaction storage.DatabaseTransaction, +) (*types.BlockIdentifier, error) { + return h.b.GetHeadBlockIdentifierTransactional(ctx, transaction) +} diff --git a/indexer/indexer.go b/indexer/indexer.go index 3c7d04b..76fa0b1 100644 --- a/indexer/indexer.go +++ b/indexer/indexer.go @@ -74,7 +74,6 @@ type Client interface { var _ syncer.Handler = (*Indexer)(nil) var _ syncer.Helper = (*Indexer)(nil) var _ services.Indexer = (*Indexer)(nil) -var _ storage.CoinStorageHelper = (*Indexer)(nil) // Indexer caches blocks and provides balance query functionality. type Indexer struct { @@ -197,7 +196,11 @@ func Initialize( asserter: asserter, } - coinStorage := storage.NewCoinStorage(localStore, i, asserter) + coinStorage := storage.NewCoinStorage( + localStore, + &CoinStorageHelper{blockStorage}, + asserter, + ) i.coinStorage = coinStorage balanceStorage := storage.NewBalanceStorage(localStore) @@ -765,12 +768,3 @@ func (i *Indexer) GetCoins( ) ([]*types.Coin, *types.BlockIdentifier, error) { return i.coinStorage.GetCoins(ctx, accountIdentifier) } - -// CurrentBlockIdentifier returns the current head block identifier -// and is used to comply with the CoinStorageHelper interface. -func (i *Indexer) CurrentBlockIdentifier( - ctx context.Context, - transaction storage.DatabaseTransaction, -) (*types.BlockIdentifier, error) { - return i.blockStorage.GetHeadBlockIdentifierTransactional(ctx, transaction) -}