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
c9b6d268
Commit
c9b6d268
authored
Mar 10, 2015
by
Jeffrey Wilcke
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #438 from ethersphere/poc9/cli
Poc9/cli (exportchain)
parents
08d396fd
41a89e18
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
49 additions
and
35 deletions
+49
-35
main.go
cmd/ethereum/main.go
+32
-11
cmd.go
cmd/utils/cmd.go
+17
-24
No files found.
cmd/ethereum/main.go
View file @
c9b6d268
...
@@ -87,6 +87,11 @@ runtime will execute the file and exit.
...
@@ -87,6 +87,11 @@ runtime will execute the file and exit.
Name
:
"import"
,
Name
:
"import"
,
Usage
:
`import a blockchain file`
,
Usage
:
`import a blockchain file`
,
},
},
{
Action
:
exportchain
,
Name
:
"export"
,
Usage
:
`export blockchain into file`
,
},
}
}
app
.
Author
=
""
app
.
Author
=
""
app
.
Email
=
""
app
.
Email
=
""
...
@@ -171,25 +176,39 @@ func importchain(ctx *cli.Context) {
...
@@ -171,25 +176,39 @@ func importchain(ctx *cli.Context) {
if
len
(
ctx
.
Args
())
!=
1
{
if
len
(
ctx
.
Args
())
!=
1
{
utils
.
Fatalf
(
"This command requires an argument."
)
utils
.
Fatalf
(
"This command requires an argument."
)
}
}
chain
,
_
,
_
:=
utils
.
GetChain
(
ctx
)
chain
mgr
,
_
,
_
:=
utils
.
GetChain
(
ctx
)
start
:=
time
.
Now
()
start
:=
time
.
Now
()
err
:=
utils
.
ImportChain
(
chain
,
ctx
.
Args
()
.
First
())
err
:=
utils
.
ImportChain
(
chain
mgr
,
ctx
.
Args
()
.
First
())
if
err
!=
nil
{
if
err
!=
nil
{
utils
.
Fatalf
(
"Import error: %v
\n
"
,
err
)
utils
.
Fatalf
(
"Import error: %v
\n
"
,
err
)
}
}
fmt
.
Printf
(
"Import done in"
,
time
.
Since
(
start
))
fmt
.
Printf
(
"Import done in %v"
,
time
.
Since
(
start
))
return
}
func
exportchain
(
ctx
*
cli
.
Context
)
{
if
len
(
ctx
.
Args
())
!=
1
{
utils
.
Fatalf
(
"This command requires an argument."
)
}
chainmgr
,
_
,
_
:=
utils
.
GetChain
(
ctx
)
start
:=
time
.
Now
()
err
:=
utils
.
ExportChain
(
chainmgr
,
ctx
.
Args
()
.
First
())
if
err
!=
nil
{
utils
.
Fatalf
(
"Export error: %v
\n
"
,
err
)
}
fmt
.
Printf
(
"Export done in %v"
,
time
.
Since
(
start
))
return
return
}
}
func
dump
(
ctx
*
cli
.
Context
)
{
func
dump
(
ctx
*
cli
.
Context
)
{
chain
,
_
,
stateDb
:=
utils
.
GetChain
(
ctx
)
chain
mgr
,
_
,
stateDb
:=
utils
.
GetChain
(
ctx
)
for
_
,
arg
:=
range
ctx
.
Args
()
{
for
_
,
arg
:=
range
ctx
.
Args
()
{
var
block
*
types
.
Block
var
block
*
types
.
Block
if
hashish
(
arg
)
{
if
hashish
(
arg
)
{
block
=
chain
.
GetBlock
(
ethutil
.
Hex2Bytes
(
arg
))
block
=
chain
mgr
.
GetBlock
(
ethutil
.
Hex2Bytes
(
arg
))
}
else
{
}
else
{
num
,
_
:=
strconv
.
Atoi
(
arg
)
num
,
_
:=
strconv
.
Atoi
(
arg
)
block
=
chain
.
GetBlockByNumber
(
uint64
(
num
))
block
=
chain
mgr
.
GetBlockByNumber
(
uint64
(
num
))
}
}
if
block
==
nil
{
if
block
==
nil
{
fmt
.
Println
(
"{}"
)
fmt
.
Println
(
"{}"
)
...
@@ -209,11 +228,13 @@ func hashish(x string) bool {
...
@@ -209,11 +228,13 @@ func hashish(x string) bool {
}
}
func
version
(
c
*
cli
.
Context
)
{
func
version
(
c
*
cli
.
Context
)
{
fmt
.
Printf
(
`%v %v
fmt
.
Printf
(
`%v
PV=%d
Version: %v
GOOS=%s
Protocol Version: %d
GO=%s
Network Id: %d
GO: %s
OS: %s
GOPATH=%s
GOPATH=%s
GOROOT=%s
GOROOT=%s
`
,
ClientIdentifier
,
Version
,
eth
.
ProtocolVersion
,
runtime
.
GOOS
,
runtime
.
Version
()
,
os
.
Getenv
(
"GOPATH"
),
runtime
.
GOROOT
())
`
,
ClientIdentifier
,
Version
,
eth
.
ProtocolVersion
,
eth
.
NetworkId
,
runtime
.
Version
(),
runtime
.
GOOS
,
os
.
Getenv
(
"GOPATH"
),
runtime
.
GOROOT
())
}
}
cmd/utils/cmd.go
View file @
c9b6d268
...
@@ -35,7 +35,6 @@ import (
...
@@ -35,7 +35,6 @@ import (
"github.com/ethereum/go-ethereum/logger"
"github.com/ethereum/go-ethereum/logger"
"github.com/ethereum/go-ethereum/rlp"
"github.com/ethereum/go-ethereum/rlp"
rpchttp
"github.com/ethereum/go-ethereum/rpc/http"
rpchttp
"github.com/ethereum/go-ethereum/rpc/http"
"github.com/ethereum/go-ethereum/state"
"github.com/ethereum/go-ethereum/xeth"
"github.com/ethereum/go-ethereum/xeth"
)
)
...
@@ -188,27 +187,8 @@ func FormatTransactionData(data string) []byte {
...
@@ -188,27 +187,8 @@ func FormatTransactionData(data string) []byte {
return
d
return
d
}
}
// Replay block
func
ImportChain
(
chainmgr
*
core
.
ChainManager
,
fn
string
)
error
{
func
BlockDo
(
ethereum
*
eth
.
Ethereum
,
hash
[]
byte
)
error
{
fmt
.
Printf
(
"importing blockchain '%s'
\n
"
,
fn
)
block
:=
ethereum
.
ChainManager
()
.
GetBlock
(
hash
)
if
block
==
nil
{
return
fmt
.
Errorf
(
"unknown block %x"
,
hash
)
}
parent
:=
ethereum
.
ChainManager
()
.
GetBlock
(
block
.
ParentHash
())
statedb
:=
state
.
New
(
parent
.
Root
(),
ethereum
.
StateDb
())
_
,
err
:=
ethereum
.
BlockProcessor
()
.
TransitionState
(
statedb
,
parent
,
block
,
true
)
if
err
!=
nil
{
return
err
}
return
nil
}
func
ImportChain
(
chain
*
core
.
ChainManager
,
fn
string
)
error
{
fmt
.
Printf
(
"importing chain '%s'
\n
"
,
fn
)
fh
,
err
:=
os
.
OpenFile
(
fn
,
os
.
O_RDONLY
,
os
.
ModePerm
)
fh
,
err
:=
os
.
OpenFile
(
fn
,
os
.
O_RDONLY
,
os
.
ModePerm
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
...
@@ -220,11 +200,24 @@ func ImportChain(chain *core.ChainManager, fn string) error {
...
@@ -220,11 +200,24 @@ func ImportChain(chain *core.ChainManager, fn string) error {
return
err
return
err
}
}
chain
.
Reset
()
chain
mgr
.
Reset
()
if
err
:=
chain
.
InsertChain
(
blocks
);
err
!=
nil
{
if
err
:=
chain
mgr
.
InsertChain
(
blocks
);
err
!=
nil
{
return
err
return
err
}
}
fmt
.
Printf
(
"imported %d blocks
\n
"
,
len
(
blocks
))
fmt
.
Printf
(
"imported %d blocks
\n
"
,
len
(
blocks
))
return
nil
return
nil
}
}
func
ExportChain
(
chainmgr
*
core
.
ChainManager
,
fn
string
)
error
{
fmt
.
Printf
(
"exporting blockchain '%s'
\n
"
,
fn
)
data
:=
chainmgr
.
Export
()
if
err
:=
ethutil
.
WriteFile
(
fn
,
data
);
err
!=
nil
{
return
err
}
fmt
.
Printf
(
"exported blockchain
\n
"
)
return
nil
}
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