MCPcopy Create free account
hub / github.com/CPChain/chain / Logs

Method Logs

protocols/cpc/filters/api.go:237–272  ·  view source on GitHub ↗

Logs creates a subscription that fires for all new log that match the given filter criteria.

(ctx context.Context, crit FilterCriteria)

Source from the content-addressed store, hash-verified

235
236// Logs creates a subscription that fires for all new log that match the given filter criteria.
237func (api *PublicFilterAPI) Logs(ctx context.Context, crit FilterCriteria) (*rpc.Subscription, error) {
238 notifier, supported := rpc.NotifierFromContext(ctx)
239 if !supported {
240 return &rpc.Subscription{}, rpc.ErrNotificationsUnsupported
241 }
242
243 var (
244 rpcSub = notifier.CreateSubscription()
245 matchedLogs = make(chan []*types.Log)
246 )
247
248 logsSub, err := api.events.SubscribeLogs(cpchain.FilterQuery(crit), matchedLogs)
249 if err != nil {
250 return nil, err
251 }
252
253 go func() {
254
255 for {
256 select {
257 case logs := <-matchedLogs:
258 for _, log := range logs {
259 notifier.Notify(rpcSub.ID, &log)
260 }
261 case <-rpcSub.Err(): // client send an unsubscribe request
262 logsSub.Unsubscribe()
263 return
264 case <-notifier.Closed(): // connection dropped
265 logsSub.Unsubscribe()
266 return
267 }
268 }
269 }()
270
271 return rpcSub, nil
272}
273
274// FilterCriteria represents a request to create a new filter.
275// Same as ethereum.FilterQuery but with UnmarshalJSON() method.

Callers 2

GetLogsMethod · 0.45
GetFilterLogsMethod · 0.45

Calls 6

CreateSubscriptionMethod · 0.80
SubscribeLogsMethod · 0.80
ErrMethod · 0.65
UnsubscribeMethod · 0.65
ClosedMethod · 0.65
NotifyMethod · 0.45

Tested by

no test coverage detected