refactor: remove state API example

This commit is contained in:
Dirk McCormick 2020-06-25 12:46:43 -04:00
parent 95a9dc9db0
commit 728afc0587

View File

@ -1,57 +0,0 @@
package state
import (
"context"
"github.com/filecoin-project/lotus/chain/store"
"github.com/filecoin-project/specs-actors/actors/abi"
"github.com/filecoin-project/lotus/api"
"github.com/filecoin-project/lotus/chain/types"
)
type StateWatcher struct {
}
type WatcherAPI interface {
ChainNotify(context.Context) (<-chan []*api.HeadChange, error)
}
type UserData interface{}
type DiffFunc func(ctx context.Context, oldState, newState *types.TipSet) (changed bool, user UserData, err error)
type Callback func(ctx context.Context, oldState, newState *types.TipSet, events interface{})
type RevertHandler func(ctx context.Context, ts *types.TipSet) error
/*
w := NewWatcher(api, OnActorChange(t04, OnDealStateChange(123)), cb)
*/
func NewWatcher(ctx context.Context, api WatcherAPI, d DiffFunc, apply Callback, revert RevertHandler, confidence, timeout abi.ChainEpoch) {
go func() {
notifs, err := api.ChainNotify(ctx)
if err != nil {
// bad
return
}
curTs := (<-notifs)[0].Val
d(ctx, curTs, curTs)
for {
select {
case update := <-notifs:
for i, change := range update {
switch change.Type {
case store.HCApply:
d(ctx, curTs, change.Val)
case store.HCRevert:
}
}
}
}
}()
}