aboutsummaryrefslogtreecommitdiffstats
path: root/cmd
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2015-03-15 06:37:21 +0800
committerobscuren <geffobscura@gmail.com>2015-03-15 06:37:21 +0800
commitd9966d615813130c8d31b3b10a59d43d00fd9943 (patch)
treeb5a196dd1ef20050160eb384c876ccaba1c4eebf /cmd
parent12cee1377f8795608bae3cad38ee22c032b3b865 (diff)
parent67f8f83a1ba2a4dbd0f6f2fd075bb440f5c420ad (diff)
downloadgo-tangerine-d9966d615813130c8d31b3b10a59d43d00fd9943.tar
go-tangerine-d9966d615813130c8d31b3b10a59d43d00fd9943.tar.gz
go-tangerine-d9966d615813130c8d31b3b10a59d43d00fd9943.tar.bz2
go-tangerine-d9966d615813130c8d31b3b10a59d43d00fd9943.tar.lz
go-tangerine-d9966d615813130c8d31b3b10a59d43d00fd9943.tar.xz
go-tangerine-d9966d615813130c8d31b3b10a59d43d00fd9943.tar.zst
go-tangerine-d9966d615813130c8d31b3b10a59d43d00fd9943.zip
merge
Diffstat (limited to 'cmd')
-rw-r--r--cmd/ethereum/blocktest.go66
-rw-r--r--cmd/ethereum/main.go19
-rw-r--r--cmd/mist/main.go4
-rw-r--r--cmd/utils/flags.go6
4 files changed, 83 insertions, 12 deletions
diff --git a/cmd/ethereum/blocktest.go b/cmd/ethereum/blocktest.go
new file mode 100644
index 000000000..1bb3809cf
--- /dev/null
+++ b/cmd/ethereum/blocktest.go
@@ -0,0 +1,66 @@
+package main
+
+import (
+ "fmt"
+
+ "github.com/codegangsta/cli"
+ "github.com/ethereum/go-ethereum/cmd/utils"
+ "github.com/ethereum/go-ethereum/eth"
+ "github.com/ethereum/go-ethereum/ethdb"
+ "github.com/ethereum/go-ethereum/ethutil"
+ "github.com/ethereum/go-ethereum/tests"
+)
+
+var blocktestCmd = cli.Command{
+ Action: runblocktest,
+ Name: "blocktest",
+ Usage: `loads a block test file`,
+ Description: `
+The first argument should be a block test file.
+The second argument is the name of a block test from the file.
+
+The block test will be loaded into an in-memory database.
+If loading succeeds, the RPC server is started. Clients will
+be able to interact with the chain defined by the test.
+`,
+}
+
+func runblocktest(ctx *cli.Context) {
+ if len(ctx.Args()) != 2 {
+ utils.Fatalf("This command requires two arguments.")
+ }
+ file, testname := ctx.Args()[0], ctx.Args()[1]
+
+ bt, err := tests.LoadBlockTests(file)
+ if err != nil {
+ utils.Fatalf("%v", err)
+ }
+ test, ok := bt[testname]
+ if !ok {
+ utils.Fatalf("Test file does not contain test named %q", testname)
+ }
+
+ cfg := utils.MakeEthConfig(ClientIdentifier, Version, ctx)
+ cfg.NewDB = func(path string) (ethutil.Database, error) { return ethdb.NewMemDatabase() }
+ ethereum, err := eth.New(cfg)
+ if err != nil {
+ utils.Fatalf("%v", err)
+ }
+
+ // import the genesis block
+ ethereum.ResetWithGenesisBlock(test.Genesis)
+
+ // import pre accounts
+ if err := test.InsertPreState(ethereum.StateDb()); err != nil {
+ utils.Fatalf("could not insert genesis accounts: %v", err)
+ }
+
+ // insert the test blocks, which will execute all transactions
+ chain := ethereum.ChainManager()
+ if err := chain.InsertChain(test.Blocks); err != nil {
+ utils.Fatalf("Block Test load error: %v", err)
+ } else {
+ fmt.Println("Block Test chain loaded, starting ethereum.")
+ }
+ startEth(ctx, ethereum)
+}
diff --git a/cmd/ethereum/main.go b/cmd/ethereum/main.go
index 4cb2d9979..53746627a 100644
--- a/cmd/ethereum/main.go
+++ b/cmd/ethereum/main.go
@@ -53,6 +53,7 @@ func init() {
app.Action = run
app.HideVersion = true // we have a command to print the version
app.Commands = []cli.Command{
+ blocktestCmd,
{
Action: version,
Name: "version",
@@ -156,24 +157,26 @@ func main() {
func run(ctx *cli.Context) {
fmt.Printf("Welcome to the FRONTIER\n")
utils.HandleInterrupt()
- eth, err := utils.GetEthereum(ClientIdentifier, Version, ctx)
+ cfg := utils.MakeEthConfig(ClientIdentifier, Version, ctx)
+ ethereum, err := eth.New(cfg)
if err != nil {
utils.Fatalf("%v", err)
}
- startEth(ctx, eth)
+ startEth(ctx, ethereum)
// this blocks the thread
- eth.WaitForShutdown()
+ ethereum.WaitForShutdown()
}
func runjs(ctx *cli.Context) {
- eth, err := utils.GetEthereum(ClientIdentifier, Version, ctx)
+ cfg := utils.MakeEthConfig(ClientIdentifier, Version, ctx)
+ ethereum, err := eth.New(cfg)
if err != nil {
utils.Fatalf("%v", err)
}
- startEth(ctx, eth)
- repl := newJSRE(eth)
+ startEth(ctx, ethereum)
+ repl := newJSRE(ethereum)
if len(ctx.Args()) == 0 {
repl.interactive()
} else {
@@ -181,8 +184,8 @@ func runjs(ctx *cli.Context) {
repl.exec(file)
}
}
- eth.Stop()
- eth.WaitForShutdown()
+ ethereum.Stop()
+ ethereum.WaitForShutdown()
}
func startEth(ctx *cli.Context, eth *eth.Ethereum) {
diff --git a/cmd/mist/main.go b/cmd/mist/main.go
index 9a773e33a..4116783c9 100644
--- a/cmd/mist/main.go
+++ b/cmd/mist/main.go
@@ -28,6 +28,7 @@ import (
"github.com/codegangsta/cli"
"github.com/ethereum/go-ethereum/cmd/utils"
+ "github.com/ethereum/go-ethereum/eth"
"github.com/ethereum/go-ethereum/ethutil"
"github.com/ethereum/go-ethereum/logger"
"github.com/ethereum/go-ethereum/ui/qt/webengine"
@@ -95,7 +96,8 @@ func run(ctx *cli.Context) {
tstart := time.Now()
// TODO: show qml popup instead of exiting if initialization fails.
- ethereum, err := utils.GetEthereum(ClientIdentifier, Version, ctx)
+ cfg := utils.MakeEthConfig(ClientIdentifier, Version, ctx)
+ ethereum, err := eth.New(cfg)
if err != nil {
utils.Fatalf("%v", err)
}
diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go
index 990fb08e0..6bcd7e811 100644
--- a/cmd/utils/flags.go
+++ b/cmd/utils/flags.go
@@ -191,8 +191,8 @@ func GetNodeKey(ctx *cli.Context) (key *ecdsa.PrivateKey) {
return key
}
-func GetEthereum(clientID, version string, ctx *cli.Context) (*eth.Ethereum, error) {
- return eth.New(&eth.Config{
+func MakeEthConfig(clientID, version string, ctx *cli.Context) *eth.Config {
+ return &eth.Config{
Name: ethutil.MakeName(clientID, version),
DataDir: ctx.GlobalString(DataDirFlag.Name),
LogFile: ctx.GlobalString(LogFileFlag.Name),
@@ -208,7 +208,7 @@ func GetEthereum(clientID, version string, ctx *cli.Context) (*eth.Ethereum, err
Shh: true,
Dial: true,
BootNodes: ctx.GlobalString(BootnodesFlag.Name),
- })
+ }
}
func GetChain(ctx *cli.Context) (*core.ChainManager, ethutil.Database, ethutil.Database) {