Moved import to utils
This commit is contained in:
parent
7d2353f24d
commit
1054c155db
@ -26,7 +26,6 @@ import (
|
||||
"github.com/ethereum/go-ethereum/core/types"
|
||||
"github.com/ethereum/go-ethereum/ethutil"
|
||||
"github.com/ethereum/go-ethereum/logger"
|
||||
"github.com/ethereum/go-ethereum/rlp"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -118,26 +117,11 @@ func main() {
|
||||
}
|
||||
|
||||
if len(ImportChain) > 0 {
|
||||
clilogger.Infof("importing chain '%s'\n", ImportChain)
|
||||
fh, err := os.OpenFile(ImportChain, os.O_RDONLY, os.ModePerm)
|
||||
err := utils.ImportChain(ethereum, ImportChain)
|
||||
if err != nil {
|
||||
clilogger.Infoln(err)
|
||||
return
|
||||
}
|
||||
defer fh.Close()
|
||||
|
||||
var chain types.Blocks
|
||||
if err := rlp.Decode(fh, &chain); err != nil {
|
||||
clilogger.Infoln(err)
|
||||
return
|
||||
}
|
||||
|
||||
ethereum.ChainManager().Reset()
|
||||
if err := ethereum.ChainManager().InsertChain(chain); err != nil {
|
||||
clilogger.Infoln(err)
|
||||
return
|
||||
}
|
||||
clilogger.Infof("imported %d blocks\n", len(chain))
|
||||
return
|
||||
}
|
||||
|
||||
// better reworked as cases
|
||||
|
@ -13,6 +13,7 @@ import (
|
||||
"runtime"
|
||||
|
||||
"bitbucket.org/kardianos/osext"
|
||||
"github.com/ethereum/go-ethereum/core/types"
|
||||
"github.com/ethereum/go-ethereum/crypto"
|
||||
"github.com/ethereum/go-ethereum/eth"
|
||||
"github.com/ethereum/go-ethereum/ethdb"
|
||||
@ -20,6 +21,7 @@ import (
|
||||
"github.com/ethereum/go-ethereum/logger"
|
||||
"github.com/ethereum/go-ethereum/miner"
|
||||
"github.com/ethereum/go-ethereum/p2p"
|
||||
"github.com/ethereum/go-ethereum/rlp"
|
||||
"github.com/ethereum/go-ethereum/rpc"
|
||||
"github.com/ethereum/go-ethereum/xeth"
|
||||
)
|
||||
@ -335,3 +337,25 @@ func BlockDo(ethereum *eth.Ethereum, hash []byte) error {
|
||||
return nil
|
||||
|
||||
}
|
||||
|
||||
func ImportChain(ethereum *eth.Ethereum, fn string) error {
|
||||
clilogger.Infof("importing chain '%s'\n", ImportChain)
|
||||
fh, err := os.OpenFile(fn, os.O_RDONLY, os.ModePerm)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer fh.Close()
|
||||
|
||||
var chain types.Blocks
|
||||
if err := rlp.Decode(fh, &chain); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
ethereum.ChainManager().Reset()
|
||||
if err := ethereum.ChainManager().InsertChain(chain); err != nil {
|
||||
return err
|
||||
}
|
||||
clilogger.Infof("imported %d blocks\n", len(chain))
|
||||
|
||||
return nil
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user