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

Method Syncing

protocols/cpc/syncer/api.go:93–120  ·  view source on GitHub ↗

Syncing provides information when this nodes starts synchronising with the Ethereum network and when it's finished.

(ctx context.Context)

Source from the content-addressed store, hash-verified

91
92// Syncing provides information when this nodes starts synchronising with the Ethereum network and when it's finished.
93func (api *PublicDownloaderAPI) Syncing(ctx context.Context) (*rpc.Subscription, error) {
94 notifier, supported := rpc.NotifierFromContext(ctx)
95 if !supported {
96 return &rpc.Subscription{}, rpc.ErrNotificationsUnsupported
97 }
98
99 rpcSub := notifier.CreateSubscription()
100
101 go func() {
102 statuses := make(chan interface{})
103 sub := api.SubscribeSyncStatus(statuses)
104
105 for {
106 select {
107 case status := <-statuses:
108 notifier.Notify(rpcSub.ID, status)
109 case <-rpcSub.Err():
110 sub.Unsubscribe()
111 return
112 case <-notifier.Closed():
113 sub.Unsubscribe()
114 return
115 }
116 }
117 }()
118
119 return rpcSub, nil
120}
121
122// SyncingResult provides information about the current synchronisation status for this node.
123type SyncingResult struct {

Callers

nothing calls this directly

Calls 6

SubscribeSyncStatusMethod · 0.95
CreateSubscriptionMethod · 0.80
ErrMethod · 0.65
UnsubscribeMethod · 0.65
ClosedMethod · 0.65
NotifyMethod · 0.45

Tested by

no test coverage detected