diff options
Diffstat (limited to 'cmd/geth/admin.go')
-rw-r--r-- | cmd/geth/admin.go | 45 |
1 files changed, 16 insertions, 29 deletions
diff --git a/cmd/geth/admin.go b/cmd/geth/admin.go index bd09291bf..31f8d4400 100644 --- a/cmd/geth/admin.go +++ b/cmd/geth/admin.go @@ -3,7 +3,6 @@ package main import ( "errors" "fmt" - "os" "time" "github.com/ethereum/go-ethereum/cmd/utils" @@ -36,7 +35,6 @@ func (js *jsre) adminBindings() { admin.Set("import", js.importChain) admin.Set("export", js.exportChain) admin.Set("verbosity", js.verbosity) - admin.Set("backtrace", js.backtrace) admin.Set("progress", js.downloadProgress) admin.Set("miner", struct{}{}) @@ -50,11 +48,12 @@ func (js *jsre) adminBindings() { admin.Set("debug", struct{}{}) t, _ = admin.Get("debug") debug := t.Object() + debug.Set("backtrace", js.backtrace) 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) + debug.Set("processBlock", js.debugBlock) } func (js *jsre) getBlock(call otto.FunctionCall) (*types.Block, error) { @@ -204,16 +203,26 @@ func (js *jsre) startRPC(call otto.FunctionCall) otto.Value { fmt.Println(err) return otto.FalseValue() } + port, err := call.Argument(1).ToInteger() if err != nil { fmt.Println(err) return otto.FalseValue() } + corsDomain := js.corsDomain + if len(call.ArgumentList) > 2 { + corsDomain, err = call.Argument(2).ToString() + if err != nil { + fmt.Println(err) + return otto.FalseValue() + } + } + config := rpc.RpcConfig{ ListenAddress: addr, ListenPort: uint(port), - // CorsDomain: ctx.GlobalString(RPCCORSDomainFlag.Name), + CorsDomain: corsDomain, } xeth := xeth.New(js.ethereum, nil) @@ -275,10 +284,6 @@ func (js *jsre) unlock(call otto.FunctionCall) otto.Value { } } am := js.ethereum.AccountManager() - // err := am.Unlock(common.FromHex(split[0]), split[1]) - // if err != nil { - // utils.Fatalf("Unlock account failed '%v'", err) - // } err = am.TimedUnlock(common.FromHex(addr), passphrase, time.Duration(seconds)*time.Second) if err != nil { fmt.Printf("Unlock account failed '%v'\n", err) @@ -318,7 +323,7 @@ func (js *jsre) newAccount(call otto.FunctionCall) otto.Value { fmt.Printf("Could not create the account: %v", err) return otto.UndefinedValue() } - return js.re.ToVal(common.Bytes2Hex(acct.Address)) + return js.re.ToVal("0x" + common.Bytes2Hex(acct.Address)) } func (js *jsre) nodeInfo(call otto.FunctionCall) otto.Value { @@ -334,33 +339,15 @@ func (js *jsre) importChain(call otto.FunctionCall) otto.Value { fmt.Println("err: require file name") return otto.FalseValue() } - fn, err := call.Argument(0).ToString() if err != nil { fmt.Println(err) return otto.FalseValue() } - - var fh *os.File - fh, err = os.OpenFile(fn, os.O_RDONLY, os.ModePerm) - if err != nil { - fmt.Println(err) - return otto.FalseValue() - } - defer fh.Close() - - var blocks types.Blocks - if err = rlp.Decode(fh, &blocks); err != nil { - fmt.Println(err) - return otto.FalseValue() - } - - js.ethereum.ChainManager().Reset() - if err = js.ethereum.ChainManager().InsertChain(blocks); err != nil { - fmt.Println(err) + if err := utils.ImportChain(js.ethereum.ChainManager(), fn); err != nil { + fmt.Println("Import error: ", err) return otto.FalseValue() } - return otto.TrueValue() } |