First pass at tracking balance
This commit is contained in:
parent
ae2ff20bd2
commit
ae78470b83
3 changed files with 86 additions and 1 deletions
31
indexer/balance_storage_handler.go
Normal file
31
indexer/balance_storage_handler.go
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
package indexer
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"github.com/coinbase/rosetta-sdk-go/parser"
|
||||||
|
"github.com/coinbase/rosetta-sdk-go/storage"
|
||||||
|
"github.com/coinbase/rosetta-sdk-go/types"
|
||||||
|
)
|
||||||
|
|
||||||
|
var _ storage.BalanceStorageHandler = (*BalanceStorageHandler)(nil)
|
||||||
|
|
||||||
|
type BalanceStorageHandler struct{}
|
||||||
|
|
||||||
|
// BlockAdded is called whenever a block is committed to BlockStorage.
|
||||||
|
func (h *BalanceStorageHandler) BlockAdded(
|
||||||
|
ctx context.Context,
|
||||||
|
block *types.Block,
|
||||||
|
changes []*parser.BalanceChange,
|
||||||
|
) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// BlockRemoved is called whenever a block is removed from BlockStorage.
|
||||||
|
func (h *BalanceStorageHandler) BlockRemoved(
|
||||||
|
ctx context.Context,
|
||||||
|
block *types.Block,
|
||||||
|
changes []*parser.BalanceChange,
|
||||||
|
) error {
|
||||||
|
return nil
|
||||||
|
}
|
47
indexer/balance_storage_helper.go
Normal file
47
indexer/balance_storage_helper.go
Normal file
|
@ -0,0 +1,47 @@
|
||||||
|
package indexer
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"github.com/coinbase/rosetta-sdk-go/asserter"
|
||||||
|
"github.com/coinbase/rosetta-sdk-go/parser"
|
||||||
|
"github.com/coinbase/rosetta-sdk-go/storage"
|
||||||
|
"github.com/coinbase/rosetta-sdk-go/types"
|
||||||
|
)
|
||||||
|
|
||||||
|
var _ storage.BalanceStorageHelper = (*BalanceStorageHelper)(nil)
|
||||||
|
|
||||||
|
type BalanceStorageHelper struct {
|
||||||
|
a *asserter.Asserter
|
||||||
|
}
|
||||||
|
|
||||||
|
// AccountBalance attempts to fetch the balance
|
||||||
|
// for a missing account in storage.
|
||||||
|
func (h *BalanceStorageHelper) AccountBalance(
|
||||||
|
ctx context.Context,
|
||||||
|
account *types.AccountIdentifier,
|
||||||
|
currency *types.Currency,
|
||||||
|
block *types.BlockIdentifier,
|
||||||
|
) (*types.Amount, error) {
|
||||||
|
return &types.Amount{
|
||||||
|
Value: "0",
|
||||||
|
Currency: currency,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Asserter returns a *asserter.Asserter.
|
||||||
|
func (h *BalanceStorageHelper) Asserter() *asserter.Asserter {
|
||||||
|
return h.a
|
||||||
|
}
|
||||||
|
|
||||||
|
// BalanceExemptions returns a list of *types.BalanceExemption.
|
||||||
|
func (h *BalanceStorageHelper) BalanceExemptions() []*types.BalanceExemption {
|
||||||
|
return []*types.BalanceExemption{}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExemptFunc returns a parser.ExemptOperation.
|
||||||
|
func (h *BalanceStorageHelper) ExemptFunc() parser.ExemptOperation {
|
||||||
|
return func(op *types.Operation) bool {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
|
@ -199,7 +199,14 @@ func Initialize(
|
||||||
|
|
||||||
coinStorage := storage.NewCoinStorage(localStore, i, asserter)
|
coinStorage := storage.NewCoinStorage(localStore, i, asserter)
|
||||||
i.coinStorage = coinStorage
|
i.coinStorage = coinStorage
|
||||||
i.workers = []storage.BlockWorker{coinStorage}
|
|
||||||
|
balanceStorage := storage.NewBalanceStorage(localStore)
|
||||||
|
balanceStorage.Initialize(
|
||||||
|
&BalanceStorageHelper{asserter},
|
||||||
|
&BalanceStorageHandler{},
|
||||||
|
)
|
||||||
|
|
||||||
|
i.workers = []storage.BlockWorker{coinStorage, balanceStorage}
|
||||||
|
|
||||||
return i, nil
|
return i, nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue