Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
Geth-Modification
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
张蕾
Geth-Modification
Commits
651030c9
Commit
651030c9
authored
May 27, 2015
by
Felix Lange
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cmd/geth: move blockchain commands to chaincmd.go
parent
62671c93
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
167 additions
and
147 deletions
+167
-147
blocktestcmd.go
cmd/geth/blocktestcmd.go
+1
-1
chaincmd.go
cmd/geth/chaincmd.go
+159
-0
main.go
cmd/geth/main.go
+7
-146
No files found.
cmd/geth/blocktest.go
→
cmd/geth/blocktest
cmd
.go
View file @
651030c9
...
...
@@ -12,7 +12,7 @@ import (
"github.com/ethereum/go-ethereum/tests"
)
var
blocktestC
m
d
=
cli
.
Command
{
var
blocktestC
omman
d
=
cli
.
Command
{
Action
:
runBlockTest
,
Name
:
"blocktest"
,
Usage
:
`loads a block test file`
,
...
...
cmd/geth/chaincmd.go
0 → 100644
View file @
651030c9
package
main
import
(
"fmt"
"os"
"path/filepath"
"strconv"
"time"
"github.com/codegangsta/cli"
"github.com/ethereum/go-ethereum/cmd/utils"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core/state"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/logger/glog"
)
var
(
importCommand
=
cli
.
Command
{
Action
:
importChain
,
Name
:
"import"
,
Usage
:
`import a blockchain file`
,
}
exportCommand
=
cli
.
Command
{
Action
:
exportChain
,
Name
:
"export"
,
Usage
:
`export blockchain into file`
,
}
upgradedbCommand
=
cli
.
Command
{
Action
:
upgradeDB
,
Name
:
"upgradedb"
,
Usage
:
"upgrade chainblock database"
,
}
removedbCommand
=
cli
.
Command
{
Action
:
removeDB
,
Name
:
"removedb"
,
Usage
:
"Remove blockchain and state databases"
,
}
dumpCommand
=
cli
.
Command
{
Action
:
dump
,
Name
:
"dump"
,
Usage
:
`dump a specific block from storage`
,
Description
:
`
The arguments are interpreted as block numbers or hashes.
Use "ethereum dump 0" to dump the genesis block.
`
,
}
)
func
importChain
(
ctx
*
cli
.
Context
)
{
if
len
(
ctx
.
Args
())
!=
1
{
utils
.
Fatalf
(
"This command requires an argument."
)
}
chain
,
blockDB
,
stateDB
,
extraDB
:=
utils
.
GetChain
(
ctx
)
start
:=
time
.
Now
()
if
err
:=
utils
.
ImportChain
(
chain
,
ctx
.
Args
()
.
First
());
err
!=
nil
{
utils
.
Fatalf
(
"Import error: %v
\n
"
,
err
)
}
flushAll
(
blockDB
,
stateDB
,
extraDB
)
fmt
.
Printf
(
"Import done in %v"
,
time
.
Since
(
start
))
}
func
exportChain
(
ctx
*
cli
.
Context
)
{
if
len
(
ctx
.
Args
())
!=
1
{
utils
.
Fatalf
(
"This command requires an argument."
)
}
chain
,
_
,
_
,
_
:=
utils
.
GetChain
(
ctx
)
start
:=
time
.
Now
()
if
err
:=
utils
.
ExportChain
(
chain
,
ctx
.
Args
()
.
First
());
err
!=
nil
{
utils
.
Fatalf
(
"Export error: %v
\n
"
,
err
)
}
fmt
.
Printf
(
"Export done in %v"
,
time
.
Since
(
start
))
}
func
removeDB
(
ctx
*
cli
.
Context
)
{
confirm
,
err
:=
utils
.
PromptConfirm
(
"Remove local databases?"
)
if
err
!=
nil
{
utils
.
Fatalf
(
"%v"
,
err
)
}
if
confirm
{
fmt
.
Println
(
"Removing chain and state databases..."
)
start
:=
time
.
Now
()
os
.
RemoveAll
(
filepath
.
Join
(
ctx
.
GlobalString
(
utils
.
DataDirFlag
.
Name
),
"blockchain"
))
os
.
RemoveAll
(
filepath
.
Join
(
ctx
.
GlobalString
(
utils
.
DataDirFlag
.
Name
),
"state"
))
fmt
.
Printf
(
"Removed in %v
\n
"
,
time
.
Since
(
start
))
}
else
{
fmt
.
Println
(
"Operation aborted"
)
}
}
func
upgradeDB
(
ctx
*
cli
.
Context
)
{
glog
.
Infoln
(
"Upgrading blockchain database"
)
chain
,
blockDB
,
stateDB
,
extraDB
:=
utils
.
GetChain
(
ctx
)
v
,
_
:=
blockDB
.
Get
([]
byte
(
"BlockchainVersion"
))
bcVersion
:=
int
(
common
.
NewValue
(
v
)
.
Uint
())
if
bcVersion
==
0
{
bcVersion
=
core
.
BlockChainVersion
}
// Export the current chain.
filename
:=
fmt
.
Sprintf
(
"blockchain_%d_%s.chain"
,
bcVersion
,
time
.
Now
()
.
Format
(
"20060102_150405"
))
exportFile
:=
filepath
.
Join
(
ctx
.
GlobalString
(
utils
.
DataDirFlag
.
Name
),
filename
)
if
err
:=
utils
.
ExportChain
(
chain
,
exportFile
);
err
!=
nil
{
utils
.
Fatalf
(
"Unable to export chain for reimport %s
\n
"
,
err
)
}
flushAll
(
blockDB
,
stateDB
,
extraDB
)
os
.
RemoveAll
(
filepath
.
Join
(
ctx
.
GlobalString
(
utils
.
DataDirFlag
.
Name
),
"blockchain"
))
os
.
RemoveAll
(
filepath
.
Join
(
ctx
.
GlobalString
(
utils
.
DataDirFlag
.
Name
),
"state"
))
// Import the chain file.
chain
,
blockDB
,
stateDB
,
extraDB
=
utils
.
GetChain
(
ctx
)
blockDB
.
Put
([]
byte
(
"BlockchainVersion"
),
common
.
NewValue
(
core
.
BlockChainVersion
)
.
Bytes
())
err
:=
utils
.
ImportChain
(
chain
,
exportFile
)
flushAll
(
blockDB
,
stateDB
,
extraDB
)
if
err
!=
nil
{
utils
.
Fatalf
(
"Import error %v (a backup is made in %s, use the import command to import it)
\n
"
,
err
,
exportFile
)
}
else
{
os
.
Remove
(
exportFile
)
glog
.
Infoln
(
"Import finished"
)
}
}
func
dump
(
ctx
*
cli
.
Context
)
{
chain
,
_
,
stateDB
,
_
:=
utils
.
GetChain
(
ctx
)
for
_
,
arg
:=
range
ctx
.
Args
()
{
var
block
*
types
.
Block
if
hashish
(
arg
)
{
block
=
chain
.
GetBlock
(
common
.
HexToHash
(
arg
))
}
else
{
num
,
_
:=
strconv
.
Atoi
(
arg
)
block
=
chain
.
GetBlockByNumber
(
uint64
(
num
))
}
if
block
==
nil
{
fmt
.
Println
(
"{}"
)
utils
.
Fatalf
(
"block not found"
)
}
else
{
state
:=
state
.
New
(
block
.
Root
(),
stateDB
)
fmt
.
Printf
(
"%s
\n
"
,
state
.
Dump
())
}
}
}
// hashish returns true for strings that look like hashes.
func
hashish
(
x
string
)
bool
{
_
,
err
:=
strconv
.
Atoi
(
x
)
return
err
!=
nil
}
func
flushAll
(
dbs
...
common
.
Database
)
{
for
_
,
db
:=
range
dbs
{
db
.
Flush
()
db
.
Close
()
}
}
cmd/geth/main.go
View file @
651030c9
...
...
@@ -24,28 +24,23 @@ import (
"fmt"
"io"
"io/ioutil"
_
"net/http/pprof"
"os"
"path/filepath"
"runtime"
"strconv"
"strings"
"time"
"github.com/codegangsta/cli"
"github.com/ethereum/ethash"
"github.com/ethereum/go-ethereum/accounts"
"github.com/ethereum/go-ethereum/cmd/utils"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core/state"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/eth"
"github.com/ethereum/go-ethereum/logger"
"github.com/ethereum/go-ethereum/logger/glog"
"github.com/mattn/go-colorable"
"github.com/mattn/go-isatty"
)
import
_
"net/http/pprof"
const
(
ClientIdentifier
=
"Geth"
...
...
@@ -69,7 +64,12 @@ func init() {
app
.
Action
=
run
app
.
HideVersion
=
true
// we have a command to print the version
app
.
Commands
=
[]
cli
.
Command
{
blocktestCmd
,
blocktestCommand
,
importCommand
,
exportCommand
,
upgradedbCommand
,
removedbCommand
,
dumpCommand
,
{
Action
:
makedag
,
Name
:
"makedag"
,
...
...
@@ -194,15 +194,6 @@ nodes.
},
},
},
{
Action
:
dump
,
Name
:
"dump"
,
Usage
:
`dump a specific block from storage`
,
Description
:
`
The arguments are interpreted as block numbers or hashes.
Use "ethereum dump 0" to dump the genesis block.
`
,
},
{
Action
:
console
,
Name
:
"console"
,
...
...
@@ -222,26 +213,6 @@ The JavaScript VM exposes a node admin interface as well as the Ðapp
JavaScript API. See https://github.com/ethereum/go-ethereum/wiki/Javascipt-Console
`
,
},
{
Action
:
importchain
,
Name
:
"import"
,
Usage
:
`import a blockchain file`
,
},
{
Action
:
exportchain
,
Name
:
"export"
,
Usage
:
`export blockchain into file`
,
},
{
Action
:
upgradeDb
,
Name
:
"upgradedb"
,
Usage
:
"upgrade chainblock database"
,
},
{
Action
:
removeDb
,
Name
:
"removedb"
,
Usage
:
"Remove blockchain and state databases"
,
},
}
app
.
Flags
=
[]
cli
.
Flag
{
utils
.
IdentityFlag
,
...
...
@@ -508,103 +479,6 @@ func accountImport(ctx *cli.Context) {
fmt
.
Printf
(
"Address: %x
\n
"
,
acct
)
}
func
importchain
(
ctx
*
cli
.
Context
)
{
if
len
(
ctx
.
Args
())
!=
1
{
utils
.
Fatalf
(
"This command requires an argument."
)
}
chain
,
blockDB
,
stateDB
,
extraDB
:=
utils
.
GetChain
(
ctx
)
start
:=
time
.
Now
()
if
err
:=
utils
.
ImportChain
(
chain
,
ctx
.
Args
()
.
First
());
err
!=
nil
{
utils
.
Fatalf
(
"Import error: %v
\n
"
,
err
)
}
flushAll
(
blockDB
,
stateDB
,
extraDB
)
fmt
.
Printf
(
"Import done in %v"
,
time
.
Since
(
start
))
}
func
exportchain
(
ctx
*
cli
.
Context
)
{
if
len
(
ctx
.
Args
())
!=
1
{
utils
.
Fatalf
(
"This command requires an argument."
)
}
chain
,
_
,
_
,
_
:=
utils
.
GetChain
(
ctx
)
start
:=
time
.
Now
()
if
err
:=
utils
.
ExportChain
(
chain
,
ctx
.
Args
()
.
First
());
err
!=
nil
{
utils
.
Fatalf
(
"Export error: %v
\n
"
,
err
)
}
fmt
.
Printf
(
"Export done in %v"
,
time
.
Since
(
start
))
}
func
removeDb
(
ctx
*
cli
.
Context
)
{
confirm
,
err
:=
utils
.
PromptConfirm
(
"Remove local databases?"
)
if
err
!=
nil
{
utils
.
Fatalf
(
"%v"
,
err
)
}
if
confirm
{
fmt
.
Println
(
"Removing chain and state databases..."
)
start
:=
time
.
Now
()
os
.
RemoveAll
(
filepath
.
Join
(
ctx
.
GlobalString
(
utils
.
DataDirFlag
.
Name
),
"blockchain"
))
os
.
RemoveAll
(
filepath
.
Join
(
ctx
.
GlobalString
(
utils
.
DataDirFlag
.
Name
),
"state"
))
fmt
.
Printf
(
"Removed in %v
\n
"
,
time
.
Since
(
start
))
}
else
{
fmt
.
Println
(
"Operation aborted"
)
}
}
func
upgradeDb
(
ctx
*
cli
.
Context
)
{
glog
.
Infoln
(
"Upgrading blockchain database"
)
chain
,
blockDB
,
stateDB
,
extraDB
:=
utils
.
GetChain
(
ctx
)
v
,
_
:=
blockDB
.
Get
([]
byte
(
"BlockchainVersion"
))
bcVersion
:=
int
(
common
.
NewValue
(
v
)
.
Uint
())
if
bcVersion
==
0
{
bcVersion
=
core
.
BlockChainVersion
}
// Export the current chain.
filename
:=
fmt
.
Sprintf
(
"blockchain_%d_%s.chain"
,
bcVersion
,
time
.
Now
()
.
Format
(
"20060102_150405"
))
exportFile
:=
filepath
.
Join
(
ctx
.
GlobalString
(
utils
.
DataDirFlag
.
Name
),
filename
)
if
err
:=
utils
.
ExportChain
(
chain
,
exportFile
);
err
!=
nil
{
utils
.
Fatalf
(
"Unable to export chain for reimport %s
\n
"
,
err
)
}
flushAll
(
blockDB
,
stateDB
,
extraDB
)
os
.
RemoveAll
(
filepath
.
Join
(
ctx
.
GlobalString
(
utils
.
DataDirFlag
.
Name
),
"blockchain"
))
os
.
RemoveAll
(
filepath
.
Join
(
ctx
.
GlobalString
(
utils
.
DataDirFlag
.
Name
),
"state"
))
// Import the chain file.
chain
,
blockDB
,
stateDB
,
extraDB
=
utils
.
GetChain
(
ctx
)
blockDB
.
Put
([]
byte
(
"BlockchainVersion"
),
common
.
NewValue
(
core
.
BlockChainVersion
)
.
Bytes
())
err
:=
utils
.
ImportChain
(
chain
,
exportFile
)
flushAll
(
blockDB
,
stateDB
,
extraDB
)
if
err
!=
nil
{
utils
.
Fatalf
(
"Import error %v (a backup is made in %s, use the import command to import it)
\n
"
,
err
,
exportFile
)
}
else
{
os
.
Remove
(
exportFile
)
glog
.
Infoln
(
"Import finished"
)
}
}
func
dump
(
ctx
*
cli
.
Context
)
{
chain
,
_
,
stateDB
,
_
:=
utils
.
GetChain
(
ctx
)
for
_
,
arg
:=
range
ctx
.
Args
()
{
var
block
*
types
.
Block
if
hashish
(
arg
)
{
block
=
chain
.
GetBlock
(
common
.
HexToHash
(
arg
))
}
else
{
num
,
_
:=
strconv
.
Atoi
(
arg
)
block
=
chain
.
GetBlockByNumber
(
uint64
(
num
))
}
if
block
==
nil
{
fmt
.
Println
(
"{}"
)
utils
.
Fatalf
(
"block not found"
)
}
else
{
state
:=
state
.
New
(
block
.
Root
(),
stateDB
)
fmt
.
Printf
(
"%s
\n
"
,
state
.
Dump
())
}
}
}
func
makedag
(
ctx
*
cli
.
Context
)
{
args
:=
ctx
.
Args
()
wrongArgs
:=
func
()
{
...
...
@@ -647,16 +521,3 @@ func version(c *cli.Context) {
fmt
.
Printf
(
"GOPATH=%s
\n
"
,
os
.
Getenv
(
"GOPATH"
))
fmt
.
Printf
(
"GOROOT=%s
\n
"
,
runtime
.
GOROOT
())
}
// hashish returns true for strings that look like hashes.
func
hashish
(
x
string
)
bool
{
_
,
err
:=
strconv
.
Atoi
(
x
)
return
err
!=
nil
}
func
flushAll
(
dbs
...
common
.
Database
)
{
for
_
,
db
:=
range
dbs
{
db
.
Flush
()
db
.
Close
()
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment