ExportN writes a subset of the active chain to the given writer.
(w io.Writer, first uint64, last uint64)
| 589 | |
| 590 | // ExportN writes a subset of the active chain to the given writer. |
| 591 | func (bc *BlockChain) ExportN(w io.Writer, first uint64, last uint64) error { |
| 592 | bc.mu.RLock() |
| 593 | defer bc.mu.RUnlock() |
| 594 | |
| 595 | if first > last { |
| 596 | return fmt.Errorf("export failed: first (%d) is greater than last (%d)", first, last) |
| 597 | } |
| 598 | log.Info("Exporting batch of blocks", "count", last-first+1) |
| 599 | |
| 600 | for nr := first; nr <= last; nr++ { |
| 601 | block := bc.GetBlockByNumber(nr) |
| 602 | if block == nil { |
| 603 | return fmt.Errorf("export failed on #%d: not found", nr) |
| 604 | } |
| 605 | |
| 606 | if err := block.EncodeRLP(w); err != nil { |
| 607 | return err |
| 608 | } |
| 609 | } |
| 610 | |
| 611 | return nil |
| 612 | } |
| 613 | |
| 614 | // insert injects a new head block into the current block chain. This method |
| 615 | // assumes that the block is indeed a true head. It will also reset the head |
no test coverage detected