| 226 | } |
| 227 | |
| 228 | func (e *Exchange) fetchOldBlocks(ctx context.Context) (err error) { |
| 229 | var blk *types.Block |
| 230 | |
| 231 | // fetch old block failed |
| 232 | if blk, err = e.client.BlockByNumber(ctx, nil); err != nil { |
| 233 | return |
| 234 | } |
| 235 | |
| 236 | e.newBlockCh <- blk |
| 237 | targetBlkNumber := blk.NumberU64() |
| 238 | |
| 239 | if e.currentBlock != 0 { |
| 240 | for i := e.currentBlock; i < targetBlkNumber; { |
| 241 | blk, err = e.client.BlockByNumber(ctx, new(big.Int).SetUint64(i)) |
| 242 | if err != nil { |
| 243 | time.Sleep(time.Second) |
| 244 | continue |
| 245 | } |
| 246 | |
| 247 | e.newBlockCh <- blk |
| 248 | i++ |
| 249 | } |
| 250 | } |
| 251 | |
| 252 | return |
| 253 | } |
| 254 | |
| 255 | func (e *Exchange) process() { |
| 256 | if e.newBlockHeaderCh == nil || e.wg == nil { |