(ctx context.Context, source chan interface{})
| 54 | ) |
| 55 | |
| 56 | func firstEvent(ctx context.Context, source chan interface{}) (out chan interface{}) { |
| 57 | out = make(chan interface{}) |
| 58 | |
| 59 | go func() { |
| 60 | defer close(out) |
| 61 | visited := make(map[string]uint64) |
| 62 | for { |
| 63 | select { |
| 64 | case <-ctx.Done(): |
| 65 | return |
| 66 | case event, ok := <-source: |
| 67 | if !ok { |
| 68 | return |
| 69 | } |
| 70 | if content, ok := event.(*LogCommon); ok { |
| 71 | if content.Removed { |
| 72 | continue |
| 73 | } |
| 74 | var bytes []byte |
| 75 | bytes = append(bytes, content.Raw.Data...) |
| 76 | bytes = append(bytes, new(big.Int).SetUint64(content.BlockN).Bytes()...) |
| 77 | nHash := sha256.Sum256(bytes) |
| 78 | |
| 79 | identity := string(nHash[:]) |
| 80 | if visited[identity] == 0 { |
| 81 | visited[identity] = content.BlockN |
| 82 | select { |
| 83 | case out <- content.log: |
| 84 | case <-ctx.Done(): |
| 85 | } |
| 86 | go func(identity string) { |
| 87 | select { |
| 88 | case <-ctx.Done(): |
| 89 | case <-time.After(100 * 15 * time.Second): |
| 90 | delete(visited, identity) |
| 91 | } |
| 92 | }(identity) |
| 93 | } |
| 94 | } |
| 95 | } |
| 96 | } |
| 97 | }() |
| 98 | |
| 99 | return |
| 100 | } |
| 101 | |
| 102 | // SubscribeEvent is a log subscription operation |
| 103 | func (e *ethAdaptor) SubscribeEvent(subscribeTypes []int) (chan interface{}, chan error) { |
no test coverage detected