aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--cmd/geth/js.go64
-rw-r--r--core/block_processor.go6
2 files changed, 46 insertions, 24 deletions
diff --git a/cmd/geth/js.go b/cmd/geth/js.go
index 0fb234d45..706bc6554 100644
--- a/cmd/geth/js.go
+++ b/cmd/geth/js.go
@@ -22,6 +22,7 @@ import (
"fmt"
"math/big"
"os"
+ "os/signal"
"path/filepath"
"strings"
@@ -47,7 +48,8 @@ type dumbterm struct{ r *bufio.Reader }
func (r dumbterm) Prompt(p string) (string, error) {
fmt.Print(p)
- return r.r.ReadString('\n')
+ line, err := r.r.ReadString('\n')
+ return strings.TrimSuffix(line, "\n"), err
}
func (r dumbterm) PasswordPrompt(p string) (string, error) {
@@ -182,30 +184,52 @@ func (self *jsre) exec(filename string) error {
}
func (self *jsre) interactive() {
- for {
- input, err := self.Prompt(self.ps1)
- if err != nil {
- break
+ // Read input lines.
+ prompt := make(chan string)
+ inputln := make(chan string)
+ go func() {
+ defer close(inputln)
+ for {
+ line, err := self.Prompt(<-prompt)
+ if err != nil {
+ return
+ }
+ inputln <- line
}
- if input == "" {
- continue
+ }()
+ // Wait for Ctrl-C, too.
+ sig := make(chan os.Signal, 1)
+ signal.Notify(sig, os.Interrupt)
+
+ defer func() {
+ if self.atexit != nil {
+ self.atexit()
}
- str += input + "\n"
- self.setIndent()
- if indentCount <= 0 {
- if input == "exit" {
- break
+ self.re.Stop(false)
+ }()
+ for {
+ prompt <- self.ps1
+ select {
+ case <-sig:
+ fmt.Println("caught interrupt, exiting")
+ return
+ case input, ok := <-inputln:
+ if !ok || indentCount <= 0 && input == "exit" {
+ return
+ }
+ if input == "" {
+ continue
+ }
+ str += input + "\n"
+ self.setIndent()
+ if indentCount <= 0 {
+ hist := str[:len(str)-1]
+ self.AppendHistory(hist)
+ self.parseInput(str)
+ str = ""
}
- hist := str[:len(str)-1]
- self.AppendHistory(hist)
- self.parseInput(str)
- str = ""
}
}
- if self.atexit != nil {
- self.atexit()
- }
- self.re.Stop(false)
}
func (self *jsre) withHistory(op func(*os.File)) {
diff --git a/core/block_processor.go b/core/block_processor.go
index 454c40e27..6cd1c8aa3 100644
--- a/core/block_processor.go
+++ b/core/block_processor.go
@@ -285,9 +285,8 @@ func (self *BlockProcessor) GetBlockReceipts(bhash common.Hash) (receipts types.
}
-// Validates the current block. Returns an error if the block was invalid,
-// an uncle or anything that isn't on the current block chain.
-// Validation validates easy over difficult (dagger takes longer time = difficult)
+// See YP section 4.3.4. "Block Header Validity"
+// Validates a block. Returns an error if the block is invalid.
func (sm *BlockProcessor) ValidateHeader(block, parent *types.Header, checkPow bool) error {
if big.NewInt(int64(len(block.Extra))).Cmp(params.MaximumExtraDataSize) == 1 {
return fmt.Errorf("Block extra data too long (%d)", len(block.Extra))
@@ -298,7 +297,6 @@ func (sm *BlockProcessor) ValidateHeader(block, parent *types.Header, checkPow b
return fmt.Errorf("Difficulty check failed for block %v, %v", block.Difficulty, expd)
}
- // block.gasLimit - parent.gasLimit <= parent.gasLimit / GasLimitBoundDivisor
a := new(big.Int).Sub(block.GasLimit, parent.GasLimit)
a.Abs(a)
b := new(big.Int).Div(parent.GasLimit, params.GasLimitBoundDivisor)