Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
whqwjb
go-ethereum
提交
181a3309
G
go-ethereum
项目概览
whqwjb
/
go-ethereum
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
go-ethereum
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
181a3309
编写于
5月 03, 2017
作者:
P
Péter Szilágyi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
cmd/geth, cmd/utils: init/removedb on light/full dbs simultaneously
上级
02fa3e31
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
45 addition
and
42 deletion
+45
-42
cmd/geth/chaincmd.go
cmd/geth/chaincmd.go
+41
-32
cmd/utils/flags.go
cmd/utils/flags.go
+4
-10
未找到文件。
cmd/geth/chaincmd.go
浏览文件 @
181a3309
...
...
@@ -58,10 +58,10 @@ participating.
ArgsUsage
:
"<filename> (<filename 2> ... <filename N>) "
,
Category
:
"BLOCKCHAIN COMMANDS"
,
Description
:
`
The import command imports blocks from an RLP-encoded form. The form can be one file
with several RLP-encoded blocks, or several files can be used.
If only one file is used, import error will result in failure. If several files are used,
processing will proceed even if an individual RLP-file import failure occurs.
The import command imports blocks from an RLP-encoded form. The form can be one file
with several RLP-encoded blocks, or several files can be used.
If only one file is used, import error will result in failure. If several files are used,
processing will proceed even if an individual RLP-file import failure occurs.
`
,
}
exportCommand
=
cli
.
Command
{
...
...
@@ -103,17 +103,14 @@ Use "ethereum dump 0" to dump the genesis block.
// initGenesis will initialise the given JSON format genesis file and writes it as
// the zero'd block (i.e. genesis) or will fail hard if it can't succeed.
func
initGenesis
(
ctx
*
cli
.
Context
)
error
{
// Make sure we have a valid genesis JSON
genesisPath
:=
ctx
.
Args
()
.
First
()
if
len
(
genesisPath
)
==
0
{
utils
.
Fatalf
(
"
m
ust supply path to genesis JSON file"
)
utils
.
Fatalf
(
"
M
ust supply path to genesis JSON file"
)
}
stack
:=
makeFullNode
(
ctx
)
chaindb
:=
utils
.
MakeChainDatabase
(
ctx
,
stack
)
file
,
err
:=
os
.
Open
(
genesisPath
)
if
err
!=
nil
{
utils
.
Fatalf
(
"
f
ailed to read genesis file: %v"
,
err
)
utils
.
Fatalf
(
"
F
ailed to read genesis file: %v"
,
err
)
}
defer
file
.
Close
()
...
...
@@ -121,12 +118,19 @@ func initGenesis(ctx *cli.Context) error {
if
err
:=
json
.
NewDecoder
(
file
)
.
Decode
(
genesis
);
err
!=
nil
{
utils
.
Fatalf
(
"invalid genesis file: %v"
,
err
)
}
_
,
hash
,
err
:=
core
.
SetupGenesisBlock
(
chaindb
,
genesis
)
if
err
!=
nil
{
utils
.
Fatalf
(
"failed to write genesis block: %v"
,
err
)
// Open an initialise both full and light databases
stack
:=
makeFullNode
(
ctx
)
for
_
,
name
:=
range
[]
string
{
"chaindata"
,
"lightchaindata"
}
{
chaindb
,
err
:=
stack
.
OpenDatabase
(
name
,
0
,
0
)
if
err
!=
nil
{
utils
.
Fatalf
(
"Failed to open database: %v"
,
err
)
}
_
,
hash
,
err
:=
core
.
SetupGenesisBlock
(
chaindb
,
genesis
)
if
err
!=
nil
{
utils
.
Fatalf
(
"Failed to write genesis block: %v"
,
err
)
}
log
.
Info
(
"Successfully wrote genesis state"
,
"database"
,
name
,
"hash"
,
hash
)
}
log
.
Info
(
"Successfully wrote genesis state"
,
"hash"
,
hash
)
return
nil
}
...
...
@@ -245,24 +249,29 @@ func exportChain(ctx *cli.Context) error {
func
removeDB
(
ctx
*
cli
.
Context
)
error
{
stack
,
_
:=
makeConfigNode
(
ctx
)
dbdir
:=
stack
.
ResolvePath
(
utils
.
ChainDbName
(
ctx
))
if
!
common
.
FileExist
(
dbdir
)
{
fmt
.
Println
(
dbdir
,
"does not exist"
)
return
nil
}
fmt
.
Println
(
dbdir
)
confirm
,
err
:=
console
.
Stdin
.
PromptConfirm
(
"Remove this database?"
)
switch
{
case
err
!=
nil
:
utils
.
Fatalf
(
"%v"
,
err
)
case
!
confirm
:
fmt
.
Println
(
"Operation aborted"
)
default
:
fmt
.
Println
(
"Removing..."
)
start
:=
time
.
Now
()
os
.
RemoveAll
(
dbdir
)
fmt
.
Printf
(
"Removed in %v
\n
"
,
time
.
Since
(
start
))
for
_
,
name
:=
range
[]
string
{
"chaindata"
,
"lightchaindata"
}
{
// Ensure the database exists in the first place
logger
:=
log
.
New
(
"database"
,
name
)
dbdir
:=
stack
.
ResolvePath
(
name
)
if
!
common
.
FileExist
(
dbdir
)
{
logger
.
Info
(
"Database doesn't exist, skipping"
,
"path"
,
dbdir
)
continue
}
// Confirm removal and execute
fmt
.
Println
(
dbdir
)
confirm
,
err
:=
console
.
Stdin
.
PromptConfirm
(
"Remove this database?"
)
switch
{
case
err
!=
nil
:
utils
.
Fatalf
(
"%v"
,
err
)
case
!
confirm
:
logger
.
Warn
(
"Database deletion aborted"
)
default
:
start
:=
time
.
Now
()
os
.
RemoveAll
(
dbdir
)
logger
.
Info
(
"Database successfully deleted"
,
"elapsed"
,
common
.
PrettyDuration
(
time
.
Since
(
start
)))
}
}
return
nil
}
...
...
cmd/utils/flags.go
浏览文件 @
181a3309
...
...
@@ -908,22 +908,16 @@ func SetupNetwork(ctx *cli.Context) {
params
.
TargetGasLimit
=
new
(
big
.
Int
)
.
SetUint64
(
ctx
.
GlobalUint64
(
TargetGasLimitFlag
.
Name
))
}
func
ChainDbName
(
ctx
*
cli
.
Context
)
string
{
if
ctx
.
GlobalBool
(
LightModeFlag
.
Name
)
{
return
"lightchaindata"
}
else
{
return
"chaindata"
}
}
// MakeChainDatabase open an LevelDB using the flags passed to the client and will hard crash if it fails.
func
MakeChainDatabase
(
ctx
*
cli
.
Context
,
stack
*
node
.
Node
)
ethdb
.
Database
{
var
(
cache
=
ctx
.
GlobalInt
(
CacheFlag
.
Name
)
handles
=
makeDatabaseHandles
()
name
=
ChainDbName
(
ctx
)
)
name
:=
"chaindata"
if
ctx
.
GlobalBool
(
LightModeFlag
.
Name
)
{
name
=
"lightchaindata"
}
chainDb
,
err
:=
stack
.
OpenDatabase
(
name
,
cache
,
handles
)
if
err
!=
nil
{
Fatalf
(
"Could not open database: %v"
,
err
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录