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) -}