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

Method ExportN

core/blockchain.go:591–612  ·  view source on GitHub ↗

ExportN writes a subset of the active chain to the given writer.

(w io.Writer, first uint64, last uint64)

Source from the content-addressed store, hash-verified

589
590// ExportN writes a subset of the active chain to the given writer.
591func (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

Callers 2

ExportMethod · 0.95
ExportChainNFunction · 0.80

Calls 3

GetBlockByNumberMethod · 0.95
InfoMethod · 0.65
EncodeRLPMethod · 0.45

Tested by

no test coverage detected