|
|
@ -18,12 +18,14 @@ |
|
|
|
package utils |
|
|
|
package utils |
|
|
|
|
|
|
|
|
|
|
|
import ( |
|
|
|
import ( |
|
|
|
|
|
|
|
"compress/gzip" |
|
|
|
"fmt" |
|
|
|
"fmt" |
|
|
|
"io" |
|
|
|
"io" |
|
|
|
"os" |
|
|
|
"os" |
|
|
|
"os/signal" |
|
|
|
"os/signal" |
|
|
|
"regexp" |
|
|
|
"regexp" |
|
|
|
"runtime" |
|
|
|
"runtime" |
|
|
|
|
|
|
|
"strings" |
|
|
|
|
|
|
|
|
|
|
|
"github.com/ethereum/go-ethereum/common" |
|
|
|
"github.com/ethereum/go-ethereum/common" |
|
|
|
"github.com/ethereum/go-ethereum/core" |
|
|
|
"github.com/ethereum/go-ethereum/core" |
|
|
@ -133,7 +135,15 @@ func ImportChain(chain *core.BlockChain, fn string) error { |
|
|
|
return err |
|
|
|
return err |
|
|
|
} |
|
|
|
} |
|
|
|
defer fh.Close() |
|
|
|
defer fh.Close() |
|
|
|
stream := rlp.NewStream(fh, 0) |
|
|
|
|
|
|
|
|
|
|
|
var reader io.Reader = fh |
|
|
|
|
|
|
|
if strings.HasSuffix(fn, ".gz") { |
|
|
|
|
|
|
|
if reader, err = gzip.NewReader(reader); err != nil { |
|
|
|
|
|
|
|
return err |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
stream := rlp.NewStream(reader, 0) |
|
|
|
|
|
|
|
|
|
|
|
// Run actual the import.
|
|
|
|
// Run actual the import.
|
|
|
|
blocks := make(types.Blocks, importBatchSize) |
|
|
|
blocks := make(types.Blocks, importBatchSize) |
|
|
@ -195,10 +205,18 @@ func ExportChain(blockchain *core.BlockChain, fn string) error { |
|
|
|
return err |
|
|
|
return err |
|
|
|
} |
|
|
|
} |
|
|
|
defer fh.Close() |
|
|
|
defer fh.Close() |
|
|
|
if err := blockchain.Export(fh); err != nil { |
|
|
|
|
|
|
|
|
|
|
|
var writer io.Writer = fh |
|
|
|
|
|
|
|
if strings.HasSuffix(fn, ".gz") { |
|
|
|
|
|
|
|
writer = gzip.NewWriter(writer) |
|
|
|
|
|
|
|
defer writer.(*gzip.Writer).Close() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if err := blockchain.Export(writer); err != nil { |
|
|
|
return err |
|
|
|
return err |
|
|
|
} |
|
|
|
} |
|
|
|
glog.Infoln("Exported blockchain to ", fn) |
|
|
|
glog.Infoln("Exported blockchain to ", fn) |
|
|
|
|
|
|
|
|
|
|
|
return nil |
|
|
|
return nil |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -210,7 +228,14 @@ func ExportAppendChain(blockchain *core.BlockChain, fn string, first uint64, las |
|
|
|
return err |
|
|
|
return err |
|
|
|
} |
|
|
|
} |
|
|
|
defer fh.Close() |
|
|
|
defer fh.Close() |
|
|
|
if err := blockchain.ExportN(fh, first, last); err != nil { |
|
|
|
|
|
|
|
|
|
|
|
var writer io.Writer = fh |
|
|
|
|
|
|
|
if strings.HasSuffix(fn, ".gz") { |
|
|
|
|
|
|
|
writer = gzip.NewWriter(writer) |
|
|
|
|
|
|
|
defer writer.(*gzip.Writer).Close() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if err := blockchain.ExportN(writer, first, last); err != nil { |
|
|
|
return err |
|
|
|
return err |
|
|
|
} |
|
|
|
} |
|
|
|
glog.Infoln("Exported blockchain to ", fn) |
|
|
|
glog.Infoln("Exported blockchain to ", fn) |
|
|
|