diff options
Diffstat (limited to 'cmd/geth')
-rw-r--r-- | cmd/geth/admin.go | 85 | ||||
-rw-r--r-- | cmd/geth/js.go | 18 | ||||
-rw-r--r-- | cmd/geth/main.go | 24 |
3 files changed, 113 insertions, 14 deletions
diff --git a/cmd/geth/admin.go b/cmd/geth/admin.go index 3b37cba75..bd09291bf 100644 --- a/cmd/geth/admin.go +++ b/cmd/geth/admin.go @@ -1,6 +1,7 @@ package main import ( + "errors" "fmt" "os" "time" @@ -9,6 +10,7 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/state" "github.com/ethereum/go-ethereum/core/types" + "github.com/ethereum/go-ethereum/core/vm" "github.com/ethereum/go-ethereum/logger/glog" "github.com/ethereum/go-ethereum/rlp" "github.com/ethereum/go-ethereum/rpc" @@ -35,6 +37,7 @@ func (js *jsre) adminBindings() { admin.Set("export", js.exportChain) admin.Set("verbosity", js.verbosity) admin.Set("backtrace", js.backtrace) + admin.Set("progress", js.downloadProgress) admin.Set("miner", struct{}{}) t, _ = admin.Get("miner") @@ -49,6 +52,88 @@ func (js *jsre) adminBindings() { debug := t.Object() debug.Set("printBlock", js.printBlock) debug.Set("dumpBlock", js.dumpBlock) + debug.Set("getBlockRlp", js.getBlockRlp) + debug.Set("setHead", js.setHead) + debug.Set("block", js.debugBlock) +} + +func (js *jsre) getBlock(call otto.FunctionCall) (*types.Block, error) { + var block *types.Block + if len(call.ArgumentList) > 0 { + if call.Argument(0).IsNumber() { + num, _ := call.Argument(0).ToInteger() + block = js.ethereum.ChainManager().GetBlockByNumber(uint64(num)) + } else if call.Argument(0).IsString() { + hash, _ := call.Argument(0).ToString() + block = js.ethereum.ChainManager().GetBlock(common.HexToHash(hash)) + } else { + return nil, errors.New("invalid argument for dump. Either hex string or number") + } + return block, nil + } + + return nil, errors.New("requires block number or block hash as argument") +} + +func (js *jsre) debugBlock(call otto.FunctionCall) otto.Value { + block, err := js.getBlock(call) + if err != nil { + fmt.Println(err) + return otto.UndefinedValue() + } + + if block == nil { + fmt.Println("block not found") + return otto.UndefinedValue() + } + + old := vm.Debug + vm.Debug = true + _, err = js.ethereum.BlockProcessor().RetryProcess(block) + if err != nil { + glog.Infoln(err) + } + vm.Debug = old + + return otto.UndefinedValue() +} + +func (js *jsre) setHead(call otto.FunctionCall) otto.Value { + block, err := js.getBlock(call) + if err != nil { + fmt.Println(err) + return otto.UndefinedValue() + } + + if block == nil { + fmt.Println("block not found") + return otto.UndefinedValue() + } + + js.ethereum.ChainManager().SetHead(block) + return otto.UndefinedValue() +} + +func (js *jsre) downloadProgress(call otto.FunctionCall) otto.Value { + current, max := js.ethereum.Downloader().Stats() + + return js.re.ToVal(fmt.Sprintf("%d/%d", current, max)) +} + +func (js *jsre) getBlockRlp(call otto.FunctionCall) otto.Value { + block, err := js.getBlock(call) + if err != nil { + fmt.Println(err) + return otto.UndefinedValue() + } + + if block == nil { + fmt.Println("block not found") + return otto.UndefinedValue() + } + + encoded, _ := rlp.EncodeToBytes(block) + return js.re.ToVal(fmt.Sprintf("%x", encoded)) } func (js *jsre) setExtra(call otto.FunctionCall) otto.Value { diff --git a/cmd/geth/js.go b/cmd/geth/js.go index 0061f20cf..6e5a6f1c7 100644 --- a/cmd/geth/js.go +++ b/cmd/geth/js.go @@ -25,7 +25,8 @@ import ( "strings" "github.com/ethereum/go-ethereum/cmd/utils" - "github.com/ethereum/go-ethereum/core/types" + "github.com/ethereum/go-ethereum/common/docserver" + "github.com/ethereum/go-ethereum/common/natspec" "github.com/ethereum/go-ethereum/eth" re "github.com/ethereum/go-ethereum/jsre" "github.com/ethereum/go-ethereum/rpc" @@ -139,10 +140,17 @@ var net = web3.net; js.re.Eval(globalRegistrar + "registrar = new GlobalRegistrar(\"" + globalRegistrarAddr + "\");") } -func (self *jsre) ConfirmTransaction(tx *types.Transaction) bool { - p := fmt.Sprintf("Confirm Transaction %v\n[y/n] ", tx) - answer, _ := self.Prompt(p) - return strings.HasPrefix(strings.Trim(answer, " "), "y") +var ds, _ = docserver.New(utils.JSpathFlag.String()) + +func (self *jsre) ConfirmTransaction(tx string) bool { + if self.ethereum.NatSpec { + notice := natspec.GetNotice(self.xeth, tx, ds) + fmt.Println(notice) + answer, _ := self.Prompt("Confirm Transaction\n[y/n] ") + return strings.HasPrefix(strings.Trim(answer, " "), "y") + } else { + return true + } } func (self *jsre) UnlockAccount(addr []byte) bool { diff --git a/cmd/geth/main.go b/cmd/geth/main.go index e18b92a2e..ddbd1f129 100644 --- a/cmd/geth/main.go +++ b/cmd/geth/main.go @@ -24,13 +24,13 @@ import ( "bufio" "fmt" "io/ioutil" - "log" - "net/http" "os" "runtime" "strconv" "time" + "path" + "github.com/codegangsta/cli" "github.com/ethereum/ethash" "github.com/ethereum/go-ethereum/accounts" @@ -42,13 +42,12 @@ import ( "github.com/ethereum/go-ethereum/eth" "github.com/ethereum/go-ethereum/logger" "github.com/peterh/liner" - "path" ) import _ "net/http/pprof" const ( ClientIdentifier = "Geth" - Version = "0.9.9" + Version = "0.9.11" ) var app = utils.NewApp(Version, "the go-ethereum command line interface") @@ -217,6 +216,7 @@ JavaScript API. See https://github.com/ethereum/go-ethereum/wiki/Javascipt-Conso }, } app.Flags = []cli.Flag{ + utils.IdentityFlag, utils.UnlockedAccountFlag, utils.PasswordFileFlag, utils.BootnodesFlag, @@ -229,11 +229,13 @@ JavaScript API. See https://github.com/ethereum/go-ethereum/wiki/Javascipt-Conso utils.MinerThreadsFlag, utils.MiningEnabledFlag, utils.NATFlag, + utils.NatspecEnabledFlag, utils.NodeKeyFileFlag, utils.NodeKeyHexFlag, utils.RPCEnabledFlag, utils.RPCListenAddrFlag, utils.RPCPortFlag, + utils.WhisperEnabledFlag, utils.VMDebugFlag, utils.ProtocolVersionFlag, utils.NetworkIdFlag, @@ -244,6 +246,14 @@ JavaScript API. See https://github.com/ethereum/go-ethereum/wiki/Javascipt-Conso utils.LogVModuleFlag, utils.LogFileFlag, utils.LogJSONFlag, + utils.PProfEanbledFlag, + utils.PProfPortFlag, + } + app.Before = func(ctx *cli.Context) error { + if ctx.GlobalBool(utils.PProfEanbledFlag.Name) { + utils.StartPProf(ctx) + } + return nil } // missing: @@ -258,11 +268,6 @@ JavaScript API. See https://github.com/ethereum/go-ethereum/wiki/Javascipt-Conso } func main() { - // Start up the default http server for pprof - go func() { - log.Println(http.ListenAndServe("localhost:6060", nil)) - }() - fmt.Printf("Welcome to the FRONTIER\n") runtime.GOMAXPROCS(runtime.NumCPU()) defer logger.Flush() @@ -334,6 +339,7 @@ func unlockAccount(ctx *cli.Context, am *accounts.Manager, account string) (pass } func startEth(ctx *cli.Context, eth *eth.Ethereum) { + // Start Ethereum itself utils.StartEthereum(eth) am := eth.AccountManager() |