diff options
Diffstat (limited to 'cmd/geth')
-rw-r--r-- | cmd/geth/admin.go | 103 | ||||
-rw-r--r-- | cmd/geth/js.go | 4 | ||||
-rw-r--r-- | cmd/geth/main.go | 50 |
3 files changed, 148 insertions, 9 deletions
diff --git a/cmd/geth/admin.go b/cmd/geth/admin.go index 77510b8b8..f15ce89a0 100644 --- a/cmd/geth/admin.go +++ b/cmd/geth/admin.go @@ -3,6 +3,7 @@ package main import ( "errors" "fmt" + "strconv" "time" "github.com/ethereum/go-ethereum/cmd/utils" @@ -15,6 +16,7 @@ import ( "github.com/ethereum/go-ethereum/rpc" "github.com/ethereum/go-ethereum/xeth" "github.com/robertkrimen/otto" + "gopkg.in/fatih/set.v0" ) /* @@ -22,6 +24,11 @@ node admin bindings */ func (js *jsre) adminBindings() { + ethO, _ := js.re.Get("eth") + eth := ethO.Object() + eth.Set("pendingTransactions", js.pendingTransactions) + eth.Set("resend", js.resend) + js.re.Set("admin", struct{}{}) t, _ := js.re.Get("admin") admin := t.Object() @@ -74,6 +81,70 @@ func (js *jsre) getBlock(call otto.FunctionCall) (*types.Block, error) { return nil, errors.New("requires block number or block hash as argument") } +func (js *jsre) pendingTransactions(call otto.FunctionCall) otto.Value { + txs := js.ethereum.TxPool().GetTransactions() + + // grab the accounts from the account manager. This will help with determening which + // transactions should be returned. + accounts, err := js.ethereum.AccountManager().Accounts() + if err != nil { + fmt.Println(err) + return otto.UndefinedValue() + } + + // Add the accouns to a new set + accountSet := set.New() + for _, account := range accounts { + accountSet.Add(common.BytesToAddress(account.Address)) + } + + //ltxs := make([]*tx, len(txs)) + var ltxs []*tx + for _, tx := range txs { + // no need to check err + if from, _ := tx.From(); accountSet.Has(from) { + ltxs = append(ltxs, newTx(tx)) + } + } + + return js.re.ToVal(ltxs) +} + +func (js *jsre) resend(call otto.FunctionCall) otto.Value { + if len(call.ArgumentList) == 0 { + fmt.Println("first argument must be a transaction") + return otto.FalseValue() + } + + v, err := call.Argument(0).Export() + if err != nil { + fmt.Println(err) + return otto.FalseValue() + } + + if tx, ok := v.(*tx); ok { + gl, gp := tx.GasLimit, tx.GasPrice + if len(call.ArgumentList) > 1 { + gp = call.Argument(1).String() + } + if len(call.ArgumentList) > 2 { + gl = call.Argument(2).String() + } + + ret, err := js.xeth.Transact(tx.From, tx.To, tx.Nonce, tx.Value, gl, gp, tx.Data) + if err != nil { + fmt.Println(err) + return otto.FalseValue() + } + js.ethereum.TxPool().RemoveTransactions(types.Transactions{tx.tx}) + + return js.re.ToVal(ret) + } + + fmt.Println("first argument must be a transaction") + return otto.FalseValue() +} + func (js *jsre) debugBlock(call otto.FunctionCall) otto.Value { block, err := js.getBlock(call) if err != nil { @@ -421,3 +492,35 @@ func (js *jsre) dumpBlock(call otto.FunctionCall) otto.Value { return js.re.ToVal(dump) } + +// internal transaction type which will allow us to resend transactions using `eth.resend` +type tx struct { + tx *types.Transaction + + To string + From string + Nonce string + Value string + Data string + GasLimit string + GasPrice string +} + +func newTx(t *types.Transaction) *tx { + from, _ := t.From() + var to string + if t := t.To(); t != nil { + to = t.Hex() + } + + return &tx{ + tx: t, + To: to, + From: from.Hex(), + Value: t.Amount.String(), + Nonce: strconv.Itoa(int(t.Nonce())), + Data: "0x" + common.Bytes2Hex(t.Data()), + GasLimit: t.GasLimit.String(), + GasPrice: t.GasPrice().String(), + } +} diff --git a/cmd/geth/js.go b/cmd/geth/js.go index a545de1d0..d8c26eb2f 100644 --- a/cmd/geth/js.go +++ b/cmd/geth/js.go @@ -103,6 +103,7 @@ func (js *jsre) apiBindings() { t, _ := js.re.Get("jeth") jethObj := t.Object() jethObj.Set("send", jeth.Send) + jethObj.Set("sendAsync", jeth.Send) err := js.re.Compile("bignumber.js", re.BigNumber_JS) if err != nil { @@ -172,8 +173,10 @@ func (self *jsre) UnlockAccount(addr []byte) bool { func (self *jsre) exec(filename string) error { if err := self.re.Exec(filename); err != nil { + self.re.Stop(false) return fmt.Errorf("Javascript Error: %v", err) } + self.re.Stop(true) return nil } @@ -201,6 +204,7 @@ func (self *jsre) interactive() { if self.atexit != nil { self.atexit() } + self.re.Stop(false) } func (self *jsre) withHistory(op func(*os.File)) { diff --git a/cmd/geth/main.go b/cmd/geth/main.go index ef007051c..f2497ccf4 100644 --- a/cmd/geth/main.go +++ b/cmd/geth/main.go @@ -23,14 +23,16 @@ package main import ( "bufio" "fmt" + "io" "io/ioutil" "os" + "path" + "path/filepath" "runtime" "strconv" + "strings" "time" - "path" - "github.com/codegangsta/cli" "github.com/ethereum/ethash" "github.com/ethereum/go-ethereum/accounts" @@ -41,13 +43,15 @@ import ( "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/eth" "github.com/ethereum/go-ethereum/logger" + "github.com/mattn/go-colorable" + "github.com/mattn/go-isatty" "github.com/peterh/liner" ) import _ "net/http/pprof" const ( ClientIdentifier = "Geth" - Version = "0.9.14" + Version = "0.9.15" ) var ( @@ -301,6 +305,14 @@ func run(ctx *cli.Context) { } func console(ctx *cli.Context) { + // Wrap the standard output with a colorified stream (windows) + if isatty.IsTerminal(os.Stdout.Fd()) { + if pr, pw, err := os.Pipe(); err == nil { + go io.Copy(colorable.NewColorableStdout(), pr) + os.Stdout = pw + } + } + cfg := utils.MakeEthConfig(ClientIdentifier, nodeNameVersion, ctx) ethereum, err := eth.New(cfg) if err != nil { @@ -591,12 +603,32 @@ func dump(ctx *cli.Context) { } func makedag(ctx *cli.Context) { - chain, _, _ := utils.GetChain(ctx) - pow := ethash.New(chain) - fmt.Println("making cache") - pow.UpdateCache(0, true) - fmt.Println("making DAG") - pow.UpdateDAG() + args := ctx.Args() + wrongArgs := func() { + utils.Fatalf(`Usage: geth makedag <block number> <outputdir>`) + } + switch { + case len(args) == 2: + blockNum, err := strconv.ParseUint(args[0], 0, 64) + dir := args[1] + if err != nil { + wrongArgs() + } else { + dir = filepath.Clean(dir) + // seems to require a trailing slash + if !strings.HasSuffix(dir, "/") { + dir = dir + "/" + } + _, err = ioutil.ReadDir(dir) + if err != nil { + utils.Fatalf("Can't find dir") + } + fmt.Println("making DAG, this could take awhile...") + ethash.MakeDAG(blockNum, dir) + } + default: + wrongArgs() + } } func version(c *cli.Context) { |