Move FilterID to types package
This commit is contained in:
parent
067f08f092
commit
1afc32f650
@ -417,7 +417,6 @@ type EthFeeHistory struct {
|
|||||||
Reward *[][]EthBigInt `json:"reward,omitempty"`
|
Reward *[][]EthBigInt `json:"reward,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// An opaque identifier generated by the Lotus node to refer to an installed filter.
|
|
||||||
type EthFilterID EthHash
|
type EthFilterID EthHash
|
||||||
|
|
||||||
// An opaque identifier generated by the Lotus node to refer to an active subscription.
|
// An opaque identifier generated by the Lotus node to refer to an active subscription.
|
||||||
|
@ -23,7 +23,7 @@ import (
|
|||||||
const indexed uint8 = 0x01
|
const indexed uint8 = 0x01
|
||||||
|
|
||||||
type EventFilter struct {
|
type EventFilter struct {
|
||||||
id FilterID
|
id types.FilterID
|
||||||
minHeight abi.ChainEpoch // minimum epoch to apply filter or -1 if no minimum
|
minHeight abi.ChainEpoch // minimum epoch to apply filter or -1 if no minimum
|
||||||
maxHeight abi.ChainEpoch // maximum epoch to apply filter or -1 if no maximum
|
maxHeight abi.ChainEpoch // maximum epoch to apply filter or -1 if no maximum
|
||||||
tipsetCid cid.Cid
|
tipsetCid cid.Cid
|
||||||
@ -50,7 +50,7 @@ type CollectedEvent struct {
|
|||||||
MsgCid cid.Cid // cid of message that produced event
|
MsgCid cid.Cid // cid of message that produced event
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *EventFilter) ID() FilterID {
|
func (f *EventFilter) ID() types.FilterID {
|
||||||
return f.id
|
return f.id
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -289,7 +289,7 @@ type EventFilterManager struct {
|
|||||||
EventIndex *EventIndex
|
EventIndex *EventIndex
|
||||||
|
|
||||||
mu sync.Mutex // guards mutations to filters
|
mu sync.Mutex // guards mutations to filters
|
||||||
filters map[FilterID]*EventFilter
|
filters map[types.FilterID]*EventFilter
|
||||||
currentHeight abi.ChainEpoch
|
currentHeight abi.ChainEpoch
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -388,7 +388,7 @@ func (m *EventFilterManager) Install(ctx context.Context, minHeight, maxHeight a
|
|||||||
|
|
||||||
m.mu.Lock()
|
m.mu.Lock()
|
||||||
if m.filters == nil {
|
if m.filters == nil {
|
||||||
m.filters = make(map[FilterID]*EventFilter)
|
m.filters = make(map[types.FilterID]*EventFilter)
|
||||||
}
|
}
|
||||||
m.filters[id] = f
|
m.filters[id] = f
|
||||||
m.mu.Unlock()
|
m.mu.Unlock()
|
||||||
@ -396,7 +396,7 @@ func (m *EventFilterManager) Install(ctx context.Context, minHeight, maxHeight a
|
|||||||
return f, nil
|
return f, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *EventFilterManager) Remove(ctx context.Context, id FilterID) error {
|
func (m *EventFilterManager) Remove(ctx context.Context, id types.FilterID) error {
|
||||||
m.mu.Lock()
|
m.mu.Lock()
|
||||||
defer m.mu.Unlock()
|
defer m.mu.Unlock()
|
||||||
if _, found := m.filters[id]; !found {
|
if _, found := m.filters[id]; !found {
|
||||||
|
@ -13,7 +13,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type MemPoolFilter struct {
|
type MemPoolFilter struct {
|
||||||
id FilterID
|
id types.FilterID
|
||||||
maxResults int // maximum number of results to collect, 0 is unlimited
|
maxResults int // maximum number of results to collect, 0 is unlimited
|
||||||
ch chan<- interface{}
|
ch chan<- interface{}
|
||||||
|
|
||||||
@ -24,7 +24,7 @@ type MemPoolFilter struct {
|
|||||||
|
|
||||||
var _ Filter = (*MemPoolFilter)(nil)
|
var _ Filter = (*MemPoolFilter)(nil)
|
||||||
|
|
||||||
func (f *MemPoolFilter) ID() FilterID {
|
func (f *MemPoolFilter) ID() types.FilterID {
|
||||||
return f.id
|
return f.id
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -78,7 +78,7 @@ type MemPoolFilterManager struct {
|
|||||||
MaxFilterResults int
|
MaxFilterResults int
|
||||||
|
|
||||||
mu sync.Mutex // guards mutations to filters
|
mu sync.Mutex // guards mutations to filters
|
||||||
filters map[FilterID]*MemPoolFilter
|
filters map[types.FilterID]*MemPoolFilter
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *MemPoolFilterManager) WaitForMpoolUpdates(ctx context.Context, ch <-chan api.MpoolUpdate) {
|
func (m *MemPoolFilterManager) WaitForMpoolUpdates(ctx context.Context, ch <-chan api.MpoolUpdate) {
|
||||||
@ -124,7 +124,7 @@ func (m *MemPoolFilterManager) Install(ctx context.Context) (*MemPoolFilter, err
|
|||||||
|
|
||||||
m.mu.Lock()
|
m.mu.Lock()
|
||||||
if m.filters == nil {
|
if m.filters == nil {
|
||||||
m.filters = make(map[FilterID]*MemPoolFilter)
|
m.filters = make(map[types.FilterID]*MemPoolFilter)
|
||||||
}
|
}
|
||||||
m.filters[id] = f
|
m.filters[id] = f
|
||||||
m.mu.Unlock()
|
m.mu.Unlock()
|
||||||
@ -132,7 +132,7 @@ func (m *MemPoolFilterManager) Install(ctx context.Context) (*MemPoolFilter, err
|
|||||||
return f, nil
|
return f, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *MemPoolFilterManager) Remove(ctx context.Context, id FilterID) error {
|
func (m *MemPoolFilterManager) Remove(ctx context.Context, id types.FilterID) error {
|
||||||
m.mu.Lock()
|
m.mu.Lock()
|
||||||
defer m.mu.Unlock()
|
defer m.mu.Unlock()
|
||||||
if _, found := m.filters[id]; !found {
|
if _, found := m.filters[id]; !found {
|
||||||
|
@ -8,10 +8,12 @@ import (
|
|||||||
|
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
"golang.org/x/xerrors"
|
"golang.org/x/xerrors"
|
||||||
|
|
||||||
|
"github.com/filecoin-project/lotus/chain/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Filter interface {
|
type Filter interface {
|
||||||
ID() FilterID
|
ID() types.FilterID
|
||||||
LastTaken() time.Time
|
LastTaken() time.Time
|
||||||
SetSubChannel(chan<- interface{})
|
SetSubChannel(chan<- interface{})
|
||||||
ClearSubChannel()
|
ClearSubChannel()
|
||||||
@ -19,8 +21,8 @@ type Filter interface {
|
|||||||
|
|
||||||
type FilterStore interface {
|
type FilterStore interface {
|
||||||
Add(context.Context, Filter) error
|
Add(context.Context, Filter) error
|
||||||
Get(context.Context, FilterID) (Filter, error)
|
Get(context.Context, types.FilterID) (Filter, error)
|
||||||
Remove(context.Context, FilterID) error
|
Remove(context.Context, types.FilterID) error
|
||||||
NotTakenSince(when time.Time) []Filter // returns a list of filters that have not had their collected results taken
|
NotTakenSince(when time.Time) []Filter // returns a list of filters that have not had their collected results taken
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -30,22 +32,20 @@ var (
|
|||||||
ErrMaximumNumberOfFilters = errors.New("maximum number of filters registered")
|
ErrMaximumNumberOfFilters = errors.New("maximum number of filters registered")
|
||||||
)
|
)
|
||||||
|
|
||||||
type FilterID [32]byte // compatible with EthHash
|
func newFilterID() (types.FilterID, error) {
|
||||||
|
|
||||||
func newFilterID() (FilterID, error) {
|
|
||||||
rawid, err := uuid.NewRandom()
|
rawid, err := uuid.NewRandom()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return FilterID{}, xerrors.Errorf("new uuid: %w", err)
|
return types.FilterID{}, xerrors.Errorf("new uuid: %w", err)
|
||||||
}
|
}
|
||||||
id := FilterID{}
|
id := types.FilterID{}
|
||||||
copy(id[:], rawid[:]) // uuid is 16 bytes
|
copy(id[:], rawid[:]) // uuid is 16 bytes, the last 16 bytes are zeroed
|
||||||
return id, nil
|
return id, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type memFilterStore struct {
|
type memFilterStore struct {
|
||||||
max int
|
max int
|
||||||
mu sync.Mutex
|
mu sync.Mutex
|
||||||
filters map[FilterID]Filter
|
filters map[types.FilterID]Filter
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ FilterStore = (*memFilterStore)(nil)
|
var _ FilterStore = (*memFilterStore)(nil)
|
||||||
@ -53,7 +53,7 @@ var _ FilterStore = (*memFilterStore)(nil)
|
|||||||
func NewMemFilterStore(maxFilters int) FilterStore {
|
func NewMemFilterStore(maxFilters int) FilterStore {
|
||||||
return &memFilterStore{
|
return &memFilterStore{
|
||||||
max: maxFilters,
|
max: maxFilters,
|
||||||
filters: make(map[FilterID]Filter),
|
filters: make(map[types.FilterID]Filter),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -72,7 +72,7 @@ func (m *memFilterStore) Add(_ context.Context, f Filter) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *memFilterStore) Get(_ context.Context, id FilterID) (Filter, error) {
|
func (m *memFilterStore) Get(_ context.Context, id types.FilterID) (Filter, error) {
|
||||||
m.mu.Lock()
|
m.mu.Lock()
|
||||||
f, found := m.filters[id]
|
f, found := m.filters[id]
|
||||||
m.mu.Unlock()
|
m.mu.Unlock()
|
||||||
@ -82,7 +82,7 @@ func (m *memFilterStore) Get(_ context.Context, id FilterID) (Filter, error) {
|
|||||||
return f, nil
|
return f, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *memFilterStore) Remove(_ context.Context, id FilterID) error {
|
func (m *memFilterStore) Remove(_ context.Context, id types.FilterID) error {
|
||||||
m.mu.Lock()
|
m.mu.Lock()
|
||||||
defer m.mu.Unlock()
|
defer m.mu.Unlock()
|
||||||
|
|
||||||
|
@ -11,7 +11,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type TipSetFilter struct {
|
type TipSetFilter struct {
|
||||||
id FilterID
|
id types.FilterID
|
||||||
maxResults int // maximum number of results to collect, 0 is unlimited
|
maxResults int // maximum number of results to collect, 0 is unlimited
|
||||||
ch chan<- interface{}
|
ch chan<- interface{}
|
||||||
|
|
||||||
@ -22,7 +22,7 @@ type TipSetFilter struct {
|
|||||||
|
|
||||||
var _ Filter = (*TipSetFilter)(nil)
|
var _ Filter = (*TipSetFilter)(nil)
|
||||||
|
|
||||||
func (f *TipSetFilter) ID() FilterID {
|
func (f *TipSetFilter) ID() types.FilterID {
|
||||||
return f.id
|
return f.id
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -76,7 +76,7 @@ type TipSetFilterManager struct {
|
|||||||
MaxFilterResults int
|
MaxFilterResults int
|
||||||
|
|
||||||
mu sync.Mutex // guards mutations to filters
|
mu sync.Mutex // guards mutations to filters
|
||||||
filters map[FilterID]*TipSetFilter
|
filters map[types.FilterID]*TipSetFilter
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *TipSetFilterManager) Apply(ctx context.Context, from, to *types.TipSet) error {
|
func (m *TipSetFilterManager) Apply(ctx context.Context, from, to *types.TipSet) error {
|
||||||
@ -111,7 +111,7 @@ func (m *TipSetFilterManager) Install(ctx context.Context) (*TipSetFilter, error
|
|||||||
|
|
||||||
m.mu.Lock()
|
m.mu.Lock()
|
||||||
if m.filters == nil {
|
if m.filters == nil {
|
||||||
m.filters = make(map[FilterID]*TipSetFilter)
|
m.filters = make(map[types.FilterID]*TipSetFilter)
|
||||||
}
|
}
|
||||||
m.filters[id] = f
|
m.filters[id] = f
|
||||||
m.mu.Unlock()
|
m.mu.Unlock()
|
||||||
@ -119,7 +119,7 @@ func (m *TipSetFilterManager) Install(ctx context.Context) (*TipSetFilter, error
|
|||||||
return f, nil
|
return f, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *TipSetFilterManager) Remove(ctx context.Context, id FilterID) error {
|
func (m *TipSetFilterManager) Remove(ctx context.Context, id types.FilterID) error {
|
||||||
m.mu.Lock()
|
m.mu.Lock()
|
||||||
defer m.mu.Unlock()
|
defer m.mu.Unlock()
|
||||||
if _, found := m.filters[id]; !found {
|
if _, found := m.filters[id]; !found {
|
||||||
|
@ -22,3 +22,5 @@ type EventEntry struct {
|
|||||||
// Any DAG-CBOR encodeable type.
|
// Any DAG-CBOR encodeable type.
|
||||||
Value []byte
|
Value []byte
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type FilterID [32]byte // compatible with EthHash
|
||||||
|
Loading…
Reference in New Issue
Block a user