aboutsummaryrefslogtreecommitdiffstats
path: root/cmd/utils/cmd.go
diff options
context:
space:
mode:
authorJeffrey Wilcke <jeffrey@ethereum.org>2015-03-10 18:24:47 +0800
committerJeffrey Wilcke <jeffrey@ethereum.org>2015-03-10 18:24:47 +0800
commitc9b6d268b45ec4cc0b1cc982ba544ed2f0a5ddd6 (patch)
tree867a55771deb1a6768c150ce91654eb72fb54c7e /cmd/utils/cmd.go
parent08d396fdba1cbe7d04084db37b2089889a72086e (diff)
parent41a89e18f68f4b12b8212544be01a4e0a6716976 (diff)
downloadgo-tangerine-c9b6d268b45ec4cc0b1cc982ba544ed2f0a5ddd6.tar.gz
go-tangerine-c9b6d268b45ec4cc0b1cc982ba544ed2f0a5ddd6.tar.zst
go-tangerine-c9b6d268b45ec4cc0b1cc982ba544ed2f0a5ddd6.zip
Merge pull request #438 from ethersphere/poc9/cli
Poc9/cli (exportchain)
Diffstat (limited to 'cmd/utils/cmd.go')
-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 a77c6ad4d..4188802ac 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
+}