diff options
author | Felix Lange <fjl@twurst.com> | 2015-03-11 00:14:31 +0800 |
---|---|---|
committer | Felix Lange <fjl@twurst.com> | 2015-03-11 00:14:31 +0800 |
commit | 269cfbb8ace76ddc1f50dbd5b218c499308c8a5c (patch) | |
tree | c2e9e274c64f431f03b9a6b8b3de22585c016027 /cmd/utils/cmd.go | |
parent | 972e2c1e31067a9bab77228c19348b66964ce643 (diff) | |
parent | 0542df941f57a75fa7b699089db1d9ae40e4ff71 (diff) | |
download | go-tangerine-269cfbb8ace76ddc1f50dbd5b218c499308c8a5c.tar.gz go-tangerine-269cfbb8ace76ddc1f50dbd5b218c499308c8a5c.tar.zst go-tangerine-269cfbb8ace76ddc1f50dbd5b218c499308c8a5c.zip |
Merge branch origin/develop into accounts-integration
Conflicts:
cmd/blocktest/main.go
cmd/mist/debugger.go
cmd/utils/cmd.go
Diffstat (limited to 'cmd/utils/cmd.go')
-rw-r--r-- | cmd/utils/cmd.go | 50 |
1 files changed, 26 insertions, 24 deletions
diff --git a/cmd/utils/cmd.go b/cmd/utils/cmd.go index c5568948d..6b99b841f 100644 --- a/cmd/utils/cmd.go +++ b/cmd/utils/cmd.go @@ -33,7 +33,6 @@ import ( "github.com/ethereum/go-ethereum/ethutil" "github.com/ethereum/go-ethereum/logger" "github.com/ethereum/go-ethereum/rlp" - "github.com/ethereum/go-ethereum/state" ) var clilogger = logger.NewLogger("CLI") @@ -123,6 +122,15 @@ func StartEthereum(ethereum *eth.Ethereum) { }) } +func StartEthereumForTest(ethereum *eth.Ethereum) { + clilogger.Infoln("Starting ", ethereum.Name()) + ethereum.StartForTest() + RegisterInterrupt(func(sig os.Signal) { + ethereum.Stop() + logger.Flush() + }) +} + func FormatTransactionData(data string) []byte { d := ethutil.StringToByteFunc(data, func(s string) (ret []byte) { slice := regexp.MustCompile("\\n|\\s").Split(s, 1000000000) @@ -136,27 +144,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 @@ -168,11 +157,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 +} |