diff options
author | Taylor Gerring <taylor.gerring@gmail.com> | 2015-06-06 11:01:54 +0800 |
---|---|---|
committer | Taylor Gerring <taylor.gerring@gmail.com> | 2015-06-06 11:01:54 +0800 |
commit | 89c9320d8000845ee144f12adee958a5ab2303ef (patch) | |
tree | d6cb6795feaae13de67a18cf8bb8723e7d411f84 /core/chain_manager.go | |
parent | 43ceb0f5c73dfde8540693a920e144fa67ffcd46 (diff) | |
download | dexon-89c9320d8000845ee144f12adee958a5ab2303ef.tar dexon-89c9320d8000845ee144f12adee958a5ab2303ef.tar.gz dexon-89c9320d8000845ee144f12adee958a5ab2303ef.tar.bz2 dexon-89c9320d8000845ee144f12adee958a5ab2303ef.tar.lz dexon-89c9320d8000845ee144f12adee958a5ab2303ef.tar.xz dexon-89c9320d8000845ee144f12adee958a5ab2303ef.tar.zst dexon-89c9320d8000845ee144f12adee958a5ab2303ef.zip |
Allow exporting subset of chain
Diffstat (limited to 'core/chain_manager.go')
-rw-r--r-- | core/chain_manager.go | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/core/chain_manager.go b/core/chain_manager.go index 86d1c1454..1d1b6554e 100644 --- a/core/chain_manager.go +++ b/core/chain_manager.go @@ -341,13 +341,25 @@ func (bc *ChainManager) ResetWithGenesisBlock(gb *types.Block) { // Export writes the active chain to the given writer. func (self *ChainManager) Export(w io.Writer) error { + if err := self.ExportN(w, uint64(1), self.currentBlock.NumberU64()); err != nil { + return err + } + return nil +} + +// ExportN writes a subset of the active chain to the given writer. +func (self *ChainManager) ExportN(w io.Writer, first uint64, last uint64) error { self.mu.RLock() defer self.mu.RUnlock() glog.V(logger.Info).Infof("exporting %v blocks...\n", self.currentBlock.Header().Number) - last := self.currentBlock.NumberU64() + if first > last { + return fmt.Errorf("export failed: first (%d) is greater than last (%d)", first, last) + } + + glog.V(logger.Info).Infof("exporting %d blocks...\n", last-first) - for nr := uint64(1); nr <= last; nr++ { + for nr := first; nr <= last; nr++ { block := self.GetBlockByNumber(nr) if block == nil { return fmt.Errorf("export failed on #%d: not found", nr) |