|
|
@ -63,6 +63,7 @@ type jsre struct { |
|
|
|
ethereum *eth.Ethereum |
|
|
|
ethereum *eth.Ethereum |
|
|
|
xeth *xeth.XEth |
|
|
|
xeth *xeth.XEth |
|
|
|
ps1 string |
|
|
|
ps1 string |
|
|
|
|
|
|
|
atexit func() |
|
|
|
|
|
|
|
|
|
|
|
prompter |
|
|
|
prompter |
|
|
|
} |
|
|
|
} |
|
|
@ -77,11 +78,13 @@ func newJSRE(ethereum *eth.Ethereum) *jsre { |
|
|
|
js.prompter = dumbterm{bufio.NewReader(os.Stdin)} |
|
|
|
js.prompter = dumbterm{bufio.NewReader(os.Stdin)} |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
lr := liner.NewLiner() |
|
|
|
lr := liner.NewLiner() |
|
|
|
lr.SetCtrlCAborts(true) |
|
|
|
|
|
|
|
defer lr.Close() |
|
|
|
|
|
|
|
js.withHistory(func(hist *os.File) { lr.ReadHistory(hist) }) |
|
|
|
js.withHistory(func(hist *os.File) { lr.ReadHistory(hist) }) |
|
|
|
defer js.withHistory(func(hist *os.File) { hist.Truncate(0); lr.WriteHistory(hist) }) |
|
|
|
lr.SetCtrlCAborts(true) |
|
|
|
js.prompter = lr |
|
|
|
js.prompter = lr |
|
|
|
|
|
|
|
js.atexit = func() { |
|
|
|
|
|
|
|
js.withHistory(func(hist *os.File) { hist.Truncate(0); lr.WriteHistory(hist) }) |
|
|
|
|
|
|
|
lr.Close() |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
return js |
|
|
|
return js |
|
|
|
} |
|
|
|
} |
|
|
@ -100,7 +103,6 @@ func (self *jsre) UnlockAccount(addr []byte) bool { |
|
|
|
} |
|
|
|
} |
|
|
|
// TODO: allow retry
|
|
|
|
// TODO: allow retry
|
|
|
|
if err := self.ethereum.AccountManager().Unlock(addr, pass); err != nil { |
|
|
|
if err := self.ethereum.AccountManager().Unlock(addr, pass); err != nil { |
|
|
|
fmt.Println("Unlocking failed: ", err) |
|
|
|
|
|
|
|
return false |
|
|
|
return false |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
fmt.Println("Account is now unlocked for this session.") |
|
|
|
fmt.Println("Account is now unlocked for this session.") |
|
|
@ -127,7 +129,7 @@ func (self *jsre) interactive() { |
|
|
|
for { |
|
|
|
for { |
|
|
|
input, err := self.Prompt(self.ps1) |
|
|
|
input, err := self.Prompt(self.ps1) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
return |
|
|
|
break |
|
|
|
} |
|
|
|
} |
|
|
|
if input == "" { |
|
|
|
if input == "" { |
|
|
|
continue |
|
|
|
continue |
|
|
@ -136,7 +138,7 @@ func (self *jsre) interactive() { |
|
|
|
self.setIndent() |
|
|
|
self.setIndent() |
|
|
|
if indentCount <= 0 { |
|
|
|
if indentCount <= 0 { |
|
|
|
if input == "exit" { |
|
|
|
if input == "exit" { |
|
|
|
return |
|
|
|
break |
|
|
|
} |
|
|
|
} |
|
|
|
hist := str[:len(str)-1] |
|
|
|
hist := str[:len(str)-1] |
|
|
|
self.AppendHistory(hist) |
|
|
|
self.AppendHistory(hist) |
|
|
@ -144,6 +146,9 @@ func (self *jsre) interactive() { |
|
|
|
str = "" |
|
|
|
str = "" |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if self.atexit != nil { |
|
|
|
|
|
|
|
self.atexit() |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (self *jsre) withHistory(op func(*os.File)) { |
|
|
|
func (self *jsre) withHistory(op func(*os.File)) { |
|
|
|