aboutsummaryrefslogtreecommitdiffstats
path: root/cmd/utils
diff options
context:
space:
mode:
authorzelig <viktor.tron@gmail.com>2015-03-08 23:44:48 +0800
committerzelig <viktor.tron@gmail.com>2015-03-08 23:44:48 +0800
commit51eed7964ec35bbdc23dd8a4a8fffedad247e33d (patch)
treefe539264e3a36bedbb016a5e31a3bb838e21c795 /cmd/utils
parent07955b30419a26b9b213f71955a02a49995dc0e3 (diff)
downloaddexon-51eed7964ec35bbdc23dd8a4a8fffedad247e33d.tar.gz
dexon-51eed7964ec35bbdc23dd8a4a8fffedad247e33d.tar.zst
dexon-51eed7964ec35bbdc23dd8a4a8fffedad247e33d.zip
add export blockchain subcommand, remove BlockDo
Diffstat (limited to 'cmd/utils')
-rw-r--r--cmd/utils/cmd.go41
1 files changed, 17 insertions, 24 deletions
diff --git a/cmd/utils/cmd.go b/cmd/utils/cmd.go
index 99e60ff9e..8e516748e 100644
--- a/cmd/utils/cmd.go
+++ b/cmd/utils/cmd.go
@@ -35,7 +35,6 @@ import (
"github.com/ethereum/go-ethereum/logger"
"github.com/ethereum/go-ethereum/rlp"
rpchttp "github.com/ethereum/go-ethereum/rpc/http"
- "github.com/ethereum/go-ethereum/state"
"github.com/ethereum/go-ethereum/xeth"
)
@@ -188,27 +187,8 @@ func FormatTransactionData(data string) []byte {
return d
}
-// Replay block
-func BlockDo(ethereum *eth.Ethereum, hash []byte) error {
- block := ethereum.ChainManager().GetBlock(hash)
- if block == nil {
- return fmt.Errorf("unknown block %x", hash)
- }
-
- parent := ethereum.ChainManager().GetBlock(block.ParentHash())
-
- statedb := state.New(parent.Root(), ethereum.StateDb())
- _, err := ethereum.BlockProcessor().TransitionState(statedb, parent, block, true)
- if err != nil {
- return err
- }
-
- return nil
-
-}
-
-func ImportChain(chain *core.ChainManager, fn string) error {
- fmt.Printf("importing chain '%s'\n", fn)
+func ImportChain(chainmgr *core.ChainManager, fn string) error {
+ fmt.Printf("importing blockchain '%s'\n", fn)
fh, err := os.OpenFile(fn, os.O_RDONLY, os.ModePerm)
if err != nil {
return err
@@ -220,11 +200,24 @@ func ImportChain(chain *core.ChainManager, fn string) error {
return err
}
- chain.Reset()
- if err := chain.InsertChain(blocks); err != nil {
+ chainmgr.Reset()
+ if err := chainmgr.InsertChain(blocks); err != nil {
return err
}
fmt.Printf("imported %d blocks\n", len(blocks))
return nil
}
+
+func ExportChain(chainmgr *core.ChainManager, fn string) error {
+ fmt.Printf("exporting blockchain '%s'\n", fn)
+
+ data := chainmgr.Export()
+
+ if err := ethutil.WriteFile(fn, data); err != nil {
+ return err
+ }
+ fmt.Printf("exported blockchain\n")
+
+ return nil
+}