Break apart coin storage helper
This commit is contained in:
parent
ae78470b83
commit
272db602e4
2 changed files with 28 additions and 11 deletions
23
indexer/coin_storage_helper.go
Normal file
23
indexer/coin_storage_helper.go
Normal 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)
|
||||||
|
}
|
|
@ -74,7 +74,6 @@ type Client interface {
|
||||||
var _ syncer.Handler = (*Indexer)(nil)
|
var _ syncer.Handler = (*Indexer)(nil)
|
||||||
var _ syncer.Helper = (*Indexer)(nil)
|
var _ syncer.Helper = (*Indexer)(nil)
|
||||||
var _ services.Indexer = (*Indexer)(nil)
|
var _ services.Indexer = (*Indexer)(nil)
|
||||||
var _ storage.CoinStorageHelper = (*Indexer)(nil)
|
|
||||||
|
|
||||||
// Indexer caches blocks and provides balance query functionality.
|
// Indexer caches blocks and provides balance query functionality.
|
||||||
type Indexer struct {
|
type Indexer struct {
|
||||||
|
@ -197,7 +196,11 @@ func Initialize(
|
||||||
asserter: asserter,
|
asserter: asserter,
|
||||||
}
|
}
|
||||||
|
|
||||||
coinStorage := storage.NewCoinStorage(localStore, i, asserter)
|
coinStorage := storage.NewCoinStorage(
|
||||||
|
localStore,
|
||||||
|
&CoinStorageHelper{blockStorage},
|
||||||
|
asserter,
|
||||||
|
)
|
||||||
i.coinStorage = coinStorage
|
i.coinStorage = coinStorage
|
||||||
|
|
||||||
balanceStorage := storage.NewBalanceStorage(localStore)
|
balanceStorage := storage.NewBalanceStorage(localStore)
|
||||||
|
@ -765,12 +768,3 @@ func (i *Indexer) GetCoins(
|
||||||
) ([]*types.Coin, *types.BlockIdentifier, error) {
|
) ([]*types.Coin, *types.BlockIdentifier, error) {
|
||||||
return i.coinStorage.GetCoins(ctx, accountIdentifier)
|
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)
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in a new issue