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

Method Connect

onchain/eth_proxy.go:124–232  ·  view source on GitHub ↗
(urls []string, t time.Time)

Source from the content-addressed store, hash-verified

122}
123
124func (e *ethAdaptor) Connect(urls []string, t time.Time) (err error) {
125 if e.isConnecting() {
126 err = errors.Errorf("connection existing")
127 return
128 }
129
130 var httpUrls []string
131 var wsUrls []string
132 for _, url := range urls {
133 if strings.Contains(url, "http") {
134 httpUrls = append(httpUrls, url)
135 } else if strings.Contains(url, "ws") {
136 wsUrls = append(wsUrls, url)
137 }
138 }
139 e.wsUrls = wsUrls
140 if len(wsUrls) == 0 {
141 return errors.New("no web socket URL")
142 }
143
144 e.ctx, e.cancelFunc = context.WithCancel(context.Background())
145 e.clients = nil
146 e.proxies = nil
147 e.crs = nil
148 e.ctxes = nil
149 e.cancels = nil
150
151 dialCtx, dialCancel := context.WithDeadline(e.ctx, t)
152 defer dialCancel()
153
154 results := DialToEth(dialCtx, e.wsUrls)
155 for result := range results {
156 if result.Err != nil {
157 e.logger.Error(errors.Errorf(": %w", result.Err))
158 continue
159 }
160 client := result.Client
161 bridge, err := dosbridge.NewDosbridge(e.bridgeAddr, client)
162 if err != nil {
163 e.logger.Error(errors.Errorf(": %w", err))
164 client.Close()
165 continue
166 }
167 proxyAddr, err := bridge.GetProxyAddress(&bind.CallOpts{Context: dialCtx})
168 if err != nil {
169 e.logger.Error(errors.Errorf(": %w", err))
170 client.Close()
171 continue
172 }
173 commitRevealAddr, err := bridge.GetCommitRevealAddress(&bind.CallOpts{Context: dialCtx})
174 if err != nil {
175 e.logger.Error(errors.Errorf(": %w", err))
176 client.Close()
177 continue
178 }
179
180 bootStrapUrl, err := bridge.GetBootStrapUrl(&bind.CallOpts{Context: dialCtx})
181 if err != nil {

Callers

nothing calls this directly

Calls 10

isConnectingMethod · 0.95
ReqLoopMethod · 0.95
DialToEthFunction · 0.85
NewMethod · 0.65
ErrorMethod · 0.65
EventMethod · 0.65
CloseMethod · 0.45
GetProxyAddressMethod · 0.45
GetBootStrapUrlMethod · 0.45

Tested by

no test coverage detected