MCPcopy Create free account
hub / github.com/DOSNetwork/core / firstEvent

Function firstEvent

onchain/eth_subscribe.go:56–100  ·  view source on GitHub ↗
(ctx context.Context, source chan interface{})

Source from the content-addressed store, hash-verified

54)
55
56func 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
103func (e *ethAdaptor) SubscribeEvent(subscribeTypes []int) (chan interface{}, chan error) {

Callers 1

SubscribeEventMethod · 0.85

Calls 1

SetUint64Method · 0.80

Tested by

no test coverage detected