Break apart coin storage helper

This commit is contained in:
Patrick O'Grady 2020-10-27 10:02:28 -07:00
parent ae78470b83
commit 272db602e4
No known key found for this signature in database
GPG key ID: 8DE11C985C0C8D85
2 changed files with 28 additions and 11 deletions

View file

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

View file

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