aboutsummaryrefslogtreecommitdiffstats
path: root/core/chain_manager.go
diff options
context:
space:
mode:
authorTaylor Gerring <taylor.gerring@gmail.com>2015-06-06 11:01:54 +0800
committerTaylor Gerring <taylor.gerring@gmail.com>2015-06-06 11:01:54 +0800
commit89c9320d8000845ee144f12adee958a5ab2303ef (patch)
treed6cb6795feaae13de67a18cf8bb8723e7d411f84 /core/chain_manager.go
parent43ceb0f5c73dfde8540693a920e144fa67ffcd46 (diff)
downloadgo-tangerine-89c9320d8000845ee144f12adee958a5ab2303ef.tar.gz
go-tangerine-89c9320d8000845ee144f12adee958a5ab2303ef.tar.zst
go-tangerine-89c9320d8000845ee144f12adee958a5ab2303ef.zip
Allow exporting subset of chain
Diffstat (limited to 'core/chain_manager.go')
-rw-r--r--core/chain_manager.go16
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)