aboutsummaryrefslogtreecommitdiffstats
path: root/cmd/utils
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2015-03-22 01:18:19 +0800
committerobscuren <geffobscura@gmail.com>2015-03-22 01:18:19 +0800
commit7f85608f30a2e34005c8d15566849229c758c2f1 (patch)
tree7aeb9d8bdfda7ec10ea38688a96ed245028764ad /cmd/utils
parent09766d1729f7530093aec7e9acd3e5339b2c2028 (diff)
parentfcacfabe1959c4aff6a63cb4e275f65328660601 (diff)
downloaddexon-7f85608f30a2e34005c8d15566849229c758c2f1.tar
dexon-7f85608f30a2e34005c8d15566849229c758c2f1.tar.gz
dexon-7f85608f30a2e34005c8d15566849229c758c2f1.tar.bz2
dexon-7f85608f30a2e34005c8d15566849229c758c2f1.tar.lz
dexon-7f85608f30a2e34005c8d15566849229c758c2f1.tar.xz
dexon-7f85608f30a2e34005c8d15566849229c758c2f1.tar.zst
dexon-7f85608f30a2e34005c8d15566849229c758c2f1.zip
Merge branch 'conversion' into develop
Diffstat (limited to 'cmd/utils')
-rw-r--r--cmd/utils/cmd.go36
1 files changed, 21 insertions, 15 deletions
diff --git a/cmd/utils/cmd.go b/cmd/utils/cmd.go
index 74fd5334e..feea29d64 100644
--- a/cmd/utils/cmd.go
+++ b/cmd/utils/cmd.go
@@ -23,14 +23,15 @@ package utils
import (
"fmt"
+ "io"
"os"
"os/signal"
"regexp"
+ "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/eth"
- "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/logger"
"github.com/ethereum/go-ethereum/rlp"
)
@@ -152,29 +153,34 @@ func ImportChain(chainmgr *core.ChainManager, fn string) error {
}
defer fh.Close()
- var blocks types.Blocks
- if err := rlp.Decode(fh, &blocks); err != nil {
- return err
- }
-
chainmgr.Reset()
- if err := chainmgr.InsertChain(blocks); err != nil {
- return err
+ stream := rlp.NewStream(fh)
+ var i int
+ for ; ; i++ {
+ var b types.Block
+ if err := stream.Decode(&b); err == io.EOF {
+ break
+ } else if err != nil {
+ return fmt.Errorf("at block %d: %v", i, err)
+ }
+ if err := chainmgr.InsertChain(types.Blocks{&b}); err != nil {
+ return fmt.Errorf("invalid block %d: %v", i, err)
+ }
}
- fmt.Printf("imported %d blocks\n", len(blocks))
-
+ fmt.Printf("imported %d blocks\n", i)
return nil
}
func ExportChain(chainmgr *core.ChainManager, fn string) error {
fmt.Printf("exporting blockchain '%s'\n", fn)
-
- data := chainmgr.Export()
-
- if err := common.WriteFile(fn, data); err != nil {
+ fh, err := os.OpenFile(fn, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, os.ModePerm)
+ if err != nil {
+ return err
+ }
+ defer fh.Close()
+ if err := chainmgr.Export(fh); err != nil {
return err
}
fmt.Printf("exported blockchain\n")
-
return nil
}