forked from cerc-io/plugeth
cmd/ethereum, cmd/utils: partial fix for chain import
This commit is contained in:
parent
d15f90645d
commit
064279c0ec
@ -221,13 +221,10 @@ func (js *jsre) exportChain(call otto.FunctionCall) otto.Value {
|
|||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
return otto.FalseValue()
|
return otto.FalseValue()
|
||||||
}
|
}
|
||||||
|
if err := utils.ExportChain(js.ethereum.ChainManager(), fn); err != nil {
|
||||||
data := js.ethereum.ChainManager().Export()
|
|
||||||
if err := common.WriteFile(fn, data); err != nil {
|
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
return otto.FalseValue()
|
return otto.FalseValue()
|
||||||
}
|
}
|
||||||
|
|
||||||
return otto.TrueValue()
|
return otto.TrueValue()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -158,13 +158,12 @@ func ImportChain(chainmgr *core.ChainManager, fn string) error {
|
|||||||
var i int
|
var i int
|
||||||
for ; ; i++ {
|
for ; ; i++ {
|
||||||
var b types.Block
|
var b types.Block
|
||||||
err := stream.Decode(&b)
|
if err := stream.Decode(&b); err == io.EOF {
|
||||||
if err == io.EOF {
|
|
||||||
break
|
break
|
||||||
} else if err != nil {
|
} else if err != nil {
|
||||||
return fmt.Errorf("at block %d: %v", i, err)
|
return fmt.Errorf("at block %d: %v", i, err)
|
||||||
}
|
}
|
||||||
if err := chainmgr.InsertChain(types.Blocks{b}); err != nil {
|
if err := chainmgr.InsertChain(types.Blocks{&b}); err != nil {
|
||||||
return fmt.Errorf("invalid block %d: %v", i, err)
|
return fmt.Errorf("invalid block %d: %v", i, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -174,7 +173,7 @@ func ImportChain(chainmgr *core.ChainManager, fn string) error {
|
|||||||
|
|
||||||
func ExportChain(chainmgr *core.ChainManager, fn string) error {
|
func ExportChain(chainmgr *core.ChainManager, fn string) error {
|
||||||
fmt.Printf("exporting blockchain '%s'\n", fn)
|
fmt.Printf("exporting blockchain '%s'\n", fn)
|
||||||
fh, err := os.OpenFile(fn, os.O_WRONLY|os.O_TRUNC, os.ModePerm)
|
fh, err := os.OpenFile(fn, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, os.ModePerm)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user